]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.5.3-201209062131.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.3-201209062131.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b4a898f..cd023f2 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 @@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56 +ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60 @@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64 +builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70 +clut_vga16.c
71 +common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78 +config.c
79 config.mak
80 config.mak.autogen
81 +config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85 @@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89 +dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93 +exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97 @@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101 +gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108 +hash
109 +hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113 @@ -145,7 +163,7 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117 -kconfig
118 +kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 @@ -153,7 +171,7 @@ kxgettext
123 lkc_defs.h
124 lex.c
125 lex.*.c
126 -linux
127 +lib1funcs.S
128 logo_*.c
129 logo_*_clut224.c
130 logo_*_mono.c
131 @@ -164,14 +182,15 @@ machtypes.h
132 map
133 map_hugetlb
134 maui_boot.h
135 -media
136 mconf
137 +mdp
138 miboot*
139 mk_elfconfig
140 mkboot
141 mkbugboot
142 mkcpustr
143 mkdep
144 +mkpiggy
145 mkprep
146 mkregtable
147 mktables
148 @@ -188,6 +207,8 @@ oui.c*
149 page-types
150 parse.c
151 parse.h
152 +parse-events*
153 +pasyms.h
154 patches*
155 pca200e.bin
156 pca200e_ecd.bin2
157 @@ -197,6 +218,7 @@ perf-archive
158 piggyback
159 piggy.gzip
160 piggy.S
161 +pmu-*
162 pnmtologo
163 ppc_defs.h*
164 pss_boot.h
165 @@ -206,7 +228,10 @@ r200_reg_safe.h
166 r300_reg_safe.h
167 r420_reg_safe.h
168 r600_reg_safe.h
169 +realmode.lds
170 +realmode.relocs
171 recordmcount
172 +regdb.c
173 relocs
174 rlim_names.h
175 rn50_reg_safe.h
176 @@ -216,8 +241,11 @@ series
177 setup
178 setup.bin
179 setup.elf
180 +size_overflow_hash.h
181 sImage
182 +slabinfo
183 sm_tbl*
184 +sortextable
185 split-include
186 syscalltab.h
187 tables.c
188 @@ -227,6 +255,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192 +user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196 @@ -238,13 +267,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200 +vdsox32.lds
201 +vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208 +vmlinux.bin.bz2
209 vmlinux.lds
210 +vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214 @@ -252,9 +285,11 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218 +utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222 zImage*
223 zconf.hash.c
224 +zconf.lex.c
225 zoffset.h
226 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
227 index a92c5eb..7530459 100644
228 --- a/Documentation/kernel-parameters.txt
229 +++ b/Documentation/kernel-parameters.txt
230 @@ -2051,6 +2051,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
231 the specified number of seconds. This is to be used if
232 your oopses keep scrolling off the screen.
233
234 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
235 + virtualization environments that don't cope well with the
236 + expand down segment used by UDEREF on X86-32 or the frequent
237 + page table updates on X86-64.
238 +
239 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
240 +
241 pcbit= [HW,ISDN]
242
243 pcd. [PARIDE]
244 diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
245 index 13d6166..8c235b6 100644
246 --- a/Documentation/sysctl/fs.txt
247 +++ b/Documentation/sysctl/fs.txt
248 @@ -163,16 +163,22 @@ This value can be used to query and set the core dump mode for setuid
249 or otherwise protected/tainted binaries. The modes are
250
251 0 - (default) - traditional behaviour. Any process which has changed
252 - privilege levels or is execute only will not be dumped
253 + privilege levels or is execute only will not be dumped.
254 1 - (debug) - all processes dump core when possible. The core dump is
255 owned by the current user and no security is applied. This is
256 intended for system debugging situations only. Ptrace is unchecked.
257 + This is insecure as it allows regular users to examine the memory
258 + contents of privileged processes.
259 2 - (suidsafe) - any binary which normally would not be dumped is dumped
260 - readable by root only. This allows the end user to remove
261 - such a dump but not access it directly. For security reasons
262 - core dumps in this mode will not overwrite one another or
263 - other files. This mode is appropriate when administrators are
264 - attempting to debug problems in a normal environment.
265 + anyway, but only if the "core_pattern" kernel sysctl is set to
266 + either a pipe handler or a fully qualified path. (For more details
267 + on this limitation, see CVE-2006-2451.) This mode is appropriate
268 + when administrators are attempting to debug problems in a normal
269 + environment, and either have a core dump pipe handler that knows
270 + to treat privileged core dumps with care, or specific directory
271 + defined for catching core dumps. If a core dump happens without
272 + a pipe handler or fully qualifid path, a message will be emitted
273 + to syslog warning about the lack of a correct setting.
274
275 ==============================================================
276
277 diff --git a/Makefile b/Makefile
278 index c901aae..0f96503 100644
279 --- a/Makefile
280 +++ b/Makefile
281 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
282
283 HOSTCC = gcc
284 HOSTCXX = g++
285 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
286 -HOSTCXXFLAGS = -O2
287 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
288 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
289 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
290
291 # Decide whether to build built-in, modular, or both.
292 # Normally, just do built-in.
293 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
294 # Rules shared between *config targets and build targets
295
296 # Basic helpers built in scripts/
297 -PHONY += scripts_basic
298 -scripts_basic:
299 +PHONY += scripts_basic gcc-plugins
300 +scripts_basic: gcc-plugins
301 $(Q)$(MAKE) $(build)=scripts/basic
302 $(Q)rm -f .tmp_quiet_recordmcount
303
304 @@ -561,6 +562,60 @@ else
305 KBUILD_CFLAGS += -O2
306 endif
307
308 +ifndef DISABLE_PAX_PLUGINS
309 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
310 +ifneq ($(PLUGINCC),)
311 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
312 +ifndef CONFIG_UML
313 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
314 +endif
315 +endif
316 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
317 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
318 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
319 +endif
320 +ifdef CONFIG_KALLOCSTAT_PLUGIN
321 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
322 +endif
323 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
324 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
325 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
326 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
327 +endif
328 +ifdef CONFIG_CHECKER_PLUGIN
329 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
330 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
331 +endif
332 +endif
333 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
334 +ifdef CONFIG_PAX_SIZE_OVERFLOW
335 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
336 +endif
337 +ifdef CONFIG_PAX_LATENT_ENTROPY
338 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
339 +endif
340 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
341 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
342 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
343 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
344 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
345 +ifeq ($(KBUILD_EXTMOD),)
346 +gcc-plugins:
347 + $(Q)$(MAKE) $(build)=tools/gcc
348 +else
349 +gcc-plugins: ;
350 +endif
351 +else
352 +gcc-plugins:
353 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
354 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
355 +else
356 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
357 +endif
358 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
359 +endif
360 +endif
361 +
362 include $(srctree)/arch/$(SRCARCH)/Makefile
363
364 ifdef CONFIG_READABLE_ASM
365 @@ -715,7 +770,7 @@ export mod_strip_cmd
366
367
368 ifeq ($(KBUILD_EXTMOD),)
369 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
370 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
371
372 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
373 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
374 @@ -762,6 +817,8 @@ endif
375
376 # The actual objects are generated when descending,
377 # make sure no implicit rule kicks in
378 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
379 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
380 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
381
382 # Handle descending into subdirectories listed in $(vmlinux-dirs)
383 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
384 # Error messages still appears in the original language
385
386 PHONY += $(vmlinux-dirs)
387 -$(vmlinux-dirs): prepare scripts
388 +$(vmlinux-dirs): gcc-plugins prepare scripts
389 $(Q)$(MAKE) $(build)=$@
390
391 # Store (new) KERNELRELASE string in include/config/kernel.release
392 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
393 $(Q)$(MAKE) $(build)=.
394
395 # All the preparing..
396 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
397 prepare: prepare0
398
399 # Generate some files
400 @@ -922,6 +980,8 @@ all: modules
401 # using awk while concatenating to the final file.
402
403 PHONY += modules
404 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
405 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
406 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
407 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
408 @$(kecho) ' Building modules, stage 2.';
409 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
410
411 # Target to prepare building external modules
412 PHONY += modules_prepare
413 -modules_prepare: prepare scripts
414 +modules_prepare: gcc-plugins prepare scripts
415
416 # Target to install modules
417 PHONY += modules_install
418 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
419 MRPROPER_DIRS += include/config usr/include include/generated \
420 arch/*/include/generated
421 MRPROPER_FILES += .config .config.old .version .old_version \
422 - include/linux/version.h \
423 + include/linux/version.h tools/gcc/size_overflow_hash.h\
424 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
425
426 # clean - Delete most, but leave enough to build external modules
427 @@ -1032,6 +1092,7 @@ distclean: mrproper
428 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
429 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
430 -o -name '.*.rej' \
431 + -o -name '.*.rej' -o -name '*.so' \
432 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
433 -type f -print | xargs rm -f
434
435 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
436 $(module-dirs): crmodverdir $(objtree)/Module.symvers
437 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
438
439 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
440 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
441 modules: $(module-dirs)
442 @$(kecho) ' Building modules, stage 2.';
443 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
444 @@ -1326,17 +1389,21 @@ else
445 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
446 endif
447
448 -%.s: %.c prepare scripts FORCE
449 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451 +%.s: %.c gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.i: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455 -%.o: %.c prepare scripts FORCE
456 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458 +%.o: %.c gcc-plugins prepare scripts FORCE
459 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
460 %.lst: %.c prepare scripts FORCE
461 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
462 -%.s: %.S prepare scripts FORCE
463 +%.s: %.S gcc-plugins prepare scripts FORCE
464 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
465 -%.o: %.S prepare scripts FORCE
466 +%.o: %.S gcc-plugins prepare scripts FORCE
467 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
468 %.symtypes: %.c prepare scripts FORCE
469 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
470 @@ -1346,11 +1413,15 @@ endif
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir)
474 -%/: prepare scripts FORCE
475 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
476 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
477 +%/: gcc-plugins prepare scripts FORCE
478 $(cmd_crmodverdir)
479 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
480 $(build)=$(build-dir)
481 -%.ko: prepare scripts FORCE
482 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484 +%.ko: gcc-plugins prepare scripts FORCE
485 $(cmd_crmodverdir)
486 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
487 $(build)=$(build-dir) $(@:.ko=.o)
488 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
489 index 3bb7ffe..347a54c 100644
490 --- a/arch/alpha/include/asm/atomic.h
491 +++ b/arch/alpha/include/asm/atomic.h
492 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
493 #define atomic_dec(v) atomic_sub(1,(v))
494 #define atomic64_dec(v) atomic64_sub(1,(v))
495
496 +#define atomic64_read_unchecked(v) atomic64_read(v)
497 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
498 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
499 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
500 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
501 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
502 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
503 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
504 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
505 +
506 #define smp_mb__before_atomic_dec() smp_mb()
507 #define smp_mb__after_atomic_dec() smp_mb()
508 #define smp_mb__before_atomic_inc() smp_mb()
509 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
510 index ad368a9..fbe0f25 100644
511 --- a/arch/alpha/include/asm/cache.h
512 +++ b/arch/alpha/include/asm/cache.h
513 @@ -4,19 +4,19 @@
514 #ifndef __ARCH_ALPHA_CACHE_H
515 #define __ARCH_ALPHA_CACHE_H
516
517 +#include <linux/const.h>
518
519 /* Bytes per L1 (data) cache line. */
520 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
521 -# define L1_CACHE_BYTES 64
522 # define L1_CACHE_SHIFT 6
523 #else
524 /* Both EV4 and EV5 are write-through, read-allocate,
525 direct-mapped, physical.
526 */
527 -# define L1_CACHE_BYTES 32
528 # define L1_CACHE_SHIFT 5
529 #endif
530
531 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
532 #define SMP_CACHE_BYTES L1_CACHE_BYTES
533
534 #endif
535 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
536 index 968d999..d36b2df 100644
537 --- a/arch/alpha/include/asm/elf.h
538 +++ b/arch/alpha/include/asm/elf.h
539 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
540
541 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
542
543 +#ifdef CONFIG_PAX_ASLR
544 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
545 +
546 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
547 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
548 +#endif
549 +
550 /* $0 is set by ld.so to a pointer to a function which might be
551 registered using atexit. This provides a mean for the dynamic
552 linker to call DT_FINI functions for shared libraries that have
553 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
554 index bc2a0da..8ad11ee 100644
555 --- a/arch/alpha/include/asm/pgalloc.h
556 +++ b/arch/alpha/include/asm/pgalloc.h
557 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
558 pgd_set(pgd, pmd);
559 }
560
561 +static inline void
562 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
563 +{
564 + pgd_populate(mm, pgd, pmd);
565 +}
566 +
567 extern pgd_t *pgd_alloc(struct mm_struct *mm);
568
569 static inline void
570 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
571 index 81a4342..348b927 100644
572 --- a/arch/alpha/include/asm/pgtable.h
573 +++ b/arch/alpha/include/asm/pgtable.h
574 @@ -102,6 +102,17 @@ struct vm_area_struct;
575 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
576 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
577 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
578 +
579 +#ifdef CONFIG_PAX_PAGEEXEC
580 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
581 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
582 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
583 +#else
584 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
585 +# define PAGE_COPY_NOEXEC PAGE_COPY
586 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
587 +#endif
588 +
589 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
590
591 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
592 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
593 index 2fd00b7..cfd5069 100644
594 --- a/arch/alpha/kernel/module.c
595 +++ b/arch/alpha/kernel/module.c
596 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
597
598 /* The small sections were sorted to the end of the segment.
599 The following should definitely cover them. */
600 - gp = (u64)me->module_core + me->core_size - 0x8000;
601 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
602 got = sechdrs[me->arch.gotsecindex].sh_addr;
603
604 for (i = 0; i < n; i++) {
605 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
606 index 98a1036..fb54ccf 100644
607 --- a/arch/alpha/kernel/osf_sys.c
608 +++ b/arch/alpha/kernel/osf_sys.c
609 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
610 /* At this point: (!vma || addr < vma->vm_end). */
611 if (limit - len < addr)
612 return -ENOMEM;
613 - if (!vma || addr + len <= vma->vm_start)
614 + if (check_heap_stack_gap(vma, addr, len))
615 return addr;
616 addr = vma->vm_end;
617 vma = vma->vm_next;
618 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
619 merely specific addresses, but regions of memory -- perhaps
620 this feature should be incorporated into all ports? */
621
622 +#ifdef CONFIG_PAX_RANDMMAP
623 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
624 +#endif
625 +
626 if (addr) {
627 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
628 if (addr != (unsigned long) -ENOMEM)
629 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
630 }
631
632 /* Next, try allocating at TASK_UNMAPPED_BASE. */
633 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
634 - len, limit);
635 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
636 +
637 if (addr != (unsigned long) -ENOMEM)
638 return addr;
639
640 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641 index 5eecab1..609abc0 100644
642 --- a/arch/alpha/mm/fault.c
643 +++ b/arch/alpha/mm/fault.c
644 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648 +#ifdef CONFIG_PAX_PAGEEXEC
649 +/*
650 + * PaX: decide what to do with offenders (regs->pc = fault address)
651 + *
652 + * returns 1 when task should be killed
653 + * 2 when patched PLT trampoline was detected
654 + * 3 when unpatched PLT trampoline was detected
655 + */
656 +static int pax_handle_fetch_fault(struct pt_regs *regs)
657 +{
658 +
659 +#ifdef CONFIG_PAX_EMUPLT
660 + int err;
661 +
662 + do { /* PaX: patched PLT emulation #1 */
663 + unsigned int ldah, ldq, jmp;
664 +
665 + err = get_user(ldah, (unsigned int *)regs->pc);
666 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668 +
669 + if (err)
670 + break;
671 +
672 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674 + jmp == 0x6BFB0000U)
675 + {
676 + unsigned long r27, addr;
677 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679 +
680 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681 + err = get_user(r27, (unsigned long *)addr);
682 + if (err)
683 + break;
684 +
685 + regs->r27 = r27;
686 + regs->pc = r27;
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: patched PLT emulation #2 */
692 + unsigned int ldah, lda, br;
693 +
694 + err = get_user(ldah, (unsigned int *)regs->pc);
695 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
696 + err |= get_user(br, (unsigned int *)(regs->pc+8));
697 +
698 + if (err)
699 + break;
700 +
701 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
703 + (br & 0xFFE00000U) == 0xC3E00000U)
704 + {
705 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708 +
709 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711 + return 2;
712 + }
713 + } while (0);
714 +
715 + do { /* PaX: unpatched PLT emulation */
716 + unsigned int br;
717 +
718 + err = get_user(br, (unsigned int *)regs->pc);
719 +
720 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721 + unsigned int br2, ldq, nop, jmp;
722 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723 +
724 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725 + err = get_user(br2, (unsigned int *)addr);
726 + err |= get_user(ldq, (unsigned int *)(addr+4));
727 + err |= get_user(nop, (unsigned int *)(addr+8));
728 + err |= get_user(jmp, (unsigned int *)(addr+12));
729 + err |= get_user(resolver, (unsigned long *)(addr+16));
730 +
731 + if (err)
732 + break;
733 +
734 + if (br2 == 0xC3600000U &&
735 + ldq == 0xA77B000CU &&
736 + nop == 0x47FF041FU &&
737 + jmp == 0x6B7B0000U)
738 + {
739 + regs->r28 = regs->pc+4;
740 + regs->r27 = addr+16;
741 + regs->pc = resolver;
742 + return 3;
743 + }
744 + }
745 + } while (0);
746 +#endif
747 +
748 + return 1;
749 +}
750 +
751 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752 +{
753 + unsigned long i;
754 +
755 + printk(KERN_ERR "PAX: bytes at PC: ");
756 + for (i = 0; i < 5; i++) {
757 + unsigned int c;
758 + if (get_user(c, (unsigned int *)pc+i))
759 + printk(KERN_CONT "???????? ");
760 + else
761 + printk(KERN_CONT "%08x ", c);
762 + }
763 + printk("\n");
764 +}
765 +#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769 @@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773 - if (!(vma->vm_flags & VM_EXEC))
774 + if (!(vma->vm_flags & VM_EXEC)) {
775 +
776 +#ifdef CONFIG_PAX_PAGEEXEC
777 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778 + goto bad_area;
779 +
780 + up_read(&mm->mmap_sem);
781 + switch (pax_handle_fetch_fault(regs)) {
782 +
783 +#ifdef CONFIG_PAX_EMUPLT
784 + case 2:
785 + case 3:
786 + return;
787 +#endif
788 +
789 + }
790 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791 + do_group_exit(SIGKILL);
792 +#else
793 goto bad_area;
794 +#endif
795 +
796 + }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
801 index c79f61f..9ac0642 100644
802 --- a/arch/arm/include/asm/atomic.h
803 +++ b/arch/arm/include/asm/atomic.h
804 @@ -17,17 +17,35 @@
805 #include <asm/barrier.h>
806 #include <asm/cmpxchg.h>
807
808 +#ifdef CONFIG_GENERIC_ATOMIC64
809 +#include <asm-generic/atomic64.h>
810 +#endif
811 +
812 #define ATOMIC_INIT(i) { (i) }
813
814 #ifdef __KERNEL__
815
816 +#define _ASM_EXTABLE(from, to) \
817 +" .pushsection __ex_table,\"a\"\n"\
818 +" .align 3\n" \
819 +" .long " #from ", " #to"\n" \
820 +" .popsection"
821 +
822 /*
823 * On ARM, ordinary assignment (str instruction) doesn't clear the local
824 * strex/ldrex monitor on some implementations. The reason we can use it for
825 * atomic_set() is the clrex or dummy strex done on every exception return.
826 */
827 #define atomic_read(v) (*(volatile int *)&(v)->counter)
828 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
829 +{
830 + return v->counter;
831 +}
832 #define atomic_set(v,i) (((v)->counter) = (i))
833 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
834 +{
835 + v->counter = i;
836 +}
837
838 #if __LINUX_ARM_ARCH__ >= 6
839
840 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
841 int result;
842
843 __asm__ __volatile__("@ atomic_add\n"
844 +"1: ldrex %1, [%3]\n"
845 +" adds %0, %1, %4\n"
846 +
847 +#ifdef CONFIG_PAX_REFCOUNT
848 +" bvc 3f\n"
849 +"2: bkpt 0xf103\n"
850 +"3:\n"
851 +#endif
852 +
853 +" strex %1, %0, [%3]\n"
854 +" teq %1, #0\n"
855 +" bne 1b"
856 +
857 +#ifdef CONFIG_PAX_REFCOUNT
858 +"\n4:\n"
859 + _ASM_EXTABLE(2b, 4b)
860 +#endif
861 +
862 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
863 + : "r" (&v->counter), "Ir" (i)
864 + : "cc");
865 +}
866 +
867 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
868 +{
869 + unsigned long tmp;
870 + int result;
871 +
872 + __asm__ __volatile__("@ atomic_add_unchecked\n"
873 "1: ldrex %0, [%3]\n"
874 " add %0, %0, %4\n"
875 " strex %1, %0, [%3]\n"
876 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
877 smp_mb();
878
879 __asm__ __volatile__("@ atomic_add_return\n"
880 +"1: ldrex %1, [%3]\n"
881 +" adds %0, %1, %4\n"
882 +
883 +#ifdef CONFIG_PAX_REFCOUNT
884 +" bvc 3f\n"
885 +" mov %0, %1\n"
886 +"2: bkpt 0xf103\n"
887 +"3:\n"
888 +#endif
889 +
890 +" strex %1, %0, [%3]\n"
891 +" teq %1, #0\n"
892 +" bne 1b"
893 +
894 +#ifdef CONFIG_PAX_REFCOUNT
895 +"\n4:\n"
896 + _ASM_EXTABLE(2b, 4b)
897 +#endif
898 +
899 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
900 + : "r" (&v->counter), "Ir" (i)
901 + : "cc");
902 +
903 + smp_mb();
904 +
905 + return result;
906 +}
907 +
908 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
909 +{
910 + unsigned long tmp;
911 + int result;
912 +
913 + smp_mb();
914 +
915 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
916 "1: ldrex %0, [%3]\n"
917 " add %0, %0, %4\n"
918 " strex %1, %0, [%3]\n"
919 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
920 int result;
921
922 __asm__ __volatile__("@ atomic_sub\n"
923 +"1: ldrex %1, [%3]\n"
924 +" subs %0, %1, %4\n"
925 +
926 +#ifdef CONFIG_PAX_REFCOUNT
927 +" bvc 3f\n"
928 +"2: bkpt 0xf103\n"
929 +"3:\n"
930 +#endif
931 +
932 +" strex %1, %0, [%3]\n"
933 +" teq %1, #0\n"
934 +" bne 1b"
935 +
936 +#ifdef CONFIG_PAX_REFCOUNT
937 +"\n4:\n"
938 + _ASM_EXTABLE(2b, 4b)
939 +#endif
940 +
941 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
942 + : "r" (&v->counter), "Ir" (i)
943 + : "cc");
944 +}
945 +
946 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
947 +{
948 + unsigned long tmp;
949 + int result;
950 +
951 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
952 "1: ldrex %0, [%3]\n"
953 " sub %0, %0, %4\n"
954 " strex %1, %0, [%3]\n"
955 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
956 smp_mb();
957
958 __asm__ __volatile__("@ atomic_sub_return\n"
959 -"1: ldrex %0, [%3]\n"
960 -" sub %0, %0, %4\n"
961 +"1: ldrex %1, [%3]\n"
962 +" subs %0, %1, %4\n"
963 +
964 +#ifdef CONFIG_PAX_REFCOUNT
965 +" bvc 3f\n"
966 +" mov %0, %1\n"
967 +"2: bkpt 0xf103\n"
968 +"3:\n"
969 +#endif
970 +
971 " strex %1, %0, [%3]\n"
972 " teq %1, #0\n"
973 " bne 1b"
974 +
975 +#ifdef CONFIG_PAX_REFCOUNT
976 +"\n4:\n"
977 + _ASM_EXTABLE(2b, 4b)
978 +#endif
979 +
980 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
981 : "r" (&v->counter), "Ir" (i)
982 : "cc");
983 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
984 return oldval;
985 }
986
987 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
988 +{
989 + unsigned long oldval, res;
990 +
991 + smp_mb();
992 +
993 + do {
994 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
995 + "ldrex %1, [%3]\n"
996 + "mov %0, #0\n"
997 + "teq %1, %4\n"
998 + "strexeq %0, %5, [%3]\n"
999 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1000 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1001 + : "cc");
1002 + } while (res);
1003 +
1004 + smp_mb();
1005 +
1006 + return oldval;
1007 +}
1008 +
1009 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1010 {
1011 unsigned long tmp, tmp2;
1012 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1013
1014 return val;
1015 }
1016 +
1017 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1018 +{
1019 + return atomic_add_return(i, v);
1020 +}
1021 +
1022 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1023 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1024 +{
1025 + (void) atomic_add_return(i, v);
1026 +}
1027
1028 static inline int atomic_sub_return(int i, atomic_t *v)
1029 {
1030 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1031 return val;
1032 }
1033 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1034 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1035 +{
1036 + (void) atomic_sub_return(i, v);
1037 +}
1038
1039 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1040 {
1041 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1042 return ret;
1043 }
1044
1045 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1046 +{
1047 + return atomic_cmpxchg(v, old, new);
1048 +}
1049 +
1050 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1051 {
1052 unsigned long flags;
1053 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 #endif /* __LINUX_ARM_ARCH__ */
1055
1056 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1057 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1058 +{
1059 + return xchg(&v->counter, new);
1060 +}
1061
1062 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1063 {
1064 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1065 }
1066
1067 #define atomic_inc(v) atomic_add(1, v)
1068 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_add_unchecked(1, v);
1071 +}
1072 #define atomic_dec(v) atomic_sub(1, v)
1073 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1074 +{
1075 + atomic_sub_unchecked(1, v);
1076 +}
1077
1078 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1079 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1080 +{
1081 + return atomic_add_return_unchecked(1, v) == 0;
1082 +}
1083 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1084 #define atomic_inc_return(v) (atomic_add_return(1, v))
1085 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1086 +{
1087 + return atomic_add_return_unchecked(1, v);
1088 +}
1089 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1090 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1091
1092 @@ -241,6 +428,14 @@ typedef struct {
1093 u64 __aligned(8) counter;
1094 } atomic64_t;
1095
1096 +#ifdef CONFIG_PAX_REFCOUNT
1097 +typedef struct {
1098 + u64 __aligned(8) counter;
1099 +} atomic64_unchecked_t;
1100 +#else
1101 +typedef atomic64_t atomic64_unchecked_t;
1102 +#endif
1103 +
1104 #define ATOMIC64_INIT(i) { (i) }
1105
1106 static inline u64 atomic64_read(const atomic64_t *v)
1107 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1108 return result;
1109 }
1110
1111 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1112 +{
1113 + u64 result;
1114 +
1115 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1116 +" ldrexd %0, %H0, [%1]"
1117 + : "=&r" (result)
1118 + : "r" (&v->counter), "Qo" (v->counter)
1119 + );
1120 +
1121 + return result;
1122 +}
1123 +
1124 static inline void atomic64_set(atomic64_t *v, u64 i)
1125 {
1126 u64 tmp;
1127 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1128 : "cc");
1129 }
1130
1131 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1132 +{
1133 + u64 tmp;
1134 +
1135 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1136 +"1: ldrexd %0, %H0, [%2]\n"
1137 +" strexd %0, %3, %H3, [%2]\n"
1138 +" teq %0, #0\n"
1139 +" bne 1b"
1140 + : "=&r" (tmp), "=Qo" (v->counter)
1141 + : "r" (&v->counter), "r" (i)
1142 + : "cc");
1143 +}
1144 +
1145 static inline void atomic64_add(u64 i, atomic64_t *v)
1146 {
1147 u64 result;
1148 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1149 __asm__ __volatile__("@ atomic64_add\n"
1150 "1: ldrexd %0, %H0, [%3]\n"
1151 " adds %0, %0, %4\n"
1152 +" adcs %H0, %H0, %H4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +"2: bkpt 0xf103\n"
1157 +"3:\n"
1158 +#endif
1159 +
1160 +" strexd %1, %0, %H0, [%3]\n"
1161 +" teq %1, #0\n"
1162 +" bne 1b"
1163 +
1164 +#ifdef CONFIG_PAX_REFCOUNT
1165 +"\n4:\n"
1166 + _ASM_EXTABLE(2b, 4b)
1167 +#endif
1168 +
1169 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1170 + : "r" (&v->counter), "r" (i)
1171 + : "cc");
1172 +}
1173 +
1174 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1175 +{
1176 + u64 result;
1177 + unsigned long tmp;
1178 +
1179 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1180 +"1: ldrexd %0, %H0, [%3]\n"
1181 +" adds %0, %0, %4\n"
1182 " adc %H0, %H0, %H4\n"
1183 " strexd %1, %0, %H0, [%3]\n"
1184 " teq %1, #0\n"
1185 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1186
1187 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1188 {
1189 - u64 result;
1190 - unsigned long tmp;
1191 + u64 result, tmp;
1192
1193 smp_mb();
1194
1195 __asm__ __volatile__("@ atomic64_add_return\n"
1196 +"1: ldrexd %1, %H1, [%3]\n"
1197 +" adds %0, %1, %4\n"
1198 +" adcs %H0, %H1, %H4\n"
1199 +
1200 +#ifdef CONFIG_PAX_REFCOUNT
1201 +" bvc 3f\n"
1202 +" mov %0, %1\n"
1203 +" mov %H0, %H1\n"
1204 +"2: bkpt 0xf103\n"
1205 +"3:\n"
1206 +#endif
1207 +
1208 +" strexd %1, %0, %H0, [%3]\n"
1209 +" teq %1, #0\n"
1210 +" bne 1b"
1211 +
1212 +#ifdef CONFIG_PAX_REFCOUNT
1213 +"\n4:\n"
1214 + _ASM_EXTABLE(2b, 4b)
1215 +#endif
1216 +
1217 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1218 + : "r" (&v->counter), "r" (i)
1219 + : "cc");
1220 +
1221 + smp_mb();
1222 +
1223 + return result;
1224 +}
1225 +
1226 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1227 +{
1228 + u64 result;
1229 + unsigned long tmp;
1230 +
1231 + smp_mb();
1232 +
1233 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " adds %0, %0, %4\n"
1236 " adc %H0, %H0, %H4\n"
1237 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1238 __asm__ __volatile__("@ atomic64_sub\n"
1239 "1: ldrexd %0, %H0, [%3]\n"
1240 " subs %0, %0, %4\n"
1241 +" sbcs %H0, %H0, %H4\n"
1242 +
1243 +#ifdef CONFIG_PAX_REFCOUNT
1244 +" bvc 3f\n"
1245 +"2: bkpt 0xf103\n"
1246 +"3:\n"
1247 +#endif
1248 +
1249 +" strexd %1, %0, %H0, [%3]\n"
1250 +" teq %1, #0\n"
1251 +" bne 1b"
1252 +
1253 +#ifdef CONFIG_PAX_REFCOUNT
1254 +"\n4:\n"
1255 + _ASM_EXTABLE(2b, 4b)
1256 +#endif
1257 +
1258 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1259 + : "r" (&v->counter), "r" (i)
1260 + : "cc");
1261 +}
1262 +
1263 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1264 +{
1265 + u64 result;
1266 + unsigned long tmp;
1267 +
1268 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%3]\n"
1270 +" subs %0, %0, %4\n"
1271 " sbc %H0, %H0, %H4\n"
1272 " strexd %1, %0, %H0, [%3]\n"
1273 " teq %1, #0\n"
1274 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1275
1276 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1277 {
1278 - u64 result;
1279 - unsigned long tmp;
1280 + u64 result, tmp;
1281
1282 smp_mb();
1283
1284 __asm__ __volatile__("@ atomic64_sub_return\n"
1285 -"1: ldrexd %0, %H0, [%3]\n"
1286 -" subs %0, %0, %4\n"
1287 -" sbc %H0, %H0, %H4\n"
1288 +"1: ldrexd %1, %H1, [%3]\n"
1289 +" subs %0, %1, %4\n"
1290 +" sbcs %H0, %H1, %H4\n"
1291 +
1292 +#ifdef CONFIG_PAX_REFCOUNT
1293 +" bvc 3f\n"
1294 +" mov %0, %1\n"
1295 +" mov %H0, %H1\n"
1296 +"2: bkpt 0xf103\n"
1297 +"3:\n"
1298 +#endif
1299 +
1300 " strexd %1, %0, %H0, [%3]\n"
1301 " teq %1, #0\n"
1302 " bne 1b"
1303 +
1304 +#ifdef CONFIG_PAX_REFCOUNT
1305 +"\n4:\n"
1306 + _ASM_EXTABLE(2b, 4b)
1307 +#endif
1308 +
1309 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1310 : "r" (&v->counter), "r" (i)
1311 : "cc");
1312 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1313 return oldval;
1314 }
1315
1316 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1317 +{
1318 + u64 oldval;
1319 + unsigned long res;
1320 +
1321 + smp_mb();
1322 +
1323 + do {
1324 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1325 + "ldrexd %1, %H1, [%3]\n"
1326 + "mov %0, #0\n"
1327 + "teq %1, %4\n"
1328 + "teqeq %H1, %H4\n"
1329 + "strexdeq %0, %5, %H5, [%3]"
1330 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1331 + : "r" (&ptr->counter), "r" (old), "r" (new)
1332 + : "cc");
1333 + } while (res);
1334 +
1335 + smp_mb();
1336 +
1337 + return oldval;
1338 +}
1339 +
1340 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1341 {
1342 u64 result;
1343 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1344
1345 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1346 {
1347 - u64 result;
1348 - unsigned long tmp;
1349 + u64 result, tmp;
1350
1351 smp_mb();
1352
1353 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1354 -"1: ldrexd %0, %H0, [%3]\n"
1355 -" subs %0, %0, #1\n"
1356 -" sbc %H0, %H0, #0\n"
1357 +"1: ldrexd %1, %H1, [%3]\n"
1358 +" subs %0, %1, #1\n"
1359 +" sbcs %H0, %H1, #0\n"
1360 +
1361 +#ifdef CONFIG_PAX_REFCOUNT
1362 +" bvc 3f\n"
1363 +" mov %0, %1\n"
1364 +" mov %H0, %H1\n"
1365 +"2: bkpt 0xf103\n"
1366 +"3:\n"
1367 +#endif
1368 +
1369 " teq %H0, #0\n"
1370 -" bmi 2f\n"
1371 +" bmi 4f\n"
1372 " strexd %1, %0, %H0, [%3]\n"
1373 " teq %1, #0\n"
1374 " bne 1b\n"
1375 -"2:"
1376 +"4:\n"
1377 +
1378 +#ifdef CONFIG_PAX_REFCOUNT
1379 + _ASM_EXTABLE(2b, 4b)
1380 +#endif
1381 +
1382 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1383 : "r" (&v->counter)
1384 : "cc");
1385 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1386 " teq %0, %5\n"
1387 " teqeq %H0, %H5\n"
1388 " moveq %1, #0\n"
1389 -" beq 2f\n"
1390 +" beq 4f\n"
1391 " adds %0, %0, %6\n"
1392 -" adc %H0, %H0, %H6\n"
1393 +" adcs %H0, %H0, %H6\n"
1394 +
1395 +#ifdef CONFIG_PAX_REFCOUNT
1396 +" bvc 3f\n"
1397 +"2: bkpt 0xf103\n"
1398 +"3:\n"
1399 +#endif
1400 +
1401 " strexd %2, %0, %H0, [%4]\n"
1402 " teq %2, #0\n"
1403 " bne 1b\n"
1404 -"2:"
1405 +"4:\n"
1406 +
1407 +#ifdef CONFIG_PAX_REFCOUNT
1408 + _ASM_EXTABLE(2b, 4b)
1409 +#endif
1410 +
1411 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1412 : "r" (&v->counter), "r" (u), "r" (a)
1413 : "cc");
1414 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1415
1416 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1417 #define atomic64_inc(v) atomic64_add(1LL, (v))
1418 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1419 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1420 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1421 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1422 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1423 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1424 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1425 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1426 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1427 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1428 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1429 index 75fe66b..2255c86 100644
1430 --- a/arch/arm/include/asm/cache.h
1431 +++ b/arch/arm/include/asm/cache.h
1432 @@ -4,8 +4,10 @@
1433 #ifndef __ASMARM_CACHE_H
1434 #define __ASMARM_CACHE_H
1435
1436 +#include <linux/const.h>
1437 +
1438 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1439 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1440 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1441
1442 /*
1443 * Memory returned by kmalloc() may be used for DMA, so we must make
1444 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1445 index e4448e1..7bc86b7 100644
1446 --- a/arch/arm/include/asm/cacheflush.h
1447 +++ b/arch/arm/include/asm/cacheflush.h
1448 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1449 void (*dma_unmap_area)(const void *, size_t, int);
1450
1451 void (*dma_flush_range)(const void *, const void *);
1452 -};
1453 +} __no_const;
1454
1455 /*
1456 * Select the calling method
1457 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1458 index 7eb18c1..e38b6d2 100644
1459 --- a/arch/arm/include/asm/cmpxchg.h
1460 +++ b/arch/arm/include/asm/cmpxchg.h
1461 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1462
1463 #define xchg(ptr,x) \
1464 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1465 +#define xchg_unchecked(ptr,x) \
1466 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467
1468 #include <asm-generic/cmpxchg-local.h>
1469
1470 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1471 index 38050b1..9d90e8b 100644
1472 --- a/arch/arm/include/asm/elf.h
1473 +++ b/arch/arm/include/asm/elf.h
1474 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1475 the loader. We need to make sure that it is out of the way of the program
1476 that it will "exec", and that there is sufficient room for the brk. */
1477
1478 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1479 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1480 +
1481 +#ifdef CONFIG_PAX_ASLR
1482 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1483 +
1484 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1485 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1486 +#endif
1487
1488 /* When the program starts, a1 contains a pointer to a function to be
1489 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1490 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1491 extern void elf_set_personality(const struct elf32_hdr *);
1492 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1493
1494 -struct mm_struct;
1495 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1496 -#define arch_randomize_brk arch_randomize_brk
1497 -
1498 #endif
1499 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1500 index e51b1e8..32a3113 100644
1501 --- a/arch/arm/include/asm/kmap_types.h
1502 +++ b/arch/arm/include/asm/kmap_types.h
1503 @@ -21,6 +21,7 @@ enum km_type {
1504 KM_L1_CACHE,
1505 KM_L2_CACHE,
1506 KM_KDB,
1507 + KM_CLEARPAGE,
1508 KM_TYPE_NR
1509 };
1510
1511 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1512 index 53426c6..c7baff3 100644
1513 --- a/arch/arm/include/asm/outercache.h
1514 +++ b/arch/arm/include/asm/outercache.h
1515 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1516 #endif
1517 void (*set_debug)(unsigned long);
1518 void (*resume)(void);
1519 -};
1520 +} __no_const;
1521
1522 #ifdef CONFIG_OUTER_CACHE
1523
1524 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1525 index ecf9019..b71d9a1 100644
1526 --- a/arch/arm/include/asm/page.h
1527 +++ b/arch/arm/include/asm/page.h
1528 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1529 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1530 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1531 unsigned long vaddr, struct vm_area_struct *vma);
1532 -};
1533 +} __no_const;
1534
1535 #ifdef MULTI_USER
1536 extern struct cpu_user_fns cpu_user;
1537 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1538 index 943504f..bf8d667 100644
1539 --- a/arch/arm/include/asm/pgalloc.h
1540 +++ b/arch/arm/include/asm/pgalloc.h
1541 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1542 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1543 }
1544
1545 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1546 +{
1547 + pud_populate(mm, pud, pmd);
1548 +}
1549 +
1550 #else /* !CONFIG_ARM_LPAE */
1551
1552 /*
1553 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1554 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1555 #define pmd_free(mm, pmd) do { } while (0)
1556 #define pud_populate(mm,pmd,pte) BUG()
1557 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1558
1559 #endif /* CONFIG_ARM_LPAE */
1560
1561 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1562 index af7b0bd..6750a8c 100644
1563 --- a/arch/arm/include/asm/thread_info.h
1564 +++ b/arch/arm/include/asm/thread_info.h
1565 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1566 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1567 #define TIF_SYSCALL_TRACE 8
1568 #define TIF_SYSCALL_AUDIT 9
1569 +
1570 +/* within 8 bits of TIF_SYSCALL_TRACE
1571 + to meet flexible second operand requirements
1572 +*/
1573 +#define TIF_GRSEC_SETXID 10
1574 +
1575 #define TIF_POLLING_NRFLAG 16
1576 #define TIF_USING_IWMMXT 17
1577 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1578 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1579 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1580 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1581 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1582 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1583
1584 /* Checks for any syscall work in entry-common.S */
1585 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1586 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1587 + _TIF_GRSEC_SETXID)
1588
1589 /*
1590 * Change these and you break ASM code in entry-common.S
1591 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1592 index 71f6536..602f279 100644
1593 --- a/arch/arm/include/asm/uaccess.h
1594 +++ b/arch/arm/include/asm/uaccess.h
1595 @@ -22,6 +22,8 @@
1596 #define VERIFY_READ 0
1597 #define VERIFY_WRITE 1
1598
1599 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1600 +
1601 /*
1602 * The exception table consists of pairs of addresses: the first is the
1603 * address of an instruction that is allowed to fault, and the second is
1604 @@ -387,8 +389,23 @@ do { \
1605
1606
1607 #ifdef CONFIG_MMU
1608 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1609 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1610 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1611 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1612 +
1613 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1614 +{
1615 + if (!__builtin_constant_p(n))
1616 + check_object_size(to, n, false);
1617 + return ___copy_from_user(to, from, n);
1618 +}
1619 +
1620 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1621 +{
1622 + if (!__builtin_constant_p(n))
1623 + check_object_size(from, n, true);
1624 + return ___copy_to_user(to, from, n);
1625 +}
1626 +
1627 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1628 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1629 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1630 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1631
1632 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1633 {
1634 + if ((long)n < 0)
1635 + return n;
1636 +
1637 if (access_ok(VERIFY_READ, from, n))
1638 n = __copy_from_user(to, from, n);
1639 else /* security hole - plug it */
1640 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1641
1642 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1643 {
1644 + if ((long)n < 0)
1645 + return n;
1646 +
1647 if (access_ok(VERIFY_WRITE, to, n))
1648 n = __copy_to_user(to, from, n);
1649 return n;
1650 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1651 index b57c75e..ed2d6b2 100644
1652 --- a/arch/arm/kernel/armksyms.c
1653 +++ b/arch/arm/kernel/armksyms.c
1654 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1655 #ifdef CONFIG_MMU
1656 EXPORT_SYMBOL(copy_page);
1657
1658 -EXPORT_SYMBOL(__copy_from_user);
1659 -EXPORT_SYMBOL(__copy_to_user);
1660 +EXPORT_SYMBOL(___copy_from_user);
1661 +EXPORT_SYMBOL(___copy_to_user);
1662 EXPORT_SYMBOL(__clear_user);
1663
1664 EXPORT_SYMBOL(__get_user_1);
1665 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1666 index 693b744..e684262 100644
1667 --- a/arch/arm/kernel/process.c
1668 +++ b/arch/arm/kernel/process.c
1669 @@ -28,7 +28,6 @@
1670 #include <linux/tick.h>
1671 #include <linux/utsname.h>
1672 #include <linux/uaccess.h>
1673 -#include <linux/random.h>
1674 #include <linux/hw_breakpoint.h>
1675 #include <linux/cpuidle.h>
1676
1677 @@ -256,9 +255,10 @@ void machine_power_off(void)
1678 machine_shutdown();
1679 if (pm_power_off)
1680 pm_power_off();
1681 + BUG();
1682 }
1683
1684 -void machine_restart(char *cmd)
1685 +__noreturn void machine_restart(char *cmd)
1686 {
1687 machine_shutdown();
1688
1689 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1690 return 0;
1691 }
1692
1693 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1694 -{
1695 - unsigned long range_end = mm->brk + 0x02000000;
1696 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1697 -}
1698 -
1699 #ifdef CONFIG_MMU
1700 /*
1701 * The vectors page is always readable from user space for the
1702 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1703 index 14e3826..d832d89 100644
1704 --- a/arch/arm/kernel/ptrace.c
1705 +++ b/arch/arm/kernel/ptrace.c
1706 @@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1707 return ret;
1708 }
1709
1710 +#ifdef CONFIG_GRKERNSEC_SETXID
1711 +extern void gr_delayed_cred_worker(void);
1712 +#endif
1713 +
1714 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1715 {
1716 unsigned long ip;
1717
1718 +#ifdef CONFIG_GRKERNSEC_SETXID
1719 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1720 + gr_delayed_cred_worker();
1721 +#endif
1722 +
1723 if (why)
1724 audit_syscall_exit(regs);
1725 else
1726 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1727 index e15d83b..8c466dd 100644
1728 --- a/arch/arm/kernel/setup.c
1729 +++ b/arch/arm/kernel/setup.c
1730 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1731 struct cpu_tlb_fns cpu_tlb __read_mostly;
1732 #endif
1733 #ifdef MULTI_USER
1734 -struct cpu_user_fns cpu_user __read_mostly;
1735 +struct cpu_user_fns cpu_user __read_only;
1736 #endif
1737 #ifdef MULTI_CACHE
1738 -struct cpu_cache_fns cpu_cache __read_mostly;
1739 +struct cpu_cache_fns cpu_cache __read_only;
1740 #endif
1741 #ifdef CONFIG_OUTER_CACHE
1742 -struct outer_cache_fns outer_cache __read_mostly;
1743 +struct outer_cache_fns outer_cache __read_only;
1744 EXPORT_SYMBOL(outer_cache);
1745 #endif
1746
1747 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1748 index c7cae6b..e1e523c 100644
1749 --- a/arch/arm/kernel/traps.c
1750 +++ b/arch/arm/kernel/traps.c
1751 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1752
1753 static DEFINE_RAW_SPINLOCK(die_lock);
1754
1755 +extern void gr_handle_kernel_exploit(void);
1756 +
1757 /*
1758 * This function is protected against re-entrancy.
1759 */
1760 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1761 panic("Fatal exception in interrupt");
1762 if (panic_on_oops)
1763 panic("Fatal exception");
1764 +
1765 + gr_handle_kernel_exploit();
1766 +
1767 if (ret != NOTIFY_STOP)
1768 do_exit(SIGSEGV);
1769 }
1770 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1771 index 66a477a..bee61d3 100644
1772 --- a/arch/arm/lib/copy_from_user.S
1773 +++ b/arch/arm/lib/copy_from_user.S
1774 @@ -16,7 +16,7 @@
1775 /*
1776 * Prototype:
1777 *
1778 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1779 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1780 *
1781 * Purpose:
1782 *
1783 @@ -84,11 +84,11 @@
1784
1785 .text
1786
1787 -ENTRY(__copy_from_user)
1788 +ENTRY(___copy_from_user)
1789
1790 #include "copy_template.S"
1791
1792 -ENDPROC(__copy_from_user)
1793 +ENDPROC(___copy_from_user)
1794
1795 .pushsection .fixup,"ax"
1796 .align 0
1797 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1798 index 6ee2f67..d1cce76 100644
1799 --- a/arch/arm/lib/copy_page.S
1800 +++ b/arch/arm/lib/copy_page.S
1801 @@ -10,6 +10,7 @@
1802 * ASM optimised string functions
1803 */
1804 #include <linux/linkage.h>
1805 +#include <linux/const.h>
1806 #include <asm/assembler.h>
1807 #include <asm/asm-offsets.h>
1808 #include <asm/cache.h>
1809 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1810 index d066df6..df28194 100644
1811 --- a/arch/arm/lib/copy_to_user.S
1812 +++ b/arch/arm/lib/copy_to_user.S
1813 @@ -16,7 +16,7 @@
1814 /*
1815 * Prototype:
1816 *
1817 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1818 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1819 *
1820 * Purpose:
1821 *
1822 @@ -88,11 +88,11 @@
1823 .text
1824
1825 ENTRY(__copy_to_user_std)
1826 -WEAK(__copy_to_user)
1827 +WEAK(___copy_to_user)
1828
1829 #include "copy_template.S"
1830
1831 -ENDPROC(__copy_to_user)
1832 +ENDPROC(___copy_to_user)
1833 ENDPROC(__copy_to_user_std)
1834
1835 .pushsection .fixup,"ax"
1836 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1837 index 025f742..8432b08 100644
1838 --- a/arch/arm/lib/uaccess_with_memcpy.c
1839 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1840 @@ -104,7 +104,7 @@ out:
1841 }
1842
1843 unsigned long
1844 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1845 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1846 {
1847 /*
1848 * This test is stubbed out of the main function above to keep
1849 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1850 index f261cd2..4ae63fb 100644
1851 --- a/arch/arm/mach-kirkwood/common.c
1852 +++ b/arch/arm/mach-kirkwood/common.c
1853 @@ -128,7 +128,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1854 clk_gate_ops.disable(hw);
1855 }
1856
1857 -static struct clk_ops clk_gate_fn_ops;
1858 +static clk_ops_no_const clk_gate_fn_ops;
1859
1860 static struct clk __init *clk_register_gate_fn(struct device *dev,
1861 const char *name,
1862 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1863 index 2c5d0ed..7d9099c 100644
1864 --- a/arch/arm/mach-omap2/board-n8x0.c
1865 +++ b/arch/arm/mach-omap2/board-n8x0.c
1866 @@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1867 }
1868 #endif
1869
1870 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1871 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1872 .late_init = n8x0_menelaus_late_init,
1873 };
1874
1875 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1876 index c3bd834..e81ef02 100644
1877 --- a/arch/arm/mm/fault.c
1878 +++ b/arch/arm/mm/fault.c
1879 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1880 }
1881 #endif
1882
1883 +#ifdef CONFIG_PAX_PAGEEXEC
1884 + if (fsr & FSR_LNX_PF) {
1885 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1886 + do_group_exit(SIGKILL);
1887 + }
1888 +#endif
1889 +
1890 tsk->thread.address = addr;
1891 tsk->thread.error_code = fsr;
1892 tsk->thread.trap_no = 14;
1893 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1894 }
1895 #endif /* CONFIG_MMU */
1896
1897 +#ifdef CONFIG_PAX_PAGEEXEC
1898 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1899 +{
1900 + long i;
1901 +
1902 + printk(KERN_ERR "PAX: bytes at PC: ");
1903 + for (i = 0; i < 20; i++) {
1904 + unsigned char c;
1905 + if (get_user(c, (__force unsigned char __user *)pc+i))
1906 + printk(KERN_CONT "?? ");
1907 + else
1908 + printk(KERN_CONT "%02x ", c);
1909 + }
1910 + printk("\n");
1911 +
1912 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1913 + for (i = -1; i < 20; i++) {
1914 + unsigned long c;
1915 + if (get_user(c, (__force unsigned long __user *)sp+i))
1916 + printk(KERN_CONT "???????? ");
1917 + else
1918 + printk(KERN_CONT "%08lx ", c);
1919 + }
1920 + printk("\n");
1921 +}
1922 +#endif
1923 +
1924 /*
1925 * First Level Translation Fault Handler
1926 *
1927 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1928 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1929 struct siginfo info;
1930
1931 +#ifdef CONFIG_PAX_REFCOUNT
1932 + if (fsr_fs(ifsr) == 2) {
1933 + unsigned int bkpt;
1934 +
1935 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1936 + current->thread.error_code = ifsr;
1937 + current->thread.trap_no = 0;
1938 + pax_report_refcount_overflow(regs);
1939 + fixup_exception(regs);
1940 + return;
1941 + }
1942 + }
1943 +#endif
1944 +
1945 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1946 return;
1947
1948 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1949 index ce8cb19..3ec539d 100644
1950 --- a/arch/arm/mm/mmap.c
1951 +++ b/arch/arm/mm/mmap.c
1952 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1953 if (len > TASK_SIZE)
1954 return -ENOMEM;
1955
1956 +#ifdef CONFIG_PAX_RANDMMAP
1957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1958 +#endif
1959 +
1960 if (addr) {
1961 if (do_align)
1962 addr = COLOUR_ALIGN(addr, pgoff);
1963 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1964 addr = PAGE_ALIGN(addr);
1965
1966 vma = find_vma(mm, addr);
1967 - if (TASK_SIZE - len >= addr &&
1968 - (!vma || addr + len <= vma->vm_start))
1969 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1970 return addr;
1971 }
1972 if (len > mm->cached_hole_size) {
1973 - start_addr = addr = mm->free_area_cache;
1974 + start_addr = addr = mm->free_area_cache;
1975 } else {
1976 - start_addr = addr = mm->mmap_base;
1977 - mm->cached_hole_size = 0;
1978 + start_addr = addr = mm->mmap_base;
1979 + mm->cached_hole_size = 0;
1980 }
1981
1982 full_search:
1983 @@ -124,14 +127,14 @@ full_search:
1984 * Start a new search - just in case we missed
1985 * some holes.
1986 */
1987 - if (start_addr != TASK_UNMAPPED_BASE) {
1988 - start_addr = addr = TASK_UNMAPPED_BASE;
1989 + if (start_addr != mm->mmap_base) {
1990 + start_addr = addr = mm->mmap_base;
1991 mm->cached_hole_size = 0;
1992 goto full_search;
1993 }
1994 return -ENOMEM;
1995 }
1996 - if (!vma || addr + len <= vma->vm_start) {
1997 + if (check_heap_stack_gap(vma, addr, len)) {
1998 /*
1999 * Remember the place where we stopped the search:
2000 */
2001 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2002
2003 if (mmap_is_legacy()) {
2004 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2005 +
2006 +#ifdef CONFIG_PAX_RANDMMAP
2007 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2008 + mm->mmap_base += mm->delta_mmap;
2009 +#endif
2010 +
2011 mm->get_unmapped_area = arch_get_unmapped_area;
2012 mm->unmap_area = arch_unmap_area;
2013 } else {
2014 mm->mmap_base = mmap_base(random_factor);
2015 +
2016 +#ifdef CONFIG_PAX_RANDMMAP
2017 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2018 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2019 +#endif
2020 +
2021 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2022 mm->unmap_area = arch_unmap_area_topdown;
2023 }
2024 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2025 index fd556f7..af2e7d2 100644
2026 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2027 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2028 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2029 value in bridge_virt_base */
2030 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2031 const int win);
2032 -};
2033 +} __no_const;
2034
2035 /*
2036 * Information needed to setup one address mapping.
2037 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2038 index 71a6827..e7fbc23 100644
2039 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2040 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2041 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2042 int (*started)(unsigned ch);
2043 int (*flush)(unsigned ch);
2044 int (*stop)(unsigned ch);
2045 -};
2046 +} __no_const;
2047
2048 extern void *samsung_dmadev_get_ops(void);
2049 extern void *s3c_dma_get_ops(void);
2050 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2051 index 5f28cae..3d23723 100644
2052 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2053 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2054 @@ -14,7 +14,7 @@
2055 struct s5p_ehci_platdata {
2056 int (*phy_init)(struct platform_device *pdev, int type);
2057 int (*phy_exit)(struct platform_device *pdev, int type);
2058 -};
2059 +} __no_const;
2060
2061 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2062
2063 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2064 index c3a58a1..78fbf54 100644
2065 --- a/arch/avr32/include/asm/cache.h
2066 +++ b/arch/avr32/include/asm/cache.h
2067 @@ -1,8 +1,10 @@
2068 #ifndef __ASM_AVR32_CACHE_H
2069 #define __ASM_AVR32_CACHE_H
2070
2071 +#include <linux/const.h>
2072 +
2073 #define L1_CACHE_SHIFT 5
2074 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2075 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2076
2077 /*
2078 * Memory returned by kmalloc() may be used for DMA, so we must make
2079 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2080 index 3b3159b..425ea94 100644
2081 --- a/arch/avr32/include/asm/elf.h
2082 +++ b/arch/avr32/include/asm/elf.h
2083 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2084 the loader. We need to make sure that it is out of the way of the program
2085 that it will "exec", and that there is sufficient room for the brk. */
2086
2087 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2088 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2089
2090 +#ifdef CONFIG_PAX_ASLR
2091 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2092 +
2093 +#define PAX_DELTA_MMAP_LEN 15
2094 +#define PAX_DELTA_STACK_LEN 15
2095 +#endif
2096
2097 /* This yields a mask that user programs can use to figure out what
2098 instruction set this CPU supports. This could be done in user space,
2099 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2100 index b7f5c68..556135c 100644
2101 --- a/arch/avr32/include/asm/kmap_types.h
2102 +++ b/arch/avr32/include/asm/kmap_types.h
2103 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2104 D(11) KM_IRQ1,
2105 D(12) KM_SOFTIRQ0,
2106 D(13) KM_SOFTIRQ1,
2107 -D(14) KM_TYPE_NR
2108 +D(14) KM_CLEARPAGE,
2109 +D(15) KM_TYPE_NR
2110 };
2111
2112 #undef D
2113 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2114 index f7040a1..db9f300 100644
2115 --- a/arch/avr32/mm/fault.c
2116 +++ b/arch/avr32/mm/fault.c
2117 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2118
2119 int exception_trace = 1;
2120
2121 +#ifdef CONFIG_PAX_PAGEEXEC
2122 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2123 +{
2124 + unsigned long i;
2125 +
2126 + printk(KERN_ERR "PAX: bytes at PC: ");
2127 + for (i = 0; i < 20; i++) {
2128 + unsigned char c;
2129 + if (get_user(c, (unsigned char *)pc+i))
2130 + printk(KERN_CONT "???????? ");
2131 + else
2132 + printk(KERN_CONT "%02x ", c);
2133 + }
2134 + printk("\n");
2135 +}
2136 +#endif
2137 +
2138 /*
2139 * This routine handles page faults. It determines the address and the
2140 * problem, and then passes it off to one of the appropriate routines.
2141 @@ -156,6 +173,16 @@ bad_area:
2142 up_read(&mm->mmap_sem);
2143
2144 if (user_mode(regs)) {
2145 +
2146 +#ifdef CONFIG_PAX_PAGEEXEC
2147 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2148 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2149 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2150 + do_group_exit(SIGKILL);
2151 + }
2152 + }
2153 +#endif
2154 +
2155 if (exception_trace && printk_ratelimit())
2156 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2157 "sp %08lx ecr %lu\n",
2158 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2159 index 568885a..f8008df 100644
2160 --- a/arch/blackfin/include/asm/cache.h
2161 +++ b/arch/blackfin/include/asm/cache.h
2162 @@ -7,6 +7,7 @@
2163 #ifndef __ARCH_BLACKFIN_CACHE_H
2164 #define __ARCH_BLACKFIN_CACHE_H
2165
2166 +#include <linux/const.h>
2167 #include <linux/linkage.h> /* for asmlinkage */
2168
2169 /*
2170 @@ -14,7 +15,7 @@
2171 * Blackfin loads 32 bytes for cache
2172 */
2173 #define L1_CACHE_SHIFT 5
2174 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2175 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2176 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2177
2178 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2179 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2180 index aea2718..3639a60 100644
2181 --- a/arch/cris/include/arch-v10/arch/cache.h
2182 +++ b/arch/cris/include/arch-v10/arch/cache.h
2183 @@ -1,8 +1,9 @@
2184 #ifndef _ASM_ARCH_CACHE_H
2185 #define _ASM_ARCH_CACHE_H
2186
2187 +#include <linux/const.h>
2188 /* Etrax 100LX have 32-byte cache-lines. */
2189 -#define L1_CACHE_BYTES 32
2190 #define L1_CACHE_SHIFT 5
2191 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2192
2193 #endif /* _ASM_ARCH_CACHE_H */
2194 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2195 index 7caf25d..ee65ac5 100644
2196 --- a/arch/cris/include/arch-v32/arch/cache.h
2197 +++ b/arch/cris/include/arch-v32/arch/cache.h
2198 @@ -1,11 +1,12 @@
2199 #ifndef _ASM_CRIS_ARCH_CACHE_H
2200 #define _ASM_CRIS_ARCH_CACHE_H
2201
2202 +#include <linux/const.h>
2203 #include <arch/hwregs/dma.h>
2204
2205 /* A cache-line is 32 bytes. */
2206 -#define L1_CACHE_BYTES 32
2207 #define L1_CACHE_SHIFT 5
2208 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2209
2210 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2211
2212 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2213 index b86329d..6709906 100644
2214 --- a/arch/frv/include/asm/atomic.h
2215 +++ b/arch/frv/include/asm/atomic.h
2216 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2217 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2218 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2219
2220 +#define atomic64_read_unchecked(v) atomic64_read(v)
2221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2229 +
2230 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2231 {
2232 int c, old;
2233 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2234 index 2797163..c2a401d 100644
2235 --- a/arch/frv/include/asm/cache.h
2236 +++ b/arch/frv/include/asm/cache.h
2237 @@ -12,10 +12,11 @@
2238 #ifndef __ASM_CACHE_H
2239 #define __ASM_CACHE_H
2240
2241 +#include <linux/const.h>
2242
2243 /* bytes per L1 cache line */
2244 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2245 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2246 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2247
2248 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2249 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2250 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2251 index f8e16b2..c73ff79 100644
2252 --- a/arch/frv/include/asm/kmap_types.h
2253 +++ b/arch/frv/include/asm/kmap_types.h
2254 @@ -23,6 +23,7 @@ enum km_type {
2255 KM_IRQ1,
2256 KM_SOFTIRQ0,
2257 KM_SOFTIRQ1,
2258 + KM_CLEARPAGE,
2259 KM_TYPE_NR
2260 };
2261
2262 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2263 index 385fd30..6c3d97e 100644
2264 --- a/arch/frv/mm/elf-fdpic.c
2265 +++ b/arch/frv/mm/elf-fdpic.c
2266 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2267 if (addr) {
2268 addr = PAGE_ALIGN(addr);
2269 vma = find_vma(current->mm, addr);
2270 - if (TASK_SIZE - len >= addr &&
2271 - (!vma || addr + len <= vma->vm_start))
2272 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2273 goto success;
2274 }
2275
2276 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2277 for (; vma; vma = vma->vm_next) {
2278 if (addr > limit)
2279 break;
2280 - if (addr + len <= vma->vm_start)
2281 + if (check_heap_stack_gap(vma, addr, len))
2282 goto success;
2283 addr = vma->vm_end;
2284 }
2285 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2286 for (; vma; vma = vma->vm_next) {
2287 if (addr > limit)
2288 break;
2289 - if (addr + len <= vma->vm_start)
2290 + if (check_heap_stack_gap(vma, addr, len))
2291 goto success;
2292 addr = vma->vm_end;
2293 }
2294 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2295 index c635028..6d9445a 100644
2296 --- a/arch/h8300/include/asm/cache.h
2297 +++ b/arch/h8300/include/asm/cache.h
2298 @@ -1,8 +1,10 @@
2299 #ifndef __ARCH_H8300_CACHE_H
2300 #define __ARCH_H8300_CACHE_H
2301
2302 +#include <linux/const.h>
2303 +
2304 /* bytes per L1 cache line */
2305 -#define L1_CACHE_BYTES 4
2306 +#define L1_CACHE_BYTES _AC(4,UL)
2307
2308 /* m68k-elf-gcc 2.95.2 doesn't like these */
2309
2310 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2311 index 0f01de2..d37d309 100644
2312 --- a/arch/hexagon/include/asm/cache.h
2313 +++ b/arch/hexagon/include/asm/cache.h
2314 @@ -21,9 +21,11 @@
2315 #ifndef __ASM_CACHE_H
2316 #define __ASM_CACHE_H
2317
2318 +#include <linux/const.h>
2319 +
2320 /* Bytes per L1 cache line */
2321 -#define L1_CACHE_SHIFT (5)
2322 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2323 +#define L1_CACHE_SHIFT 5
2324 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2325
2326 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2327 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2328 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2329 index 6e6fe18..a6ae668 100644
2330 --- a/arch/ia64/include/asm/atomic.h
2331 +++ b/arch/ia64/include/asm/atomic.h
2332 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2333 #define atomic64_inc(v) atomic64_add(1, (v))
2334 #define atomic64_dec(v) atomic64_sub(1, (v))
2335
2336 +#define atomic64_read_unchecked(v) atomic64_read(v)
2337 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2338 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2339 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2340 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2341 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2342 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2343 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2344 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2345 +
2346 /* Atomic operations are already serializing */
2347 #define smp_mb__before_atomic_dec() barrier()
2348 #define smp_mb__after_atomic_dec() barrier()
2349 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2350 index 988254a..e1ee885 100644
2351 --- a/arch/ia64/include/asm/cache.h
2352 +++ b/arch/ia64/include/asm/cache.h
2353 @@ -1,6 +1,7 @@
2354 #ifndef _ASM_IA64_CACHE_H
2355 #define _ASM_IA64_CACHE_H
2356
2357 +#include <linux/const.h>
2358
2359 /*
2360 * Copyright (C) 1998-2000 Hewlett-Packard Co
2361 @@ -9,7 +10,7 @@
2362
2363 /* Bytes per L1 (data) cache line. */
2364 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2365 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2366 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2367
2368 #ifdef CONFIG_SMP
2369 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2370 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2371 index b5298eb..67c6e62 100644
2372 --- a/arch/ia64/include/asm/elf.h
2373 +++ b/arch/ia64/include/asm/elf.h
2374 @@ -42,6 +42,13 @@
2375 */
2376 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2377
2378 +#ifdef CONFIG_PAX_ASLR
2379 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2380 +
2381 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2382 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2383 +#endif
2384 +
2385 #define PT_IA_64_UNWIND 0x70000001
2386
2387 /* IA-64 relocations: */
2388 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2389 index 96a8d92..617a1cf 100644
2390 --- a/arch/ia64/include/asm/pgalloc.h
2391 +++ b/arch/ia64/include/asm/pgalloc.h
2392 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2393 pgd_val(*pgd_entry) = __pa(pud);
2394 }
2395
2396 +static inline void
2397 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2398 +{
2399 + pgd_populate(mm, pgd_entry, pud);
2400 +}
2401 +
2402 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2403 {
2404 return quicklist_alloc(0, GFP_KERNEL, NULL);
2405 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2406 pud_val(*pud_entry) = __pa(pmd);
2407 }
2408
2409 +static inline void
2410 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2411 +{
2412 + pud_populate(mm, pud_entry, pmd);
2413 +}
2414 +
2415 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2416 {
2417 return quicklist_alloc(0, GFP_KERNEL, NULL);
2418 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2419 index 815810c..d60bd4c 100644
2420 --- a/arch/ia64/include/asm/pgtable.h
2421 +++ b/arch/ia64/include/asm/pgtable.h
2422 @@ -12,7 +12,7 @@
2423 * David Mosberger-Tang <davidm@hpl.hp.com>
2424 */
2425
2426 -
2427 +#include <linux/const.h>
2428 #include <asm/mman.h>
2429 #include <asm/page.h>
2430 #include <asm/processor.h>
2431 @@ -142,6 +142,17 @@
2432 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2434 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2435 +
2436 +#ifdef CONFIG_PAX_PAGEEXEC
2437 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2438 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2439 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2440 +#else
2441 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2442 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2443 +# define PAGE_COPY_NOEXEC PAGE_COPY
2444 +#endif
2445 +
2446 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2447 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2448 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2449 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2450 index 54ff557..70c88b7 100644
2451 --- a/arch/ia64/include/asm/spinlock.h
2452 +++ b/arch/ia64/include/asm/spinlock.h
2453 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2454 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2455
2456 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2457 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2458 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2459 }
2460
2461 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2462 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2463 index 449c8c0..432a3d2 100644
2464 --- a/arch/ia64/include/asm/uaccess.h
2465 +++ b/arch/ia64/include/asm/uaccess.h
2466 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2467 const void *__cu_from = (from); \
2468 long __cu_len = (n); \
2469 \
2470 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2471 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2472 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2473 __cu_len; \
2474 })
2475 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2476 long __cu_len = (n); \
2477 \
2478 __chk_user_ptr(__cu_from); \
2479 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2480 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2481 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2482 __cu_len; \
2483 })
2484 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2485 index 24603be..948052d 100644
2486 --- a/arch/ia64/kernel/module.c
2487 +++ b/arch/ia64/kernel/module.c
2488 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2489 void
2490 module_free (struct module *mod, void *module_region)
2491 {
2492 - if (mod && mod->arch.init_unw_table &&
2493 - module_region == mod->module_init) {
2494 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2495 unw_remove_unwind_table(mod->arch.init_unw_table);
2496 mod->arch.init_unw_table = NULL;
2497 }
2498 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2499 }
2500
2501 static inline int
2502 +in_init_rx (const struct module *mod, uint64_t addr)
2503 +{
2504 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2505 +}
2506 +
2507 +static inline int
2508 +in_init_rw (const struct module *mod, uint64_t addr)
2509 +{
2510 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2511 +}
2512 +
2513 +static inline int
2514 in_init (const struct module *mod, uint64_t addr)
2515 {
2516 - return addr - (uint64_t) mod->module_init < mod->init_size;
2517 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2518 +}
2519 +
2520 +static inline int
2521 +in_core_rx (const struct module *mod, uint64_t addr)
2522 +{
2523 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2524 +}
2525 +
2526 +static inline int
2527 +in_core_rw (const struct module *mod, uint64_t addr)
2528 +{
2529 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2530 }
2531
2532 static inline int
2533 in_core (const struct module *mod, uint64_t addr)
2534 {
2535 - return addr - (uint64_t) mod->module_core < mod->core_size;
2536 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2537 }
2538
2539 static inline int
2540 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2541 break;
2542
2543 case RV_BDREL:
2544 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2545 + if (in_init_rx(mod, val))
2546 + val -= (uint64_t) mod->module_init_rx;
2547 + else if (in_init_rw(mod, val))
2548 + val -= (uint64_t) mod->module_init_rw;
2549 + else if (in_core_rx(mod, val))
2550 + val -= (uint64_t) mod->module_core_rx;
2551 + else if (in_core_rw(mod, val))
2552 + val -= (uint64_t) mod->module_core_rw;
2553 break;
2554
2555 case RV_LTV:
2556 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2557 * addresses have been selected...
2558 */
2559 uint64_t gp;
2560 - if (mod->core_size > MAX_LTOFF)
2561 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2562 /*
2563 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2564 * at the end of the module.
2565 */
2566 - gp = mod->core_size - MAX_LTOFF / 2;
2567 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2568 else
2569 - gp = mod->core_size / 2;
2570 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2571 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2572 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2573 mod->arch.gp = gp;
2574 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2575 }
2576 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2577 index d9439ef..b9a4303 100644
2578 --- a/arch/ia64/kernel/sys_ia64.c
2579 +++ b/arch/ia64/kernel/sys_ia64.c
2580 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2581 if (REGION_NUMBER(addr) == RGN_HPAGE)
2582 addr = 0;
2583 #endif
2584 +
2585 +#ifdef CONFIG_PAX_RANDMMAP
2586 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2587 + addr = mm->free_area_cache;
2588 + else
2589 +#endif
2590 +
2591 if (!addr)
2592 addr = mm->free_area_cache;
2593
2594 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2595 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2596 /* At this point: (!vma || addr < vma->vm_end). */
2597 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2598 - if (start_addr != TASK_UNMAPPED_BASE) {
2599 + if (start_addr != mm->mmap_base) {
2600 /* Start a new search --- just in case we missed some holes. */
2601 - addr = TASK_UNMAPPED_BASE;
2602 + addr = mm->mmap_base;
2603 goto full_search;
2604 }
2605 return -ENOMEM;
2606 }
2607 - if (!vma || addr + len <= vma->vm_start) {
2608 + if (check_heap_stack_gap(vma, addr, len)) {
2609 /* Remember the address where we stopped this search: */
2610 mm->free_area_cache = addr + len;
2611 return addr;
2612 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2613 index 0ccb28f..8992469 100644
2614 --- a/arch/ia64/kernel/vmlinux.lds.S
2615 +++ b/arch/ia64/kernel/vmlinux.lds.S
2616 @@ -198,7 +198,7 @@ SECTIONS {
2617 /* Per-cpu data: */
2618 . = ALIGN(PERCPU_PAGE_SIZE);
2619 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2620 - __phys_per_cpu_start = __per_cpu_load;
2621 + __phys_per_cpu_start = per_cpu_load;
2622 /*
2623 * ensure percpu data fits
2624 * into percpu page size
2625 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2626 index 02d29c2..ea893df 100644
2627 --- a/arch/ia64/mm/fault.c
2628 +++ b/arch/ia64/mm/fault.c
2629 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2630 return pte_present(pte);
2631 }
2632
2633 +#ifdef CONFIG_PAX_PAGEEXEC
2634 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2635 +{
2636 + unsigned long i;
2637 +
2638 + printk(KERN_ERR "PAX: bytes at PC: ");
2639 + for (i = 0; i < 8; i++) {
2640 + unsigned int c;
2641 + if (get_user(c, (unsigned int *)pc+i))
2642 + printk(KERN_CONT "???????? ");
2643 + else
2644 + printk(KERN_CONT "%08x ", c);
2645 + }
2646 + printk("\n");
2647 +}
2648 +#endif
2649 +
2650 void __kprobes
2651 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2652 {
2653 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2654 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2655 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2656
2657 - if ((vma->vm_flags & mask) != mask)
2658 + if ((vma->vm_flags & mask) != mask) {
2659 +
2660 +#ifdef CONFIG_PAX_PAGEEXEC
2661 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2662 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2663 + goto bad_area;
2664 +
2665 + up_read(&mm->mmap_sem);
2666 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2667 + do_group_exit(SIGKILL);
2668 + }
2669 +#endif
2670 +
2671 goto bad_area;
2672
2673 + }
2674 +
2675 /*
2676 * If for any reason at all we couldn't handle the fault, make
2677 * sure we exit gracefully rather than endlessly redo the
2678 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2679 index 5ca674b..e0e1b70 100644
2680 --- a/arch/ia64/mm/hugetlbpage.c
2681 +++ b/arch/ia64/mm/hugetlbpage.c
2682 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2683 /* At this point: (!vmm || addr < vmm->vm_end). */
2684 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2685 return -ENOMEM;
2686 - if (!vmm || (addr + len) <= vmm->vm_start)
2687 + if (check_heap_stack_gap(vmm, addr, len))
2688 return addr;
2689 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2690 }
2691 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2692 index 0eab454..bd794f2 100644
2693 --- a/arch/ia64/mm/init.c
2694 +++ b/arch/ia64/mm/init.c
2695 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2696 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2697 vma->vm_end = vma->vm_start + PAGE_SIZE;
2698 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2699 +
2700 +#ifdef CONFIG_PAX_PAGEEXEC
2701 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2702 + vma->vm_flags &= ~VM_EXEC;
2703 +
2704 +#ifdef CONFIG_PAX_MPROTECT
2705 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2706 + vma->vm_flags &= ~VM_MAYEXEC;
2707 +#endif
2708 +
2709 + }
2710 +#endif
2711 +
2712 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2713 down_write(&current->mm->mmap_sem);
2714 if (insert_vm_struct(current->mm, vma)) {
2715 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2716 index 40b3ee9..8c2c112 100644
2717 --- a/arch/m32r/include/asm/cache.h
2718 +++ b/arch/m32r/include/asm/cache.h
2719 @@ -1,8 +1,10 @@
2720 #ifndef _ASM_M32R_CACHE_H
2721 #define _ASM_M32R_CACHE_H
2722
2723 +#include <linux/const.h>
2724 +
2725 /* L1 cache line size */
2726 #define L1_CACHE_SHIFT 4
2727 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2728 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2729
2730 #endif /* _ASM_M32R_CACHE_H */
2731 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2732 index 82abd15..d95ae5d 100644
2733 --- a/arch/m32r/lib/usercopy.c
2734 +++ b/arch/m32r/lib/usercopy.c
2735 @@ -14,6 +14,9 @@
2736 unsigned long
2737 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2738 {
2739 + if ((long)n < 0)
2740 + return n;
2741 +
2742 prefetch(from);
2743 if (access_ok(VERIFY_WRITE, to, n))
2744 __copy_user(to,from,n);
2745 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2746 unsigned long
2747 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2748 {
2749 + if ((long)n < 0)
2750 + return n;
2751 +
2752 prefetchw(to);
2753 if (access_ok(VERIFY_READ, from, n))
2754 __copy_user_zeroing(to,from,n);
2755 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2756 index 0395c51..5f26031 100644
2757 --- a/arch/m68k/include/asm/cache.h
2758 +++ b/arch/m68k/include/asm/cache.h
2759 @@ -4,9 +4,11 @@
2760 #ifndef __ARCH_M68K_CACHE_H
2761 #define __ARCH_M68K_CACHE_H
2762
2763 +#include <linux/const.h>
2764 +
2765 /* bytes per L1 cache line */
2766 #define L1_CACHE_SHIFT 4
2767 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2768 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2769
2770 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2771
2772 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2773 index 4efe96a..60e8699 100644
2774 --- a/arch/microblaze/include/asm/cache.h
2775 +++ b/arch/microblaze/include/asm/cache.h
2776 @@ -13,11 +13,12 @@
2777 #ifndef _ASM_MICROBLAZE_CACHE_H
2778 #define _ASM_MICROBLAZE_CACHE_H
2779
2780 +#include <linux/const.h>
2781 #include <asm/registers.h>
2782
2783 #define L1_CACHE_SHIFT 5
2784 /* word-granular cache in microblaze */
2785 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2786 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2787
2788 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2789
2790 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2791 index 3f4c5cb..3439c6e 100644
2792 --- a/arch/mips/include/asm/atomic.h
2793 +++ b/arch/mips/include/asm/atomic.h
2794 @@ -21,6 +21,10 @@
2795 #include <asm/cmpxchg.h>
2796 #include <asm/war.h>
2797
2798 +#ifdef CONFIG_GENERIC_ATOMIC64
2799 +#include <asm-generic/atomic64.h>
2800 +#endif
2801 +
2802 #define ATOMIC_INIT(i) { (i) }
2803
2804 /*
2805 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2806 */
2807 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2808
2809 +#define atomic64_read_unchecked(v) atomic64_read(v)
2810 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2811 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2812 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2813 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2814 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2815 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2816 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2817 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2818 +
2819 #endif /* CONFIG_64BIT */
2820
2821 /*
2822 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2823 index b4db69f..8f3b093 100644
2824 --- a/arch/mips/include/asm/cache.h
2825 +++ b/arch/mips/include/asm/cache.h
2826 @@ -9,10 +9,11 @@
2827 #ifndef _ASM_CACHE_H
2828 #define _ASM_CACHE_H
2829
2830 +#include <linux/const.h>
2831 #include <kmalloc.h>
2832
2833 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2834 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2835 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2836
2837 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2838 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2839 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2840 index 455c0ac..ad65fbe 100644
2841 --- a/arch/mips/include/asm/elf.h
2842 +++ b/arch/mips/include/asm/elf.h
2843 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2844 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2845 #endif
2846
2847 +#ifdef CONFIG_PAX_ASLR
2848 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2849 +
2850 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2851 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2852 +#endif
2853 +
2854 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2855 struct linux_binprm;
2856 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2857 int uses_interp);
2858
2859 -struct mm_struct;
2860 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2861 -#define arch_randomize_brk arch_randomize_brk
2862 -
2863 #endif /* _ASM_ELF_H */
2864 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2865 index c1f6afa..38cc6e9 100644
2866 --- a/arch/mips/include/asm/exec.h
2867 +++ b/arch/mips/include/asm/exec.h
2868 @@ -12,6 +12,6 @@
2869 #ifndef _ASM_EXEC_H
2870 #define _ASM_EXEC_H
2871
2872 -extern unsigned long arch_align_stack(unsigned long sp);
2873 +#define arch_align_stack(x) ((x) & ~0xfUL)
2874
2875 #endif /* _ASM_EXEC_H */
2876 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2877 index da9bd7d..91aa7ab 100644
2878 --- a/arch/mips/include/asm/page.h
2879 +++ b/arch/mips/include/asm/page.h
2880 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2881 #ifdef CONFIG_CPU_MIPS32
2882 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2883 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2884 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2885 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2886 #else
2887 typedef struct { unsigned long long pte; } pte_t;
2888 #define pte_val(x) ((x).pte)
2889 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2890 index 881d18b..cea38bc 100644
2891 --- a/arch/mips/include/asm/pgalloc.h
2892 +++ b/arch/mips/include/asm/pgalloc.h
2893 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2894 {
2895 set_pud(pud, __pud((unsigned long)pmd));
2896 }
2897 +
2898 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2899 +{
2900 + pud_populate(mm, pud, pmd);
2901 +}
2902 #endif
2903
2904 /*
2905 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2906 index ca97e0e..cd08920 100644
2907 --- a/arch/mips/include/asm/thread_info.h
2908 +++ b/arch/mips/include/asm/thread_info.h
2909 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2910 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2911 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2912 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2913 +/* li takes a 32bit immediate */
2914 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2915 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2916
2917 #ifdef CONFIG_MIPS32_O32
2918 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2919 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2920 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2921 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2922 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2923 +
2924 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2925
2926 /* work to do in syscall_trace_leave() */
2927 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2928 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2929
2930 /* work to do on interrupt/exception return */
2931 #define _TIF_WORK_MASK (0x0000ffef & \
2932 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2933 /* work to do on any return to u-space */
2934 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2935 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2936
2937 #endif /* __KERNEL__ */
2938
2939 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2940 index 9fdd8bc..4bd7f1a 100644
2941 --- a/arch/mips/kernel/binfmt_elfn32.c
2942 +++ b/arch/mips/kernel/binfmt_elfn32.c
2943 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2944 #undef ELF_ET_DYN_BASE
2945 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2946
2947 +#ifdef CONFIG_PAX_ASLR
2948 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2949 +
2950 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2951 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2952 +#endif
2953 +
2954 #include <asm/processor.h>
2955 #include <linux/module.h>
2956 #include <linux/elfcore.h>
2957 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2958 index ff44823..97f8906 100644
2959 --- a/arch/mips/kernel/binfmt_elfo32.c
2960 +++ b/arch/mips/kernel/binfmt_elfo32.c
2961 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2962 #undef ELF_ET_DYN_BASE
2963 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2964
2965 +#ifdef CONFIG_PAX_ASLR
2966 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2967 +
2968 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2969 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2970 +#endif
2971 +
2972 #include <asm/processor.h>
2973
2974 /*
2975 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2976 index e9a5fd7..378809a 100644
2977 --- a/arch/mips/kernel/process.c
2978 +++ b/arch/mips/kernel/process.c
2979 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2980 out:
2981 return pc;
2982 }
2983 -
2984 -/*
2985 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2986 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2987 - */
2988 -unsigned long arch_align_stack(unsigned long sp)
2989 -{
2990 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2991 - sp -= get_random_int() & ~PAGE_MASK;
2992 -
2993 - return sp & ALMASK;
2994 -}
2995 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2996 index 4812c6d..2069554 100644
2997 --- a/arch/mips/kernel/ptrace.c
2998 +++ b/arch/mips/kernel/ptrace.c
2999 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3000 return arch;
3001 }
3002
3003 +#ifdef CONFIG_GRKERNSEC_SETXID
3004 +extern void gr_delayed_cred_worker(void);
3005 +#endif
3006 +
3007 /*
3008 * Notification of system call entry/exit
3009 * - triggered by current->work.syscall_trace
3010 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3011 /* do the secure computing check first */
3012 secure_computing_strict(regs->regs[2]);
3013
3014 +#ifdef CONFIG_GRKERNSEC_SETXID
3015 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3016 + gr_delayed_cred_worker();
3017 +#endif
3018 +
3019 if (!(current->ptrace & PT_PTRACED))
3020 goto out;
3021
3022 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3023 index a632bc1..0b77c7c 100644
3024 --- a/arch/mips/kernel/scall32-o32.S
3025 +++ b/arch/mips/kernel/scall32-o32.S
3026 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3027
3028 stack_done:
3029 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3030 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3031 + li t1, _TIF_SYSCALL_WORK
3032 and t0, t1
3033 bnez t0, syscall_trace_entry # -> yes
3034
3035 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3036 index 3b5a5e9..e1ee86d 100644
3037 --- a/arch/mips/kernel/scall64-64.S
3038 +++ b/arch/mips/kernel/scall64-64.S
3039 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3040
3041 sd a3, PT_R26(sp) # save a3 for syscall restarting
3042
3043 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3044 + li t1, _TIF_SYSCALL_WORK
3045 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3046 and t0, t1, t0
3047 bnez t0, syscall_trace_entry
3048 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3049 index 6be6f70..1859577 100644
3050 --- a/arch/mips/kernel/scall64-n32.S
3051 +++ b/arch/mips/kernel/scall64-n32.S
3052 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3053
3054 sd a3, PT_R26(sp) # save a3 for syscall restarting
3055
3056 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3057 + li t1, _TIF_SYSCALL_WORK
3058 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3059 and t0, t1, t0
3060 bnez t0, n32_syscall_trace_entry
3061 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3062 index 5422855..74e63a3 100644
3063 --- a/arch/mips/kernel/scall64-o32.S
3064 +++ b/arch/mips/kernel/scall64-o32.S
3065 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3066 PTR 4b, bad_stack
3067 .previous
3068
3069 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3070 + li t1, _TIF_SYSCALL_WORK
3071 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3072 and t0, t1, t0
3073 bnez t0, trace_a_syscall
3074 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3075 index c14f6df..537e729 100644
3076 --- a/arch/mips/mm/fault.c
3077 +++ b/arch/mips/mm/fault.c
3078 @@ -27,6 +27,23 @@
3079 #include <asm/highmem.h> /* For VMALLOC_END */
3080 #include <linux/kdebug.h>
3081
3082 +#ifdef CONFIG_PAX_PAGEEXEC
3083 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3084 +{
3085 + unsigned long i;
3086 +
3087 + printk(KERN_ERR "PAX: bytes at PC: ");
3088 + for (i = 0; i < 5; i++) {
3089 + unsigned int c;
3090 + if (get_user(c, (unsigned int *)pc+i))
3091 + printk(KERN_CONT "???????? ");
3092 + else
3093 + printk(KERN_CONT "%08x ", c);
3094 + }
3095 + printk("\n");
3096 +}
3097 +#endif
3098 +
3099 /*
3100 * This routine handles page faults. It determines the address,
3101 * and the problem, and then passes it off to one of the appropriate
3102 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3103 index 302d779..7d35bf8 100644
3104 --- a/arch/mips/mm/mmap.c
3105 +++ b/arch/mips/mm/mmap.c
3106 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3107 do_color_align = 1;
3108
3109 /* requesting a specific address */
3110 +
3111 +#ifdef CONFIG_PAX_RANDMMAP
3112 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3113 +#endif
3114 +
3115 if (addr) {
3116 if (do_color_align)
3117 addr = COLOUR_ALIGN(addr, pgoff);
3118 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3119 addr = PAGE_ALIGN(addr);
3120
3121 vma = find_vma(mm, addr);
3122 - if (TASK_SIZE - len >= addr &&
3123 - (!vma || addr + len <= vma->vm_start))
3124 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3125 return addr;
3126 }
3127
3128 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3129 /* At this point: (!vma || addr < vma->vm_end). */
3130 if (TASK_SIZE - len < addr)
3131 return -ENOMEM;
3132 - if (!vma || addr + len <= vma->vm_start)
3133 + if (check_heap_stack_gap(vmm, addr, len))
3134 return addr;
3135 addr = vma->vm_end;
3136 if (do_color_align)
3137 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3138 /* make sure it can fit in the remaining address space */
3139 if (likely(addr > len)) {
3140 vma = find_vma(mm, addr - len);
3141 - if (!vma || addr <= vma->vm_start) {
3142 + if (check_heap_stack_gap(vmm, addr - len, len))
3143 /* cache the address as a hint for next time */
3144 return mm->free_area_cache = addr - len;
3145 }
3146 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3147 * return with success:
3148 */
3149 vma = find_vma(mm, addr);
3150 - if (likely(!vma || addr + len <= vma->vm_start)) {
3151 + if (check_heap_stack_gap(vmm, addr, len)) {
3152 /* cache the address as a hint for next time */
3153 return mm->free_area_cache = addr;
3154 }
3155 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3156 mm->unmap_area = arch_unmap_area_topdown;
3157 }
3158 }
3159 -
3160 -static inline unsigned long brk_rnd(void)
3161 -{
3162 - unsigned long rnd = get_random_int();
3163 -
3164 - rnd = rnd << PAGE_SHIFT;
3165 - /* 8MB for 32bit, 256MB for 64bit */
3166 - if (TASK_IS_32BIT_ADDR)
3167 - rnd = rnd & 0x7ffffful;
3168 - else
3169 - rnd = rnd & 0xffffffful;
3170 -
3171 - return rnd;
3172 -}
3173 -
3174 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3175 -{
3176 - unsigned long base = mm->brk;
3177 - unsigned long ret;
3178 -
3179 - ret = PAGE_ALIGN(base + brk_rnd());
3180 -
3181 - if (ret < mm->brk)
3182 - return mm->brk;
3183 -
3184 - return ret;
3185 -}
3186 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3187 index 967d144..db12197 100644
3188 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3189 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3190 @@ -11,12 +11,14 @@
3191 #ifndef _ASM_PROC_CACHE_H
3192 #define _ASM_PROC_CACHE_H
3193
3194 +#include <linux/const.h>
3195 +
3196 /* L1 cache */
3197
3198 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3199 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3200 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3201 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3202 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3203 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3204
3205 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3206 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3207 index bcb5df2..84fabd2 100644
3208 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3209 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3210 @@ -16,13 +16,15 @@
3211 #ifndef _ASM_PROC_CACHE_H
3212 #define _ASM_PROC_CACHE_H
3213
3214 +#include <linux/const.h>
3215 +
3216 /*
3217 * L1 cache
3218 */
3219 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3220 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3221 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3222 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3223 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3224 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3225
3226 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3227 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3228 index 4ce7a01..449202a 100644
3229 --- a/arch/openrisc/include/asm/cache.h
3230 +++ b/arch/openrisc/include/asm/cache.h
3231 @@ -19,11 +19,13 @@
3232 #ifndef __ASM_OPENRISC_CACHE_H
3233 #define __ASM_OPENRISC_CACHE_H
3234
3235 +#include <linux/const.h>
3236 +
3237 /* FIXME: How can we replace these with values from the CPU...
3238 * they shouldn't be hard-coded!
3239 */
3240
3241 -#define L1_CACHE_BYTES 16
3242 #define L1_CACHE_SHIFT 4
3243 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3244
3245 #endif /* __ASM_OPENRISC_CACHE_H */
3246 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3247 index 6c6defc..d30653d 100644
3248 --- a/arch/parisc/include/asm/atomic.h
3249 +++ b/arch/parisc/include/asm/atomic.h
3250 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3251
3252 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3253
3254 +#define atomic64_read_unchecked(v) atomic64_read(v)
3255 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3256 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3257 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3258 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3259 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3260 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3261 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3262 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3263 +
3264 #endif /* !CONFIG_64BIT */
3265
3266
3267 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3268 index 47f11c7..3420df2 100644
3269 --- a/arch/parisc/include/asm/cache.h
3270 +++ b/arch/parisc/include/asm/cache.h
3271 @@ -5,6 +5,7 @@
3272 #ifndef __ARCH_PARISC_CACHE_H
3273 #define __ARCH_PARISC_CACHE_H
3274
3275 +#include <linux/const.h>
3276
3277 /*
3278 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3279 @@ -15,13 +16,13 @@
3280 * just ruin performance.
3281 */
3282 #ifdef CONFIG_PA20
3283 -#define L1_CACHE_BYTES 64
3284 #define L1_CACHE_SHIFT 6
3285 #else
3286 -#define L1_CACHE_BYTES 32
3287 #define L1_CACHE_SHIFT 5
3288 #endif
3289
3290 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3291 +
3292 #ifndef __ASSEMBLY__
3293
3294 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3295 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3296 index 19f6cb1..6c78cf2 100644
3297 --- a/arch/parisc/include/asm/elf.h
3298 +++ b/arch/parisc/include/asm/elf.h
3299 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3300
3301 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3302
3303 +#ifdef CONFIG_PAX_ASLR
3304 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3305 +
3306 +#define PAX_DELTA_MMAP_LEN 16
3307 +#define PAX_DELTA_STACK_LEN 16
3308 +#endif
3309 +
3310 /* This yields a mask that user programs can use to figure out what
3311 instruction set this CPU supports. This could be done in user space,
3312 but it's not easy, and we've already done it here. */
3313 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3314 index fc987a1..6e068ef 100644
3315 --- a/arch/parisc/include/asm/pgalloc.h
3316 +++ b/arch/parisc/include/asm/pgalloc.h
3317 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3318 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3319 }
3320
3321 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3322 +{
3323 + pgd_populate(mm, pgd, pmd);
3324 +}
3325 +
3326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3327 {
3328 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3329 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3330 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3331 #define pmd_free(mm, x) do { } while (0)
3332 #define pgd_populate(mm, pmd, pte) BUG()
3333 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3334
3335 #endif
3336
3337 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3338 index ee99f23..802b0a1 100644
3339 --- a/arch/parisc/include/asm/pgtable.h
3340 +++ b/arch/parisc/include/asm/pgtable.h
3341 @@ -212,6 +212,17 @@ struct vm_area_struct;
3342 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3343 #define PAGE_COPY PAGE_EXECREAD
3344 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3345 +
3346 +#ifdef CONFIG_PAX_PAGEEXEC
3347 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3348 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3349 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3350 +#else
3351 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3352 +# define PAGE_COPY_NOEXEC PAGE_COPY
3353 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3354 +#endif
3355 +
3356 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3357 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3358 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3359 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3360 index 4ba2c93..f5e3974 100644
3361 --- a/arch/parisc/include/asm/uaccess.h
3362 +++ b/arch/parisc/include/asm/uaccess.h
3363 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3364 const void __user *from,
3365 unsigned long n)
3366 {
3367 - int sz = __compiletime_object_size(to);
3368 + size_t sz = __compiletime_object_size(to);
3369 int ret = -EFAULT;
3370
3371 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3372 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3373 ret = __copy_from_user(to, from, n);
3374 else
3375 copy_from_user_overflow();
3376 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3377 index 5e34ccf..672bc9c 100644
3378 --- a/arch/parisc/kernel/module.c
3379 +++ b/arch/parisc/kernel/module.c
3380 @@ -98,16 +98,38 @@
3381
3382 /* three functions to determine where in the module core
3383 * or init pieces the location is */
3384 +static inline int in_init_rx(struct module *me, void *loc)
3385 +{
3386 + return (loc >= me->module_init_rx &&
3387 + loc < (me->module_init_rx + me->init_size_rx));
3388 +}
3389 +
3390 +static inline int in_init_rw(struct module *me, void *loc)
3391 +{
3392 + return (loc >= me->module_init_rw &&
3393 + loc < (me->module_init_rw + me->init_size_rw));
3394 +}
3395 +
3396 static inline int in_init(struct module *me, void *loc)
3397 {
3398 - return (loc >= me->module_init &&
3399 - loc <= (me->module_init + me->init_size));
3400 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3401 +}
3402 +
3403 +static inline int in_core_rx(struct module *me, void *loc)
3404 +{
3405 + return (loc >= me->module_core_rx &&
3406 + loc < (me->module_core_rx + me->core_size_rx));
3407 +}
3408 +
3409 +static inline int in_core_rw(struct module *me, void *loc)
3410 +{
3411 + return (loc >= me->module_core_rw &&
3412 + loc < (me->module_core_rw + me->core_size_rw));
3413 }
3414
3415 static inline int in_core(struct module *me, void *loc)
3416 {
3417 - return (loc >= me->module_core &&
3418 - loc <= (me->module_core + me->core_size));
3419 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3420 }
3421
3422 static inline int in_local(struct module *me, void *loc)
3423 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3424 }
3425
3426 /* align things a bit */
3427 - me->core_size = ALIGN(me->core_size, 16);
3428 - me->arch.got_offset = me->core_size;
3429 - me->core_size += gots * sizeof(struct got_entry);
3430 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3431 + me->arch.got_offset = me->core_size_rw;
3432 + me->core_size_rw += gots * sizeof(struct got_entry);
3433
3434 - me->core_size = ALIGN(me->core_size, 16);
3435 - me->arch.fdesc_offset = me->core_size;
3436 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3437 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3438 + me->arch.fdesc_offset = me->core_size_rw;
3439 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3440
3441 me->arch.got_max = gots;
3442 me->arch.fdesc_max = fdescs;
3443 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3444
3445 BUG_ON(value == 0);
3446
3447 - got = me->module_core + me->arch.got_offset;
3448 + got = me->module_core_rw + me->arch.got_offset;
3449 for (i = 0; got[i].addr; i++)
3450 if (got[i].addr == value)
3451 goto out;
3452 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3453 #ifdef CONFIG_64BIT
3454 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3455 {
3456 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3457 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3458
3459 if (!value) {
3460 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3461 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3462
3463 /* Create new one */
3464 fdesc->addr = value;
3465 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3466 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3467 return (Elf_Addr)fdesc;
3468 }
3469 #endif /* CONFIG_64BIT */
3470 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3471
3472 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3473 end = table + sechdrs[me->arch.unwind_section].sh_size;
3474 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3475 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3476
3477 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3478 me->arch.unwind_section, table, end, gp);
3479 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3480 index c9b9322..02d8940 100644
3481 --- a/arch/parisc/kernel/sys_parisc.c
3482 +++ b/arch/parisc/kernel/sys_parisc.c
3483 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3484 /* At this point: (!vma || addr < vma->vm_end). */
3485 if (TASK_SIZE - len < addr)
3486 return -ENOMEM;
3487 - if (!vma || addr + len <= vma->vm_start)
3488 + if (check_heap_stack_gap(vma, addr, len))
3489 return addr;
3490 addr = vma->vm_end;
3491 }
3492 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3493 /* At this point: (!vma || addr < vma->vm_end). */
3494 if (TASK_SIZE - len < addr)
3495 return -ENOMEM;
3496 - if (!vma || addr + len <= vma->vm_start)
3497 + if (check_heap_stack_gap(vma, addr, len))
3498 return addr;
3499 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3500 if (addr < vma->vm_end) /* handle wraparound */
3501 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3502 if (flags & MAP_FIXED)
3503 return addr;
3504 if (!addr)
3505 - addr = TASK_UNMAPPED_BASE;
3506 + addr = current->mm->mmap_base;
3507
3508 if (filp) {
3509 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3510 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3511 index 45ba99f..8e22c33 100644
3512 --- a/arch/parisc/kernel/traps.c
3513 +++ b/arch/parisc/kernel/traps.c
3514 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3515
3516 down_read(&current->mm->mmap_sem);
3517 vma = find_vma(current->mm,regs->iaoq[0]);
3518 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3519 - && (vma->vm_flags & VM_EXEC)) {
3520 -
3521 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3522 fault_address = regs->iaoq[0];
3523 fault_space = regs->iasq[0];
3524
3525 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3526 index 18162ce..94de376 100644
3527 --- a/arch/parisc/mm/fault.c
3528 +++ b/arch/parisc/mm/fault.c
3529 @@ -15,6 +15,7 @@
3530 #include <linux/sched.h>
3531 #include <linux/interrupt.h>
3532 #include <linux/module.h>
3533 +#include <linux/unistd.h>
3534
3535 #include <asm/uaccess.h>
3536 #include <asm/traps.h>
3537 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3538 static unsigned long
3539 parisc_acctyp(unsigned long code, unsigned int inst)
3540 {
3541 - if (code == 6 || code == 16)
3542 + if (code == 6 || code == 7 || code == 16)
3543 return VM_EXEC;
3544
3545 switch (inst & 0xf0000000) {
3546 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3547 }
3548 #endif
3549
3550 +#ifdef CONFIG_PAX_PAGEEXEC
3551 +/*
3552 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3553 + *
3554 + * returns 1 when task should be killed
3555 + * 2 when rt_sigreturn trampoline was detected
3556 + * 3 when unpatched PLT trampoline was detected
3557 + */
3558 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3559 +{
3560 +
3561 +#ifdef CONFIG_PAX_EMUPLT
3562 + int err;
3563 +
3564 + do { /* PaX: unpatched PLT emulation */
3565 + unsigned int bl, depwi;
3566 +
3567 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3568 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3569 +
3570 + if (err)
3571 + break;
3572 +
3573 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3574 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3575 +
3576 + err = get_user(ldw, (unsigned int *)addr);
3577 + err |= get_user(bv, (unsigned int *)(addr+4));
3578 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3579 +
3580 + if (err)
3581 + break;
3582 +
3583 + if (ldw == 0x0E801096U &&
3584 + bv == 0xEAC0C000U &&
3585 + ldw2 == 0x0E881095U)
3586 + {
3587 + unsigned int resolver, map;
3588 +
3589 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3590 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3591 + if (err)
3592 + break;
3593 +
3594 + regs->gr[20] = instruction_pointer(regs)+8;
3595 + regs->gr[21] = map;
3596 + regs->gr[22] = resolver;
3597 + regs->iaoq[0] = resolver | 3UL;
3598 + regs->iaoq[1] = regs->iaoq[0] + 4;
3599 + return 3;
3600 + }
3601 + }
3602 + } while (0);
3603 +#endif
3604 +
3605 +#ifdef CONFIG_PAX_EMUTRAMP
3606 +
3607 +#ifndef CONFIG_PAX_EMUSIGRT
3608 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3609 + return 1;
3610 +#endif
3611 +
3612 + do { /* PaX: rt_sigreturn emulation */
3613 + unsigned int ldi1, ldi2, bel, nop;
3614 +
3615 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3616 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3617 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3618 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3619 +
3620 + if (err)
3621 + break;
3622 +
3623 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3624 + ldi2 == 0x3414015AU &&
3625 + bel == 0xE4008200U &&
3626 + nop == 0x08000240U)
3627 + {
3628 + regs->gr[25] = (ldi1 & 2) >> 1;
3629 + regs->gr[20] = __NR_rt_sigreturn;
3630 + regs->gr[31] = regs->iaoq[1] + 16;
3631 + regs->sr[0] = regs->iasq[1];
3632 + regs->iaoq[0] = 0x100UL;
3633 + regs->iaoq[1] = regs->iaoq[0] + 4;
3634 + regs->iasq[0] = regs->sr[2];
3635 + regs->iasq[1] = regs->sr[2];
3636 + return 2;
3637 + }
3638 + } while (0);
3639 +#endif
3640 +
3641 + return 1;
3642 +}
3643 +
3644 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3645 +{
3646 + unsigned long i;
3647 +
3648 + printk(KERN_ERR "PAX: bytes at PC: ");
3649 + for (i = 0; i < 5; i++) {
3650 + unsigned int c;
3651 + if (get_user(c, (unsigned int *)pc+i))
3652 + printk(KERN_CONT "???????? ");
3653 + else
3654 + printk(KERN_CONT "%08x ", c);
3655 + }
3656 + printk("\n");
3657 +}
3658 +#endif
3659 +
3660 int fixup_exception(struct pt_regs *regs)
3661 {
3662 const struct exception_table_entry *fix;
3663 @@ -192,8 +303,33 @@ good_area:
3664
3665 acc_type = parisc_acctyp(code,regs->iir);
3666
3667 - if ((vma->vm_flags & acc_type) != acc_type)
3668 + if ((vma->vm_flags & acc_type) != acc_type) {
3669 +
3670 +#ifdef CONFIG_PAX_PAGEEXEC
3671 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3672 + (address & ~3UL) == instruction_pointer(regs))
3673 + {
3674 + up_read(&mm->mmap_sem);
3675 + switch (pax_handle_fetch_fault(regs)) {
3676 +
3677 +#ifdef CONFIG_PAX_EMUPLT
3678 + case 3:
3679 + return;
3680 +#endif
3681 +
3682 +#ifdef CONFIG_PAX_EMUTRAMP
3683 + case 2:
3684 + return;
3685 +#endif
3686 +
3687 + }
3688 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3689 + do_group_exit(SIGKILL);
3690 + }
3691 +#endif
3692 +
3693 goto bad_area;
3694 + }
3695
3696 /*
3697 * If for any reason at all we couldn't handle the fault, make
3698 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3699 index da29032..f76c24c 100644
3700 --- a/arch/powerpc/include/asm/atomic.h
3701 +++ b/arch/powerpc/include/asm/atomic.h
3702 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3703 return t1;
3704 }
3705
3706 +#define atomic64_read_unchecked(v) atomic64_read(v)
3707 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3708 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3709 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3710 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3711 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3712 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3713 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3714 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3715 +
3716 #endif /* __powerpc64__ */
3717
3718 #endif /* __KERNEL__ */
3719 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3720 index 9e495c9..b6878e5 100644
3721 --- a/arch/powerpc/include/asm/cache.h
3722 +++ b/arch/powerpc/include/asm/cache.h
3723 @@ -3,6 +3,7 @@
3724
3725 #ifdef __KERNEL__
3726
3727 +#include <linux/const.h>
3728
3729 /* bytes per L1 cache line */
3730 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3731 @@ -22,7 +23,7 @@
3732 #define L1_CACHE_SHIFT 7
3733 #endif
3734
3735 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3736 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3737
3738 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3739
3740 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3741 index 3bf9cca..e7457d0 100644
3742 --- a/arch/powerpc/include/asm/elf.h
3743 +++ b/arch/powerpc/include/asm/elf.h
3744 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3745 the loader. We need to make sure that it is out of the way of the program
3746 that it will "exec", and that there is sufficient room for the brk. */
3747
3748 -extern unsigned long randomize_et_dyn(unsigned long base);
3749 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3750 +#define ELF_ET_DYN_BASE (0x20000000)
3751 +
3752 +#ifdef CONFIG_PAX_ASLR
3753 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3754 +
3755 +#ifdef __powerpc64__
3756 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3757 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3758 +#else
3759 +#define PAX_DELTA_MMAP_LEN 15
3760 +#define PAX_DELTA_STACK_LEN 15
3761 +#endif
3762 +#endif
3763
3764 /*
3765 * Our registers are always unsigned longs, whether we're a 32 bit
3766 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3767 (0x7ff >> (PAGE_SHIFT - 12)) : \
3768 (0x3ffff >> (PAGE_SHIFT - 12)))
3769
3770 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3771 -#define arch_randomize_brk arch_randomize_brk
3772 -
3773 #endif /* __KERNEL__ */
3774
3775 /*
3776 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3777 index 8196e9c..d83a9f3 100644
3778 --- a/arch/powerpc/include/asm/exec.h
3779 +++ b/arch/powerpc/include/asm/exec.h
3780 @@ -4,6 +4,6 @@
3781 #ifndef _ASM_POWERPC_EXEC_H
3782 #define _ASM_POWERPC_EXEC_H
3783
3784 -extern unsigned long arch_align_stack(unsigned long sp);
3785 +#define arch_align_stack(x) ((x) & ~0xfUL)
3786
3787 #endif /* _ASM_POWERPC_EXEC_H */
3788 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3789 index bca8fdc..61e9580 100644
3790 --- a/arch/powerpc/include/asm/kmap_types.h
3791 +++ b/arch/powerpc/include/asm/kmap_types.h
3792 @@ -27,6 +27,7 @@ enum km_type {
3793 KM_PPC_SYNC_PAGE,
3794 KM_PPC_SYNC_ICACHE,
3795 KM_KDB,
3796 + KM_CLEARPAGE,
3797 KM_TYPE_NR
3798 };
3799
3800 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3801 index d4a7f64..451de1c 100644
3802 --- a/arch/powerpc/include/asm/mman.h
3803 +++ b/arch/powerpc/include/asm/mman.h
3804 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3805 }
3806 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3807
3808 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3809 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3810 {
3811 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3812 }
3813 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3814 index f072e97..b436dee 100644
3815 --- a/arch/powerpc/include/asm/page.h
3816 +++ b/arch/powerpc/include/asm/page.h
3817 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3818 * and needs to be executable. This means the whole heap ends
3819 * up being executable.
3820 */
3821 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3822 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3823 +#define VM_DATA_DEFAULT_FLAGS32 \
3824 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3825 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3826
3827 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3828 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3829 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3830 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3831 #endif
3832
3833 +#define ktla_ktva(addr) (addr)
3834 +#define ktva_ktla(addr) (addr)
3835 +
3836 /*
3837 * Use the top bit of the higher-level page table entries to indicate whether
3838 * the entries we point to contain hugepages. This works because we know that
3839 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3840 index fed85e6..da5c71b 100644
3841 --- a/arch/powerpc/include/asm/page_64.h
3842 +++ b/arch/powerpc/include/asm/page_64.h
3843 @@ -146,15 +146,18 @@ do { \
3844 * stack by default, so in the absence of a PT_GNU_STACK program header
3845 * we turn execute permission off.
3846 */
3847 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3848 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3849 +#define VM_STACK_DEFAULT_FLAGS32 \
3850 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3851 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3852
3853 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3854 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3855
3856 +#ifndef CONFIG_PAX_PAGEEXEC
3857 #define VM_STACK_DEFAULT_FLAGS \
3858 (is_32bit_task() ? \
3859 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3860 +#endif
3861
3862 #include <asm-generic/getorder.h>
3863
3864 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3865 index 292725c..f87ae14 100644
3866 --- a/arch/powerpc/include/asm/pgalloc-64.h
3867 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3868 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3869 #ifndef CONFIG_PPC_64K_PAGES
3870
3871 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3872 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3873
3874 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3875 {
3876 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3877 pud_set(pud, (unsigned long)pmd);
3878 }
3879
3880 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3881 +{
3882 + pud_populate(mm, pud, pmd);
3883 +}
3884 +
3885 #define pmd_populate(mm, pmd, pte_page) \
3886 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3887 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3888 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3889 #else /* CONFIG_PPC_64K_PAGES */
3890
3891 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3892 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3893
3894 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3895 pte_t *pte)
3896 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3897 index 2e0e411..7899c68 100644
3898 --- a/arch/powerpc/include/asm/pgtable.h
3899 +++ b/arch/powerpc/include/asm/pgtable.h
3900 @@ -2,6 +2,7 @@
3901 #define _ASM_POWERPC_PGTABLE_H
3902 #ifdef __KERNEL__
3903
3904 +#include <linux/const.h>
3905 #ifndef __ASSEMBLY__
3906 #include <asm/processor.h> /* For TASK_SIZE */
3907 #include <asm/mmu.h>
3908 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3909 index 4aad413..85d86bf 100644
3910 --- a/arch/powerpc/include/asm/pte-hash32.h
3911 +++ b/arch/powerpc/include/asm/pte-hash32.h
3912 @@ -21,6 +21,7 @@
3913 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3914 #define _PAGE_USER 0x004 /* usermode access allowed */
3915 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3916 +#define _PAGE_EXEC _PAGE_GUARDED
3917 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3918 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3919 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3920 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3921 index 360585d..c3930ef 100644
3922 --- a/arch/powerpc/include/asm/reg.h
3923 +++ b/arch/powerpc/include/asm/reg.h
3924 @@ -212,6 +212,7 @@
3925 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3926 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3927 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3928 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3929 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3930 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3931 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3932 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3933 index 68831e9..379c695 100644
3934 --- a/arch/powerpc/include/asm/thread_info.h
3935 +++ b/arch/powerpc/include/asm/thread_info.h
3936 @@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3937 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3938 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3939 #define TIF_SINGLESTEP 8 /* singlestepping active */
3940 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3941 #define TIF_SECCOMP 10 /* secure computing */
3942 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3943 #define TIF_NOERROR 12 /* Force successful syscall return */
3944 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3945 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3946 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3947 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3948 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3949
3950 /* as above, but as bit values */
3951 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3952 @@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3953 #define _TIF_NOERROR (1<<TIF_NOERROR)
3954 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3955 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3956 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3957 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3958 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3959 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3960 + _TIF_GRSEC_SETXID)
3961
3962 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3963 _TIF_NOTIFY_RESUME)
3964 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3965 index 17bb40c..353c98b 100644
3966 --- a/arch/powerpc/include/asm/uaccess.h
3967 +++ b/arch/powerpc/include/asm/uaccess.h
3968 @@ -13,6 +13,8 @@
3969 #define VERIFY_READ 0
3970 #define VERIFY_WRITE 1
3971
3972 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3973 +
3974 /*
3975 * The fs value determines whether argument validity checking should be
3976 * performed or not. If get_fs() == USER_DS, checking is performed, with
3977 @@ -329,52 +331,6 @@ do { \
3978 extern unsigned long __copy_tofrom_user(void __user *to,
3979 const void __user *from, unsigned long size);
3980
3981 -#ifndef __powerpc64__
3982 -
3983 -static inline unsigned long copy_from_user(void *to,
3984 - const void __user *from, unsigned long n)
3985 -{
3986 - unsigned long over;
3987 -
3988 - if (access_ok(VERIFY_READ, from, n))
3989 - return __copy_tofrom_user((__force void __user *)to, from, n);
3990 - if ((unsigned long)from < TASK_SIZE) {
3991 - over = (unsigned long)from + n - TASK_SIZE;
3992 - return __copy_tofrom_user((__force void __user *)to, from,
3993 - n - over) + over;
3994 - }
3995 - return n;
3996 -}
3997 -
3998 -static inline unsigned long copy_to_user(void __user *to,
3999 - const void *from, unsigned long n)
4000 -{
4001 - unsigned long over;
4002 -
4003 - if (access_ok(VERIFY_WRITE, to, n))
4004 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4005 - if ((unsigned long)to < TASK_SIZE) {
4006 - over = (unsigned long)to + n - TASK_SIZE;
4007 - return __copy_tofrom_user(to, (__force void __user *)from,
4008 - n - over) + over;
4009 - }
4010 - return n;
4011 -}
4012 -
4013 -#else /* __powerpc64__ */
4014 -
4015 -#define __copy_in_user(to, from, size) \
4016 - __copy_tofrom_user((to), (from), (size))
4017 -
4018 -extern unsigned long copy_from_user(void *to, const void __user *from,
4019 - unsigned long n);
4020 -extern unsigned long copy_to_user(void __user *to, const void *from,
4021 - unsigned long n);
4022 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4023 - unsigned long n);
4024 -
4025 -#endif /* __powerpc64__ */
4026 -
4027 static inline unsigned long __copy_from_user_inatomic(void *to,
4028 const void __user *from, unsigned long n)
4029 {
4030 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4031 if (ret == 0)
4032 return 0;
4033 }
4034 +
4035 + if (!__builtin_constant_p(n))
4036 + check_object_size(to, n, false);
4037 +
4038 return __copy_tofrom_user((__force void __user *)to, from, n);
4039 }
4040
4041 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4042 if (ret == 0)
4043 return 0;
4044 }
4045 +
4046 + if (!__builtin_constant_p(n))
4047 + check_object_size(from, n, true);
4048 +
4049 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4050 }
4051
4052 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4053 return __copy_to_user_inatomic(to, from, size);
4054 }
4055
4056 +#ifndef __powerpc64__
4057 +
4058 +static inline unsigned long __must_check copy_from_user(void *to,
4059 + const void __user *from, unsigned long n)
4060 +{
4061 + unsigned long over;
4062 +
4063 + if ((long)n < 0)
4064 + return n;
4065 +
4066 + if (access_ok(VERIFY_READ, from, n)) {
4067 + if (!__builtin_constant_p(n))
4068 + check_object_size(to, n, false);
4069 + return __copy_tofrom_user((__force void __user *)to, from, n);
4070 + }
4071 + if ((unsigned long)from < TASK_SIZE) {
4072 + over = (unsigned long)from + n - TASK_SIZE;
4073 + if (!__builtin_constant_p(n - over))
4074 + check_object_size(to, n - over, false);
4075 + return __copy_tofrom_user((__force void __user *)to, from,
4076 + n - over) + over;
4077 + }
4078 + return n;
4079 +}
4080 +
4081 +static inline unsigned long __must_check copy_to_user(void __user *to,
4082 + const void *from, unsigned long n)
4083 +{
4084 + unsigned long over;
4085 +
4086 + if ((long)n < 0)
4087 + return n;
4088 +
4089 + if (access_ok(VERIFY_WRITE, to, n)) {
4090 + if (!__builtin_constant_p(n))
4091 + check_object_size(from, n, true);
4092 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4093 + }
4094 + if ((unsigned long)to < TASK_SIZE) {
4095 + over = (unsigned long)to + n - TASK_SIZE;
4096 + if (!__builtin_constant_p(n))
4097 + check_object_size(from, n - over, true);
4098 + return __copy_tofrom_user(to, (__force void __user *)from,
4099 + n - over) + over;
4100 + }
4101 + return n;
4102 +}
4103 +
4104 +#else /* __powerpc64__ */
4105 +
4106 +#define __copy_in_user(to, from, size) \
4107 + __copy_tofrom_user((to), (from), (size))
4108 +
4109 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4110 +{
4111 + if ((long)n < 0 || n > INT_MAX)
4112 + return n;
4113 +
4114 + if (!__builtin_constant_p(n))
4115 + check_object_size(to, n, false);
4116 +
4117 + if (likely(access_ok(VERIFY_READ, from, n)))
4118 + n = __copy_from_user(to, from, n);
4119 + else
4120 + memset(to, 0, n);
4121 + return n;
4122 +}
4123 +
4124 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4125 +{
4126 + if ((long)n < 0 || n > INT_MAX)
4127 + return n;
4128 +
4129 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4130 + if (!__builtin_constant_p(n))
4131 + check_object_size(from, n, true);
4132 + n = __copy_to_user(to, from, n);
4133 + }
4134 + return n;
4135 +}
4136 +
4137 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4138 + unsigned long n);
4139 +
4140 +#endif /* __powerpc64__ */
4141 +
4142 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4143
4144 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4145 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4146 index 7215cc2..a9730c1 100644
4147 --- a/arch/powerpc/kernel/exceptions-64e.S
4148 +++ b/arch/powerpc/kernel/exceptions-64e.S
4149 @@ -661,6 +661,7 @@ storage_fault_common:
4150 std r14,_DAR(r1)
4151 std r15,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 + bl .save_nvgprs
4154 mr r4,r14
4155 mr r5,r15
4156 ld r14,PACA_EXGEN+EX_R14(r13)
4157 @@ -669,8 +670,7 @@ storage_fault_common:
4158 cmpdi r3,0
4159 bne- 1f
4160 b .ret_from_except_lite
4161 -1: bl .save_nvgprs
4162 - mr r5,r3
4163 +1: mr r5,r3
4164 addi r3,r1,STACK_FRAME_OVERHEAD
4165 ld r4,_DAR(r1)
4166 bl .bad_page_fault
4167 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4168 index 1c06d29..c2a339b 100644
4169 --- a/arch/powerpc/kernel/exceptions-64s.S
4170 +++ b/arch/powerpc/kernel/exceptions-64s.S
4171 @@ -888,10 +888,10 @@ handle_page_fault:
4172 11: ld r4,_DAR(r1)
4173 ld r5,_DSISR(r1)
4174 addi r3,r1,STACK_FRAME_OVERHEAD
4175 + bl .save_nvgprs
4176 bl .do_page_fault
4177 cmpdi r3,0
4178 beq+ 12f
4179 - bl .save_nvgprs
4180 mr r5,r3
4181 addi r3,r1,STACK_FRAME_OVERHEAD
4182 lwz r4,_DAR(r1)
4183 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4184 index 2e3200c..72095ce 100644
4185 --- a/arch/powerpc/kernel/module_32.c
4186 +++ b/arch/powerpc/kernel/module_32.c
4187 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4188 me->arch.core_plt_section = i;
4189 }
4190 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4191 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4192 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4193 return -ENOEXEC;
4194 }
4195
4196 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4197
4198 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4199 /* Init, or core PLT? */
4200 - if (location >= mod->module_core
4201 - && location < mod->module_core + mod->core_size)
4202 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4203 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4204 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4205 - else
4206 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4207 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4208 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4209 + else {
4210 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4211 + return ~0UL;
4212 + }
4213
4214 /* Find this entry, or if that fails, the next avail. entry */
4215 while (entry->jump[0]) {
4216 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4217 index 710f400..d00ebe6 100644
4218 --- a/arch/powerpc/kernel/process.c
4219 +++ b/arch/powerpc/kernel/process.c
4220 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4221 * Lookup NIP late so we have the best change of getting the
4222 * above info out without failing
4223 */
4224 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4225 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4226 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4227 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4228 #endif
4229 show_stack(current, (unsigned long *) regs->gpr[1]);
4230 if (!user_mode(regs))
4231 @@ -1189,10 +1189,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4232 newsp = stack[0];
4233 ip = stack[STACK_FRAME_LR_SAVE];
4234 if (!firstframe || ip != lr) {
4235 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4236 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4237 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4238 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4239 - printk(" (%pS)",
4240 + printk(" (%pA)",
4241 (void *)current->ret_stack[curr_frame].ret);
4242 curr_frame--;
4243 }
4244 @@ -1212,7 +1212,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4245 struct pt_regs *regs = (struct pt_regs *)
4246 (sp + STACK_FRAME_OVERHEAD);
4247 lr = regs->link;
4248 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4249 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4250 regs->trap, (void *)regs->nip, (void *)lr);
4251 firstframe = 1;
4252 }
4253 @@ -1254,58 +1254,3 @@ void __ppc64_runlatch_off(void)
4254 mtspr(SPRN_CTRLT, ctrl);
4255 }
4256 #endif /* CONFIG_PPC64 */
4257 -
4258 -unsigned long arch_align_stack(unsigned long sp)
4259 -{
4260 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4261 - sp -= get_random_int() & ~PAGE_MASK;
4262 - return sp & ~0xf;
4263 -}
4264 -
4265 -static inline unsigned long brk_rnd(void)
4266 -{
4267 - unsigned long rnd = 0;
4268 -
4269 - /* 8MB for 32bit, 1GB for 64bit */
4270 - if (is_32bit_task())
4271 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4272 - else
4273 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4274 -
4275 - return rnd << PAGE_SHIFT;
4276 -}
4277 -
4278 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4279 -{
4280 - unsigned long base = mm->brk;
4281 - unsigned long ret;
4282 -
4283 -#ifdef CONFIG_PPC_STD_MMU_64
4284 - /*
4285 - * If we are using 1TB segments and we are allowed to randomise
4286 - * the heap, we can put it above 1TB so it is backed by a 1TB
4287 - * segment. Otherwise the heap will be in the bottom 1TB
4288 - * which always uses 256MB segments and this may result in a
4289 - * performance penalty.
4290 - */
4291 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4292 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4293 -#endif
4294 -
4295 - ret = PAGE_ALIGN(base + brk_rnd());
4296 -
4297 - if (ret < mm->brk)
4298 - return mm->brk;
4299 -
4300 - return ret;
4301 -}
4302 -
4303 -unsigned long randomize_et_dyn(unsigned long base)
4304 -{
4305 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4306 -
4307 - if (ret < base)
4308 - return base;
4309 -
4310 - return ret;
4311 -}
4312 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4313 index c10fc28..c4ef063 100644
4314 --- a/arch/powerpc/kernel/ptrace.c
4315 +++ b/arch/powerpc/kernel/ptrace.c
4316 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4317 return ret;
4318 }
4319
4320 +#ifdef CONFIG_GRKERNSEC_SETXID
4321 +extern void gr_delayed_cred_worker(void);
4322 +#endif
4323 +
4324 /*
4325 * We must return the syscall number to actually look up in the table.
4326 * This can be -1L to skip running any syscall at all.
4327 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4328
4329 secure_computing_strict(regs->gpr[0]);
4330
4331 +#ifdef CONFIG_GRKERNSEC_SETXID
4332 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4333 + gr_delayed_cred_worker();
4334 +#endif
4335 +
4336 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4337 tracehook_report_syscall_entry(regs))
4338 /*
4339 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4340 {
4341 int step;
4342
4343 +#ifdef CONFIG_GRKERNSEC_SETXID
4344 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4345 + gr_delayed_cred_worker();
4346 +#endif
4347 +
4348 audit_syscall_exit(regs);
4349
4350 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4351 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4352 index 8b4c049..dcd6ef3 100644
4353 --- a/arch/powerpc/kernel/signal_32.c
4354 +++ b/arch/powerpc/kernel/signal_32.c
4355 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4356 /* Save user registers on the stack */
4357 frame = &rt_sf->uc.uc_mcontext;
4358 addr = frame;
4359 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4360 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4361 if (save_user_regs(regs, frame, 0, 1))
4362 goto badframe;
4363 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4364 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4365 index d183f87..1867f1a 100644
4366 --- a/arch/powerpc/kernel/signal_64.c
4367 +++ b/arch/powerpc/kernel/signal_64.c
4368 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4369 current->thread.fpscr.val = 0;
4370
4371 /* Set up to return from userspace. */
4372 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4373 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4374 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4375 } else {
4376 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4377 diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
4378 index f2496f2..4e3cc47 100644
4379 --- a/arch/powerpc/kernel/syscalls.c
4380 +++ b/arch/powerpc/kernel/syscalls.c
4381 @@ -107,11 +107,11 @@ long ppc64_personality(unsigned long personality)
4382 long ret;
4383
4384 if (personality(current->personality) == PER_LINUX32
4385 - && personality == PER_LINUX)
4386 - personality = PER_LINUX32;
4387 + && personality(personality) == PER_LINUX)
4388 + personality = (personality & ~PER_MASK) | PER_LINUX32;
4389 ret = sys_personality(personality);
4390 - if (ret == PER_LINUX32)
4391 - ret = PER_LINUX;
4392 + if (personality(ret) == PER_LINUX32)
4393 + ret = (ret & ~PER_MASK) | PER_LINUX;
4394 return ret;
4395 }
4396 #endif
4397 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4398 index 1589723..cefe690 100644
4399 --- a/arch/powerpc/kernel/traps.c
4400 +++ b/arch/powerpc/kernel/traps.c
4401 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4402 return flags;
4403 }
4404
4405 +extern void gr_handle_kernel_exploit(void);
4406 +
4407 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4408 int signr)
4409 {
4410 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4411 panic("Fatal exception in interrupt");
4412 if (panic_on_oops)
4413 panic("Fatal exception");
4414 +
4415 + gr_handle_kernel_exploit();
4416 +
4417 do_exit(signr);
4418 }
4419
4420 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4421 index 9eb5b9b..e45498a 100644
4422 --- a/arch/powerpc/kernel/vdso.c
4423 +++ b/arch/powerpc/kernel/vdso.c
4424 @@ -34,6 +34,7 @@
4425 #include <asm/firmware.h>
4426 #include <asm/vdso.h>
4427 #include <asm/vdso_datapage.h>
4428 +#include <asm/mman.h>
4429
4430 #include "setup.h"
4431
4432 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4433 vdso_base = VDSO32_MBASE;
4434 #endif
4435
4436 - current->mm->context.vdso_base = 0;
4437 + current->mm->context.vdso_base = ~0UL;
4438
4439 /* vDSO has a problem and was disabled, just don't "enable" it for the
4440 * process
4441 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4442 vdso_base = get_unmapped_area(NULL, vdso_base,
4443 (vdso_pages << PAGE_SHIFT) +
4444 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4445 - 0, 0);
4446 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4447 if (IS_ERR_VALUE(vdso_base)) {
4448 rc = vdso_base;
4449 goto fail_mmapsem;
4450 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4451 index 5eea6f3..5d10396 100644
4452 --- a/arch/powerpc/lib/usercopy_64.c
4453 +++ b/arch/powerpc/lib/usercopy_64.c
4454 @@ -9,22 +9,6 @@
4455 #include <linux/module.h>
4456 #include <asm/uaccess.h>
4457
4458 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4459 -{
4460 - if (likely(access_ok(VERIFY_READ, from, n)))
4461 - n = __copy_from_user(to, from, n);
4462 - else
4463 - memset(to, 0, n);
4464 - return n;
4465 -}
4466 -
4467 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4468 -{
4469 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4470 - n = __copy_to_user(to, from, n);
4471 - return n;
4472 -}
4473 -
4474 unsigned long copy_in_user(void __user *to, const void __user *from,
4475 unsigned long n)
4476 {
4477 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4478 return n;
4479 }
4480
4481 -EXPORT_SYMBOL(copy_from_user);
4482 -EXPORT_SYMBOL(copy_to_user);
4483 EXPORT_SYMBOL(copy_in_user);
4484
4485 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4486 index 08ffcf5..a0ab912 100644
4487 --- a/arch/powerpc/mm/fault.c
4488 +++ b/arch/powerpc/mm/fault.c
4489 @@ -32,6 +32,10 @@
4490 #include <linux/perf_event.h>
4491 #include <linux/magic.h>
4492 #include <linux/ratelimit.h>
4493 +#include <linux/slab.h>
4494 +#include <linux/pagemap.h>
4495 +#include <linux/compiler.h>
4496 +#include <linux/unistd.h>
4497
4498 #include <asm/firmware.h>
4499 #include <asm/page.h>
4500 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4501 }
4502 #endif
4503
4504 +#ifdef CONFIG_PAX_PAGEEXEC
4505 +/*
4506 + * PaX: decide what to do with offenders (regs->nip = fault address)
4507 + *
4508 + * returns 1 when task should be killed
4509 + */
4510 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4511 +{
4512 + return 1;
4513 +}
4514 +
4515 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4516 +{
4517 + unsigned long i;
4518 +
4519 + printk(KERN_ERR "PAX: bytes at PC: ");
4520 + for (i = 0; i < 5; i++) {
4521 + unsigned int c;
4522 + if (get_user(c, (unsigned int __user *)pc+i))
4523 + printk(KERN_CONT "???????? ");
4524 + else
4525 + printk(KERN_CONT "%08x ", c);
4526 + }
4527 + printk("\n");
4528 +}
4529 +#endif
4530 +
4531 /*
4532 * Check whether the instruction at regs->nip is a store using
4533 * an update addressing form which will update r1.
4534 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4535 * indicate errors in DSISR but can validly be set in SRR1.
4536 */
4537 if (trap == 0x400)
4538 - error_code &= 0x48200000;
4539 + error_code &= 0x58200000;
4540 else
4541 is_write = error_code & DSISR_ISSTORE;
4542 #else
4543 @@ -366,7 +397,7 @@ good_area:
4544 * "undefined". Of those that can be set, this is the only
4545 * one which seems bad.
4546 */
4547 - if (error_code & 0x10000000)
4548 + if (error_code & DSISR_GUARDED)
4549 /* Guarded storage error. */
4550 goto bad_area;
4551 #endif /* CONFIG_8xx */
4552 @@ -381,7 +412,7 @@ good_area:
4553 * processors use the same I/D cache coherency mechanism
4554 * as embedded.
4555 */
4556 - if (error_code & DSISR_PROTFAULT)
4557 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4558 goto bad_area;
4559 #endif /* CONFIG_PPC_STD_MMU */
4560
4561 @@ -463,6 +494,23 @@ bad_area:
4562 bad_area_nosemaphore:
4563 /* User mode accesses cause a SIGSEGV */
4564 if (user_mode(regs)) {
4565 +
4566 +#ifdef CONFIG_PAX_PAGEEXEC
4567 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4568 +#ifdef CONFIG_PPC_STD_MMU
4569 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4570 +#else
4571 + if (is_exec && regs->nip == address) {
4572 +#endif
4573 + switch (pax_handle_fetch_fault(regs)) {
4574 + }
4575 +
4576 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4577 + do_group_exit(SIGKILL);
4578 + }
4579 + }
4580 +#endif
4581 +
4582 _exception(SIGSEGV, regs, code, address);
4583 return 0;
4584 }
4585 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4586 index 67a42ed..1c7210c 100644
4587 --- a/arch/powerpc/mm/mmap_64.c
4588 +++ b/arch/powerpc/mm/mmap_64.c
4589 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4590 */
4591 if (mmap_is_legacy()) {
4592 mm->mmap_base = TASK_UNMAPPED_BASE;
4593 +
4594 +#ifdef CONFIG_PAX_RANDMMAP
4595 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4596 + mm->mmap_base += mm->delta_mmap;
4597 +#endif
4598 +
4599 mm->get_unmapped_area = arch_get_unmapped_area;
4600 mm->unmap_area = arch_unmap_area;
4601 } else {
4602 mm->mmap_base = mmap_base();
4603 +
4604 +#ifdef CONFIG_PAX_RANDMMAP
4605 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4606 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4607 +#endif
4608 +
4609 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4610 mm->unmap_area = arch_unmap_area_topdown;
4611 }
4612 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4613 index 73709f7..6b90313 100644
4614 --- a/arch/powerpc/mm/slice.c
4615 +++ b/arch/powerpc/mm/slice.c
4616 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4617 if ((mm->task_size - len) < addr)
4618 return 0;
4619 vma = find_vma(mm, addr);
4620 - return (!vma || (addr + len) <= vma->vm_start);
4621 + return check_heap_stack_gap(vma, addr, len);
4622 }
4623
4624 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4625 @@ -256,7 +256,7 @@ full_search:
4626 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4627 continue;
4628 }
4629 - if (!vma || addr + len <= vma->vm_start) {
4630 + if (check_heap_stack_gap(vma, addr, len)) {
4631 /*
4632 * Remember the place where we stopped the search:
4633 */
4634 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4635 }
4636 }
4637
4638 - addr = mm->mmap_base;
4639 - while (addr > len) {
4640 + if (mm->mmap_base < len)
4641 + addr = -ENOMEM;
4642 + else
4643 + addr = mm->mmap_base - len;
4644 +
4645 + while (!IS_ERR_VALUE(addr)) {
4646 /* Go down by chunk size */
4647 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4648 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4649
4650 /* Check for hit with different page size */
4651 mask = slice_range_to_mask(addr, len);
4652 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4653 * return with success:
4654 */
4655 vma = find_vma(mm, addr);
4656 - if (!vma || (addr + len) <= vma->vm_start) {
4657 + if (check_heap_stack_gap(vma, addr, len)) {
4658 /* remember the address as a hint for next time */
4659 if (use_cache)
4660 mm->free_area_cache = addr;
4661 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4662 mm->cached_hole_size = vma->vm_start - addr;
4663
4664 /* try just below the current vma->vm_start */
4665 - addr = vma->vm_start;
4666 + addr = skip_heap_stack_gap(vma, len);
4667 }
4668
4669 /*
4670 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4671 if (fixed && addr > (mm->task_size - len))
4672 return -EINVAL;
4673
4674 +#ifdef CONFIG_PAX_RANDMMAP
4675 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4676 + addr = 0;
4677 +#endif
4678 +
4679 /* If hint, make sure it matches our alignment restrictions */
4680 if (!fixed && addr) {
4681 addr = _ALIGN_UP(addr, 1ul << pshift);
4682 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4683 index 748347b..81bc6c7 100644
4684 --- a/arch/s390/include/asm/atomic.h
4685 +++ b/arch/s390/include/asm/atomic.h
4686 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4687 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4688 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4689
4690 +#define atomic64_read_unchecked(v) atomic64_read(v)
4691 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4692 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4693 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4694 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4695 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4696 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4697 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4698 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4699 +
4700 #define smp_mb__before_atomic_dec() smp_mb()
4701 #define smp_mb__after_atomic_dec() smp_mb()
4702 #define smp_mb__before_atomic_inc() smp_mb()
4703 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4704 index 2a30d5a..5e5586f 100644
4705 --- a/arch/s390/include/asm/cache.h
4706 +++ b/arch/s390/include/asm/cache.h
4707 @@ -11,8 +11,10 @@
4708 #ifndef __ARCH_S390_CACHE_H
4709 #define __ARCH_S390_CACHE_H
4710
4711 -#define L1_CACHE_BYTES 256
4712 +#include <linux/const.h>
4713 +
4714 #define L1_CACHE_SHIFT 8
4715 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4716 #define NET_SKB_PAD 32
4717
4718 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4719 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4720 index 06151e6..598f9a5 100644
4721 --- a/arch/s390/include/asm/elf.h
4722 +++ b/arch/s390/include/asm/elf.h
4723 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4724 the loader. We need to make sure that it is out of the way of the program
4725 that it will "exec", and that there is sufficient room for the brk. */
4726
4727 -extern unsigned long randomize_et_dyn(unsigned long base);
4728 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4729 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4730 +
4731 +#ifdef CONFIG_PAX_ASLR
4732 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4733 +
4734 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4735 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4736 +#endif
4737
4738 /* This yields a mask that user programs can use to figure out what
4739 instruction set this CPU supports. */
4740 @@ -182,7 +188,8 @@ extern char elf_platform[];
4741 #define ELF_PLATFORM (elf_platform)
4742
4743 #ifndef CONFIG_64BIT
4744 -#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
4745 +#define SET_PERSONALITY(ex) \
4746 + set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
4747 #else /* CONFIG_64BIT */
4748 #define SET_PERSONALITY(ex) \
4749 do { \
4750 @@ -210,7 +217,4 @@ struct linux_binprm;
4751 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4752 int arch_setup_additional_pages(struct linux_binprm *, int);
4753
4754 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4755 -#define arch_randomize_brk arch_randomize_brk
4756 -
4757 #endif
4758 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4759 index c4a93d6..4d2a9b4 100644
4760 --- a/arch/s390/include/asm/exec.h
4761 +++ b/arch/s390/include/asm/exec.h
4762 @@ -7,6 +7,6 @@
4763 #ifndef __ASM_EXEC_H
4764 #define __ASM_EXEC_H
4765
4766 -extern unsigned long arch_align_stack(unsigned long sp);
4767 +#define arch_align_stack(x) ((x) & ~0xfUL)
4768
4769 #endif /* __ASM_EXEC_H */
4770 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4771 index 1f3a79b..44d7f9c 100644
4772 --- a/arch/s390/include/asm/uaccess.h
4773 +++ b/arch/s390/include/asm/uaccess.h
4774 @@ -241,6 +241,10 @@ static inline unsigned long __must_check
4775 copy_to_user(void __user *to, const void *from, unsigned long n)
4776 {
4777 might_fault();
4778 +
4779 + if ((long)n < 0)
4780 + return n;
4781 +
4782 if (access_ok(VERIFY_WRITE, to, n))
4783 n = __copy_to_user(to, from, n);
4784 return n;
4785 @@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4786 static inline unsigned long __must_check
4787 __copy_from_user(void *to, const void __user *from, unsigned long n)
4788 {
4789 + if ((long)n < 0)
4790 + return n;
4791 +
4792 if (__builtin_constant_p(n) && (n <= 256))
4793 return uaccess.copy_from_user_small(n, from, to);
4794 else
4795 @@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4796 static inline unsigned long __must_check
4797 copy_from_user(void *to, const void __user *from, unsigned long n)
4798 {
4799 - unsigned int sz = __compiletime_object_size(to);
4800 + size_t sz = __compiletime_object_size(to);
4801
4802 might_fault();
4803 - if (unlikely(sz != -1 && sz < n)) {
4804 +
4805 + if ((long)n < 0)
4806 + return n;
4807 +
4808 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4809 copy_from_user_overflow();
4810 return n;
4811 }
4812 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4813 index dfcb343..eda788a 100644
4814 --- a/arch/s390/kernel/module.c
4815 +++ b/arch/s390/kernel/module.c
4816 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4817
4818 /* Increase core size by size of got & plt and set start
4819 offsets for got and plt. */
4820 - me->core_size = ALIGN(me->core_size, 4);
4821 - me->arch.got_offset = me->core_size;
4822 - me->core_size += me->arch.got_size;
4823 - me->arch.plt_offset = me->core_size;
4824 - me->core_size += me->arch.plt_size;
4825 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4826 + me->arch.got_offset = me->core_size_rw;
4827 + me->core_size_rw += me->arch.got_size;
4828 + me->arch.plt_offset = me->core_size_rx;
4829 + me->core_size_rx += me->arch.plt_size;
4830 return 0;
4831 }
4832
4833 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4834 if (info->got_initialized == 0) {
4835 Elf_Addr *gotent;
4836
4837 - gotent = me->module_core + me->arch.got_offset +
4838 + gotent = me->module_core_rw + me->arch.got_offset +
4839 info->got_offset;
4840 *gotent = val;
4841 info->got_initialized = 1;
4842 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4843 else if (r_type == R_390_GOTENT ||
4844 r_type == R_390_GOTPLTENT)
4845 *(unsigned int *) loc =
4846 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4847 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4848 else if (r_type == R_390_GOT64 ||
4849 r_type == R_390_GOTPLT64)
4850 *(unsigned long *) loc = val;
4851 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4852 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4853 if (info->plt_initialized == 0) {
4854 unsigned int *ip;
4855 - ip = me->module_core + me->arch.plt_offset +
4856 + ip = me->module_core_rx + me->arch.plt_offset +
4857 info->plt_offset;
4858 #ifndef CONFIG_64BIT
4859 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4860 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4861 val - loc + 0xffffUL < 0x1ffffeUL) ||
4862 (r_type == R_390_PLT32DBL &&
4863 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4864 - val = (Elf_Addr) me->module_core +
4865 + val = (Elf_Addr) me->module_core_rx +
4866 me->arch.plt_offset +
4867 info->plt_offset;
4868 val += rela->r_addend - loc;
4869 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4870 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4871 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4872 val = val + rela->r_addend -
4873 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4874 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4875 if (r_type == R_390_GOTOFF16)
4876 *(unsigned short *) loc = val;
4877 else if (r_type == R_390_GOTOFF32)
4878 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4879 break;
4880 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4881 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4882 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4883 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4884 rela->r_addend - loc;
4885 if (r_type == R_390_GOTPC)
4886 *(unsigned int *) loc = val;
4887 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4888 index 60055ce..ee4b252 100644
4889 --- a/arch/s390/kernel/process.c
4890 +++ b/arch/s390/kernel/process.c
4891 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4892 }
4893 return 0;
4894 }
4895 -
4896 -unsigned long arch_align_stack(unsigned long sp)
4897 -{
4898 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4899 - sp -= get_random_int() & ~PAGE_MASK;
4900 - return sp & ~0xf;
4901 -}
4902 -
4903 -static inline unsigned long brk_rnd(void)
4904 -{
4905 - /* 8MB for 32bit, 1GB for 64bit */
4906 - if (is_32bit_task())
4907 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4908 - else
4909 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4910 -}
4911 -
4912 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4913 -{
4914 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4915 -
4916 - if (ret < mm->brk)
4917 - return mm->brk;
4918 - return ret;
4919 -}
4920 -
4921 -unsigned long randomize_et_dyn(unsigned long base)
4922 -{
4923 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4924 -
4925 - if (!(current->flags & PF_RANDOMIZE))
4926 - return base;
4927 - if (ret < base)
4928 - return base;
4929 - return ret;
4930 -}
4931 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4932 index a64fe53..5c66963 100644
4933 --- a/arch/s390/mm/mmap.c
4934 +++ b/arch/s390/mm/mmap.c
4935 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4936 */
4937 if (mmap_is_legacy()) {
4938 mm->mmap_base = TASK_UNMAPPED_BASE;
4939 +
4940 +#ifdef CONFIG_PAX_RANDMMAP
4941 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4942 + mm->mmap_base += mm->delta_mmap;
4943 +#endif
4944 +
4945 mm->get_unmapped_area = arch_get_unmapped_area;
4946 mm->unmap_area = arch_unmap_area;
4947 } else {
4948 mm->mmap_base = mmap_base();
4949 +
4950 +#ifdef CONFIG_PAX_RANDMMAP
4951 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4952 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4953 +#endif
4954 +
4955 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4956 mm->unmap_area = arch_unmap_area_topdown;
4957 }
4958 @@ -174,10 +186,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4959 */
4960 if (mmap_is_legacy()) {
4961 mm->mmap_base = TASK_UNMAPPED_BASE;
4962 +
4963 +#ifdef CONFIG_PAX_RANDMMAP
4964 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4965 + mm->mmap_base += mm->delta_mmap;
4966 +#endif
4967 +
4968 mm->get_unmapped_area = s390_get_unmapped_area;
4969 mm->unmap_area = arch_unmap_area;
4970 } else {
4971 mm->mmap_base = mmap_base();
4972 +
4973 +#ifdef CONFIG_PAX_RANDMMAP
4974 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4975 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4976 +#endif
4977 +
4978 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4979 mm->unmap_area = arch_unmap_area_topdown;
4980 }
4981 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4982 index ae3d59f..f65f075 100644
4983 --- a/arch/score/include/asm/cache.h
4984 +++ b/arch/score/include/asm/cache.h
4985 @@ -1,7 +1,9 @@
4986 #ifndef _ASM_SCORE_CACHE_H
4987 #define _ASM_SCORE_CACHE_H
4988
4989 +#include <linux/const.h>
4990 +
4991 #define L1_CACHE_SHIFT 4
4992 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4993 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4994
4995 #endif /* _ASM_SCORE_CACHE_H */
4996 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4997 index f9f3cd5..58ff438 100644
4998 --- a/arch/score/include/asm/exec.h
4999 +++ b/arch/score/include/asm/exec.h
5000 @@ -1,6 +1,6 @@
5001 #ifndef _ASM_SCORE_EXEC_H
5002 #define _ASM_SCORE_EXEC_H
5003
5004 -extern unsigned long arch_align_stack(unsigned long sp);
5005 +#define arch_align_stack(x) (x)
5006
5007 #endif /* _ASM_SCORE_EXEC_H */
5008 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5009 index 2707023..1c2a3b7 100644
5010 --- a/arch/score/kernel/process.c
5011 +++ b/arch/score/kernel/process.c
5012 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
5013
5014 return task_pt_regs(task)->cp0_epc;
5015 }
5016 -
5017 -unsigned long arch_align_stack(unsigned long sp)
5018 -{
5019 - return sp;
5020 -}
5021 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5022 index ef9e555..331bd29 100644
5023 --- a/arch/sh/include/asm/cache.h
5024 +++ b/arch/sh/include/asm/cache.h
5025 @@ -9,10 +9,11 @@
5026 #define __ASM_SH_CACHE_H
5027 #ifdef __KERNEL__
5028
5029 +#include <linux/const.h>
5030 #include <linux/init.h>
5031 #include <cpu/cache.h>
5032
5033 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5034 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5035
5036 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5037
5038 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5039 index afeb710..d1d1289 100644
5040 --- a/arch/sh/mm/mmap.c
5041 +++ b/arch/sh/mm/mmap.c
5042 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5043 addr = PAGE_ALIGN(addr);
5044
5045 vma = find_vma(mm, addr);
5046 - if (TASK_SIZE - len >= addr &&
5047 - (!vma || addr + len <= vma->vm_start))
5048 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5049 return addr;
5050 }
5051
5052 @@ -106,7 +105,7 @@ full_search:
5053 }
5054 return -ENOMEM;
5055 }
5056 - if (likely(!vma || addr + len <= vma->vm_start)) {
5057 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5058 /*
5059 * Remember the place where we stopped the search:
5060 */
5061 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5062 addr = PAGE_ALIGN(addr);
5063
5064 vma = find_vma(mm, addr);
5065 - if (TASK_SIZE - len >= addr &&
5066 - (!vma || addr + len <= vma->vm_start))
5067 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5068 return addr;
5069 }
5070
5071 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5072 /* make sure it can fit in the remaining address space */
5073 if (likely(addr > len)) {
5074 vma = find_vma(mm, addr-len);
5075 - if (!vma || addr <= vma->vm_start) {
5076 + if (check_heap_stack_gap(vma, addr - len, len)) {
5077 /* remember the address as a hint for next time */
5078 return (mm->free_area_cache = addr-len);
5079 }
5080 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5081 if (unlikely(mm->mmap_base < len))
5082 goto bottomup;
5083
5084 - addr = mm->mmap_base-len;
5085 - if (do_colour_align)
5086 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5087 + addr = mm->mmap_base - len;
5088
5089 do {
5090 + if (do_colour_align)
5091 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5092 /*
5093 * Lookup failure means no vma is above this address,
5094 * else if new region fits below vma->vm_start,
5095 * return with success:
5096 */
5097 vma = find_vma(mm, addr);
5098 - if (likely(!vma || addr+len <= vma->vm_start)) {
5099 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5100 /* remember the address as a hint for next time */
5101 return (mm->free_area_cache = addr);
5102 }
5103 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5104 mm->cached_hole_size = vma->vm_start - addr;
5105
5106 /* try just below the current vma->vm_start */
5107 - addr = vma->vm_start-len;
5108 - if (do_colour_align)
5109 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5110 - } while (likely(len < vma->vm_start));
5111 + addr = skip_heap_stack_gap(vma, len);
5112 + } while (!IS_ERR_VALUE(addr));
5113
5114 bottomup:
5115 /*
5116 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5117 index ce35a1c..2e7b8f9 100644
5118 --- a/arch/sparc/include/asm/atomic_64.h
5119 +++ b/arch/sparc/include/asm/atomic_64.h
5120 @@ -14,18 +14,40 @@
5121 #define ATOMIC64_INIT(i) { (i) }
5122
5123 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5124 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5125 +{
5126 + return v->counter;
5127 +}
5128 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5129 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5130 +{
5131 + return v->counter;
5132 +}
5133
5134 #define atomic_set(v, i) (((v)->counter) = i)
5135 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5136 +{
5137 + v->counter = i;
5138 +}
5139 #define atomic64_set(v, i) (((v)->counter) = i)
5140 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5141 +{
5142 + v->counter = i;
5143 +}
5144
5145 extern void atomic_add(int, atomic_t *);
5146 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5147 extern void atomic64_add(long, atomic64_t *);
5148 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5149 extern void atomic_sub(int, atomic_t *);
5150 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5151 extern void atomic64_sub(long, atomic64_t *);
5152 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5153
5154 extern int atomic_add_ret(int, atomic_t *);
5155 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5156 extern long atomic64_add_ret(long, atomic64_t *);
5157 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5158 extern int atomic_sub_ret(int, atomic_t *);
5159 extern long atomic64_sub_ret(long, atomic64_t *);
5160
5161 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5162 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5163
5164 #define atomic_inc_return(v) atomic_add_ret(1, v)
5165 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5166 +{
5167 + return atomic_add_ret_unchecked(1, v);
5168 +}
5169 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5170 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5171 +{
5172 + return atomic64_add_ret_unchecked(1, v);
5173 +}
5174
5175 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5176 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5177
5178 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5179 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5180 +{
5181 + return atomic_add_ret_unchecked(i, v);
5182 +}
5183 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5184 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5185 +{
5186 + return atomic64_add_ret_unchecked(i, v);
5187 +}
5188
5189 /*
5190 * atomic_inc_and_test - increment and test
5191 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5192 * other cases.
5193 */
5194 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5195 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5196 +{
5197 + return atomic_inc_return_unchecked(v) == 0;
5198 +}
5199 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5200
5201 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5202 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5203 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5204
5205 #define atomic_inc(v) atomic_add(1, v)
5206 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5207 +{
5208 + atomic_add_unchecked(1, v);
5209 +}
5210 #define atomic64_inc(v) atomic64_add(1, v)
5211 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5212 +{
5213 + atomic64_add_unchecked(1, v);
5214 +}
5215
5216 #define atomic_dec(v) atomic_sub(1, v)
5217 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5218 +{
5219 + atomic_sub_unchecked(1, v);
5220 +}
5221 #define atomic64_dec(v) atomic64_sub(1, v)
5222 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5223 +{
5224 + atomic64_sub_unchecked(1, v);
5225 +}
5226
5227 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5228 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5229
5230 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5231 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5232 +{
5233 + return cmpxchg(&v->counter, old, new);
5234 +}
5235 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5236 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5237 +{
5238 + return xchg(&v->counter, new);
5239 +}
5240
5241 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5242 {
5243 - int c, old;
5244 + int c, old, new;
5245 c = atomic_read(v);
5246 for (;;) {
5247 - if (unlikely(c == (u)))
5248 + if (unlikely(c == u))
5249 break;
5250 - old = atomic_cmpxchg((v), c, c + (a));
5251 +
5252 + asm volatile("addcc %2, %0, %0\n"
5253 +
5254 +#ifdef CONFIG_PAX_REFCOUNT
5255 + "tvs %%icc, 6\n"
5256 +#endif
5257 +
5258 + : "=r" (new)
5259 + : "0" (c), "ir" (a)
5260 + : "cc");
5261 +
5262 + old = atomic_cmpxchg(v, c, new);
5263 if (likely(old == c))
5264 break;
5265 c = old;
5266 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5267 #define atomic64_cmpxchg(v, o, n) \
5268 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5269 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5270 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5271 +{
5272 + return xchg(&v->counter, new);
5273 +}
5274
5275 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5276 {
5277 - long c, old;
5278 + long c, old, new;
5279 c = atomic64_read(v);
5280 for (;;) {
5281 - if (unlikely(c == (u)))
5282 + if (unlikely(c == u))
5283 break;
5284 - old = atomic64_cmpxchg((v), c, c + (a));
5285 +
5286 + asm volatile("addcc %2, %0, %0\n"
5287 +
5288 +#ifdef CONFIG_PAX_REFCOUNT
5289 + "tvs %%xcc, 6\n"
5290 +#endif
5291 +
5292 + : "=r" (new)
5293 + : "0" (c), "ir" (a)
5294 + : "cc");
5295 +
5296 + old = atomic64_cmpxchg(v, c, new);
5297 if (likely(old == c))
5298 break;
5299 c = old;
5300 }
5301 - return c != (u);
5302 + return c != u;
5303 }
5304
5305 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5306 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5307 index 5bb6991..5c2132e 100644
5308 --- a/arch/sparc/include/asm/cache.h
5309 +++ b/arch/sparc/include/asm/cache.h
5310 @@ -7,10 +7,12 @@
5311 #ifndef _SPARC_CACHE_H
5312 #define _SPARC_CACHE_H
5313
5314 +#include <linux/const.h>
5315 +
5316 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5317
5318 #define L1_CACHE_SHIFT 5
5319 -#define L1_CACHE_BYTES 32
5320 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5321
5322 #ifdef CONFIG_SPARC32
5323 #define SMP_CACHE_BYTES_SHIFT 5
5324 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5325 index 2d4d755..81b6662 100644
5326 --- a/arch/sparc/include/asm/elf_32.h
5327 +++ b/arch/sparc/include/asm/elf_32.h
5328 @@ -114,6 +114,13 @@ typedef struct {
5329
5330 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5331
5332 +#ifdef CONFIG_PAX_ASLR
5333 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5334 +
5335 +#define PAX_DELTA_MMAP_LEN 16
5336 +#define PAX_DELTA_STACK_LEN 16
5337 +#endif
5338 +
5339 /* This yields a mask that user programs can use to figure out what
5340 instruction set this cpu supports. This can NOT be done in userspace
5341 on Sparc. */
5342 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5343 index 7df8b7f..4946269 100644
5344 --- a/arch/sparc/include/asm/elf_64.h
5345 +++ b/arch/sparc/include/asm/elf_64.h
5346 @@ -180,6 +180,13 @@ typedef struct {
5347 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5348 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5349
5350 +#ifdef CONFIG_PAX_ASLR
5351 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5352 +
5353 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5354 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5355 +#endif
5356 +
5357 extern unsigned long sparc64_elf_hwcap;
5358 #define ELF_HWCAP sparc64_elf_hwcap
5359
5360 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5361 index e5b169b46..e90b4fa 100644
5362 --- a/arch/sparc/include/asm/pgalloc_32.h
5363 +++ b/arch/sparc/include/asm/pgalloc_32.h
5364 @@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5365 }
5366
5367 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5368 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5369
5370 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5371 unsigned long address)
5372 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5373 index 40b2d7a..22a665b 100644
5374 --- a/arch/sparc/include/asm/pgalloc_64.h
5375 +++ b/arch/sparc/include/asm/pgalloc_64.h
5376 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5377 }
5378
5379 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5380 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5381
5382 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5383 {
5384 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5385 index cbbbed5..0983069 100644
5386 --- a/arch/sparc/include/asm/pgtable_32.h
5387 +++ b/arch/sparc/include/asm/pgtable_32.h
5388 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5389 #define PAGE_SHARED SRMMU_PAGE_SHARED
5390 #define PAGE_COPY SRMMU_PAGE_COPY
5391 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5392 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5393 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5394 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5395 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5396
5397 /* Top-level page directory */
5398 @@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5399
5400 /* xwr */
5401 #define __P000 PAGE_NONE
5402 -#define __P001 PAGE_READONLY
5403 -#define __P010 PAGE_COPY
5404 -#define __P011 PAGE_COPY
5405 +#define __P001 PAGE_READONLY_NOEXEC
5406 +#define __P010 PAGE_COPY_NOEXEC
5407 +#define __P011 PAGE_COPY_NOEXEC
5408 #define __P100 PAGE_READONLY
5409 #define __P101 PAGE_READONLY
5410 #define __P110 PAGE_COPY
5411 #define __P111 PAGE_COPY
5412
5413 #define __S000 PAGE_NONE
5414 -#define __S001 PAGE_READONLY
5415 -#define __S010 PAGE_SHARED
5416 -#define __S011 PAGE_SHARED
5417 +#define __S001 PAGE_READONLY_NOEXEC
5418 +#define __S010 PAGE_SHARE_NOEXEC
5419 +#define __S011 PAGE_SHARE_NOEXEC
5420 #define __S100 PAGE_READONLY
5421 #define __S101 PAGE_READONLY
5422 #define __S110 PAGE_SHARED
5423 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5424 index 79da178..c2eede8 100644
5425 --- a/arch/sparc/include/asm/pgtsrmmu.h
5426 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5427 @@ -115,6 +115,11 @@
5428 SRMMU_EXEC | SRMMU_REF)
5429 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5430 SRMMU_EXEC | SRMMU_REF)
5431 +
5432 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5433 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5434 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5435 +
5436 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5437 SRMMU_DIRTY | SRMMU_REF)
5438
5439 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5440 index 9689176..63c18ea 100644
5441 --- a/arch/sparc/include/asm/spinlock_64.h
5442 +++ b/arch/sparc/include/asm/spinlock_64.h
5443 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5444
5445 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5446
5447 -static void inline arch_read_lock(arch_rwlock_t *lock)
5448 +static inline void arch_read_lock(arch_rwlock_t *lock)
5449 {
5450 unsigned long tmp1, tmp2;
5451
5452 __asm__ __volatile__ (
5453 "1: ldsw [%2], %0\n"
5454 " brlz,pn %0, 2f\n"
5455 -"4: add %0, 1, %1\n"
5456 +"4: addcc %0, 1, %1\n"
5457 +
5458 +#ifdef CONFIG_PAX_REFCOUNT
5459 +" tvs %%icc, 6\n"
5460 +#endif
5461 +
5462 " cas [%2], %0, %1\n"
5463 " cmp %0, %1\n"
5464 " bne,pn %%icc, 1b\n"
5465 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5466 " .previous"
5467 : "=&r" (tmp1), "=&r" (tmp2)
5468 : "r" (lock)
5469 - : "memory");
5470 + : "memory", "cc");
5471 }
5472
5473 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5474 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5475 {
5476 int tmp1, tmp2;
5477
5478 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5479 "1: ldsw [%2], %0\n"
5480 " brlz,a,pn %0, 2f\n"
5481 " mov 0, %0\n"
5482 -" add %0, 1, %1\n"
5483 +" addcc %0, 1, %1\n"
5484 +
5485 +#ifdef CONFIG_PAX_REFCOUNT
5486 +" tvs %%icc, 6\n"
5487 +#endif
5488 +
5489 " cas [%2], %0, %1\n"
5490 " cmp %0, %1\n"
5491 " bne,pn %%icc, 1b\n"
5492 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5493 return tmp1;
5494 }
5495
5496 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5497 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5498 {
5499 unsigned long tmp1, tmp2;
5500
5501 __asm__ __volatile__(
5502 "1: lduw [%2], %0\n"
5503 -" sub %0, 1, %1\n"
5504 +" subcc %0, 1, %1\n"
5505 +
5506 +#ifdef CONFIG_PAX_REFCOUNT
5507 +" tvs %%icc, 6\n"
5508 +#endif
5509 +
5510 " cas [%2], %0, %1\n"
5511 " cmp %0, %1\n"
5512 " bne,pn %%xcc, 1b\n"
5513 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5514 : "memory");
5515 }
5516
5517 -static void inline arch_write_lock(arch_rwlock_t *lock)
5518 +static inline void arch_write_lock(arch_rwlock_t *lock)
5519 {
5520 unsigned long mask, tmp1, tmp2;
5521
5522 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5523 : "memory");
5524 }
5525
5526 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5527 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5528 {
5529 __asm__ __volatile__(
5530 " stw %%g0, [%0]"
5531 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5532 : "memory");
5533 }
5534
5535 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5536 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5537 {
5538 unsigned long mask, tmp1, tmp2, result;
5539
5540 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5541 index e6cd224..3a71793 100644
5542 --- a/arch/sparc/include/asm/thread_info_32.h
5543 +++ b/arch/sparc/include/asm/thread_info_32.h
5544 @@ -49,6 +49,8 @@ struct thread_info {
5545 unsigned long w_saved;
5546
5547 struct restart_block restart_block;
5548 +
5549 + unsigned long lowest_stack;
5550 };
5551
5552 /*
5553 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5554 index cfa8c38..13f30d3 100644
5555 --- a/arch/sparc/include/asm/thread_info_64.h
5556 +++ b/arch/sparc/include/asm/thread_info_64.h
5557 @@ -63,6 +63,8 @@ struct thread_info {
5558 struct pt_regs *kern_una_regs;
5559 unsigned int kern_una_insn;
5560
5561 + unsigned long lowest_stack;
5562 +
5563 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5564 };
5565
5566 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5567 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5568 /* flag bit 6 is available */
5569 #define TIF_32BIT 7 /* 32-bit binary */
5570 -/* flag bit 8 is available */
5571 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5572 #define TIF_SECCOMP 9 /* secure computing */
5573 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5574 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5575 +
5576 /* NOTE: Thread flags >= 12 should be ones we have no interest
5577 * in using in assembly, else we can't use the mask as
5578 * an immediate value in instructions such as andcc.
5579 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5580 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5581 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5582 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5583 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5584
5585 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5586 _TIF_DO_NOTIFY_RESUME_MASK | \
5587 _TIF_NEED_RESCHED)
5588 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5589
5590 +#define _TIF_WORK_SYSCALL \
5591 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5592 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5593 +
5594 +
5595 /*
5596 * Thread-synchronous status.
5597 *
5598 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5599 index 0167d26..9acd8ed 100644
5600 --- a/arch/sparc/include/asm/uaccess.h
5601 +++ b/arch/sparc/include/asm/uaccess.h
5602 @@ -1,5 +1,13 @@
5603 #ifndef ___ASM_SPARC_UACCESS_H
5604 #define ___ASM_SPARC_UACCESS_H
5605 +
5606 +#ifdef __KERNEL__
5607 +#ifndef __ASSEMBLY__
5608 +#include <linux/types.h>
5609 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5610 +#endif
5611 +#endif
5612 +
5613 #if defined(__sparc__) && defined(__arch64__)
5614 #include <asm/uaccess_64.h>
5615 #else
5616 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5617 index 53a28dd..50c38c3 100644
5618 --- a/arch/sparc/include/asm/uaccess_32.h
5619 +++ b/arch/sparc/include/asm/uaccess_32.h
5620 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5621
5622 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5623 {
5624 - if (n && __access_ok((unsigned long) to, n))
5625 + if ((long)n < 0)
5626 + return n;
5627 +
5628 + if (n && __access_ok((unsigned long) to, n)) {
5629 + if (!__builtin_constant_p(n))
5630 + check_object_size(from, n, true);
5631 return __copy_user(to, (__force void __user *) from, n);
5632 - else
5633 + } else
5634 return n;
5635 }
5636
5637 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5638 {
5639 + if ((long)n < 0)
5640 + return n;
5641 +
5642 + if (!__builtin_constant_p(n))
5643 + check_object_size(from, n, true);
5644 +
5645 return __copy_user(to, (__force void __user *) from, n);
5646 }
5647
5648 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5649 {
5650 - if (n && __access_ok((unsigned long) from, n))
5651 + if ((long)n < 0)
5652 + return n;
5653 +
5654 + if (n && __access_ok((unsigned long) from, n)) {
5655 + if (!__builtin_constant_p(n))
5656 + check_object_size(to, n, false);
5657 return __copy_user((__force void __user *) to, from, n);
5658 - else
5659 + } else
5660 return n;
5661 }
5662
5663 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5664 {
5665 + if ((long)n < 0)
5666 + return n;
5667 +
5668 return __copy_user((__force void __user *) to, from, n);
5669 }
5670
5671 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5672 index 7c831d8..d440ca7 100644
5673 --- a/arch/sparc/include/asm/uaccess_64.h
5674 +++ b/arch/sparc/include/asm/uaccess_64.h
5675 @@ -10,6 +10,7 @@
5676 #include <linux/compiler.h>
5677 #include <linux/string.h>
5678 #include <linux/thread_info.h>
5679 +#include <linux/kernel.h>
5680 #include <asm/asi.h>
5681 #include <asm/spitfire.h>
5682 #include <asm-generic/uaccess-unaligned.h>
5683 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5684 static inline unsigned long __must_check
5685 copy_from_user(void *to, const void __user *from, unsigned long size)
5686 {
5687 - unsigned long ret = ___copy_from_user(to, from, size);
5688 + unsigned long ret;
5689
5690 + if ((long)size < 0 || size > INT_MAX)
5691 + return size;
5692 +
5693 + if (!__builtin_constant_p(size))
5694 + check_object_size(to, size, false);
5695 +
5696 + ret = ___copy_from_user(to, from, size);
5697 if (unlikely(ret))
5698 ret = copy_from_user_fixup(to, from, size);
5699
5700 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5701 static inline unsigned long __must_check
5702 copy_to_user(void __user *to, const void *from, unsigned long size)
5703 {
5704 - unsigned long ret = ___copy_to_user(to, from, size);
5705 + unsigned long ret;
5706
5707 + if ((long)size < 0 || size > INT_MAX)
5708 + return size;
5709 +
5710 + if (!__builtin_constant_p(size))
5711 + check_object_size(from, size, true);
5712 +
5713 + ret = ___copy_to_user(to, from, size);
5714 if (unlikely(ret))
5715 ret = copy_to_user_fixup(to, from, size);
5716 return ret;
5717 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5718 index 6cf591b..b49e65a 100644
5719 --- a/arch/sparc/kernel/Makefile
5720 +++ b/arch/sparc/kernel/Makefile
5721 @@ -3,7 +3,7 @@
5722 #
5723
5724 asflags-y := -ansi
5725 -ccflags-y := -Werror
5726 +#ccflags-y := -Werror
5727
5728 extra-y := head_$(BITS).o
5729
5730 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5731 index cb36e82..1c1462f 100644
5732 --- a/arch/sparc/kernel/process_32.c
5733 +++ b/arch/sparc/kernel/process_32.c
5734 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5735
5736 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5737 r->psr, r->pc, r->npc, r->y, print_tainted());
5738 - printk("PC: <%pS>\n", (void *) r->pc);
5739 + printk("PC: <%pA>\n", (void *) r->pc);
5740 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5741 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5742 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5743 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5744 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5745 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5746 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5747 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5748
5749 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5750 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5751 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5752 rw = (struct reg_window32 *) fp;
5753 pc = rw->ins[7];
5754 printk("[%08lx : ", pc);
5755 - printk("%pS ] ", (void *) pc);
5756 + printk("%pA ] ", (void *) pc);
5757 fp = rw->ins[6];
5758 } while (++count < 16);
5759 printk("\n");
5760 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5761 index aff0c72..9067b39 100644
5762 --- a/arch/sparc/kernel/process_64.c
5763 +++ b/arch/sparc/kernel/process_64.c
5764 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5765 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5766 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5767 if (regs->tstate & TSTATE_PRIV)
5768 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5769 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5770 }
5771
5772 void show_regs(struct pt_regs *regs)
5773 {
5774 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5775 regs->tpc, regs->tnpc, regs->y, print_tainted());
5776 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5777 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5778 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5779 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5780 regs->u_regs[3]);
5781 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5782 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5783 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5784 regs->u_regs[15]);
5785 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5786 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5787 show_regwindow(regs);
5788 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5789 }
5790 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5791 ((tp && tp->task) ? tp->task->pid : -1));
5792
5793 if (gp->tstate & TSTATE_PRIV) {
5794 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5795 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5796 (void *) gp->tpc,
5797 (void *) gp->o7,
5798 (void *) gp->i7,
5799 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5800 index 484daba..0674139 100644
5801 --- a/arch/sparc/kernel/ptrace_64.c
5802 +++ b/arch/sparc/kernel/ptrace_64.c
5803 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5804 return ret;
5805 }
5806
5807 +#ifdef CONFIG_GRKERNSEC_SETXID
5808 +extern void gr_delayed_cred_worker(void);
5809 +#endif
5810 +
5811 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5812 {
5813 int ret = 0;
5814 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5815 /* do the secure computing check first */
5816 secure_computing_strict(regs->u_regs[UREG_G1]);
5817
5818 +#ifdef CONFIG_GRKERNSEC_SETXID
5819 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5820 + gr_delayed_cred_worker();
5821 +#endif
5822 +
5823 if (test_thread_flag(TIF_SYSCALL_TRACE))
5824 ret = tracehook_report_syscall_entry(regs);
5825
5826 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5827
5828 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5829 {
5830 +#ifdef CONFIG_GRKERNSEC_SETXID
5831 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5832 + gr_delayed_cred_worker();
5833 +#endif
5834 +
5835 audit_syscall_exit(regs);
5836
5837 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5838 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5839 index 0c9b31b..7cb7aee 100644
5840 --- a/arch/sparc/kernel/sys_sparc_32.c
5841 +++ b/arch/sparc/kernel/sys_sparc_32.c
5842 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5843 if (len > TASK_SIZE - PAGE_SIZE)
5844 return -ENOMEM;
5845 if (!addr)
5846 - addr = TASK_UNMAPPED_BASE;
5847 + addr = current->mm->mmap_base;
5848
5849 if (flags & MAP_SHARED)
5850 addr = COLOUR_ALIGN(addr);
5851 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5852 /* At this point: (!vmm || addr < vmm->vm_end). */
5853 if (TASK_SIZE - PAGE_SIZE - len < addr)
5854 return -ENOMEM;
5855 - if (!vmm || addr + len <= vmm->vm_start)
5856 + if (check_heap_stack_gap(vmm, addr, len))
5857 return addr;
5858 addr = vmm->vm_end;
5859 if (flags & MAP_SHARED)
5860 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5861 index 275f74f..81bf5b8 100644
5862 --- a/arch/sparc/kernel/sys_sparc_64.c
5863 +++ b/arch/sparc/kernel/sys_sparc_64.c
5864 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5865 /* We do not accept a shared mapping if it would violate
5866 * cache aliasing constraints.
5867 */
5868 - if ((flags & MAP_SHARED) &&
5869 + if ((filp || (flags & MAP_SHARED)) &&
5870 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5871 return -EINVAL;
5872 return addr;
5873 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5874 if (filp || (flags & MAP_SHARED))
5875 do_color_align = 1;
5876
5877 +#ifdef CONFIG_PAX_RANDMMAP
5878 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5879 +#endif
5880 +
5881 if (addr) {
5882 if (do_color_align)
5883 addr = COLOUR_ALIGN(addr, pgoff);
5884 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5885 addr = PAGE_ALIGN(addr);
5886
5887 vma = find_vma(mm, addr);
5888 - if (task_size - len >= addr &&
5889 - (!vma || addr + len <= vma->vm_start))
5890 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5891 return addr;
5892 }
5893
5894 if (len > mm->cached_hole_size) {
5895 - start_addr = addr = mm->free_area_cache;
5896 + start_addr = addr = mm->free_area_cache;
5897 } else {
5898 - start_addr = addr = TASK_UNMAPPED_BASE;
5899 + start_addr = addr = mm->mmap_base;
5900 mm->cached_hole_size = 0;
5901 }
5902
5903 @@ -174,14 +177,14 @@ full_search:
5904 vma = find_vma(mm, VA_EXCLUDE_END);
5905 }
5906 if (unlikely(task_size < addr)) {
5907 - if (start_addr != TASK_UNMAPPED_BASE) {
5908 - start_addr = addr = TASK_UNMAPPED_BASE;
5909 + if (start_addr != mm->mmap_base) {
5910 + start_addr = addr = mm->mmap_base;
5911 mm->cached_hole_size = 0;
5912 goto full_search;
5913 }
5914 return -ENOMEM;
5915 }
5916 - if (likely(!vma || addr + len <= vma->vm_start)) {
5917 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5918 /*
5919 * Remember the place where we stopped the search:
5920 */
5921 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5922 /* We do not accept a shared mapping if it would violate
5923 * cache aliasing constraints.
5924 */
5925 - if ((flags & MAP_SHARED) &&
5926 + if ((filp || (flags & MAP_SHARED)) &&
5927 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5928 return -EINVAL;
5929 return addr;
5930 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5931 addr = PAGE_ALIGN(addr);
5932
5933 vma = find_vma(mm, addr);
5934 - if (task_size - len >= addr &&
5935 - (!vma || addr + len <= vma->vm_start))
5936 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5937 return addr;
5938 }
5939
5940 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5941 /* make sure it can fit in the remaining address space */
5942 if (likely(addr > len)) {
5943 vma = find_vma(mm, addr-len);
5944 - if (!vma || addr <= vma->vm_start) {
5945 + if (check_heap_stack_gap(vma, addr - len, len)) {
5946 /* remember the address as a hint for next time */
5947 return (mm->free_area_cache = addr-len);
5948 }
5949 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5950 if (unlikely(mm->mmap_base < len))
5951 goto bottomup;
5952
5953 - addr = mm->mmap_base-len;
5954 - if (do_color_align)
5955 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5956 + addr = mm->mmap_base - len;
5957
5958 do {
5959 + if (do_color_align)
5960 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5961 /*
5962 * Lookup failure means no vma is above this address,
5963 * else if new region fits below vma->vm_start,
5964 * return with success:
5965 */
5966 vma = find_vma(mm, addr);
5967 - if (likely(!vma || addr+len <= vma->vm_start)) {
5968 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5969 /* remember the address as a hint for next time */
5970 return (mm->free_area_cache = addr);
5971 }
5972 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5973 mm->cached_hole_size = vma->vm_start - addr;
5974
5975 /* try just below the current vma->vm_start */
5976 - addr = vma->vm_start-len;
5977 - if (do_color_align)
5978 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5979 - } while (likely(len < vma->vm_start));
5980 + addr = skip_heap_stack_gap(vma, len);
5981 + } while (!IS_ERR_VALUE(addr));
5982
5983 bottomup:
5984 /*
5985 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5986 gap == RLIM_INFINITY ||
5987 sysctl_legacy_va_layout) {
5988 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5989 +
5990 +#ifdef CONFIG_PAX_RANDMMAP
5991 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5992 + mm->mmap_base += mm->delta_mmap;
5993 +#endif
5994 +
5995 mm->get_unmapped_area = arch_get_unmapped_area;
5996 mm->unmap_area = arch_unmap_area;
5997 } else {
5998 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5999 gap = (task_size / 6 * 5);
6000
6001 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6002 +
6003 +#ifdef CONFIG_PAX_RANDMMAP
6004 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6005 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6006 +#endif
6007 +
6008 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6009 mm->unmap_area = arch_unmap_area_topdown;
6010 }
6011 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6012 index 1d7e274..b39c527 100644
6013 --- a/arch/sparc/kernel/syscalls.S
6014 +++ b/arch/sparc/kernel/syscalls.S
6015 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6016 #endif
6017 .align 32
6018 1: ldx [%g6 + TI_FLAGS], %l5
6019 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6020 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6021 be,pt %icc, rtrap
6022 nop
6023 call syscall_trace_leave
6024 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6025
6026 srl %i5, 0, %o5 ! IEU1
6027 srl %i2, 0, %o2 ! IEU0 Group
6028 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6029 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6030 bne,pn %icc, linux_syscall_trace32 ! CTI
6031 mov %i0, %l5 ! IEU1
6032 call %l7 ! CTI Group brk forced
6033 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6034
6035 mov %i3, %o3 ! IEU1
6036 mov %i4, %o4 ! IEU0 Group
6037 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6038 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6039 bne,pn %icc, linux_syscall_trace ! CTI Group
6040 mov %i0, %l5 ! IEU0
6041 2: call %l7 ! CTI Group brk forced
6042 @@ -226,7 +226,7 @@ ret_sys_call:
6043
6044 cmp %o0, -ERESTART_RESTARTBLOCK
6045 bgeu,pn %xcc, 1f
6046 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6047 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6048 80:
6049 /* System call success, clear Carry condition code. */
6050 andn %g3, %g2, %g3
6051 @@ -241,7 +241,7 @@ ret_sys_call:
6052 /* System call failure, set Carry condition code.
6053 * Also, get abs(errno) to return to the process.
6054 */
6055 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6056 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6057 sub %g0, %o0, %o0
6058 or %g3, %g2, %g3
6059 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6060 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6061 index a5785ea..405c5f7 100644
6062 --- a/arch/sparc/kernel/traps_32.c
6063 +++ b/arch/sparc/kernel/traps_32.c
6064 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6065 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6066 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6067
6068 +extern void gr_handle_kernel_exploit(void);
6069 +
6070 void die_if_kernel(char *str, struct pt_regs *regs)
6071 {
6072 static int die_counter;
6073 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6074 count++ < 30 &&
6075 (((unsigned long) rw) >= PAGE_OFFSET) &&
6076 !(((unsigned long) rw) & 0x7)) {
6077 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6078 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6079 (void *) rw->ins[7]);
6080 rw = (struct reg_window32 *)rw->ins[6];
6081 }
6082 }
6083 printk("Instruction DUMP:");
6084 instruction_dump ((unsigned long *) regs->pc);
6085 - if(regs->psr & PSR_PS)
6086 + if(regs->psr & PSR_PS) {
6087 + gr_handle_kernel_exploit();
6088 do_exit(SIGKILL);
6089 + }
6090 do_exit(SIGSEGV);
6091 }
6092
6093 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6094 index 3b05e66..6ea2917 100644
6095 --- a/arch/sparc/kernel/traps_64.c
6096 +++ b/arch/sparc/kernel/traps_64.c
6097 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6098 i + 1,
6099 p->trapstack[i].tstate, p->trapstack[i].tpc,
6100 p->trapstack[i].tnpc, p->trapstack[i].tt);
6101 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6102 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6103 }
6104 }
6105
6106 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6107
6108 lvl -= 0x100;
6109 if (regs->tstate & TSTATE_PRIV) {
6110 +
6111 +#ifdef CONFIG_PAX_REFCOUNT
6112 + if (lvl == 6)
6113 + pax_report_refcount_overflow(regs);
6114 +#endif
6115 +
6116 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6117 die_if_kernel(buffer, regs);
6118 }
6119 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6120 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6121 {
6122 char buffer[32];
6123 -
6124 +
6125 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6126 0, lvl, SIGTRAP) == NOTIFY_STOP)
6127 return;
6128
6129 +#ifdef CONFIG_PAX_REFCOUNT
6130 + if (lvl == 6)
6131 + pax_report_refcount_overflow(regs);
6132 +#endif
6133 +
6134 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6135
6136 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6137 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6138 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6139 printk("%s" "ERROR(%d): ",
6140 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6141 - printk("TPC<%pS>\n", (void *) regs->tpc);
6142 + printk("TPC<%pA>\n", (void *) regs->tpc);
6143 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6144 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6145 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6146 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6147 smp_processor_id(),
6148 (type & 0x1) ? 'I' : 'D',
6149 regs->tpc);
6150 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6151 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6152 panic("Irrecoverable Cheetah+ parity error.");
6153 }
6154
6155 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6156 smp_processor_id(),
6157 (type & 0x1) ? 'I' : 'D',
6158 regs->tpc);
6159 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6160 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6161 }
6162
6163 struct sun4v_error_entry {
6164 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6165
6166 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6167 regs->tpc, tl);
6168 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6169 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6170 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6171 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6172 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6173 (void *) regs->u_regs[UREG_I7]);
6174 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6175 "pte[%lx] error[%lx]\n",
6176 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6177
6178 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6179 regs->tpc, tl);
6180 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6181 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6182 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6183 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6184 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6185 (void *) regs->u_regs[UREG_I7]);
6186 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6187 "pte[%lx] error[%lx]\n",
6188 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6189 fp = (unsigned long)sf->fp + STACK_BIAS;
6190 }
6191
6192 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6193 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6195 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6196 int index = tsk->curr_ret_stack;
6197 if (tsk->ret_stack && index >= graph) {
6198 pc = tsk->ret_stack[index - graph].ret;
6199 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6200 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6201 graph++;
6202 }
6203 }
6204 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6205 return (struct reg_window *) (fp + STACK_BIAS);
6206 }
6207
6208 +extern void gr_handle_kernel_exploit(void);
6209 +
6210 void die_if_kernel(char *str, struct pt_regs *regs)
6211 {
6212 static int die_counter;
6213 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6214 while (rw &&
6215 count++ < 30 &&
6216 kstack_valid(tp, (unsigned long) rw)) {
6217 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6218 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6219 (void *) rw->ins[7]);
6220
6221 rw = kernel_stack_up(rw);
6222 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6223 }
6224 user_instruction_dump ((unsigned int __user *) regs->tpc);
6225 }
6226 - if (regs->tstate & TSTATE_PRIV)
6227 + if (regs->tstate & TSTATE_PRIV) {
6228 + gr_handle_kernel_exploit();
6229 do_exit(SIGKILL);
6230 + }
6231 do_exit(SIGSEGV);
6232 }
6233 EXPORT_SYMBOL(die_if_kernel);
6234 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6235 index f81d038..e7a4680 100644
6236 --- a/arch/sparc/kernel/unaligned_64.c
6237 +++ b/arch/sparc/kernel/unaligned_64.c
6238 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6239 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6240
6241 if (__ratelimit(&ratelimit)) {
6242 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6243 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6244 regs->tpc, (void *) regs->tpc);
6245 }
6246 }
6247 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6248 index dff4096..bd9a388 100644
6249 --- a/arch/sparc/lib/Makefile
6250 +++ b/arch/sparc/lib/Makefile
6251 @@ -2,7 +2,7 @@
6252 #
6253
6254 asflags-y := -ansi -DST_DIV0=0x02
6255 -ccflags-y := -Werror
6256 +#ccflags-y := -Werror
6257
6258 lib-$(CONFIG_SPARC32) += ashrdi3.o
6259 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6260 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6261 index 4d502da..527c48d 100644
6262 --- a/arch/sparc/lib/atomic_64.S
6263 +++ b/arch/sparc/lib/atomic_64.S
6264 @@ -17,7 +17,12 @@
6265 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6266 BACKOFF_SETUP(%o2)
6267 1: lduw [%o1], %g1
6268 - add %g1, %o0, %g7
6269 + addcc %g1, %o0, %g7
6270 +
6271 +#ifdef CONFIG_PAX_REFCOUNT
6272 + tvs %icc, 6
6273 +#endif
6274 +
6275 cas [%o1], %g1, %g7
6276 cmp %g1, %g7
6277 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6278 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6279 2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 ENDPROC(atomic_add)
6281
6282 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6283 + BACKOFF_SETUP(%o2)
6284 +1: lduw [%o1], %g1
6285 + add %g1, %o0, %g7
6286 + cas [%o1], %g1, %g7
6287 + cmp %g1, %g7
6288 + bne,pn %icc, 2f
6289 + nop
6290 + retl
6291 + nop
6292 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6293 +ENDPROC(atomic_add_unchecked)
6294 +
6295 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298 - sub %g1, %o0, %g7
6299 + subcc %g1, %o0, %g7
6300 +
6301 +#ifdef CONFIG_PAX_REFCOUNT
6302 + tvs %icc, 6
6303 +#endif
6304 +
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6309 2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 ENDPROC(atomic_sub)
6311
6312 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6313 + BACKOFF_SETUP(%o2)
6314 +1: lduw [%o1], %g1
6315 + sub %g1, %o0, %g7
6316 + cas [%o1], %g1, %g7
6317 + cmp %g1, %g7
6318 + bne,pn %icc, 2f
6319 + nop
6320 + retl
6321 + nop
6322 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6323 +ENDPROC(atomic_sub_unchecked)
6324 +
6325 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6326 BACKOFF_SETUP(%o2)
6327 1: lduw [%o1], %g1
6328 - add %g1, %o0, %g7
6329 + addcc %g1, %o0, %g7
6330 +
6331 +#ifdef CONFIG_PAX_REFCOUNT
6332 + tvs %icc, 6
6333 +#endif
6334 +
6335 cas [%o1], %g1, %g7
6336 cmp %g1, %g7
6337 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6338 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6339 2: BACKOFF_SPIN(%o2, %o3, 1b)
6340 ENDPROC(atomic_add_ret)
6341
6342 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6343 + BACKOFF_SETUP(%o2)
6344 +1: lduw [%o1], %g1
6345 + addcc %g1, %o0, %g7
6346 + cas [%o1], %g1, %g7
6347 + cmp %g1, %g7
6348 + bne,pn %icc, 2f
6349 + add %g7, %o0, %g7
6350 + sra %g7, 0, %o0
6351 + retl
6352 + nop
6353 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 +ENDPROC(atomic_add_ret_unchecked)
6355 +
6356 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6357 BACKOFF_SETUP(%o2)
6358 1: lduw [%o1], %g1
6359 - sub %g1, %o0, %g7
6360 + subcc %g1, %o0, %g7
6361 +
6362 +#ifdef CONFIG_PAX_REFCOUNT
6363 + tvs %icc, 6
6364 +#endif
6365 +
6366 cas [%o1], %g1, %g7
6367 cmp %g1, %g7
6368 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6369 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6370 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6371 BACKOFF_SETUP(%o2)
6372 1: ldx [%o1], %g1
6373 - add %g1, %o0, %g7
6374 + addcc %g1, %o0, %g7
6375 +
6376 +#ifdef CONFIG_PAX_REFCOUNT
6377 + tvs %xcc, 6
6378 +#endif
6379 +
6380 casx [%o1], %g1, %g7
6381 cmp %g1, %g7
6382 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6383 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6384 2: BACKOFF_SPIN(%o2, %o3, 1b)
6385 ENDPROC(atomic64_add)
6386
6387 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6388 + BACKOFF_SETUP(%o2)
6389 +1: ldx [%o1], %g1
6390 + addcc %g1, %o0, %g7
6391 + casx [%o1], %g1, %g7
6392 + cmp %g1, %g7
6393 + bne,pn %xcc, 2f
6394 + nop
6395 + retl
6396 + nop
6397 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6398 +ENDPROC(atomic64_add_unchecked)
6399 +
6400 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - sub %g1, %o0, %g7
6404 + subcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 ENDPROC(atomic64_sub)
6416
6417 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6418 + BACKOFF_SETUP(%o2)
6419 +1: ldx [%o1], %g1
6420 + subcc %g1, %o0, %g7
6421 + casx [%o1], %g1, %g7
6422 + cmp %g1, %g7
6423 + bne,pn %xcc, 2f
6424 + nop
6425 + retl
6426 + nop
6427 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6428 +ENDPROC(atomic64_sub_unchecked)
6429 +
6430 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6431 BACKOFF_SETUP(%o2)
6432 1: ldx [%o1], %g1
6433 - add %g1, %o0, %g7
6434 + addcc %g1, %o0, %g7
6435 +
6436 +#ifdef CONFIG_PAX_REFCOUNT
6437 + tvs %xcc, 6
6438 +#endif
6439 +
6440 casx [%o1], %g1, %g7
6441 cmp %g1, %g7
6442 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6443 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6444 2: BACKOFF_SPIN(%o2, %o3, 1b)
6445 ENDPROC(atomic64_add_ret)
6446
6447 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6448 + BACKOFF_SETUP(%o2)
6449 +1: ldx [%o1], %g1
6450 + addcc %g1, %o0, %g7
6451 + casx [%o1], %g1, %g7
6452 + cmp %g1, %g7
6453 + bne,pn %xcc, 2f
6454 + add %g7, %o0, %g7
6455 + mov %g7, %o0
6456 + retl
6457 + nop
6458 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6459 +ENDPROC(atomic64_add_ret_unchecked)
6460 +
6461 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6462 BACKOFF_SETUP(%o2)
6463 1: ldx [%o1], %g1
6464 - sub %g1, %o0, %g7
6465 + subcc %g1, %o0, %g7
6466 +
6467 +#ifdef CONFIG_PAX_REFCOUNT
6468 + tvs %xcc, 6
6469 +#endif
6470 +
6471 casx [%o1], %g1, %g7
6472 cmp %g1, %g7
6473 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6474 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6475 index 3b31218..345c609 100644
6476 --- a/arch/sparc/lib/ksyms.c
6477 +++ b/arch/sparc/lib/ksyms.c
6478 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6479
6480 /* Atomic counter implementation. */
6481 EXPORT_SYMBOL(atomic_add);
6482 +EXPORT_SYMBOL(atomic_add_unchecked);
6483 EXPORT_SYMBOL(atomic_add_ret);
6484 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6485 EXPORT_SYMBOL(atomic_sub);
6486 +EXPORT_SYMBOL(atomic_sub_unchecked);
6487 EXPORT_SYMBOL(atomic_sub_ret);
6488 EXPORT_SYMBOL(atomic64_add);
6489 +EXPORT_SYMBOL(atomic64_add_unchecked);
6490 EXPORT_SYMBOL(atomic64_add_ret);
6491 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6492 EXPORT_SYMBOL(atomic64_sub);
6493 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6494 EXPORT_SYMBOL(atomic64_sub_ret);
6495
6496 /* Atomic bit operations. */
6497 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6498 index 30c3ecc..736f015 100644
6499 --- a/arch/sparc/mm/Makefile
6500 +++ b/arch/sparc/mm/Makefile
6501 @@ -2,7 +2,7 @@
6502 #
6503
6504 asflags-y := -ansi
6505 -ccflags-y := -Werror
6506 +#ccflags-y := -Werror
6507
6508 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6509 obj-y += fault_$(BITS).o
6510 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6511 index f46cf6b..cc0666bae 100644
6512 --- a/arch/sparc/mm/fault_32.c
6513 +++ b/arch/sparc/mm/fault_32.c
6514 @@ -21,6 +21,9 @@
6515 #include <linux/perf_event.h>
6516 #include <linux/interrupt.h>
6517 #include <linux/kdebug.h>
6518 +#include <linux/slab.h>
6519 +#include <linux/pagemap.h>
6520 +#include <linux/compiler.h>
6521
6522 #include <asm/page.h>
6523 #include <asm/pgtable.h>
6524 @@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6525 return safe_compute_effective_address(regs, insn);
6526 }
6527
6528 +#ifdef CONFIG_PAX_PAGEEXEC
6529 +#ifdef CONFIG_PAX_DLRESOLVE
6530 +static void pax_emuplt_close(struct vm_area_struct *vma)
6531 +{
6532 + vma->vm_mm->call_dl_resolve = 0UL;
6533 +}
6534 +
6535 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6536 +{
6537 + unsigned int *kaddr;
6538 +
6539 + vmf->page = alloc_page(GFP_HIGHUSER);
6540 + if (!vmf->page)
6541 + return VM_FAULT_OOM;
6542 +
6543 + kaddr = kmap(vmf->page);
6544 + memset(kaddr, 0, PAGE_SIZE);
6545 + kaddr[0] = 0x9DE3BFA8U; /* save */
6546 + flush_dcache_page(vmf->page);
6547 + kunmap(vmf->page);
6548 + return VM_FAULT_MAJOR;
6549 +}
6550 +
6551 +static const struct vm_operations_struct pax_vm_ops = {
6552 + .close = pax_emuplt_close,
6553 + .fault = pax_emuplt_fault
6554 +};
6555 +
6556 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6557 +{
6558 + int ret;
6559 +
6560 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6561 + vma->vm_mm = current->mm;
6562 + vma->vm_start = addr;
6563 + vma->vm_end = addr + PAGE_SIZE;
6564 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6565 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6566 + vma->vm_ops = &pax_vm_ops;
6567 +
6568 + ret = insert_vm_struct(current->mm, vma);
6569 + if (ret)
6570 + return ret;
6571 +
6572 + ++current->mm->total_vm;
6573 + return 0;
6574 +}
6575 +#endif
6576 +
6577 +/*
6578 + * PaX: decide what to do with offenders (regs->pc = fault address)
6579 + *
6580 + * returns 1 when task should be killed
6581 + * 2 when patched PLT trampoline was detected
6582 + * 3 when unpatched PLT trampoline was detected
6583 + */
6584 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6585 +{
6586 +
6587 +#ifdef CONFIG_PAX_EMUPLT
6588 + int err;
6589 +
6590 + do { /* PaX: patched PLT emulation #1 */
6591 + unsigned int sethi1, sethi2, jmpl;
6592 +
6593 + err = get_user(sethi1, (unsigned int *)regs->pc);
6594 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6595 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6596 +
6597 + if (err)
6598 + break;
6599 +
6600 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6601 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6602 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6603 + {
6604 + unsigned int addr;
6605 +
6606 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6607 + addr = regs->u_regs[UREG_G1];
6608 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6609 + regs->pc = addr;
6610 + regs->npc = addr+4;
6611 + return 2;
6612 + }
6613 + } while (0);
6614 +
6615 + do { /* PaX: patched PLT emulation #2 */
6616 + unsigned int ba;
6617 +
6618 + err = get_user(ba, (unsigned int *)regs->pc);
6619 +
6620 + if (err)
6621 + break;
6622 +
6623 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6624 + unsigned int addr;
6625 +
6626 + if ((ba & 0xFFC00000U) == 0x30800000U)
6627 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6628 + else
6629 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6630 + regs->pc = addr;
6631 + regs->npc = addr+4;
6632 + return 2;
6633 + }
6634 + } while (0);
6635 +
6636 + do { /* PaX: patched PLT emulation #3 */
6637 + unsigned int sethi, bajmpl, nop;
6638 +
6639 + err = get_user(sethi, (unsigned int *)regs->pc);
6640 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6641 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6642 +
6643 + if (err)
6644 + break;
6645 +
6646 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6647 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6648 + nop == 0x01000000U)
6649 + {
6650 + unsigned int addr;
6651 +
6652 + addr = (sethi & 0x003FFFFFU) << 10;
6653 + regs->u_regs[UREG_G1] = addr;
6654 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6655 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6656 + else
6657 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6658 + regs->pc = addr;
6659 + regs->npc = addr+4;
6660 + return 2;
6661 + }
6662 + } while (0);
6663 +
6664 + do { /* PaX: unpatched PLT emulation step 1 */
6665 + unsigned int sethi, ba, nop;
6666 +
6667 + err = get_user(sethi, (unsigned int *)regs->pc);
6668 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6669 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6670 +
6671 + if (err)
6672 + break;
6673 +
6674 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6675 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6676 + nop == 0x01000000U)
6677 + {
6678 + unsigned int addr, save, call;
6679 +
6680 + if ((ba & 0xFFC00000U) == 0x30800000U)
6681 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6682 + else
6683 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6684 +
6685 + err = get_user(save, (unsigned int *)addr);
6686 + err |= get_user(call, (unsigned int *)(addr+4));
6687 + err |= get_user(nop, (unsigned int *)(addr+8));
6688 + if (err)
6689 + break;
6690 +
6691 +#ifdef CONFIG_PAX_DLRESOLVE
6692 + if (save == 0x9DE3BFA8U &&
6693 + (call & 0xC0000000U) == 0x40000000U &&
6694 + nop == 0x01000000U)
6695 + {
6696 + struct vm_area_struct *vma;
6697 + unsigned long call_dl_resolve;
6698 +
6699 + down_read(&current->mm->mmap_sem);
6700 + call_dl_resolve = current->mm->call_dl_resolve;
6701 + up_read(&current->mm->mmap_sem);
6702 + if (likely(call_dl_resolve))
6703 + goto emulate;
6704 +
6705 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6706 +
6707 + down_write(&current->mm->mmap_sem);
6708 + if (current->mm->call_dl_resolve) {
6709 + call_dl_resolve = current->mm->call_dl_resolve;
6710 + up_write(&current->mm->mmap_sem);
6711 + if (vma)
6712 + kmem_cache_free(vm_area_cachep, vma);
6713 + goto emulate;
6714 + }
6715 +
6716 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6717 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6718 + up_write(&current->mm->mmap_sem);
6719 + if (vma)
6720 + kmem_cache_free(vm_area_cachep, vma);
6721 + return 1;
6722 + }
6723 +
6724 + if (pax_insert_vma(vma, call_dl_resolve)) {
6725 + up_write(&current->mm->mmap_sem);
6726 + kmem_cache_free(vm_area_cachep, vma);
6727 + return 1;
6728 + }
6729 +
6730 + current->mm->call_dl_resolve = call_dl_resolve;
6731 + up_write(&current->mm->mmap_sem);
6732 +
6733 +emulate:
6734 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6735 + regs->pc = call_dl_resolve;
6736 + regs->npc = addr+4;
6737 + return 3;
6738 + }
6739 +#endif
6740 +
6741 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6742 + if ((save & 0xFFC00000U) == 0x05000000U &&
6743 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6744 + nop == 0x01000000U)
6745 + {
6746 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6747 + regs->u_regs[UREG_G2] = addr + 4;
6748 + addr = (save & 0x003FFFFFU) << 10;
6749 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6750 + regs->pc = addr;
6751 + regs->npc = addr+4;
6752 + return 3;
6753 + }
6754 + }
6755 + } while (0);
6756 +
6757 + do { /* PaX: unpatched PLT emulation step 2 */
6758 + unsigned int save, call, nop;
6759 +
6760 + err = get_user(save, (unsigned int *)(regs->pc-4));
6761 + err |= get_user(call, (unsigned int *)regs->pc);
6762 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6763 + if (err)
6764 + break;
6765 +
6766 + if (save == 0x9DE3BFA8U &&
6767 + (call & 0xC0000000U) == 0x40000000U &&
6768 + nop == 0x01000000U)
6769 + {
6770 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6771 +
6772 + regs->u_regs[UREG_RETPC] = regs->pc;
6773 + regs->pc = dl_resolve;
6774 + regs->npc = dl_resolve+4;
6775 + return 3;
6776 + }
6777 + } while (0);
6778 +#endif
6779 +
6780 + return 1;
6781 +}
6782 +
6783 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6784 +{
6785 + unsigned long i;
6786 +
6787 + printk(KERN_ERR "PAX: bytes at PC: ");
6788 + for (i = 0; i < 8; i++) {
6789 + unsigned int c;
6790 + if (get_user(c, (unsigned int *)pc+i))
6791 + printk(KERN_CONT "???????? ");
6792 + else
6793 + printk(KERN_CONT "%08x ", c);
6794 + }
6795 + printk("\n");
6796 +}
6797 +#endif
6798 +
6799 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6800 int text_fault)
6801 {
6802 @@ -248,6 +522,24 @@ good_area:
6803 if (!(vma->vm_flags & VM_WRITE))
6804 goto bad_area;
6805 } else {
6806 +
6807 +#ifdef CONFIG_PAX_PAGEEXEC
6808 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6809 + up_read(&mm->mmap_sem);
6810 + switch (pax_handle_fetch_fault(regs)) {
6811 +
6812 +#ifdef CONFIG_PAX_EMUPLT
6813 + case 2:
6814 + case 3:
6815 + return;
6816 +#endif
6817 +
6818 + }
6819 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6820 + do_group_exit(SIGKILL);
6821 + }
6822 +#endif
6823 +
6824 /* Allow reads even for write-only mappings */
6825 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6826 goto bad_area;
6827 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6828 index 1fe0429..8dd5dd5 100644
6829 --- a/arch/sparc/mm/fault_64.c
6830 +++ b/arch/sparc/mm/fault_64.c
6831 @@ -21,6 +21,9 @@
6832 #include <linux/kprobes.h>
6833 #include <linux/kdebug.h>
6834 #include <linux/percpu.h>
6835 +#include <linux/slab.h>
6836 +#include <linux/pagemap.h>
6837 +#include <linux/compiler.h>
6838
6839 #include <asm/page.h>
6840 #include <asm/pgtable.h>
6841 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6842 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6843 regs->tpc);
6844 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6845 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6846 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6847 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6848 dump_stack();
6849 unhandled_fault(regs->tpc, current, regs);
6850 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6851 show_regs(regs);
6852 }
6853
6854 +#ifdef CONFIG_PAX_PAGEEXEC
6855 +#ifdef CONFIG_PAX_DLRESOLVE
6856 +static void pax_emuplt_close(struct vm_area_struct *vma)
6857 +{
6858 + vma->vm_mm->call_dl_resolve = 0UL;
6859 +}
6860 +
6861 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6862 +{
6863 + unsigned int *kaddr;
6864 +
6865 + vmf->page = alloc_page(GFP_HIGHUSER);
6866 + if (!vmf->page)
6867 + return VM_FAULT_OOM;
6868 +
6869 + kaddr = kmap(vmf->page);
6870 + memset(kaddr, 0, PAGE_SIZE);
6871 + kaddr[0] = 0x9DE3BFA8U; /* save */
6872 + flush_dcache_page(vmf->page);
6873 + kunmap(vmf->page);
6874 + return VM_FAULT_MAJOR;
6875 +}
6876 +
6877 +static const struct vm_operations_struct pax_vm_ops = {
6878 + .close = pax_emuplt_close,
6879 + .fault = pax_emuplt_fault
6880 +};
6881 +
6882 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6883 +{
6884 + int ret;
6885 +
6886 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6887 + vma->vm_mm = current->mm;
6888 + vma->vm_start = addr;
6889 + vma->vm_end = addr + PAGE_SIZE;
6890 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6891 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6892 + vma->vm_ops = &pax_vm_ops;
6893 +
6894 + ret = insert_vm_struct(current->mm, vma);
6895 + if (ret)
6896 + return ret;
6897 +
6898 + ++current->mm->total_vm;
6899 + return 0;
6900 +}
6901 +#endif
6902 +
6903 +/*
6904 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6905 + *
6906 + * returns 1 when task should be killed
6907 + * 2 when patched PLT trampoline was detected
6908 + * 3 when unpatched PLT trampoline was detected
6909 + */
6910 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6911 +{
6912 +
6913 +#ifdef CONFIG_PAX_EMUPLT
6914 + int err;
6915 +
6916 + do { /* PaX: patched PLT emulation #1 */
6917 + unsigned int sethi1, sethi2, jmpl;
6918 +
6919 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6920 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6921 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6922 +
6923 + if (err)
6924 + break;
6925 +
6926 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6927 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6928 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6929 + {
6930 + unsigned long addr;
6931 +
6932 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6933 + addr = regs->u_regs[UREG_G1];
6934 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6935 +
6936 + if (test_thread_flag(TIF_32BIT))
6937 + addr &= 0xFFFFFFFFUL;
6938 +
6939 + regs->tpc = addr;
6940 + regs->tnpc = addr+4;
6941 + return 2;
6942 + }
6943 + } while (0);
6944 +
6945 + do { /* PaX: patched PLT emulation #2 */
6946 + unsigned int ba;
6947 +
6948 + err = get_user(ba, (unsigned int *)regs->tpc);
6949 +
6950 + if (err)
6951 + break;
6952 +
6953 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6954 + unsigned long addr;
6955 +
6956 + if ((ba & 0xFFC00000U) == 0x30800000U)
6957 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6958 + else
6959 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6960 +
6961 + if (test_thread_flag(TIF_32BIT))
6962 + addr &= 0xFFFFFFFFUL;
6963 +
6964 + regs->tpc = addr;
6965 + regs->tnpc = addr+4;
6966 + return 2;
6967 + }
6968 + } while (0);
6969 +
6970 + do { /* PaX: patched PLT emulation #3 */
6971 + unsigned int sethi, bajmpl, nop;
6972 +
6973 + err = get_user(sethi, (unsigned int *)regs->tpc);
6974 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6975 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6976 +
6977 + if (err)
6978 + break;
6979 +
6980 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6981 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6982 + nop == 0x01000000U)
6983 + {
6984 + unsigned long addr;
6985 +
6986 + addr = (sethi & 0x003FFFFFU) << 10;
6987 + regs->u_regs[UREG_G1] = addr;
6988 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6989 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6990 + else
6991 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6992 +
6993 + if (test_thread_flag(TIF_32BIT))
6994 + addr &= 0xFFFFFFFFUL;
6995 +
6996 + regs->tpc = addr;
6997 + regs->tnpc = addr+4;
6998 + return 2;
6999 + }
7000 + } while (0);
7001 +
7002 + do { /* PaX: patched PLT emulation #4 */
7003 + unsigned int sethi, mov1, call, mov2;
7004 +
7005 + err = get_user(sethi, (unsigned int *)regs->tpc);
7006 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7007 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
7008 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7009 +
7010 + if (err)
7011 + break;
7012 +
7013 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7014 + mov1 == 0x8210000FU &&
7015 + (call & 0xC0000000U) == 0x40000000U &&
7016 + mov2 == 0x9E100001U)
7017 + {
7018 + unsigned long addr;
7019 +
7020 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7021 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7022 +
7023 + if (test_thread_flag(TIF_32BIT))
7024 + addr &= 0xFFFFFFFFUL;
7025 +
7026 + regs->tpc = addr;
7027 + regs->tnpc = addr+4;
7028 + return 2;
7029 + }
7030 + } while (0);
7031 +
7032 + do { /* PaX: patched PLT emulation #5 */
7033 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7034 +
7035 + err = get_user(sethi, (unsigned int *)regs->tpc);
7036 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7037 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7038 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7039 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7040 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7041 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7042 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7043 +
7044 + if (err)
7045 + break;
7046 +
7047 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7048 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7049 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7050 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7051 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7052 + sllx == 0x83287020U &&
7053 + jmpl == 0x81C04005U &&
7054 + nop == 0x01000000U)
7055 + {
7056 + unsigned long addr;
7057 +
7058 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7059 + regs->u_regs[UREG_G1] <<= 32;
7060 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7061 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7062 + regs->tpc = addr;
7063 + regs->tnpc = addr+4;
7064 + return 2;
7065 + }
7066 + } while (0);
7067 +
7068 + do { /* PaX: patched PLT emulation #6 */
7069 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7070 +
7071 + err = get_user(sethi, (unsigned int *)regs->tpc);
7072 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7073 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7074 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7075 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7076 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7077 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7078 +
7079 + if (err)
7080 + break;
7081 +
7082 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7083 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7084 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7085 + sllx == 0x83287020U &&
7086 + (or & 0xFFFFE000U) == 0x8A116000U &&
7087 + jmpl == 0x81C04005U &&
7088 + nop == 0x01000000U)
7089 + {
7090 + unsigned long addr;
7091 +
7092 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7093 + regs->u_regs[UREG_G1] <<= 32;
7094 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7095 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7096 + regs->tpc = addr;
7097 + regs->tnpc = addr+4;
7098 + return 2;
7099 + }
7100 + } while (0);
7101 +
7102 + do { /* PaX: unpatched PLT emulation step 1 */
7103 + unsigned int sethi, ba, nop;
7104 +
7105 + err = get_user(sethi, (unsigned int *)regs->tpc);
7106 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7107 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7108 +
7109 + if (err)
7110 + break;
7111 +
7112 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7113 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7114 + nop == 0x01000000U)
7115 + {
7116 + unsigned long addr;
7117 + unsigned int save, call;
7118 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7119 +
7120 + if ((ba & 0xFFC00000U) == 0x30800000U)
7121 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7122 + else
7123 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7124 +
7125 + if (test_thread_flag(TIF_32BIT))
7126 + addr &= 0xFFFFFFFFUL;
7127 +
7128 + err = get_user(save, (unsigned int *)addr);
7129 + err |= get_user(call, (unsigned int *)(addr+4));
7130 + err |= get_user(nop, (unsigned int *)(addr+8));
7131 + if (err)
7132 + break;
7133 +
7134 +#ifdef CONFIG_PAX_DLRESOLVE
7135 + if (save == 0x9DE3BFA8U &&
7136 + (call & 0xC0000000U) == 0x40000000U &&
7137 + nop == 0x01000000U)
7138 + {
7139 + struct vm_area_struct *vma;
7140 + unsigned long call_dl_resolve;
7141 +
7142 + down_read(&current->mm->mmap_sem);
7143 + call_dl_resolve = current->mm->call_dl_resolve;
7144 + up_read(&current->mm->mmap_sem);
7145 + if (likely(call_dl_resolve))
7146 + goto emulate;
7147 +
7148 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7149 +
7150 + down_write(&current->mm->mmap_sem);
7151 + if (current->mm->call_dl_resolve) {
7152 + call_dl_resolve = current->mm->call_dl_resolve;
7153 + up_write(&current->mm->mmap_sem);
7154 + if (vma)
7155 + kmem_cache_free(vm_area_cachep, vma);
7156 + goto emulate;
7157 + }
7158 +
7159 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7160 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7161 + up_write(&current->mm->mmap_sem);
7162 + if (vma)
7163 + kmem_cache_free(vm_area_cachep, vma);
7164 + return 1;
7165 + }
7166 +
7167 + if (pax_insert_vma(vma, call_dl_resolve)) {
7168 + up_write(&current->mm->mmap_sem);
7169 + kmem_cache_free(vm_area_cachep, vma);
7170 + return 1;
7171 + }
7172 +
7173 + current->mm->call_dl_resolve = call_dl_resolve;
7174 + up_write(&current->mm->mmap_sem);
7175 +
7176 +emulate:
7177 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7178 + regs->tpc = call_dl_resolve;
7179 + regs->tnpc = addr+4;
7180 + return 3;
7181 + }
7182 +#endif
7183 +
7184 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7185 + if ((save & 0xFFC00000U) == 0x05000000U &&
7186 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7187 + nop == 0x01000000U)
7188 + {
7189 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7190 + regs->u_regs[UREG_G2] = addr + 4;
7191 + addr = (save & 0x003FFFFFU) << 10;
7192 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7193 +
7194 + if (test_thread_flag(TIF_32BIT))
7195 + addr &= 0xFFFFFFFFUL;
7196 +
7197 + regs->tpc = addr;
7198 + regs->tnpc = addr+4;
7199 + return 3;
7200 + }
7201 +
7202 + /* PaX: 64-bit PLT stub */
7203 + err = get_user(sethi1, (unsigned int *)addr);
7204 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7205 + err |= get_user(or1, (unsigned int *)(addr+8));
7206 + err |= get_user(or2, (unsigned int *)(addr+12));
7207 + err |= get_user(sllx, (unsigned int *)(addr+16));
7208 + err |= get_user(add, (unsigned int *)(addr+20));
7209 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7210 + err |= get_user(nop, (unsigned int *)(addr+28));
7211 + if (err)
7212 + break;
7213 +
7214 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7215 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7216 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7217 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7218 + sllx == 0x89293020U &&
7219 + add == 0x8A010005U &&
7220 + jmpl == 0x89C14000U &&
7221 + nop == 0x01000000U)
7222 + {
7223 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7224 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7225 + regs->u_regs[UREG_G4] <<= 32;
7226 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7227 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7228 + regs->u_regs[UREG_G4] = addr + 24;
7229 + addr = regs->u_regs[UREG_G5];
7230 + regs->tpc = addr;
7231 + regs->tnpc = addr+4;
7232 + return 3;
7233 + }
7234 + }
7235 + } while (0);
7236 +
7237 +#ifdef CONFIG_PAX_DLRESOLVE
7238 + do { /* PaX: unpatched PLT emulation step 2 */
7239 + unsigned int save, call, nop;
7240 +
7241 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7242 + err |= get_user(call, (unsigned int *)regs->tpc);
7243 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7244 + if (err)
7245 + break;
7246 +
7247 + if (save == 0x9DE3BFA8U &&
7248 + (call & 0xC0000000U) == 0x40000000U &&
7249 + nop == 0x01000000U)
7250 + {
7251 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7252 +
7253 + if (test_thread_flag(TIF_32BIT))
7254 + dl_resolve &= 0xFFFFFFFFUL;
7255 +
7256 + regs->u_regs[UREG_RETPC] = regs->tpc;
7257 + regs->tpc = dl_resolve;
7258 + regs->tnpc = dl_resolve+4;
7259 + return 3;
7260 + }
7261 + } while (0);
7262 +#endif
7263 +
7264 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7265 + unsigned int sethi, ba, nop;
7266 +
7267 + err = get_user(sethi, (unsigned int *)regs->tpc);
7268 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7269 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7270 +
7271 + if (err)
7272 + break;
7273 +
7274 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7275 + (ba & 0xFFF00000U) == 0x30600000U &&
7276 + nop == 0x01000000U)
7277 + {
7278 + unsigned long addr;
7279 +
7280 + addr = (sethi & 0x003FFFFFU) << 10;
7281 + regs->u_regs[UREG_G1] = addr;
7282 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7283 +
7284 + if (test_thread_flag(TIF_32BIT))
7285 + addr &= 0xFFFFFFFFUL;
7286 +
7287 + regs->tpc = addr;
7288 + regs->tnpc = addr+4;
7289 + return 2;
7290 + }
7291 + } while (0);
7292 +
7293 +#endif
7294 +
7295 + return 1;
7296 +}
7297 +
7298 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7299 +{
7300 + unsigned long i;
7301 +
7302 + printk(KERN_ERR "PAX: bytes at PC: ");
7303 + for (i = 0; i < 8; i++) {
7304 + unsigned int c;
7305 + if (get_user(c, (unsigned int *)pc+i))
7306 + printk(KERN_CONT "???????? ");
7307 + else
7308 + printk(KERN_CONT "%08x ", c);
7309 + }
7310 + printk("\n");
7311 +}
7312 +#endif
7313 +
7314 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7315 {
7316 struct mm_struct *mm = current->mm;
7317 @@ -343,6 +806,29 @@ retry:
7318 if (!vma)
7319 goto bad_area;
7320
7321 +#ifdef CONFIG_PAX_PAGEEXEC
7322 + /* PaX: detect ITLB misses on non-exec pages */
7323 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7324 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7325 + {
7326 + if (address != regs->tpc)
7327 + goto good_area;
7328 +
7329 + up_read(&mm->mmap_sem);
7330 + switch (pax_handle_fetch_fault(regs)) {
7331 +
7332 +#ifdef CONFIG_PAX_EMUPLT
7333 + case 2:
7334 + case 3:
7335 + return;
7336 +#endif
7337 +
7338 + }
7339 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7340 + do_group_exit(SIGKILL);
7341 + }
7342 +#endif
7343 +
7344 /* Pure DTLB misses do not tell us whether the fault causing
7345 * load/store/atomic was a write or not, it only says that there
7346 * was no match. So in such a case we (carefully) read the
7347 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7348 index 07e1453..0a7d9e9 100644
7349 --- a/arch/sparc/mm/hugetlbpage.c
7350 +++ b/arch/sparc/mm/hugetlbpage.c
7351 @@ -67,7 +67,7 @@ full_search:
7352 }
7353 return -ENOMEM;
7354 }
7355 - if (likely(!vma || addr + len <= vma->vm_start)) {
7356 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7357 /*
7358 * Remember the place where we stopped the search:
7359 */
7360 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7361 /* make sure it can fit in the remaining address space */
7362 if (likely(addr > len)) {
7363 vma = find_vma(mm, addr-len);
7364 - if (!vma || addr <= vma->vm_start) {
7365 + if (check_heap_stack_gap(vma, addr - len, len)) {
7366 /* remember the address as a hint for next time */
7367 return (mm->free_area_cache = addr-len);
7368 }
7369 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7370 if (unlikely(mm->mmap_base < len))
7371 goto bottomup;
7372
7373 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7374 + addr = mm->mmap_base - len;
7375
7376 do {
7377 + addr &= HPAGE_MASK;
7378 /*
7379 * Lookup failure means no vma is above this address,
7380 * else if new region fits below vma->vm_start,
7381 * return with success:
7382 */
7383 vma = find_vma(mm, addr);
7384 - if (likely(!vma || addr+len <= vma->vm_start)) {
7385 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7386 /* remember the address as a hint for next time */
7387 return (mm->free_area_cache = addr);
7388 }
7389 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7390 mm->cached_hole_size = vma->vm_start - addr;
7391
7392 /* try just below the current vma->vm_start */
7393 - addr = (vma->vm_start-len) & HPAGE_MASK;
7394 - } while (likely(len < vma->vm_start));
7395 + addr = skip_heap_stack_gap(vma, len);
7396 + } while (!IS_ERR_VALUE(addr));
7397
7398 bottomup:
7399 /*
7400 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7401 if (addr) {
7402 addr = ALIGN(addr, HPAGE_SIZE);
7403 vma = find_vma(mm, addr);
7404 - if (task_size - len >= addr &&
7405 - (!vma || addr + len <= vma->vm_start))
7406 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7407 return addr;
7408 }
7409 if (mm->get_unmapped_area == arch_get_unmapped_area)
7410 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7411 index f4500c6..889656c 100644
7412 --- a/arch/tile/include/asm/atomic_64.h
7413 +++ b/arch/tile/include/asm/atomic_64.h
7414 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7415
7416 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7417
7418 +#define atomic64_read_unchecked(v) atomic64_read(v)
7419 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7420 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7421 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7422 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7423 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7424 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7425 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7426 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7427 +
7428 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7429 #define smp_mb__before_atomic_dec() smp_mb()
7430 #define smp_mb__after_atomic_dec() smp_mb()
7431 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7432 index 392e533..536b092 100644
7433 --- a/arch/tile/include/asm/cache.h
7434 +++ b/arch/tile/include/asm/cache.h
7435 @@ -15,11 +15,12 @@
7436 #ifndef _ASM_TILE_CACHE_H
7437 #define _ASM_TILE_CACHE_H
7438
7439 +#include <linux/const.h>
7440 #include <arch/chip.h>
7441
7442 /* bytes per L1 data cache line */
7443 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 /* bytes per L2 cache line */
7448 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7449 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7450 index 9ab078a..d6635c2 100644
7451 --- a/arch/tile/include/asm/uaccess.h
7452 +++ b/arch/tile/include/asm/uaccess.h
7453 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7454 const void __user *from,
7455 unsigned long n)
7456 {
7457 - int sz = __compiletime_object_size(to);
7458 + size_t sz = __compiletime_object_size(to);
7459
7460 - if (likely(sz == -1 || sz >= n))
7461 + if (likely(sz == (size_t)-1 || sz >= n))
7462 n = _copy_from_user(to, from, n);
7463 else
7464 copy_from_user_overflow();
7465 diff --git a/arch/um/Makefile b/arch/um/Makefile
7466 index 0970910..13adb57a 100644
7467 --- a/arch/um/Makefile
7468 +++ b/arch/um/Makefile
7469 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7470 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7471 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7472
7473 +ifdef CONSTIFY_PLUGIN
7474 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7475 +endif
7476 +
7477 #This will adjust *FLAGS accordingly to the platform.
7478 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7479
7480 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7481 index 19e1bdd..3665b77 100644
7482 --- a/arch/um/include/asm/cache.h
7483 +++ b/arch/um/include/asm/cache.h
7484 @@ -1,6 +1,7 @@
7485 #ifndef __UM_CACHE_H
7486 #define __UM_CACHE_H
7487
7488 +#include <linux/const.h>
7489
7490 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7491 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7492 @@ -12,6 +13,6 @@
7493 # define L1_CACHE_SHIFT 5
7494 #endif
7495
7496 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7497 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7498
7499 #endif
7500 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7501 index 6c03acd..a5e0215 100644
7502 --- a/arch/um/include/asm/kmap_types.h
7503 +++ b/arch/um/include/asm/kmap_types.h
7504 @@ -23,6 +23,7 @@ enum km_type {
7505 KM_IRQ1,
7506 KM_SOFTIRQ0,
7507 KM_SOFTIRQ1,
7508 + KM_CLEARPAGE,
7509 KM_TYPE_NR
7510 };
7511
7512 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7513 index 7cfc3ce..cbd1a58 100644
7514 --- a/arch/um/include/asm/page.h
7515 +++ b/arch/um/include/asm/page.h
7516 @@ -14,6 +14,9 @@
7517 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7518 #define PAGE_MASK (~(PAGE_SIZE-1))
7519
7520 +#define ktla_ktva(addr) (addr)
7521 +#define ktva_ktla(addr) (addr)
7522 +
7523 #ifndef __ASSEMBLY__
7524
7525 struct page;
7526 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7527 index 0032f92..cd151e0 100644
7528 --- a/arch/um/include/asm/pgtable-3level.h
7529 +++ b/arch/um/include/asm/pgtable-3level.h
7530 @@ -58,6 +58,7 @@
7531 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7532 #define pud_populate(mm, pud, pmd) \
7533 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7534 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7535
7536 #ifdef CONFIG_64BIT
7537 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7538 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7539 index ccb9a9d..cc425bb 100644
7540 --- a/arch/um/kernel/process.c
7541 +++ b/arch/um/kernel/process.c
7542 @@ -407,22 +407,6 @@ int singlestepping(void * t)
7543 return 2;
7544 }
7545
7546 -/*
7547 - * Only x86 and x86_64 have an arch_align_stack().
7548 - * All other arches have "#define arch_align_stack(x) (x)"
7549 - * in their asm/system.h
7550 - * As this is included in UML from asm-um/system-generic.h,
7551 - * we can use it to behave as the subarch does.
7552 - */
7553 -#ifndef arch_align_stack
7554 -unsigned long arch_align_stack(unsigned long sp)
7555 -{
7556 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7557 - sp -= get_random_int() % 8192;
7558 - return sp & ~0xf;
7559 -}
7560 -#endif
7561 -
7562 unsigned long get_wchan(struct task_struct *p)
7563 {
7564 unsigned long stack_page, sp, ip;
7565 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7566 index ad8f795..2c7eec6 100644
7567 --- a/arch/unicore32/include/asm/cache.h
7568 +++ b/arch/unicore32/include/asm/cache.h
7569 @@ -12,8 +12,10 @@
7570 #ifndef __UNICORE_CACHE_H__
7571 #define __UNICORE_CACHE_H__
7572
7573 -#define L1_CACHE_SHIFT (5)
7574 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7575 +#include <linux/const.h>
7576 +
7577 +#define L1_CACHE_SHIFT 5
7578 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7579
7580 /*
7581 * Memory returned by kmalloc() may be used for DMA, so we must make
7582 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7583 index c70684f..698fa4b 100644
7584 --- a/arch/x86/Kconfig
7585 +++ b/arch/x86/Kconfig
7586 @@ -218,7 +218,7 @@ config X86_HT
7587
7588 config X86_32_LAZY_GS
7589 def_bool y
7590 - depends on X86_32 && !CC_STACKPROTECTOR
7591 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7592
7593 config ARCH_HWEIGHT_CFLAGS
7594 string
7595 @@ -1047,7 +1047,7 @@ choice
7596
7597 config NOHIGHMEM
7598 bool "off"
7599 - depends on !X86_NUMAQ
7600 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7601 ---help---
7602 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7603 However, the address space of 32-bit x86 processors is only 4
7604 @@ -1084,7 +1084,7 @@ config NOHIGHMEM
7605
7606 config HIGHMEM4G
7607 bool "4GB"
7608 - depends on !X86_NUMAQ
7609 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7610 ---help---
7611 Select this if you have a 32-bit processor and between 1 and 4
7612 gigabytes of physical RAM.
7613 @@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7614 hex
7615 default 0xB0000000 if VMSPLIT_3G_OPT
7616 default 0x80000000 if VMSPLIT_2G
7617 - default 0x78000000 if VMSPLIT_2G_OPT
7618 + default 0x70000000 if VMSPLIT_2G_OPT
7619 default 0x40000000 if VMSPLIT_1G
7620 default 0xC0000000
7621 depends on X86_32
7622 @@ -1526,6 +1526,7 @@ config SECCOMP
7623
7624 config CC_STACKPROTECTOR
7625 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7626 + depends on X86_64 || !PAX_MEMORY_UDEREF
7627 ---help---
7628 This option turns on the -fstack-protector GCC feature. This
7629 feature puts, at the beginning of functions, a canary value on
7630 @@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7631 config PHYSICAL_START
7632 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7633 default "0x1000000"
7634 + range 0x400000 0x40000000
7635 ---help---
7636 This gives the physical address where the kernel is loaded.
7637
7638 @@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7639 config PHYSICAL_ALIGN
7640 hex "Alignment value to which kernel should be aligned" if X86_32
7641 default "0x1000000"
7642 + range 0x400000 0x1000000 if PAX_KERNEXEC
7643 range 0x2000 0x1000000
7644 ---help---
7645 This value puts the alignment restrictions on physical address
7646 @@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7647 Say N if you want to disable CPU hotplug.
7648
7649 config COMPAT_VDSO
7650 - def_bool y
7651 + def_bool n
7652 prompt "Compat VDSO support"
7653 depends on X86_32 || IA32_EMULATION
7654 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7655 ---help---
7656 Map the 32-bit VDSO to the predictable old-style address too.
7657
7658 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7659 index 706e12e..62e4feb 100644
7660 --- a/arch/x86/Kconfig.cpu
7661 +++ b/arch/x86/Kconfig.cpu
7662 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7663
7664 config X86_F00F_BUG
7665 def_bool y
7666 - depends on M586MMX || M586TSC || M586 || M486 || M386
7667 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7668
7669 config X86_INVD_BUG
7670 def_bool y
7671 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7672
7673 config X86_ALIGNMENT_16
7674 def_bool y
7675 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7676 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7677
7678 config X86_INTEL_USERCOPY
7679 def_bool y
7680 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7681 # generates cmov.
7682 config X86_CMOV
7683 def_bool y
7684 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7685 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7686
7687 config X86_MINIMUM_CPU_FAMILY
7688 int
7689 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7690 index e46c214..ab62fd1 100644
7691 --- a/arch/x86/Kconfig.debug
7692 +++ b/arch/x86/Kconfig.debug
7693 @@ -84,7 +84,7 @@ config X86_PTDUMP
7694 config DEBUG_RODATA
7695 bool "Write protect kernel read-only data structures"
7696 default y
7697 - depends on DEBUG_KERNEL
7698 + depends on DEBUG_KERNEL && BROKEN
7699 ---help---
7700 Mark the kernel read-only data as write-protected in the pagetables,
7701 in order to catch accidental (and incorrect) writes to such const
7702 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7703
7704 config DEBUG_SET_MODULE_RONX
7705 bool "Set loadable kernel module data as NX and text as RO"
7706 - depends on MODULES
7707 + depends on MODULES && BROKEN
7708 ---help---
7709 This option helps catch unintended modifications to loadable
7710 kernel module's text and read-only data. It also prevents execution
7711 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7712
7713 config DEBUG_STRICT_USER_COPY_CHECKS
7714 bool "Strict copy size checks"
7715 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7716 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7717 ---help---
7718 Enabling this option turns a certain set of sanity checks for user
7719 copy operations into compile time failures.
7720 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7721 index 1f25214..39422b3 100644
7722 --- a/arch/x86/Makefile
7723 +++ b/arch/x86/Makefile
7724 @@ -46,6 +46,7 @@ else
7725 UTS_MACHINE := x86_64
7726 CHECKFLAGS += -D__x86_64__ -m64
7727
7728 + biarch := $(call cc-option,-m64)
7729 KBUILD_AFLAGS += -m64
7730 KBUILD_CFLAGS += -m64
7731
7732 @@ -222,3 +223,12 @@ define archhelp
7733 echo ' FDARGS="..." arguments for the booted kernel'
7734 echo ' FDINITRD=file initrd for the booted kernel'
7735 endef
7736 +
7737 +define OLD_LD
7738 +
7739 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7740 +*** Please upgrade your binutils to 2.18 or newer
7741 +endef
7742 +
7743 +archprepare:
7744 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7745 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7746 index 5a747dd..ff7b12c 100644
7747 --- a/arch/x86/boot/Makefile
7748 +++ b/arch/x86/boot/Makefile
7749 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7750 $(call cc-option, -fno-stack-protector) \
7751 $(call cc-option, -mpreferred-stack-boundary=2)
7752 KBUILD_CFLAGS += $(call cc-option, -m32)
7753 +ifdef CONSTIFY_PLUGIN
7754 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7755 +endif
7756 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7757 GCOV_PROFILE := n
7758
7759 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7760 index 878e4b9..20537ab 100644
7761 --- a/arch/x86/boot/bitops.h
7762 +++ b/arch/x86/boot/bitops.h
7763 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7764 u8 v;
7765 const u32 *p = (const u32 *)addr;
7766
7767 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7768 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7769 return v;
7770 }
7771
7772 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7773
7774 static inline void set_bit(int nr, void *addr)
7775 {
7776 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7777 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7778 }
7779
7780 #endif /* BOOT_BITOPS_H */
7781 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7782 index 18997e5..83d9c67 100644
7783 --- a/arch/x86/boot/boot.h
7784 +++ b/arch/x86/boot/boot.h
7785 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7786 static inline u16 ds(void)
7787 {
7788 u16 seg;
7789 - asm("movw %%ds,%0" : "=rm" (seg));
7790 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7791 return seg;
7792 }
7793
7794 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7795 static inline int memcmp(const void *s1, const void *s2, size_t len)
7796 {
7797 u8 diff;
7798 - asm("repe; cmpsb; setnz %0"
7799 + asm volatile("repe; cmpsb; setnz %0"
7800 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7801 return diff;
7802 }
7803 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7804 index e398bb5..3a382ca 100644
7805 --- a/arch/x86/boot/compressed/Makefile
7806 +++ b/arch/x86/boot/compressed/Makefile
7807 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7808 KBUILD_CFLAGS += $(cflags-y)
7809 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7810 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7811 +ifdef CONSTIFY_PLUGIN
7812 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7813 +endif
7814
7815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7816 GCOV_PROFILE := n
7817 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7818 index 4e85f5f..39fa641 100644
7819 --- a/arch/x86/boot/compressed/eboot.c
7820 +++ b/arch/x86/boot/compressed/eboot.c
7821 @@ -142,7 +142,6 @@ again:
7822 *addr = max_addr;
7823 }
7824
7825 -free_pool:
7826 efi_call_phys1(sys_table->boottime->free_pool, map);
7827
7828 fail:
7829 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7830 if (i == map_size / desc_size)
7831 status = EFI_NOT_FOUND;
7832
7833 -free_pool:
7834 efi_call_phys1(sys_table->boottime->free_pool, map);
7835 fail:
7836 return status;
7837 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7838 index c85e3ac..6f5aa80 100644
7839 --- a/arch/x86/boot/compressed/head_32.S
7840 +++ b/arch/x86/boot/compressed/head_32.S
7841 @@ -106,7 +106,7 @@ preferred_addr:
7842 notl %eax
7843 andl %eax, %ebx
7844 #else
7845 - movl $LOAD_PHYSICAL_ADDR, %ebx
7846 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7847 #endif
7848
7849 /* Target address to relocate to for decompression */
7850 @@ -192,7 +192,7 @@ relocated:
7851 * and where it was actually loaded.
7852 */
7853 movl %ebp, %ebx
7854 - subl $LOAD_PHYSICAL_ADDR, %ebx
7855 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7856 jz 2f /* Nothing to be done if loaded at compiled addr. */
7857 /*
7858 * Process relocations.
7859 @@ -200,8 +200,7 @@ relocated:
7860
7861 1: subl $4, %edi
7862 movl (%edi), %ecx
7863 - testl %ecx, %ecx
7864 - jz 2f
7865 + jecxz 2f
7866 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7867 jmp 1b
7868 2:
7869 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7870 index 87e03a1..0d94c76 100644
7871 --- a/arch/x86/boot/compressed/head_64.S
7872 +++ b/arch/x86/boot/compressed/head_64.S
7873 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7874 notl %eax
7875 andl %eax, %ebx
7876 #else
7877 - movl $LOAD_PHYSICAL_ADDR, %ebx
7878 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7879 #endif
7880
7881 /* Target address to relocate to for decompression */
7882 @@ -263,7 +263,7 @@ preferred_addr:
7883 notq %rax
7884 andq %rax, %rbp
7885 #else
7886 - movq $LOAD_PHYSICAL_ADDR, %rbp
7887 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7888 #endif
7889
7890 /* Target address to relocate to for decompression */
7891 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7892 index 7116dcb..d9ae1d7 100644
7893 --- a/arch/x86/boot/compressed/misc.c
7894 +++ b/arch/x86/boot/compressed/misc.c
7895 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7896 case PT_LOAD:
7897 #ifdef CONFIG_RELOCATABLE
7898 dest = output;
7899 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7900 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7901 #else
7902 dest = (void *)(phdr->p_paddr);
7903 #endif
7904 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7905 error("Destination address too large");
7906 #endif
7907 #ifndef CONFIG_RELOCATABLE
7908 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7909 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7910 error("Wrong destination address");
7911 #endif
7912
7913 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7914 index 4d3ff03..e4972ff 100644
7915 --- a/arch/x86/boot/cpucheck.c
7916 +++ b/arch/x86/boot/cpucheck.c
7917 @@ -74,7 +74,7 @@ static int has_fpu(void)
7918 u16 fcw = -1, fsw = -1;
7919 u32 cr0;
7920
7921 - asm("movl %%cr0,%0" : "=r" (cr0));
7922 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7923 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7924 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7925 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7926 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7927 {
7928 u32 f0, f1;
7929
7930 - asm("pushfl ; "
7931 + asm volatile("pushfl ; "
7932 "pushfl ; "
7933 "popl %0 ; "
7934 "movl %0,%1 ; "
7935 @@ -115,7 +115,7 @@ static void get_flags(void)
7936 set_bit(X86_FEATURE_FPU, cpu.flags);
7937
7938 if (has_eflag(X86_EFLAGS_ID)) {
7939 - asm("cpuid"
7940 + asm volatile("cpuid"
7941 : "=a" (max_intel_level),
7942 "=b" (cpu_vendor[0]),
7943 "=d" (cpu_vendor[1]),
7944 @@ -124,7 +124,7 @@ static void get_flags(void)
7945
7946 if (max_intel_level >= 0x00000001 &&
7947 max_intel_level <= 0x0000ffff) {
7948 - asm("cpuid"
7949 + asm volatile("cpuid"
7950 : "=a" (tfms),
7951 "=c" (cpu.flags[4]),
7952 "=d" (cpu.flags[0])
7953 @@ -136,7 +136,7 @@ static void get_flags(void)
7954 cpu.model += ((tfms >> 16) & 0xf) << 4;
7955 }
7956
7957 - asm("cpuid"
7958 + asm volatile("cpuid"
7959 : "=a" (max_amd_level)
7960 : "a" (0x80000000)
7961 : "ebx", "ecx", "edx");
7962 @@ -144,7 +144,7 @@ static void get_flags(void)
7963 if (max_amd_level >= 0x80000001 &&
7964 max_amd_level <= 0x8000ffff) {
7965 u32 eax = 0x80000001;
7966 - asm("cpuid"
7967 + asm volatile("cpuid"
7968 : "+a" (eax),
7969 "=c" (cpu.flags[6]),
7970 "=d" (cpu.flags[1])
7971 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 ecx = MSR_K7_HWCR;
7973 u32 eax, edx;
7974
7975 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7977 eax &= ~(1 << 15);
7978 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7979 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7980
7981 get_flags(); /* Make sure it really did something */
7982 err = check_flags();
7983 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7984 u32 ecx = MSR_VIA_FCR;
7985 u32 eax, edx;
7986
7987 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7988 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7989 eax |= (1<<1)|(1<<7);
7990 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7991 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7992
7993 set_bit(X86_FEATURE_CX8, cpu.flags);
7994 err = check_flags();
7995 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7996 u32 eax, edx;
7997 u32 level = 1;
7998
7999 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8000 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8001 - asm("cpuid"
8002 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8003 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8004 + asm volatile("cpuid"
8005 : "+a" (level), "=d" (cpu.flags[0])
8006 : : "ecx", "ebx");
8007 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8008 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8009
8010 err = check_flags();
8011 }
8012 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8013 index efe5acf..22a3784 100644
8014 --- a/arch/x86/boot/header.S
8015 +++ b/arch/x86/boot/header.S
8016 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8017 # single linked list of
8018 # struct setup_data
8019
8020 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8021 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8022
8023 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8024 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8025 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8026 +#else
8027 #define VO_INIT_SIZE (VO__end - VO__text)
8028 +#endif
8029 #if ZO_INIT_SIZE > VO_INIT_SIZE
8030 #define INIT_SIZE ZO_INIT_SIZE
8031 #else
8032 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8033 index db75d07..8e6d0af 100644
8034 --- a/arch/x86/boot/memory.c
8035 +++ b/arch/x86/boot/memory.c
8036 @@ -19,7 +19,7 @@
8037
8038 static int detect_memory_e820(void)
8039 {
8040 - int count = 0;
8041 + unsigned int count = 0;
8042 struct biosregs ireg, oreg;
8043 struct e820entry *desc = boot_params.e820_map;
8044 static struct e820entry buf; /* static so it is zeroed */
8045 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8046 index 11e8c6e..fdbb1ed 100644
8047 --- a/arch/x86/boot/video-vesa.c
8048 +++ b/arch/x86/boot/video-vesa.c
8049 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8050
8051 boot_params.screen_info.vesapm_seg = oreg.es;
8052 boot_params.screen_info.vesapm_off = oreg.di;
8053 + boot_params.screen_info.vesapm_size = oreg.cx;
8054 }
8055
8056 /*
8057 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8058 index 43eda28..5ab5fdb 100644
8059 --- a/arch/x86/boot/video.c
8060 +++ b/arch/x86/boot/video.c
8061 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8062 static unsigned int get_entry(void)
8063 {
8064 char entry_buf[4];
8065 - int i, len = 0;
8066 + unsigned int i, len = 0;
8067 int key;
8068 unsigned int v;
8069
8070 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8071 index 5b577d5..3c1fed4 100644
8072 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8073 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8074 @@ -8,6 +8,8 @@
8075 * including this sentence is retained in full.
8076 */
8077
8078 +#include <asm/alternative-asm.h>
8079 +
8080 .extern crypto_ft_tab
8081 .extern crypto_it_tab
8082 .extern crypto_fl_tab
8083 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8084 je B192; \
8085 leaq 32(r9),r9;
8086
8087 +#define ret pax_force_retaddr 0, 1; ret
8088 +
8089 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8090 movq r1,r2; \
8091 movq r3,r4; \
8092 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8093 index 3470624..201259d 100644
8094 --- a/arch/x86/crypto/aesni-intel_asm.S
8095 +++ b/arch/x86/crypto/aesni-intel_asm.S
8096 @@ -31,6 +31,7 @@
8097
8098 #include <linux/linkage.h>
8099 #include <asm/inst.h>
8100 +#include <asm/alternative-asm.h>
8101
8102 #ifdef __x86_64__
8103 .data
8104 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8105 pop %r14
8106 pop %r13
8107 pop %r12
8108 + pax_force_retaddr 0, 1
8109 ret
8110 +ENDPROC(aesni_gcm_dec)
8111
8112
8113 /*****************************************************************************
8114 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8115 pop %r14
8116 pop %r13
8117 pop %r12
8118 + pax_force_retaddr 0, 1
8119 ret
8120 +ENDPROC(aesni_gcm_enc)
8121
8122 #endif
8123
8124 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8125 pxor %xmm1, %xmm0
8126 movaps %xmm0, (TKEYP)
8127 add $0x10, TKEYP
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 .align 4
8132 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8133 shufps $0b01001110, %xmm2, %xmm1
8134 movaps %xmm1, 0x10(TKEYP)
8135 add $0x20, TKEYP
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 .align 4
8140 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8141
8142 movaps %xmm0, (TKEYP)
8143 add $0x10, TKEYP
8144 + pax_force_retaddr_bts
8145 ret
8146
8147 .align 4
8148 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8149 pxor %xmm1, %xmm2
8150 movaps %xmm2, (TKEYP)
8151 add $0x10, TKEYP
8152 + pax_force_retaddr_bts
8153 ret
8154
8155 /*
8156 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8157 #ifndef __x86_64__
8158 popl KEYP
8159 #endif
8160 + pax_force_retaddr 0, 1
8161 ret
8162 +ENDPROC(aesni_set_key)
8163
8164 /*
8165 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8166 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8167 popl KLEN
8168 popl KEYP
8169 #endif
8170 + pax_force_retaddr 0, 1
8171 ret
8172 +ENDPROC(aesni_enc)
8173
8174 /*
8175 * _aesni_enc1: internal ABI
8176 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8177 AESENC KEY STATE
8178 movaps 0x70(TKEYP), KEY
8179 AESENCLAST KEY STATE
8180 + pax_force_retaddr_bts
8181 ret
8182
8183 /*
8184 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8185 AESENCLAST KEY STATE2
8186 AESENCLAST KEY STATE3
8187 AESENCLAST KEY STATE4
8188 + pax_force_retaddr_bts
8189 ret
8190
8191 /*
8192 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8193 popl KLEN
8194 popl KEYP
8195 #endif
8196 + pax_force_retaddr 0, 1
8197 ret
8198 +ENDPROC(aesni_dec)
8199
8200 /*
8201 * _aesni_dec1: internal ABI
8202 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8203 AESDEC KEY STATE
8204 movaps 0x70(TKEYP), KEY
8205 AESDECLAST KEY STATE
8206 + pax_force_retaddr_bts
8207 ret
8208
8209 /*
8210 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8211 AESDECLAST KEY STATE2
8212 AESDECLAST KEY STATE3
8213 AESDECLAST KEY STATE4
8214 + pax_force_retaddr_bts
8215 ret
8216
8217 /*
8218 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8219 popl KEYP
8220 popl LEN
8221 #endif
8222 + pax_force_retaddr 0, 1
8223 ret
8224 +ENDPROC(aesni_ecb_enc)
8225
8226 /*
8227 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8228 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8229 popl KEYP
8230 popl LEN
8231 #endif
8232 + pax_force_retaddr 0, 1
8233 ret
8234 +ENDPROC(aesni_ecb_dec)
8235
8236 /*
8237 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8239 popl LEN
8240 popl IVP
8241 #endif
8242 + pax_force_retaddr 0, 1
8243 ret
8244 +ENDPROC(aesni_cbc_enc)
8245
8246 /*
8247 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8248 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8249 popl LEN
8250 popl IVP
8251 #endif
8252 + pax_force_retaddr 0, 1
8253 ret
8254 +ENDPROC(aesni_cbc_dec)
8255
8256 #ifdef __x86_64__
8257 .align 16
8258 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8259 mov $1, TCTR_LOW
8260 MOVQ_R64_XMM TCTR_LOW INC
8261 MOVQ_R64_XMM CTR TCTR_LOW
8262 + pax_force_retaddr_bts
8263 ret
8264
8265 /*
8266 @@ -2554,6 +2582,7 @@ _aesni_inc:
8267 .Linc_low:
8268 movaps CTR, IV
8269 PSHUFB_XMM BSWAP_MASK IV
8270 + pax_force_retaddr_bts
8271 ret
8272
8273 /*
8274 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8275 .Lctr_enc_ret:
8276 movups IV, (IVP)
8277 .Lctr_enc_just_ret:
8278 + pax_force_retaddr 0, 1
8279 ret
8280 +ENDPROC(aesni_ctr_enc)
8281 #endif
8282 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8283 index 391d245..67f35c2 100644
8284 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8285 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8286 @@ -20,6 +20,8 @@
8287 *
8288 */
8289
8290 +#include <asm/alternative-asm.h>
8291 +
8292 .file "blowfish-x86_64-asm.S"
8293 .text
8294
8295 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8296 jnz __enc_xor;
8297
8298 write_block();
8299 + pax_force_retaddr 0, 1
8300 ret;
8301 __enc_xor:
8302 xor_block();
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8308
8309 movq %r11, %rbp;
8310
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 /**********************************************************************
8315 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8316
8317 popq %rbx;
8318 popq %rbp;
8319 + pax_force_retaddr 0, 1
8320 ret;
8321
8322 __enc_xor4:
8323 @@ -349,6 +355,7 @@ __enc_xor4:
8324
8325 popq %rbx;
8326 popq %rbp;
8327 + pax_force_retaddr 0, 1
8328 ret;
8329
8330 .align 8
8331 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8332 popq %rbx;
8333 popq %rbp;
8334
8335 + pax_force_retaddr 0, 1
8336 ret;
8337
8338 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8339 index 0b33743..7a56206 100644
8340 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8341 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8342 @@ -20,6 +20,8 @@
8343 *
8344 */
8345
8346 +#include <asm/alternative-asm.h>
8347 +
8348 .file "camellia-x86_64-asm_64.S"
8349 .text
8350
8351 @@ -229,12 +231,14 @@ __enc_done:
8352 enc_outunpack(mov, RT1);
8353
8354 movq RRBP, %rbp;
8355 + pax_force_retaddr 0, 1
8356 ret;
8357
8358 __enc_xor:
8359 enc_outunpack(xor, RT1);
8360
8361 movq RRBP, %rbp;
8362 + pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk;
8366 @@ -275,6 +279,7 @@ __dec_rounds16:
8367 dec_outunpack();
8368
8369 movq RRBP, %rbp;
8370 + pax_force_retaddr 0, 1
8371 ret;
8372
8373 /**********************************************************************
8374 @@ -468,6 +473,7 @@ __enc2_done:
8375
8376 movq RRBP, %rbp;
8377 popq %rbx;
8378 + pax_force_retaddr 0, 1
8379 ret;
8380
8381 __enc2_xor:
8382 @@ -475,6 +481,7 @@ __enc2_xor:
8383
8384 movq RRBP, %rbp;
8385 popq %rbx;
8386 + pax_force_retaddr 0, 1
8387 ret;
8388
8389 .global camellia_dec_blk_2way;
8390 @@ -517,4 +524,5 @@ __dec2_rounds16:
8391
8392 movq RRBP, %rbp;
8393 movq RXOR, %rbx;
8394 + pax_force_retaddr 0, 1
8395 ret;
8396 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8397 index 6214a9b..1f4fc9a 100644
8398 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8399 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8400 @@ -1,3 +1,5 @@
8401 +#include <asm/alternative-asm.h>
8402 +
8403 # enter ECRYPT_encrypt_bytes
8404 .text
8405 .p2align 5
8406 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8407 add %r11,%rsp
8408 mov %rdi,%rax
8409 mov %rsi,%rdx
8410 + pax_force_retaddr 0, 1
8411 ret
8412 # bytesatleast65:
8413 ._bytesatleast65:
8414 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8415 add %r11,%rsp
8416 mov %rdi,%rax
8417 mov %rsi,%rdx
8418 + pax_force_retaddr
8419 ret
8420 # enter ECRYPT_ivsetup
8421 .text
8422 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8423 add %r11,%rsp
8424 mov %rdi,%rax
8425 mov %rsi,%rdx
8426 + pax_force_retaddr
8427 ret
8428 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8429 index 3ee1ff0..cbc568b 100644
8430 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8431 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8432 @@ -24,6 +24,8 @@
8433 *
8434 */
8435
8436 +#include <asm/alternative-asm.h>
8437 +
8438 .file "serpent-sse2-x86_64-asm_64.S"
8439 .text
8440
8441 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8442 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8443 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8444
8445 + pax_force_retaddr
8446 ret;
8447
8448 __enc_xor8:
8449 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8450 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8451
8452 + pax_force_retaddr
8453 ret;
8454
8455 .align 8
8456 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8457 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8458 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8459
8460 + pax_force_retaddr
8461 ret;
8462 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8463 index b2c2f57..8470cab 100644
8464 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8465 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8466 @@ -28,6 +28,8 @@
8467 * (at your option) any later version.
8468 */
8469
8470 +#include <asm/alternative-asm.h>
8471 +
8472 #define CTX %rdi // arg1
8473 #define BUF %rsi // arg2
8474 #define CNT %rdx // arg3
8475 @@ -104,6 +106,7 @@
8476 pop %r12
8477 pop %rbp
8478 pop %rbx
8479 + pax_force_retaddr 0, 1
8480 ret
8481
8482 .size \name, .-\name
8483 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8484 index 5b012a2..36d5364 100644
8485 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8486 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8487 @@ -20,6 +20,8 @@
8488 *
8489 */
8490
8491 +#include <asm/alternative-asm.h>
8492 +
8493 .file "twofish-x86_64-asm-3way.S"
8494 .text
8495
8496 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8497 popq %r13;
8498 popq %r14;
8499 popq %r15;
8500 + pax_force_retaddr 0, 1
8501 ret;
8502
8503 __enc_xor3:
8504 @@ -271,6 +274,7 @@ __enc_xor3:
8505 popq %r13;
8506 popq %r14;
8507 popq %r15;
8508 + pax_force_retaddr 0, 1
8509 ret;
8510
8511 .global twofish_dec_blk_3way
8512 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8513 popq %r13;
8514 popq %r14;
8515 popq %r15;
8516 + pax_force_retaddr 0, 1
8517 ret;
8518
8519 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8520 index 7bcf3fc..f53832f 100644
8521 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8522 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8523 @@ -21,6 +21,7 @@
8524 .text
8525
8526 #include <asm/asm-offsets.h>
8527 +#include <asm/alternative-asm.h>
8528
8529 #define a_offset 0
8530 #define b_offset 4
8531 @@ -268,6 +269,7 @@ twofish_enc_blk:
8532
8533 popq R1
8534 movq $1,%rax
8535 + pax_force_retaddr 0, 1
8536 ret
8537
8538 twofish_dec_blk:
8539 @@ -319,4 +321,5 @@ twofish_dec_blk:
8540
8541 popq R1
8542 movq $1,%rax
8543 + pax_force_retaddr 0, 1
8544 ret
8545 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8546 index 07b3a68..bd2a388 100644
8547 --- a/arch/x86/ia32/ia32_aout.c
8548 +++ b/arch/x86/ia32/ia32_aout.c
8549 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8550 unsigned long dump_start, dump_size;
8551 struct user32 dump;
8552
8553 + memset(&dump, 0, sizeof(dump));
8554 +
8555 fs = get_fs();
8556 set_fs(KERNEL_DS);
8557 has_dumped = 1;
8558 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8559 index 673ac9b..7a8c5df 100644
8560 --- a/arch/x86/ia32/ia32_signal.c
8561 +++ b/arch/x86/ia32/ia32_signal.c
8562 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8563 }
8564 seg = get_fs();
8565 set_fs(KERNEL_DS);
8566 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8567 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8568 set_fs(seg);
8569 if (ret >= 0 && uoss_ptr) {
8570 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8571 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8572 */
8573 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8574 size_t frame_size,
8575 - void **fpstate)
8576 + void __user **fpstate)
8577 {
8578 unsigned long sp;
8579
8580 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8581
8582 if (used_math()) {
8583 sp = sp - sig_xstate_ia32_size;
8584 - *fpstate = (struct _fpstate_ia32 *) sp;
8585 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8586 if (save_i387_xstate_ia32(*fpstate) < 0)
8587 return (void __user *) -1L;
8588 }
8589 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8590 sp -= frame_size;
8591 /* Align the stack pointer according to the i386 ABI,
8592 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8593 - sp = ((sp + 4) & -16ul) - 4;
8594 + sp = ((sp - 12) & -16ul) - 4;
8595 return (void __user *) sp;
8596 }
8597
8598 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8599 * These are actually not used anymore, but left because some
8600 * gdb versions depend on them as a marker.
8601 */
8602 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8603 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8604 } put_user_catch(err);
8605
8606 if (err)
8607 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8608 0xb8,
8609 __NR_ia32_rt_sigreturn,
8610 0x80cd,
8611 - 0,
8612 + 0
8613 };
8614
8615 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8616 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8617
8618 if (ka->sa.sa_flags & SA_RESTORER)
8619 restorer = ka->sa.sa_restorer;
8620 + else if (current->mm->context.vdso)
8621 + /* Return stub is in 32bit vsyscall page */
8622 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8623 else
8624 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8625 - rt_sigreturn);
8626 + restorer = &frame->retcode;
8627 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8628
8629 /*
8630 * Not actually used anymore, but left because some gdb
8631 * versions need it.
8632 */
8633 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8634 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8635 } put_user_catch(err);
8636
8637 if (err)
8638 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8639 index 20e5f7b..f33c779 100644
8640 --- a/arch/x86/ia32/ia32entry.S
8641 +++ b/arch/x86/ia32/ia32entry.S
8642 @@ -14,8 +14,10 @@
8643 #include <asm/segment.h>
8644 #include <asm/irqflags.h>
8645 #include <asm/asm.h>
8646 +#include <asm/pgtable.h>
8647 #include <linux/linkage.h>
8648 #include <linux/err.h>
8649 +#include <asm/alternative-asm.h>
8650
8651 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8652 #include <linux/elf-em.h>
8653 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8654 ENDPROC(native_irq_enable_sysexit)
8655 #endif
8656
8657 + .macro pax_enter_kernel_user
8658 + pax_set_fptr_mask
8659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8660 + call pax_enter_kernel_user
8661 +#endif
8662 + .endm
8663 +
8664 + .macro pax_exit_kernel_user
8665 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8666 + call pax_exit_kernel_user
8667 +#endif
8668 +#ifdef CONFIG_PAX_RANDKSTACK
8669 + pushq %rax
8670 + pushq %r11
8671 + call pax_randomize_kstack
8672 + popq %r11
8673 + popq %rax
8674 +#endif
8675 + .endm
8676 +
8677 +.macro pax_erase_kstack
8678 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8679 + call pax_erase_kstack
8680 +#endif
8681 +.endm
8682 +
8683 /*
8684 * 32bit SYSENTER instruction entry.
8685 *
8686 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8687 CFI_REGISTER rsp,rbp
8688 SWAPGS_UNSAFE_STACK
8689 movq PER_CPU_VAR(kernel_stack), %rsp
8690 - addq $(KERNEL_STACK_OFFSET),%rsp
8691 - /*
8692 - * No need to follow this irqs on/off section: the syscall
8693 - * disabled irqs, here we enable it straight after entry:
8694 - */
8695 - ENABLE_INTERRUPTS(CLBR_NONE)
8696 movl %ebp,%ebp /* zero extension */
8697 pushq_cfi $__USER32_DS
8698 /*CFI_REL_OFFSET ss,0*/
8699 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8700 CFI_REL_OFFSET rsp,0
8701 pushfq_cfi
8702 /*CFI_REL_OFFSET rflags,0*/
8703 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8704 - CFI_REGISTER rip,r10
8705 + orl $X86_EFLAGS_IF,(%rsp)
8706 + GET_THREAD_INFO(%r11)
8707 + movl TI_sysenter_return(%r11), %r11d
8708 + CFI_REGISTER rip,r11
8709 pushq_cfi $__USER32_CS
8710 /*CFI_REL_OFFSET cs,0*/
8711 movl %eax, %eax
8712 - pushq_cfi %r10
8713 + pushq_cfi %r11
8714 CFI_REL_OFFSET rip,0
8715 pushq_cfi %rax
8716 cld
8717 SAVE_ARGS 0,1,0
8718 + pax_enter_kernel_user
8719 +
8720 +#ifdef CONFIG_PAX_RANDKSTACK
8721 + pax_erase_kstack
8722 +#endif
8723 +
8724 + /*
8725 + * No need to follow this irqs on/off section: the syscall
8726 + * disabled irqs, here we enable it straight after entry:
8727 + */
8728 + ENABLE_INTERRUPTS(CLBR_NONE)
8729 /* no need to do an access_ok check here because rbp has been
8730 32bit zero extended */
8731 +
8732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8733 + mov $PAX_USER_SHADOW_BASE,%r11
8734 + add %r11,%rbp
8735 +#endif
8736 +
8737 1: movl (%rbp),%ebp
8738 _ASM_EXTABLE(1b,ia32_badarg)
8739 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8740 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8741 + GET_THREAD_INFO(%r11)
8742 + orl $TS_COMPAT,TI_status(%r11)
8743 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8744 CFI_REMEMBER_STATE
8745 jnz sysenter_tracesys
8746 cmpq $(IA32_NR_syscalls-1),%rax
8747 @@ -159,12 +201,15 @@ sysenter_do_call:
8748 sysenter_dispatch:
8749 call *ia32_sys_call_table(,%rax,8)
8750 movq %rax,RAX-ARGOFFSET(%rsp)
8751 + GET_THREAD_INFO(%r11)
8752 DISABLE_INTERRUPTS(CLBR_NONE)
8753 TRACE_IRQS_OFF
8754 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8755 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8756 jnz sysexit_audit
8757 sysexit_from_sys_call:
8758 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8759 + pax_exit_kernel_user
8760 + pax_erase_kstack
8761 + andl $~TS_COMPAT,TI_status(%r11)
8762 /* clear IF, that popfq doesn't enable interrupts early */
8763 andl $~0x200,EFLAGS-R11(%rsp)
8764 movl RIP-R11(%rsp),%edx /* User %eip */
8765 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8766 movl %eax,%esi /* 2nd arg: syscall number */
8767 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8768 call __audit_syscall_entry
8769 +
8770 + pax_erase_kstack
8771 +
8772 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8773 cmpq $(IA32_NR_syscalls-1),%rax
8774 ja ia32_badsys
8775 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8776 .endm
8777
8778 .macro auditsys_exit exit
8779 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8780 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8781 jnz ia32_ret_from_sys_call
8782 TRACE_IRQS_ON
8783 sti
8784 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8785 1: setbe %al /* 1 if error, 0 if not */
8786 movzbl %al,%edi /* zero-extend that into %edi */
8787 call __audit_syscall_exit
8788 + GET_THREAD_INFO(%r11)
8789 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8790 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8791 cli
8792 TRACE_IRQS_OFF
8793 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8794 + testl %edi,TI_flags(%r11)
8795 jz \exit
8796 CLEAR_RREGS -ARGOFFSET
8797 jmp int_with_check
8798 @@ -234,7 +283,7 @@ sysexit_audit:
8799
8800 sysenter_tracesys:
8801 #ifdef CONFIG_AUDITSYSCALL
8802 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8803 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8804 jz sysenter_auditsys
8805 #endif
8806 SAVE_REST
8807 @@ -246,6 +295,9 @@ sysenter_tracesys:
8808 RESTORE_REST
8809 cmpq $(IA32_NR_syscalls-1),%rax
8810 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8811 +
8812 + pax_erase_kstack
8813 +
8814 jmp sysenter_do_call
8815 CFI_ENDPROC
8816 ENDPROC(ia32_sysenter_target)
8817 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8818 ENTRY(ia32_cstar_target)
8819 CFI_STARTPROC32 simple
8820 CFI_SIGNAL_FRAME
8821 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8822 + CFI_DEF_CFA rsp,0
8823 CFI_REGISTER rip,rcx
8824 /*CFI_REGISTER rflags,r11*/
8825 SWAPGS_UNSAFE_STACK
8826 movl %esp,%r8d
8827 CFI_REGISTER rsp,r8
8828 movq PER_CPU_VAR(kernel_stack),%rsp
8829 + SAVE_ARGS 8*6,0,0
8830 + pax_enter_kernel_user
8831 +
8832 +#ifdef CONFIG_PAX_RANDKSTACK
8833 + pax_erase_kstack
8834 +#endif
8835 +
8836 /*
8837 * No need to follow this irqs on/off section: the syscall
8838 * disabled irqs and here we enable it straight after entry:
8839 */
8840 ENABLE_INTERRUPTS(CLBR_NONE)
8841 - SAVE_ARGS 8,0,0
8842 movl %eax,%eax /* zero extension */
8843 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8844 movq %rcx,RIP-ARGOFFSET(%rsp)
8845 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8846 /* no need to do an access_ok check here because r8 has been
8847 32bit zero extended */
8848 /* hardware stack frame is complete now */
8849 +
8850 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8851 + mov $PAX_USER_SHADOW_BASE,%r11
8852 + add %r11,%r8
8853 +#endif
8854 +
8855 1: movl (%r8),%r9d
8856 _ASM_EXTABLE(1b,ia32_badarg)
8857 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8858 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8859 + GET_THREAD_INFO(%r11)
8860 + orl $TS_COMPAT,TI_status(%r11)
8861 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8862 CFI_REMEMBER_STATE
8863 jnz cstar_tracesys
8864 cmpq $IA32_NR_syscalls-1,%rax
8865 @@ -314,12 +379,15 @@ cstar_do_call:
8866 cstar_dispatch:
8867 call *ia32_sys_call_table(,%rax,8)
8868 movq %rax,RAX-ARGOFFSET(%rsp)
8869 + GET_THREAD_INFO(%r11)
8870 DISABLE_INTERRUPTS(CLBR_NONE)
8871 TRACE_IRQS_OFF
8872 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8873 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8874 jnz sysretl_audit
8875 sysretl_from_sys_call:
8876 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8877 + pax_exit_kernel_user
8878 + pax_erase_kstack
8879 + andl $~TS_COMPAT,TI_status(%r11)
8880 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8881 movl RIP-ARGOFFSET(%rsp),%ecx
8882 CFI_REGISTER rip,rcx
8883 @@ -347,7 +415,7 @@ sysretl_audit:
8884
8885 cstar_tracesys:
8886 #ifdef CONFIG_AUDITSYSCALL
8887 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8888 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8889 jz cstar_auditsys
8890 #endif
8891 xchgl %r9d,%ebp
8892 @@ -361,6 +429,9 @@ cstar_tracesys:
8893 xchgl %ebp,%r9d
8894 cmpq $(IA32_NR_syscalls-1),%rax
8895 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8896 +
8897 + pax_erase_kstack
8898 +
8899 jmp cstar_do_call
8900 END(ia32_cstar_target)
8901
8902 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8903 CFI_REL_OFFSET rip,RIP-RIP
8904 PARAVIRT_ADJUST_EXCEPTION_FRAME
8905 SWAPGS
8906 - /*
8907 - * No need to follow this irqs on/off section: the syscall
8908 - * disabled irqs and here we enable it straight after entry:
8909 - */
8910 - ENABLE_INTERRUPTS(CLBR_NONE)
8911 movl %eax,%eax
8912 pushq_cfi %rax
8913 cld
8914 /* note the registers are not zero extended to the sf.
8915 this could be a problem. */
8916 SAVE_ARGS 0,1,0
8917 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8918 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8919 + pax_enter_kernel_user
8920 +
8921 +#ifdef CONFIG_PAX_RANDKSTACK
8922 + pax_erase_kstack
8923 +#endif
8924 +
8925 + /*
8926 + * No need to follow this irqs on/off section: the syscall
8927 + * disabled irqs and here we enable it straight after entry:
8928 + */
8929 + ENABLE_INTERRUPTS(CLBR_NONE)
8930 + GET_THREAD_INFO(%r11)
8931 + orl $TS_COMPAT,TI_status(%r11)
8932 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8933 jnz ia32_tracesys
8934 cmpq $(IA32_NR_syscalls-1),%rax
8935 ja ia32_badsys
8936 @@ -436,6 +514,9 @@ ia32_tracesys:
8937 RESTORE_REST
8938 cmpq $(IA32_NR_syscalls-1),%rax
8939 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8940 +
8941 + pax_erase_kstack
8942 +
8943 jmp ia32_do_call
8944 END(ia32_syscall)
8945
8946 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8947 index 4540bec..714d913 100644
8948 --- a/arch/x86/ia32/sys_ia32.c
8949 +++ b/arch/x86/ia32/sys_ia32.c
8950 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8951 */
8952 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8953 {
8954 - typeof(ubuf->st_uid) uid = 0;
8955 - typeof(ubuf->st_gid) gid = 0;
8956 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8957 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8958 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8959 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8960 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8961 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8962 return ret;
8963 }
8964
8965 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8966 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8967 int options)
8968 {
8969 return compat_sys_wait4(pid, stat_addr, options, NULL);
8970 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8971 mm_segment_t old_fs = get_fs();
8972
8973 set_fs(KERNEL_DS);
8974 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8975 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8976 set_fs(old_fs);
8977 if (put_compat_timespec(&t, interval))
8978 return -EFAULT;
8979 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8980 mm_segment_t old_fs = get_fs();
8981
8982 set_fs(KERNEL_DS);
8983 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8984 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8985 set_fs(old_fs);
8986 if (!ret) {
8987 switch (_NSIG_WORDS) {
8988 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8989 if (copy_siginfo_from_user32(&info, uinfo))
8990 return -EFAULT;
8991 set_fs(KERNEL_DS);
8992 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8993 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8994 set_fs(old_fs);
8995 return ret;
8996 }
8997 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8998 return -EFAULT;
8999
9000 set_fs(KERNEL_DS);
9001 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9002 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9003 count);
9004 set_fs(old_fs);
9005
9006 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9007 index 952bd01..7692c6f 100644
9008 --- a/arch/x86/include/asm/alternative-asm.h
9009 +++ b/arch/x86/include/asm/alternative-asm.h
9010 @@ -15,6 +15,45 @@
9011 .endm
9012 #endif
9013
9014 +#ifdef KERNEXEC_PLUGIN
9015 + .macro pax_force_retaddr_bts rip=0
9016 + btsq $63,\rip(%rsp)
9017 + .endm
9018 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9019 + .macro pax_force_retaddr rip=0, reload=0
9020 + btsq $63,\rip(%rsp)
9021 + .endm
9022 + .macro pax_force_fptr ptr
9023 + btsq $63,\ptr
9024 + .endm
9025 + .macro pax_set_fptr_mask
9026 + .endm
9027 +#endif
9028 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9029 + .macro pax_force_retaddr rip=0, reload=0
9030 + .if \reload
9031 + pax_set_fptr_mask
9032 + .endif
9033 + orq %r10,\rip(%rsp)
9034 + .endm
9035 + .macro pax_force_fptr ptr
9036 + orq %r10,\ptr
9037 + .endm
9038 + .macro pax_set_fptr_mask
9039 + movabs $0x8000000000000000,%r10
9040 + .endm
9041 +#endif
9042 +#else
9043 + .macro pax_force_retaddr rip=0, reload=0
9044 + .endm
9045 + .macro pax_force_fptr ptr
9046 + .endm
9047 + .macro pax_force_retaddr_bts rip=0
9048 + .endm
9049 + .macro pax_set_fptr_mask
9050 + .endm
9051 +#endif
9052 +
9053 .macro altinstruction_entry orig alt feature orig_len alt_len
9054 .long \orig - .
9055 .long \alt - .
9056 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9057 index 49331be..9706065 100644
9058 --- a/arch/x86/include/asm/alternative.h
9059 +++ b/arch/x86/include/asm/alternative.h
9060 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9061 ".section .discard,\"aw\",@progbits\n" \
9062 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9063 ".previous\n" \
9064 - ".section .altinstr_replacement, \"ax\"\n" \
9065 + ".section .altinstr_replacement, \"a\"\n" \
9066 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9067 ".previous"
9068
9069 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9070 index eaff479..3025a63 100644
9071 --- a/arch/x86/include/asm/apic.h
9072 +++ b/arch/x86/include/asm/apic.h
9073 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9074
9075 #ifdef CONFIG_X86_LOCAL_APIC
9076
9077 -extern unsigned int apic_verbosity;
9078 +extern int apic_verbosity;
9079 extern int local_apic_timer_c2_ok;
9080
9081 extern int disable_apic;
9082 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9083 index 20370c6..a2eb9b0 100644
9084 --- a/arch/x86/include/asm/apm.h
9085 +++ b/arch/x86/include/asm/apm.h
9086 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9087 __asm__ __volatile__(APM_DO_ZERO_SEGS
9088 "pushl %%edi\n\t"
9089 "pushl %%ebp\n\t"
9090 - "lcall *%%cs:apm_bios_entry\n\t"
9091 + "lcall *%%ss:apm_bios_entry\n\t"
9092 "setc %%al\n\t"
9093 "popl %%ebp\n\t"
9094 "popl %%edi\n\t"
9095 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9096 __asm__ __volatile__(APM_DO_ZERO_SEGS
9097 "pushl %%edi\n\t"
9098 "pushl %%ebp\n\t"
9099 - "lcall *%%cs:apm_bios_entry\n\t"
9100 + "lcall *%%ss:apm_bios_entry\n\t"
9101 "setc %%bl\n\t"
9102 "popl %%ebp\n\t"
9103 "popl %%edi\n\t"
9104 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9105 index 58cb6d4..a4b806c 100644
9106 --- a/arch/x86/include/asm/atomic.h
9107 +++ b/arch/x86/include/asm/atomic.h
9108 @@ -22,7 +22,18 @@
9109 */
9110 static inline int atomic_read(const atomic_t *v)
9111 {
9112 - return (*(volatile int *)&(v)->counter);
9113 + return (*(volatile const int *)&(v)->counter);
9114 +}
9115 +
9116 +/**
9117 + * atomic_read_unchecked - read atomic variable
9118 + * @v: pointer of type atomic_unchecked_t
9119 + *
9120 + * Atomically reads the value of @v.
9121 + */
9122 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9123 +{
9124 + return (*(volatile const int *)&(v)->counter);
9125 }
9126
9127 /**
9128 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9129 }
9130
9131 /**
9132 + * atomic_set_unchecked - set atomic variable
9133 + * @v: pointer of type atomic_unchecked_t
9134 + * @i: required value
9135 + *
9136 + * Atomically sets the value of @v to @i.
9137 + */
9138 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9139 +{
9140 + v->counter = i;
9141 +}
9142 +
9143 +/**
9144 * atomic_add - add integer to atomic variable
9145 * @i: integer value to add
9146 * @v: pointer of type atomic_t
9147 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9148 */
9149 static inline void atomic_add(int i, atomic_t *v)
9150 {
9151 - asm volatile(LOCK_PREFIX "addl %1,%0"
9152 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9153 +
9154 +#ifdef CONFIG_PAX_REFCOUNT
9155 + "jno 0f\n"
9156 + LOCK_PREFIX "subl %1,%0\n"
9157 + "int $4\n0:\n"
9158 + _ASM_EXTABLE(0b, 0b)
9159 +#endif
9160 +
9161 + : "+m" (v->counter)
9162 + : "ir" (i));
9163 +}
9164 +
9165 +/**
9166 + * atomic_add_unchecked - add integer to atomic variable
9167 + * @i: integer value to add
9168 + * @v: pointer of type atomic_unchecked_t
9169 + *
9170 + * Atomically adds @i to @v.
9171 + */
9172 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9173 +{
9174 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9175 : "+m" (v->counter)
9176 : "ir" (i));
9177 }
9178 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9179 */
9180 static inline void atomic_sub(int i, atomic_t *v)
9181 {
9182 - asm volatile(LOCK_PREFIX "subl %1,%0"
9183 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9184 +
9185 +#ifdef CONFIG_PAX_REFCOUNT
9186 + "jno 0f\n"
9187 + LOCK_PREFIX "addl %1,%0\n"
9188 + "int $4\n0:\n"
9189 + _ASM_EXTABLE(0b, 0b)
9190 +#endif
9191 +
9192 + : "+m" (v->counter)
9193 + : "ir" (i));
9194 +}
9195 +
9196 +/**
9197 + * atomic_sub_unchecked - subtract integer from atomic variable
9198 + * @i: integer value to subtract
9199 + * @v: pointer of type atomic_unchecked_t
9200 + *
9201 + * Atomically subtracts @i from @v.
9202 + */
9203 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9204 +{
9205 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9206 : "+m" (v->counter)
9207 : "ir" (i));
9208 }
9209 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9210 {
9211 unsigned char c;
9212
9213 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9214 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9215 +
9216 +#ifdef CONFIG_PAX_REFCOUNT
9217 + "jno 0f\n"
9218 + LOCK_PREFIX "addl %2,%0\n"
9219 + "int $4\n0:\n"
9220 + _ASM_EXTABLE(0b, 0b)
9221 +#endif
9222 +
9223 + "sete %1\n"
9224 : "+m" (v->counter), "=qm" (c)
9225 : "ir" (i) : "memory");
9226 return c;
9227 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9228 */
9229 static inline void atomic_inc(atomic_t *v)
9230 {
9231 - asm volatile(LOCK_PREFIX "incl %0"
9232 + asm volatile(LOCK_PREFIX "incl %0\n"
9233 +
9234 +#ifdef CONFIG_PAX_REFCOUNT
9235 + "jno 0f\n"
9236 + LOCK_PREFIX "decl %0\n"
9237 + "int $4\n0:\n"
9238 + _ASM_EXTABLE(0b, 0b)
9239 +#endif
9240 +
9241 + : "+m" (v->counter));
9242 +}
9243 +
9244 +/**
9245 + * atomic_inc_unchecked - increment atomic variable
9246 + * @v: pointer of type atomic_unchecked_t
9247 + *
9248 + * Atomically increments @v by 1.
9249 + */
9250 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9251 +{
9252 + asm volatile(LOCK_PREFIX "incl %0\n"
9253 : "+m" (v->counter));
9254 }
9255
9256 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9257 */
9258 static inline void atomic_dec(atomic_t *v)
9259 {
9260 - asm volatile(LOCK_PREFIX "decl %0"
9261 + asm volatile(LOCK_PREFIX "decl %0\n"
9262 +
9263 +#ifdef CONFIG_PAX_REFCOUNT
9264 + "jno 0f\n"
9265 + LOCK_PREFIX "incl %0\n"
9266 + "int $4\n0:\n"
9267 + _ASM_EXTABLE(0b, 0b)
9268 +#endif
9269 +
9270 + : "+m" (v->counter));
9271 +}
9272 +
9273 +/**
9274 + * atomic_dec_unchecked - decrement atomic variable
9275 + * @v: pointer of type atomic_unchecked_t
9276 + *
9277 + * Atomically decrements @v by 1.
9278 + */
9279 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9280 +{
9281 + asm volatile(LOCK_PREFIX "decl %0\n"
9282 : "+m" (v->counter));
9283 }
9284
9285 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9286 {
9287 unsigned char c;
9288
9289 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9290 + asm volatile(LOCK_PREFIX "decl %0\n"
9291 +
9292 +#ifdef CONFIG_PAX_REFCOUNT
9293 + "jno 0f\n"
9294 + LOCK_PREFIX "incl %0\n"
9295 + "int $4\n0:\n"
9296 + _ASM_EXTABLE(0b, 0b)
9297 +#endif
9298 +
9299 + "sete %1\n"
9300 : "+m" (v->counter), "=qm" (c)
9301 : : "memory");
9302 return c != 0;
9303 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9304 {
9305 unsigned char c;
9306
9307 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9308 + asm volatile(LOCK_PREFIX "incl %0\n"
9309 +
9310 +#ifdef CONFIG_PAX_REFCOUNT
9311 + "jno 0f\n"
9312 + LOCK_PREFIX "decl %0\n"
9313 + "int $4\n0:\n"
9314 + _ASM_EXTABLE(0b, 0b)
9315 +#endif
9316 +
9317 + "sete %1\n"
9318 + : "+m" (v->counter), "=qm" (c)
9319 + : : "memory");
9320 + return c != 0;
9321 +}
9322 +
9323 +/**
9324 + * atomic_inc_and_test_unchecked - increment and test
9325 + * @v: pointer of type atomic_unchecked_t
9326 + *
9327 + * Atomically increments @v by 1
9328 + * and returns true if the result is zero, or false for all
9329 + * other cases.
9330 + */
9331 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9332 +{
9333 + unsigned char c;
9334 +
9335 + asm volatile(LOCK_PREFIX "incl %0\n"
9336 + "sete %1\n"
9337 : "+m" (v->counter), "=qm" (c)
9338 : : "memory");
9339 return c != 0;
9340 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9341 {
9342 unsigned char c;
9343
9344 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9345 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9346 +
9347 +#ifdef CONFIG_PAX_REFCOUNT
9348 + "jno 0f\n"
9349 + LOCK_PREFIX "subl %2,%0\n"
9350 + "int $4\n0:\n"
9351 + _ASM_EXTABLE(0b, 0b)
9352 +#endif
9353 +
9354 + "sets %1\n"
9355 : "+m" (v->counter), "=qm" (c)
9356 : "ir" (i) : "memory");
9357 return c;
9358 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9359 goto no_xadd;
9360 #endif
9361 /* Modern 486+ processor */
9362 - return i + xadd(&v->counter, i);
9363 + return i + xadd_check_overflow(&v->counter, i);
9364
9365 #ifdef CONFIG_M386
9366 no_xadd: /* Legacy 386 processor */
9367 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9368 }
9369
9370 /**
9371 + * atomic_add_return_unchecked - add integer and return
9372 + * @i: integer value to add
9373 + * @v: pointer of type atomic_unchecked_t
9374 + *
9375 + * Atomically adds @i to @v and returns @i + @v
9376 + */
9377 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9378 +{
9379 +#ifdef CONFIG_M386
9380 + int __i;
9381 + unsigned long flags;
9382 + if (unlikely(boot_cpu_data.x86 <= 3))
9383 + goto no_xadd;
9384 +#endif
9385 + /* Modern 486+ processor */
9386 + return i + xadd(&v->counter, i);
9387 +
9388 +#ifdef CONFIG_M386
9389 +no_xadd: /* Legacy 386 processor */
9390 + raw_local_irq_save(flags);
9391 + __i = atomic_read_unchecked(v);
9392 + atomic_set_unchecked(v, i + __i);
9393 + raw_local_irq_restore(flags);
9394 + return i + __i;
9395 +#endif
9396 +}
9397 +
9398 +/**
9399 * atomic_sub_return - subtract integer and return
9400 * @v: pointer of type atomic_t
9401 * @i: integer value to subtract
9402 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9403 }
9404
9405 #define atomic_inc_return(v) (atomic_add_return(1, v))
9406 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9407 +{
9408 + return atomic_add_return_unchecked(1, v);
9409 +}
9410 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9411
9412 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9413 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9414 return cmpxchg(&v->counter, old, new);
9415 }
9416
9417 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9418 +{
9419 + return cmpxchg(&v->counter, old, new);
9420 +}
9421 +
9422 static inline int atomic_xchg(atomic_t *v, int new)
9423 {
9424 return xchg(&v->counter, new);
9425 }
9426
9427 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9428 +{
9429 + return xchg(&v->counter, new);
9430 +}
9431 +
9432 /**
9433 * __atomic_add_unless - add unless the number is already a given value
9434 * @v: pointer of type atomic_t
9435 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9436 */
9437 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9438 {
9439 - int c, old;
9440 + int c, old, new;
9441 c = atomic_read(v);
9442 for (;;) {
9443 - if (unlikely(c == (u)))
9444 + if (unlikely(c == u))
9445 break;
9446 - old = atomic_cmpxchg((v), c, c + (a));
9447 +
9448 + asm volatile("addl %2,%0\n"
9449 +
9450 +#ifdef CONFIG_PAX_REFCOUNT
9451 + "jno 0f\n"
9452 + "subl %2,%0\n"
9453 + "int $4\n0:\n"
9454 + _ASM_EXTABLE(0b, 0b)
9455 +#endif
9456 +
9457 + : "=r" (new)
9458 + : "0" (c), "ir" (a));
9459 +
9460 + old = atomic_cmpxchg(v, c, new);
9461 if (likely(old == c))
9462 break;
9463 c = old;
9464 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9465 return c;
9466 }
9467
9468 +/**
9469 + * atomic_inc_not_zero_hint - increment if not null
9470 + * @v: pointer of type atomic_t
9471 + * @hint: probable value of the atomic before the increment
9472 + *
9473 + * This version of atomic_inc_not_zero() gives a hint of probable
9474 + * value of the atomic. This helps processor to not read the memory
9475 + * before doing the atomic read/modify/write cycle, lowering
9476 + * number of bus transactions on some arches.
9477 + *
9478 + * Returns: 0 if increment was not done, 1 otherwise.
9479 + */
9480 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9481 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9482 +{
9483 + int val, c = hint, new;
9484 +
9485 + /* sanity test, should be removed by compiler if hint is a constant */
9486 + if (!hint)
9487 + return __atomic_add_unless(v, 1, 0);
9488 +
9489 + do {
9490 + asm volatile("incl %0\n"
9491 +
9492 +#ifdef CONFIG_PAX_REFCOUNT
9493 + "jno 0f\n"
9494 + "decl %0\n"
9495 + "int $4\n0:\n"
9496 + _ASM_EXTABLE(0b, 0b)
9497 +#endif
9498 +
9499 + : "=r" (new)
9500 + : "0" (c));
9501 +
9502 + val = atomic_cmpxchg(v, c, new);
9503 + if (val == c)
9504 + return 1;
9505 + c = val;
9506 + } while (c);
9507 +
9508 + return 0;
9509 +}
9510
9511 /*
9512 * atomic_dec_if_positive - decrement by 1 if old value positive
9513 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9514 #endif
9515
9516 /* These are x86-specific, used by some header files */
9517 -#define atomic_clear_mask(mask, addr) \
9518 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9519 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9520 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9521 +{
9522 + asm volatile(LOCK_PREFIX "andl %1,%0"
9523 + : "+m" (v->counter)
9524 + : "r" (~(mask))
9525 + : "memory");
9526 +}
9527
9528 -#define atomic_set_mask(mask, addr) \
9529 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9530 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9531 - : "memory")
9532 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9533 +{
9534 + asm volatile(LOCK_PREFIX "andl %1,%0"
9535 + : "+m" (v->counter)
9536 + : "r" (~(mask))
9537 + : "memory");
9538 +}
9539 +
9540 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9541 +{
9542 + asm volatile(LOCK_PREFIX "orl %1,%0"
9543 + : "+m" (v->counter)
9544 + : "r" (mask)
9545 + : "memory");
9546 +}
9547 +
9548 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9549 +{
9550 + asm volatile(LOCK_PREFIX "orl %1,%0"
9551 + : "+m" (v->counter)
9552 + : "r" (mask)
9553 + : "memory");
9554 +}
9555
9556 /* Atomic operations are already serializing on x86 */
9557 #define smp_mb__before_atomic_dec() barrier()
9558 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9559 index b154de7..aadebd8 100644
9560 --- a/arch/x86/include/asm/atomic64_32.h
9561 +++ b/arch/x86/include/asm/atomic64_32.h
9562 @@ -12,6 +12,14 @@ typedef struct {
9563 u64 __aligned(8) counter;
9564 } atomic64_t;
9565
9566 +#ifdef CONFIG_PAX_REFCOUNT
9567 +typedef struct {
9568 + u64 __aligned(8) counter;
9569 +} atomic64_unchecked_t;
9570 +#else
9571 +typedef atomic64_t atomic64_unchecked_t;
9572 +#endif
9573 +
9574 #define ATOMIC64_INIT(val) { (val) }
9575
9576 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9577 @@ -37,21 +45,31 @@ typedef struct {
9578 ATOMIC64_DECL_ONE(sym##_386)
9579
9580 ATOMIC64_DECL_ONE(add_386);
9581 +ATOMIC64_DECL_ONE(add_unchecked_386);
9582 ATOMIC64_DECL_ONE(sub_386);
9583 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9584 ATOMIC64_DECL_ONE(inc_386);
9585 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9586 ATOMIC64_DECL_ONE(dec_386);
9587 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9588 #endif
9589
9590 #define alternative_atomic64(f, out, in...) \
9591 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9592
9593 ATOMIC64_DECL(read);
9594 +ATOMIC64_DECL(read_unchecked);
9595 ATOMIC64_DECL(set);
9596 +ATOMIC64_DECL(set_unchecked);
9597 ATOMIC64_DECL(xchg);
9598 ATOMIC64_DECL(add_return);
9599 +ATOMIC64_DECL(add_return_unchecked);
9600 ATOMIC64_DECL(sub_return);
9601 +ATOMIC64_DECL(sub_return_unchecked);
9602 ATOMIC64_DECL(inc_return);
9603 +ATOMIC64_DECL(inc_return_unchecked);
9604 ATOMIC64_DECL(dec_return);
9605 +ATOMIC64_DECL(dec_return_unchecked);
9606 ATOMIC64_DECL(dec_if_positive);
9607 ATOMIC64_DECL(inc_not_zero);
9608 ATOMIC64_DECL(add_unless);
9609 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9610 }
9611
9612 /**
9613 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9614 + * @p: pointer to type atomic64_unchecked_t
9615 + * @o: expected value
9616 + * @n: new value
9617 + *
9618 + * Atomically sets @v to @n if it was equal to @o and returns
9619 + * the old value.
9620 + */
9621 +
9622 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9623 +{
9624 + return cmpxchg64(&v->counter, o, n);
9625 +}
9626 +
9627 +/**
9628 * atomic64_xchg - xchg atomic64 variable
9629 * @v: pointer to type atomic64_t
9630 * @n: value to assign
9631 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9632 }
9633
9634 /**
9635 + * atomic64_set_unchecked - set atomic64 variable
9636 + * @v: pointer to type atomic64_unchecked_t
9637 + * @n: value to assign
9638 + *
9639 + * Atomically sets the value of @v to @n.
9640 + */
9641 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9642 +{
9643 + unsigned high = (unsigned)(i >> 32);
9644 + unsigned low = (unsigned)i;
9645 + alternative_atomic64(set, /* no output */,
9646 + "S" (v), "b" (low), "c" (high)
9647 + : "eax", "edx", "memory");
9648 +}
9649 +
9650 +/**
9651 * atomic64_read - read atomic64 variable
9652 * @v: pointer to type atomic64_t
9653 *
9654 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9655 }
9656
9657 /**
9658 + * atomic64_read_unchecked - read atomic64 variable
9659 + * @v: pointer to type atomic64_unchecked_t
9660 + *
9661 + * Atomically reads the value of @v and returns it.
9662 + */
9663 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9664 +{
9665 + long long r;
9666 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9667 + return r;
9668 + }
9669 +
9670 +/**
9671 * atomic64_add_return - add and return
9672 * @i: integer value to add
9673 * @v: pointer to type atomic64_t
9674 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9675 return i;
9676 }
9677
9678 +/**
9679 + * atomic64_add_return_unchecked - add and return
9680 + * @i: integer value to add
9681 + * @v: pointer to type atomic64_unchecked_t
9682 + *
9683 + * Atomically adds @i to @v and returns @i + *@v
9684 + */
9685 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9686 +{
9687 + alternative_atomic64(add_return_unchecked,
9688 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9689 + ASM_NO_INPUT_CLOBBER("memory"));
9690 + return i;
9691 +}
9692 +
9693 /*
9694 * Other variants with different arithmetic operators:
9695 */
9696 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9697 return a;
9698 }
9699
9700 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9701 +{
9702 + long long a;
9703 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9704 + "S" (v) : "memory", "ecx");
9705 + return a;
9706 +}
9707 +
9708 static inline long long atomic64_dec_return(atomic64_t *v)
9709 {
9710 long long a;
9711 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9712 }
9713
9714 /**
9715 + * atomic64_add_unchecked - add integer to atomic64 variable
9716 + * @i: integer value to add
9717 + * @v: pointer to type atomic64_unchecked_t
9718 + *
9719 + * Atomically adds @i to @v.
9720 + */
9721 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9722 +{
9723 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9724 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9725 + ASM_NO_INPUT_CLOBBER("memory"));
9726 + return i;
9727 +}
9728 +
9729 +/**
9730 * atomic64_sub - subtract the atomic64 variable
9731 * @i: integer value to subtract
9732 * @v: pointer to type atomic64_t
9733 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9734 index 0e1cbfc..5623683 100644
9735 --- a/arch/x86/include/asm/atomic64_64.h
9736 +++ b/arch/x86/include/asm/atomic64_64.h
9737 @@ -18,7 +18,19 @@
9738 */
9739 static inline long atomic64_read(const atomic64_t *v)
9740 {
9741 - return (*(volatile long *)&(v)->counter);
9742 + return (*(volatile const long *)&(v)->counter);
9743 +}
9744 +
9745 +/**
9746 + * atomic64_read_unchecked - read atomic64 variable
9747 + * @v: pointer of type atomic64_unchecked_t
9748 + *
9749 + * Atomically reads the value of @v.
9750 + * Doesn't imply a read memory barrier.
9751 + */
9752 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9753 +{
9754 + return (*(volatile const long *)&(v)->counter);
9755 }
9756
9757 /**
9758 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9759 }
9760
9761 /**
9762 + * atomic64_set_unchecked - set atomic64 variable
9763 + * @v: pointer to type atomic64_unchecked_t
9764 + * @i: required value
9765 + *
9766 + * Atomically sets the value of @v to @i.
9767 + */
9768 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9769 +{
9770 + v->counter = i;
9771 +}
9772 +
9773 +/**
9774 * atomic64_add - add integer to atomic64 variable
9775 * @i: integer value to add
9776 * @v: pointer to type atomic64_t
9777 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9778 */
9779 static inline void atomic64_add(long i, atomic64_t *v)
9780 {
9781 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9782 +
9783 +#ifdef CONFIG_PAX_REFCOUNT
9784 + "jno 0f\n"
9785 + LOCK_PREFIX "subq %1,%0\n"
9786 + "int $4\n0:\n"
9787 + _ASM_EXTABLE(0b, 0b)
9788 +#endif
9789 +
9790 + : "=m" (v->counter)
9791 + : "er" (i), "m" (v->counter));
9792 +}
9793 +
9794 +/**
9795 + * atomic64_add_unchecked - add integer to atomic64 variable
9796 + * @i: integer value to add
9797 + * @v: pointer to type atomic64_unchecked_t
9798 + *
9799 + * Atomically adds @i to @v.
9800 + */
9801 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9802 +{
9803 asm volatile(LOCK_PREFIX "addq %1,%0"
9804 : "=m" (v->counter)
9805 : "er" (i), "m" (v->counter));
9806 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9807 */
9808 static inline void atomic64_sub(long i, atomic64_t *v)
9809 {
9810 - asm volatile(LOCK_PREFIX "subq %1,%0"
9811 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9812 +
9813 +#ifdef CONFIG_PAX_REFCOUNT
9814 + "jno 0f\n"
9815 + LOCK_PREFIX "addq %1,%0\n"
9816 + "int $4\n0:\n"
9817 + _ASM_EXTABLE(0b, 0b)
9818 +#endif
9819 +
9820 + : "=m" (v->counter)
9821 + : "er" (i), "m" (v->counter));
9822 +}
9823 +
9824 +/**
9825 + * atomic64_sub_unchecked - subtract the atomic64 variable
9826 + * @i: integer value to subtract
9827 + * @v: pointer to type atomic64_unchecked_t
9828 + *
9829 + * Atomically subtracts @i from @v.
9830 + */
9831 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9832 +{
9833 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9834 : "=m" (v->counter)
9835 : "er" (i), "m" (v->counter));
9836 }
9837 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9838 {
9839 unsigned char c;
9840
9841 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9842 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9843 +
9844 +#ifdef CONFIG_PAX_REFCOUNT
9845 + "jno 0f\n"
9846 + LOCK_PREFIX "addq %2,%0\n"
9847 + "int $4\n0:\n"
9848 + _ASM_EXTABLE(0b, 0b)
9849 +#endif
9850 +
9851 + "sete %1\n"
9852 : "=m" (v->counter), "=qm" (c)
9853 : "er" (i), "m" (v->counter) : "memory");
9854 return c;
9855 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9856 */
9857 static inline void atomic64_inc(atomic64_t *v)
9858 {
9859 + asm volatile(LOCK_PREFIX "incq %0\n"
9860 +
9861 +#ifdef CONFIG_PAX_REFCOUNT
9862 + "jno 0f\n"
9863 + LOCK_PREFIX "decq %0\n"
9864 + "int $4\n0:\n"
9865 + _ASM_EXTABLE(0b, 0b)
9866 +#endif
9867 +
9868 + : "=m" (v->counter)
9869 + : "m" (v->counter));
9870 +}
9871 +
9872 +/**
9873 + * atomic64_inc_unchecked - increment atomic64 variable
9874 + * @v: pointer to type atomic64_unchecked_t
9875 + *
9876 + * Atomically increments @v by 1.
9877 + */
9878 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9879 +{
9880 asm volatile(LOCK_PREFIX "incq %0"
9881 : "=m" (v->counter)
9882 : "m" (v->counter));
9883 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9884 */
9885 static inline void atomic64_dec(atomic64_t *v)
9886 {
9887 - asm volatile(LOCK_PREFIX "decq %0"
9888 + asm volatile(LOCK_PREFIX "decq %0\n"
9889 +
9890 +#ifdef CONFIG_PAX_REFCOUNT
9891 + "jno 0f\n"
9892 + LOCK_PREFIX "incq %0\n"
9893 + "int $4\n0:\n"
9894 + _ASM_EXTABLE(0b, 0b)
9895 +#endif
9896 +
9897 + : "=m" (v->counter)
9898 + : "m" (v->counter));
9899 +}
9900 +
9901 +/**
9902 + * atomic64_dec_unchecked - decrement atomic64 variable
9903 + * @v: pointer to type atomic64_t
9904 + *
9905 + * Atomically decrements @v by 1.
9906 + */
9907 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9908 +{
9909 + asm volatile(LOCK_PREFIX "decq %0\n"
9910 : "=m" (v->counter)
9911 : "m" (v->counter));
9912 }
9913 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9914 {
9915 unsigned char c;
9916
9917 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9918 + asm volatile(LOCK_PREFIX "decq %0\n"
9919 +
9920 +#ifdef CONFIG_PAX_REFCOUNT
9921 + "jno 0f\n"
9922 + LOCK_PREFIX "incq %0\n"
9923 + "int $4\n0:\n"
9924 + _ASM_EXTABLE(0b, 0b)
9925 +#endif
9926 +
9927 + "sete %1\n"
9928 : "=m" (v->counter), "=qm" (c)
9929 : "m" (v->counter) : "memory");
9930 return c != 0;
9931 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9932 {
9933 unsigned char c;
9934
9935 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9936 + asm volatile(LOCK_PREFIX "incq %0\n"
9937 +
9938 +#ifdef CONFIG_PAX_REFCOUNT
9939 + "jno 0f\n"
9940 + LOCK_PREFIX "decq %0\n"
9941 + "int $4\n0:\n"
9942 + _ASM_EXTABLE(0b, 0b)
9943 +#endif
9944 +
9945 + "sete %1\n"
9946 : "=m" (v->counter), "=qm" (c)
9947 : "m" (v->counter) : "memory");
9948 return c != 0;
9949 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9950 {
9951 unsigned char c;
9952
9953 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9954 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9955 +
9956 +#ifdef CONFIG_PAX_REFCOUNT
9957 + "jno 0f\n"
9958 + LOCK_PREFIX "subq %2,%0\n"
9959 + "int $4\n0:\n"
9960 + _ASM_EXTABLE(0b, 0b)
9961 +#endif
9962 +
9963 + "sets %1\n"
9964 : "=m" (v->counter), "=qm" (c)
9965 : "er" (i), "m" (v->counter) : "memory");
9966 return c;
9967 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9968 */
9969 static inline long atomic64_add_return(long i, atomic64_t *v)
9970 {
9971 + return i + xadd_check_overflow(&v->counter, i);
9972 +}
9973 +
9974 +/**
9975 + * atomic64_add_return_unchecked - add and return
9976 + * @i: integer value to add
9977 + * @v: pointer to type atomic64_unchecked_t
9978 + *
9979 + * Atomically adds @i to @v and returns @i + @v
9980 + */
9981 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9982 +{
9983 return i + xadd(&v->counter, i);
9984 }
9985
9986 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9987 }
9988
9989 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9990 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9991 +{
9992 + return atomic64_add_return_unchecked(1, v);
9993 +}
9994 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9995
9996 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9997 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9998 return cmpxchg(&v->counter, old, new);
9999 }
10000
10001 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10002 +{
10003 + return cmpxchg(&v->counter, old, new);
10004 +}
10005 +
10006 static inline long atomic64_xchg(atomic64_t *v, long new)
10007 {
10008 return xchg(&v->counter, new);
10009 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10010 */
10011 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10012 {
10013 - long c, old;
10014 + long c, old, new;
10015 c = atomic64_read(v);
10016 for (;;) {
10017 - if (unlikely(c == (u)))
10018 + if (unlikely(c == u))
10019 break;
10020 - old = atomic64_cmpxchg((v), c, c + (a));
10021 +
10022 + asm volatile("add %2,%0\n"
10023 +
10024 +#ifdef CONFIG_PAX_REFCOUNT
10025 + "jno 0f\n"
10026 + "sub %2,%0\n"
10027 + "int $4\n0:\n"
10028 + _ASM_EXTABLE(0b, 0b)
10029 +#endif
10030 +
10031 + : "=r" (new)
10032 + : "0" (c), "ir" (a));
10033 +
10034 + old = atomic64_cmpxchg(v, c, new);
10035 if (likely(old == c))
10036 break;
10037 c = old;
10038 }
10039 - return c != (u);
10040 + return c != u;
10041 }
10042
10043 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10044 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10045 index a6983b2..63f48a2 100644
10046 --- a/arch/x86/include/asm/bitops.h
10047 +++ b/arch/x86/include/asm/bitops.h
10048 @@ -40,7 +40,7 @@
10049 * a mask operation on a byte.
10050 */
10051 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10052 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10053 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10054 #define CONST_MASK(nr) (1 << ((nr) & 7))
10055
10056 /**
10057 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10058 index b13fe63..0dab13a 100644
10059 --- a/arch/x86/include/asm/boot.h
10060 +++ b/arch/x86/include/asm/boot.h
10061 @@ -11,10 +11,15 @@
10062 #include <asm/pgtable_types.h>
10063
10064 /* Physical address where kernel should be loaded. */
10065 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10066 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10067 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10068 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10069
10070 +#ifndef __ASSEMBLY__
10071 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10072 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10073 +#endif
10074 +
10075 /* Minimum kernel alignment, as a power of two */
10076 #ifdef CONFIG_X86_64
10077 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10078 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10079 index 48f99f1..d78ebf9 100644
10080 --- a/arch/x86/include/asm/cache.h
10081 +++ b/arch/x86/include/asm/cache.h
10082 @@ -5,12 +5,13 @@
10083
10084 /* L1 cache line size */
10085 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10086 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10087 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10088
10089 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10090 +#define __read_only __attribute__((__section__(".data..read_only")))
10091
10092 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10093 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10094 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10095
10096 #ifdef CONFIG_X86_VSMP
10097 #ifdef CONFIG_SMP
10098 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10099 index 9863ee3..4a1f8e1 100644
10100 --- a/arch/x86/include/asm/cacheflush.h
10101 +++ b/arch/x86/include/asm/cacheflush.h
10102 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10103 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10104
10105 if (pg_flags == _PGMT_DEFAULT)
10106 - return -1;
10107 + return ~0UL;
10108 else if (pg_flags == _PGMT_WC)
10109 return _PAGE_CACHE_WC;
10110 else if (pg_flags == _PGMT_UC_MINUS)
10111 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10112 index 46fc474..b02b0f9 100644
10113 --- a/arch/x86/include/asm/checksum_32.h
10114 +++ b/arch/x86/include/asm/checksum_32.h
10115 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10116 int len, __wsum sum,
10117 int *src_err_ptr, int *dst_err_ptr);
10118
10119 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10120 + int len, __wsum sum,
10121 + int *src_err_ptr, int *dst_err_ptr);
10122 +
10123 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10124 + int len, __wsum sum,
10125 + int *src_err_ptr, int *dst_err_ptr);
10126 +
10127 /*
10128 * Note: when you get a NULL pointer exception here this means someone
10129 * passed in an incorrect kernel address to one of these functions.
10130 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10131 int *err_ptr)
10132 {
10133 might_sleep();
10134 - return csum_partial_copy_generic((__force void *)src, dst,
10135 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10136 len, sum, err_ptr, NULL);
10137 }
10138
10139 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10140 {
10141 might_sleep();
10142 if (access_ok(VERIFY_WRITE, dst, len))
10143 - return csum_partial_copy_generic(src, (__force void *)dst,
10144 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10145 len, sum, NULL, err_ptr);
10146
10147 if (len)
10148 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10149 index 99480e5..d81165b 100644
10150 --- a/arch/x86/include/asm/cmpxchg.h
10151 +++ b/arch/x86/include/asm/cmpxchg.h
10152 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10153 __compiletime_error("Bad argument size for cmpxchg");
10154 extern void __xadd_wrong_size(void)
10155 __compiletime_error("Bad argument size for xadd");
10156 +extern void __xadd_check_overflow_wrong_size(void)
10157 + __compiletime_error("Bad argument size for xadd_check_overflow");
10158 extern void __add_wrong_size(void)
10159 __compiletime_error("Bad argument size for add");
10160 +extern void __add_check_overflow_wrong_size(void)
10161 + __compiletime_error("Bad argument size for add_check_overflow");
10162
10163 /*
10164 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10165 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10166 __ret; \
10167 })
10168
10169 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10170 + ({ \
10171 + __typeof__ (*(ptr)) __ret = (arg); \
10172 + switch (sizeof(*(ptr))) { \
10173 + case __X86_CASE_L: \
10174 + asm volatile (lock #op "l %0, %1\n" \
10175 + "jno 0f\n" \
10176 + "mov %0,%1\n" \
10177 + "int $4\n0:\n" \
10178 + _ASM_EXTABLE(0b, 0b) \
10179 + : "+r" (__ret), "+m" (*(ptr)) \
10180 + : : "memory", "cc"); \
10181 + break; \
10182 + case __X86_CASE_Q: \
10183 + asm volatile (lock #op "q %q0, %1\n" \
10184 + "jno 0f\n" \
10185 + "mov %0,%1\n" \
10186 + "int $4\n0:\n" \
10187 + _ASM_EXTABLE(0b, 0b) \
10188 + : "+r" (__ret), "+m" (*(ptr)) \
10189 + : : "memory", "cc"); \
10190 + break; \
10191 + default: \
10192 + __ ## op ## _check_overflow_wrong_size(); \
10193 + } \
10194 + __ret; \
10195 + })
10196 +
10197 /*
10198 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10199 * Since this is generally used to protect other memory information, we
10200 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10201 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10202 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10203
10204 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10205 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10206 +
10207 #define __add(ptr, inc, lock) \
10208 ({ \
10209 __typeof__ (*(ptr)) __ret = (inc); \
10210 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10211 index f91e80f..7f9bd27 100644
10212 --- a/arch/x86/include/asm/cpufeature.h
10213 +++ b/arch/x86/include/asm/cpufeature.h
10214 @@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10215 ".section .discard,\"aw\",@progbits\n"
10216 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10217 ".previous\n"
10218 - ".section .altinstr_replacement,\"ax\"\n"
10219 + ".section .altinstr_replacement,\"a\"\n"
10220 "3: movb $1,%0\n"
10221 "4:\n"
10222 ".previous\n"
10223 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10224 index 8bf1c06..f723dfd 100644
10225 --- a/arch/x86/include/asm/desc.h
10226 +++ b/arch/x86/include/asm/desc.h
10227 @@ -4,6 +4,7 @@
10228 #include <asm/desc_defs.h>
10229 #include <asm/ldt.h>
10230 #include <asm/mmu.h>
10231 +#include <asm/pgtable.h>
10232
10233 #include <linux/smp.h>
10234 #include <linux/percpu.h>
10235 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10236
10237 desc->type = (info->read_exec_only ^ 1) << 1;
10238 desc->type |= info->contents << 2;
10239 + desc->type |= info->seg_not_present ^ 1;
10240
10241 desc->s = 1;
10242 desc->dpl = 0x3;
10243 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10244 }
10245
10246 extern struct desc_ptr idt_descr;
10247 -extern gate_desc idt_table[];
10248 extern struct desc_ptr nmi_idt_descr;
10249 -extern gate_desc nmi_idt_table[];
10250 -
10251 -struct gdt_page {
10252 - struct desc_struct gdt[GDT_ENTRIES];
10253 -} __attribute__((aligned(PAGE_SIZE)));
10254 -
10255 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10256 +extern gate_desc idt_table[256];
10257 +extern gate_desc nmi_idt_table[256];
10258
10259 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10260 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10261 {
10262 - return per_cpu(gdt_page, cpu).gdt;
10263 + return cpu_gdt_table[cpu];
10264 }
10265
10266 #ifdef CONFIG_X86_64
10267 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10268 unsigned long base, unsigned dpl, unsigned flags,
10269 unsigned short seg)
10270 {
10271 - gate->a = (seg << 16) | (base & 0xffff);
10272 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10273 + gate->gate.offset_low = base;
10274 + gate->gate.seg = seg;
10275 + gate->gate.reserved = 0;
10276 + gate->gate.type = type;
10277 + gate->gate.s = 0;
10278 + gate->gate.dpl = dpl;
10279 + gate->gate.p = 1;
10280 + gate->gate.offset_high = base >> 16;
10281 }
10282
10283 #endif
10284 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10285
10286 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10287 {
10288 + pax_open_kernel();
10289 memcpy(&idt[entry], gate, sizeof(*gate));
10290 + pax_close_kernel();
10291 }
10292
10293 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10294 {
10295 + pax_open_kernel();
10296 memcpy(&ldt[entry], desc, 8);
10297 + pax_close_kernel();
10298 }
10299
10300 static inline void
10301 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10302 default: size = sizeof(*gdt); break;
10303 }
10304
10305 + pax_open_kernel();
10306 memcpy(&gdt[entry], desc, size);
10307 + pax_close_kernel();
10308 }
10309
10310 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10311 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10312
10313 static inline void native_load_tr_desc(void)
10314 {
10315 + pax_open_kernel();
10316 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10317 + pax_close_kernel();
10318 }
10319
10320 static inline void native_load_gdt(const struct desc_ptr *dtr)
10321 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10322 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10323 unsigned int i;
10324
10325 + pax_open_kernel();
10326 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10327 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10328 + pax_close_kernel();
10329 }
10330
10331 #define _LDT_empty(info) \
10332 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10333 }
10334
10335 #ifdef CONFIG_X86_64
10336 -static inline void set_nmi_gate(int gate, void *addr)
10337 +static inline void set_nmi_gate(int gate, const void *addr)
10338 {
10339 gate_desc s;
10340
10341 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10342 }
10343 #endif
10344
10345 -static inline void _set_gate(int gate, unsigned type, void *addr,
10346 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10347 unsigned dpl, unsigned ist, unsigned seg)
10348 {
10349 gate_desc s;
10350 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10351 * Pentium F0 0F bugfix can have resulted in the mapped
10352 * IDT being write-protected.
10353 */
10354 -static inline void set_intr_gate(unsigned int n, void *addr)
10355 +static inline void set_intr_gate(unsigned int n, const void *addr)
10356 {
10357 BUG_ON((unsigned)n > 0xFF);
10358 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10359 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10360 /*
10361 * This routine sets up an interrupt gate at directory privilege level 3.
10362 */
10363 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10364 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10365 {
10366 BUG_ON((unsigned)n > 0xFF);
10367 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10368 }
10369
10370 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10371 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10372 {
10373 BUG_ON((unsigned)n > 0xFF);
10374 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10375 }
10376
10377 -static inline void set_trap_gate(unsigned int n, void *addr)
10378 +static inline void set_trap_gate(unsigned int n, const void *addr)
10379 {
10380 BUG_ON((unsigned)n > 0xFF);
10381 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10382 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10383 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10384 {
10385 BUG_ON((unsigned)n > 0xFF);
10386 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10387 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10388 }
10389
10390 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10391 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10392 {
10393 BUG_ON((unsigned)n > 0xFF);
10394 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10395 }
10396
10397 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10398 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10399 {
10400 BUG_ON((unsigned)n > 0xFF);
10401 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10402 }
10403
10404 +#ifdef CONFIG_X86_32
10405 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10406 +{
10407 + struct desc_struct d;
10408 +
10409 + if (likely(limit))
10410 + limit = (limit - 1UL) >> PAGE_SHIFT;
10411 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10412 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10413 +}
10414 +#endif
10415 +
10416 #endif /* _ASM_X86_DESC_H */
10417 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10418 index 278441f..b95a174 100644
10419 --- a/arch/x86/include/asm/desc_defs.h
10420 +++ b/arch/x86/include/asm/desc_defs.h
10421 @@ -31,6 +31,12 @@ struct desc_struct {
10422 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10423 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10424 };
10425 + struct {
10426 + u16 offset_low;
10427 + u16 seg;
10428 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10429 + unsigned offset_high: 16;
10430 + } gate;
10431 };
10432 } __attribute__((packed));
10433
10434 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10435 index 3778256..c5d4fce 100644
10436 --- a/arch/x86/include/asm/e820.h
10437 +++ b/arch/x86/include/asm/e820.h
10438 @@ -69,7 +69,7 @@ struct e820map {
10439 #define ISA_START_ADDRESS 0xa0000
10440 #define ISA_END_ADDRESS 0x100000
10441
10442 -#define BIOS_BEGIN 0x000a0000
10443 +#define BIOS_BEGIN 0x000c0000
10444 #define BIOS_END 0x00100000
10445
10446 #define BIOS_ROM_BASE 0xffe00000
10447 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10448 index 5939f44..f8845f6 100644
10449 --- a/arch/x86/include/asm/elf.h
10450 +++ b/arch/x86/include/asm/elf.h
10451 @@ -243,7 +243,25 @@ extern int force_personality32;
10452 the loader. We need to make sure that it is out of the way of the program
10453 that it will "exec", and that there is sufficient room for the brk. */
10454
10455 +#ifdef CONFIG_PAX_SEGMEXEC
10456 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10457 +#else
10458 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10459 +#endif
10460 +
10461 +#ifdef CONFIG_PAX_ASLR
10462 +#ifdef CONFIG_X86_32
10463 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10464 +
10465 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10466 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10467 +#else
10468 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10469 +
10470 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10471 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10472 +#endif
10473 +#endif
10474
10475 /* This yields a mask that user programs can use to figure out what
10476 instruction set this CPU supports. This could be done in user space,
10477 @@ -296,16 +314,12 @@ do { \
10478
10479 #define ARCH_DLINFO \
10480 do { \
10481 - if (vdso_enabled) \
10482 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10483 - (unsigned long)current->mm->context.vdso); \
10484 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10485 } while (0)
10486
10487 #define ARCH_DLINFO_X32 \
10488 do { \
10489 - if (vdso_enabled) \
10490 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10491 - (unsigned long)current->mm->context.vdso); \
10492 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10493 } while (0)
10494
10495 #define AT_SYSINFO 32
10496 @@ -320,7 +334,7 @@ else \
10497
10498 #endif /* !CONFIG_X86_32 */
10499
10500 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10501 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10502
10503 #define VDSO_ENTRY \
10504 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10505 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10506 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10507 #define compat_arch_setup_additional_pages syscall32_setup_pages
10508
10509 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10510 -#define arch_randomize_brk arch_randomize_brk
10511 -
10512 /*
10513 * True on X86_32 or when emulating IA32 on X86_64
10514 */
10515 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10516 index cc70c1c..d96d011 100644
10517 --- a/arch/x86/include/asm/emergency-restart.h
10518 +++ b/arch/x86/include/asm/emergency-restart.h
10519 @@ -15,6 +15,6 @@ enum reboot_type {
10520
10521 extern enum reboot_type reboot_type;
10522
10523 -extern void machine_emergency_restart(void);
10524 +extern void machine_emergency_restart(void) __noreturn;
10525
10526 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10527 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10528 index 75f4c6d..ee3eb8f 100644
10529 --- a/arch/x86/include/asm/fpu-internal.h
10530 +++ b/arch/x86/include/asm/fpu-internal.h
10531 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10532 {
10533 int err;
10534
10535 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10536 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10537 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10538 +#endif
10539 +
10540 /* See comment in fxsave() below. */
10541 #ifdef CONFIG_AS_FXSAVEQ
10542 asm volatile("1: fxrstorq %[fx]\n\t"
10543 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10544 {
10545 int err;
10546
10547 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10548 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10549 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10550 +#endif
10551 +
10552 /*
10553 * Clear the bytes not touched by the fxsave and reserved
10554 * for the SW usage.
10555 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10556 "emms\n\t" /* clear stack tags */
10557 "fildl %P[addr]", /* set F?P to defined value */
10558 X86_FEATURE_FXSAVE_LEAK,
10559 - [addr] "m" (tsk->thread.fpu.has_fpu));
10560 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10561
10562 return fpu_restore_checking(&tsk->thread.fpu);
10563 }
10564 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10565 index 71ecbcb..bac10b7 100644
10566 --- a/arch/x86/include/asm/futex.h
10567 +++ b/arch/x86/include/asm/futex.h
10568 @@ -11,16 +11,18 @@
10569 #include <asm/processor.h>
10570
10571 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10572 + typecheck(u32 __user *, uaddr); \
10573 asm volatile("1:\t" insn "\n" \
10574 "2:\t.section .fixup,\"ax\"\n" \
10575 "3:\tmov\t%3, %1\n" \
10576 "\tjmp\t2b\n" \
10577 "\t.previous\n" \
10578 _ASM_EXTABLE(1b, 3b) \
10579 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10580 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10581 : "i" (-EFAULT), "0" (oparg), "1" (0))
10582
10583 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10584 + typecheck(u32 __user *, uaddr); \
10585 asm volatile("1:\tmovl %2, %0\n" \
10586 "\tmovl\t%0, %3\n" \
10587 "\t" insn "\n" \
10588 @@ -33,7 +35,7 @@
10589 _ASM_EXTABLE(1b, 4b) \
10590 _ASM_EXTABLE(2b, 4b) \
10591 : "=&a" (oldval), "=&r" (ret), \
10592 - "+m" (*uaddr), "=&r" (tem) \
10593 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10594 : "r" (oparg), "i" (-EFAULT), "1" (0))
10595
10596 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10597 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10598
10599 switch (op) {
10600 case FUTEX_OP_SET:
10601 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10602 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10603 break;
10604 case FUTEX_OP_ADD:
10605 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10606 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10607 uaddr, oparg);
10608 break;
10609 case FUTEX_OP_OR:
10610 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10611 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10612 return -EFAULT;
10613
10614 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10615 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10616 "2:\t.section .fixup, \"ax\"\n"
10617 "3:\tmov %3, %0\n"
10618 "\tjmp 2b\n"
10619 "\t.previous\n"
10620 _ASM_EXTABLE(1b, 3b)
10621 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10622 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10623 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10624 : "memory"
10625 );
10626 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10627 index eb92a6e..b98b2f4 100644
10628 --- a/arch/x86/include/asm/hw_irq.h
10629 +++ b/arch/x86/include/asm/hw_irq.h
10630 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10631 extern void enable_IO_APIC(void);
10632
10633 /* Statistics */
10634 -extern atomic_t irq_err_count;
10635 -extern atomic_t irq_mis_count;
10636 +extern atomic_unchecked_t irq_err_count;
10637 +extern atomic_unchecked_t irq_mis_count;
10638
10639 /* EISA */
10640 extern void eisa_set_level_irq(unsigned int irq);
10641 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10642 index d8e8eef..99f81ae 100644
10643 --- a/arch/x86/include/asm/io.h
10644 +++ b/arch/x86/include/asm/io.h
10645 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10646
10647 #include <linux/vmalloc.h>
10648
10649 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10650 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10651 +{
10652 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10653 +}
10654 +
10655 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10656 +{
10657 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10658 +}
10659 +
10660 /*
10661 * Convert a virtual cached pointer to an uncached pointer
10662 */
10663 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10664 index bba3cf8..06bc8da 100644
10665 --- a/arch/x86/include/asm/irqflags.h
10666 +++ b/arch/x86/include/asm/irqflags.h
10667 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10668 sti; \
10669 sysexit
10670
10671 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10672 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10673 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10674 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10675 +
10676 #else
10677 #define INTERRUPT_RETURN iret
10678 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10679 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10680 index 5478825..839e88c 100644
10681 --- a/arch/x86/include/asm/kprobes.h
10682 +++ b/arch/x86/include/asm/kprobes.h
10683 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10684 #define RELATIVEJUMP_SIZE 5
10685 #define RELATIVECALL_OPCODE 0xe8
10686 #define RELATIVE_ADDR_SIZE 4
10687 -#define MAX_STACK_SIZE 64
10688 -#define MIN_STACK_SIZE(ADDR) \
10689 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10690 - THREAD_SIZE - (unsigned long)(ADDR))) \
10691 - ? (MAX_STACK_SIZE) \
10692 - : (((unsigned long)current_thread_info()) + \
10693 - THREAD_SIZE - (unsigned long)(ADDR)))
10694 +#define MAX_STACK_SIZE 64UL
10695 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10696
10697 #define flush_insn_slot(p) do { } while (0)
10698
10699 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10700 index db7c1f2..92f130a 100644
10701 --- a/arch/x86/include/asm/kvm_host.h
10702 +++ b/arch/x86/include/asm/kvm_host.h
10703 @@ -680,7 +680,7 @@ struct kvm_x86_ops {
10704 int (*check_intercept)(struct kvm_vcpu *vcpu,
10705 struct x86_instruction_info *info,
10706 enum x86_intercept_stage stage);
10707 -};
10708 +} __do_const;
10709
10710 struct kvm_arch_async_pf {
10711 u32 token;
10712 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10713 index c8bed0d..e5721fa 100644
10714 --- a/arch/x86/include/asm/local.h
10715 +++ b/arch/x86/include/asm/local.h
10716 @@ -17,26 +17,58 @@ typedef struct {
10717
10718 static inline void local_inc(local_t *l)
10719 {
10720 - asm volatile(_ASM_INC "%0"
10721 + asm volatile(_ASM_INC "%0\n"
10722 +
10723 +#ifdef CONFIG_PAX_REFCOUNT
10724 + "jno 0f\n"
10725 + _ASM_DEC "%0\n"
10726 + "int $4\n0:\n"
10727 + _ASM_EXTABLE(0b, 0b)
10728 +#endif
10729 +
10730 : "+m" (l->a.counter));
10731 }
10732
10733 static inline void local_dec(local_t *l)
10734 {
10735 - asm volatile(_ASM_DEC "%0"
10736 + asm volatile(_ASM_DEC "%0\n"
10737 +
10738 +#ifdef CONFIG_PAX_REFCOUNT
10739 + "jno 0f\n"
10740 + _ASM_INC "%0\n"
10741 + "int $4\n0:\n"
10742 + _ASM_EXTABLE(0b, 0b)
10743 +#endif
10744 +
10745 : "+m" (l->a.counter));
10746 }
10747
10748 static inline void local_add(long i, local_t *l)
10749 {
10750 - asm volatile(_ASM_ADD "%1,%0"
10751 + asm volatile(_ASM_ADD "%1,%0\n"
10752 +
10753 +#ifdef CONFIG_PAX_REFCOUNT
10754 + "jno 0f\n"
10755 + _ASM_SUB "%1,%0\n"
10756 + "int $4\n0:\n"
10757 + _ASM_EXTABLE(0b, 0b)
10758 +#endif
10759 +
10760 : "+m" (l->a.counter)
10761 : "ir" (i));
10762 }
10763
10764 static inline void local_sub(long i, local_t *l)
10765 {
10766 - asm volatile(_ASM_SUB "%1,%0"
10767 + asm volatile(_ASM_SUB "%1,%0\n"
10768 +
10769 +#ifdef CONFIG_PAX_REFCOUNT
10770 + "jno 0f\n"
10771 + _ASM_ADD "%1,%0\n"
10772 + "int $4\n0:\n"
10773 + _ASM_EXTABLE(0b, 0b)
10774 +#endif
10775 +
10776 : "+m" (l->a.counter)
10777 : "ir" (i));
10778 }
10779 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10780 {
10781 unsigned char c;
10782
10783 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10784 + asm volatile(_ASM_SUB "%2,%0\n"
10785 +
10786 +#ifdef CONFIG_PAX_REFCOUNT
10787 + "jno 0f\n"
10788 + _ASM_ADD "%2,%0\n"
10789 + "int $4\n0:\n"
10790 + _ASM_EXTABLE(0b, 0b)
10791 +#endif
10792 +
10793 + "sete %1\n"
10794 : "+m" (l->a.counter), "=qm" (c)
10795 : "ir" (i) : "memory");
10796 return c;
10797 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10798 {
10799 unsigned char c;
10800
10801 - asm volatile(_ASM_DEC "%0; sete %1"
10802 + asm volatile(_ASM_DEC "%0\n"
10803 +
10804 +#ifdef CONFIG_PAX_REFCOUNT
10805 + "jno 0f\n"
10806 + _ASM_INC "%0\n"
10807 + "int $4\n0:\n"
10808 + _ASM_EXTABLE(0b, 0b)
10809 +#endif
10810 +
10811 + "sete %1\n"
10812 : "+m" (l->a.counter), "=qm" (c)
10813 : : "memory");
10814 return c != 0;
10815 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10816 {
10817 unsigned char c;
10818
10819 - asm volatile(_ASM_INC "%0; sete %1"
10820 + asm volatile(_ASM_INC "%0\n"
10821 +
10822 +#ifdef CONFIG_PAX_REFCOUNT
10823 + "jno 0f\n"
10824 + _ASM_DEC "%0\n"
10825 + "int $4\n0:\n"
10826 + _ASM_EXTABLE(0b, 0b)
10827 +#endif
10828 +
10829 + "sete %1\n"
10830 : "+m" (l->a.counter), "=qm" (c)
10831 : : "memory");
10832 return c != 0;
10833 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10834 {
10835 unsigned char c;
10836
10837 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10838 + asm volatile(_ASM_ADD "%2,%0\n"
10839 +
10840 +#ifdef CONFIG_PAX_REFCOUNT
10841 + "jno 0f\n"
10842 + _ASM_SUB "%2,%0\n"
10843 + "int $4\n0:\n"
10844 + _ASM_EXTABLE(0b, 0b)
10845 +#endif
10846 +
10847 + "sets %1\n"
10848 : "+m" (l->a.counter), "=qm" (c)
10849 : "ir" (i) : "memory");
10850 return c;
10851 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10852 #endif
10853 /* Modern 486+ processor */
10854 __i = i;
10855 - asm volatile(_ASM_XADD "%0, %1;"
10856 + asm volatile(_ASM_XADD "%0, %1\n"
10857 +
10858 +#ifdef CONFIG_PAX_REFCOUNT
10859 + "jno 0f\n"
10860 + _ASM_MOV "%0,%1\n"
10861 + "int $4\n0:\n"
10862 + _ASM_EXTABLE(0b, 0b)
10863 +#endif
10864 +
10865 : "+r" (i), "+m" (l->a.counter)
10866 : : "memory");
10867 return i + __i;
10868 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10869 index 593e51d..fa69c9a 100644
10870 --- a/arch/x86/include/asm/mman.h
10871 +++ b/arch/x86/include/asm/mman.h
10872 @@ -5,4 +5,14 @@
10873
10874 #include <asm-generic/mman.h>
10875
10876 +#ifdef __KERNEL__
10877 +#ifndef __ASSEMBLY__
10878 +#ifdef CONFIG_X86_32
10879 +#define arch_mmap_check i386_mmap_check
10880 +int i386_mmap_check(unsigned long addr, unsigned long len,
10881 + unsigned long flags);
10882 +#endif
10883 +#endif
10884 +#endif
10885 +
10886 #endif /* _ASM_X86_MMAN_H */
10887 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10888 index 5f55e69..e20bfb1 100644
10889 --- a/arch/x86/include/asm/mmu.h
10890 +++ b/arch/x86/include/asm/mmu.h
10891 @@ -9,7 +9,7 @@
10892 * we put the segment information here.
10893 */
10894 typedef struct {
10895 - void *ldt;
10896 + struct desc_struct *ldt;
10897 int size;
10898
10899 #ifdef CONFIG_X86_64
10900 @@ -18,7 +18,19 @@ typedef struct {
10901 #endif
10902
10903 struct mutex lock;
10904 - void *vdso;
10905 + unsigned long vdso;
10906 +
10907 +#ifdef CONFIG_X86_32
10908 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10909 + unsigned long user_cs_base;
10910 + unsigned long user_cs_limit;
10911 +
10912 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10913 + cpumask_t cpu_user_cs_mask;
10914 +#endif
10915 +
10916 +#endif
10917 +#endif
10918 } mm_context_t;
10919
10920 #ifdef CONFIG_SMP
10921 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10922 index cdbf367..adb37ac 100644
10923 --- a/arch/x86/include/asm/mmu_context.h
10924 +++ b/arch/x86/include/asm/mmu_context.h
10925 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10926
10927 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10928 {
10929 +
10930 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10931 + unsigned int i;
10932 + pgd_t *pgd;
10933 +
10934 + pax_open_kernel();
10935 + pgd = get_cpu_pgd(smp_processor_id());
10936 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10937 + set_pgd_batched(pgd+i, native_make_pgd(0));
10938 + pax_close_kernel();
10939 +#endif
10940 +
10941 #ifdef CONFIG_SMP
10942 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10943 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10944 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10945 struct task_struct *tsk)
10946 {
10947 unsigned cpu = smp_processor_id();
10948 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10949 + int tlbstate = TLBSTATE_OK;
10950 +#endif
10951
10952 if (likely(prev != next)) {
10953 #ifdef CONFIG_SMP
10954 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10955 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10956 +#endif
10957 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10958 this_cpu_write(cpu_tlbstate.active_mm, next);
10959 #endif
10960 cpumask_set_cpu(cpu, mm_cpumask(next));
10961
10962 /* Re-load page tables */
10963 +#ifdef CONFIG_PAX_PER_CPU_PGD
10964 + pax_open_kernel();
10965 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10966 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10967 + pax_close_kernel();
10968 + load_cr3(get_cpu_pgd(cpu));
10969 +#else
10970 load_cr3(next->pgd);
10971 +#endif
10972
10973 /* stop flush ipis for the previous mm */
10974 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10975 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10976 */
10977 if (unlikely(prev->context.ldt != next->context.ldt))
10978 load_LDT_nolock(&next->context);
10979 - }
10980 +
10981 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10982 + if (!(__supported_pte_mask & _PAGE_NX)) {
10983 + smp_mb__before_clear_bit();
10984 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10985 + smp_mb__after_clear_bit();
10986 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10987 + }
10988 +#endif
10989 +
10990 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10991 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10992 + prev->context.user_cs_limit != next->context.user_cs_limit))
10993 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10994 #ifdef CONFIG_SMP
10995 + else if (unlikely(tlbstate != TLBSTATE_OK))
10996 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10997 +#endif
10998 +#endif
10999 +
11000 + }
11001 else {
11002 +
11003 +#ifdef CONFIG_PAX_PER_CPU_PGD
11004 + pax_open_kernel();
11005 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11006 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11007 + pax_close_kernel();
11008 + load_cr3(get_cpu_pgd(cpu));
11009 +#endif
11010 +
11011 +#ifdef CONFIG_SMP
11012 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11013 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11014
11015 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11016 * tlb flush IPI delivery. We must reload CR3
11017 * to make sure to use no freed page tables.
11018 */
11019 +
11020 +#ifndef CONFIG_PAX_PER_CPU_PGD
11021 load_cr3(next->pgd);
11022 +#endif
11023 +
11024 load_LDT_nolock(&next->context);
11025 +
11026 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11027 + if (!(__supported_pte_mask & _PAGE_NX))
11028 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11029 +#endif
11030 +
11031 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11032 +#ifdef CONFIG_PAX_PAGEEXEC
11033 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11034 +#endif
11035 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11036 +#endif
11037 +
11038 }
11039 +#endif
11040 }
11041 -#endif
11042 }
11043
11044 #define activate_mm(prev, next) \
11045 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11046 index 9eae775..c914fea 100644
11047 --- a/arch/x86/include/asm/module.h
11048 +++ b/arch/x86/include/asm/module.h
11049 @@ -5,6 +5,7 @@
11050
11051 #ifdef CONFIG_X86_64
11052 /* X86_64 does not define MODULE_PROC_FAMILY */
11053 +#define MODULE_PROC_FAMILY ""
11054 #elif defined CONFIG_M386
11055 #define MODULE_PROC_FAMILY "386 "
11056 #elif defined CONFIG_M486
11057 @@ -59,8 +60,20 @@
11058 #error unknown processor family
11059 #endif
11060
11061 -#ifdef CONFIG_X86_32
11062 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11063 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11064 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11065 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11066 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11067 +#else
11068 +#define MODULE_PAX_KERNEXEC ""
11069 #endif
11070
11071 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11072 +#define MODULE_PAX_UDEREF "UDEREF "
11073 +#else
11074 +#define MODULE_PAX_UDEREF ""
11075 +#endif
11076 +
11077 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11078 +
11079 #endif /* _ASM_X86_MODULE_H */
11080 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11081 index 320f7bb..e89f8f8 100644
11082 --- a/arch/x86/include/asm/page_64_types.h
11083 +++ b/arch/x86/include/asm/page_64_types.h
11084 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11085
11086 /* duplicated to the one in bootmem.h */
11087 extern unsigned long max_pfn;
11088 -extern unsigned long phys_base;
11089 +extern const unsigned long phys_base;
11090
11091 extern unsigned long __phys_addr(unsigned long);
11092 #define __phys_reloc_hide(x) (x)
11093 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11094 index 6cbbabf..11b3aed 100644
11095 --- a/arch/x86/include/asm/paravirt.h
11096 +++ b/arch/x86/include/asm/paravirt.h
11097 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11098 val);
11099 }
11100
11101 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11102 +{
11103 + pgdval_t val = native_pgd_val(pgd);
11104 +
11105 + if (sizeof(pgdval_t) > sizeof(long))
11106 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11107 + val, (u64)val >> 32);
11108 + else
11109 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11110 + val);
11111 +}
11112 +
11113 static inline void pgd_clear(pgd_t *pgdp)
11114 {
11115 set_pgd(pgdp, __pgd(0));
11116 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11117 pv_mmu_ops.set_fixmap(idx, phys, flags);
11118 }
11119
11120 +#ifdef CONFIG_PAX_KERNEXEC
11121 +static inline unsigned long pax_open_kernel(void)
11122 +{
11123 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11124 +}
11125 +
11126 +static inline unsigned long pax_close_kernel(void)
11127 +{
11128 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11129 +}
11130 +#else
11131 +static inline unsigned long pax_open_kernel(void) { return 0; }
11132 +static inline unsigned long pax_close_kernel(void) { return 0; }
11133 +#endif
11134 +
11135 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11136
11137 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11138 @@ -965,7 +992,7 @@ extern void default_banner(void);
11139
11140 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11141 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11142 -#define PARA_INDIRECT(addr) *%cs:addr
11143 +#define PARA_INDIRECT(addr) *%ss:addr
11144 #endif
11145
11146 #define INTERRUPT_RETURN \
11147 @@ -1040,6 +1067,21 @@ extern void default_banner(void);
11148 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11149 CLBR_NONE, \
11150 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11151 +
11152 +#define GET_CR0_INTO_RDI \
11153 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11154 + mov %rax,%rdi
11155 +
11156 +#define SET_RDI_INTO_CR0 \
11157 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11158 +
11159 +#define GET_CR3_INTO_RDI \
11160 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11161 + mov %rax,%rdi
11162 +
11163 +#define SET_RDI_INTO_CR3 \
11164 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11165 +
11166 #endif /* CONFIG_X86_32 */
11167
11168 #endif /* __ASSEMBLY__ */
11169 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11170 index 8e8b9a4..f07d725 100644
11171 --- a/arch/x86/include/asm/paravirt_types.h
11172 +++ b/arch/x86/include/asm/paravirt_types.h
11173 @@ -84,20 +84,20 @@ struct pv_init_ops {
11174 */
11175 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11176 unsigned long addr, unsigned len);
11177 -};
11178 +} __no_const;
11179
11180
11181 struct pv_lazy_ops {
11182 /* Set deferred update mode, used for batching operations. */
11183 void (*enter)(void);
11184 void (*leave)(void);
11185 -};
11186 +} __no_const;
11187
11188 struct pv_time_ops {
11189 unsigned long long (*sched_clock)(void);
11190 unsigned long long (*steal_clock)(int cpu);
11191 unsigned long (*get_tsc_khz)(void);
11192 -};
11193 +} __no_const;
11194
11195 struct pv_cpu_ops {
11196 /* hooks for various privileged instructions */
11197 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11198
11199 void (*start_context_switch)(struct task_struct *prev);
11200 void (*end_context_switch)(struct task_struct *next);
11201 -};
11202 +} __no_const;
11203
11204 struct pv_irq_ops {
11205 /*
11206 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11207 unsigned long start_eip,
11208 unsigned long start_esp);
11209 #endif
11210 -};
11211 +} __no_const;
11212
11213 struct pv_mmu_ops {
11214 unsigned long (*read_cr2)(void);
11215 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11216 struct paravirt_callee_save make_pud;
11217
11218 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11219 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11220 #endif /* PAGETABLE_LEVELS == 4 */
11221 #endif /* PAGETABLE_LEVELS >= 3 */
11222
11223 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11224 an mfn. We can tell which is which from the index. */
11225 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11226 phys_addr_t phys, pgprot_t flags);
11227 +
11228 +#ifdef CONFIG_PAX_KERNEXEC
11229 + unsigned long (*pax_open_kernel)(void);
11230 + unsigned long (*pax_close_kernel)(void);
11231 +#endif
11232 +
11233 };
11234
11235 struct arch_spinlock;
11236 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11237 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11238 int (*spin_trylock)(struct arch_spinlock *lock);
11239 void (*spin_unlock)(struct arch_spinlock *lock);
11240 -};
11241 +} __no_const;
11242
11243 /* This contains all the paravirt structures: we get a convenient
11244 * number for each function using the offset which we use to indicate
11245 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11246 index b4389a4..7024269 100644
11247 --- a/arch/x86/include/asm/pgalloc.h
11248 +++ b/arch/x86/include/asm/pgalloc.h
11249 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11250 pmd_t *pmd, pte_t *pte)
11251 {
11252 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11253 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11254 +}
11255 +
11256 +static inline void pmd_populate_user(struct mm_struct *mm,
11257 + pmd_t *pmd, pte_t *pte)
11258 +{
11259 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11260 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11261 }
11262
11263 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11264
11265 #ifdef CONFIG_X86_PAE
11266 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11267 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11268 +{
11269 + pud_populate(mm, pudp, pmd);
11270 +}
11271 #else /* !CONFIG_X86_PAE */
11272 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11273 {
11274 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11275 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11276 }
11277 +
11278 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11279 +{
11280 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11281 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11282 +}
11283 #endif /* CONFIG_X86_PAE */
11284
11285 #if PAGETABLE_LEVELS > 3
11286 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11287 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11288 }
11289
11290 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11291 +{
11292 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11293 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11294 +}
11295 +
11296 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11297 {
11298 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11299 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11300 index 98391db..8f6984e 100644
11301 --- a/arch/x86/include/asm/pgtable-2level.h
11302 +++ b/arch/x86/include/asm/pgtable-2level.h
11303 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11304
11305 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11306 {
11307 + pax_open_kernel();
11308 *pmdp = pmd;
11309 + pax_close_kernel();
11310 }
11311
11312 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11313 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11314 index cb00ccc..17e9054 100644
11315 --- a/arch/x86/include/asm/pgtable-3level.h
11316 +++ b/arch/x86/include/asm/pgtable-3level.h
11317 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11318
11319 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11320 {
11321 + pax_open_kernel();
11322 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11323 + pax_close_kernel();
11324 }
11325
11326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11327 {
11328 + pax_open_kernel();
11329 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11330 + pax_close_kernel();
11331 }
11332
11333 /*
11334 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11335 index 49afb3f..91a8c63 100644
11336 --- a/arch/x86/include/asm/pgtable.h
11337 +++ b/arch/x86/include/asm/pgtable.h
11338 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11339
11340 #ifndef __PAGETABLE_PUD_FOLDED
11341 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11342 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11343 #define pgd_clear(pgd) native_pgd_clear(pgd)
11344 #endif
11345
11346 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11347
11348 #define arch_end_context_switch(prev) do {} while(0)
11349
11350 +#define pax_open_kernel() native_pax_open_kernel()
11351 +#define pax_close_kernel() native_pax_close_kernel()
11352 #endif /* CONFIG_PARAVIRT */
11353
11354 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11355 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11356 +
11357 +#ifdef CONFIG_PAX_KERNEXEC
11358 +static inline unsigned long native_pax_open_kernel(void)
11359 +{
11360 + unsigned long cr0;
11361 +
11362 + preempt_disable();
11363 + barrier();
11364 + cr0 = read_cr0() ^ X86_CR0_WP;
11365 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11366 + write_cr0(cr0);
11367 + return cr0 ^ X86_CR0_WP;
11368 +}
11369 +
11370 +static inline unsigned long native_pax_close_kernel(void)
11371 +{
11372 + unsigned long cr0;
11373 +
11374 + cr0 = read_cr0() ^ X86_CR0_WP;
11375 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11376 + write_cr0(cr0);
11377 + barrier();
11378 + preempt_enable_no_resched();
11379 + return cr0 ^ X86_CR0_WP;
11380 +}
11381 +#else
11382 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11383 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11384 +#endif
11385 +
11386 /*
11387 * The following only work if pte_present() is true.
11388 * Undefined behaviour if not..
11389 */
11390 +static inline int pte_user(pte_t pte)
11391 +{
11392 + return pte_val(pte) & _PAGE_USER;
11393 +}
11394 +
11395 static inline int pte_dirty(pte_t pte)
11396 {
11397 return pte_flags(pte) & _PAGE_DIRTY;
11398 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11399 return pte_clear_flags(pte, _PAGE_RW);
11400 }
11401
11402 +static inline pte_t pte_mkread(pte_t pte)
11403 +{
11404 + return __pte(pte_val(pte) | _PAGE_USER);
11405 +}
11406 +
11407 static inline pte_t pte_mkexec(pte_t pte)
11408 {
11409 - return pte_clear_flags(pte, _PAGE_NX);
11410 +#ifdef CONFIG_X86_PAE
11411 + if (__supported_pte_mask & _PAGE_NX)
11412 + return pte_clear_flags(pte, _PAGE_NX);
11413 + else
11414 +#endif
11415 + return pte_set_flags(pte, _PAGE_USER);
11416 +}
11417 +
11418 +static inline pte_t pte_exprotect(pte_t pte)
11419 +{
11420 +#ifdef CONFIG_X86_PAE
11421 + if (__supported_pte_mask & _PAGE_NX)
11422 + return pte_set_flags(pte, _PAGE_NX);
11423 + else
11424 +#endif
11425 + return pte_clear_flags(pte, _PAGE_USER);
11426 }
11427
11428 static inline pte_t pte_mkdirty(pte_t pte)
11429 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11430 #endif
11431
11432 #ifndef __ASSEMBLY__
11433 +
11434 +#ifdef CONFIG_PAX_PER_CPU_PGD
11435 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11436 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11437 +{
11438 + return cpu_pgd[cpu];
11439 +}
11440 +#endif
11441 +
11442 #include <linux/mm_types.h>
11443
11444 static inline int pte_none(pte_t pte)
11445 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11446
11447 static inline int pgd_bad(pgd_t pgd)
11448 {
11449 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11450 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11451 }
11452
11453 static inline int pgd_none(pgd_t pgd)
11454 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11455 * pgd_offset() returns a (pgd_t *)
11456 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11457 */
11458 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11459 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11460 +
11461 +#ifdef CONFIG_PAX_PER_CPU_PGD
11462 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11463 +#endif
11464 +
11465 /*
11466 * a shortcut which implies the use of the kernel's pgd, instead
11467 * of a process's
11468 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11469 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11470 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11471
11472 +#ifdef CONFIG_X86_32
11473 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11474 +#else
11475 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11476 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11477 +
11478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11479 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11480 +#else
11481 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11482 +#endif
11483 +
11484 +#endif
11485 +
11486 #ifndef __ASSEMBLY__
11487
11488 extern int direct_gbpages;
11489 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11490 * dst and src can be on the same page, but the range must not overlap,
11491 * and must not cross a page boundary.
11492 */
11493 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11494 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11495 {
11496 - memcpy(dst, src, count * sizeof(pgd_t));
11497 + pax_open_kernel();
11498 + while (count--)
11499 + *dst++ = *src++;
11500 + pax_close_kernel();
11501 }
11502
11503 +#ifdef CONFIG_PAX_PER_CPU_PGD
11504 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11505 +#endif
11506 +
11507 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11508 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11509 +#else
11510 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11511 +#endif
11512
11513 #include <asm-generic/pgtable.h>
11514 #endif /* __ASSEMBLY__ */
11515 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11516 index 0c92113..34a77c6 100644
11517 --- a/arch/x86/include/asm/pgtable_32.h
11518 +++ b/arch/x86/include/asm/pgtable_32.h
11519 @@ -25,9 +25,6 @@
11520 struct mm_struct;
11521 struct vm_area_struct;
11522
11523 -extern pgd_t swapper_pg_dir[1024];
11524 -extern pgd_t initial_page_table[1024];
11525 -
11526 static inline void pgtable_cache_init(void) { }
11527 static inline void check_pgt_cache(void) { }
11528 void paging_init(void);
11529 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11530 # include <asm/pgtable-2level.h>
11531 #endif
11532
11533 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11534 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11535 +#ifdef CONFIG_X86_PAE
11536 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11537 +#endif
11538 +
11539 #if defined(CONFIG_HIGHPTE)
11540 #define pte_offset_map(dir, address) \
11541 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11542 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11543 /* Clear a kernel PTE and flush it from the TLB */
11544 #define kpte_clear_flush(ptep, vaddr) \
11545 do { \
11546 + pax_open_kernel(); \
11547 pte_clear(&init_mm, (vaddr), (ptep)); \
11548 + pax_close_kernel(); \
11549 __flush_tlb_one((vaddr)); \
11550 } while (0)
11551
11552 @@ -74,6 +79,9 @@ do { \
11553
11554 #endif /* !__ASSEMBLY__ */
11555
11556 +#define HAVE_ARCH_UNMAPPED_AREA
11557 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11558 +
11559 /*
11560 * kern_addr_valid() is (1) for FLATMEM and (0) for
11561 * SPARSEMEM and DISCONTIGMEM
11562 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11563 index ed5903b..c7fe163 100644
11564 --- a/arch/x86/include/asm/pgtable_32_types.h
11565 +++ b/arch/x86/include/asm/pgtable_32_types.h
11566 @@ -8,7 +8,7 @@
11567 */
11568 #ifdef CONFIG_X86_PAE
11569 # include <asm/pgtable-3level_types.h>
11570 -# define PMD_SIZE (1UL << PMD_SHIFT)
11571 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11572 # define PMD_MASK (~(PMD_SIZE - 1))
11573 #else
11574 # include <asm/pgtable-2level_types.h>
11575 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11576 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11577 #endif
11578
11579 +#ifdef CONFIG_PAX_KERNEXEC
11580 +#ifndef __ASSEMBLY__
11581 +extern unsigned char MODULES_EXEC_VADDR[];
11582 +extern unsigned char MODULES_EXEC_END[];
11583 +#endif
11584 +#include <asm/boot.h>
11585 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11586 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11587 +#else
11588 +#define ktla_ktva(addr) (addr)
11589 +#define ktva_ktla(addr) (addr)
11590 +#endif
11591 +
11592 #define MODULES_VADDR VMALLOC_START
11593 #define MODULES_END VMALLOC_END
11594 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11595 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11596 index 975f709..9f779c9 100644
11597 --- a/arch/x86/include/asm/pgtable_64.h
11598 +++ b/arch/x86/include/asm/pgtable_64.h
11599 @@ -16,10 +16,14 @@
11600
11601 extern pud_t level3_kernel_pgt[512];
11602 extern pud_t level3_ident_pgt[512];
11603 +extern pud_t level3_vmalloc_start_pgt[512];
11604 +extern pud_t level3_vmalloc_end_pgt[512];
11605 +extern pud_t level3_vmemmap_pgt[512];
11606 +extern pud_t level2_vmemmap_pgt[512];
11607 extern pmd_t level2_kernel_pgt[512];
11608 extern pmd_t level2_fixmap_pgt[512];
11609 -extern pmd_t level2_ident_pgt[512];
11610 -extern pgd_t init_level4_pgt[];
11611 +extern pmd_t level2_ident_pgt[512*2];
11612 +extern pgd_t init_level4_pgt[512];
11613
11614 #define swapper_pg_dir init_level4_pgt
11615
11616 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11617
11618 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11619 {
11620 + pax_open_kernel();
11621 *pmdp = pmd;
11622 + pax_close_kernel();
11623 }
11624
11625 static inline void native_pmd_clear(pmd_t *pmd)
11626 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11627
11628 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11629 {
11630 + pax_open_kernel();
11631 *pudp = pud;
11632 + pax_close_kernel();
11633 }
11634
11635 static inline void native_pud_clear(pud_t *pud)
11636 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11637
11638 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11639 {
11640 + pax_open_kernel();
11641 + *pgdp = pgd;
11642 + pax_close_kernel();
11643 +}
11644 +
11645 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11646 +{
11647 *pgdp = pgd;
11648 }
11649
11650 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11651 index 766ea16..5b96cb3 100644
11652 --- a/arch/x86/include/asm/pgtable_64_types.h
11653 +++ b/arch/x86/include/asm/pgtable_64_types.h
11654 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11655 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11656 #define MODULES_END _AC(0xffffffffff000000, UL)
11657 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11658 +#define MODULES_EXEC_VADDR MODULES_VADDR
11659 +#define MODULES_EXEC_END MODULES_END
11660 +
11661 +#define ktla_ktva(addr) (addr)
11662 +#define ktva_ktla(addr) (addr)
11663
11664 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11665 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11666 index 013286a..8b42f4f 100644
11667 --- a/arch/x86/include/asm/pgtable_types.h
11668 +++ b/arch/x86/include/asm/pgtable_types.h
11669 @@ -16,13 +16,12 @@
11670 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11671 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11672 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11673 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11674 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11675 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11676 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11677 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11678 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11679 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11680 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11681 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11682 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11683 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11684
11685 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11686 @@ -40,7 +39,6 @@
11687 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11688 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11689 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11690 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11691 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11692 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11693 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11694 @@ -57,8 +55,10 @@
11695
11696 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11697 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11698 -#else
11699 +#elif defined(CONFIG_KMEMCHECK)
11700 #define _PAGE_NX (_AT(pteval_t, 0))
11701 +#else
11702 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11703 #endif
11704
11705 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11706 @@ -96,6 +96,9 @@
11707 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11708 _PAGE_ACCESSED)
11709
11710 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11711 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11712 +
11713 #define __PAGE_KERNEL_EXEC \
11714 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11715 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11716 @@ -106,7 +109,7 @@
11717 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11718 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11719 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11720 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11721 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11722 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11723 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11724 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11725 @@ -168,8 +171,8 @@
11726 * bits are combined, this will alow user to access the high address mapped
11727 * VDSO in the presence of CONFIG_COMPAT_VDSO
11728 */
11729 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11730 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11731 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11732 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11733 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11734 #endif
11735
11736 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11737 {
11738 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11739 }
11740 +#endif
11741
11742 +#if PAGETABLE_LEVELS == 3
11743 +#include <asm-generic/pgtable-nopud.h>
11744 +#endif
11745 +
11746 +#if PAGETABLE_LEVELS == 2
11747 +#include <asm-generic/pgtable-nopmd.h>
11748 +#endif
11749 +
11750 +#ifndef __ASSEMBLY__
11751 #if PAGETABLE_LEVELS > 3
11752 typedef struct { pudval_t pud; } pud_t;
11753
11754 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11755 return pud.pud;
11756 }
11757 #else
11758 -#include <asm-generic/pgtable-nopud.h>
11759 -
11760 static inline pudval_t native_pud_val(pud_t pud)
11761 {
11762 return native_pgd_val(pud.pgd);
11763 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11764 return pmd.pmd;
11765 }
11766 #else
11767 -#include <asm-generic/pgtable-nopmd.h>
11768 -
11769 static inline pmdval_t native_pmd_val(pmd_t pmd)
11770 {
11771 return native_pgd_val(pmd.pud.pgd);
11772 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11773
11774 extern pteval_t __supported_pte_mask;
11775 extern void set_nx(void);
11776 -extern int nx_enabled;
11777
11778 #define pgprot_writecombine pgprot_writecombine
11779 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11780 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11781 index 39bc577..538233f 100644
11782 --- a/arch/x86/include/asm/processor.h
11783 +++ b/arch/x86/include/asm/processor.h
11784 @@ -276,7 +276,7 @@ struct tss_struct {
11785
11786 } ____cacheline_aligned;
11787
11788 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11789 +extern struct tss_struct init_tss[NR_CPUS];
11790
11791 /*
11792 * Save the original ist values for checking stack pointers during debugging
11793 @@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11794 */
11795 #define TASK_SIZE PAGE_OFFSET
11796 #define TASK_SIZE_MAX TASK_SIZE
11797 +
11798 +#ifdef CONFIG_PAX_SEGMEXEC
11799 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11800 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11801 +#else
11802 #define STACK_TOP TASK_SIZE
11803 -#define STACK_TOP_MAX STACK_TOP
11804 +#endif
11805 +
11806 +#define STACK_TOP_MAX TASK_SIZE
11807
11808 #define INIT_THREAD { \
11809 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11810 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11811 .vm86_info = NULL, \
11812 .sysenter_cs = __KERNEL_CS, \
11813 .io_bitmap_ptr = NULL, \
11814 @@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11815 */
11816 #define INIT_TSS { \
11817 .x86_tss = { \
11818 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11819 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11820 .ss0 = __KERNEL_DS, \
11821 .ss1 = __KERNEL_CS, \
11822 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11823 @@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11824 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11825
11826 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11827 -#define KSTK_TOP(info) \
11828 -({ \
11829 - unsigned long *__ptr = (unsigned long *)(info); \
11830 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11831 -})
11832 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11833
11834 /*
11835 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11836 @@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11837 #define task_pt_regs(task) \
11838 ({ \
11839 struct pt_regs *__regs__; \
11840 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11841 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11842 __regs__ - 1; \
11843 })
11844
11845 @@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11846 /*
11847 * User space process size. 47bits minus one guard page.
11848 */
11849 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11850 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11851
11852 /* This decides where the kernel will search for a free chunk of vm
11853 * space during mmap's.
11854 */
11855 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11856 - 0xc0000000 : 0xFFFFe000)
11857 + 0xc0000000 : 0xFFFFf000)
11858
11859 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11860 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11861 @@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11862 #define STACK_TOP_MAX TASK_SIZE_MAX
11863
11864 #define INIT_THREAD { \
11865 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11866 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11867 }
11868
11869 #define INIT_TSS { \
11870 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11871 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11872 }
11873
11874 /*
11875 @@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11876 */
11877 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11878
11879 +#ifdef CONFIG_PAX_SEGMEXEC
11880 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11881 +#endif
11882 +
11883 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11884
11885 /* Get/set a process' ability to use the timestamp counter instruction */
11886 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11887 #define cpu_has_amd_erratum(x) (false)
11888 #endif /* CONFIG_CPU_SUP_AMD */
11889
11890 -extern unsigned long arch_align_stack(unsigned long sp);
11891 +#define arch_align_stack(x) ((x) & ~0xfUL)
11892 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11893
11894 void default_idle(void);
11895 bool set_pm_idle_to_default(void);
11896
11897 -void stop_this_cpu(void *dummy);
11898 +void stop_this_cpu(void *dummy) __noreturn;
11899
11900 #endif /* _ASM_X86_PROCESSOR_H */
11901 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11902 index dcfde52..dbfea06 100644
11903 --- a/arch/x86/include/asm/ptrace.h
11904 +++ b/arch/x86/include/asm/ptrace.h
11905 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11906 }
11907
11908 /*
11909 - * user_mode_vm(regs) determines whether a register set came from user mode.
11910 + * user_mode(regs) determines whether a register set came from user mode.
11911 * This is true if V8086 mode was enabled OR if the register set was from
11912 * protected mode with RPL-3 CS value. This tricky test checks that with
11913 * one comparison. Many places in the kernel can bypass this full check
11914 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11915 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11916 + * be used.
11917 */
11918 -static inline int user_mode(struct pt_regs *regs)
11919 +static inline int user_mode_novm(struct pt_regs *regs)
11920 {
11921 #ifdef CONFIG_X86_32
11922 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11923 #else
11924 - return !!(regs->cs & 3);
11925 + return !!(regs->cs & SEGMENT_RPL_MASK);
11926 #endif
11927 }
11928
11929 -static inline int user_mode_vm(struct pt_regs *regs)
11930 +static inline int user_mode(struct pt_regs *regs)
11931 {
11932 #ifdef CONFIG_X86_32
11933 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11934 USER_RPL;
11935 #else
11936 - return user_mode(regs);
11937 + return user_mode_novm(regs);
11938 #endif
11939 }
11940
11941 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11942 #ifdef CONFIG_X86_64
11943 static inline bool user_64bit_mode(struct pt_regs *regs)
11944 {
11945 + unsigned long cs = regs->cs & 0xffff;
11946 #ifndef CONFIG_PARAVIRT
11947 /*
11948 * On non-paravirt systems, this is the only long mode CPL 3
11949 * selector. We do not allow long mode selectors in the LDT.
11950 */
11951 - return regs->cs == __USER_CS;
11952 + return cs == __USER_CS;
11953 #else
11954 /* Headers are too twisted for this to go in paravirt.h. */
11955 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11956 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11957 #endif
11958 }
11959 #endif
11960 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11961 index fce3f4a..3f69f2a 100644
11962 --- a/arch/x86/include/asm/realmode.h
11963 +++ b/arch/x86/include/asm/realmode.h
11964 @@ -30,7 +30,7 @@ struct real_mode_header {
11965 struct trampoline_header {
11966 #ifdef CONFIG_X86_32
11967 u32 start;
11968 - u16 gdt_pad;
11969 + u16 boot_cs;
11970 u16 gdt_limit;
11971 u32 gdt_base;
11972 #else
11973 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11974 index 92f29706..a79cbbb 100644
11975 --- a/arch/x86/include/asm/reboot.h
11976 +++ b/arch/x86/include/asm/reboot.h
11977 @@ -6,19 +6,19 @@
11978 struct pt_regs;
11979
11980 struct machine_ops {
11981 - void (*restart)(char *cmd);
11982 - void (*halt)(void);
11983 - void (*power_off)(void);
11984 + void (* __noreturn restart)(char *cmd);
11985 + void (* __noreturn halt)(void);
11986 + void (* __noreturn power_off)(void);
11987 void (*shutdown)(void);
11988 void (*crash_shutdown)(struct pt_regs *);
11989 - void (*emergency_restart)(void);
11990 -};
11991 + void (* __noreturn emergency_restart)(void);
11992 +} __no_const;
11993
11994 extern struct machine_ops machine_ops;
11995
11996 void native_machine_crash_shutdown(struct pt_regs *regs);
11997 void native_machine_shutdown(void);
11998 -void machine_real_restart(unsigned int type);
11999 +void machine_real_restart(unsigned int type) __noreturn;
12000 /* These must match dispatch_table in reboot_32.S */
12001 #define MRR_BIOS 0
12002 #define MRR_APM 1
12003 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12004 index 2dbe4a7..ce1db00 100644
12005 --- a/arch/x86/include/asm/rwsem.h
12006 +++ b/arch/x86/include/asm/rwsem.h
12007 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12008 {
12009 asm volatile("# beginning down_read\n\t"
12010 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12011 +
12012 +#ifdef CONFIG_PAX_REFCOUNT
12013 + "jno 0f\n"
12014 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12015 + "int $4\n0:\n"
12016 + _ASM_EXTABLE(0b, 0b)
12017 +#endif
12018 +
12019 /* adds 0x00000001 */
12020 " jns 1f\n"
12021 " call call_rwsem_down_read_failed\n"
12022 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12023 "1:\n\t"
12024 " mov %1,%2\n\t"
12025 " add %3,%2\n\t"
12026 +
12027 +#ifdef CONFIG_PAX_REFCOUNT
12028 + "jno 0f\n"
12029 + "sub %3,%2\n"
12030 + "int $4\n0:\n"
12031 + _ASM_EXTABLE(0b, 0b)
12032 +#endif
12033 +
12034 " jle 2f\n\t"
12035 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12036 " jnz 1b\n\t"
12037 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12038 long tmp;
12039 asm volatile("# beginning down_write\n\t"
12040 LOCK_PREFIX " xadd %1,(%2)\n\t"
12041 +
12042 +#ifdef CONFIG_PAX_REFCOUNT
12043 + "jno 0f\n"
12044 + "mov %1,(%2)\n"
12045 + "int $4\n0:\n"
12046 + _ASM_EXTABLE(0b, 0b)
12047 +#endif
12048 +
12049 /* adds 0xffff0001, returns the old value */
12050 " test %1,%1\n\t"
12051 /* was the count 0 before? */
12052 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12053 long tmp;
12054 asm volatile("# beginning __up_read\n\t"
12055 LOCK_PREFIX " xadd %1,(%2)\n\t"
12056 +
12057 +#ifdef CONFIG_PAX_REFCOUNT
12058 + "jno 0f\n"
12059 + "mov %1,(%2)\n"
12060 + "int $4\n0:\n"
12061 + _ASM_EXTABLE(0b, 0b)
12062 +#endif
12063 +
12064 /* subtracts 1, returns the old value */
12065 " jns 1f\n\t"
12066 " call call_rwsem_wake\n" /* expects old value in %edx */
12067 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12068 long tmp;
12069 asm volatile("# beginning __up_write\n\t"
12070 LOCK_PREFIX " xadd %1,(%2)\n\t"
12071 +
12072 +#ifdef CONFIG_PAX_REFCOUNT
12073 + "jno 0f\n"
12074 + "mov %1,(%2)\n"
12075 + "int $4\n0:\n"
12076 + _ASM_EXTABLE(0b, 0b)
12077 +#endif
12078 +
12079 /* subtracts 0xffff0001, returns the old value */
12080 " jns 1f\n\t"
12081 " call call_rwsem_wake\n" /* expects old value in %edx */
12082 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12083 {
12084 asm volatile("# beginning __downgrade_write\n\t"
12085 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12086 +
12087 +#ifdef CONFIG_PAX_REFCOUNT
12088 + "jno 0f\n"
12089 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12090 + "int $4\n0:\n"
12091 + _ASM_EXTABLE(0b, 0b)
12092 +#endif
12093 +
12094 /*
12095 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12096 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12097 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12098 */
12099 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12100 {
12101 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12102 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12103 +
12104 +#ifdef CONFIG_PAX_REFCOUNT
12105 + "jno 0f\n"
12106 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12107 + "int $4\n0:\n"
12108 + _ASM_EXTABLE(0b, 0b)
12109 +#endif
12110 +
12111 : "+m" (sem->count)
12112 : "er" (delta));
12113 }
12114 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12115 */
12116 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12117 {
12118 - return delta + xadd(&sem->count, delta);
12119 + return delta + xadd_check_overflow(&sem->count, delta);
12120 }
12121
12122 #endif /* __KERNEL__ */
12123 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12124 index c48a950..c6d7468 100644
12125 --- a/arch/x86/include/asm/segment.h
12126 +++ b/arch/x86/include/asm/segment.h
12127 @@ -64,10 +64,15 @@
12128 * 26 - ESPFIX small SS
12129 * 27 - per-cpu [ offset to per-cpu data area ]
12130 * 28 - stack_canary-20 [ for stack protector ]
12131 - * 29 - unused
12132 - * 30 - unused
12133 + * 29 - PCI BIOS CS
12134 + * 30 - PCI BIOS DS
12135 * 31 - TSS for double fault handler
12136 */
12137 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12138 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12139 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12140 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12141 +
12142 #define GDT_ENTRY_TLS_MIN 6
12143 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12144
12145 @@ -79,6 +84,8 @@
12146
12147 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12148
12149 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12150 +
12151 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12152
12153 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12154 @@ -104,6 +111,12 @@
12155 #define __KERNEL_STACK_CANARY 0
12156 #endif
12157
12158 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12159 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12160 +
12161 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12162 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12163 +
12164 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12165
12166 /*
12167 @@ -141,7 +154,7 @@
12168 */
12169
12170 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12171 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12172 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12173
12174
12175 #else
12176 @@ -165,6 +178,8 @@
12177 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12178 #define __USER32_DS __USER_DS
12179
12180 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12181 +
12182 #define GDT_ENTRY_TSS 8 /* needs two entries */
12183 #define GDT_ENTRY_LDT 10 /* needs two entries */
12184 #define GDT_ENTRY_TLS_MIN 12
12185 @@ -185,6 +200,7 @@
12186 #endif
12187
12188 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12189 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12190 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12191 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12192 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12193 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12194 {
12195 unsigned long __limit;
12196 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12197 - return __limit + 1;
12198 + return __limit;
12199 }
12200
12201 #endif /* !__ASSEMBLY__ */
12202 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12203 index f483945..64a7851 100644
12204 --- a/arch/x86/include/asm/smp.h
12205 +++ b/arch/x86/include/asm/smp.h
12206 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12207 /* cpus sharing the last level cache: */
12208 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12209 DECLARE_PER_CPU(u16, cpu_llc_id);
12210 -DECLARE_PER_CPU(int, cpu_number);
12211 +DECLARE_PER_CPU(unsigned int, cpu_number);
12212
12213 static inline struct cpumask *cpu_sibling_mask(int cpu)
12214 {
12215 @@ -79,7 +79,7 @@ struct smp_ops {
12216
12217 void (*send_call_func_ipi)(const struct cpumask *mask);
12218 void (*send_call_func_single_ipi)(int cpu);
12219 -};
12220 +} __no_const;
12221
12222 /* Globals due to paravirt */
12223 extern void set_cpu_sibling_map(int cpu);
12224 @@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12225 extern int safe_smp_processor_id(void);
12226
12227 #elif defined(CONFIG_X86_64_SMP)
12228 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12229 -
12230 -#define stack_smp_processor_id() \
12231 -({ \
12232 - struct thread_info *ti; \
12233 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12234 - ti->cpu; \
12235 -})
12236 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12237 +#define stack_smp_processor_id() raw_smp_processor_id()
12238 #define safe_smp_processor_id() smp_processor_id()
12239
12240 #endif
12241 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12242 index b315a33..8849ab0 100644
12243 --- a/arch/x86/include/asm/spinlock.h
12244 +++ b/arch/x86/include/asm/spinlock.h
12245 @@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12246 static inline void arch_read_lock(arch_rwlock_t *rw)
12247 {
12248 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12249 +
12250 +#ifdef CONFIG_PAX_REFCOUNT
12251 + "jno 0f\n"
12252 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12253 + "int $4\n0:\n"
12254 + _ASM_EXTABLE(0b, 0b)
12255 +#endif
12256 +
12257 "jns 1f\n"
12258 "call __read_lock_failed\n\t"
12259 "1:\n"
12260 @@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12261 static inline void arch_write_lock(arch_rwlock_t *rw)
12262 {
12263 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12264 +
12265 +#ifdef CONFIG_PAX_REFCOUNT
12266 + "jno 0f\n"
12267 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12268 + "int $4\n0:\n"
12269 + _ASM_EXTABLE(0b, 0b)
12270 +#endif
12271 +
12272 "jz 1f\n"
12273 "call __write_lock_failed\n\t"
12274 "1:\n"
12275 @@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12276
12277 static inline void arch_read_unlock(arch_rwlock_t *rw)
12278 {
12279 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12280 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12281 +
12282 +#ifdef CONFIG_PAX_REFCOUNT
12283 + "jno 0f\n"
12284 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12285 + "int $4\n0:\n"
12286 + _ASM_EXTABLE(0b, 0b)
12287 +#endif
12288 +
12289 :"+m" (rw->lock) : : "memory");
12290 }
12291
12292 static inline void arch_write_unlock(arch_rwlock_t *rw)
12293 {
12294 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12295 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12296 +
12297 +#ifdef CONFIG_PAX_REFCOUNT
12298 + "jno 0f\n"
12299 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12300 + "int $4\n0:\n"
12301 + _ASM_EXTABLE(0b, 0b)
12302 +#endif
12303 +
12304 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12305 }
12306
12307 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12308 index 6a99859..03cb807 100644
12309 --- a/arch/x86/include/asm/stackprotector.h
12310 +++ b/arch/x86/include/asm/stackprotector.h
12311 @@ -47,7 +47,7 @@
12312 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12313 */
12314 #define GDT_STACK_CANARY_INIT \
12315 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12316 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12317
12318 /*
12319 * Initialize the stackprotector canary value.
12320 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12321
12322 static inline void load_stack_canary_segment(void)
12323 {
12324 -#ifdef CONFIG_X86_32
12325 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12326 asm volatile ("mov %0, %%gs" : : "r" (0));
12327 #endif
12328 }
12329 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12330 index 70bbe39..4ae2bd4 100644
12331 --- a/arch/x86/include/asm/stacktrace.h
12332 +++ b/arch/x86/include/asm/stacktrace.h
12333 @@ -11,28 +11,20 @@
12334
12335 extern int kstack_depth_to_print;
12336
12337 -struct thread_info;
12338 +struct task_struct;
12339 struct stacktrace_ops;
12340
12341 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12342 - unsigned long *stack,
12343 - unsigned long bp,
12344 - const struct stacktrace_ops *ops,
12345 - void *data,
12346 - unsigned long *end,
12347 - int *graph);
12348 +typedef unsigned long walk_stack_t(struct task_struct *task,
12349 + void *stack_start,
12350 + unsigned long *stack,
12351 + unsigned long bp,
12352 + const struct stacktrace_ops *ops,
12353 + void *data,
12354 + unsigned long *end,
12355 + int *graph);
12356
12357 -extern unsigned long
12358 -print_context_stack(struct thread_info *tinfo,
12359 - unsigned long *stack, unsigned long bp,
12360 - const struct stacktrace_ops *ops, void *data,
12361 - unsigned long *end, int *graph);
12362 -
12363 -extern unsigned long
12364 -print_context_stack_bp(struct thread_info *tinfo,
12365 - unsigned long *stack, unsigned long bp,
12366 - const struct stacktrace_ops *ops, void *data,
12367 - unsigned long *end, int *graph);
12368 +extern walk_stack_t print_context_stack;
12369 +extern walk_stack_t print_context_stack_bp;
12370
12371 /* Generic stack tracer with callbacks */
12372
12373 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12374 void (*address)(void *data, unsigned long address, int reliable);
12375 /* On negative return stop dumping */
12376 int (*stack)(void *data, char *name);
12377 - walk_stack_t walk_stack;
12378 + walk_stack_t *walk_stack;
12379 };
12380
12381 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12382 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12383 index 4ec45b3..a4f0a8a 100644
12384 --- a/arch/x86/include/asm/switch_to.h
12385 +++ b/arch/x86/include/asm/switch_to.h
12386 @@ -108,7 +108,7 @@ do { \
12387 "call __switch_to\n\t" \
12388 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12389 __switch_canary \
12390 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12391 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12392 "movq %%rax,%%rdi\n\t" \
12393 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12394 "jnz ret_from_fork\n\t" \
12395 @@ -119,7 +119,7 @@ do { \
12396 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12397 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12398 [_tif_fork] "i" (_TIF_FORK), \
12399 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12400 + [thread_info] "m" (current_tinfo), \
12401 [current_task] "m" (current_task) \
12402 __switch_canary_iparam \
12403 : "memory", "cc" __EXTRA_CLOBBER)
12404 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12405 index 3fda9db4..4ca1c61 100644
12406 --- a/arch/x86/include/asm/sys_ia32.h
12407 +++ b/arch/x86/include/asm/sys_ia32.h
12408 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12409 struct old_sigaction32 __user *);
12410 asmlinkage long sys32_alarm(unsigned int);
12411
12412 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12413 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12414 asmlinkage long sys32_sysfs(int, u32, u32);
12415
12416 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12417 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12418 index 89f794f..1422765 100644
12419 --- a/arch/x86/include/asm/thread_info.h
12420 +++ b/arch/x86/include/asm/thread_info.h
12421 @@ -10,6 +10,7 @@
12422 #include <linux/compiler.h>
12423 #include <asm/page.h>
12424 #include <asm/types.h>
12425 +#include <asm/percpu.h>
12426
12427 /*
12428 * low level task data that entry.S needs immediate access to
12429 @@ -24,7 +25,6 @@ struct exec_domain;
12430 #include <linux/atomic.h>
12431
12432 struct thread_info {
12433 - struct task_struct *task; /* main task structure */
12434 struct exec_domain *exec_domain; /* execution domain */
12435 __u32 flags; /* low level flags */
12436 __u32 status; /* thread synchronous flags */
12437 @@ -34,19 +34,13 @@ struct thread_info {
12438 mm_segment_t addr_limit;
12439 struct restart_block restart_block;
12440 void __user *sysenter_return;
12441 -#ifdef CONFIG_X86_32
12442 - unsigned long previous_esp; /* ESP of the previous stack in
12443 - case of nested (IRQ) stacks
12444 - */
12445 - __u8 supervisor_stack[0];
12446 -#endif
12447 + unsigned long lowest_stack;
12448 unsigned int sig_on_uaccess_error:1;
12449 unsigned int uaccess_err:1; /* uaccess failed */
12450 };
12451
12452 -#define INIT_THREAD_INFO(tsk) \
12453 +#define INIT_THREAD_INFO \
12454 { \
12455 - .task = &tsk, \
12456 .exec_domain = &default_exec_domain, \
12457 .flags = 0, \
12458 .cpu = 0, \
12459 @@ -57,7 +51,7 @@ struct thread_info {
12460 }, \
12461 }
12462
12463 -#define init_thread_info (init_thread_union.thread_info)
12464 +#define init_thread_info (init_thread_union.stack)
12465 #define init_stack (init_thread_union.stack)
12466
12467 #else /* !__ASSEMBLY__ */
12468 @@ -98,6 +92,7 @@ struct thread_info {
12469 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12470 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12471 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12472 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12473
12474 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12475 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12476 @@ -122,16 +117,18 @@ struct thread_info {
12477 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12478 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12479 #define _TIF_X32 (1 << TIF_X32)
12480 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12481
12482 /* work to do in syscall_trace_enter() */
12483 #define _TIF_WORK_SYSCALL_ENTRY \
12484 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12485 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12486 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12487 + _TIF_GRSEC_SETXID)
12488
12489 /* work to do in syscall_trace_leave() */
12490 #define _TIF_WORK_SYSCALL_EXIT \
12491 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12492 - _TIF_SYSCALL_TRACEPOINT)
12493 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12494
12495 /* work to do on interrupt/exception return */
12496 #define _TIF_WORK_MASK \
12497 @@ -141,7 +138,8 @@ struct thread_info {
12498
12499 /* work to do on any return to user space */
12500 #define _TIF_ALLWORK_MASK \
12501 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12502 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12503 + _TIF_GRSEC_SETXID)
12504
12505 /* Only used for 64 bit */
12506 #define _TIF_DO_NOTIFY_MASK \
12507 @@ -157,45 +155,40 @@ struct thread_info {
12508
12509 #define PREEMPT_ACTIVE 0x10000000
12510
12511 -#ifdef CONFIG_X86_32
12512 -
12513 -#define STACK_WARN (THREAD_SIZE/8)
12514 -/*
12515 - * macros/functions for gaining access to the thread information structure
12516 - *
12517 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12518 - */
12519 -#ifndef __ASSEMBLY__
12520 -
12521 -
12522 -/* how to get the current stack pointer from C */
12523 -register unsigned long current_stack_pointer asm("esp") __used;
12524 -
12525 -/* how to get the thread information struct from C */
12526 -static inline struct thread_info *current_thread_info(void)
12527 -{
12528 - return (struct thread_info *)
12529 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12530 -}
12531 -
12532 -#else /* !__ASSEMBLY__ */
12533 -
12534 +#ifdef __ASSEMBLY__
12535 /* how to get the thread information struct from ASM */
12536 #define GET_THREAD_INFO(reg) \
12537 - movl $-THREAD_SIZE, reg; \
12538 - andl %esp, reg
12539 + mov PER_CPU_VAR(current_tinfo), reg
12540
12541 /* use this one if reg already contains %esp */
12542 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12543 - andl $-THREAD_SIZE, reg
12544 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12545 +#else
12546 +/* how to get the thread information struct from C */
12547 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12548 +
12549 +static __always_inline struct thread_info *current_thread_info(void)
12550 +{
12551 + return this_cpu_read_stable(current_tinfo);
12552 +}
12553 +#endif
12554 +
12555 +#ifdef CONFIG_X86_32
12556 +
12557 +#define STACK_WARN (THREAD_SIZE/8)
12558 +/*
12559 + * macros/functions for gaining access to the thread information structure
12560 + *
12561 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12562 + */
12563 +#ifndef __ASSEMBLY__
12564 +
12565 +/* how to get the current stack pointer from C */
12566 +register unsigned long current_stack_pointer asm("esp") __used;
12567
12568 #endif
12569
12570 #else /* X86_32 */
12571
12572 -#include <asm/percpu.h>
12573 -#define KERNEL_STACK_OFFSET (5*8)
12574 -
12575 /*
12576 * macros/functions for gaining access to the thread information structure
12577 * preempt_count needs to be 1 initially, until the scheduler is functional.
12578 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12579 #ifndef __ASSEMBLY__
12580 DECLARE_PER_CPU(unsigned long, kernel_stack);
12581
12582 -static inline struct thread_info *current_thread_info(void)
12583 -{
12584 - struct thread_info *ti;
12585 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12586 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12587 - return ti;
12588 -}
12589 -
12590 -#else /* !__ASSEMBLY__ */
12591 -
12592 -/* how to get the thread information struct from ASM */
12593 -#define GET_THREAD_INFO(reg) \
12594 - movq PER_CPU_VAR(kernel_stack),reg ; \
12595 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12596 -
12597 -/*
12598 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12599 - * a certain register (to be used in assembler memory operands).
12600 - */
12601 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12602 -
12603 +/* how to get the current stack pointer from C */
12604 +register unsigned long current_stack_pointer asm("rsp") __used;
12605 #endif
12606
12607 #endif /* !X86_32 */
12608 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12609 extern void arch_task_cache_init(void);
12610 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12611 extern void arch_release_task_struct(struct task_struct *tsk);
12612 +
12613 +#define __HAVE_THREAD_FUNCTIONS
12614 +#define task_thread_info(task) (&(task)->tinfo)
12615 +#define task_stack_page(task) ((task)->stack)
12616 +#define setup_thread_stack(p, org) do {} while (0)
12617 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12618 +
12619 #endif
12620 #endif /* _ASM_X86_THREAD_INFO_H */
12621 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12622 index e1f3a17..1ab364d 100644
12623 --- a/arch/x86/include/asm/uaccess.h
12624 +++ b/arch/x86/include/asm/uaccess.h
12625 @@ -7,12 +7,15 @@
12626 #include <linux/compiler.h>
12627 #include <linux/thread_info.h>
12628 #include <linux/string.h>
12629 +#include <linux/sched.h>
12630 #include <asm/asm.h>
12631 #include <asm/page.h>
12632
12633 #define VERIFY_READ 0
12634 #define VERIFY_WRITE 1
12635
12636 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12637 +
12638 /*
12639 * The fs value determines whether argument validity checking should be
12640 * performed or not. If get_fs() == USER_DS, checking is performed, with
12641 @@ -28,7 +31,12 @@
12642
12643 #define get_ds() (KERNEL_DS)
12644 #define get_fs() (current_thread_info()->addr_limit)
12645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12646 +void __set_fs(mm_segment_t x);
12647 +void set_fs(mm_segment_t x);
12648 +#else
12649 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12650 +#endif
12651
12652 #define segment_eq(a, b) ((a).seg == (b).seg)
12653
12654 @@ -76,8 +84,33 @@
12655 * checks that the pointer is in the user space range - after calling
12656 * this function, memory access functions may still return -EFAULT.
12657 */
12658 -#define access_ok(type, addr, size) \
12659 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12660 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12661 +#define access_ok(type, addr, size) \
12662 +({ \
12663 + long __size = size; \
12664 + unsigned long __addr = (unsigned long)addr; \
12665 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12666 + unsigned long __end_ao = __addr + __size - 1; \
12667 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12668 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12669 + while(__addr_ao <= __end_ao) { \
12670 + char __c_ao; \
12671 + __addr_ao += PAGE_SIZE; \
12672 + if (__size > PAGE_SIZE) \
12673 + cond_resched(); \
12674 + if (__get_user(__c_ao, (char __user *)__addr)) \
12675 + break; \
12676 + if (type != VERIFY_WRITE) { \
12677 + __addr = __addr_ao; \
12678 + continue; \
12679 + } \
12680 + if (__put_user(__c_ao, (char __user *)__addr)) \
12681 + break; \
12682 + __addr = __addr_ao; \
12683 + } \
12684 + } \
12685 + __ret_ao; \
12686 +})
12687
12688 /*
12689 * The exception table consists of pairs of addresses relative to the
12690 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12691 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12692 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12693
12694 -
12695 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12696 +#define __copyuser_seg "gs;"
12697 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12698 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12699 +#else
12700 +#define __copyuser_seg
12701 +#define __COPYUSER_SET_ES
12702 +#define __COPYUSER_RESTORE_ES
12703 +#endif
12704
12705 #ifdef CONFIG_X86_32
12706 #define __put_user_asm_u64(x, addr, err, errret) \
12707 - asm volatile("1: movl %%eax,0(%2)\n" \
12708 - "2: movl %%edx,4(%2)\n" \
12709 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12710 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12711 "3:\n" \
12712 ".section .fixup,\"ax\"\n" \
12713 "4: movl %3,%0\n" \
12714 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12715 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12716
12717 #define __put_user_asm_ex_u64(x, addr) \
12718 - asm volatile("1: movl %%eax,0(%1)\n" \
12719 - "2: movl %%edx,4(%1)\n" \
12720 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12721 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12722 "3:\n" \
12723 _ASM_EXTABLE_EX(1b, 2b) \
12724 _ASM_EXTABLE_EX(2b, 3b) \
12725 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12726 __typeof__(*(ptr)) __pu_val; \
12727 __chk_user_ptr(ptr); \
12728 might_fault(); \
12729 - __pu_val = x; \
12730 + __pu_val = (x); \
12731 switch (sizeof(*(ptr))) { \
12732 case 1: \
12733 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12734 @@ -379,7 +420,7 @@ do { \
12735 } while (0)
12736
12737 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12738 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12739 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12740 "2:\n" \
12741 ".section .fixup,\"ax\"\n" \
12742 "3: mov %3,%0\n" \
12743 @@ -387,7 +428,7 @@ do { \
12744 " jmp 2b\n" \
12745 ".previous\n" \
12746 _ASM_EXTABLE(1b, 3b) \
12747 - : "=r" (err), ltype(x) \
12748 + : "=r" (err), ltype (x) \
12749 : "m" (__m(addr)), "i" (errret), "0" (err))
12750
12751 #define __get_user_size_ex(x, ptr, size) \
12752 @@ -412,7 +453,7 @@ do { \
12753 } while (0)
12754
12755 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12756 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12757 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12758 "2:\n" \
12759 _ASM_EXTABLE_EX(1b, 2b) \
12760 : ltype(x) : "m" (__m(addr)))
12761 @@ -429,13 +470,24 @@ do { \
12762 int __gu_err; \
12763 unsigned long __gu_val; \
12764 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12765 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12766 + (x) = (__typeof__(*(ptr)))__gu_val; \
12767 __gu_err; \
12768 })
12769
12770 /* FIXME: this hack is definitely wrong -AK */
12771 struct __large_struct { unsigned long buf[100]; };
12772 -#define __m(x) (*(struct __large_struct __user *)(x))
12773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12774 +#define ____m(x) \
12775 +({ \
12776 + unsigned long ____x = (unsigned long)(x); \
12777 + if (____x < PAX_USER_SHADOW_BASE) \
12778 + ____x += PAX_USER_SHADOW_BASE; \
12779 + (void __user *)____x; \
12780 +})
12781 +#else
12782 +#define ____m(x) (x)
12783 +#endif
12784 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12785
12786 /*
12787 * Tell gcc we read from memory instead of writing: this is because
12788 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12789 * aliasing issues.
12790 */
12791 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12792 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12793 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12794 "2:\n" \
12795 ".section .fixup,\"ax\"\n" \
12796 "3: mov %3,%0\n" \
12797 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12798 ".previous\n" \
12799 _ASM_EXTABLE(1b, 3b) \
12800 : "=r"(err) \
12801 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12802 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12803
12804 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12805 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12806 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12807 "2:\n" \
12808 _ASM_EXTABLE_EX(1b, 2b) \
12809 : : ltype(x), "m" (__m(addr)))
12810 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12811 * On error, the variable @x is set to zero.
12812 */
12813
12814 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12815 +#define __get_user(x, ptr) get_user((x), (ptr))
12816 +#else
12817 #define __get_user(x, ptr) \
12818 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12819 +#endif
12820
12821 /**
12822 * __put_user: - Write a simple value into user space, with less checking.
12823 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12824 * Returns zero on success, or -EFAULT on error.
12825 */
12826
12827 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12828 +#define __put_user(x, ptr) put_user((x), (ptr))
12829 +#else
12830 #define __put_user(x, ptr) \
12831 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12832 +#endif
12833
12834 #define __get_user_unaligned __get_user
12835 #define __put_user_unaligned __put_user
12836 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12837 #define get_user_ex(x, ptr) do { \
12838 unsigned long __gue_val; \
12839 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12840 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12841 + (x) = (__typeof__(*(ptr)))__gue_val; \
12842 } while (0)
12843
12844 #ifdef CONFIG_X86_WP_WORKS_OK
12845 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12846 index 576e39b..ccd0a39 100644
12847 --- a/arch/x86/include/asm/uaccess_32.h
12848 +++ b/arch/x86/include/asm/uaccess_32.h
12849 @@ -11,15 +11,15 @@
12850 #include <asm/page.h>
12851
12852 unsigned long __must_check __copy_to_user_ll
12853 - (void __user *to, const void *from, unsigned long n);
12854 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12855 unsigned long __must_check __copy_from_user_ll
12856 - (void *to, const void __user *from, unsigned long n);
12857 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12858 unsigned long __must_check __copy_from_user_ll_nozero
12859 - (void *to, const void __user *from, unsigned long n);
12860 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12861 unsigned long __must_check __copy_from_user_ll_nocache
12862 - (void *to, const void __user *from, unsigned long n);
12863 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12864 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12865 - (void *to, const void __user *from, unsigned long n);
12866 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12867
12868 /**
12869 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12870 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12871 static __always_inline unsigned long __must_check
12872 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12873 {
12874 + if ((long)n < 0)
12875 + return n;
12876 +
12877 if (__builtin_constant_p(n)) {
12878 unsigned long ret;
12879
12880 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12881 return ret;
12882 }
12883 }
12884 + if (!__builtin_constant_p(n))
12885 + check_object_size(from, n, true);
12886 return __copy_to_user_ll(to, from, n);
12887 }
12888
12889 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12890 __copy_to_user(void __user *to, const void *from, unsigned long n)
12891 {
12892 might_fault();
12893 +
12894 return __copy_to_user_inatomic(to, from, n);
12895 }
12896
12897 static __always_inline unsigned long
12898 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12899 {
12900 + if ((long)n < 0)
12901 + return n;
12902 +
12903 /* Avoid zeroing the tail if the copy fails..
12904 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12905 * but as the zeroing behaviour is only significant when n is not
12906 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12907 __copy_from_user(void *to, const void __user *from, unsigned long n)
12908 {
12909 might_fault();
12910 +
12911 + if ((long)n < 0)
12912 + return n;
12913 +
12914 if (__builtin_constant_p(n)) {
12915 unsigned long ret;
12916
12917 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12918 return ret;
12919 }
12920 }
12921 + if (!__builtin_constant_p(n))
12922 + check_object_size(to, n, false);
12923 return __copy_from_user_ll(to, from, n);
12924 }
12925
12926 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12927 const void __user *from, unsigned long n)
12928 {
12929 might_fault();
12930 +
12931 + if ((long)n < 0)
12932 + return n;
12933 +
12934 if (__builtin_constant_p(n)) {
12935 unsigned long ret;
12936
12937 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12938 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12939 unsigned long n)
12940 {
12941 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12942 + if ((long)n < 0)
12943 + return n;
12944 +
12945 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12946 }
12947
12948 -unsigned long __must_check copy_to_user(void __user *to,
12949 - const void *from, unsigned long n);
12950 -unsigned long __must_check _copy_from_user(void *to,
12951 - const void __user *from,
12952 - unsigned long n);
12953 -
12954 +extern void copy_to_user_overflow(void)
12955 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12956 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12957 +#else
12958 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12959 +#endif
12960 +;
12961
12962 extern void copy_from_user_overflow(void)
12963 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12964 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12965 #endif
12966 ;
12967
12968 -static inline unsigned long __must_check copy_from_user(void *to,
12969 - const void __user *from,
12970 - unsigned long n)
12971 +/**
12972 + * copy_to_user: - Copy a block of data into user space.
12973 + * @to: Destination address, in user space.
12974 + * @from: Source address, in kernel space.
12975 + * @n: Number of bytes to copy.
12976 + *
12977 + * Context: User context only. This function may sleep.
12978 + *
12979 + * Copy data from kernel space to user space.
12980 + *
12981 + * Returns number of bytes that could not be copied.
12982 + * On success, this will be zero.
12983 + */
12984 +static inline unsigned long __must_check
12985 +copy_to_user(void __user *to, const void *from, unsigned long n)
12986 {
12987 - int sz = __compiletime_object_size(to);
12988 + size_t sz = __compiletime_object_size(from);
12989
12990 - if (likely(sz == -1 || sz >= n))
12991 - n = _copy_from_user(to, from, n);
12992 - else
12993 + if (unlikely(sz != (size_t)-1 && sz < n))
12994 + copy_to_user_overflow();
12995 + else if (access_ok(VERIFY_WRITE, to, n))
12996 + n = __copy_to_user(to, from, n);
12997 + return n;
12998 +}
12999 +
13000 +/**
13001 + * copy_from_user: - Copy a block of data from user space.
13002 + * @to: Destination address, in kernel space.
13003 + * @from: Source address, in user space.
13004 + * @n: Number of bytes to copy.
13005 + *
13006 + * Context: User context only. This function may sleep.
13007 + *
13008 + * Copy data from user space to kernel space.
13009 + *
13010 + * Returns number of bytes that could not be copied.
13011 + * On success, this will be zero.
13012 + *
13013 + * If some data could not be copied, this function will pad the copied
13014 + * data to the requested size using zero bytes.
13015 + */
13016 +static inline unsigned long __must_check
13017 +copy_from_user(void *to, const void __user *from, unsigned long n)
13018 +{
13019 + size_t sz = __compiletime_object_size(to);
13020 +
13021 + if (unlikely(sz != (size_t)-1 && sz < n))
13022 copy_from_user_overflow();
13023 -
13024 + else if (access_ok(VERIFY_READ, from, n))
13025 + n = __copy_from_user(to, from, n);
13026 + else if ((long)n > 0) {
13027 + if (!__builtin_constant_p(n))
13028 + check_object_size(to, n, false);
13029 + memset(to, 0, n);
13030 + }
13031 return n;
13032 }
13033
13034 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13035 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13036 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13037 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13038
13039 #endif /* _ASM_X86_UACCESS_32_H */
13040 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13041 index 8e796fb..72fd934 100644
13042 --- a/arch/x86/include/asm/uaccess_64.h
13043 +++ b/arch/x86/include/asm/uaccess_64.h
13044 @@ -10,6 +10,9 @@
13045 #include <asm/alternative.h>
13046 #include <asm/cpufeature.h>
13047 #include <asm/page.h>
13048 +#include <asm/pgtable.h>
13049 +
13050 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13051
13052 /*
13053 * Copy To/From Userspace
13054 @@ -17,12 +20,14 @@
13055
13056 /* Handles exceptions in both to and from, but doesn't do access_ok */
13057 __must_check unsigned long
13058 -copy_user_generic_string(void *to, const void *from, unsigned len);
13059 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13060 __must_check unsigned long
13061 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13062 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13063
13064 static __always_inline __must_check unsigned long
13065 -copy_user_generic(void *to, const void *from, unsigned len)
13066 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13067 +static __always_inline __must_check unsigned long
13068 +copy_user_generic(void *to, const void *from, unsigned long len)
13069 {
13070 unsigned ret;
13071
13072 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13073 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13074 "=d" (len)),
13075 "1" (to), "2" (from), "3" (len)
13076 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13077 + : "memory", "rcx", "r8", "r9", "r11");
13078 return ret;
13079 }
13080
13081 +static __always_inline __must_check unsigned long
13082 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13083 +static __always_inline __must_check unsigned long
13084 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13085 __must_check unsigned long
13086 -_copy_to_user(void __user *to, const void *from, unsigned len);
13087 -__must_check unsigned long
13088 -_copy_from_user(void *to, const void __user *from, unsigned len);
13089 -__must_check unsigned long
13090 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13091 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13092 +
13093 +extern void copy_to_user_overflow(void)
13094 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13095 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13096 +#else
13097 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13098 +#endif
13099 +;
13100 +
13101 +extern void copy_from_user_overflow(void)
13102 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13103 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13104 +#else
13105 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13106 +#endif
13107 +;
13108
13109 static inline unsigned long __must_check copy_from_user(void *to,
13110 const void __user *from,
13111 unsigned long n)
13112 {
13113 - int sz = __compiletime_object_size(to);
13114 -
13115 might_fault();
13116 - if (likely(sz == -1 || sz >= n))
13117 - n = _copy_from_user(to, from, n);
13118 -#ifdef CONFIG_DEBUG_VM
13119 - else
13120 - WARN(1, "Buffer overflow detected!\n");
13121 -#endif
13122 +
13123 + if (access_ok(VERIFY_READ, from, n))
13124 + n = __copy_from_user(to, from, n);
13125 + else if (n < INT_MAX) {
13126 + if (!__builtin_constant_p(n))
13127 + check_object_size(to, n, false);
13128 + memset(to, 0, n);
13129 + }
13130 return n;
13131 }
13132
13133 static __always_inline __must_check
13134 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13135 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13136 {
13137 might_fault();
13138
13139 - return _copy_to_user(dst, src, size);
13140 + if (access_ok(VERIFY_WRITE, dst, size))
13141 + size = __copy_to_user(dst, src, size);
13142 + return size;
13143 }
13144
13145 static __always_inline __must_check
13146 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13147 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13148 {
13149 - int ret = 0;
13150 + size_t sz = __compiletime_object_size(dst);
13151 + unsigned ret = 0;
13152
13153 might_fault();
13154 - if (!__builtin_constant_p(size))
13155 - return copy_user_generic(dst, (__force void *)src, size);
13156 +
13157 + if (size > INT_MAX)
13158 + return size;
13159 +
13160 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13161 + if (!__access_ok(VERIFY_READ, src, size))
13162 + return size;
13163 +#endif
13164 +
13165 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13166 + copy_from_user_overflow();
13167 + return size;
13168 + }
13169 +
13170 + if (!__builtin_constant_p(size)) {
13171 + check_object_size(dst, size, false);
13172 +
13173 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13174 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13175 + src += PAX_USER_SHADOW_BASE;
13176 +#endif
13177 +
13178 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13179 + }
13180 switch (size) {
13181 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13182 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13183 ret, "b", "b", "=q", 1);
13184 return ret;
13185 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13186 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13187 ret, "w", "w", "=r", 2);
13188 return ret;
13189 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13190 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13191 ret, "l", "k", "=r", 4);
13192 return ret;
13193 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13194 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13195 ret, "q", "", "=r", 8);
13196 return ret;
13197 case 10:
13198 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13199 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13200 ret, "q", "", "=r", 10);
13201 if (unlikely(ret))
13202 return ret;
13203 __get_user_asm(*(u16 *)(8 + (char *)dst),
13204 - (u16 __user *)(8 + (char __user *)src),
13205 + (const u16 __user *)(8 + (const char __user *)src),
13206 ret, "w", "w", "=r", 2);
13207 return ret;
13208 case 16:
13209 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13210 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13211 ret, "q", "", "=r", 16);
13212 if (unlikely(ret))
13213 return ret;
13214 __get_user_asm(*(u64 *)(8 + (char *)dst),
13215 - (u64 __user *)(8 + (char __user *)src),
13216 + (const u64 __user *)(8 + (const char __user *)src),
13217 ret, "q", "", "=r", 8);
13218 return ret;
13219 default:
13220 - return copy_user_generic(dst, (__force void *)src, size);
13221 +
13222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13223 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13224 + src += PAX_USER_SHADOW_BASE;
13225 +#endif
13226 +
13227 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13228 }
13229 }
13230
13231 static __always_inline __must_check
13232 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13233 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13234 {
13235 - int ret = 0;
13236 + size_t sz = __compiletime_object_size(src);
13237 + unsigned ret = 0;
13238
13239 might_fault();
13240 - if (!__builtin_constant_p(size))
13241 - return copy_user_generic((__force void *)dst, src, size);
13242 +
13243 + if (size > INT_MAX)
13244 + return size;
13245 +
13246 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13247 + if (!__access_ok(VERIFY_WRITE, dst, size))
13248 + return size;
13249 +#endif
13250 +
13251 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13252 + copy_to_user_overflow();
13253 + return size;
13254 + }
13255 +
13256 + if (!__builtin_constant_p(size)) {
13257 + check_object_size(src, size, true);
13258 +
13259 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13260 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13261 + dst += PAX_USER_SHADOW_BASE;
13262 +#endif
13263 +
13264 + return copy_user_generic((__force_kernel void *)dst, src, size);
13265 + }
13266 switch (size) {
13267 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13268 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13269 ret, "b", "b", "iq", 1);
13270 return ret;
13271 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13272 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13273 ret, "w", "w", "ir", 2);
13274 return ret;
13275 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13276 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13277 ret, "l", "k", "ir", 4);
13278 return ret;
13279 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13280 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13281 ret, "q", "", "er", 8);
13282 return ret;
13283 case 10:
13284 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13285 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13286 ret, "q", "", "er", 10);
13287 if (unlikely(ret))
13288 return ret;
13289 asm("":::"memory");
13290 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13291 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13292 ret, "w", "w", "ir", 2);
13293 return ret;
13294 case 16:
13295 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13296 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13297 ret, "q", "", "er", 16);
13298 if (unlikely(ret))
13299 return ret;
13300 asm("":::"memory");
13301 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13302 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13303 ret, "q", "", "er", 8);
13304 return ret;
13305 default:
13306 - return copy_user_generic((__force void *)dst, src, size);
13307 +
13308 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13309 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13310 + dst += PAX_USER_SHADOW_BASE;
13311 +#endif
13312 +
13313 + return copy_user_generic((__force_kernel void *)dst, src, size);
13314 }
13315 }
13316
13317 static __always_inline __must_check
13318 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13319 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13320 {
13321 - int ret = 0;
13322 + unsigned ret = 0;
13323
13324 might_fault();
13325 - if (!__builtin_constant_p(size))
13326 - return copy_user_generic((__force void *)dst,
13327 - (__force void *)src, size);
13328 +
13329 + if (size > INT_MAX)
13330 + return size;
13331 +
13332 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13333 + if (!__access_ok(VERIFY_READ, src, size))
13334 + return size;
13335 + if (!__access_ok(VERIFY_WRITE, dst, size))
13336 + return size;
13337 +#endif
13338 +
13339 + if (!__builtin_constant_p(size)) {
13340 +
13341 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13342 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13343 + src += PAX_USER_SHADOW_BASE;
13344 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13345 + dst += PAX_USER_SHADOW_BASE;
13346 +#endif
13347 +
13348 + return copy_user_generic((__force_kernel void *)dst,
13349 + (__force_kernel const void *)src, size);
13350 + }
13351 switch (size) {
13352 case 1: {
13353 u8 tmp;
13354 - __get_user_asm(tmp, (u8 __user *)src,
13355 + __get_user_asm(tmp, (const u8 __user *)src,
13356 ret, "b", "b", "=q", 1);
13357 if (likely(!ret))
13358 __put_user_asm(tmp, (u8 __user *)dst,
13359 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13360 }
13361 case 2: {
13362 u16 tmp;
13363 - __get_user_asm(tmp, (u16 __user *)src,
13364 + __get_user_asm(tmp, (const u16 __user *)src,
13365 ret, "w", "w", "=r", 2);
13366 if (likely(!ret))
13367 __put_user_asm(tmp, (u16 __user *)dst,
13368 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13369
13370 case 4: {
13371 u32 tmp;
13372 - __get_user_asm(tmp, (u32 __user *)src,
13373 + __get_user_asm(tmp, (const u32 __user *)src,
13374 ret, "l", "k", "=r", 4);
13375 if (likely(!ret))
13376 __put_user_asm(tmp, (u32 __user *)dst,
13377 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13378 }
13379 case 8: {
13380 u64 tmp;
13381 - __get_user_asm(tmp, (u64 __user *)src,
13382 + __get_user_asm(tmp, (const u64 __user *)src,
13383 ret, "q", "", "=r", 8);
13384 if (likely(!ret))
13385 __put_user_asm(tmp, (u64 __user *)dst,
13386 @@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13387 return ret;
13388 }
13389 default:
13390 - return copy_user_generic((__force void *)dst,
13391 - (__force void *)src, size);
13392 +
13393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13394 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13395 + src += PAX_USER_SHADOW_BASE;
13396 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13397 + dst += PAX_USER_SHADOW_BASE;
13398 +#endif
13399 +
13400 + return copy_user_generic((__force_kernel void *)dst,
13401 + (__force_kernel const void *)src, size);
13402 }
13403 }
13404
13405 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13406 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13407 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13408 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13409
13410 static __must_check __always_inline int
13411 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13412 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13413 {
13414 - return copy_user_generic(dst, (__force const void *)src, size);
13415 + if (size > INT_MAX)
13416 + return size;
13417 +
13418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13419 + if (!__access_ok(VERIFY_READ, src, size))
13420 + return size;
13421 +
13422 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13423 + src += PAX_USER_SHADOW_BASE;
13424 +#endif
13425 +
13426 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13427 }
13428
13429 -static __must_check __always_inline int
13430 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13431 +static __must_check __always_inline unsigned long
13432 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13433 {
13434 - return copy_user_generic((__force void *)dst, src, size);
13435 + if (size > INT_MAX)
13436 + return size;
13437 +
13438 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13439 + if (!__access_ok(VERIFY_WRITE, dst, size))
13440 + return size;
13441 +
13442 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13443 + dst += PAX_USER_SHADOW_BASE;
13444 +#endif
13445 +
13446 + return copy_user_generic((__force_kernel void *)dst, src, size);
13447 }
13448
13449 -extern long __copy_user_nocache(void *dst, const void __user *src,
13450 - unsigned size, int zerorest);
13451 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13452 + unsigned long size, int zerorest) __size_overflow(3);
13453
13454 -static inline int
13455 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13456 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13457 {
13458 might_sleep();
13459 +
13460 + if (size > INT_MAX)
13461 + return size;
13462 +
13463 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13464 + if (!__access_ok(VERIFY_READ, src, size))
13465 + return size;
13466 +#endif
13467 +
13468 return __copy_user_nocache(dst, src, size, 1);
13469 }
13470
13471 -static inline int
13472 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13473 - unsigned size)
13474 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13475 + unsigned long size)
13476 {
13477 + if (size > INT_MAX)
13478 + return size;
13479 +
13480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13481 + if (!__access_ok(VERIFY_READ, src, size))
13482 + return size;
13483 +#endif
13484 +
13485 return __copy_user_nocache(dst, src, size, 0);
13486 }
13487
13488 -unsigned long
13489 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13490 +extern unsigned long
13491 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13492
13493 #endif /* _ASM_X86_UACCESS_64_H */
13494 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13495 index bb05228..d763d5b 100644
13496 --- a/arch/x86/include/asm/vdso.h
13497 +++ b/arch/x86/include/asm/vdso.h
13498 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13499 #define VDSO32_SYMBOL(base, name) \
13500 ({ \
13501 extern const char VDSO32_##name[]; \
13502 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13503 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13504 })
13505 #endif
13506
13507 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13508 index 5b238981..77fdd78 100644
13509 --- a/arch/x86/include/asm/word-at-a-time.h
13510 +++ b/arch/x86/include/asm/word-at-a-time.h
13511 @@ -11,7 +11,7 @@
13512 * and shift, for example.
13513 */
13514 struct word_at_a_time {
13515 - const unsigned long one_bits, high_bits;
13516 + unsigned long one_bits, high_bits;
13517 };
13518
13519 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13520 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13521 index c090af1..7e7bf16 100644
13522 --- a/arch/x86/include/asm/x86_init.h
13523 +++ b/arch/x86/include/asm/x86_init.h
13524 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13525 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13526 void (*find_smp_config)(void);
13527 void (*get_smp_config)(unsigned int early);
13528 -};
13529 +} __no_const;
13530
13531 /**
13532 * struct x86_init_resources - platform specific resource related ops
13533 @@ -43,7 +43,7 @@ struct x86_init_resources {
13534 void (*probe_roms)(void);
13535 void (*reserve_resources)(void);
13536 char *(*memory_setup)(void);
13537 -};
13538 +} __no_const;
13539
13540 /**
13541 * struct x86_init_irqs - platform specific interrupt setup
13542 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13543 void (*pre_vector_init)(void);
13544 void (*intr_init)(void);
13545 void (*trap_init)(void);
13546 -};
13547 +} __no_const;
13548
13549 /**
13550 * struct x86_init_oem - oem platform specific customizing functions
13551 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13552 struct x86_init_oem {
13553 void (*arch_setup)(void);
13554 void (*banner)(void);
13555 -};
13556 +} __no_const;
13557
13558 /**
13559 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13560 @@ -77,7 +77,7 @@ struct x86_init_oem {
13561 */
13562 struct x86_init_mapping {
13563 void (*pagetable_reserve)(u64 start, u64 end);
13564 -};
13565 +} __no_const;
13566
13567 /**
13568 * struct x86_init_paging - platform specific paging functions
13569 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13570 struct x86_init_paging {
13571 void (*pagetable_setup_start)(pgd_t *base);
13572 void (*pagetable_setup_done)(pgd_t *base);
13573 -};
13574 +} __no_const;
13575
13576 /**
13577 * struct x86_init_timers - platform specific timer setup
13578 @@ -102,7 +102,7 @@ struct x86_init_timers {
13579 void (*tsc_pre_init)(void);
13580 void (*timer_init)(void);
13581 void (*wallclock_init)(void);
13582 -};
13583 +} __no_const;
13584
13585 /**
13586 * struct x86_init_iommu - platform specific iommu setup
13587 @@ -110,7 +110,7 @@ struct x86_init_timers {
13588 */
13589 struct x86_init_iommu {
13590 int (*iommu_init)(void);
13591 -};
13592 +} __no_const;
13593
13594 /**
13595 * struct x86_init_pci - platform specific pci init functions
13596 @@ -124,7 +124,7 @@ struct x86_init_pci {
13597 int (*init)(void);
13598 void (*init_irq)(void);
13599 void (*fixup_irqs)(void);
13600 -};
13601 +} __no_const;
13602
13603 /**
13604 * struct x86_init_ops - functions for platform specific setup
13605 @@ -140,7 +140,7 @@ struct x86_init_ops {
13606 struct x86_init_timers timers;
13607 struct x86_init_iommu iommu;
13608 struct x86_init_pci pci;
13609 -};
13610 +} __no_const;
13611
13612 /**
13613 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13614 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13615 void (*setup_percpu_clockev)(void);
13616 void (*early_percpu_clock_init)(void);
13617 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13618 -};
13619 +} __no_const;
13620
13621 /**
13622 * struct x86_platform_ops - platform specific runtime functions
13623 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13624 int (*i8042_detect)(void);
13625 void (*save_sched_clock_state)(void);
13626 void (*restore_sched_clock_state)(void);
13627 -};
13628 +} __no_const;
13629
13630 struct pci_dev;
13631
13632 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13633 void (*teardown_msi_irq)(unsigned int irq);
13634 void (*teardown_msi_irqs)(struct pci_dev *dev);
13635 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13636 -};
13637 +} __no_const;
13638
13639 struct x86_io_apic_ops {
13640 void (*init) (void);
13641 unsigned int (*read) (unsigned int apic, unsigned int reg);
13642 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13643 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13644 -};
13645 +} __no_const;
13646
13647 extern struct x86_init_ops x86_init;
13648 extern struct x86_cpuinit_ops x86_cpuinit;
13649 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13650 index 8a1b6f9..a29c4e4 100644
13651 --- a/arch/x86/include/asm/xsave.h
13652 +++ b/arch/x86/include/asm/xsave.h
13653 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13654 {
13655 int err;
13656
13657 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13658 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13659 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13660 +#endif
13661 +
13662 /*
13663 * Clear the xsave header first, so that reserved fields are
13664 * initialized to zero.
13665 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13666 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13667 {
13668 int err;
13669 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13670 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13671 u32 lmask = mask;
13672 u32 hmask = mask >> 32;
13673
13674 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13675 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13676 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13677 +#endif
13678 +
13679 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13680 "2:\n"
13681 ".section .fixup,\"ax\"\n"
13682 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13683 index 95bf99de..de9235c 100644
13684 --- a/arch/x86/kernel/acpi/sleep.c
13685 +++ b/arch/x86/kernel/acpi/sleep.c
13686 @@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13687 #else /* CONFIG_64BIT */
13688 #ifdef CONFIG_SMP
13689 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13690 +
13691 + pax_open_kernel();
13692 early_gdt_descr.address =
13693 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13694 + pax_close_kernel();
13695 +
13696 initial_gs = per_cpu_offset(smp_processor_id());
13697 #endif
13698 initial_code = (unsigned long)wakeup_long64;
13699 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13700 index 7261083..5c12053 100644
13701 --- a/arch/x86/kernel/acpi/wakeup_32.S
13702 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13703 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13704 # and restore the stack ... but you need gdt for this to work
13705 movl saved_context_esp, %esp
13706
13707 - movl %cs:saved_magic, %eax
13708 - cmpl $0x12345678, %eax
13709 + cmpl $0x12345678, saved_magic
13710 jne bogus_magic
13711
13712 # jump to place where we left off
13713 - movl saved_eip, %eax
13714 - jmp *%eax
13715 + jmp *(saved_eip)
13716
13717 bogus_magic:
13718 jmp bogus_magic
13719 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13720 index 73ef56c..0238021 100644
13721 --- a/arch/x86/kernel/alternative.c
13722 +++ b/arch/x86/kernel/alternative.c
13723 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13724 */
13725 for (a = start; a < end; a++) {
13726 instr = (u8 *)&a->instr_offset + a->instr_offset;
13727 +
13728 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13729 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13730 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13731 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13732 +#endif
13733 +
13734 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13735 BUG_ON(a->replacementlen > a->instrlen);
13736 BUG_ON(a->instrlen > sizeof(insnbuf));
13737 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13738 for (poff = start; poff < end; poff++) {
13739 u8 *ptr = (u8 *)poff + *poff;
13740
13741 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13742 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13743 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13744 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13745 +#endif
13746 +
13747 if (!*poff || ptr < text || ptr >= text_end)
13748 continue;
13749 /* turn DS segment override prefix into lock prefix */
13750 - if (*ptr == 0x3e)
13751 + if (*ktla_ktva(ptr) == 0x3e)
13752 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13753 };
13754 mutex_unlock(&text_mutex);
13755 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13756 for (poff = start; poff < end; poff++) {
13757 u8 *ptr = (u8 *)poff + *poff;
13758
13759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13760 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13761 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13762 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13763 +#endif
13764 +
13765 if (!*poff || ptr < text || ptr >= text_end)
13766 continue;
13767 /* turn lock prefix into DS segment override prefix */
13768 - if (*ptr == 0xf0)
13769 + if (*ktla_ktva(ptr) == 0xf0)
13770 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13771 };
13772 mutex_unlock(&text_mutex);
13773 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13774
13775 BUG_ON(p->len > MAX_PATCH_LEN);
13776 /* prep the buffer with the original instructions */
13777 - memcpy(insnbuf, p->instr, p->len);
13778 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13779 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13780 (unsigned long)p->instr, p->len);
13781
13782 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13783 if (smp_alt_once)
13784 free_init_pages("SMP alternatives",
13785 (unsigned long)__smp_locks,
13786 - (unsigned long)__smp_locks_end);
13787 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13788
13789 restart_nmi();
13790 }
13791 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13792 * instructions. And on the local CPU you need to be protected again NMI or MCE
13793 * handlers seeing an inconsistent instruction while you patch.
13794 */
13795 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13796 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13797 size_t len)
13798 {
13799 unsigned long flags;
13800 local_irq_save(flags);
13801 - memcpy(addr, opcode, len);
13802 +
13803 + pax_open_kernel();
13804 + memcpy(ktla_ktva(addr), opcode, len);
13805 sync_core();
13806 + pax_close_kernel();
13807 +
13808 local_irq_restore(flags);
13809 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13810 that causes hangs on some VIA CPUs. */
13811 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13812 */
13813 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13814 {
13815 - unsigned long flags;
13816 - char *vaddr;
13817 + unsigned char *vaddr = ktla_ktva(addr);
13818 struct page *pages[2];
13819 - int i;
13820 + size_t i;
13821
13822 if (!core_kernel_text((unsigned long)addr)) {
13823 - pages[0] = vmalloc_to_page(addr);
13824 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13825 + pages[0] = vmalloc_to_page(vaddr);
13826 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13827 } else {
13828 - pages[0] = virt_to_page(addr);
13829 + pages[0] = virt_to_page(vaddr);
13830 WARN_ON(!PageReserved(pages[0]));
13831 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13832 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13833 }
13834 BUG_ON(!pages[0]);
13835 - local_irq_save(flags);
13836 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13837 - if (pages[1])
13838 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13839 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13840 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13841 - clear_fixmap(FIX_TEXT_POKE0);
13842 - if (pages[1])
13843 - clear_fixmap(FIX_TEXT_POKE1);
13844 - local_flush_tlb();
13845 - sync_core();
13846 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13847 - that causes hangs on some VIA CPUs. */
13848 + text_poke_early(addr, opcode, len);
13849 for (i = 0; i < len; i++)
13850 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13851 - local_irq_restore(flags);
13852 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13853 return addr;
13854 }
13855
13856 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13857 index 39a222e..85a7767 100644
13858 --- a/arch/x86/kernel/apic/apic.c
13859 +++ b/arch/x86/kernel/apic/apic.c
13860 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13861 /*
13862 * Debug level, exported for io_apic.c
13863 */
13864 -unsigned int apic_verbosity;
13865 +int apic_verbosity;
13866
13867 int pic_mode;
13868
13869 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13870 apic_write(APIC_ESR, 0);
13871 v1 = apic_read(APIC_ESR);
13872 ack_APIC_irq();
13873 - atomic_inc(&irq_err_count);
13874 + atomic_inc_unchecked(&irq_err_count);
13875
13876 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13877 smp_processor_id(), v0 , v1);
13878 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13879 index 5f0ff59..f9e01bc 100644
13880 --- a/arch/x86/kernel/apic/io_apic.c
13881 +++ b/arch/x86/kernel/apic/io_apic.c
13882 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13883 }
13884 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13885
13886 -void lock_vector_lock(void)
13887 +void lock_vector_lock(void) __acquires(vector_lock)
13888 {
13889 /* Used to the online set of cpus does not change
13890 * during assign_irq_vector.
13891 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13892 raw_spin_lock(&vector_lock);
13893 }
13894
13895 -void unlock_vector_lock(void)
13896 +void unlock_vector_lock(void) __releases(vector_lock)
13897 {
13898 raw_spin_unlock(&vector_lock);
13899 }
13900 @@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13901 ack_APIC_irq();
13902 }
13903
13904 -atomic_t irq_mis_count;
13905 +atomic_unchecked_t irq_mis_count;
13906
13907 #ifdef CONFIG_GENERIC_PENDING_IRQ
13908 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13909 @@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13910 * at the cpu.
13911 */
13912 if (!(v & (1 << (i & 0x1f)))) {
13913 - atomic_inc(&irq_mis_count);
13914 + atomic_inc_unchecked(&irq_mis_count);
13915
13916 eoi_ioapic_irq(irq, cfg);
13917 }
13918 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13919 index 07b0c0d..1df6f42 100644
13920 --- a/arch/x86/kernel/apm_32.c
13921 +++ b/arch/x86/kernel/apm_32.c
13922 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13923 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13924 * even though they are called in protected mode.
13925 */
13926 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13927 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13928 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13929
13930 static const char driver_version[] = "1.16ac"; /* no spaces */
13931 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13932 BUG_ON(cpu != 0);
13933 gdt = get_cpu_gdt_table(cpu);
13934 save_desc_40 = gdt[0x40 / 8];
13935 +
13936 + pax_open_kernel();
13937 gdt[0x40 / 8] = bad_bios_desc;
13938 + pax_close_kernel();
13939
13940 apm_irq_save(flags);
13941 APM_DO_SAVE_SEGS;
13942 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13943 &call->esi);
13944 APM_DO_RESTORE_SEGS;
13945 apm_irq_restore(flags);
13946 +
13947 + pax_open_kernel();
13948 gdt[0x40 / 8] = save_desc_40;
13949 + pax_close_kernel();
13950 +
13951 put_cpu();
13952
13953 return call->eax & 0xff;
13954 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13955 BUG_ON(cpu != 0);
13956 gdt = get_cpu_gdt_table(cpu);
13957 save_desc_40 = gdt[0x40 / 8];
13958 +
13959 + pax_open_kernel();
13960 gdt[0x40 / 8] = bad_bios_desc;
13961 + pax_close_kernel();
13962
13963 apm_irq_save(flags);
13964 APM_DO_SAVE_SEGS;
13965 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13966 &call->eax);
13967 APM_DO_RESTORE_SEGS;
13968 apm_irq_restore(flags);
13969 +
13970 + pax_open_kernel();
13971 gdt[0x40 / 8] = save_desc_40;
13972 + pax_close_kernel();
13973 +
13974 put_cpu();
13975 return error;
13976 }
13977 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13978 * code to that CPU.
13979 */
13980 gdt = get_cpu_gdt_table(0);
13981 +
13982 + pax_open_kernel();
13983 set_desc_base(&gdt[APM_CS >> 3],
13984 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13985 set_desc_base(&gdt[APM_CS_16 >> 3],
13986 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13987 set_desc_base(&gdt[APM_DS >> 3],
13988 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13989 + pax_close_kernel();
13990
13991 proc_create("apm", 0, NULL, &apm_file_ops);
13992
13993 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13994 index 68de2dc..1f3c720 100644
13995 --- a/arch/x86/kernel/asm-offsets.c
13996 +++ b/arch/x86/kernel/asm-offsets.c
13997 @@ -33,6 +33,8 @@ void common(void) {
13998 OFFSET(TI_status, thread_info, status);
13999 OFFSET(TI_addr_limit, thread_info, addr_limit);
14000 OFFSET(TI_preempt_count, thread_info, preempt_count);
14001 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14002 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14003
14004 BLANK();
14005 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14006 @@ -53,8 +55,26 @@ void common(void) {
14007 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14008 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14009 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14010 +
14011 +#ifdef CONFIG_PAX_KERNEXEC
14012 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14013 #endif
14014
14015 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14016 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14017 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14018 +#ifdef CONFIG_X86_64
14019 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14020 +#endif
14021 +#endif
14022 +
14023 +#endif
14024 +
14025 + BLANK();
14026 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14027 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14028 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14029 +
14030 #ifdef CONFIG_XEN
14031 BLANK();
14032 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14033 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14034 index 1b4754f..fbb4227 100644
14035 --- a/arch/x86/kernel/asm-offsets_64.c
14036 +++ b/arch/x86/kernel/asm-offsets_64.c
14037 @@ -76,6 +76,7 @@ int main(void)
14038 BLANK();
14039 #undef ENTRY
14040
14041 + DEFINE(TSS_size, sizeof(struct tss_struct));
14042 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14043 BLANK();
14044
14045 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14046 index 6ab6aa2..8f71507 100644
14047 --- a/arch/x86/kernel/cpu/Makefile
14048 +++ b/arch/x86/kernel/cpu/Makefile
14049 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14050 CFLAGS_REMOVE_perf_event.o = -pg
14051 endif
14052
14053 -# Make sure load_percpu_segment has no stackprotector
14054 -nostackp := $(call cc-option, -fno-stack-protector)
14055 -CFLAGS_common.o := $(nostackp)
14056 -
14057 obj-y := intel_cacheinfo.o scattered.o topology.o
14058 obj-y += proc.o capflags.o powerflags.o common.o
14059 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14060 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14061 index 146bb62..ac9c74a 100644
14062 --- a/arch/x86/kernel/cpu/amd.c
14063 +++ b/arch/x86/kernel/cpu/amd.c
14064 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14065 unsigned int size)
14066 {
14067 /* AMD errata T13 (order #21922) */
14068 - if ((c->x86 == 6)) {
14069 + if (c->x86 == 6) {
14070 /* Duron Rev A0 */
14071 if (c->x86_model == 3 && c->x86_mask == 0)
14072 size = 64;
14073 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14074 index 6b9333b..4c3083a 100644
14075 --- a/arch/x86/kernel/cpu/common.c
14076 +++ b/arch/x86/kernel/cpu/common.c
14077 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14078
14079 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14080
14081 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14082 -#ifdef CONFIG_X86_64
14083 - /*
14084 - * We need valid kernel segments for data and code in long mode too
14085 - * IRET will check the segment types kkeil 2000/10/28
14086 - * Also sysret mandates a special GDT layout
14087 - *
14088 - * TLS descriptors are currently at a different place compared to i386.
14089 - * Hopefully nobody expects them at a fixed place (Wine?)
14090 - */
14091 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14092 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14093 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14094 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14095 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14096 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14097 -#else
14098 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14099 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14100 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14101 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14102 - /*
14103 - * Segments used for calling PnP BIOS have byte granularity.
14104 - * They code segments and data segments have fixed 64k limits,
14105 - * the transfer segment sizes are set at run time.
14106 - */
14107 - /* 32-bit code */
14108 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14109 - /* 16-bit code */
14110 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14111 - /* 16-bit data */
14112 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14113 - /* 16-bit data */
14114 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14115 - /* 16-bit data */
14116 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14117 - /*
14118 - * The APM segments have byte granularity and their bases
14119 - * are set at run time. All have 64k limits.
14120 - */
14121 - /* 32-bit code */
14122 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14123 - /* 16-bit code */
14124 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14125 - /* data */
14126 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14127 -
14128 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14129 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14130 - GDT_STACK_CANARY_INIT
14131 -#endif
14132 -} };
14133 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14134 -
14135 static int __init x86_xsave_setup(char *s)
14136 {
14137 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14138 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14139 {
14140 struct desc_ptr gdt_descr;
14141
14142 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14143 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14144 gdt_descr.size = GDT_SIZE - 1;
14145 load_gdt(&gdt_descr);
14146 /* Reload the per-cpu base */
14147 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14148 /* Filter out anything that depends on CPUID levels we don't have */
14149 filter_cpuid_features(c, true);
14150
14151 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14152 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14153 +#endif
14154 +
14155 /* If the model name is still unset, do table lookup. */
14156 if (!c->x86_model_id[0]) {
14157 const char *p;
14158 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14159 }
14160 __setup("clearcpuid=", setup_disablecpuid);
14161
14162 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14163 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14164 +
14165 #ifdef CONFIG_X86_64
14166 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14167 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14168 - (unsigned long) nmi_idt_table };
14169 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14170
14171 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14172 irq_stack_union) __aligned(PAGE_SIZE);
14173 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14174 EXPORT_PER_CPU_SYMBOL(current_task);
14175
14176 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14177 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14178 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14179 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14180
14181 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14182 @@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14183 {
14184 memset(regs, 0, sizeof(struct pt_regs));
14185 regs->fs = __KERNEL_PERCPU;
14186 - regs->gs = __KERNEL_STACK_CANARY;
14187 + savesegment(gs, regs->gs);
14188
14189 return regs;
14190 }
14191 @@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14192 int i;
14193
14194 cpu = stack_smp_processor_id();
14195 - t = &per_cpu(init_tss, cpu);
14196 + t = init_tss + cpu;
14197 oist = &per_cpu(orig_ist, cpu);
14198
14199 #ifdef CONFIG_NUMA
14200 @@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14201 switch_to_new_gdt(cpu);
14202 loadsegment(fs, 0);
14203
14204 - load_idt((const struct desc_ptr *)&idt_descr);
14205 + load_idt(&idt_descr);
14206
14207 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14208 syscall_init();
14209 @@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14210 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14211 barrier();
14212
14213 - x86_configure_nx();
14214 if (cpu != 0)
14215 enable_x2apic();
14216
14217 @@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14218 {
14219 int cpu = smp_processor_id();
14220 struct task_struct *curr = current;
14221 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14222 + struct tss_struct *t = init_tss + cpu;
14223 struct thread_struct *thread = &curr->thread;
14224
14225 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14226 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14227 index 3e6ff6c..54b4992 100644
14228 --- a/arch/x86/kernel/cpu/intel.c
14229 +++ b/arch/x86/kernel/cpu/intel.c
14230 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14231 * Update the IDT descriptor and reload the IDT so that
14232 * it uses the read-only mapped virtual address.
14233 */
14234 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14235 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14236 load_idt(&idt_descr);
14237 }
14238 #endif
14239 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14240 index c46ed49..5dc0a53 100644
14241 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14242 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14243 @@ -42,6 +42,7 @@
14244 #include <asm/processor.h>
14245 #include <asm/mce.h>
14246 #include <asm/msr.h>
14247 +#include <asm/local.h>
14248
14249 #include "mce-internal.h"
14250
14251 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14252 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14253 m->cs, m->ip);
14254
14255 - if (m->cs == __KERNEL_CS)
14256 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14257 print_symbol("{%s}", m->ip);
14258 pr_cont("\n");
14259 }
14260 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14261
14262 #define PANIC_TIMEOUT 5 /* 5 seconds */
14263
14264 -static atomic_t mce_paniced;
14265 +static atomic_unchecked_t mce_paniced;
14266
14267 static int fake_panic;
14268 -static atomic_t mce_fake_paniced;
14269 +static atomic_unchecked_t mce_fake_paniced;
14270
14271 /* Panic in progress. Enable interrupts and wait for final IPI */
14272 static void wait_for_panic(void)
14273 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14274 /*
14275 * Make sure only one CPU runs in machine check panic
14276 */
14277 - if (atomic_inc_return(&mce_paniced) > 1)
14278 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14279 wait_for_panic();
14280 barrier();
14281
14282 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14283 console_verbose();
14284 } else {
14285 /* Don't log too much for fake panic */
14286 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14287 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14288 return;
14289 }
14290 /* First print corrected ones that are still unlogged */
14291 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14292 * might have been modified by someone else.
14293 */
14294 rmb();
14295 - if (atomic_read(&mce_paniced))
14296 + if (atomic_read_unchecked(&mce_paniced))
14297 wait_for_panic();
14298 if (!monarch_timeout)
14299 goto out;
14300 @@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14301 }
14302
14303 /* Call the installed machine check handler for this CPU setup. */
14304 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14305 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14306 unexpected_machine_check;
14307
14308 /*
14309 @@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14310 return;
14311 }
14312
14313 + pax_open_kernel();
14314 machine_check_vector = do_machine_check;
14315 + pax_close_kernel();
14316
14317 __mcheck_cpu_init_generic();
14318 __mcheck_cpu_init_vendor(c);
14319 @@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14320 */
14321
14322 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14323 -static int mce_chrdev_open_count; /* #times opened */
14324 +static local_t mce_chrdev_open_count; /* #times opened */
14325 static int mce_chrdev_open_exclu; /* already open exclusive? */
14326
14327 static int mce_chrdev_open(struct inode *inode, struct file *file)
14328 @@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14329 spin_lock(&mce_chrdev_state_lock);
14330
14331 if (mce_chrdev_open_exclu ||
14332 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14333 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14334 spin_unlock(&mce_chrdev_state_lock);
14335
14336 return -EBUSY;
14337 @@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14338
14339 if (file->f_flags & O_EXCL)
14340 mce_chrdev_open_exclu = 1;
14341 - mce_chrdev_open_count++;
14342 + local_inc(&mce_chrdev_open_count);
14343
14344 spin_unlock(&mce_chrdev_state_lock);
14345
14346 @@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14347 {
14348 spin_lock(&mce_chrdev_state_lock);
14349
14350 - mce_chrdev_open_count--;
14351 + local_dec(&mce_chrdev_open_count);
14352 mce_chrdev_open_exclu = 0;
14353
14354 spin_unlock(&mce_chrdev_state_lock);
14355 @@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14356 static void mce_reset(void)
14357 {
14358 cpu_missing = 0;
14359 - atomic_set(&mce_fake_paniced, 0);
14360 + atomic_set_unchecked(&mce_fake_paniced, 0);
14361 atomic_set(&mce_executing, 0);
14362 atomic_set(&mce_callin, 0);
14363 atomic_set(&global_nwo, 0);
14364 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14365 index 2d5454c..51987eb 100644
14366 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14367 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14368 @@ -11,6 +11,7 @@
14369 #include <asm/processor.h>
14370 #include <asm/mce.h>
14371 #include <asm/msr.h>
14372 +#include <asm/pgtable.h>
14373
14374 /* By default disabled */
14375 int mce_p5_enabled __read_mostly;
14376 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14377 if (!cpu_has(c, X86_FEATURE_MCE))
14378 return;
14379
14380 + pax_open_kernel();
14381 machine_check_vector = pentium_machine_check;
14382 + pax_close_kernel();
14383 /* Make sure the vector pointer is visible before we enable MCEs: */
14384 wmb();
14385
14386 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14387 index 2d7998f..17c9de1 100644
14388 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14389 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14390 @@ -10,6 +10,7 @@
14391 #include <asm/processor.h>
14392 #include <asm/mce.h>
14393 #include <asm/msr.h>
14394 +#include <asm/pgtable.h>
14395
14396 /* Machine check handler for WinChip C6: */
14397 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14398 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14399 {
14400 u32 lo, hi;
14401
14402 + pax_open_kernel();
14403 machine_check_vector = winchip_machine_check;
14404 + pax_close_kernel();
14405 /* Make sure the vector pointer is visible before we enable MCEs: */
14406 wmb();
14407
14408 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14409 index 6b96110..0da73eb 100644
14410 --- a/arch/x86/kernel/cpu/mtrr/main.c
14411 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14412 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14413 u64 size_or_mask, size_and_mask;
14414 static bool mtrr_aps_delayed_init;
14415
14416 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14417 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14418
14419 const struct mtrr_ops *mtrr_if;
14420
14421 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14422 index df5e41f..816c719 100644
14423 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14424 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14425 @@ -25,7 +25,7 @@ struct mtrr_ops {
14426 int (*validate_add_page)(unsigned long base, unsigned long size,
14427 unsigned int type);
14428 int (*have_wrcomb)(void);
14429 -};
14430 +} __do_const;
14431
14432 extern int generic_get_free_region(unsigned long base, unsigned long size,
14433 int replace_reg);
14434 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14435 index c4706cf..264b0f7 100644
14436 --- a/arch/x86/kernel/cpu/perf_event.c
14437 +++ b/arch/x86/kernel/cpu/perf_event.c
14438 @@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14439 break;
14440
14441 perf_callchain_store(entry, frame.return_address);
14442 - fp = frame.next_frame;
14443 + fp = (const void __force_user *)frame.next_frame;
14444 }
14445 }
14446
14447 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14448 index 13ad899..f642b9a 100644
14449 --- a/arch/x86/kernel/crash.c
14450 +++ b/arch/x86/kernel/crash.c
14451 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14452 {
14453 #ifdef CONFIG_X86_32
14454 struct pt_regs fixed_regs;
14455 -#endif
14456
14457 -#ifdef CONFIG_X86_32
14458 - if (!user_mode_vm(regs)) {
14459 + if (!user_mode(regs)) {
14460 crash_fixup_ss_esp(&fixed_regs, regs);
14461 regs = &fixed_regs;
14462 }
14463 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14464 index 37250fe..bf2ec74 100644
14465 --- a/arch/x86/kernel/doublefault_32.c
14466 +++ b/arch/x86/kernel/doublefault_32.c
14467 @@ -11,7 +11,7 @@
14468
14469 #define DOUBLEFAULT_STACKSIZE (1024)
14470 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14471 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14472 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14473
14474 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14475
14476 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14477 unsigned long gdt, tss;
14478
14479 store_gdt(&gdt_desc);
14480 - gdt = gdt_desc.address;
14481 + gdt = (unsigned long)gdt_desc.address;
14482
14483 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14484
14485 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14486 /* 0x2 bit is always set */
14487 .flags = X86_EFLAGS_SF | 0x2,
14488 .sp = STACK_START,
14489 - .es = __USER_DS,
14490 + .es = __KERNEL_DS,
14491 .cs = __KERNEL_CS,
14492 .ss = __KERNEL_DS,
14493 - .ds = __USER_DS,
14494 + .ds = __KERNEL_DS,
14495 .fs = __KERNEL_PERCPU,
14496
14497 .__cr3 = __pa_nodebug(swapper_pg_dir),
14498 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14499 index 571246d..81f335c 100644
14500 --- a/arch/x86/kernel/dumpstack.c
14501 +++ b/arch/x86/kernel/dumpstack.c
14502 @@ -2,6 +2,9 @@
14503 * Copyright (C) 1991, 1992 Linus Torvalds
14504 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14505 */
14506 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14507 +#define __INCLUDED_BY_HIDESYM 1
14508 +#endif
14509 #include <linux/kallsyms.h>
14510 #include <linux/kprobes.h>
14511 #include <linux/uaccess.h>
14512 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14513 static void
14514 print_ftrace_graph_addr(unsigned long addr, void *data,
14515 const struct stacktrace_ops *ops,
14516 - struct thread_info *tinfo, int *graph)
14517 + struct task_struct *task, int *graph)
14518 {
14519 - struct task_struct *task;
14520 unsigned long ret_addr;
14521 int index;
14522
14523 if (addr != (unsigned long)return_to_handler)
14524 return;
14525
14526 - task = tinfo->task;
14527 index = task->curr_ret_stack;
14528
14529 if (!task->ret_stack || index < *graph)
14530 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14531 static inline void
14532 print_ftrace_graph_addr(unsigned long addr, void *data,
14533 const struct stacktrace_ops *ops,
14534 - struct thread_info *tinfo, int *graph)
14535 + struct task_struct *task, int *graph)
14536 { }
14537 #endif
14538
14539 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14540 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14541 */
14542
14543 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14544 - void *p, unsigned int size, void *end)
14545 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14546 {
14547 - void *t = tinfo;
14548 if (end) {
14549 if (p < end && p >= (end-THREAD_SIZE))
14550 return 1;
14551 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14552 }
14553
14554 unsigned long
14555 -print_context_stack(struct thread_info *tinfo,
14556 +print_context_stack(struct task_struct *task, void *stack_start,
14557 unsigned long *stack, unsigned long bp,
14558 const struct stacktrace_ops *ops, void *data,
14559 unsigned long *end, int *graph)
14560 {
14561 struct stack_frame *frame = (struct stack_frame *)bp;
14562
14563 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14564 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14565 unsigned long addr;
14566
14567 addr = *stack;
14568 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14569 } else {
14570 ops->address(data, addr, 0);
14571 }
14572 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14573 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14574 }
14575 stack++;
14576 }
14577 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14578 EXPORT_SYMBOL_GPL(print_context_stack);
14579
14580 unsigned long
14581 -print_context_stack_bp(struct thread_info *tinfo,
14582 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14583 unsigned long *stack, unsigned long bp,
14584 const struct stacktrace_ops *ops, void *data,
14585 unsigned long *end, int *graph)
14586 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14587 struct stack_frame *frame = (struct stack_frame *)bp;
14588 unsigned long *ret_addr = &frame->return_address;
14589
14590 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14591 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14592 unsigned long addr = *ret_addr;
14593
14594 if (!__kernel_text_address(addr))
14595 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14596 ops->address(data, addr, 1);
14597 frame = frame->next_frame;
14598 ret_addr = &frame->return_address;
14599 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14600 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14601 }
14602
14603 return (unsigned long)frame;
14604 @@ -189,7 +188,7 @@ void dump_stack(void)
14605
14606 bp = stack_frame(current, NULL);
14607 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14608 - current->pid, current->comm, print_tainted(),
14609 + task_pid_nr(current), current->comm, print_tainted(),
14610 init_utsname()->release,
14611 (int)strcspn(init_utsname()->version, " "),
14612 init_utsname()->version);
14613 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14614 }
14615 EXPORT_SYMBOL_GPL(oops_begin);
14616
14617 +extern void gr_handle_kernel_exploit(void);
14618 +
14619 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14620 {
14621 if (regs && kexec_should_crash(current))
14622 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14623 panic("Fatal exception in interrupt");
14624 if (panic_on_oops)
14625 panic("Fatal exception");
14626 - do_exit(signr);
14627 +
14628 + gr_handle_kernel_exploit();
14629 +
14630 + do_group_exit(signr);
14631 }
14632
14633 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14634 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14635
14636 show_regs(regs);
14637 #ifdef CONFIG_X86_32
14638 - if (user_mode_vm(regs)) {
14639 + if (user_mode(regs)) {
14640 sp = regs->sp;
14641 ss = regs->ss & 0xffff;
14642 } else {
14643 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14644 unsigned long flags = oops_begin();
14645 int sig = SIGSEGV;
14646
14647 - if (!user_mode_vm(regs))
14648 + if (!user_mode(regs))
14649 report_bug(regs->ip, regs);
14650
14651 if (__die(str, regs, err))
14652 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14653 index e0b1d78..a8ade5e 100644
14654 --- a/arch/x86/kernel/dumpstack_32.c
14655 +++ b/arch/x86/kernel/dumpstack_32.c
14656 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14657 bp = stack_frame(task, regs);
14658
14659 for (;;) {
14660 - struct thread_info *context;
14661 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14662
14663 - context = (struct thread_info *)
14664 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14665 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14666 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14667
14668 - stack = (unsigned long *)context->previous_esp;
14669 - if (!stack)
14670 + if (stack_start == task_stack_page(task))
14671 break;
14672 + stack = *(unsigned long **)stack_start;
14673 if (ops->stack(data, "IRQ") < 0)
14674 break;
14675 touch_nmi_watchdog();
14676 @@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14677 int i;
14678
14679 print_modules();
14680 - __show_regs(regs, !user_mode_vm(regs));
14681 + __show_regs(regs, !user_mode(regs));
14682
14683 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14684 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14685 @@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14686 * When in-kernel, we also print out the stack and code at the
14687 * time of the fault..
14688 */
14689 - if (!user_mode_vm(regs)) {
14690 + if (!user_mode(regs)) {
14691 unsigned int code_prologue = code_bytes * 43 / 64;
14692 unsigned int code_len = code_bytes;
14693 unsigned char c;
14694 u8 *ip;
14695 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14696
14697 printk(KERN_EMERG "Stack:\n");
14698 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14699
14700 printk(KERN_EMERG "Code: ");
14701
14702 - ip = (u8 *)regs->ip - code_prologue;
14703 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14704 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14705 /* try starting at IP */
14706 - ip = (u8 *)regs->ip;
14707 + ip = (u8 *)regs->ip + cs_base;
14708 code_len = code_len - code_prologue + 1;
14709 }
14710 for (i = 0; i < code_len; i++, ip++) {
14711 @@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14712 printk(KERN_CONT " Bad EIP value.");
14713 break;
14714 }
14715 - if (ip == (u8 *)regs->ip)
14716 + if (ip == (u8 *)regs->ip + cs_base)
14717 printk(KERN_CONT "<%02x> ", c);
14718 else
14719 printk(KERN_CONT "%02x ", c);
14720 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14721 {
14722 unsigned short ud2;
14723
14724 + ip = ktla_ktva(ip);
14725 if (ip < PAGE_OFFSET)
14726 return 0;
14727 if (probe_kernel_address((unsigned short *)ip, ud2))
14728 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14729
14730 return ud2 == 0x0b0f;
14731 }
14732 +
14733 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14734 +void pax_check_alloca(unsigned long size)
14735 +{
14736 + unsigned long sp = (unsigned long)&sp, stack_left;
14737 +
14738 + /* all kernel stacks are of the same size */
14739 + stack_left = sp & (THREAD_SIZE - 1);
14740 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14741 +}
14742 +EXPORT_SYMBOL(pax_check_alloca);
14743 +#endif
14744 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14745 index 791b761..2ab6e33 100644
14746 --- a/arch/x86/kernel/dumpstack_64.c
14747 +++ b/arch/x86/kernel/dumpstack_64.c
14748 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14749 unsigned long *irq_stack_end =
14750 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14751 unsigned used = 0;
14752 - struct thread_info *tinfo;
14753 int graph = 0;
14754 unsigned long dummy;
14755 + void *stack_start;
14756
14757 if (!task)
14758 task = current;
14759 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14760 * current stack address. If the stacks consist of nested
14761 * exceptions
14762 */
14763 - tinfo = task_thread_info(task);
14764 for (;;) {
14765 char *id;
14766 unsigned long *estack_end;
14767 +
14768 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14769 &used, &id);
14770
14771 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14772 if (ops->stack(data, id) < 0)
14773 break;
14774
14775 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14776 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14777 data, estack_end, &graph);
14778 ops->stack(data, "<EOE>");
14779 /*
14780 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14781 * second-to-last pointer (index -2 to end) in the
14782 * exception stack:
14783 */
14784 + if ((u16)estack_end[-1] != __KERNEL_DS)
14785 + goto out;
14786 stack = (unsigned long *) estack_end[-2];
14787 continue;
14788 }
14789 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14790 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14791 if (ops->stack(data, "IRQ") < 0)
14792 break;
14793 - bp = ops->walk_stack(tinfo, stack, bp,
14794 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14795 ops, data, irq_stack_end, &graph);
14796 /*
14797 * We link to the next stack (which would be
14798 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14799 /*
14800 * This handles the process stack:
14801 */
14802 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14803 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14804 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14805 +out:
14806 put_cpu();
14807 }
14808 EXPORT_SYMBOL(dump_trace);
14809 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14810
14811 return ud2 == 0x0b0f;
14812 }
14813 +
14814 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14815 +void pax_check_alloca(unsigned long size)
14816 +{
14817 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14818 + unsigned cpu, used;
14819 + char *id;
14820 +
14821 + /* check the process stack first */
14822 + stack_start = (unsigned long)task_stack_page(current);
14823 + stack_end = stack_start + THREAD_SIZE;
14824 + if (likely(stack_start <= sp && sp < stack_end)) {
14825 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14826 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14827 + return;
14828 + }
14829 +
14830 + cpu = get_cpu();
14831 +
14832 + /* check the irq stacks */
14833 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14834 + stack_start = stack_end - IRQ_STACK_SIZE;
14835 + if (stack_start <= sp && sp < stack_end) {
14836 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14837 + put_cpu();
14838 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14839 + return;
14840 + }
14841 +
14842 + /* check the exception stacks */
14843 + used = 0;
14844 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14845 + stack_start = stack_end - EXCEPTION_STKSZ;
14846 + if (stack_end && stack_start <= sp && sp < stack_end) {
14847 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14848 + put_cpu();
14849 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14850 + return;
14851 + }
14852 +
14853 + put_cpu();
14854 +
14855 + /* unknown stack */
14856 + BUG();
14857 +}
14858 +EXPORT_SYMBOL(pax_check_alloca);
14859 +#endif
14860 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14861 index 9b9f18b..9fcaa04 100644
14862 --- a/arch/x86/kernel/early_printk.c
14863 +++ b/arch/x86/kernel/early_printk.c
14864 @@ -7,6 +7,7 @@
14865 #include <linux/pci_regs.h>
14866 #include <linux/pci_ids.h>
14867 #include <linux/errno.h>
14868 +#include <linux/sched.h>
14869 #include <asm/io.h>
14870 #include <asm/processor.h>
14871 #include <asm/fcntl.h>
14872 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14873 index 623f288..8bdd78a 100644
14874 --- a/arch/x86/kernel/entry_32.S
14875 +++ b/arch/x86/kernel/entry_32.S
14876 @@ -176,13 +176,153 @@
14877 /*CFI_REL_OFFSET gs, PT_GS*/
14878 .endm
14879 .macro SET_KERNEL_GS reg
14880 +
14881 +#ifdef CONFIG_CC_STACKPROTECTOR
14882 movl $(__KERNEL_STACK_CANARY), \reg
14883 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14884 + movl $(__USER_DS), \reg
14885 +#else
14886 + xorl \reg, \reg
14887 +#endif
14888 +
14889 movl \reg, %gs
14890 .endm
14891
14892 #endif /* CONFIG_X86_32_LAZY_GS */
14893
14894 -.macro SAVE_ALL
14895 +.macro pax_enter_kernel
14896 +#ifdef CONFIG_PAX_KERNEXEC
14897 + call pax_enter_kernel
14898 +#endif
14899 +.endm
14900 +
14901 +.macro pax_exit_kernel
14902 +#ifdef CONFIG_PAX_KERNEXEC
14903 + call pax_exit_kernel
14904 +#endif
14905 +.endm
14906 +
14907 +#ifdef CONFIG_PAX_KERNEXEC
14908 +ENTRY(pax_enter_kernel)
14909 +#ifdef CONFIG_PARAVIRT
14910 + pushl %eax
14911 + pushl %ecx
14912 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14913 + mov %eax, %esi
14914 +#else
14915 + mov %cr0, %esi
14916 +#endif
14917 + bts $16, %esi
14918 + jnc 1f
14919 + mov %cs, %esi
14920 + cmp $__KERNEL_CS, %esi
14921 + jz 3f
14922 + ljmp $__KERNEL_CS, $3f
14923 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14924 +2:
14925 +#ifdef CONFIG_PARAVIRT
14926 + mov %esi, %eax
14927 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14928 +#else
14929 + mov %esi, %cr0
14930 +#endif
14931 +3:
14932 +#ifdef CONFIG_PARAVIRT
14933 + popl %ecx
14934 + popl %eax
14935 +#endif
14936 + ret
14937 +ENDPROC(pax_enter_kernel)
14938 +
14939 +ENTRY(pax_exit_kernel)
14940 +#ifdef CONFIG_PARAVIRT
14941 + pushl %eax
14942 + pushl %ecx
14943 +#endif
14944 + mov %cs, %esi
14945 + cmp $__KERNEXEC_KERNEL_CS, %esi
14946 + jnz 2f
14947 +#ifdef CONFIG_PARAVIRT
14948 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14949 + mov %eax, %esi
14950 +#else
14951 + mov %cr0, %esi
14952 +#endif
14953 + btr $16, %esi
14954 + ljmp $__KERNEL_CS, $1f
14955 +1:
14956 +#ifdef CONFIG_PARAVIRT
14957 + mov %esi, %eax
14958 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14959 +#else
14960 + mov %esi, %cr0
14961 +#endif
14962 +2:
14963 +#ifdef CONFIG_PARAVIRT
14964 + popl %ecx
14965 + popl %eax
14966 +#endif
14967 + ret
14968 +ENDPROC(pax_exit_kernel)
14969 +#endif
14970 +
14971 +.macro pax_erase_kstack
14972 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14973 + call pax_erase_kstack
14974 +#endif
14975 +.endm
14976 +
14977 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14978 +/*
14979 + * ebp: thread_info
14980 + */
14981 +ENTRY(pax_erase_kstack)
14982 + pushl %edi
14983 + pushl %ecx
14984 + pushl %eax
14985 +
14986 + mov TI_lowest_stack(%ebp), %edi
14987 + mov $-0xBEEF, %eax
14988 + std
14989 +
14990 +1: mov %edi, %ecx
14991 + and $THREAD_SIZE_asm - 1, %ecx
14992 + shr $2, %ecx
14993 + repne scasl
14994 + jecxz 2f
14995 +
14996 + cmp $2*16, %ecx
14997 + jc 2f
14998 +
14999 + mov $2*16, %ecx
15000 + repe scasl
15001 + jecxz 2f
15002 + jne 1b
15003 +
15004 +2: cld
15005 + mov %esp, %ecx
15006 + sub %edi, %ecx
15007 +
15008 + cmp $THREAD_SIZE_asm, %ecx
15009 + jb 3f
15010 + ud2
15011 +3:
15012 +
15013 + shr $2, %ecx
15014 + rep stosl
15015 +
15016 + mov TI_task_thread_sp0(%ebp), %edi
15017 + sub $128, %edi
15018 + mov %edi, TI_lowest_stack(%ebp)
15019 +
15020 + popl %eax
15021 + popl %ecx
15022 + popl %edi
15023 + ret
15024 +ENDPROC(pax_erase_kstack)
15025 +#endif
15026 +
15027 +.macro __SAVE_ALL _DS
15028 cld
15029 PUSH_GS
15030 pushl_cfi %fs
15031 @@ -205,7 +345,7 @@
15032 CFI_REL_OFFSET ecx, 0
15033 pushl_cfi %ebx
15034 CFI_REL_OFFSET ebx, 0
15035 - movl $(__USER_DS), %edx
15036 + movl $\_DS, %edx
15037 movl %edx, %ds
15038 movl %edx, %es
15039 movl $(__KERNEL_PERCPU), %edx
15040 @@ -213,6 +353,15 @@
15041 SET_KERNEL_GS %edx
15042 .endm
15043
15044 +.macro SAVE_ALL
15045 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15046 + __SAVE_ALL __KERNEL_DS
15047 + pax_enter_kernel
15048 +#else
15049 + __SAVE_ALL __USER_DS
15050 +#endif
15051 +.endm
15052 +
15053 .macro RESTORE_INT_REGS
15054 popl_cfi %ebx
15055 CFI_RESTORE ebx
15056 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15057 popfl_cfi
15058 jmp syscall_exit
15059 CFI_ENDPROC
15060 -END(ret_from_fork)
15061 +ENDPROC(ret_from_fork)
15062
15063 /*
15064 * Interrupt exit functions should be protected against kprobes
15065 @@ -329,7 +478,15 @@ ret_from_intr:
15066 andl $SEGMENT_RPL_MASK, %eax
15067 #endif
15068 cmpl $USER_RPL, %eax
15069 +
15070 +#ifdef CONFIG_PAX_KERNEXEC
15071 + jae resume_userspace
15072 +
15073 + pax_exit_kernel
15074 + jmp resume_kernel
15075 +#else
15076 jb resume_kernel # not returning to v8086 or userspace
15077 +#endif
15078
15079 ENTRY(resume_userspace)
15080 LOCKDEP_SYS_EXIT
15081 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15082 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15083 # int/exception return?
15084 jne work_pending
15085 - jmp restore_all
15086 -END(ret_from_exception)
15087 + jmp restore_all_pax
15088 +ENDPROC(ret_from_exception)
15089
15090 #ifdef CONFIG_PREEMPT
15091 ENTRY(resume_kernel)
15092 @@ -357,7 +514,7 @@ need_resched:
15093 jz restore_all
15094 call preempt_schedule_irq
15095 jmp need_resched
15096 -END(resume_kernel)
15097 +ENDPROC(resume_kernel)
15098 #endif
15099 CFI_ENDPROC
15100 /*
15101 @@ -391,28 +548,43 @@ sysenter_past_esp:
15102 /*CFI_REL_OFFSET cs, 0*/
15103 /*
15104 * Push current_thread_info()->sysenter_return to the stack.
15105 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15106 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15107 */
15108 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15109 + pushl_cfi $0
15110 CFI_REL_OFFSET eip, 0
15111
15112 pushl_cfi %eax
15113 SAVE_ALL
15114 + GET_THREAD_INFO(%ebp)
15115 + movl TI_sysenter_return(%ebp),%ebp
15116 + movl %ebp,PT_EIP(%esp)
15117 ENABLE_INTERRUPTS(CLBR_NONE)
15118
15119 /*
15120 * Load the potential sixth argument from user stack.
15121 * Careful about security.
15122 */
15123 + movl PT_OLDESP(%esp),%ebp
15124 +
15125 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15126 + mov PT_OLDSS(%esp),%ds
15127 +1: movl %ds:(%ebp),%ebp
15128 + push %ss
15129 + pop %ds
15130 +#else
15131 cmpl $__PAGE_OFFSET-3,%ebp
15132 jae syscall_fault
15133 1: movl (%ebp),%ebp
15134 +#endif
15135 +
15136 movl %ebp,PT_EBP(%esp)
15137 _ASM_EXTABLE(1b,syscall_fault)
15138
15139 GET_THREAD_INFO(%ebp)
15140
15141 +#ifdef CONFIG_PAX_RANDKSTACK
15142 + pax_erase_kstack
15143 +#endif
15144 +
15145 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15146 jnz sysenter_audit
15147 sysenter_do_call:
15148 @@ -427,12 +599,24 @@ sysenter_do_call:
15149 testl $_TIF_ALLWORK_MASK, %ecx
15150 jne sysexit_audit
15151 sysenter_exit:
15152 +
15153 +#ifdef CONFIG_PAX_RANDKSTACK
15154 + pushl_cfi %eax
15155 + movl %esp, %eax
15156 + call pax_randomize_kstack
15157 + popl_cfi %eax
15158 +#endif
15159 +
15160 + pax_erase_kstack
15161 +
15162 /* if something modifies registers it must also disable sysexit */
15163 movl PT_EIP(%esp), %edx
15164 movl PT_OLDESP(%esp), %ecx
15165 xorl %ebp,%ebp
15166 TRACE_IRQS_ON
15167 1: mov PT_FS(%esp), %fs
15168 +2: mov PT_DS(%esp), %ds
15169 +3: mov PT_ES(%esp), %es
15170 PTGS_TO_GS
15171 ENABLE_INTERRUPTS_SYSEXIT
15172
15173 @@ -449,6 +633,9 @@ sysenter_audit:
15174 movl %eax,%edx /* 2nd arg: syscall number */
15175 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15176 call __audit_syscall_entry
15177 +
15178 + pax_erase_kstack
15179 +
15180 pushl_cfi %ebx
15181 movl PT_EAX(%esp),%eax /* reload syscall number */
15182 jmp sysenter_do_call
15183 @@ -474,10 +661,16 @@ sysexit_audit:
15184
15185 CFI_ENDPROC
15186 .pushsection .fixup,"ax"
15187 -2: movl $0,PT_FS(%esp)
15188 +4: movl $0,PT_FS(%esp)
15189 + jmp 1b
15190 +5: movl $0,PT_DS(%esp)
15191 + jmp 1b
15192 +6: movl $0,PT_ES(%esp)
15193 jmp 1b
15194 .popsection
15195 - _ASM_EXTABLE(1b,2b)
15196 + _ASM_EXTABLE(1b,4b)
15197 + _ASM_EXTABLE(2b,5b)
15198 + _ASM_EXTABLE(3b,6b)
15199 PTGS_TO_GS_EX
15200 ENDPROC(ia32_sysenter_target)
15201
15202 @@ -491,6 +684,11 @@ ENTRY(system_call)
15203 pushl_cfi %eax # save orig_eax
15204 SAVE_ALL
15205 GET_THREAD_INFO(%ebp)
15206 +
15207 +#ifdef CONFIG_PAX_RANDKSTACK
15208 + pax_erase_kstack
15209 +#endif
15210 +
15211 # system call tracing in operation / emulation
15212 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15213 jnz syscall_trace_entry
15214 @@ -509,6 +707,15 @@ syscall_exit:
15215 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15216 jne syscall_exit_work
15217
15218 +restore_all_pax:
15219 +
15220 +#ifdef CONFIG_PAX_RANDKSTACK
15221 + movl %esp, %eax
15222 + call pax_randomize_kstack
15223 +#endif
15224 +
15225 + pax_erase_kstack
15226 +
15227 restore_all:
15228 TRACE_IRQS_IRET
15229 restore_all_notrace:
15230 @@ -565,14 +772,34 @@ ldt_ss:
15231 * compensating for the offset by changing to the ESPFIX segment with
15232 * a base address that matches for the difference.
15233 */
15234 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15235 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15236 mov %esp, %edx /* load kernel esp */
15237 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15238 mov %dx, %ax /* eax: new kernel esp */
15239 sub %eax, %edx /* offset (low word is 0) */
15240 +#ifdef CONFIG_SMP
15241 + movl PER_CPU_VAR(cpu_number), %ebx
15242 + shll $PAGE_SHIFT_asm, %ebx
15243 + addl $cpu_gdt_table, %ebx
15244 +#else
15245 + movl $cpu_gdt_table, %ebx
15246 +#endif
15247 shr $16, %edx
15248 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15249 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15250 +
15251 +#ifdef CONFIG_PAX_KERNEXEC
15252 + mov %cr0, %esi
15253 + btr $16, %esi
15254 + mov %esi, %cr0
15255 +#endif
15256 +
15257 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15258 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15259 +
15260 +#ifdef CONFIG_PAX_KERNEXEC
15261 + bts $16, %esi
15262 + mov %esi, %cr0
15263 +#endif
15264 +
15265 pushl_cfi $__ESPFIX_SS
15266 pushl_cfi %eax /* new kernel esp */
15267 /* Disable interrupts, but do not irqtrace this section: we
15268 @@ -601,35 +828,23 @@ work_resched:
15269 movl TI_flags(%ebp), %ecx
15270 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15271 # than syscall tracing?
15272 - jz restore_all
15273 + jz restore_all_pax
15274 testb $_TIF_NEED_RESCHED, %cl
15275 jnz work_resched
15276
15277 work_notifysig: # deal with pending signals and
15278 # notify-resume requests
15279 + movl %esp, %eax
15280 #ifdef CONFIG_VM86
15281 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15282 - movl %esp, %eax
15283 - jne work_notifysig_v86 # returning to kernel-space or
15284 + jz 1f # returning to kernel-space or
15285 # vm86-space
15286 - TRACE_IRQS_ON
15287 - ENABLE_INTERRUPTS(CLBR_NONE)
15288 - movb PT_CS(%esp), %bl
15289 - andb $SEGMENT_RPL_MASK, %bl
15290 - cmpb $USER_RPL, %bl
15291 - jb resume_kernel
15292 - xorl %edx, %edx
15293 - call do_notify_resume
15294 - jmp resume_userspace
15295
15296 - ALIGN
15297 -work_notifysig_v86:
15298 pushl_cfi %ecx # save ti_flags for do_notify_resume
15299 call save_v86_state # %eax contains pt_regs pointer
15300 popl_cfi %ecx
15301 movl %eax, %esp
15302 -#else
15303 - movl %esp, %eax
15304 +1:
15305 #endif
15306 TRACE_IRQS_ON
15307 ENABLE_INTERRUPTS(CLBR_NONE)
15308 @@ -640,7 +855,7 @@ work_notifysig_v86:
15309 xorl %edx, %edx
15310 call do_notify_resume
15311 jmp resume_userspace
15312 -END(work_pending)
15313 +ENDPROC(work_pending)
15314
15315 # perform syscall exit tracing
15316 ALIGN
15317 @@ -648,11 +863,14 @@ syscall_trace_entry:
15318 movl $-ENOSYS,PT_EAX(%esp)
15319 movl %esp, %eax
15320 call syscall_trace_enter
15321 +
15322 + pax_erase_kstack
15323 +
15324 /* What it returned is what we'll actually use. */
15325 cmpl $(NR_syscalls), %eax
15326 jnae syscall_call
15327 jmp syscall_exit
15328 -END(syscall_trace_entry)
15329 +ENDPROC(syscall_trace_entry)
15330
15331 # perform syscall exit tracing
15332 ALIGN
15333 @@ -665,20 +883,24 @@ syscall_exit_work:
15334 movl %esp, %eax
15335 call syscall_trace_leave
15336 jmp resume_userspace
15337 -END(syscall_exit_work)
15338 +ENDPROC(syscall_exit_work)
15339 CFI_ENDPROC
15340
15341 RING0_INT_FRAME # can't unwind into user space anyway
15342 syscall_fault:
15343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15344 + push %ss
15345 + pop %ds
15346 +#endif
15347 GET_THREAD_INFO(%ebp)
15348 movl $-EFAULT,PT_EAX(%esp)
15349 jmp resume_userspace
15350 -END(syscall_fault)
15351 +ENDPROC(syscall_fault)
15352
15353 syscall_badsys:
15354 movl $-ENOSYS,PT_EAX(%esp)
15355 jmp resume_userspace
15356 -END(syscall_badsys)
15357 +ENDPROC(syscall_badsys)
15358 CFI_ENDPROC
15359 /*
15360 * End of kprobes section
15361 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15362 CFI_ENDPROC
15363 ENDPROC(ptregs_clone)
15364
15365 + ALIGN;
15366 +ENTRY(kernel_execve)
15367 + CFI_STARTPROC
15368 + pushl_cfi %ebp
15369 + sub $PT_OLDSS+4,%esp
15370 + pushl_cfi %edi
15371 + pushl_cfi %ecx
15372 + pushl_cfi %eax
15373 + lea 3*4(%esp),%edi
15374 + mov $PT_OLDSS/4+1,%ecx
15375 + xorl %eax,%eax
15376 + rep stosl
15377 + popl_cfi %eax
15378 + popl_cfi %ecx
15379 + popl_cfi %edi
15380 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15381 + pushl_cfi %esp
15382 + call sys_execve
15383 + add $4,%esp
15384 + CFI_ADJUST_CFA_OFFSET -4
15385 + GET_THREAD_INFO(%ebp)
15386 + test %eax,%eax
15387 + jz syscall_exit
15388 + add $PT_OLDSS+4,%esp
15389 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15390 + popl_cfi %ebp
15391 + ret
15392 + CFI_ENDPROC
15393 +ENDPROC(kernel_execve)
15394 +
15395 .macro FIXUP_ESPFIX_STACK
15396 /*
15397 * Switch back for ESPFIX stack to the normal zerobased stack
15398 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15399 * normal stack and adjusts ESP with the matching offset.
15400 */
15401 /* fixup the stack */
15402 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15403 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15404 +#ifdef CONFIG_SMP
15405 + movl PER_CPU_VAR(cpu_number), %ebx
15406 + shll $PAGE_SHIFT_asm, %ebx
15407 + addl $cpu_gdt_table, %ebx
15408 +#else
15409 + movl $cpu_gdt_table, %ebx
15410 +#endif
15411 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15412 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15413 shl $16, %eax
15414 addl %esp, %eax /* the adjusted stack pointer */
15415 pushl_cfi $__KERNEL_DS
15416 @@ -813,7 +1072,7 @@ vector=vector+1
15417 .endr
15418 2: jmp common_interrupt
15419 .endr
15420 -END(irq_entries_start)
15421 +ENDPROC(irq_entries_start)
15422
15423 .previous
15424 END(interrupt)
15425 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15426 pushl_cfi $do_coprocessor_error
15427 jmp error_code
15428 CFI_ENDPROC
15429 -END(coprocessor_error)
15430 +ENDPROC(coprocessor_error)
15431
15432 ENTRY(simd_coprocessor_error)
15433 RING0_INT_FRAME
15434 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15435 #endif
15436 jmp error_code
15437 CFI_ENDPROC
15438 -END(simd_coprocessor_error)
15439 +ENDPROC(simd_coprocessor_error)
15440
15441 ENTRY(device_not_available)
15442 RING0_INT_FRAME
15443 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15444 pushl_cfi $do_device_not_available
15445 jmp error_code
15446 CFI_ENDPROC
15447 -END(device_not_available)
15448 +ENDPROC(device_not_available)
15449
15450 #ifdef CONFIG_PARAVIRT
15451 ENTRY(native_iret)
15452 iret
15453 _ASM_EXTABLE(native_iret, iret_exc)
15454 -END(native_iret)
15455 +ENDPROC(native_iret)
15456
15457 ENTRY(native_irq_enable_sysexit)
15458 sti
15459 sysexit
15460 -END(native_irq_enable_sysexit)
15461 +ENDPROC(native_irq_enable_sysexit)
15462 #endif
15463
15464 ENTRY(overflow)
15465 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15466 pushl_cfi $do_overflow
15467 jmp error_code
15468 CFI_ENDPROC
15469 -END(overflow)
15470 +ENDPROC(overflow)
15471
15472 ENTRY(bounds)
15473 RING0_INT_FRAME
15474 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15475 pushl_cfi $do_bounds
15476 jmp error_code
15477 CFI_ENDPROC
15478 -END(bounds)
15479 +ENDPROC(bounds)
15480
15481 ENTRY(invalid_op)
15482 RING0_INT_FRAME
15483 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15484 pushl_cfi $do_invalid_op
15485 jmp error_code
15486 CFI_ENDPROC
15487 -END(invalid_op)
15488 +ENDPROC(invalid_op)
15489
15490 ENTRY(coprocessor_segment_overrun)
15491 RING0_INT_FRAME
15492 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15493 pushl_cfi $do_coprocessor_segment_overrun
15494 jmp error_code
15495 CFI_ENDPROC
15496 -END(coprocessor_segment_overrun)
15497 +ENDPROC(coprocessor_segment_overrun)
15498
15499 ENTRY(invalid_TSS)
15500 RING0_EC_FRAME
15501 pushl_cfi $do_invalid_TSS
15502 jmp error_code
15503 CFI_ENDPROC
15504 -END(invalid_TSS)
15505 +ENDPROC(invalid_TSS)
15506
15507 ENTRY(segment_not_present)
15508 RING0_EC_FRAME
15509 pushl_cfi $do_segment_not_present
15510 jmp error_code
15511 CFI_ENDPROC
15512 -END(segment_not_present)
15513 +ENDPROC(segment_not_present)
15514
15515 ENTRY(stack_segment)
15516 RING0_EC_FRAME
15517 pushl_cfi $do_stack_segment
15518 jmp error_code
15519 CFI_ENDPROC
15520 -END(stack_segment)
15521 +ENDPROC(stack_segment)
15522
15523 ENTRY(alignment_check)
15524 RING0_EC_FRAME
15525 pushl_cfi $do_alignment_check
15526 jmp error_code
15527 CFI_ENDPROC
15528 -END(alignment_check)
15529 +ENDPROC(alignment_check)
15530
15531 ENTRY(divide_error)
15532 RING0_INT_FRAME
15533 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15534 pushl_cfi $do_divide_error
15535 jmp error_code
15536 CFI_ENDPROC
15537 -END(divide_error)
15538 +ENDPROC(divide_error)
15539
15540 #ifdef CONFIG_X86_MCE
15541 ENTRY(machine_check)
15542 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15543 pushl_cfi machine_check_vector
15544 jmp error_code
15545 CFI_ENDPROC
15546 -END(machine_check)
15547 +ENDPROC(machine_check)
15548 #endif
15549
15550 ENTRY(spurious_interrupt_bug)
15551 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15552 pushl_cfi $do_spurious_interrupt_bug
15553 jmp error_code
15554 CFI_ENDPROC
15555 -END(spurious_interrupt_bug)
15556 +ENDPROC(spurious_interrupt_bug)
15557 /*
15558 * End of kprobes section
15559 */
15560 @@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15561
15562 ENTRY(mcount)
15563 ret
15564 -END(mcount)
15565 +ENDPROC(mcount)
15566
15567 ENTRY(ftrace_caller)
15568 cmpl $0, function_trace_stop
15569 @@ -1129,7 +1388,7 @@ ftrace_graph_call:
15570 .globl ftrace_stub
15571 ftrace_stub:
15572 ret
15573 -END(ftrace_caller)
15574 +ENDPROC(ftrace_caller)
15575
15576 #else /* ! CONFIG_DYNAMIC_FTRACE */
15577
15578 @@ -1165,7 +1424,7 @@ trace:
15579 popl %ecx
15580 popl %eax
15581 jmp ftrace_stub
15582 -END(mcount)
15583 +ENDPROC(mcount)
15584 #endif /* CONFIG_DYNAMIC_FTRACE */
15585 #endif /* CONFIG_FUNCTION_TRACER */
15586
15587 @@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15588 popl %ecx
15589 popl %eax
15590 ret
15591 -END(ftrace_graph_caller)
15592 +ENDPROC(ftrace_graph_caller)
15593
15594 .globl return_to_handler
15595 return_to_handler:
15596 @@ -1241,15 +1500,18 @@ error_code:
15597 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15598 REG_TO_PTGS %ecx
15599 SET_KERNEL_GS %ecx
15600 - movl $(__USER_DS), %ecx
15601 + movl $(__KERNEL_DS), %ecx
15602 movl %ecx, %ds
15603 movl %ecx, %es
15604 +
15605 + pax_enter_kernel
15606 +
15607 TRACE_IRQS_OFF
15608 movl %esp,%eax # pt_regs pointer
15609 call *%edi
15610 jmp ret_from_exception
15611 CFI_ENDPROC
15612 -END(page_fault)
15613 +ENDPROC(page_fault)
15614
15615 /*
15616 * Debug traps and NMI can happen at the one SYSENTER instruction
15617 @@ -1291,7 +1553,7 @@ debug_stack_correct:
15618 call do_debug
15619 jmp ret_from_exception
15620 CFI_ENDPROC
15621 -END(debug)
15622 +ENDPROC(debug)
15623
15624 /*
15625 * NMI is doubly nasty. It can happen _while_ we're handling
15626 @@ -1328,6 +1590,9 @@ nmi_stack_correct:
15627 xorl %edx,%edx # zero error code
15628 movl %esp,%eax # pt_regs pointer
15629 call do_nmi
15630 +
15631 + pax_exit_kernel
15632 +
15633 jmp restore_all_notrace
15634 CFI_ENDPROC
15635
15636 @@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15637 FIXUP_ESPFIX_STACK # %eax == %esp
15638 xorl %edx,%edx # zero error code
15639 call do_nmi
15640 +
15641 + pax_exit_kernel
15642 +
15643 RESTORE_REGS
15644 lss 12+4(%esp), %esp # back to espfix stack
15645 CFI_ADJUST_CFA_OFFSET -24
15646 jmp irq_return
15647 CFI_ENDPROC
15648 -END(nmi)
15649 +ENDPROC(nmi)
15650
15651 ENTRY(int3)
15652 RING0_INT_FRAME
15653 @@ -1381,14 +1649,14 @@ ENTRY(int3)
15654 call do_int3
15655 jmp ret_from_exception
15656 CFI_ENDPROC
15657 -END(int3)
15658 +ENDPROC(int3)
15659
15660 ENTRY(general_protection)
15661 RING0_EC_FRAME
15662 pushl_cfi $do_general_protection
15663 jmp error_code
15664 CFI_ENDPROC
15665 -END(general_protection)
15666 +ENDPROC(general_protection)
15667
15668 #ifdef CONFIG_KVM_GUEST
15669 ENTRY(async_page_fault)
15670 @@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15671 pushl_cfi $do_async_page_fault
15672 jmp error_code
15673 CFI_ENDPROC
15674 -END(async_page_fault)
15675 +ENDPROC(async_page_fault)
15676 #endif
15677
15678 /*
15679 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15680 index 7d65133..c888d5f 100644
15681 --- a/arch/x86/kernel/entry_64.S
15682 +++ b/arch/x86/kernel/entry_64.S
15683 @@ -57,6 +57,8 @@
15684 #include <asm/percpu.h>
15685 #include <asm/asm.h>
15686 #include <linux/err.h>
15687 +#include <asm/pgtable.h>
15688 +#include <asm/alternative-asm.h>
15689
15690 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15691 #include <linux/elf-em.h>
15692 @@ -70,8 +72,9 @@
15693 #ifdef CONFIG_FUNCTION_TRACER
15694 #ifdef CONFIG_DYNAMIC_FTRACE
15695 ENTRY(mcount)
15696 + pax_force_retaddr
15697 retq
15698 -END(mcount)
15699 +ENDPROC(mcount)
15700
15701 ENTRY(ftrace_caller)
15702 cmpl $0, function_trace_stop
15703 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15704 #endif
15705
15706 GLOBAL(ftrace_stub)
15707 + pax_force_retaddr
15708 retq
15709 -END(ftrace_caller)
15710 +ENDPROC(ftrace_caller)
15711
15712 #else /* ! CONFIG_DYNAMIC_FTRACE */
15713 ENTRY(mcount)
15714 @@ -114,6 +118,7 @@ ENTRY(mcount)
15715 #endif
15716
15717 GLOBAL(ftrace_stub)
15718 + pax_force_retaddr
15719 retq
15720
15721 trace:
15722 @@ -123,12 +128,13 @@ trace:
15723 movq 8(%rbp), %rsi
15724 subq $MCOUNT_INSN_SIZE, %rdi
15725
15726 + pax_force_fptr ftrace_trace_function
15727 call *ftrace_trace_function
15728
15729 MCOUNT_RESTORE_FRAME
15730
15731 jmp ftrace_stub
15732 -END(mcount)
15733 +ENDPROC(mcount)
15734 #endif /* CONFIG_DYNAMIC_FTRACE */
15735 #endif /* CONFIG_FUNCTION_TRACER */
15736
15737 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15738
15739 MCOUNT_RESTORE_FRAME
15740
15741 + pax_force_retaddr
15742 retq
15743 -END(ftrace_graph_caller)
15744 +ENDPROC(ftrace_graph_caller)
15745
15746 GLOBAL(return_to_handler)
15747 subq $24, %rsp
15748 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15749 movq 8(%rsp), %rdx
15750 movq (%rsp), %rax
15751 addq $24, %rsp
15752 + pax_force_fptr %rdi
15753 jmp *%rdi
15754 #endif
15755
15756 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15757 ENDPROC(native_usergs_sysret64)
15758 #endif /* CONFIG_PARAVIRT */
15759
15760 + .macro ljmpq sel, off
15761 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15762 + .byte 0x48; ljmp *1234f(%rip)
15763 + .pushsection .rodata
15764 + .align 16
15765 + 1234: .quad \off; .word \sel
15766 + .popsection
15767 +#else
15768 + pushq $\sel
15769 + pushq $\off
15770 + lretq
15771 +#endif
15772 + .endm
15773 +
15774 + .macro pax_enter_kernel
15775 + pax_set_fptr_mask
15776 +#ifdef CONFIG_PAX_KERNEXEC
15777 + call pax_enter_kernel
15778 +#endif
15779 + .endm
15780 +
15781 + .macro pax_exit_kernel
15782 +#ifdef CONFIG_PAX_KERNEXEC
15783 + call pax_exit_kernel
15784 +#endif
15785 + .endm
15786 +
15787 +#ifdef CONFIG_PAX_KERNEXEC
15788 +ENTRY(pax_enter_kernel)
15789 + pushq %rdi
15790 +
15791 +#ifdef CONFIG_PARAVIRT
15792 + PV_SAVE_REGS(CLBR_RDI)
15793 +#endif
15794 +
15795 + GET_CR0_INTO_RDI
15796 + bts $16,%rdi
15797 + jnc 3f
15798 + mov %cs,%edi
15799 + cmp $__KERNEL_CS,%edi
15800 + jnz 2f
15801 +1:
15802 +
15803 +#ifdef CONFIG_PARAVIRT
15804 + PV_RESTORE_REGS(CLBR_RDI)
15805 +#endif
15806 +
15807 + popq %rdi
15808 + pax_force_retaddr
15809 + retq
15810 +
15811 +2: ljmpq __KERNEL_CS,1f
15812 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15813 +4: SET_RDI_INTO_CR0
15814 + jmp 1b
15815 +ENDPROC(pax_enter_kernel)
15816 +
15817 +ENTRY(pax_exit_kernel)
15818 + pushq %rdi
15819 +
15820 +#ifdef CONFIG_PARAVIRT
15821 + PV_SAVE_REGS(CLBR_RDI)
15822 +#endif
15823 +
15824 + mov %cs,%rdi
15825 + cmp $__KERNEXEC_KERNEL_CS,%edi
15826 + jz 2f
15827 +1:
15828 +
15829 +#ifdef CONFIG_PARAVIRT
15830 + PV_RESTORE_REGS(CLBR_RDI);
15831 +#endif
15832 +
15833 + popq %rdi
15834 + pax_force_retaddr
15835 + retq
15836 +
15837 +2: GET_CR0_INTO_RDI
15838 + btr $16,%rdi
15839 + ljmpq __KERNEL_CS,3f
15840 +3: SET_RDI_INTO_CR0
15841 + jmp 1b
15842 +#ifdef CONFIG_PARAVIRT
15843 + PV_RESTORE_REGS(CLBR_RDI);
15844 +#endif
15845 +
15846 + popq %rdi
15847 + pax_force_retaddr
15848 + retq
15849 +ENDPROC(pax_exit_kernel)
15850 +#endif
15851 +
15852 + .macro pax_enter_kernel_user
15853 + pax_set_fptr_mask
15854 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15855 + call pax_enter_kernel_user
15856 +#endif
15857 + .endm
15858 +
15859 + .macro pax_exit_kernel_user
15860 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15861 + call pax_exit_kernel_user
15862 +#endif
15863 +#ifdef CONFIG_PAX_RANDKSTACK
15864 + pushq %rax
15865 + call pax_randomize_kstack
15866 + popq %rax
15867 +#endif
15868 + .endm
15869 +
15870 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15871 +ENTRY(pax_enter_kernel_user)
15872 + pushq %rdi
15873 + pushq %rbx
15874 +
15875 +#ifdef CONFIG_PARAVIRT
15876 + PV_SAVE_REGS(CLBR_RDI)
15877 +#endif
15878 +
15879 + GET_CR3_INTO_RDI
15880 + mov %rdi,%rbx
15881 + add $__START_KERNEL_map,%rbx
15882 + sub phys_base(%rip),%rbx
15883 +
15884 +#ifdef CONFIG_PARAVIRT
15885 + pushq %rdi
15886 + cmpl $0, pv_info+PARAVIRT_enabled
15887 + jz 1f
15888 + i = 0
15889 + .rept USER_PGD_PTRS
15890 + mov i*8(%rbx),%rsi
15891 + mov $0,%sil
15892 + lea i*8(%rbx),%rdi
15893 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15894 + i = i + 1
15895 + .endr
15896 + jmp 2f
15897 +1:
15898 +#endif
15899 +
15900 + i = 0
15901 + .rept USER_PGD_PTRS
15902 + movb $0,i*8(%rbx)
15903 + i = i + 1
15904 + .endr
15905 +
15906 +#ifdef CONFIG_PARAVIRT
15907 +2: popq %rdi
15908 +#endif
15909 + SET_RDI_INTO_CR3
15910 +
15911 +#ifdef CONFIG_PAX_KERNEXEC
15912 + GET_CR0_INTO_RDI
15913 + bts $16,%rdi
15914 + SET_RDI_INTO_CR0
15915 +#endif
15916 +
15917 +#ifdef CONFIG_PARAVIRT
15918 + PV_RESTORE_REGS(CLBR_RDI)
15919 +#endif
15920 +
15921 + popq %rbx
15922 + popq %rdi
15923 + pax_force_retaddr
15924 + retq
15925 +ENDPROC(pax_enter_kernel_user)
15926 +
15927 +ENTRY(pax_exit_kernel_user)
15928 + push %rdi
15929 +
15930 +#ifdef CONFIG_PARAVIRT
15931 + pushq %rbx
15932 + PV_SAVE_REGS(CLBR_RDI)
15933 +#endif
15934 +
15935 +#ifdef CONFIG_PAX_KERNEXEC
15936 + GET_CR0_INTO_RDI
15937 + btr $16,%rdi
15938 + SET_RDI_INTO_CR0
15939 +#endif
15940 +
15941 + GET_CR3_INTO_RDI
15942 + add $__START_KERNEL_map,%rdi
15943 + sub phys_base(%rip),%rdi
15944 +
15945 +#ifdef CONFIG_PARAVIRT
15946 + cmpl $0, pv_info+PARAVIRT_enabled
15947 + jz 1f
15948 + mov %rdi,%rbx
15949 + i = 0
15950 + .rept USER_PGD_PTRS
15951 + mov i*8(%rbx),%rsi
15952 + mov $0x67,%sil
15953 + lea i*8(%rbx),%rdi
15954 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15955 + i = i + 1
15956 + .endr
15957 + jmp 2f
15958 +1:
15959 +#endif
15960 +
15961 + i = 0
15962 + .rept USER_PGD_PTRS
15963 + movb $0x67,i*8(%rdi)
15964 + i = i + 1
15965 + .endr
15966 +
15967 +#ifdef CONFIG_PARAVIRT
15968 +2: PV_RESTORE_REGS(CLBR_RDI)
15969 + popq %rbx
15970 +#endif
15971 +
15972 + popq %rdi
15973 + pax_force_retaddr
15974 + retq
15975 +ENDPROC(pax_exit_kernel_user)
15976 +#endif
15977 +
15978 +.macro pax_erase_kstack
15979 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15980 + call pax_erase_kstack
15981 +#endif
15982 +.endm
15983 +
15984 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15985 +ENTRY(pax_erase_kstack)
15986 + pushq %rdi
15987 + pushq %rcx
15988 + pushq %rax
15989 + pushq %r11
15990 +
15991 + GET_THREAD_INFO(%r11)
15992 + mov TI_lowest_stack(%r11), %rdi
15993 + mov $-0xBEEF, %rax
15994 + std
15995 +
15996 +1: mov %edi, %ecx
15997 + and $THREAD_SIZE_asm - 1, %ecx
15998 + shr $3, %ecx
15999 + repne scasq
16000 + jecxz 2f
16001 +
16002 + cmp $2*8, %ecx
16003 + jc 2f
16004 +
16005 + mov $2*8, %ecx
16006 + repe scasq
16007 + jecxz 2f
16008 + jne 1b
16009 +
16010 +2: cld
16011 + mov %esp, %ecx
16012 + sub %edi, %ecx
16013 +
16014 + cmp $THREAD_SIZE_asm, %rcx
16015 + jb 3f
16016 + ud2
16017 +3:
16018 +
16019 + shr $3, %ecx
16020 + rep stosq
16021 +
16022 + mov TI_task_thread_sp0(%r11), %rdi
16023 + sub $256, %rdi
16024 + mov %rdi, TI_lowest_stack(%r11)
16025 +
16026 + popq %r11
16027 + popq %rax
16028 + popq %rcx
16029 + popq %rdi
16030 + pax_force_retaddr
16031 + ret
16032 +ENDPROC(pax_erase_kstack)
16033 +#endif
16034
16035 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16036 #ifdef CONFIG_TRACE_IRQFLAGS
16037 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16038 .endm
16039
16040 .macro UNFAKE_STACK_FRAME
16041 - addq $8*6, %rsp
16042 - CFI_ADJUST_CFA_OFFSET -(6*8)
16043 + addq $8*6 + ARG_SKIP, %rsp
16044 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16045 .endm
16046
16047 /*
16048 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16049 movq %rsp, %rsi
16050
16051 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16052 - testl $3, CS-RBP(%rsi)
16053 + testb $3, CS-RBP(%rsi)
16054 je 1f
16055 SWAPGS
16056 /*
16057 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16058 movq_cfi r15, R15+16
16059 movq %r11, 8(%rsp) /* return address */
16060 FIXUP_TOP_OF_STACK %r11, 16
16061 + pax_force_retaddr
16062 ret
16063 CFI_ENDPROC
16064 -END(save_rest)
16065 +ENDPROC(save_rest)
16066
16067 /* save complete stack frame */
16068 .pushsection .kprobes.text, "ax"
16069 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16070 js 1f /* negative -> in kernel */
16071 SWAPGS
16072 xorl %ebx,%ebx
16073 -1: ret
16074 +1: pax_force_retaddr_bts
16075 + ret
16076 CFI_ENDPROC
16077 -END(save_paranoid)
16078 +ENDPROC(save_paranoid)
16079 .popsection
16080
16081 /*
16082 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16083
16084 RESTORE_REST
16085
16086 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16087 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16088 jz retint_restore_args
16089
16090 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16091 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16092 jmp ret_from_sys_call # go to the SYSRET fastpath
16093
16094 CFI_ENDPROC
16095 -END(ret_from_fork)
16096 +ENDPROC(ret_from_fork)
16097
16098 /*
16099 * System call entry. Up to 6 arguments in registers are supported.
16100 @@ -495,7 +779,7 @@ END(ret_from_fork)
16101 ENTRY(system_call)
16102 CFI_STARTPROC simple
16103 CFI_SIGNAL_FRAME
16104 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16105 + CFI_DEF_CFA rsp,0
16106 CFI_REGISTER rip,rcx
16107 /*CFI_REGISTER rflags,r11*/
16108 SWAPGS_UNSAFE_STACK
16109 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16110
16111 movq %rsp,PER_CPU_VAR(old_rsp)
16112 movq PER_CPU_VAR(kernel_stack),%rsp
16113 + SAVE_ARGS 8*6,0
16114 + pax_enter_kernel_user
16115 +
16116 +#ifdef CONFIG_PAX_RANDKSTACK
16117 + pax_erase_kstack
16118 +#endif
16119 +
16120 /*
16121 * No need to follow this irqs off/on section - it's straight
16122 * and short:
16123 */
16124 ENABLE_INTERRUPTS(CLBR_NONE)
16125 - SAVE_ARGS 8,0
16126 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16127 movq %rcx,RIP-ARGOFFSET(%rsp)
16128 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16129 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16130 + GET_THREAD_INFO(%rcx)
16131 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16132 jnz tracesys
16133 system_call_fastpath:
16134 #if __SYSCALL_MASK == ~0
16135 @@ -527,7 +818,7 @@ system_call_fastpath:
16136 cmpl $__NR_syscall_max,%eax
16137 #endif
16138 ja badsys
16139 - movq %r10,%rcx
16140 + movq R10-ARGOFFSET(%rsp),%rcx
16141 call *sys_call_table(,%rax,8) # XXX: rip relative
16142 movq %rax,RAX-ARGOFFSET(%rsp)
16143 /*
16144 @@ -541,10 +832,13 @@ sysret_check:
16145 LOCKDEP_SYS_EXIT
16146 DISABLE_INTERRUPTS(CLBR_NONE)
16147 TRACE_IRQS_OFF
16148 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16149 + GET_THREAD_INFO(%rcx)
16150 + movl TI_flags(%rcx),%edx
16151 andl %edi,%edx
16152 jnz sysret_careful
16153 CFI_REMEMBER_STATE
16154 + pax_exit_kernel_user
16155 + pax_erase_kstack
16156 /*
16157 * sysretq will re-enable interrupts:
16158 */
16159 @@ -596,14 +890,18 @@ badsys:
16160 * jump back to the normal fast path.
16161 */
16162 auditsys:
16163 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16164 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16165 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16166 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16167 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16168 movq %rax,%rsi /* 2nd arg: syscall number */
16169 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16170 call __audit_syscall_entry
16171 +
16172 + pax_erase_kstack
16173 +
16174 LOAD_ARGS 0 /* reload call-clobbered registers */
16175 + pax_set_fptr_mask
16176 jmp system_call_fastpath
16177
16178 /*
16179 @@ -624,7 +922,7 @@ sysret_audit:
16180 /* Do syscall tracing */
16181 tracesys:
16182 #ifdef CONFIG_AUDITSYSCALL
16183 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16184 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16185 jz auditsys
16186 #endif
16187 SAVE_REST
16188 @@ -632,12 +930,16 @@ tracesys:
16189 FIXUP_TOP_OF_STACK %rdi
16190 movq %rsp,%rdi
16191 call syscall_trace_enter
16192 +
16193 + pax_erase_kstack
16194 +
16195 /*
16196 * Reload arg registers from stack in case ptrace changed them.
16197 * We don't reload %rax because syscall_trace_enter() returned
16198 * the value it wants us to use in the table lookup.
16199 */
16200 LOAD_ARGS ARGOFFSET, 1
16201 + pax_set_fptr_mask
16202 RESTORE_REST
16203 #if __SYSCALL_MASK == ~0
16204 cmpq $__NR_syscall_max,%rax
16205 @@ -646,7 +948,7 @@ tracesys:
16206 cmpl $__NR_syscall_max,%eax
16207 #endif
16208 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16209 - movq %r10,%rcx /* fixup for C */
16210 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16211 call *sys_call_table(,%rax,8)
16212 movq %rax,RAX-ARGOFFSET(%rsp)
16213 /* Use IRET because user could have changed frame */
16214 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16215 andl %edi,%edx
16216 jnz int_careful
16217 andl $~TS_COMPAT,TI_status(%rcx)
16218 - jmp retint_swapgs
16219 + pax_exit_kernel_user
16220 + pax_erase_kstack
16221 + jmp retint_swapgs_pax
16222
16223 /* Either reschedule or signal or syscall exit tracking needed. */
16224 /* First do a reschedule test. */
16225 @@ -713,7 +1017,7 @@ int_restore_rest:
16226 TRACE_IRQS_OFF
16227 jmp int_with_check
16228 CFI_ENDPROC
16229 -END(system_call)
16230 +ENDPROC(system_call)
16231
16232 /*
16233 * Certain special system calls that need to save a complete full stack frame.
16234 @@ -729,7 +1033,7 @@ ENTRY(\label)
16235 call \func
16236 jmp ptregscall_common
16237 CFI_ENDPROC
16238 -END(\label)
16239 +ENDPROC(\label)
16240 .endm
16241
16242 PTREGSCALL stub_clone, sys_clone, %r8
16243 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16244 movq_cfi_restore R12+8, r12
16245 movq_cfi_restore RBP+8, rbp
16246 movq_cfi_restore RBX+8, rbx
16247 + pax_force_retaddr
16248 ret $REST_SKIP /* pop extended registers */
16249 CFI_ENDPROC
16250 -END(ptregscall_common)
16251 +ENDPROC(ptregscall_common)
16252
16253 ENTRY(stub_execve)
16254 CFI_STARTPROC
16255 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16256 RESTORE_REST
16257 jmp int_ret_from_sys_call
16258 CFI_ENDPROC
16259 -END(stub_execve)
16260 +ENDPROC(stub_execve)
16261
16262 /*
16263 * sigreturn is special because it needs to restore all registers on return.
16264 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16265 RESTORE_REST
16266 jmp int_ret_from_sys_call
16267 CFI_ENDPROC
16268 -END(stub_rt_sigreturn)
16269 +ENDPROC(stub_rt_sigreturn)
16270
16271 #ifdef CONFIG_X86_X32_ABI
16272 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16273 @@ -851,7 +1156,7 @@ vector=vector+1
16274 2: jmp common_interrupt
16275 .endr
16276 CFI_ENDPROC
16277 -END(irq_entries_start)
16278 +ENDPROC(irq_entries_start)
16279
16280 .previous
16281 END(interrupt)
16282 @@ -871,6 +1176,16 @@ END(interrupt)
16283 subq $ORIG_RAX-RBP, %rsp
16284 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16285 SAVE_ARGS_IRQ
16286 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16287 + testb $3, CS(%rdi)
16288 + jnz 1f
16289 + pax_enter_kernel
16290 + jmp 2f
16291 +1: pax_enter_kernel_user
16292 +2:
16293 +#else
16294 + pax_enter_kernel
16295 +#endif
16296 call \func
16297 .endm
16298
16299 @@ -902,7 +1217,7 @@ ret_from_intr:
16300
16301 exit_intr:
16302 GET_THREAD_INFO(%rcx)
16303 - testl $3,CS-ARGOFFSET(%rsp)
16304 + testb $3,CS-ARGOFFSET(%rsp)
16305 je retint_kernel
16306
16307 /* Interrupt came from user space */
16308 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16309 * The iretq could re-enable interrupts:
16310 */
16311 DISABLE_INTERRUPTS(CLBR_ANY)
16312 + pax_exit_kernel_user
16313 +retint_swapgs_pax:
16314 TRACE_IRQS_IRETQ
16315 SWAPGS
16316 jmp restore_args
16317
16318 retint_restore_args: /* return to kernel space */
16319 DISABLE_INTERRUPTS(CLBR_ANY)
16320 + pax_exit_kernel
16321 + pax_force_retaddr RIP-ARGOFFSET
16322 /*
16323 * The iretq could re-enable interrupts:
16324 */
16325 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16326 #endif
16327
16328 CFI_ENDPROC
16329 -END(common_interrupt)
16330 +ENDPROC(common_interrupt)
16331 /*
16332 * End of kprobes section
16333 */
16334 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16335 interrupt \do_sym
16336 jmp ret_from_intr
16337 CFI_ENDPROC
16338 -END(\sym)
16339 +ENDPROC(\sym)
16340 .endm
16341
16342 #ifdef CONFIG_SMP
16343 @@ -1102,12 +1421,22 @@ ENTRY(\sym)
16344 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16345 call error_entry
16346 DEFAULT_FRAME 0
16347 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16348 + testb $3, CS(%rsp)
16349 + jnz 1f
16350 + pax_enter_kernel
16351 + jmp 2f
16352 +1: pax_enter_kernel_user
16353 +2:
16354 +#else
16355 + pax_enter_kernel
16356 +#endif
16357 movq %rsp,%rdi /* pt_regs pointer */
16358 xorl %esi,%esi /* no error code */
16359 call \do_sym
16360 jmp error_exit /* %ebx: no swapgs flag */
16361 CFI_ENDPROC
16362 -END(\sym)
16363 +ENDPROC(\sym)
16364 .endm
16365
16366 .macro paranoidzeroentry sym do_sym
16367 @@ -1119,15 +1448,25 @@ ENTRY(\sym)
16368 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16369 call save_paranoid
16370 TRACE_IRQS_OFF
16371 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16372 + testb $3, CS(%rsp)
16373 + jnz 1f
16374 + pax_enter_kernel
16375 + jmp 2f
16376 +1: pax_enter_kernel_user
16377 +2:
16378 +#else
16379 + pax_enter_kernel
16380 +#endif
16381 movq %rsp,%rdi /* pt_regs pointer */
16382 xorl %esi,%esi /* no error code */
16383 call \do_sym
16384 jmp paranoid_exit /* %ebx: no swapgs flag */
16385 CFI_ENDPROC
16386 -END(\sym)
16387 +ENDPROC(\sym)
16388 .endm
16389
16390 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16391 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16392 .macro paranoidzeroentry_ist sym do_sym ist
16393 ENTRY(\sym)
16394 INTR_FRAME
16395 @@ -1137,14 +1476,30 @@ ENTRY(\sym)
16396 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16397 call save_paranoid
16398 TRACE_IRQS_OFF_DEBUG
16399 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16400 + testb $3, CS(%rsp)
16401 + jnz 1f
16402 + pax_enter_kernel
16403 + jmp 2f
16404 +1: pax_enter_kernel_user
16405 +2:
16406 +#else
16407 + pax_enter_kernel
16408 +#endif
16409 movq %rsp,%rdi /* pt_regs pointer */
16410 xorl %esi,%esi /* no error code */
16411 +#ifdef CONFIG_SMP
16412 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16413 + lea init_tss(%r12), %r12
16414 +#else
16415 + lea init_tss(%rip), %r12
16416 +#endif
16417 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16418 call \do_sym
16419 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16420 jmp paranoid_exit /* %ebx: no swapgs flag */
16421 CFI_ENDPROC
16422 -END(\sym)
16423 +ENDPROC(\sym)
16424 .endm
16425
16426 .macro errorentry sym do_sym
16427 @@ -1155,13 +1510,23 @@ ENTRY(\sym)
16428 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16429 call error_entry
16430 DEFAULT_FRAME 0
16431 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16432 + testb $3, CS(%rsp)
16433 + jnz 1f
16434 + pax_enter_kernel
16435 + jmp 2f
16436 +1: pax_enter_kernel_user
16437 +2:
16438 +#else
16439 + pax_enter_kernel
16440 +#endif
16441 movq %rsp,%rdi /* pt_regs pointer */
16442 movq ORIG_RAX(%rsp),%rsi /* get error code */
16443 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16444 call \do_sym
16445 jmp error_exit /* %ebx: no swapgs flag */
16446 CFI_ENDPROC
16447 -END(\sym)
16448 +ENDPROC(\sym)
16449 .endm
16450
16451 /* error code is on the stack already */
16452 @@ -1174,13 +1539,23 @@ ENTRY(\sym)
16453 call save_paranoid
16454 DEFAULT_FRAME 0
16455 TRACE_IRQS_OFF
16456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16457 + testb $3, CS(%rsp)
16458 + jnz 1f
16459 + pax_enter_kernel
16460 + jmp 2f
16461 +1: pax_enter_kernel_user
16462 +2:
16463 +#else
16464 + pax_enter_kernel
16465 +#endif
16466 movq %rsp,%rdi /* pt_regs pointer */
16467 movq ORIG_RAX(%rsp),%rsi /* get error code */
16468 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16469 call \do_sym
16470 jmp paranoid_exit /* %ebx: no swapgs flag */
16471 CFI_ENDPROC
16472 -END(\sym)
16473 +ENDPROC(\sym)
16474 .endm
16475
16476 zeroentry divide_error do_divide_error
16477 @@ -1210,9 +1585,10 @@ gs_change:
16478 2: mfence /* workaround */
16479 SWAPGS
16480 popfq_cfi
16481 + pax_force_retaddr
16482 ret
16483 CFI_ENDPROC
16484 -END(native_load_gs_index)
16485 +ENDPROC(native_load_gs_index)
16486
16487 _ASM_EXTABLE(gs_change,bad_gs)
16488 .section .fixup,"ax"
16489 @@ -1231,13 +1607,14 @@ ENTRY(kernel_thread_helper)
16490 * Here we are in the child and the registers are set as they were
16491 * at kernel_thread() invocation in the parent.
16492 */
16493 + pax_force_fptr %rsi
16494 call *%rsi
16495 # exit
16496 mov %eax, %edi
16497 call do_exit
16498 ud2 # padding for call trace
16499 CFI_ENDPROC
16500 -END(kernel_thread_helper)
16501 +ENDPROC(kernel_thread_helper)
16502
16503 /*
16504 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16505 @@ -1264,11 +1641,11 @@ ENTRY(kernel_execve)
16506 RESTORE_REST
16507 testq %rax,%rax
16508 je int_ret_from_sys_call
16509 - RESTORE_ARGS
16510 UNFAKE_STACK_FRAME
16511 + pax_force_retaddr
16512 ret
16513 CFI_ENDPROC
16514 -END(kernel_execve)
16515 +ENDPROC(kernel_execve)
16516
16517 /* Call softirq on interrupt stack. Interrupts are off. */
16518 ENTRY(call_softirq)
16519 @@ -1286,9 +1663,10 @@ ENTRY(call_softirq)
16520 CFI_DEF_CFA_REGISTER rsp
16521 CFI_ADJUST_CFA_OFFSET -8
16522 decl PER_CPU_VAR(irq_count)
16523 + pax_force_retaddr
16524 ret
16525 CFI_ENDPROC
16526 -END(call_softirq)
16527 +ENDPROC(call_softirq)
16528
16529 #ifdef CONFIG_XEN
16530 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16531 @@ -1326,7 +1704,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16532 decl PER_CPU_VAR(irq_count)
16533 jmp error_exit
16534 CFI_ENDPROC
16535 -END(xen_do_hypervisor_callback)
16536 +ENDPROC(xen_do_hypervisor_callback)
16537
16538 /*
16539 * Hypervisor uses this for application faults while it executes.
16540 @@ -1385,7 +1763,7 @@ ENTRY(xen_failsafe_callback)
16541 SAVE_ALL
16542 jmp error_exit
16543 CFI_ENDPROC
16544 -END(xen_failsafe_callback)
16545 +ENDPROC(xen_failsafe_callback)
16546
16547 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16548 xen_hvm_callback_vector xen_evtchn_do_upcall
16549 @@ -1434,16 +1812,31 @@ ENTRY(paranoid_exit)
16550 TRACE_IRQS_OFF_DEBUG
16551 testl %ebx,%ebx /* swapgs needed? */
16552 jnz paranoid_restore
16553 - testl $3,CS(%rsp)
16554 + testb $3,CS(%rsp)
16555 jnz paranoid_userspace
16556 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16557 + pax_exit_kernel
16558 + TRACE_IRQS_IRETQ 0
16559 + SWAPGS_UNSAFE_STACK
16560 + RESTORE_ALL 8
16561 + pax_force_retaddr_bts
16562 + jmp irq_return
16563 +#endif
16564 paranoid_swapgs:
16565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16566 + pax_exit_kernel_user
16567 +#else
16568 + pax_exit_kernel
16569 +#endif
16570 TRACE_IRQS_IRETQ 0
16571 SWAPGS_UNSAFE_STACK
16572 RESTORE_ALL 8
16573 jmp irq_return
16574 paranoid_restore:
16575 + pax_exit_kernel
16576 TRACE_IRQS_IRETQ_DEBUG 0
16577 RESTORE_ALL 8
16578 + pax_force_retaddr_bts
16579 jmp irq_return
16580 paranoid_userspace:
16581 GET_THREAD_INFO(%rcx)
16582 @@ -1472,7 +1865,7 @@ paranoid_schedule:
16583 TRACE_IRQS_OFF
16584 jmp paranoid_userspace
16585 CFI_ENDPROC
16586 -END(paranoid_exit)
16587 +ENDPROC(paranoid_exit)
16588
16589 /*
16590 * Exception entry point. This expects an error code/orig_rax on the stack.
16591 @@ -1499,12 +1892,13 @@ ENTRY(error_entry)
16592 movq_cfi r14, R14+8
16593 movq_cfi r15, R15+8
16594 xorl %ebx,%ebx
16595 - testl $3,CS+8(%rsp)
16596 + testb $3,CS+8(%rsp)
16597 je error_kernelspace
16598 error_swapgs:
16599 SWAPGS
16600 error_sti:
16601 TRACE_IRQS_OFF
16602 + pax_force_retaddr_bts
16603 ret
16604
16605 /*
16606 @@ -1531,7 +1925,7 @@ bstep_iret:
16607 movq %rcx,RIP+8(%rsp)
16608 jmp error_swapgs
16609 CFI_ENDPROC
16610 -END(error_entry)
16611 +ENDPROC(error_entry)
16612
16613
16614 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16615 @@ -1551,7 +1945,7 @@ ENTRY(error_exit)
16616 jnz retint_careful
16617 jmp retint_swapgs
16618 CFI_ENDPROC
16619 -END(error_exit)
16620 +ENDPROC(error_exit)
16621
16622 /*
16623 * Test if a given stack is an NMI stack or not.
16624 @@ -1609,9 +2003,11 @@ ENTRY(nmi)
16625 * If %cs was not the kernel segment, then the NMI triggered in user
16626 * space, which means it is definitely not nested.
16627 */
16628 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16629 + je 1f
16630 cmpl $__KERNEL_CS, 16(%rsp)
16631 jne first_nmi
16632 -
16633 +1:
16634 /*
16635 * Check the special variable on the stack to see if NMIs are
16636 * executing.
16637 @@ -1758,6 +2154,16 @@ end_repeat_nmi:
16638 */
16639 call save_paranoid
16640 DEFAULT_FRAME 0
16641 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16642 + testb $3, CS(%rsp)
16643 + jnz 1f
16644 + pax_enter_kernel
16645 + jmp 2f
16646 +1: pax_enter_kernel_user
16647 +2:
16648 +#else
16649 + pax_enter_kernel
16650 +#endif
16651 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16652 movq %rsp,%rdi
16653 movq $-1,%rsi
16654 @@ -1765,21 +2171,32 @@ end_repeat_nmi:
16655 testl %ebx,%ebx /* swapgs needed? */
16656 jnz nmi_restore
16657 nmi_swapgs:
16658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16659 + pax_exit_kernel_user
16660 +#else
16661 + pax_exit_kernel
16662 +#endif
16663 SWAPGS_UNSAFE_STACK
16664 + RESTORE_ALL 8
16665 + /* Clear the NMI executing stack variable */
16666 + movq $0, 10*8(%rsp)
16667 + jmp irq_return
16668 nmi_restore:
16669 + pax_exit_kernel
16670 RESTORE_ALL 8
16671 + pax_force_retaddr_bts
16672 /* Clear the NMI executing stack variable */
16673 movq $0, 10*8(%rsp)
16674 jmp irq_return
16675 CFI_ENDPROC
16676 -END(nmi)
16677 +ENDPROC(nmi)
16678
16679 ENTRY(ignore_sysret)
16680 CFI_STARTPROC
16681 mov $-ENOSYS,%eax
16682 sysret
16683 CFI_ENDPROC
16684 -END(ignore_sysret)
16685 +ENDPROC(ignore_sysret)
16686
16687 /*
16688 * End of kprobes section
16689 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16690 index c3a7cb4..3ad00dc 100644
16691 --- a/arch/x86/kernel/ftrace.c
16692 +++ b/arch/x86/kernel/ftrace.c
16693 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16694 {
16695 unsigned char replaced[MCOUNT_INSN_SIZE];
16696
16697 + ip = ktla_ktva(ip);
16698 +
16699 /*
16700 * Note: Due to modules and __init, code can
16701 * disappear and change, we need to protect against faulting
16702 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16703 unsigned char old[MCOUNT_INSN_SIZE], *new;
16704 int ret;
16705
16706 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16707 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16708 new = ftrace_call_replace(ip, (unsigned long)func);
16709
16710 /* See comment above by declaration of modifying_ftrace_code */
16711 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16712 {
16713 unsigned char code[MCOUNT_INSN_SIZE];
16714
16715 + ip = ktla_ktva(ip);
16716 +
16717 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16718 return -EFAULT;
16719
16720 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16721 index c18f59d..9c0c9f6 100644
16722 --- a/arch/x86/kernel/head32.c
16723 +++ b/arch/x86/kernel/head32.c
16724 @@ -18,6 +18,7 @@
16725 #include <asm/io_apic.h>
16726 #include <asm/bios_ebda.h>
16727 #include <asm/tlbflush.h>
16728 +#include <asm/boot.h>
16729
16730 static void __init i386_default_early_setup(void)
16731 {
16732 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16733
16734 void __init i386_start_kernel(void)
16735 {
16736 - memblock_reserve(__pa_symbol(&_text),
16737 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16738 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16739
16740 #ifdef CONFIG_BLK_DEV_INITRD
16741 /* Reserve INITRD */
16742 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16743 index d42ab17..cb1b997 100644
16744 --- a/arch/x86/kernel/head_32.S
16745 +++ b/arch/x86/kernel/head_32.S
16746 @@ -26,6 +26,12 @@
16747 /* Physical address */
16748 #define pa(X) ((X) - __PAGE_OFFSET)
16749
16750 +#ifdef CONFIG_PAX_KERNEXEC
16751 +#define ta(X) (X)
16752 +#else
16753 +#define ta(X) ((X) - __PAGE_OFFSET)
16754 +#endif
16755 +
16756 /*
16757 * References to members of the new_cpu_data structure.
16758 */
16759 @@ -55,11 +61,7 @@
16760 * and small than max_low_pfn, otherwise will waste some page table entries
16761 */
16762
16763 -#if PTRS_PER_PMD > 1
16764 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16765 -#else
16766 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16767 -#endif
16768 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16769
16770 /* Number of possible pages in the lowmem region */
16771 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16772 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16773 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16774
16775 /*
16776 + * Real beginning of normal "text" segment
16777 + */
16778 +ENTRY(stext)
16779 +ENTRY(_stext)
16780 +
16781 +/*
16782 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16783 * %esi points to the real-mode code as a 32-bit pointer.
16784 * CS and DS must be 4 GB flat segments, but we don't depend on
16785 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16786 * can.
16787 */
16788 __HEAD
16789 +
16790 +#ifdef CONFIG_PAX_KERNEXEC
16791 + jmp startup_32
16792 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16793 +.fill PAGE_SIZE-5,1,0xcc
16794 +#endif
16795 +
16796 ENTRY(startup_32)
16797 movl pa(stack_start),%ecx
16798
16799 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16800 2:
16801 leal -__PAGE_OFFSET(%ecx),%esp
16802
16803 +#ifdef CONFIG_SMP
16804 + movl $pa(cpu_gdt_table),%edi
16805 + movl $__per_cpu_load,%eax
16806 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16807 + rorl $16,%eax
16808 + movb %al,__KERNEL_PERCPU + 4(%edi)
16809 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16810 + movl $__per_cpu_end - 1,%eax
16811 + subl $__per_cpu_start,%eax
16812 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16813 +#endif
16814 +
16815 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16816 + movl $NR_CPUS,%ecx
16817 + movl $pa(cpu_gdt_table),%edi
16818 +1:
16819 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16820 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16821 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16822 + addl $PAGE_SIZE_asm,%edi
16823 + loop 1b
16824 +#endif
16825 +
16826 +#ifdef CONFIG_PAX_KERNEXEC
16827 + movl $pa(boot_gdt),%edi
16828 + movl $__LOAD_PHYSICAL_ADDR,%eax
16829 + movw %ax,__BOOT_CS + 2(%edi)
16830 + rorl $16,%eax
16831 + movb %al,__BOOT_CS + 4(%edi)
16832 + movb %ah,__BOOT_CS + 7(%edi)
16833 + rorl $16,%eax
16834 +
16835 + ljmp $(__BOOT_CS),$1f
16836 +1:
16837 +
16838 + movl $NR_CPUS,%ecx
16839 + movl $pa(cpu_gdt_table),%edi
16840 + addl $__PAGE_OFFSET,%eax
16841 +1:
16842 + movw %ax,__KERNEL_CS + 2(%edi)
16843 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16844 + rorl $16,%eax
16845 + movb %al,__KERNEL_CS + 4(%edi)
16846 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16847 + movb %ah,__KERNEL_CS + 7(%edi)
16848 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16849 + rorl $16,%eax
16850 + addl $PAGE_SIZE_asm,%edi
16851 + loop 1b
16852 +#endif
16853 +
16854 /*
16855 * Clear BSS first so that there are no surprises...
16856 */
16857 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16858 movl %eax, pa(max_pfn_mapped)
16859
16860 /* Do early initialization of the fixmap area */
16861 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16862 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16863 +#ifdef CONFIG_COMPAT_VDSO
16864 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16865 +#else
16866 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16867 +#endif
16868 #else /* Not PAE */
16869
16870 page_pde_offset = (__PAGE_OFFSET >> 20);
16871 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16872 movl %eax, pa(max_pfn_mapped)
16873
16874 /* Do early initialization of the fixmap area */
16875 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16876 - movl %eax,pa(initial_page_table+0xffc)
16877 +#ifdef CONFIG_COMPAT_VDSO
16878 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16879 +#else
16880 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16881 +#endif
16882 #endif
16883
16884 #ifdef CONFIG_PARAVIRT
16885 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16886 cmpl $num_subarch_entries, %eax
16887 jae bad_subarch
16888
16889 - movl pa(subarch_entries)(,%eax,4), %eax
16890 - subl $__PAGE_OFFSET, %eax
16891 - jmp *%eax
16892 + jmp *pa(subarch_entries)(,%eax,4)
16893
16894 bad_subarch:
16895 WEAK(lguest_entry)
16896 @@ -256,10 +326,10 @@ WEAK(xen_entry)
16897 __INITDATA
16898
16899 subarch_entries:
16900 - .long default_entry /* normal x86/PC */
16901 - .long lguest_entry /* lguest hypervisor */
16902 - .long xen_entry /* Xen hypervisor */
16903 - .long default_entry /* Moorestown MID */
16904 + .long ta(default_entry) /* normal x86/PC */
16905 + .long ta(lguest_entry) /* lguest hypervisor */
16906 + .long ta(xen_entry) /* Xen hypervisor */
16907 + .long ta(default_entry) /* Moorestown MID */
16908 num_subarch_entries = (. - subarch_entries) / 4
16909 .previous
16910 #else
16911 @@ -310,6 +380,7 @@ default_entry:
16912 orl %edx,%eax
16913 movl %eax,%cr4
16914
16915 +#ifdef CONFIG_X86_PAE
16916 testb $X86_CR4_PAE, %al # check if PAE is enabled
16917 jz 6f
16918
16919 @@ -338,6 +409,9 @@ default_entry:
16920 /* Make changes effective */
16921 wrmsr
16922
16923 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16924 +#endif
16925 +
16926 6:
16927
16928 /*
16929 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16930 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16931 movl %eax,%ss # after changing gdt.
16932
16933 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16934 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16935 movl %eax,%ds
16936 movl %eax,%es
16937
16938 movl $(__KERNEL_PERCPU), %eax
16939 movl %eax,%fs # set this cpu's percpu
16940
16941 +#ifdef CONFIG_CC_STACKPROTECTOR
16942 movl $(__KERNEL_STACK_CANARY),%eax
16943 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16944 + movl $(__USER_DS),%eax
16945 +#else
16946 + xorl %eax,%eax
16947 +#endif
16948 movl %eax,%gs
16949
16950 xorl %eax,%eax # Clear LDT
16951 @@ -520,8 +600,11 @@ setup_once:
16952 * relocation. Manually set base address in stack canary
16953 * segment descriptor.
16954 */
16955 - movl $gdt_page,%eax
16956 + movl $cpu_gdt_table,%eax
16957 movl $stack_canary,%ecx
16958 +#ifdef CONFIG_SMP
16959 + addl $__per_cpu_load,%ecx
16960 +#endif
16961 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16962 shrl $16, %ecx
16963 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16964 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16965 /* This is global to keep gas from relaxing the jumps */
16966 ENTRY(early_idt_handler)
16967 cld
16968 - cmpl $2,%ss:early_recursion_flag
16969 + cmpl $1,%ss:early_recursion_flag
16970 je hlt_loop
16971 incl %ss:early_recursion_flag
16972
16973 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16974 pushl (20+6*4)(%esp) /* trapno */
16975 pushl $fault_msg
16976 call printk
16977 -#endif
16978 call dump_stack
16979 +#endif
16980 hlt_loop:
16981 hlt
16982 jmp hlt_loop
16983 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16984 /* This is the default interrupt "handler" :-) */
16985 ALIGN
16986 ignore_int:
16987 - cld
16988 #ifdef CONFIG_PRINTK
16989 + cmpl $2,%ss:early_recursion_flag
16990 + je hlt_loop
16991 + incl %ss:early_recursion_flag
16992 + cld
16993 pushl %eax
16994 pushl %ecx
16995 pushl %edx
16996 @@ -620,9 +706,6 @@ ignore_int:
16997 movl $(__KERNEL_DS),%eax
16998 movl %eax,%ds
16999 movl %eax,%es
17000 - cmpl $2,early_recursion_flag
17001 - je hlt_loop
17002 - incl early_recursion_flag
17003 pushl 16(%esp)
17004 pushl 24(%esp)
17005 pushl 32(%esp)
17006 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17007 /*
17008 * BSS section
17009 */
17010 -__PAGE_ALIGNED_BSS
17011 - .align PAGE_SIZE
17012 #ifdef CONFIG_X86_PAE
17013 +.section .initial_pg_pmd,"a",@progbits
17014 initial_pg_pmd:
17015 .fill 1024*KPMDS,4,0
17016 #else
17017 +.section .initial_page_table,"a",@progbits
17018 ENTRY(initial_page_table)
17019 .fill 1024,4,0
17020 #endif
17021 +.section .initial_pg_fixmap,"a",@progbits
17022 initial_pg_fixmap:
17023 .fill 1024,4,0
17024 +.section .empty_zero_page,"a",@progbits
17025 ENTRY(empty_zero_page)
17026 .fill 4096,1,0
17027 +.section .swapper_pg_dir,"a",@progbits
17028 ENTRY(swapper_pg_dir)
17029 +#ifdef CONFIG_X86_PAE
17030 + .fill 4,8,0
17031 +#else
17032 .fill 1024,4,0
17033 +#endif
17034 +
17035 +/*
17036 + * The IDT has to be page-aligned to simplify the Pentium
17037 + * F0 0F bug workaround.. We have a special link segment
17038 + * for this.
17039 + */
17040 +.section .idt,"a",@progbits
17041 +ENTRY(idt_table)
17042 + .fill 256,8,0
17043
17044 /*
17045 * This starts the data section.
17046 */
17047 #ifdef CONFIG_X86_PAE
17048 -__PAGE_ALIGNED_DATA
17049 - /* Page-aligned for the benefit of paravirt? */
17050 - .align PAGE_SIZE
17051 +.section .initial_page_table,"a",@progbits
17052 ENTRY(initial_page_table)
17053 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17054 # if KPMDS == 3
17055 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17056 # error "Kernel PMDs should be 1, 2 or 3"
17057 # endif
17058 .align PAGE_SIZE /* needs to be page-sized too */
17059 +
17060 +#ifdef CONFIG_PAX_PER_CPU_PGD
17061 +ENTRY(cpu_pgd)
17062 + .rept NR_CPUS
17063 + .fill 4,8,0
17064 + .endr
17065 +#endif
17066 +
17067 #endif
17068
17069 .data
17070 .balign 4
17071 ENTRY(stack_start)
17072 - .long init_thread_union+THREAD_SIZE
17073 + .long init_thread_union+THREAD_SIZE-8
17074
17075 __INITRODATA
17076 int_msg:
17077 @@ -730,7 +835,7 @@ fault_msg:
17078 * segment size, and 32-bit linear address value:
17079 */
17080
17081 - .data
17082 +.section .rodata,"a",@progbits
17083 .globl boot_gdt_descr
17084 .globl idt_descr
17085
17086 @@ -739,7 +844,7 @@ fault_msg:
17087 .word 0 # 32 bit align gdt_desc.address
17088 boot_gdt_descr:
17089 .word __BOOT_DS+7
17090 - .long boot_gdt - __PAGE_OFFSET
17091 + .long pa(boot_gdt)
17092
17093 .word 0 # 32-bit align idt_desc.address
17094 idt_descr:
17095 @@ -750,7 +855,7 @@ idt_descr:
17096 .word 0 # 32 bit align gdt_desc.address
17097 ENTRY(early_gdt_descr)
17098 .word GDT_ENTRIES*8-1
17099 - .long gdt_page /* Overwritten for secondary CPUs */
17100 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17101
17102 /*
17103 * The boot_gdt must mirror the equivalent in setup.S and is
17104 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17105 .align L1_CACHE_BYTES
17106 ENTRY(boot_gdt)
17107 .fill GDT_ENTRY_BOOT_CS,8,0
17108 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17109 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17110 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17111 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17112 +
17113 + .align PAGE_SIZE_asm
17114 +ENTRY(cpu_gdt_table)
17115 + .rept NR_CPUS
17116 + .quad 0x0000000000000000 /* NULL descriptor */
17117 + .quad 0x0000000000000000 /* 0x0b reserved */
17118 + .quad 0x0000000000000000 /* 0x13 reserved */
17119 + .quad 0x0000000000000000 /* 0x1b reserved */
17120 +
17121 +#ifdef CONFIG_PAX_KERNEXEC
17122 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17123 +#else
17124 + .quad 0x0000000000000000 /* 0x20 unused */
17125 +#endif
17126 +
17127 + .quad 0x0000000000000000 /* 0x28 unused */
17128 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17129 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17130 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17131 + .quad 0x0000000000000000 /* 0x4b reserved */
17132 + .quad 0x0000000000000000 /* 0x53 reserved */
17133 + .quad 0x0000000000000000 /* 0x5b reserved */
17134 +
17135 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17136 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17137 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17138 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17139 +
17140 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17141 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17142 +
17143 + /*
17144 + * Segments used for calling PnP BIOS have byte granularity.
17145 + * The code segments and data segments have fixed 64k limits,
17146 + * the transfer segment sizes are set at run time.
17147 + */
17148 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17149 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17150 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17151 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17152 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17153 +
17154 + /*
17155 + * The APM segments have byte granularity and their bases
17156 + * are set at run time. All have 64k limits.
17157 + */
17158 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17159 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17160 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17161 +
17162 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17163 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17164 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17165 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17166 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17167 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17168 +
17169 + /* Be sure this is zeroed to avoid false validations in Xen */
17170 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17171 + .endr
17172 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17173 index 94bf9cc..400455a 100644
17174 --- a/arch/x86/kernel/head_64.S
17175 +++ b/arch/x86/kernel/head_64.S
17176 @@ -20,6 +20,8 @@
17177 #include <asm/processor-flags.h>
17178 #include <asm/percpu.h>
17179 #include <asm/nops.h>
17180 +#include <asm/cpufeature.h>
17181 +#include <asm/alternative-asm.h>
17182
17183 #ifdef CONFIG_PARAVIRT
17184 #include <asm/asm-offsets.h>
17185 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17186 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17187 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17188 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17189 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17190 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17191 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17192 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17193 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17194 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17195
17196 .text
17197 __HEAD
17198 @@ -88,35 +96,23 @@ startup_64:
17199 */
17200 addq %rbp, init_level4_pgt + 0(%rip)
17201 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17202 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17203 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17204 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17205 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17206
17207 addq %rbp, level3_ident_pgt + 0(%rip)
17208 +#ifndef CONFIG_XEN
17209 + addq %rbp, level3_ident_pgt + 8(%rip)
17210 +#endif
17211
17212 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17213 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17214 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17215 +
17216 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17217 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17218
17219 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17220 -
17221 - /* Add an Identity mapping if I am above 1G */
17222 - leaq _text(%rip), %rdi
17223 - andq $PMD_PAGE_MASK, %rdi
17224 -
17225 - movq %rdi, %rax
17226 - shrq $PUD_SHIFT, %rax
17227 - andq $(PTRS_PER_PUD - 1), %rax
17228 - jz ident_complete
17229 -
17230 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17231 - leaq level3_ident_pgt(%rip), %rbx
17232 - movq %rdx, 0(%rbx, %rax, 8)
17233 -
17234 - movq %rdi, %rax
17235 - shrq $PMD_SHIFT, %rax
17236 - andq $(PTRS_PER_PMD - 1), %rax
17237 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17238 - leaq level2_spare_pgt(%rip), %rbx
17239 - movq %rdx, 0(%rbx, %rax, 8)
17240 -ident_complete:
17241 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17242
17243 /*
17244 * Fixup the kernel text+data virtual addresses. Note that
17245 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17246 * after the boot processor executes this code.
17247 */
17248
17249 - /* Enable PAE mode and PGE */
17250 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17251 + /* Enable PAE mode and PSE/PGE */
17252 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17253 movq %rax, %cr4
17254
17255 /* Setup early boot stage 4 level pagetables. */
17256 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17257 movl $MSR_EFER, %ecx
17258 rdmsr
17259 btsl $_EFER_SCE, %eax /* Enable System Call */
17260 - btl $20,%edi /* No Execute supported? */
17261 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17262 jnc 1f
17263 btsl $_EFER_NX, %eax
17264 + leaq init_level4_pgt(%rip), %rdi
17265 +#ifndef CONFIG_EFI
17266 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17267 +#endif
17268 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17269 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17270 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17271 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17272 1: wrmsr /* Make changes effective */
17273
17274 /* Setup cr0 */
17275 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17276 * jump. In addition we need to ensure %cs is set so we make this
17277 * a far return.
17278 */
17279 + pax_set_fptr_mask
17280 movq initial_code(%rip),%rax
17281 pushq $0 # fake return address to stop unwinder
17282 pushq $__KERNEL_CS # set correct cs
17283 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17284 bad_address:
17285 jmp bad_address
17286
17287 - .section ".init.text","ax"
17288 + __INIT
17289 .globl early_idt_handlers
17290 early_idt_handlers:
17291 # 104(%rsp) %rflags
17292 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17293 addq $16,%rsp # drop vector number and error code
17294 decl early_recursion_flag(%rip)
17295 INTERRUPT_RETURN
17296 + .previous
17297
17298 + __INITDATA
17299 .balign 4
17300 early_recursion_flag:
17301 .long 0
17302 + .previous
17303
17304 + .section .rodata,"a",@progbits
17305 #ifdef CONFIG_EARLY_PRINTK
17306 early_idt_msg:
17307 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17308 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17309 #endif /* CONFIG_EARLY_PRINTK */
17310 .previous
17311
17312 + .section .rodata,"a",@progbits
17313 #define NEXT_PAGE(name) \
17314 .balign PAGE_SIZE; \
17315 ENTRY(name)
17316 @@ -372,7 +382,6 @@ ENTRY(name)
17317 i = i + 1 ; \
17318 .endr
17319
17320 - .data
17321 /*
17322 * This default setting generates an ident mapping at address 0x100000
17323 * and a mapping for the kernel that precisely maps virtual address
17324 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17325 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17326 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17327 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17328 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17329 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17330 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17331 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17332 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17333 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17334 .org init_level4_pgt + L4_START_KERNEL*8, 0
17335 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17336 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17337
17338 +#ifdef CONFIG_PAX_PER_CPU_PGD
17339 +NEXT_PAGE(cpu_pgd)
17340 + .rept NR_CPUS
17341 + .fill 512,8,0
17342 + .endr
17343 +#endif
17344 +
17345 NEXT_PAGE(level3_ident_pgt)
17346 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17347 +#ifdef CONFIG_XEN
17348 .fill 511,8,0
17349 +#else
17350 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17351 + .fill 510,8,0
17352 +#endif
17353 +
17354 +NEXT_PAGE(level3_vmalloc_start_pgt)
17355 + .fill 512,8,0
17356 +
17357 +NEXT_PAGE(level3_vmalloc_end_pgt)
17358 + .fill 512,8,0
17359 +
17360 +NEXT_PAGE(level3_vmemmap_pgt)
17361 + .fill L3_VMEMMAP_START,8,0
17362 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17363
17364 NEXT_PAGE(level3_kernel_pgt)
17365 .fill L3_START_KERNEL,8,0
17366 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17367 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17368 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17369
17370 +NEXT_PAGE(level2_vmemmap_pgt)
17371 + .fill 512,8,0
17372 +
17373 NEXT_PAGE(level2_fixmap_pgt)
17374 - .fill 506,8,0
17375 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17376 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17377 - .fill 5,8,0
17378 + .fill 507,8,0
17379 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17380 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17381 + .fill 4,8,0
17382
17383 -NEXT_PAGE(level1_fixmap_pgt)
17384 +NEXT_PAGE(level1_vsyscall_pgt)
17385 .fill 512,8,0
17386
17387 -NEXT_PAGE(level2_ident_pgt)
17388 - /* Since I easily can, map the first 1G.
17389 + /* Since I easily can, map the first 2G.
17390 * Don't set NX because code runs from these pages.
17391 */
17392 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17393 +NEXT_PAGE(level2_ident_pgt)
17394 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17395
17396 NEXT_PAGE(level2_kernel_pgt)
17397 /*
17398 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17399 * If you want to increase this then increase MODULES_VADDR
17400 * too.)
17401 */
17402 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17403 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17404 -
17405 -NEXT_PAGE(level2_spare_pgt)
17406 - .fill 512, 8, 0
17407 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17408
17409 #undef PMDS
17410 #undef NEXT_PAGE
17411
17412 - .data
17413 + .align PAGE_SIZE
17414 +ENTRY(cpu_gdt_table)
17415 + .rept NR_CPUS
17416 + .quad 0x0000000000000000 /* NULL descriptor */
17417 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17418 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17419 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17420 + .quad 0x00cffb000000ffff /* __USER32_CS */
17421 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17422 + .quad 0x00affb000000ffff /* __USER_CS */
17423 +
17424 +#ifdef CONFIG_PAX_KERNEXEC
17425 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17426 +#else
17427 + .quad 0x0 /* unused */
17428 +#endif
17429 +
17430 + .quad 0,0 /* TSS */
17431 + .quad 0,0 /* LDT */
17432 + .quad 0,0,0 /* three TLS descriptors */
17433 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17434 + /* asm/segment.h:GDT_ENTRIES must match this */
17435 +
17436 + /* zero the remaining page */
17437 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17438 + .endr
17439 +
17440 .align 16
17441 .globl early_gdt_descr
17442 early_gdt_descr:
17443 .word GDT_ENTRIES*8-1
17444 early_gdt_descr_base:
17445 - .quad INIT_PER_CPU_VAR(gdt_page)
17446 + .quad cpu_gdt_table
17447
17448 ENTRY(phys_base)
17449 /* This must match the first entry in level2_kernel_pgt */
17450 .quad 0x0000000000000000
17451
17452 #include "../../x86/xen/xen-head.S"
17453 -
17454 - .section .bss, "aw", @nobits
17455 +
17456 + .section .rodata,"a",@progbits
17457 .align L1_CACHE_BYTES
17458 ENTRY(idt_table)
17459 - .skip IDT_ENTRIES * 16
17460 + .fill 512,8,0
17461
17462 .align L1_CACHE_BYTES
17463 ENTRY(nmi_idt_table)
17464 - .skip IDT_ENTRIES * 16
17465 + .fill 512,8,0
17466
17467 __PAGE_ALIGNED_BSS
17468 .align PAGE_SIZE
17469 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17470 index 9c3bd4a..e1d9b35 100644
17471 --- a/arch/x86/kernel/i386_ksyms_32.c
17472 +++ b/arch/x86/kernel/i386_ksyms_32.c
17473 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17474 EXPORT_SYMBOL(cmpxchg8b_emu);
17475 #endif
17476
17477 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17478 +
17479 /* Networking helper routines. */
17480 EXPORT_SYMBOL(csum_partial_copy_generic);
17481 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17482 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17483
17484 EXPORT_SYMBOL(__get_user_1);
17485 EXPORT_SYMBOL(__get_user_2);
17486 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17487
17488 EXPORT_SYMBOL(csum_partial);
17489 EXPORT_SYMBOL(empty_zero_page);
17490 +
17491 +#ifdef CONFIG_PAX_KERNEXEC
17492 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17493 +#endif
17494 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17495 index f250431..54097e7 100644
17496 --- a/arch/x86/kernel/i387.c
17497 +++ b/arch/x86/kernel/i387.c
17498 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17499 static inline bool interrupted_user_mode(void)
17500 {
17501 struct pt_regs *regs = get_irq_regs();
17502 - return regs && user_mode_vm(regs);
17503 + return regs && user_mode(regs);
17504 }
17505
17506 /*
17507 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17508 index 36d1853..bf25736 100644
17509 --- a/arch/x86/kernel/i8259.c
17510 +++ b/arch/x86/kernel/i8259.c
17511 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17512 "spurious 8259A interrupt: IRQ%d.\n", irq);
17513 spurious_irq_mask |= irqmask;
17514 }
17515 - atomic_inc(&irq_err_count);
17516 + atomic_inc_unchecked(&irq_err_count);
17517 /*
17518 * Theoretically we do not have to handle this IRQ,
17519 * but in Linux this does not cause problems and is
17520 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17521 index 8c96897..be66bfa 100644
17522 --- a/arch/x86/kernel/ioport.c
17523 +++ b/arch/x86/kernel/ioport.c
17524 @@ -6,6 +6,7 @@
17525 #include <linux/sched.h>
17526 #include <linux/kernel.h>
17527 #include <linux/capability.h>
17528 +#include <linux/security.h>
17529 #include <linux/errno.h>
17530 #include <linux/types.h>
17531 #include <linux/ioport.h>
17532 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17533
17534 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17535 return -EINVAL;
17536 +#ifdef CONFIG_GRKERNSEC_IO
17537 + if (turn_on && grsec_disable_privio) {
17538 + gr_handle_ioperm();
17539 + return -EPERM;
17540 + }
17541 +#endif
17542 if (turn_on && !capable(CAP_SYS_RAWIO))
17543 return -EPERM;
17544
17545 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17546 * because the ->io_bitmap_max value must match the bitmap
17547 * contents:
17548 */
17549 - tss = &per_cpu(init_tss, get_cpu());
17550 + tss = init_tss + get_cpu();
17551
17552 if (turn_on)
17553 bitmap_clear(t->io_bitmap_ptr, from, num);
17554 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17555 return -EINVAL;
17556 /* Trying to gain more privileges? */
17557 if (level > old) {
17558 +#ifdef CONFIG_GRKERNSEC_IO
17559 + if (grsec_disable_privio) {
17560 + gr_handle_iopl();
17561 + return -EPERM;
17562 + }
17563 +#endif
17564 if (!capable(CAP_SYS_RAWIO))
17565 return -EPERM;
17566 }
17567 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17568 index 3dafc60..aa8e9c4 100644
17569 --- a/arch/x86/kernel/irq.c
17570 +++ b/arch/x86/kernel/irq.c
17571 @@ -18,7 +18,7 @@
17572 #include <asm/mce.h>
17573 #include <asm/hw_irq.h>
17574
17575 -atomic_t irq_err_count;
17576 +atomic_unchecked_t irq_err_count;
17577
17578 /* Function pointer for generic interrupt vector handling */
17579 void (*x86_platform_ipi_callback)(void) = NULL;
17580 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17581 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17582 seq_printf(p, " Machine check polls\n");
17583 #endif
17584 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17585 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17586 #if defined(CONFIG_X86_IO_APIC)
17587 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17588 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17589 #endif
17590 return 0;
17591 }
17592 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17593
17594 u64 arch_irq_stat(void)
17595 {
17596 - u64 sum = atomic_read(&irq_err_count);
17597 + u64 sum = atomic_read_unchecked(&irq_err_count);
17598
17599 #ifdef CONFIG_X86_IO_APIC
17600 - sum += atomic_read(&irq_mis_count);
17601 + sum += atomic_read_unchecked(&irq_mis_count);
17602 #endif
17603 return sum;
17604 }
17605 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17606 index 344faf8..355f60d 100644
17607 --- a/arch/x86/kernel/irq_32.c
17608 +++ b/arch/x86/kernel/irq_32.c
17609 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17610 __asm__ __volatile__("andl %%esp,%0" :
17611 "=r" (sp) : "0" (THREAD_SIZE - 1));
17612
17613 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17614 + return sp < STACK_WARN;
17615 }
17616
17617 static void print_stack_overflow(void)
17618 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17619 * per-CPU IRQ handling contexts (thread information and stack)
17620 */
17621 union irq_ctx {
17622 - struct thread_info tinfo;
17623 - u32 stack[THREAD_SIZE/sizeof(u32)];
17624 + unsigned long previous_esp;
17625 + u32 stack[THREAD_SIZE/sizeof(u32)];
17626 } __attribute__((aligned(THREAD_SIZE)));
17627
17628 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17629 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17630 static inline int
17631 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17632 {
17633 - union irq_ctx *curctx, *irqctx;
17634 + union irq_ctx *irqctx;
17635 u32 *isp, arg1, arg2;
17636
17637 - curctx = (union irq_ctx *) current_thread_info();
17638 irqctx = __this_cpu_read(hardirq_ctx);
17639
17640 /*
17641 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17642 * handler) we can't do that and just have to keep using the
17643 * current stack (which is the irq stack already after all)
17644 */
17645 - if (unlikely(curctx == irqctx))
17646 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17647 return 0;
17648
17649 /* build the stack frame on the IRQ stack */
17650 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17651 - irqctx->tinfo.task = curctx->tinfo.task;
17652 - irqctx->tinfo.previous_esp = current_stack_pointer;
17653 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17654 + irqctx->previous_esp = current_stack_pointer;
17655
17656 - /* Copy the preempt_count so that the [soft]irq checks work. */
17657 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17659 + __set_fs(MAKE_MM_SEG(0));
17660 +#endif
17661
17662 if (unlikely(overflow))
17663 call_on_stack(print_stack_overflow, isp);
17664 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17665 : "0" (irq), "1" (desc), "2" (isp),
17666 "D" (desc->handle_irq)
17667 : "memory", "cc", "ecx");
17668 +
17669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17670 + __set_fs(current_thread_info()->addr_limit);
17671 +#endif
17672 +
17673 return 1;
17674 }
17675
17676 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17677 */
17678 void __cpuinit irq_ctx_init(int cpu)
17679 {
17680 - union irq_ctx *irqctx;
17681 -
17682 if (per_cpu(hardirq_ctx, cpu))
17683 return;
17684
17685 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17686 - THREADINFO_GFP,
17687 - THREAD_SIZE_ORDER));
17688 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17689 - irqctx->tinfo.cpu = cpu;
17690 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17691 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17692 -
17693 - per_cpu(hardirq_ctx, cpu) = irqctx;
17694 -
17695 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17696 - THREADINFO_GFP,
17697 - THREAD_SIZE_ORDER));
17698 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17699 - irqctx->tinfo.cpu = cpu;
17700 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17701 -
17702 - per_cpu(softirq_ctx, cpu) = irqctx;
17703 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17704 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17705 +
17706 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17707 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17708
17709 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17710 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17711 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17712 asmlinkage void do_softirq(void)
17713 {
17714 unsigned long flags;
17715 - struct thread_info *curctx;
17716 union irq_ctx *irqctx;
17717 u32 *isp;
17718
17719 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17720 local_irq_save(flags);
17721
17722 if (local_softirq_pending()) {
17723 - curctx = current_thread_info();
17724 irqctx = __this_cpu_read(softirq_ctx);
17725 - irqctx->tinfo.task = curctx->task;
17726 - irqctx->tinfo.previous_esp = current_stack_pointer;
17727 + irqctx->previous_esp = current_stack_pointer;
17728
17729 /* build the stack frame on the softirq stack */
17730 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17731 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17732 +
17733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17734 + __set_fs(MAKE_MM_SEG(0));
17735 +#endif
17736
17737 call_on_stack(__do_softirq, isp);
17738 +
17739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17740 + __set_fs(current_thread_info()->addr_limit);
17741 +#endif
17742 +
17743 /*
17744 * Shouldn't happen, we returned above if in_interrupt():
17745 */
17746 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17747 if (unlikely(!desc))
17748 return false;
17749
17750 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17751 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17752 if (unlikely(overflow))
17753 print_stack_overflow();
17754 desc->handle_irq(irq, desc);
17755 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17756 index d04d3ec..ea4b374 100644
17757 --- a/arch/x86/kernel/irq_64.c
17758 +++ b/arch/x86/kernel/irq_64.c
17759 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17760 u64 estack_top, estack_bottom;
17761 u64 curbase = (u64)task_stack_page(current);
17762
17763 - if (user_mode_vm(regs))
17764 + if (user_mode(regs))
17765 return;
17766
17767 if (regs->sp >= curbase + sizeof(struct thread_info) +
17768 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17769 index 1d5d31e..72731d4 100644
17770 --- a/arch/x86/kernel/kdebugfs.c
17771 +++ b/arch/x86/kernel/kdebugfs.c
17772 @@ -27,7 +27,7 @@ struct setup_data_node {
17773 u32 len;
17774 };
17775
17776 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17777 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17778 size_t count, loff_t *ppos)
17779 {
17780 struct setup_data_node *node = file->private_data;
17781 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17782 index 3f61904..873cea9 100644
17783 --- a/arch/x86/kernel/kgdb.c
17784 +++ b/arch/x86/kernel/kgdb.c
17785 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17786 #ifdef CONFIG_X86_32
17787 switch (regno) {
17788 case GDB_SS:
17789 - if (!user_mode_vm(regs))
17790 + if (!user_mode(regs))
17791 *(unsigned long *)mem = __KERNEL_DS;
17792 break;
17793 case GDB_SP:
17794 - if (!user_mode_vm(regs))
17795 + if (!user_mode(regs))
17796 *(unsigned long *)mem = kernel_stack_pointer(regs);
17797 break;
17798 case GDB_GS:
17799 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17800 case 'k':
17801 /* clear the trace bit */
17802 linux_regs->flags &= ~X86_EFLAGS_TF;
17803 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17804 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17805
17806 /* set the trace bit if we're stepping */
17807 if (remcomInBuffer[0] == 's') {
17808 linux_regs->flags |= X86_EFLAGS_TF;
17809 - atomic_set(&kgdb_cpu_doing_single_step,
17810 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17811 raw_smp_processor_id());
17812 }
17813
17814 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17815
17816 switch (cmd) {
17817 case DIE_DEBUG:
17818 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17819 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17820 if (user_mode(regs))
17821 return single_step_cont(regs, args);
17822 break;
17823 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17824 index c5e410e..da6aaf9 100644
17825 --- a/arch/x86/kernel/kprobes-opt.c
17826 +++ b/arch/x86/kernel/kprobes-opt.c
17827 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17828 * Verify if the address gap is in 2GB range, because this uses
17829 * a relative jump.
17830 */
17831 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17832 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17833 if (abs(rel) > 0x7fffffff)
17834 return -ERANGE;
17835
17836 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17837 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17838
17839 /* Set probe function call */
17840 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17841 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17842
17843 /* Set returning jmp instruction at the tail of out-of-line buffer */
17844 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17845 - (u8 *)op->kp.addr + op->optinsn.size);
17846 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17847
17848 flush_icache_range((unsigned long) buf,
17849 (unsigned long) buf + TMPL_END_IDX +
17850 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17851 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17852
17853 /* Backup instructions which will be replaced by jump address */
17854 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17855 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17856 RELATIVE_ADDR_SIZE);
17857
17858 insn_buf[0] = RELATIVEJUMP_OPCODE;
17859 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17860 index e2f751e..dffa2a0 100644
17861 --- a/arch/x86/kernel/kprobes.c
17862 +++ b/arch/x86/kernel/kprobes.c
17863 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17864 } __attribute__((packed)) *insn;
17865
17866 insn = (struct __arch_relative_insn *)from;
17867 +
17868 + pax_open_kernel();
17869 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17870 insn->op = op;
17871 + pax_close_kernel();
17872 }
17873
17874 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17875 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17876 kprobe_opcode_t opcode;
17877 kprobe_opcode_t *orig_opcodes = opcodes;
17878
17879 - if (search_exception_tables((unsigned long)opcodes))
17880 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17881 return 0; /* Page fault may occur on this address. */
17882
17883 retry:
17884 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17885 /* Another subsystem puts a breakpoint, failed to recover */
17886 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17887 return 0;
17888 + pax_open_kernel();
17889 memcpy(dest, insn.kaddr, insn.length);
17890 + pax_close_kernel();
17891
17892 #ifdef CONFIG_X86_64
17893 if (insn_rip_relative(&insn)) {
17894 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17895 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17896 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17897 disp = (u8 *) dest + insn_offset_displacement(&insn);
17898 + pax_open_kernel();
17899 *(s32 *) disp = (s32) newdisp;
17900 + pax_close_kernel();
17901 }
17902 #endif
17903 return insn.length;
17904 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17905 * nor set current_kprobe, because it doesn't use single
17906 * stepping.
17907 */
17908 - regs->ip = (unsigned long)p->ainsn.insn;
17909 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17910 preempt_enable_no_resched();
17911 return;
17912 }
17913 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17914 if (p->opcode == BREAKPOINT_INSTRUCTION)
17915 regs->ip = (unsigned long)p->addr;
17916 else
17917 - regs->ip = (unsigned long)p->ainsn.insn;
17918 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17919 }
17920
17921 /*
17922 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17923 setup_singlestep(p, regs, kcb, 0);
17924 return 1;
17925 }
17926 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17927 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17928 /*
17929 * The breakpoint instruction was removed right
17930 * after we hit it. Another cpu has removed
17931 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17932 " movq %rax, 152(%rsp)\n"
17933 RESTORE_REGS_STRING
17934 " popfq\n"
17935 +#ifdef KERNEXEC_PLUGIN
17936 + " btsq $63,(%rsp)\n"
17937 +#endif
17938 #else
17939 " pushf\n"
17940 SAVE_REGS_STRING
17941 @@ -765,7 +775,7 @@ static void __kprobes
17942 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17943 {
17944 unsigned long *tos = stack_addr(regs);
17945 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17946 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17947 unsigned long orig_ip = (unsigned long)p->addr;
17948 kprobe_opcode_t *insn = p->ainsn.insn;
17949
17950 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17951 struct die_args *args = data;
17952 int ret = NOTIFY_DONE;
17953
17954 - if (args->regs && user_mode_vm(args->regs))
17955 + if (args->regs && user_mode(args->regs))
17956 return ret;
17957
17958 switch (val) {
17959 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17960 index ebc9873..1b9724b 100644
17961 --- a/arch/x86/kernel/ldt.c
17962 +++ b/arch/x86/kernel/ldt.c
17963 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17964 if (reload) {
17965 #ifdef CONFIG_SMP
17966 preempt_disable();
17967 - load_LDT(pc);
17968 + load_LDT_nolock(pc);
17969 if (!cpumask_equal(mm_cpumask(current->mm),
17970 cpumask_of(smp_processor_id())))
17971 smp_call_function(flush_ldt, current->mm, 1);
17972 preempt_enable();
17973 #else
17974 - load_LDT(pc);
17975 + load_LDT_nolock(pc);
17976 #endif
17977 }
17978 if (oldsize) {
17979 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17980 return err;
17981
17982 for (i = 0; i < old->size; i++)
17983 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17984 + write_ldt_entry(new->ldt, i, old->ldt + i);
17985 return 0;
17986 }
17987
17988 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17989 retval = copy_ldt(&mm->context, &old_mm->context);
17990 mutex_unlock(&old_mm->context.lock);
17991 }
17992 +
17993 + if (tsk == current) {
17994 + mm->context.vdso = 0;
17995 +
17996 +#ifdef CONFIG_X86_32
17997 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17998 + mm->context.user_cs_base = 0UL;
17999 + mm->context.user_cs_limit = ~0UL;
18000 +
18001 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18002 + cpus_clear(mm->context.cpu_user_cs_mask);
18003 +#endif
18004 +
18005 +#endif
18006 +#endif
18007 +
18008 + }
18009 +
18010 return retval;
18011 }
18012
18013 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18014 }
18015 }
18016
18017 +#ifdef CONFIG_PAX_SEGMEXEC
18018 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18019 + error = -EINVAL;
18020 + goto out_unlock;
18021 + }
18022 +#endif
18023 +
18024 fill_ldt(&ldt, &ldt_info);
18025 if (oldmode)
18026 ldt.avl = 0;
18027 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18028 index 5b19e4d..6476a76 100644
18029 --- a/arch/x86/kernel/machine_kexec_32.c
18030 +++ b/arch/x86/kernel/machine_kexec_32.c
18031 @@ -26,7 +26,7 @@
18032 #include <asm/cacheflush.h>
18033 #include <asm/debugreg.h>
18034
18035 -static void set_idt(void *newidt, __u16 limit)
18036 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18037 {
18038 struct desc_ptr curidt;
18039
18040 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18041 }
18042
18043
18044 -static void set_gdt(void *newgdt, __u16 limit)
18045 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18046 {
18047 struct desc_ptr curgdt;
18048
18049 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18050 }
18051
18052 control_page = page_address(image->control_code_page);
18053 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18054 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18055
18056 relocate_kernel_ptr = control_page;
18057 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18058 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18059 index 0327e2b..e43737b 100644
18060 --- a/arch/x86/kernel/microcode_intel.c
18061 +++ b/arch/x86/kernel/microcode_intel.c
18062 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18063
18064 static int get_ucode_user(void *to, const void *from, size_t n)
18065 {
18066 - return copy_from_user(to, from, n);
18067 + return copy_from_user(to, (const void __force_user *)from, n);
18068 }
18069
18070 static enum ucode_state
18071 request_microcode_user(int cpu, const void __user *buf, size_t size)
18072 {
18073 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18074 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18075 }
18076
18077 static void microcode_fini_cpu(int cpu)
18078 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18079 index f21fd94..61565cd 100644
18080 --- a/arch/x86/kernel/module.c
18081 +++ b/arch/x86/kernel/module.c
18082 @@ -35,15 +35,60 @@
18083 #define DEBUGP(fmt...)
18084 #endif
18085
18086 -void *module_alloc(unsigned long size)
18087 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18088 {
18089 - if (PAGE_ALIGN(size) > MODULES_LEN)
18090 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18091 return NULL;
18092 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18093 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18094 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18095 -1, __builtin_return_address(0));
18096 }
18097
18098 +void *module_alloc(unsigned long size)
18099 +{
18100 +
18101 +#ifdef CONFIG_PAX_KERNEXEC
18102 + return __module_alloc(size, PAGE_KERNEL);
18103 +#else
18104 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18105 +#endif
18106 +
18107 +}
18108 +
18109 +#ifdef CONFIG_PAX_KERNEXEC
18110 +#ifdef CONFIG_X86_32
18111 +void *module_alloc_exec(unsigned long size)
18112 +{
18113 + struct vm_struct *area;
18114 +
18115 + if (size == 0)
18116 + return NULL;
18117 +
18118 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18119 + return area ? area->addr : NULL;
18120 +}
18121 +EXPORT_SYMBOL(module_alloc_exec);
18122 +
18123 +void module_free_exec(struct module *mod, void *module_region)
18124 +{
18125 + vunmap(module_region);
18126 +}
18127 +EXPORT_SYMBOL(module_free_exec);
18128 +#else
18129 +void module_free_exec(struct module *mod, void *module_region)
18130 +{
18131 + module_free(mod, module_region);
18132 +}
18133 +EXPORT_SYMBOL(module_free_exec);
18134 +
18135 +void *module_alloc_exec(unsigned long size)
18136 +{
18137 + return __module_alloc(size, PAGE_KERNEL_RX);
18138 +}
18139 +EXPORT_SYMBOL(module_alloc_exec);
18140 +#endif
18141 +#endif
18142 +
18143 #ifdef CONFIG_X86_32
18144 int apply_relocate(Elf32_Shdr *sechdrs,
18145 const char *strtab,
18146 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18147 unsigned int i;
18148 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18149 Elf32_Sym *sym;
18150 - uint32_t *location;
18151 + uint32_t *plocation, location;
18152
18153 DEBUGP("Applying relocate section %u to %u\n", relsec,
18154 sechdrs[relsec].sh_info);
18155 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18156 /* This is where to make the change */
18157 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18158 - + rel[i].r_offset;
18159 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18160 + location = (uint32_t)plocation;
18161 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18162 + plocation = ktla_ktva((void *)plocation);
18163 /* This is the symbol it is referring to. Note that all
18164 undefined symbols have been resolved. */
18165 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18166 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18167 switch (ELF32_R_TYPE(rel[i].r_info)) {
18168 case R_386_32:
18169 /* We add the value into the location given */
18170 - *location += sym->st_value;
18171 + pax_open_kernel();
18172 + *plocation += sym->st_value;
18173 + pax_close_kernel();
18174 break;
18175 case R_386_PC32:
18176 /* Add the value, subtract its postition */
18177 - *location += sym->st_value - (uint32_t)location;
18178 + pax_open_kernel();
18179 + *plocation += sym->st_value - location;
18180 + pax_close_kernel();
18181 break;
18182 default:
18183 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18184 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18185 case R_X86_64_NONE:
18186 break;
18187 case R_X86_64_64:
18188 + pax_open_kernel();
18189 *(u64 *)loc = val;
18190 + pax_close_kernel();
18191 break;
18192 case R_X86_64_32:
18193 + pax_open_kernel();
18194 *(u32 *)loc = val;
18195 + pax_close_kernel();
18196 if (val != *(u32 *)loc)
18197 goto overflow;
18198 break;
18199 case R_X86_64_32S:
18200 + pax_open_kernel();
18201 *(s32 *)loc = val;
18202 + pax_close_kernel();
18203 if ((s64)val != *(s32 *)loc)
18204 goto overflow;
18205 break;
18206 case R_X86_64_PC32:
18207 val -= (u64)loc;
18208 + pax_open_kernel();
18209 *(u32 *)loc = val;
18210 + pax_close_kernel();
18211 +
18212 #if 0
18213 if ((s64)val != *(s32 *)loc)
18214 goto overflow;
18215 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18216 index a0b2f84..875ab81 100644
18217 --- a/arch/x86/kernel/nmi.c
18218 +++ b/arch/x86/kernel/nmi.c
18219 @@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18220 dotraplinkage notrace __kprobes void
18221 do_nmi(struct pt_regs *regs, long error_code)
18222 {
18223 +
18224 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18225 + if (!user_mode(regs)) {
18226 + unsigned long cs = regs->cs & 0xFFFF;
18227 + unsigned long ip = ktva_ktla(regs->ip);
18228 +
18229 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18230 + regs->ip = ip;
18231 + }
18232 +#endif
18233 +
18234 nmi_nesting_preprocess(regs);
18235
18236 nmi_enter();
18237 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18238 index 676b8c7..870ba04 100644
18239 --- a/arch/x86/kernel/paravirt-spinlocks.c
18240 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18241 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18242 arch_spin_lock(lock);
18243 }
18244
18245 -struct pv_lock_ops pv_lock_ops = {
18246 +struct pv_lock_ops pv_lock_ops __read_only = {
18247 #ifdef CONFIG_SMP
18248 .spin_is_locked = __ticket_spin_is_locked,
18249 .spin_is_contended = __ticket_spin_is_contended,
18250 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18251 index 9ce8859..b49bf51 100644
18252 --- a/arch/x86/kernel/paravirt.c
18253 +++ b/arch/x86/kernel/paravirt.c
18254 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18255 {
18256 return x;
18257 }
18258 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18259 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18260 +#endif
18261
18262 void __init default_banner(void)
18263 {
18264 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18265 if (opfunc == NULL)
18266 /* If there's no function, patch it with a ud2a (BUG) */
18267 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18268 - else if (opfunc == _paravirt_nop)
18269 + else if (opfunc == (void *)_paravirt_nop)
18270 /* If the operation is a nop, then nop the callsite */
18271 ret = paravirt_patch_nop();
18272
18273 /* identity functions just return their single argument */
18274 - else if (opfunc == _paravirt_ident_32)
18275 + else if (opfunc == (void *)_paravirt_ident_32)
18276 ret = paravirt_patch_ident_32(insnbuf, len);
18277 - else if (opfunc == _paravirt_ident_64)
18278 + else if (opfunc == (void *)_paravirt_ident_64)
18279 ret = paravirt_patch_ident_64(insnbuf, len);
18280 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18281 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18282 + ret = paravirt_patch_ident_64(insnbuf, len);
18283 +#endif
18284
18285 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18286 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18287 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18288 if (insn_len > len || start == NULL)
18289 insn_len = len;
18290 else
18291 - memcpy(insnbuf, start, insn_len);
18292 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18293
18294 return insn_len;
18295 }
18296 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18297 preempt_enable();
18298 }
18299
18300 -struct pv_info pv_info = {
18301 +struct pv_info pv_info __read_only = {
18302 .name = "bare hardware",
18303 .paravirt_enabled = 0,
18304 .kernel_rpl = 0,
18305 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18306 #endif
18307 };
18308
18309 -struct pv_init_ops pv_init_ops = {
18310 +struct pv_init_ops pv_init_ops __read_only = {
18311 .patch = native_patch,
18312 };
18313
18314 -struct pv_time_ops pv_time_ops = {
18315 +struct pv_time_ops pv_time_ops __read_only = {
18316 .sched_clock = native_sched_clock,
18317 .steal_clock = native_steal_clock,
18318 };
18319
18320 -struct pv_irq_ops pv_irq_ops = {
18321 +struct pv_irq_ops pv_irq_ops __read_only = {
18322 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18323 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18324 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18325 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18326 #endif
18327 };
18328
18329 -struct pv_cpu_ops pv_cpu_ops = {
18330 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18331 .cpuid = native_cpuid,
18332 .get_debugreg = native_get_debugreg,
18333 .set_debugreg = native_set_debugreg,
18334 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18335 .end_context_switch = paravirt_nop,
18336 };
18337
18338 -struct pv_apic_ops pv_apic_ops = {
18339 +struct pv_apic_ops pv_apic_ops __read_only = {
18340 #ifdef CONFIG_X86_LOCAL_APIC
18341 .startup_ipi_hook = paravirt_nop,
18342 #endif
18343 };
18344
18345 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18346 +#ifdef CONFIG_X86_32
18347 +#ifdef CONFIG_X86_PAE
18348 +/* 64-bit pagetable entries */
18349 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18350 +#else
18351 /* 32-bit pagetable entries */
18352 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18353 +#endif
18354 #else
18355 /* 64-bit pagetable entries */
18356 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18357 #endif
18358
18359 -struct pv_mmu_ops pv_mmu_ops = {
18360 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18361
18362 .read_cr2 = native_read_cr2,
18363 .write_cr2 = native_write_cr2,
18364 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18365 .make_pud = PTE_IDENT,
18366
18367 .set_pgd = native_set_pgd,
18368 + .set_pgd_batched = native_set_pgd_batched,
18369 #endif
18370 #endif /* PAGETABLE_LEVELS >= 3 */
18371
18372 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18373 },
18374
18375 .set_fixmap = native_set_fixmap,
18376 +
18377 +#ifdef CONFIG_PAX_KERNEXEC
18378 + .pax_open_kernel = native_pax_open_kernel,
18379 + .pax_close_kernel = native_pax_close_kernel,
18380 +#endif
18381 +
18382 };
18383
18384 EXPORT_SYMBOL_GPL(pv_time_ops);
18385 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18386 index 35ccf75..7a15747 100644
18387 --- a/arch/x86/kernel/pci-iommu_table.c
18388 +++ b/arch/x86/kernel/pci-iommu_table.c
18389 @@ -2,7 +2,7 @@
18390 #include <asm/iommu_table.h>
18391 #include <linux/string.h>
18392 #include <linux/kallsyms.h>
18393 -
18394 +#include <linux/sched.h>
18395
18396 #define DEBUG 1
18397
18398 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18399 index 735279e..5008677 100644
18400 --- a/arch/x86/kernel/process.c
18401 +++ b/arch/x86/kernel/process.c
18402 @@ -34,7 +34,8 @@
18403 * section. Since TSS's are completely CPU-local, we want them
18404 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18405 */
18406 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18407 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18408 +EXPORT_SYMBOL(init_tss);
18409
18410 #ifdef CONFIG_X86_64
18411 static DEFINE_PER_CPU(unsigned char, is_idle);
18412 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18413 task_xstate_cachep =
18414 kmem_cache_create("task_xstate", xstate_size,
18415 __alignof__(union thread_xstate),
18416 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18417 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18418 }
18419
18420 static inline void drop_fpu(struct task_struct *tsk)
18421 @@ -115,7 +116,7 @@ void exit_thread(void)
18422 unsigned long *bp = t->io_bitmap_ptr;
18423
18424 if (bp) {
18425 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18426 + struct tss_struct *tss = init_tss + get_cpu();
18427
18428 t->io_bitmap_ptr = NULL;
18429 clear_thread_flag(TIF_IO_BITMAP);
18430 @@ -147,7 +148,7 @@ void show_regs_common(void)
18431
18432 printk(KERN_CONT "\n");
18433 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18434 - current->pid, current->comm, print_tainted(),
18435 + task_pid_nr(current), current->comm, print_tainted(),
18436 init_utsname()->release,
18437 (int)strcspn(init_utsname()->version, " "),
18438 init_utsname()->version);
18439 @@ -161,6 +162,9 @@ void flush_thread(void)
18440 {
18441 struct task_struct *tsk = current;
18442
18443 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18444 + loadsegment(gs, 0);
18445 +#endif
18446 flush_ptrace_hw_breakpoint(tsk);
18447 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18448 drop_fpu(tsk);
18449 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18450 regs.di = (unsigned long) arg;
18451
18452 #ifdef CONFIG_X86_32
18453 - regs.ds = __USER_DS;
18454 - regs.es = __USER_DS;
18455 + regs.ds = __KERNEL_DS;
18456 + regs.es = __KERNEL_DS;
18457 regs.fs = __KERNEL_PERCPU;
18458 - regs.gs = __KERNEL_STACK_CANARY;
18459 + savesegment(gs, regs.gs);
18460 #else
18461 regs.ss = __KERNEL_DS;
18462 #endif
18463 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18464 void exit_idle(void)
18465 {
18466 /* idle loop has pid 0 */
18467 - if (current->pid)
18468 + if (task_pid_nr(current))
18469 return;
18470 __exit_idle();
18471 }
18472 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18473
18474 return ret;
18475 }
18476 -void stop_this_cpu(void *dummy)
18477 +__noreturn void stop_this_cpu(void *dummy)
18478 {
18479 local_irq_disable();
18480 /*
18481 @@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18482 }
18483 early_param("idle", idle_setup);
18484
18485 -unsigned long arch_align_stack(unsigned long sp)
18486 +#ifdef CONFIG_PAX_RANDKSTACK
18487 +void pax_randomize_kstack(struct pt_regs *regs)
18488 {
18489 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18490 - sp -= get_random_int() % 8192;
18491 - return sp & ~0xf;
18492 -}
18493 + struct thread_struct *thread = &current->thread;
18494 + unsigned long time;
18495
18496 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18497 -{
18498 - unsigned long range_end = mm->brk + 0x02000000;
18499 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18500 -}
18501 + if (!randomize_va_space)
18502 + return;
18503 +
18504 + if (v8086_mode(regs))
18505 + return;
18506
18507 + rdtscl(time);
18508 +
18509 + /* P4 seems to return a 0 LSB, ignore it */
18510 +#ifdef CONFIG_MPENTIUM4
18511 + time &= 0x3EUL;
18512 + time <<= 2;
18513 +#elif defined(CONFIG_X86_64)
18514 + time &= 0xFUL;
18515 + time <<= 4;
18516 +#else
18517 + time &= 0x1FUL;
18518 + time <<= 3;
18519 +#endif
18520 +
18521 + thread->sp0 ^= time;
18522 + load_sp0(init_tss + smp_processor_id(), thread);
18523 +
18524 +#ifdef CONFIG_X86_64
18525 + this_cpu_write(kernel_stack, thread->sp0);
18526 +#endif
18527 +}
18528 +#endif
18529 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18530 index 516fa18..80bd9e6 100644
18531 --- a/arch/x86/kernel/process_32.c
18532 +++ b/arch/x86/kernel/process_32.c
18533 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18534 unsigned long thread_saved_pc(struct task_struct *tsk)
18535 {
18536 return ((unsigned long *)tsk->thread.sp)[3];
18537 +//XXX return tsk->thread.eip;
18538 }
18539
18540 void __show_regs(struct pt_regs *regs, int all)
18541 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18542 unsigned long sp;
18543 unsigned short ss, gs;
18544
18545 - if (user_mode_vm(regs)) {
18546 + if (user_mode(regs)) {
18547 sp = regs->sp;
18548 ss = regs->ss & 0xffff;
18549 - gs = get_user_gs(regs);
18550 } else {
18551 sp = kernel_stack_pointer(regs);
18552 savesegment(ss, ss);
18553 - savesegment(gs, gs);
18554 }
18555 + gs = get_user_gs(regs);
18556
18557 show_regs_common();
18558
18559 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18560 struct task_struct *tsk;
18561 int err;
18562
18563 - childregs = task_pt_regs(p);
18564 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18565 *childregs = *regs;
18566 childregs->ax = 0;
18567 childregs->sp = sp;
18568
18569 p->thread.sp = (unsigned long) childregs;
18570 p->thread.sp0 = (unsigned long) (childregs+1);
18571 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18572
18573 p->thread.ip = (unsigned long) ret_from_fork;
18574
18575 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18576 struct thread_struct *prev = &prev_p->thread,
18577 *next = &next_p->thread;
18578 int cpu = smp_processor_id();
18579 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18580 + struct tss_struct *tss = init_tss + cpu;
18581 fpu_switch_t fpu;
18582
18583 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18584 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18585 */
18586 lazy_save_gs(prev->gs);
18587
18588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18589 + __set_fs(task_thread_info(next_p)->addr_limit);
18590 +#endif
18591 +
18592 /*
18593 * Load the per-thread Thread-Local Storage descriptor.
18594 */
18595 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18596 */
18597 arch_end_context_switch(next_p);
18598
18599 + this_cpu_write(current_task, next_p);
18600 + this_cpu_write(current_tinfo, &next_p->tinfo);
18601 +
18602 /*
18603 * Restore %gs if needed (which is common)
18604 */
18605 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18606
18607 switch_fpu_finish(next_p, fpu);
18608
18609 - this_cpu_write(current_task, next_p);
18610 -
18611 return prev_p;
18612 }
18613
18614 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18615 } while (count++ < 16);
18616 return 0;
18617 }
18618 -
18619 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18620 index 61cdf7f..797f06a 100644
18621 --- a/arch/x86/kernel/process_64.c
18622 +++ b/arch/x86/kernel/process_64.c
18623 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18624 struct pt_regs *childregs;
18625 struct task_struct *me = current;
18626
18627 - childregs = ((struct pt_regs *)
18628 - (THREAD_SIZE + task_stack_page(p))) - 1;
18629 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18630 *childregs = *regs;
18631
18632 childregs->ax = 0;
18633 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18634 p->thread.sp = (unsigned long) childregs;
18635 p->thread.sp0 = (unsigned long) (childregs+1);
18636 p->thread.usersp = me->thread.usersp;
18637 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18638
18639 set_tsk_thread_flag(p, TIF_FORK);
18640
18641 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18642 struct thread_struct *prev = &prev_p->thread;
18643 struct thread_struct *next = &next_p->thread;
18644 int cpu = smp_processor_id();
18645 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18646 + struct tss_struct *tss = init_tss + cpu;
18647 unsigned fsindex, gsindex;
18648 fpu_switch_t fpu;
18649
18650 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18651 prev->usersp = this_cpu_read(old_rsp);
18652 this_cpu_write(old_rsp, next->usersp);
18653 this_cpu_write(current_task, next_p);
18654 + this_cpu_write(current_tinfo, &next_p->tinfo);
18655
18656 - this_cpu_write(kernel_stack,
18657 - (unsigned long)task_stack_page(next_p) +
18658 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18659 + this_cpu_write(kernel_stack, next->sp0);
18660
18661 /*
18662 * Now maybe reload the debug registers and handle I/O bitmaps
18663 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18664 if (!p || p == current || p->state == TASK_RUNNING)
18665 return 0;
18666 stack = (unsigned long)task_stack_page(p);
18667 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18668 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18669 return 0;
18670 fp = *(u64 *)(p->thread.sp);
18671 do {
18672 - if (fp < (unsigned long)stack ||
18673 - fp >= (unsigned long)stack+THREAD_SIZE)
18674 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18675 return 0;
18676 ip = *(u64 *)(fp+8);
18677 if (!in_sched_functions(ip))
18678 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18679 index c4c6a5c..905f440 100644
18680 --- a/arch/x86/kernel/ptrace.c
18681 +++ b/arch/x86/kernel/ptrace.c
18682 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18683 unsigned long addr, unsigned long data)
18684 {
18685 int ret;
18686 - unsigned long __user *datap = (unsigned long __user *)data;
18687 + unsigned long __user *datap = (__force unsigned long __user *)data;
18688
18689 switch (request) {
18690 /* read the word at location addr in the USER area. */
18691 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18692 if ((int) addr < 0)
18693 return -EIO;
18694 ret = do_get_thread_area(child, addr,
18695 - (struct user_desc __user *)data);
18696 + (__force struct user_desc __user *) data);
18697 break;
18698
18699 case PTRACE_SET_THREAD_AREA:
18700 if ((int) addr < 0)
18701 return -EIO;
18702 ret = do_set_thread_area(child, addr,
18703 - (struct user_desc __user *)data, 0);
18704 + (__force struct user_desc __user *) data, 0);
18705 break;
18706 #endif
18707
18708 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18709 memset(info, 0, sizeof(*info));
18710 info->si_signo = SIGTRAP;
18711 info->si_code = si_code;
18712 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18713 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18714 }
18715
18716 void user_single_step_siginfo(struct task_struct *tsk,
18717 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18718 # define IS_IA32 0
18719 #endif
18720
18721 +#ifdef CONFIG_GRKERNSEC_SETXID
18722 +extern void gr_delayed_cred_worker(void);
18723 +#endif
18724 +
18725 /*
18726 * We must return the syscall number to actually look up in the table.
18727 * This can be -1L to skip running any syscall at all.
18728 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18729 {
18730 long ret = 0;
18731
18732 +#ifdef CONFIG_GRKERNSEC_SETXID
18733 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18734 + gr_delayed_cred_worker();
18735 +#endif
18736 +
18737 /*
18738 * If we stepped into a sysenter/syscall insn, it trapped in
18739 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18740 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18741 {
18742 bool step;
18743
18744 +#ifdef CONFIG_GRKERNSEC_SETXID
18745 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18746 + gr_delayed_cred_worker();
18747 +#endif
18748 +
18749 audit_syscall_exit(regs);
18750
18751 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18752 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18753 index 42eb330..139955c 100644
18754 --- a/arch/x86/kernel/pvclock.c
18755 +++ b/arch/x86/kernel/pvclock.c
18756 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18757 return pv_tsc_khz;
18758 }
18759
18760 -static atomic64_t last_value = ATOMIC64_INIT(0);
18761 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18762
18763 void pvclock_resume(void)
18764 {
18765 - atomic64_set(&last_value, 0);
18766 + atomic64_set_unchecked(&last_value, 0);
18767 }
18768
18769 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18770 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18771 * updating at the same time, and one of them could be slightly behind,
18772 * making the assumption that last_value always go forward fail to hold.
18773 */
18774 - last = atomic64_read(&last_value);
18775 + last = atomic64_read_unchecked(&last_value);
18776 do {
18777 if (ret < last)
18778 return last;
18779 - last = atomic64_cmpxchg(&last_value, last, ret);
18780 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18781 } while (unlikely(last != ret));
18782
18783 return ret;
18784 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18785 index 5de92f1..2732385 100644
18786 --- a/arch/x86/kernel/reboot.c
18787 +++ b/arch/x86/kernel/reboot.c
18788 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18789 EXPORT_SYMBOL(pm_power_off);
18790
18791 static const struct desc_ptr no_idt = {};
18792 -static int reboot_mode;
18793 +static unsigned short reboot_mode;
18794 enum reboot_type reboot_type = BOOT_ACPI;
18795 int reboot_force;
18796
18797 @@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18798 return 0;
18799 }
18800
18801 -void machine_real_restart(unsigned int type)
18802 +__noreturn void machine_real_restart(unsigned int type)
18803 {
18804 - void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18805 + void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18806 real_mode_header->machine_real_restart_asm;
18807
18808 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18809 + struct desc_struct *gdt;
18810 +#endif
18811 +
18812 local_irq_disable();
18813
18814 /*
18815 @@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18816 * boot)". This seems like a fairly standard thing that gets set by
18817 * REBOOT.COM programs, and the previous reset routine did this
18818 * too. */
18819 - *((unsigned short *)0x472) = reboot_mode;
18820 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18821
18822 /* Jump to the identity-mapped low memory code */
18823 +
18824 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18825 + gdt = get_cpu_gdt_table(smp_processor_id());
18826 + pax_open_kernel();
18827 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18828 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18829 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18830 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18831 +#endif
18832 +#ifdef CONFIG_PAX_KERNEXEC
18833 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18834 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18835 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18836 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18837 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18838 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18839 +#endif
18840 + pax_close_kernel();
18841 +#endif
18842 +
18843 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18844 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18845 + unreachable();
18846 +#else
18847 restart_lowmem(type);
18848 +#endif
18849 +
18850 }
18851 #ifdef CONFIG_APM_MODULE
18852 EXPORT_SYMBOL(machine_real_restart);
18853 @@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18854 * try to force a triple fault and then cycle between hitting the keyboard
18855 * controller and doing that
18856 */
18857 -static void native_machine_emergency_restart(void)
18858 +__noreturn static void native_machine_emergency_restart(void)
18859 {
18860 int i;
18861 int attempt = 0;
18862 @@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18863 #endif
18864 }
18865
18866 -static void __machine_emergency_restart(int emergency)
18867 +static __noreturn void __machine_emergency_restart(int emergency)
18868 {
18869 reboot_emergency = emergency;
18870 machine_ops.emergency_restart();
18871 }
18872
18873 -static void native_machine_restart(char *__unused)
18874 +static __noreturn void native_machine_restart(char *__unused)
18875 {
18876 printk("machine restart\n");
18877
18878 @@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18879 __machine_emergency_restart(0);
18880 }
18881
18882 -static void native_machine_halt(void)
18883 +static __noreturn void native_machine_halt(void)
18884 {
18885 /* Stop other cpus and apics */
18886 machine_shutdown();
18887 @@ -695,7 +725,7 @@ static void native_machine_halt(void)
18888 stop_this_cpu(NULL);
18889 }
18890
18891 -static void native_machine_power_off(void)
18892 +__noreturn static void native_machine_power_off(void)
18893 {
18894 if (pm_power_off) {
18895 if (!reboot_force)
18896 @@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18897 }
18898 /* A fallback in case there is no PM info available */
18899 tboot_shutdown(TB_SHUTDOWN_HALT);
18900 + unreachable();
18901 }
18902
18903 struct machine_ops machine_ops = {
18904 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18905 index 7a6f3b3..bed145d7 100644
18906 --- a/arch/x86/kernel/relocate_kernel_64.S
18907 +++ b/arch/x86/kernel/relocate_kernel_64.S
18908 @@ -11,6 +11,7 @@
18909 #include <asm/kexec.h>
18910 #include <asm/processor-flags.h>
18911 #include <asm/pgtable_types.h>
18912 +#include <asm/alternative-asm.h>
18913
18914 /*
18915 * Must be relocatable PIC code callable as a C function
18916 @@ -160,13 +161,14 @@ identity_mapped:
18917 xorq %rbp, %rbp
18918 xorq %r8, %r8
18919 xorq %r9, %r9
18920 - xorq %r10, %r9
18921 + xorq %r10, %r10
18922 xorq %r11, %r11
18923 xorq %r12, %r12
18924 xorq %r13, %r13
18925 xorq %r14, %r14
18926 xorq %r15, %r15
18927
18928 + pax_force_retaddr 0, 1
18929 ret
18930
18931 1:
18932 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18933 index 16be6dc..4686132 100644
18934 --- a/arch/x86/kernel/setup.c
18935 +++ b/arch/x86/kernel/setup.c
18936 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18937
18938 switch (data->type) {
18939 case SETUP_E820_EXT:
18940 - parse_e820_ext(data);
18941 + parse_e820_ext((struct setup_data __force_kernel *)data);
18942 break;
18943 case SETUP_DTB:
18944 add_dtb(pa_data);
18945 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18946 * area (640->1Mb) as ram even though it is not.
18947 * take them out.
18948 */
18949 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18950 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18951 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18952 }
18953
18954 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18955
18956 if (!boot_params.hdr.root_flags)
18957 root_mountflags &= ~MS_RDONLY;
18958 - init_mm.start_code = (unsigned long) _text;
18959 - init_mm.end_code = (unsigned long) _etext;
18960 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18961 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18962 init_mm.end_data = (unsigned long) _edata;
18963 init_mm.brk = _brk_end;
18964
18965 - code_resource.start = virt_to_phys(_text);
18966 - code_resource.end = virt_to_phys(_etext)-1;
18967 - data_resource.start = virt_to_phys(_etext);
18968 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18969 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18970 + data_resource.start = virt_to_phys(_sdata);
18971 data_resource.end = virt_to_phys(_edata)-1;
18972 bss_resource.start = virt_to_phys(&__bss_start);
18973 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18974 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18975 index 5a98aa2..2f9288d 100644
18976 --- a/arch/x86/kernel/setup_percpu.c
18977 +++ b/arch/x86/kernel/setup_percpu.c
18978 @@ -21,19 +21,17 @@
18979 #include <asm/cpu.h>
18980 #include <asm/stackprotector.h>
18981
18982 -DEFINE_PER_CPU(int, cpu_number);
18983 +#ifdef CONFIG_SMP
18984 +DEFINE_PER_CPU(unsigned int, cpu_number);
18985 EXPORT_PER_CPU_SYMBOL(cpu_number);
18986 +#endif
18987
18988 -#ifdef CONFIG_X86_64
18989 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18990 -#else
18991 -#define BOOT_PERCPU_OFFSET 0
18992 -#endif
18993
18994 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18995 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18996
18997 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18998 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18999 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19000 };
19001 EXPORT_SYMBOL(__per_cpu_offset);
19002 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19003 {
19004 #ifdef CONFIG_X86_32
19005 struct desc_struct gdt;
19006 + unsigned long base = per_cpu_offset(cpu);
19007
19008 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19009 - 0x2 | DESCTYPE_S, 0x8);
19010 - gdt.s = 1;
19011 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19012 + 0x83 | DESCTYPE_S, 0xC);
19013 write_gdt_entry(get_cpu_gdt_table(cpu),
19014 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19015 #endif
19016 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19017 /* alrighty, percpu areas up and running */
19018 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19019 for_each_possible_cpu(cpu) {
19020 +#ifdef CONFIG_CC_STACKPROTECTOR
19021 +#ifdef CONFIG_X86_32
19022 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19023 +#endif
19024 +#endif
19025 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19026 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19027 per_cpu(cpu_number, cpu) = cpu;
19028 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19029 */
19030 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19031 #endif
19032 +#ifdef CONFIG_CC_STACKPROTECTOR
19033 +#ifdef CONFIG_X86_32
19034 + if (!cpu)
19035 + per_cpu(stack_canary.canary, cpu) = canary;
19036 +#endif
19037 +#endif
19038 /*
19039 * Up to this point, the boot CPU has been using .init.data
19040 * area. Reload any changed state for the boot CPU.
19041 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19042 index 21af737..fb45e22 100644
19043 --- a/arch/x86/kernel/signal.c
19044 +++ b/arch/x86/kernel/signal.c
19045 @@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
19046 * Align the stack pointer according to the i386 ABI,
19047 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19048 */
19049 - sp = ((sp + 4) & -16ul) - 4;
19050 + sp = ((sp - 12) & -16ul) - 4;
19051 #else /* !CONFIG_X86_32 */
19052 sp = round_down(sp, 16) - 8;
19053 #endif
19054 @@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19055 * Return an always-bogus address instead so we will die with SIGSEGV.
19056 */
19057 if (onsigstack && !likely(on_sig_stack(sp)))
19058 - return (void __user *)-1L;
19059 + return (__force void __user *)-1L;
19060
19061 /* save i387 state */
19062 if (used_math() && save_i387_xstate(*fpstate) < 0)
19063 - return (void __user *)-1L;
19064 + return (__force void __user *)-1L;
19065
19066 return (void __user *)sp;
19067 }
19068 @@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19069 }
19070
19071 if (current->mm->context.vdso)
19072 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19073 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19074 else
19075 - restorer = &frame->retcode;
19076 + restorer = (void __user *)&frame->retcode;
19077 if (ka->sa.sa_flags & SA_RESTORER)
19078 restorer = ka->sa.sa_restorer;
19079
19080 @@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19081 * reasons and because gdb uses it as a signature to notice
19082 * signal handler stack frames.
19083 */
19084 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19085 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19086
19087 if (err)
19088 return -EFAULT;
19089 @@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19090 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19091
19092 /* Set up to return from userspace. */
19093 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19094 + if (current->mm->context.vdso)
19095 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19096 + else
19097 + restorer = (void __user *)&frame->retcode;
19098 if (ka->sa.sa_flags & SA_RESTORER)
19099 restorer = ka->sa.sa_restorer;
19100 put_user_ex(restorer, &frame->pretcode);
19101 @@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19102 * reasons and because gdb uses it as a signature to notice
19103 * signal handler stack frames.
19104 */
19105 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19106 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19107 } put_user_catch(err);
19108
19109 if (err)
19110 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19111 index 7bd8a08..2659b5b 100644
19112 --- a/arch/x86/kernel/smpboot.c
19113 +++ b/arch/x86/kernel/smpboot.c
19114 @@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19115 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19116 (THREAD_SIZE + task_stack_page(idle))) - 1);
19117 per_cpu(current_task, cpu) = idle;
19118 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19119
19120 #ifdef CONFIG_X86_32
19121 /* Stack for startup_32 can be just as for start_secondary onwards */
19122 @@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19123 #else
19124 clear_tsk_thread_flag(idle, TIF_FORK);
19125 initial_gs = per_cpu_offset(cpu);
19126 - per_cpu(kernel_stack, cpu) =
19127 - (unsigned long)task_stack_page(idle) -
19128 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19129 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19130 #endif
19131 +
19132 + pax_open_kernel();
19133 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19134 + pax_close_kernel();
19135 +
19136 initial_code = (unsigned long)start_secondary;
19137 stack_start = idle->thread.sp;
19138
19139 @@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19140
19141 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19142
19143 +#ifdef CONFIG_PAX_PER_CPU_PGD
19144 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19145 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19146 + KERNEL_PGD_PTRS);
19147 +#endif
19148 +
19149 err = do_boot_cpu(apicid, cpu, tidle);
19150 if (err) {
19151 pr_debug("do_boot_cpu failed %d\n", err);
19152 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19153 index c346d11..d43b163 100644
19154 --- a/arch/x86/kernel/step.c
19155 +++ b/arch/x86/kernel/step.c
19156 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19157 struct desc_struct *desc;
19158 unsigned long base;
19159
19160 - seg &= ~7UL;
19161 + seg >>= 3;
19162
19163 mutex_lock(&child->mm->context.lock);
19164 - if (unlikely((seg >> 3) >= child->mm->context.size))
19165 + if (unlikely(seg >= child->mm->context.size))
19166 addr = -1L; /* bogus selector, access would fault */
19167 else {
19168 desc = child->mm->context.ldt + seg;
19169 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19170 addr += base;
19171 }
19172 mutex_unlock(&child->mm->context.lock);
19173 - }
19174 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19175 + addr = ktla_ktva(addr);
19176
19177 return addr;
19178 }
19179 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19180 unsigned char opcode[15];
19181 unsigned long addr = convert_ip_to_linear(child, regs);
19182
19183 + if (addr == -EINVAL)
19184 + return 0;
19185 +
19186 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19187 for (i = 0; i < copied; i++) {
19188 switch (opcode[i]) {
19189 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19190 index 0b0cb5f..db6b9ed 100644
19191 --- a/arch/x86/kernel/sys_i386_32.c
19192 +++ b/arch/x86/kernel/sys_i386_32.c
19193 @@ -24,17 +24,224 @@
19194
19195 #include <asm/syscalls.h>
19196
19197 -/*
19198 - * Do a system call from kernel instead of calling sys_execve so we
19199 - * end up with proper pt_regs.
19200 - */
19201 -int kernel_execve(const char *filename,
19202 - const char *const argv[],
19203 - const char *const envp[])
19204 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19205 {
19206 - long __res;
19207 - asm volatile ("int $0x80"
19208 - : "=a" (__res)
19209 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19210 - return __res;
19211 + unsigned long pax_task_size = TASK_SIZE;
19212 +
19213 +#ifdef CONFIG_PAX_SEGMEXEC
19214 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19215 + pax_task_size = SEGMEXEC_TASK_SIZE;
19216 +#endif
19217 +
19218 + if (len > pax_task_size || addr > pax_task_size - len)
19219 + return -EINVAL;
19220 +
19221 + return 0;
19222 +}
19223 +
19224 +unsigned long
19225 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19226 + unsigned long len, unsigned long pgoff, unsigned long flags)
19227 +{
19228 + struct mm_struct *mm = current->mm;
19229 + struct vm_area_struct *vma;
19230 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19231 +
19232 +#ifdef CONFIG_PAX_SEGMEXEC
19233 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19234 + pax_task_size = SEGMEXEC_TASK_SIZE;
19235 +#endif
19236 +
19237 + pax_task_size -= PAGE_SIZE;
19238 +
19239 + if (len > pax_task_size)
19240 + return -ENOMEM;
19241 +
19242 + if (flags & MAP_FIXED)
19243 + return addr;
19244 +
19245 +#ifdef CONFIG_PAX_RANDMMAP
19246 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19247 +#endif
19248 +
19249 + if (addr) {
19250 + addr = PAGE_ALIGN(addr);
19251 + if (pax_task_size - len >= addr) {
19252 + vma = find_vma(mm, addr);
19253 + if (check_heap_stack_gap(vma, addr, len))
19254 + return addr;
19255 + }
19256 + }
19257 + if (len > mm->cached_hole_size) {
19258 + start_addr = addr = mm->free_area_cache;
19259 + } else {
19260 + start_addr = addr = mm->mmap_base;
19261 + mm->cached_hole_size = 0;
19262 + }
19263 +
19264 +#ifdef CONFIG_PAX_PAGEEXEC
19265 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19266 + start_addr = 0x00110000UL;
19267 +
19268 +#ifdef CONFIG_PAX_RANDMMAP
19269 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19270 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19271 +#endif
19272 +
19273 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19274 + start_addr = addr = mm->mmap_base;
19275 + else
19276 + addr = start_addr;
19277 + }
19278 +#endif
19279 +
19280 +full_search:
19281 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19282 + /* At this point: (!vma || addr < vma->vm_end). */
19283 + if (pax_task_size - len < addr) {
19284 + /*
19285 + * Start a new search - just in case we missed
19286 + * some holes.
19287 + */
19288 + if (start_addr != mm->mmap_base) {
19289 + start_addr = addr = mm->mmap_base;
19290 + mm->cached_hole_size = 0;
19291 + goto full_search;
19292 + }
19293 + return -ENOMEM;
19294 + }
19295 + if (check_heap_stack_gap(vma, addr, len))
19296 + break;
19297 + if (addr + mm->cached_hole_size < vma->vm_start)
19298 + mm->cached_hole_size = vma->vm_start - addr;
19299 + addr = vma->vm_end;
19300 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19301 + start_addr = addr = mm->mmap_base;
19302 + mm->cached_hole_size = 0;
19303 + goto full_search;
19304 + }
19305 + }
19306 +
19307 + /*
19308 + * Remember the place where we stopped the search:
19309 + */
19310 + mm->free_area_cache = addr + len;
19311 + return addr;
19312 +}
19313 +
19314 +unsigned long
19315 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19316 + const unsigned long len, const unsigned long pgoff,
19317 + const unsigned long flags)
19318 +{
19319 + struct vm_area_struct *vma;
19320 + struct mm_struct *mm = current->mm;
19321 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19322 +
19323 +#ifdef CONFIG_PAX_SEGMEXEC
19324 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19325 + pax_task_size = SEGMEXEC_TASK_SIZE;
19326 +#endif
19327 +
19328 + pax_task_size -= PAGE_SIZE;
19329 +
19330 + /* requested length too big for entire address space */
19331 + if (len > pax_task_size)
19332 + return -ENOMEM;
19333 +
19334 + if (flags & MAP_FIXED)
19335 + return addr;
19336 +
19337 +#ifdef CONFIG_PAX_PAGEEXEC
19338 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19339 + goto bottomup;
19340 +#endif
19341 +
19342 +#ifdef CONFIG_PAX_RANDMMAP
19343 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19344 +#endif
19345 +
19346 + /* requesting a specific address */
19347 + if (addr) {
19348 + addr = PAGE_ALIGN(addr);
19349 + if (pax_task_size - len >= addr) {
19350 + vma = find_vma(mm, addr);
19351 + if (check_heap_stack_gap(vma, addr, len))
19352 + return addr;
19353 + }
19354 + }
19355 +
19356 + /* check if free_area_cache is useful for us */
19357 + if (len <= mm->cached_hole_size) {
19358 + mm->cached_hole_size = 0;
19359 + mm->free_area_cache = mm->mmap_base;
19360 + }
19361 +
19362 + /* either no address requested or can't fit in requested address hole */
19363 + addr = mm->free_area_cache;
19364 +
19365 + /* make sure it can fit in the remaining address space */
19366 + if (addr > len) {
19367 + vma = find_vma(mm, addr-len);
19368 + if (check_heap_stack_gap(vma, addr - len, len))
19369 + /* remember the address as a hint for next time */
19370 + return (mm->free_area_cache = addr-len);
19371 + }
19372 +
19373 + if (mm->mmap_base < len)
19374 + goto bottomup;
19375 +
19376 + addr = mm->mmap_base-len;
19377 +
19378 + do {
19379 + /*
19380 + * Lookup failure means no vma is above this address,
19381 + * else if new region fits below vma->vm_start,
19382 + * return with success:
19383 + */
19384 + vma = find_vma(mm, addr);
19385 + if (check_heap_stack_gap(vma, addr, len))
19386 + /* remember the address as a hint for next time */
19387 + return (mm->free_area_cache = addr);
19388 +
19389 + /* remember the largest hole we saw so far */
19390 + if (addr + mm->cached_hole_size < vma->vm_start)
19391 + mm->cached_hole_size = vma->vm_start - addr;
19392 +
19393 + /* try just below the current vma->vm_start */
19394 + addr = skip_heap_stack_gap(vma, len);
19395 + } while (!IS_ERR_VALUE(addr));
19396 +
19397 +bottomup:
19398 + /*
19399 + * A failed mmap() very likely causes application failure,
19400 + * so fall back to the bottom-up function here. This scenario
19401 + * can happen with large stack limits and large mmap()
19402 + * allocations.
19403 + */
19404 +
19405 +#ifdef CONFIG_PAX_SEGMEXEC
19406 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19407 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19408 + else
19409 +#endif
19410 +
19411 + mm->mmap_base = TASK_UNMAPPED_BASE;
19412 +
19413 +#ifdef CONFIG_PAX_RANDMMAP
19414 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19415 + mm->mmap_base += mm->delta_mmap;
19416 +#endif
19417 +
19418 + mm->free_area_cache = mm->mmap_base;
19419 + mm->cached_hole_size = ~0UL;
19420 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19421 + /*
19422 + * Restore the topdown base:
19423 + */
19424 + mm->mmap_base = base;
19425 + mm->free_area_cache = base;
19426 + mm->cached_hole_size = ~0UL;
19427 +
19428 + return addr;
19429 }
19430 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19431 index b4d3c39..82bb73b 100644
19432 --- a/arch/x86/kernel/sys_x86_64.c
19433 +++ b/arch/x86/kernel/sys_x86_64.c
19434 @@ -95,8 +95,8 @@ out:
19435 return error;
19436 }
19437
19438 -static void find_start_end(unsigned long flags, unsigned long *begin,
19439 - unsigned long *end)
19440 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19441 + unsigned long *begin, unsigned long *end)
19442 {
19443 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19444 unsigned long new_begin;
19445 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19446 *begin = new_begin;
19447 }
19448 } else {
19449 - *begin = TASK_UNMAPPED_BASE;
19450 + *begin = mm->mmap_base;
19451 *end = TASK_SIZE;
19452 }
19453 }
19454 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19455 if (flags & MAP_FIXED)
19456 return addr;
19457
19458 - find_start_end(flags, &begin, &end);
19459 + find_start_end(mm, flags, &begin, &end);
19460
19461 if (len > end)
19462 return -ENOMEM;
19463
19464 +#ifdef CONFIG_PAX_RANDMMAP
19465 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19466 +#endif
19467 +
19468 if (addr) {
19469 addr = PAGE_ALIGN(addr);
19470 vma = find_vma(mm, addr);
19471 - if (end - len >= addr &&
19472 - (!vma || addr + len <= vma->vm_start))
19473 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19474 return addr;
19475 }
19476 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19477 @@ -172,7 +175,7 @@ full_search:
19478 }
19479 return -ENOMEM;
19480 }
19481 - if (!vma || addr + len <= vma->vm_start) {
19482 + if (check_heap_stack_gap(vma, addr, len)) {
19483 /*
19484 * Remember the place where we stopped the search:
19485 */
19486 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19487 {
19488 struct vm_area_struct *vma;
19489 struct mm_struct *mm = current->mm;
19490 - unsigned long addr = addr0, start_addr;
19491 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19492
19493 /* requested length too big for entire address space */
19494 if (len > TASK_SIZE)
19495 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19496 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19497 goto bottomup;
19498
19499 +#ifdef CONFIG_PAX_RANDMMAP
19500 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19501 +#endif
19502 +
19503 /* requesting a specific address */
19504 if (addr) {
19505 addr = PAGE_ALIGN(addr);
19506 - vma = find_vma(mm, addr);
19507 - if (TASK_SIZE - len >= addr &&
19508 - (!vma || addr + len <= vma->vm_start))
19509 - return addr;
19510 + if (TASK_SIZE - len >= addr) {
19511 + vma = find_vma(mm, addr);
19512 + if (check_heap_stack_gap(vma, addr, len))
19513 + return addr;
19514 + }
19515 }
19516
19517 /* check if free_area_cache is useful for us */
19518 @@ -240,7 +248,7 @@ try_again:
19519 * return with success:
19520 */
19521 vma = find_vma(mm, addr);
19522 - if (!vma || addr+len <= vma->vm_start)
19523 + if (check_heap_stack_gap(vma, addr, len))
19524 /* remember the address as a hint for next time */
19525 return mm->free_area_cache = addr;
19526
19527 @@ -249,8 +257,8 @@ try_again:
19528 mm->cached_hole_size = vma->vm_start - addr;
19529
19530 /* try just below the current vma->vm_start */
19531 - addr = vma->vm_start-len;
19532 - } while (len < vma->vm_start);
19533 + addr = skip_heap_stack_gap(vma, len);
19534 + } while (!IS_ERR_VALUE(addr));
19535
19536 fail:
19537 /*
19538 @@ -270,13 +278,21 @@ bottomup:
19539 * can happen with large stack limits and large mmap()
19540 * allocations.
19541 */
19542 + mm->mmap_base = TASK_UNMAPPED_BASE;
19543 +
19544 +#ifdef CONFIG_PAX_RANDMMAP
19545 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19546 + mm->mmap_base += mm->delta_mmap;
19547 +#endif
19548 +
19549 + mm->free_area_cache = mm->mmap_base;
19550 mm->cached_hole_size = ~0UL;
19551 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19552 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19553 /*
19554 * Restore the topdown base:
19555 */
19556 - mm->free_area_cache = mm->mmap_base;
19557 + mm->mmap_base = base;
19558 + mm->free_area_cache = base;
19559 mm->cached_hole_size = ~0UL;
19560
19561 return addr;
19562 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19563 index f84fe00..93fe08f 100644
19564 --- a/arch/x86/kernel/tboot.c
19565 +++ b/arch/x86/kernel/tboot.c
19566 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19567
19568 void tboot_shutdown(u32 shutdown_type)
19569 {
19570 - void (*shutdown)(void);
19571 + void (* __noreturn shutdown)(void);
19572
19573 if (!tboot_enabled())
19574 return;
19575 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19576
19577 switch_to_tboot_pt();
19578
19579 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19580 + shutdown = (void *)tboot->shutdown_entry;
19581 shutdown();
19582
19583 /* should not reach here */
19584 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19585 return 0;
19586 }
19587
19588 -static atomic_t ap_wfs_count;
19589 +static atomic_unchecked_t ap_wfs_count;
19590
19591 static int tboot_wait_for_aps(int num_aps)
19592 {
19593 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19594 {
19595 switch (action) {
19596 case CPU_DYING:
19597 - atomic_inc(&ap_wfs_count);
19598 + atomic_inc_unchecked(&ap_wfs_count);
19599 if (num_online_cpus() == 1)
19600 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19601 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19602 return NOTIFY_BAD;
19603 break;
19604 }
19605 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19606
19607 tboot_create_trampoline();
19608
19609 - atomic_set(&ap_wfs_count, 0);
19610 + atomic_set_unchecked(&ap_wfs_count, 0);
19611 register_hotcpu_notifier(&tboot_cpu_notifier);
19612
19613 acpi_os_set_prepare_sleep(&tboot_sleep);
19614 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19615 index 24d3c91..d06b473 100644
19616 --- a/arch/x86/kernel/time.c
19617 +++ b/arch/x86/kernel/time.c
19618 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19619 {
19620 unsigned long pc = instruction_pointer(regs);
19621
19622 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19623 + if (!user_mode(regs) && in_lock_functions(pc)) {
19624 #ifdef CONFIG_FRAME_POINTER
19625 - return *(unsigned long *)(regs->bp + sizeof(long));
19626 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19627 #else
19628 unsigned long *sp =
19629 (unsigned long *)kernel_stack_pointer(regs);
19630 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19631 * or above a saved flags. Eflags has bits 22-31 zero,
19632 * kernel addresses don't.
19633 */
19634 +
19635 +#ifdef CONFIG_PAX_KERNEXEC
19636 + return ktla_ktva(sp[0]);
19637 +#else
19638 if (sp[0] >> 22)
19639 return sp[0];
19640 if (sp[1] >> 22)
19641 return sp[1];
19642 #endif
19643 +
19644 +#endif
19645 }
19646 return pc;
19647 }
19648 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19649 index 9d9d2f9..ed344e4 100644
19650 --- a/arch/x86/kernel/tls.c
19651 +++ b/arch/x86/kernel/tls.c
19652 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19653 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19654 return -EINVAL;
19655
19656 +#ifdef CONFIG_PAX_SEGMEXEC
19657 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19658 + return -EINVAL;
19659 +#endif
19660 +
19661 set_tls_desc(p, idx, &info, 1);
19662
19663 return 0;
19664 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19665 index 05b31d9..501d3ba 100644
19666 --- a/arch/x86/kernel/traps.c
19667 +++ b/arch/x86/kernel/traps.c
19668 @@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19669
19670 /* Do we ignore FPU interrupts ? */
19671 char ignore_fpu_irq;
19672 -
19673 -/*
19674 - * The IDT has to be page-aligned to simplify the Pentium
19675 - * F0 0F bug workaround.
19676 - */
19677 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19678 #endif
19679
19680 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19681 @@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19682 }
19683
19684 static void __kprobes
19685 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19686 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19687 long error_code, siginfo_t *info)
19688 {
19689 struct task_struct *tsk = current;
19690
19691 #ifdef CONFIG_X86_32
19692 - if (regs->flags & X86_VM_MASK) {
19693 + if (v8086_mode(regs)) {
19694 /*
19695 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19696 * On nmi (interrupt 2), do_trap should not be called.
19697 @@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19698 }
19699 #endif
19700
19701 - if (!user_mode(regs))
19702 + if (!user_mode_novm(regs))
19703 goto kernel_trap;
19704
19705 #ifdef CONFIG_X86_32
19706 @@ -145,7 +139,7 @@ trap_signal:
19707 printk_ratelimit()) {
19708 printk(KERN_INFO
19709 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19710 - tsk->comm, tsk->pid, str,
19711 + tsk->comm, task_pid_nr(tsk), str,
19712 regs->ip, regs->sp, error_code);
19713 print_vma_addr(" in ", regs->ip);
19714 printk("\n");
19715 @@ -162,8 +156,20 @@ kernel_trap:
19716 if (!fixup_exception(regs)) {
19717 tsk->thread.error_code = error_code;
19718 tsk->thread.trap_nr = trapnr;
19719 +
19720 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19721 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19722 + str = "PAX: suspicious stack segment fault";
19723 +#endif
19724 +
19725 die(str, regs, error_code);
19726 }
19727 +
19728 +#ifdef CONFIG_PAX_REFCOUNT
19729 + if (trapnr == 4)
19730 + pax_report_refcount_overflow(regs);
19731 +#endif
19732 +
19733 return;
19734
19735 #ifdef CONFIG_X86_32
19736 @@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19737 conditional_sti(regs);
19738
19739 #ifdef CONFIG_X86_32
19740 - if (regs->flags & X86_VM_MASK)
19741 + if (v8086_mode(regs))
19742 goto gp_in_vm86;
19743 #endif
19744
19745 tsk = current;
19746 - if (!user_mode(regs))
19747 + if (!user_mode_novm(regs))
19748 goto gp_in_kernel;
19749
19750 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19751 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19752 + struct mm_struct *mm = tsk->mm;
19753 + unsigned long limit;
19754 +
19755 + down_write(&mm->mmap_sem);
19756 + limit = mm->context.user_cs_limit;
19757 + if (limit < TASK_SIZE) {
19758 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19759 + up_write(&mm->mmap_sem);
19760 + return;
19761 + }
19762 + up_write(&mm->mmap_sem);
19763 + }
19764 +#endif
19765 +
19766 tsk->thread.error_code = error_code;
19767 tsk->thread.trap_nr = X86_TRAP_GP;
19768
19769 @@ -296,6 +318,13 @@ gp_in_kernel:
19770 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19771 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19772 return;
19773 +
19774 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19775 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19776 + die("PAX: suspicious general protection fault", regs, error_code);
19777 + else
19778 +#endif
19779 +
19780 die("general protection fault", regs, error_code);
19781 }
19782
19783 @@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19784 /* It's safe to allow irq's after DR6 has been saved */
19785 preempt_conditional_sti(regs);
19786
19787 - if (regs->flags & X86_VM_MASK) {
19788 + if (v8086_mode(regs)) {
19789 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19790 X86_TRAP_DB);
19791 preempt_conditional_cli(regs);
19792 @@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19793 * We already checked v86 mode above, so we can check for kernel mode
19794 * by just checking the CPL of CS.
19795 */
19796 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19797 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19798 tsk->thread.debugreg6 &= ~DR_STEP;
19799 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19800 regs->flags &= ~X86_EFLAGS_TF;
19801 @@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19802 return;
19803 conditional_sti(regs);
19804
19805 - if (!user_mode_vm(regs))
19806 + if (!user_mode(regs))
19807 {
19808 if (!fixup_exception(regs)) {
19809 task->thread.error_code = error_code;
19810 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19811 index dc4e910..c9dedab 100644
19812 --- a/arch/x86/kernel/uprobes.c
19813 +++ b/arch/x86/kernel/uprobes.c
19814 @@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19815 int ret = NOTIFY_DONE;
19816
19817 /* We are only interested in userspace traps */
19818 - if (regs && !user_mode_vm(regs))
19819 + if (regs && !user_mode(regs))
19820 return NOTIFY_DONE;
19821
19822 switch (val) {
19823 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19824 index b9242ba..50c5edd 100644
19825 --- a/arch/x86/kernel/verify_cpu.S
19826 +++ b/arch/x86/kernel/verify_cpu.S
19827 @@ -20,6 +20,7 @@
19828 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19829 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19830 * arch/x86/kernel/head_32.S: processor startup
19831 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19832 *
19833 * verify_cpu, returns the status of longmode and SSE in register %eax.
19834 * 0: Success 1: Failure
19835 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19836 index 255f58a..5e91150 100644
19837 --- a/arch/x86/kernel/vm86_32.c
19838 +++ b/arch/x86/kernel/vm86_32.c
19839 @@ -41,6 +41,7 @@
19840 #include <linux/ptrace.h>
19841 #include <linux/audit.h>
19842 #include <linux/stddef.h>
19843 +#include <linux/grsecurity.h>
19844
19845 #include <asm/uaccess.h>
19846 #include <asm/io.h>
19847 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19848 do_exit(SIGSEGV);
19849 }
19850
19851 - tss = &per_cpu(init_tss, get_cpu());
19852 + tss = init_tss + get_cpu();
19853 current->thread.sp0 = current->thread.saved_sp0;
19854 current->thread.sysenter_cs = __KERNEL_CS;
19855 load_sp0(tss, &current->thread);
19856 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19857 struct task_struct *tsk;
19858 int tmp, ret = -EPERM;
19859
19860 +#ifdef CONFIG_GRKERNSEC_VM86
19861 + if (!capable(CAP_SYS_RAWIO)) {
19862 + gr_handle_vm86();
19863 + goto out;
19864 + }
19865 +#endif
19866 +
19867 tsk = current;
19868 if (tsk->thread.saved_sp0)
19869 goto out;
19870 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19871 int tmp, ret;
19872 struct vm86plus_struct __user *v86;
19873
19874 +#ifdef CONFIG_GRKERNSEC_VM86
19875 + if (!capable(CAP_SYS_RAWIO)) {
19876 + gr_handle_vm86();
19877 + ret = -EPERM;
19878 + goto out;
19879 + }
19880 +#endif
19881 +
19882 tsk = current;
19883 switch (cmd) {
19884 case VM86_REQUEST_IRQ:
19885 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19886 tsk->thread.saved_fs = info->regs32->fs;
19887 tsk->thread.saved_gs = get_user_gs(info->regs32);
19888
19889 - tss = &per_cpu(init_tss, get_cpu());
19890 + tss = init_tss + get_cpu();
19891 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19892 if (cpu_has_sep)
19893 tsk->thread.sysenter_cs = 0;
19894 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19895 goto cannot_handle;
19896 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19897 goto cannot_handle;
19898 - intr_ptr = (unsigned long __user *) (i << 2);
19899 + intr_ptr = (__force unsigned long __user *) (i << 2);
19900 if (get_user(segoffs, intr_ptr))
19901 goto cannot_handle;
19902 if ((segoffs >> 16) == BIOSSEG)
19903 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19904 index 22a1530..8fbaaad 100644
19905 --- a/arch/x86/kernel/vmlinux.lds.S
19906 +++ b/arch/x86/kernel/vmlinux.lds.S
19907 @@ -26,6 +26,13 @@
19908 #include <asm/page_types.h>
19909 #include <asm/cache.h>
19910 #include <asm/boot.h>
19911 +#include <asm/segment.h>
19912 +
19913 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19914 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19915 +#else
19916 +#define __KERNEL_TEXT_OFFSET 0
19917 +#endif
19918
19919 #undef i386 /* in case the preprocessor is a 32bit one */
19920
19921 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19922
19923 PHDRS {
19924 text PT_LOAD FLAGS(5); /* R_E */
19925 +#ifdef CONFIG_X86_32
19926 + module PT_LOAD FLAGS(5); /* R_E */
19927 +#endif
19928 +#ifdef CONFIG_XEN
19929 + rodata PT_LOAD FLAGS(5); /* R_E */
19930 +#else
19931 + rodata PT_LOAD FLAGS(4); /* R__ */
19932 +#endif
19933 data PT_LOAD FLAGS(6); /* RW_ */
19934 -#ifdef CONFIG_X86_64
19935 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19936 #ifdef CONFIG_SMP
19937 percpu PT_LOAD FLAGS(6); /* RW_ */
19938 #endif
19939 + text.init PT_LOAD FLAGS(5); /* R_E */
19940 + text.exit PT_LOAD FLAGS(5); /* R_E */
19941 init PT_LOAD FLAGS(7); /* RWE */
19942 -#endif
19943 note PT_NOTE FLAGS(0); /* ___ */
19944 }
19945
19946 SECTIONS
19947 {
19948 #ifdef CONFIG_X86_32
19949 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19950 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19951 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19952 #else
19953 - . = __START_KERNEL;
19954 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19955 + . = __START_KERNEL;
19956 #endif
19957
19958 /* Text and read-only data */
19959 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19960 - _text = .;
19961 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19962 /* bootstrapping code */
19963 +#ifdef CONFIG_X86_32
19964 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19965 +#else
19966 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19967 +#endif
19968 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19969 + _text = .;
19970 HEAD_TEXT
19971 #ifdef CONFIG_X86_32
19972 . = ALIGN(PAGE_SIZE);
19973 @@ -108,13 +128,48 @@ SECTIONS
19974 IRQENTRY_TEXT
19975 *(.fixup)
19976 *(.gnu.warning)
19977 - /* End of text section */
19978 - _etext = .;
19979 } :text = 0x9090
19980
19981 - NOTES :text :note
19982 + . += __KERNEL_TEXT_OFFSET;
19983
19984 - EXCEPTION_TABLE(16) :text = 0x9090
19985 +#ifdef CONFIG_X86_32
19986 + . = ALIGN(PAGE_SIZE);
19987 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19988 +
19989 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19990 + MODULES_EXEC_VADDR = .;
19991 + BYTE(0)
19992 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19993 + . = ALIGN(HPAGE_SIZE) - 1;
19994 + MODULES_EXEC_END = .;
19995 +#endif
19996 +
19997 + } :module
19998 +#endif
19999 +
20000 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20001 + /* End of text section */
20002 + BYTE(0)
20003 + _etext = . - __KERNEL_TEXT_OFFSET;
20004 + }
20005 +
20006 +#ifdef CONFIG_X86_32
20007 + . = ALIGN(PAGE_SIZE);
20008 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20009 + *(.idt)
20010 + . = ALIGN(PAGE_SIZE);
20011 + *(.empty_zero_page)
20012 + *(.initial_pg_fixmap)
20013 + *(.initial_pg_pmd)
20014 + *(.initial_page_table)
20015 + *(.swapper_pg_dir)
20016 + } :rodata
20017 +#endif
20018 +
20019 + . = ALIGN(PAGE_SIZE);
20020 + NOTES :rodata :note
20021 +
20022 + EXCEPTION_TABLE(16) :rodata
20023
20024 #if defined(CONFIG_DEBUG_RODATA)
20025 /* .text should occupy whole number of pages */
20026 @@ -126,16 +181,20 @@ SECTIONS
20027
20028 /* Data */
20029 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20030 +
20031 +#ifdef CONFIG_PAX_KERNEXEC
20032 + . = ALIGN(HPAGE_SIZE);
20033 +#else
20034 + . = ALIGN(PAGE_SIZE);
20035 +#endif
20036 +
20037 /* Start of data section */
20038 _sdata = .;
20039
20040 /* init_task */
20041 INIT_TASK_DATA(THREAD_SIZE)
20042
20043 -#ifdef CONFIG_X86_32
20044 - /* 32 bit has nosave before _edata */
20045 NOSAVE_DATA
20046 -#endif
20047
20048 PAGE_ALIGNED_DATA(PAGE_SIZE)
20049
20050 @@ -176,12 +235,19 @@ SECTIONS
20051 #endif /* CONFIG_X86_64 */
20052
20053 /* Init code and data - will be freed after init */
20054 - . = ALIGN(PAGE_SIZE);
20055 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20056 + BYTE(0)
20057 +
20058 +#ifdef CONFIG_PAX_KERNEXEC
20059 + . = ALIGN(HPAGE_SIZE);
20060 +#else
20061 + . = ALIGN(PAGE_SIZE);
20062 +#endif
20063 +
20064 __init_begin = .; /* paired with __init_end */
20065 - }
20066 + } :init.begin
20067
20068 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20069 +#ifdef CONFIG_SMP
20070 /*
20071 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20072 * output PHDR, so the next output section - .init.text - should
20073 @@ -190,12 +256,27 @@ SECTIONS
20074 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20075 #endif
20076
20077 - INIT_TEXT_SECTION(PAGE_SIZE)
20078 -#ifdef CONFIG_X86_64
20079 - :init
20080 -#endif
20081 + . = ALIGN(PAGE_SIZE);
20082 + init_begin = .;
20083 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20084 + VMLINUX_SYMBOL(_sinittext) = .;
20085 + INIT_TEXT
20086 + VMLINUX_SYMBOL(_einittext) = .;
20087 + . = ALIGN(PAGE_SIZE);
20088 + } :text.init
20089
20090 - INIT_DATA_SECTION(16)
20091 + /*
20092 + * .exit.text is discard at runtime, not link time, to deal with
20093 + * references from .altinstructions and .eh_frame
20094 + */
20095 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20096 + EXIT_TEXT
20097 + . = ALIGN(16);
20098 + } :text.exit
20099 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20100 +
20101 + . = ALIGN(PAGE_SIZE);
20102 + INIT_DATA_SECTION(16) :init
20103
20104 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20105 __x86_cpu_dev_start = .;
20106 @@ -257,19 +338,12 @@ SECTIONS
20107 }
20108
20109 . = ALIGN(8);
20110 - /*
20111 - * .exit.text is discard at runtime, not link time, to deal with
20112 - * references from .altinstructions and .eh_frame
20113 - */
20114 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20115 - EXIT_TEXT
20116 - }
20117
20118 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20119 EXIT_DATA
20120 }
20121
20122 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20123 +#ifndef CONFIG_SMP
20124 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20125 #endif
20126
20127 @@ -288,16 +362,10 @@ SECTIONS
20128 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20129 __smp_locks = .;
20130 *(.smp_locks)
20131 - . = ALIGN(PAGE_SIZE);
20132 __smp_locks_end = .;
20133 + . = ALIGN(PAGE_SIZE);
20134 }
20135
20136 -#ifdef CONFIG_X86_64
20137 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20138 - NOSAVE_DATA
20139 - }
20140 -#endif
20141 -
20142 /* BSS */
20143 . = ALIGN(PAGE_SIZE);
20144 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20145 @@ -313,6 +381,7 @@ SECTIONS
20146 __brk_base = .;
20147 . += 64 * 1024; /* 64k alignment slop space */
20148 *(.brk_reservation) /* areas brk users have reserved */
20149 + . = ALIGN(HPAGE_SIZE);
20150 __brk_limit = .;
20151 }
20152
20153 @@ -339,13 +408,12 @@ SECTIONS
20154 * for the boot processor.
20155 */
20156 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20157 -INIT_PER_CPU(gdt_page);
20158 INIT_PER_CPU(irq_stack_union);
20159
20160 /*
20161 * Build-time check on the image size:
20162 */
20163 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20164 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20165 "kernel image bigger than KERNEL_IMAGE_SIZE");
20166
20167 #ifdef CONFIG_SMP
20168 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20169 index 5db36ca..2938af9 100644
20170 --- a/arch/x86/kernel/vsyscall_64.c
20171 +++ b/arch/x86/kernel/vsyscall_64.c
20172 @@ -54,15 +54,13 @@
20173 DEFINE_VVAR(int, vgetcpu_mode);
20174 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20175
20176 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20177 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20178
20179 static int __init vsyscall_setup(char *str)
20180 {
20181 if (str) {
20182 if (!strcmp("emulate", str))
20183 vsyscall_mode = EMULATE;
20184 - else if (!strcmp("native", str))
20185 - vsyscall_mode = NATIVE;
20186 else if (!strcmp("none", str))
20187 vsyscall_mode = NONE;
20188 else
20189 @@ -309,8 +307,7 @@ done:
20190 return true;
20191
20192 sigsegv:
20193 - force_sig(SIGSEGV, current);
20194 - return true;
20195 + do_group_exit(SIGKILL);
20196 }
20197
20198 /*
20199 @@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20200 extern char __vvar_page;
20201 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20202
20203 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20204 - vsyscall_mode == NATIVE
20205 - ? PAGE_KERNEL_VSYSCALL
20206 - : PAGE_KERNEL_VVAR);
20207 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20208 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20209 (unsigned long)VSYSCALL_START);
20210
20211 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20212 index 9796c2f..f686fbf 100644
20213 --- a/arch/x86/kernel/x8664_ksyms_64.c
20214 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20215 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20216 EXPORT_SYMBOL(copy_user_generic_string);
20217 EXPORT_SYMBOL(copy_user_generic_unrolled);
20218 EXPORT_SYMBOL(__copy_user_nocache);
20219 -EXPORT_SYMBOL(_copy_from_user);
20220 -EXPORT_SYMBOL(_copy_to_user);
20221
20222 EXPORT_SYMBOL(copy_page);
20223 EXPORT_SYMBOL(clear_page);
20224 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20225 index bd18149..2ea0183 100644
20226 --- a/arch/x86/kernel/xsave.c
20227 +++ b/arch/x86/kernel/xsave.c
20228 @@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20229 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20230 return -EINVAL;
20231
20232 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20233 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20234 fx_sw_user->extended_size -
20235 FP_XSTATE_MAGIC2_SIZE));
20236 if (err)
20237 @@ -265,7 +265,7 @@ fx_only:
20238 * the other extended state.
20239 */
20240 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20241 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20242 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20243 }
20244
20245 /*
20246 @@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20247 if (use_xsave())
20248 err = restore_user_xstate(buf);
20249 else
20250 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20251 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20252 buf);
20253 if (unlikely(err)) {
20254 /*
20255 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20256 index 7df1c6d..9ea7c79 100644
20257 --- a/arch/x86/kvm/cpuid.c
20258 +++ b/arch/x86/kvm/cpuid.c
20259 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20260 struct kvm_cpuid2 *cpuid,
20261 struct kvm_cpuid_entry2 __user *entries)
20262 {
20263 - int r;
20264 + int r, i;
20265
20266 r = -E2BIG;
20267 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20268 goto out;
20269 r = -EFAULT;
20270 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20271 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20272 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20273 goto out;
20274 + for (i = 0; i < cpuid->nent; ++i) {
20275 + struct kvm_cpuid_entry2 cpuid_entry;
20276 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20277 + goto out;
20278 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20279 + }
20280 vcpu->arch.cpuid_nent = cpuid->nent;
20281 kvm_apic_set_version(vcpu);
20282 kvm_x86_ops->cpuid_update(vcpu);
20283 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20284 struct kvm_cpuid2 *cpuid,
20285 struct kvm_cpuid_entry2 __user *entries)
20286 {
20287 - int r;
20288 + int r, i;
20289
20290 r = -E2BIG;
20291 if (cpuid->nent < vcpu->arch.cpuid_nent)
20292 goto out;
20293 r = -EFAULT;
20294 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20295 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20296 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20297 goto out;
20298 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20299 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20300 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20301 + goto out;
20302 + }
20303 return 0;
20304
20305 out:
20306 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20307 index 4837375..2cc9722 100644
20308 --- a/arch/x86/kvm/emulate.c
20309 +++ b/arch/x86/kvm/emulate.c
20310 @@ -256,6 +256,7 @@ struct gprefix {
20311
20312 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20313 do { \
20314 + unsigned long _tmp; \
20315 __asm__ __volatile__ ( \
20316 _PRE_EFLAGS("0", "4", "2") \
20317 _op _suffix " %"_x"3,%1; " \
20318 @@ -270,8 +271,6 @@ struct gprefix {
20319 /* Raw emulation: instruction has two explicit operands. */
20320 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20321 do { \
20322 - unsigned long _tmp; \
20323 - \
20324 switch ((ctxt)->dst.bytes) { \
20325 case 2: \
20326 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20327 @@ -287,7 +286,6 @@ struct gprefix {
20328
20329 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20330 do { \
20331 - unsigned long _tmp; \
20332 switch ((ctxt)->dst.bytes) { \
20333 case 1: \
20334 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20335 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20336 index 93c1574..d6097dc 100644
20337 --- a/arch/x86/kvm/lapic.c
20338 +++ b/arch/x86/kvm/lapic.c
20339 @@ -54,7 +54,7 @@
20340 #define APIC_BUS_CYCLE_NS 1
20341
20342 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20343 -#define apic_debug(fmt, arg...)
20344 +#define apic_debug(fmt, arg...) do {} while (0)
20345
20346 #define APIC_LVT_NUM 6
20347 /* 14 is the version for Xeon and Pentium 8.4.8*/
20348 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20349 index 34f9709..8eca2d5 100644
20350 --- a/arch/x86/kvm/paging_tmpl.h
20351 +++ b/arch/x86/kvm/paging_tmpl.h
20352 @@ -197,7 +197,7 @@ retry_walk:
20353 if (unlikely(kvm_is_error_hva(host_addr)))
20354 goto error;
20355
20356 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20357 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20358 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20359 goto error;
20360
20361 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20362 index f75af40..285b18f 100644
20363 --- a/arch/x86/kvm/svm.c
20364 +++ b/arch/x86/kvm/svm.c
20365 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20366 int cpu = raw_smp_processor_id();
20367
20368 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20369 +
20370 + pax_open_kernel();
20371 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20372 + pax_close_kernel();
20373 +
20374 load_TR_desc();
20375 }
20376
20377 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20378 #endif
20379 #endif
20380
20381 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20382 + __set_fs(current_thread_info()->addr_limit);
20383 +#endif
20384 +
20385 reload_tss(vcpu);
20386
20387 local_irq_disable();
20388 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20389 index 86c8704..e8ee2ac 100644
20390 --- a/arch/x86/kvm/vmx.c
20391 +++ b/arch/x86/kvm/vmx.c
20392 @@ -1317,7 +1317,11 @@ static void reload_tss(void)
20393 struct desc_struct *descs;
20394
20395 descs = (void *)gdt->address;
20396 +
20397 + pax_open_kernel();
20398 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20399 + pax_close_kernel();
20400 +
20401 load_TR_desc();
20402 }
20403
20404 @@ -2650,8 +2654,11 @@ static __init int hardware_setup(void)
20405 if (!cpu_has_vmx_flexpriority())
20406 flexpriority_enabled = 0;
20407
20408 - if (!cpu_has_vmx_tpr_shadow())
20409 - kvm_x86_ops->update_cr8_intercept = NULL;
20410 + if (!cpu_has_vmx_tpr_shadow()) {
20411 + pax_open_kernel();
20412 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20413 + pax_close_kernel();
20414 + }
20415
20416 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20417 kvm_disable_largepages();
20418 @@ -3719,7 +3726,7 @@ static void vmx_set_constant_host_state(void)
20419 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20420
20421 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20422 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20423 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20424
20425 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20426 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20427 @@ -6257,6 +6264,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20428 "jmp .Lkvm_vmx_return \n\t"
20429 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20430 ".Lkvm_vmx_return: "
20431 +
20432 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20433 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20434 + ".Lkvm_vmx_return2: "
20435 +#endif
20436 +
20437 /* Save guest registers, load host registers, keep flags */
20438 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20439 "pop %0 \n\t"
20440 @@ -6305,6 +6318,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20441 #endif
20442 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20443 [wordsize]"i"(sizeof(ulong))
20444 +
20445 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20446 + ,[cs]"i"(__KERNEL_CS)
20447 +#endif
20448 +
20449 : "cc", "memory"
20450 , R"ax", R"bx", R"di", R"si"
20451 #ifdef CONFIG_X86_64
20452 @@ -6312,7 +6330,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20453 #endif
20454 );
20455
20456 -#ifndef CONFIG_X86_64
20457 +#ifdef CONFIG_X86_32
20458 /*
20459 * The sysexit path does not restore ds/es, so we must set them to
20460 * a reasonable value ourselves.
20461 @@ -6321,8 +6339,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20462 * may be executed in interrupt context, which saves and restore segments
20463 * around it, nullifying its effect.
20464 */
20465 - loadsegment(ds, __USER_DS);
20466 - loadsegment(es, __USER_DS);
20467 + loadsegment(ds, __KERNEL_DS);
20468 + loadsegment(es, __KERNEL_DS);
20469 + loadsegment(ss, __KERNEL_DS);
20470 +
20471 +#ifdef CONFIG_PAX_KERNEXEC
20472 + loadsegment(fs, __KERNEL_PERCPU);
20473 +#endif
20474 +
20475 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20476 + __set_fs(current_thread_info()->addr_limit);
20477 +#endif
20478 +
20479 #endif
20480
20481 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20482 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20483 index 14c290d..0dae6e5 100644
20484 --- a/arch/x86/kvm/x86.c
20485 +++ b/arch/x86/kvm/x86.c
20486 @@ -1361,8 +1361,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20487 {
20488 struct kvm *kvm = vcpu->kvm;
20489 int lm = is_long_mode(vcpu);
20490 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20491 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20492 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20493 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20494 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20495 : kvm->arch.xen_hvm_config.blob_size_32;
20496 u32 page_num = data & ~PAGE_MASK;
20497 @@ -2218,6 +2218,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20498 if (n < msr_list.nmsrs)
20499 goto out;
20500 r = -EFAULT;
20501 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20502 + goto out;
20503 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20504 num_msrs_to_save * sizeof(u32)))
20505 goto out;
20506 @@ -2343,7 +2345,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20507 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20508 struct kvm_interrupt *irq)
20509 {
20510 - if (irq->irq < 0 || irq->irq >= 256)
20511 + if (irq->irq >= 256)
20512 return -EINVAL;
20513 if (irqchip_in_kernel(vcpu->kvm))
20514 return -ENXIO;
20515 @@ -4880,7 +4882,7 @@ static void kvm_set_mmio_spte_mask(void)
20516 kvm_mmu_set_mmio_spte_mask(mask);
20517 }
20518
20519 -int kvm_arch_init(void *opaque)
20520 +int kvm_arch_init(const void *opaque)
20521 {
20522 int r;
20523 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20524 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20525 index 642d880..44e0f3f 100644
20526 --- a/arch/x86/lguest/boot.c
20527 +++ b/arch/x86/lguest/boot.c
20528 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20529 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20530 * Launcher to reboot us.
20531 */
20532 -static void lguest_restart(char *reason)
20533 +static __noreturn void lguest_restart(char *reason)
20534 {
20535 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20536 + BUG();
20537 }
20538
20539 /*G:050
20540 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20541 index 00933d5..3a64af9 100644
20542 --- a/arch/x86/lib/atomic64_386_32.S
20543 +++ b/arch/x86/lib/atomic64_386_32.S
20544 @@ -48,6 +48,10 @@ BEGIN(read)
20545 movl (v), %eax
20546 movl 4(v), %edx
20547 RET_ENDP
20548 +BEGIN(read_unchecked)
20549 + movl (v), %eax
20550 + movl 4(v), %edx
20551 +RET_ENDP
20552 #undef v
20553
20554 #define v %esi
20555 @@ -55,6 +59,10 @@ BEGIN(set)
20556 movl %ebx, (v)
20557 movl %ecx, 4(v)
20558 RET_ENDP
20559 +BEGIN(set_unchecked)
20560 + movl %ebx, (v)
20561 + movl %ecx, 4(v)
20562 +RET_ENDP
20563 #undef v
20564
20565 #define v %esi
20566 @@ -70,6 +78,20 @@ RET_ENDP
20567 BEGIN(add)
20568 addl %eax, (v)
20569 adcl %edx, 4(v)
20570 +
20571 +#ifdef CONFIG_PAX_REFCOUNT
20572 + jno 0f
20573 + subl %eax, (v)
20574 + sbbl %edx, 4(v)
20575 + int $4
20576 +0:
20577 + _ASM_EXTABLE(0b, 0b)
20578 +#endif
20579 +
20580 +RET_ENDP
20581 +BEGIN(add_unchecked)
20582 + addl %eax, (v)
20583 + adcl %edx, 4(v)
20584 RET_ENDP
20585 #undef v
20586
20587 @@ -77,6 +99,24 @@ RET_ENDP
20588 BEGIN(add_return)
20589 addl (v), %eax
20590 adcl 4(v), %edx
20591 +
20592 +#ifdef CONFIG_PAX_REFCOUNT
20593 + into
20594 +1234:
20595 + _ASM_EXTABLE(1234b, 2f)
20596 +#endif
20597 +
20598 + movl %eax, (v)
20599 + movl %edx, 4(v)
20600 +
20601 +#ifdef CONFIG_PAX_REFCOUNT
20602 +2:
20603 +#endif
20604 +
20605 +RET_ENDP
20606 +BEGIN(add_return_unchecked)
20607 + addl (v), %eax
20608 + adcl 4(v), %edx
20609 movl %eax, (v)
20610 movl %edx, 4(v)
20611 RET_ENDP
20612 @@ -86,6 +126,20 @@ RET_ENDP
20613 BEGIN(sub)
20614 subl %eax, (v)
20615 sbbl %edx, 4(v)
20616 +
20617 +#ifdef CONFIG_PAX_REFCOUNT
20618 + jno 0f
20619 + addl %eax, (v)
20620 + adcl %edx, 4(v)
20621 + int $4
20622 +0:
20623 + _ASM_EXTABLE(0b, 0b)
20624 +#endif
20625 +
20626 +RET_ENDP
20627 +BEGIN(sub_unchecked)
20628 + subl %eax, (v)
20629 + sbbl %edx, 4(v)
20630 RET_ENDP
20631 #undef v
20632
20633 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20634 sbbl $0, %edx
20635 addl (v), %eax
20636 adcl 4(v), %edx
20637 +
20638 +#ifdef CONFIG_PAX_REFCOUNT
20639 + into
20640 +1234:
20641 + _ASM_EXTABLE(1234b, 2f)
20642 +#endif
20643 +
20644 + movl %eax, (v)
20645 + movl %edx, 4(v)
20646 +
20647 +#ifdef CONFIG_PAX_REFCOUNT
20648 +2:
20649 +#endif
20650 +
20651 +RET_ENDP
20652 +BEGIN(sub_return_unchecked)
20653 + negl %edx
20654 + negl %eax
20655 + sbbl $0, %edx
20656 + addl (v), %eax
20657 + adcl 4(v), %edx
20658 movl %eax, (v)
20659 movl %edx, 4(v)
20660 RET_ENDP
20661 @@ -105,6 +180,20 @@ RET_ENDP
20662 BEGIN(inc)
20663 addl $1, (v)
20664 adcl $0, 4(v)
20665 +
20666 +#ifdef CONFIG_PAX_REFCOUNT
20667 + jno 0f
20668 + subl $1, (v)
20669 + sbbl $0, 4(v)
20670 + int $4
20671 +0:
20672 + _ASM_EXTABLE(0b, 0b)
20673 +#endif
20674 +
20675 +RET_ENDP
20676 +BEGIN(inc_unchecked)
20677 + addl $1, (v)
20678 + adcl $0, 4(v)
20679 RET_ENDP
20680 #undef v
20681
20682 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20683 movl 4(v), %edx
20684 addl $1, %eax
20685 adcl $0, %edx
20686 +
20687 +#ifdef CONFIG_PAX_REFCOUNT
20688 + into
20689 +1234:
20690 + _ASM_EXTABLE(1234b, 2f)
20691 +#endif
20692 +
20693 + movl %eax, (v)
20694 + movl %edx, 4(v)
20695 +
20696 +#ifdef CONFIG_PAX_REFCOUNT
20697 +2:
20698 +#endif
20699 +
20700 +RET_ENDP
20701 +BEGIN(inc_return_unchecked)
20702 + movl (v), %eax
20703 + movl 4(v), %edx
20704 + addl $1, %eax
20705 + adcl $0, %edx
20706 movl %eax, (v)
20707 movl %edx, 4(v)
20708 RET_ENDP
20709 @@ -123,6 +232,20 @@ RET_ENDP
20710 BEGIN(dec)
20711 subl $1, (v)
20712 sbbl $0, 4(v)
20713 +
20714 +#ifdef CONFIG_PAX_REFCOUNT
20715 + jno 0f
20716 + addl $1, (v)
20717 + adcl $0, 4(v)
20718 + int $4
20719 +0:
20720 + _ASM_EXTABLE(0b, 0b)
20721 +#endif
20722 +
20723 +RET_ENDP
20724 +BEGIN(dec_unchecked)
20725 + subl $1, (v)
20726 + sbbl $0, 4(v)
20727 RET_ENDP
20728 #undef v
20729
20730 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20731 movl 4(v), %edx
20732 subl $1, %eax
20733 sbbl $0, %edx
20734 +
20735 +#ifdef CONFIG_PAX_REFCOUNT
20736 + into
20737 +1234:
20738 + _ASM_EXTABLE(1234b, 2f)
20739 +#endif
20740 +
20741 + movl %eax, (v)
20742 + movl %edx, 4(v)
20743 +
20744 +#ifdef CONFIG_PAX_REFCOUNT
20745 +2:
20746 +#endif
20747 +
20748 +RET_ENDP
20749 +BEGIN(dec_return_unchecked)
20750 + movl (v), %eax
20751 + movl 4(v), %edx
20752 + subl $1, %eax
20753 + sbbl $0, %edx
20754 movl %eax, (v)
20755 movl %edx, 4(v)
20756 RET_ENDP
20757 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20758 adcl %edx, %edi
20759 addl (v), %eax
20760 adcl 4(v), %edx
20761 +
20762 +#ifdef CONFIG_PAX_REFCOUNT
20763 + into
20764 +1234:
20765 + _ASM_EXTABLE(1234b, 2f)
20766 +#endif
20767 +
20768 cmpl %eax, %ecx
20769 je 3f
20770 1:
20771 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20772 1:
20773 addl $1, %eax
20774 adcl $0, %edx
20775 +
20776 +#ifdef CONFIG_PAX_REFCOUNT
20777 + into
20778 +1234:
20779 + _ASM_EXTABLE(1234b, 2f)
20780 +#endif
20781 +
20782 movl %eax, (v)
20783 movl %edx, 4(v)
20784 movl $1, %eax
20785 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20786 movl 4(v), %edx
20787 subl $1, %eax
20788 sbbl $0, %edx
20789 +
20790 +#ifdef CONFIG_PAX_REFCOUNT
20791 + into
20792 +1234:
20793 + _ASM_EXTABLE(1234b, 1f)
20794 +#endif
20795 +
20796 js 1f
20797 movl %eax, (v)
20798 movl %edx, 4(v)
20799 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20800 index f5cc9eb..51fa319 100644
20801 --- a/arch/x86/lib/atomic64_cx8_32.S
20802 +++ b/arch/x86/lib/atomic64_cx8_32.S
20803 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20804 CFI_STARTPROC
20805
20806 read64 %ecx
20807 + pax_force_retaddr
20808 ret
20809 CFI_ENDPROC
20810 ENDPROC(atomic64_read_cx8)
20811
20812 +ENTRY(atomic64_read_unchecked_cx8)
20813 + CFI_STARTPROC
20814 +
20815 + read64 %ecx
20816 + pax_force_retaddr
20817 + ret
20818 + CFI_ENDPROC
20819 +ENDPROC(atomic64_read_unchecked_cx8)
20820 +
20821 ENTRY(atomic64_set_cx8)
20822 CFI_STARTPROC
20823
20824 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20825 cmpxchg8b (%esi)
20826 jne 1b
20827
20828 + pax_force_retaddr
20829 ret
20830 CFI_ENDPROC
20831 ENDPROC(atomic64_set_cx8)
20832
20833 +ENTRY(atomic64_set_unchecked_cx8)
20834 + CFI_STARTPROC
20835 +
20836 +1:
20837 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20838 + * are atomic on 586 and newer */
20839 + cmpxchg8b (%esi)
20840 + jne 1b
20841 +
20842 + pax_force_retaddr
20843 + ret
20844 + CFI_ENDPROC
20845 +ENDPROC(atomic64_set_unchecked_cx8)
20846 +
20847 ENTRY(atomic64_xchg_cx8)
20848 CFI_STARTPROC
20849
20850 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20851 cmpxchg8b (%esi)
20852 jne 1b
20853
20854 + pax_force_retaddr
20855 ret
20856 CFI_ENDPROC
20857 ENDPROC(atomic64_xchg_cx8)
20858
20859 -.macro addsub_return func ins insc
20860 -ENTRY(atomic64_\func\()_return_cx8)
20861 +.macro addsub_return func ins insc unchecked=""
20862 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20863 CFI_STARTPROC
20864 SAVE ebp
20865 SAVE ebx
20866 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20867 movl %edx, %ecx
20868 \ins\()l %esi, %ebx
20869 \insc\()l %edi, %ecx
20870 +
20871 +.ifb \unchecked
20872 +#ifdef CONFIG_PAX_REFCOUNT
20873 + into
20874 +2:
20875 + _ASM_EXTABLE(2b, 3f)
20876 +#endif
20877 +.endif
20878 +
20879 LOCK_PREFIX
20880 cmpxchg8b (%ebp)
20881 jne 1b
20882 -
20883 -10:
20884 movl %ebx, %eax
20885 movl %ecx, %edx
20886 +
20887 +.ifb \unchecked
20888 +#ifdef CONFIG_PAX_REFCOUNT
20889 +3:
20890 +#endif
20891 +.endif
20892 +
20893 RESTORE edi
20894 RESTORE esi
20895 RESTORE ebx
20896 RESTORE ebp
20897 + pax_force_retaddr
20898 ret
20899 CFI_ENDPROC
20900 -ENDPROC(atomic64_\func\()_return_cx8)
20901 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20902 .endm
20903
20904 addsub_return add add adc
20905 addsub_return sub sub sbb
20906 +addsub_return add add adc _unchecked
20907 +addsub_return sub sub sbb _unchecked
20908
20909 -.macro incdec_return func ins insc
20910 -ENTRY(atomic64_\func\()_return_cx8)
20911 +.macro incdec_return func ins insc unchecked=""
20912 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20913 CFI_STARTPROC
20914 SAVE ebx
20915
20916 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20917 movl %edx, %ecx
20918 \ins\()l $1, %ebx
20919 \insc\()l $0, %ecx
20920 +
20921 +.ifb \unchecked
20922 +#ifdef CONFIG_PAX_REFCOUNT
20923 + into
20924 +2:
20925 + _ASM_EXTABLE(2b, 3f)
20926 +#endif
20927 +.endif
20928 +
20929 LOCK_PREFIX
20930 cmpxchg8b (%esi)
20931 jne 1b
20932
20933 -10:
20934 movl %ebx, %eax
20935 movl %ecx, %edx
20936 +
20937 +.ifb \unchecked
20938 +#ifdef CONFIG_PAX_REFCOUNT
20939 +3:
20940 +#endif
20941 +.endif
20942 +
20943 RESTORE ebx
20944 + pax_force_retaddr
20945 ret
20946 CFI_ENDPROC
20947 -ENDPROC(atomic64_\func\()_return_cx8)
20948 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20949 .endm
20950
20951 incdec_return inc add adc
20952 incdec_return dec sub sbb
20953 +incdec_return inc add adc _unchecked
20954 +incdec_return dec sub sbb _unchecked
20955
20956 ENTRY(atomic64_dec_if_positive_cx8)
20957 CFI_STARTPROC
20958 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20959 movl %edx, %ecx
20960 subl $1, %ebx
20961 sbb $0, %ecx
20962 +
20963 +#ifdef CONFIG_PAX_REFCOUNT
20964 + into
20965 +1234:
20966 + _ASM_EXTABLE(1234b, 2f)
20967 +#endif
20968 +
20969 js 2f
20970 LOCK_PREFIX
20971 cmpxchg8b (%esi)
20972 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20973 movl %ebx, %eax
20974 movl %ecx, %edx
20975 RESTORE ebx
20976 + pax_force_retaddr
20977 ret
20978 CFI_ENDPROC
20979 ENDPROC(atomic64_dec_if_positive_cx8)
20980 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20981 movl %edx, %ecx
20982 addl %ebp, %ebx
20983 adcl %edi, %ecx
20984 +
20985 +#ifdef CONFIG_PAX_REFCOUNT
20986 + into
20987 +1234:
20988 + _ASM_EXTABLE(1234b, 3f)
20989 +#endif
20990 +
20991 LOCK_PREFIX
20992 cmpxchg8b (%esi)
20993 jne 1b
20994 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20995 CFI_ADJUST_CFA_OFFSET -8
20996 RESTORE ebx
20997 RESTORE ebp
20998 + pax_force_retaddr
20999 ret
21000 4:
21001 cmpl %edx, 4(%esp)
21002 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21003 xorl %ecx, %ecx
21004 addl $1, %ebx
21005 adcl %edx, %ecx
21006 +
21007 +#ifdef CONFIG_PAX_REFCOUNT
21008 + into
21009 +1234:
21010 + _ASM_EXTABLE(1234b, 3f)
21011 +#endif
21012 +
21013 LOCK_PREFIX
21014 cmpxchg8b (%esi)
21015 jne 1b
21016 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21017 movl $1, %eax
21018 3:
21019 RESTORE ebx
21020 + pax_force_retaddr
21021 ret
21022 CFI_ENDPROC
21023 ENDPROC(atomic64_inc_not_zero_cx8)
21024 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21025 index 2af5df3..62b1a5a 100644
21026 --- a/arch/x86/lib/checksum_32.S
21027 +++ b/arch/x86/lib/checksum_32.S
21028 @@ -29,7 +29,8 @@
21029 #include <asm/dwarf2.h>
21030 #include <asm/errno.h>
21031 #include <asm/asm.h>
21032 -
21033 +#include <asm/segment.h>
21034 +
21035 /*
21036 * computes a partial checksum, e.g. for TCP/UDP fragments
21037 */
21038 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21039
21040 #define ARGBASE 16
21041 #define FP 12
21042 -
21043 -ENTRY(csum_partial_copy_generic)
21044 +
21045 +ENTRY(csum_partial_copy_generic_to_user)
21046 CFI_STARTPROC
21047 +
21048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21049 + pushl_cfi %gs
21050 + popl_cfi %es
21051 + jmp csum_partial_copy_generic
21052 +#endif
21053 +
21054 +ENTRY(csum_partial_copy_generic_from_user)
21055 +
21056 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21057 + pushl_cfi %gs
21058 + popl_cfi %ds
21059 +#endif
21060 +
21061 +ENTRY(csum_partial_copy_generic)
21062 subl $4,%esp
21063 CFI_ADJUST_CFA_OFFSET 4
21064 pushl_cfi %edi
21065 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21066 jmp 4f
21067 SRC(1: movw (%esi), %bx )
21068 addl $2, %esi
21069 -DST( movw %bx, (%edi) )
21070 +DST( movw %bx, %es:(%edi) )
21071 addl $2, %edi
21072 addw %bx, %ax
21073 adcl $0, %eax
21074 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21075 SRC(1: movl (%esi), %ebx )
21076 SRC( movl 4(%esi), %edx )
21077 adcl %ebx, %eax
21078 -DST( movl %ebx, (%edi) )
21079 +DST( movl %ebx, %es:(%edi) )
21080 adcl %edx, %eax
21081 -DST( movl %edx, 4(%edi) )
21082 +DST( movl %edx, %es:4(%edi) )
21083
21084 SRC( movl 8(%esi), %ebx )
21085 SRC( movl 12(%esi), %edx )
21086 adcl %ebx, %eax
21087 -DST( movl %ebx, 8(%edi) )
21088 +DST( movl %ebx, %es:8(%edi) )
21089 adcl %edx, %eax
21090 -DST( movl %edx, 12(%edi) )
21091 +DST( movl %edx, %es:12(%edi) )
21092
21093 SRC( movl 16(%esi), %ebx )
21094 SRC( movl 20(%esi), %edx )
21095 adcl %ebx, %eax
21096 -DST( movl %ebx, 16(%edi) )
21097 +DST( movl %ebx, %es:16(%edi) )
21098 adcl %edx, %eax
21099 -DST( movl %edx, 20(%edi) )
21100 +DST( movl %edx, %es:20(%edi) )
21101
21102 SRC( movl 24(%esi), %ebx )
21103 SRC( movl 28(%esi), %edx )
21104 adcl %ebx, %eax
21105 -DST( movl %ebx, 24(%edi) )
21106 +DST( movl %ebx, %es:24(%edi) )
21107 adcl %edx, %eax
21108 -DST( movl %edx, 28(%edi) )
21109 +DST( movl %edx, %es:28(%edi) )
21110
21111 lea 32(%esi), %esi
21112 lea 32(%edi), %edi
21113 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21114 shrl $2, %edx # This clears CF
21115 SRC(3: movl (%esi), %ebx )
21116 adcl %ebx, %eax
21117 -DST( movl %ebx, (%edi) )
21118 +DST( movl %ebx, %es:(%edi) )
21119 lea 4(%esi), %esi
21120 lea 4(%edi), %edi
21121 dec %edx
21122 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21123 jb 5f
21124 SRC( movw (%esi), %cx )
21125 leal 2(%esi), %esi
21126 -DST( movw %cx, (%edi) )
21127 +DST( movw %cx, %es:(%edi) )
21128 leal 2(%edi), %edi
21129 je 6f
21130 shll $16,%ecx
21131 SRC(5: movb (%esi), %cl )
21132 -DST( movb %cl, (%edi) )
21133 +DST( movb %cl, %es:(%edi) )
21134 6: addl %ecx, %eax
21135 adcl $0, %eax
21136 7:
21137 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21138
21139 6001:
21140 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21141 - movl $-EFAULT, (%ebx)
21142 + movl $-EFAULT, %ss:(%ebx)
21143
21144 # zero the complete destination - computing the rest
21145 # is too much work
21146 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21147
21148 6002:
21149 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21150 - movl $-EFAULT,(%ebx)
21151 + movl $-EFAULT,%ss:(%ebx)
21152 jmp 5000b
21153
21154 .previous
21155
21156 + pushl_cfi %ss
21157 + popl_cfi %ds
21158 + pushl_cfi %ss
21159 + popl_cfi %es
21160 popl_cfi %ebx
21161 CFI_RESTORE ebx
21162 popl_cfi %esi
21163 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21164 popl_cfi %ecx # equivalent to addl $4,%esp
21165 ret
21166 CFI_ENDPROC
21167 -ENDPROC(csum_partial_copy_generic)
21168 +ENDPROC(csum_partial_copy_generic_to_user)
21169
21170 #else
21171
21172 /* Version for PentiumII/PPro */
21173
21174 #define ROUND1(x) \
21175 + nop; nop; nop; \
21176 SRC(movl x(%esi), %ebx ) ; \
21177 addl %ebx, %eax ; \
21178 - DST(movl %ebx, x(%edi) ) ;
21179 + DST(movl %ebx, %es:x(%edi)) ;
21180
21181 #define ROUND(x) \
21182 + nop; nop; nop; \
21183 SRC(movl x(%esi), %ebx ) ; \
21184 adcl %ebx, %eax ; \
21185 - DST(movl %ebx, x(%edi) ) ;
21186 + DST(movl %ebx, %es:x(%edi)) ;
21187
21188 #define ARGBASE 12
21189 -
21190 -ENTRY(csum_partial_copy_generic)
21191 +
21192 +ENTRY(csum_partial_copy_generic_to_user)
21193 CFI_STARTPROC
21194 +
21195 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21196 + pushl_cfi %gs
21197 + popl_cfi %es
21198 + jmp csum_partial_copy_generic
21199 +#endif
21200 +
21201 +ENTRY(csum_partial_copy_generic_from_user)
21202 +
21203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21204 + pushl_cfi %gs
21205 + popl_cfi %ds
21206 +#endif
21207 +
21208 +ENTRY(csum_partial_copy_generic)
21209 pushl_cfi %ebx
21210 CFI_REL_OFFSET ebx, 0
21211 pushl_cfi %edi
21212 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21213 subl %ebx, %edi
21214 lea -1(%esi),%edx
21215 andl $-32,%edx
21216 - lea 3f(%ebx,%ebx), %ebx
21217 + lea 3f(%ebx,%ebx,2), %ebx
21218 testl %esi, %esi
21219 jmp *%ebx
21220 1: addl $64,%esi
21221 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21222 jb 5f
21223 SRC( movw (%esi), %dx )
21224 leal 2(%esi), %esi
21225 -DST( movw %dx, (%edi) )
21226 +DST( movw %dx, %es:(%edi) )
21227 leal 2(%edi), %edi
21228 je 6f
21229 shll $16,%edx
21230 5:
21231 SRC( movb (%esi), %dl )
21232 -DST( movb %dl, (%edi) )
21233 +DST( movb %dl, %es:(%edi) )
21234 6: addl %edx, %eax
21235 adcl $0, %eax
21236 7:
21237 .section .fixup, "ax"
21238 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21239 - movl $-EFAULT, (%ebx)
21240 + movl $-EFAULT, %ss:(%ebx)
21241 # zero the complete destination (computing the rest is too much work)
21242 movl ARGBASE+8(%esp),%edi # dst
21243 movl ARGBASE+12(%esp),%ecx # len
21244 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21245 rep; stosb
21246 jmp 7b
21247 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21248 - movl $-EFAULT, (%ebx)
21249 + movl $-EFAULT, %ss:(%ebx)
21250 jmp 7b
21251 .previous
21252
21253 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21254 + pushl_cfi %ss
21255 + popl_cfi %ds
21256 + pushl_cfi %ss
21257 + popl_cfi %es
21258 +#endif
21259 +
21260 popl_cfi %esi
21261 CFI_RESTORE esi
21262 popl_cfi %edi
21263 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21264 CFI_RESTORE ebx
21265 ret
21266 CFI_ENDPROC
21267 -ENDPROC(csum_partial_copy_generic)
21268 +ENDPROC(csum_partial_copy_generic_to_user)
21269
21270 #undef ROUND
21271 #undef ROUND1
21272 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21273 index f2145cf..cea889d 100644
21274 --- a/arch/x86/lib/clear_page_64.S
21275 +++ b/arch/x86/lib/clear_page_64.S
21276 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21277 movl $4096/8,%ecx
21278 xorl %eax,%eax
21279 rep stosq
21280 + pax_force_retaddr
21281 ret
21282 CFI_ENDPROC
21283 ENDPROC(clear_page_c)
21284 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21285 movl $4096,%ecx
21286 xorl %eax,%eax
21287 rep stosb
21288 + pax_force_retaddr
21289 ret
21290 CFI_ENDPROC
21291 ENDPROC(clear_page_c_e)
21292 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21293 leaq 64(%rdi),%rdi
21294 jnz .Lloop
21295 nop
21296 + pax_force_retaddr
21297 ret
21298 CFI_ENDPROC
21299 .Lclear_page_end:
21300 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21301
21302 #include <asm/cpufeature.h>
21303
21304 - .section .altinstr_replacement,"ax"
21305 + .section .altinstr_replacement,"a"
21306 1: .byte 0xeb /* jmp <disp8> */
21307 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21308 2: .byte 0xeb /* jmp <disp8> */
21309 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21310 index 1e572c5..2a162cd 100644
21311 --- a/arch/x86/lib/cmpxchg16b_emu.S
21312 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21313 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21314
21315 popf
21316 mov $1, %al
21317 + pax_force_retaddr
21318 ret
21319
21320 not_same:
21321 popf
21322 xor %al,%al
21323 + pax_force_retaddr
21324 ret
21325
21326 CFI_ENDPROC
21327 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21328 index 6b34d04..dccb07f 100644
21329 --- a/arch/x86/lib/copy_page_64.S
21330 +++ b/arch/x86/lib/copy_page_64.S
21331 @@ -9,6 +9,7 @@ copy_page_c:
21332 CFI_STARTPROC
21333 movl $4096/8,%ecx
21334 rep movsq
21335 + pax_force_retaddr
21336 ret
21337 CFI_ENDPROC
21338 ENDPROC(copy_page_c)
21339 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21340
21341 ENTRY(copy_page)
21342 CFI_STARTPROC
21343 - subq $2*8,%rsp
21344 - CFI_ADJUST_CFA_OFFSET 2*8
21345 + subq $3*8,%rsp
21346 + CFI_ADJUST_CFA_OFFSET 3*8
21347 movq %rbx,(%rsp)
21348 CFI_REL_OFFSET rbx, 0
21349 movq %r12,1*8(%rsp)
21350 CFI_REL_OFFSET r12, 1*8
21351 + movq %r13,2*8(%rsp)
21352 + CFI_REL_OFFSET r13, 2*8
21353
21354 movl $(4096/64)-5,%ecx
21355 .p2align 4
21356 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21357 movq 16 (%rsi), %rdx
21358 movq 24 (%rsi), %r8
21359 movq 32 (%rsi), %r9
21360 - movq 40 (%rsi), %r10
21361 + movq 40 (%rsi), %r13
21362 movq 48 (%rsi), %r11
21363 movq 56 (%rsi), %r12
21364
21365 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21366 movq %rdx, 16 (%rdi)
21367 movq %r8, 24 (%rdi)
21368 movq %r9, 32 (%rdi)
21369 - movq %r10, 40 (%rdi)
21370 + movq %r13, 40 (%rdi)
21371 movq %r11, 48 (%rdi)
21372 movq %r12, 56 (%rdi)
21373
21374 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21375 movq 16 (%rsi), %rdx
21376 movq 24 (%rsi), %r8
21377 movq 32 (%rsi), %r9
21378 - movq 40 (%rsi), %r10
21379 + movq 40 (%rsi), %r13
21380 movq 48 (%rsi), %r11
21381 movq 56 (%rsi), %r12
21382
21383 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21384 movq %rdx, 16 (%rdi)
21385 movq %r8, 24 (%rdi)
21386 movq %r9, 32 (%rdi)
21387 - movq %r10, 40 (%rdi)
21388 + movq %r13, 40 (%rdi)
21389 movq %r11, 48 (%rdi)
21390 movq %r12, 56 (%rdi)
21391
21392 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21393 CFI_RESTORE rbx
21394 movq 1*8(%rsp),%r12
21395 CFI_RESTORE r12
21396 - addq $2*8,%rsp
21397 - CFI_ADJUST_CFA_OFFSET -2*8
21398 + movq 2*8(%rsp),%r13
21399 + CFI_RESTORE r13
21400 + addq $3*8,%rsp
21401 + CFI_ADJUST_CFA_OFFSET -3*8
21402 + pax_force_retaddr
21403 ret
21404 .Lcopy_page_end:
21405 CFI_ENDPROC
21406 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21407
21408 #include <asm/cpufeature.h>
21409
21410 - .section .altinstr_replacement,"ax"
21411 + .section .altinstr_replacement,"a"
21412 1: .byte 0xeb /* jmp <disp8> */
21413 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21414 2:
21415 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21416 index 5b2995f..78e7644 100644
21417 --- a/arch/x86/lib/copy_user_64.S
21418 +++ b/arch/x86/lib/copy_user_64.S
21419 @@ -17,6 +17,7 @@
21420 #include <asm/cpufeature.h>
21421 #include <asm/alternative-asm.h>
21422 #include <asm/asm.h>
21423 +#include <asm/pgtable.h>
21424
21425 /*
21426 * By placing feature2 after feature1 in altinstructions section, we logically
21427 @@ -30,7 +31,7 @@
21428 .byte 0xe9 /* 32bit jump */
21429 .long \orig-1f /* by default jump to orig */
21430 1:
21431 - .section .altinstr_replacement,"ax"
21432 + .section .altinstr_replacement,"a"
21433 2: .byte 0xe9 /* near jump with 32bit immediate */
21434 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21435 3: .byte 0xe9 /* near jump with 32bit immediate */
21436 @@ -69,47 +70,20 @@
21437 #endif
21438 .endm
21439
21440 -/* Standard copy_to_user with segment limit checking */
21441 -ENTRY(_copy_to_user)
21442 - CFI_STARTPROC
21443 - GET_THREAD_INFO(%rax)
21444 - movq %rdi,%rcx
21445 - addq %rdx,%rcx
21446 - jc bad_to_user
21447 - cmpq TI_addr_limit(%rax),%rcx
21448 - ja bad_to_user
21449 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21450 - copy_user_generic_unrolled,copy_user_generic_string, \
21451 - copy_user_enhanced_fast_string
21452 - CFI_ENDPROC
21453 -ENDPROC(_copy_to_user)
21454 -
21455 -/* Standard copy_from_user with segment limit checking */
21456 -ENTRY(_copy_from_user)
21457 - CFI_STARTPROC
21458 - GET_THREAD_INFO(%rax)
21459 - movq %rsi,%rcx
21460 - addq %rdx,%rcx
21461 - jc bad_from_user
21462 - cmpq TI_addr_limit(%rax),%rcx
21463 - ja bad_from_user
21464 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21465 - copy_user_generic_unrolled,copy_user_generic_string, \
21466 - copy_user_enhanced_fast_string
21467 - CFI_ENDPROC
21468 -ENDPROC(_copy_from_user)
21469 -
21470 .section .fixup,"ax"
21471 /* must zero dest */
21472 ENTRY(bad_from_user)
21473 bad_from_user:
21474 CFI_STARTPROC
21475 + testl %edx,%edx
21476 + js bad_to_user
21477 movl %edx,%ecx
21478 xorl %eax,%eax
21479 rep
21480 stosb
21481 bad_to_user:
21482 movl %edx,%eax
21483 + pax_force_retaddr
21484 ret
21485 CFI_ENDPROC
21486 ENDPROC(bad_from_user)
21487 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21488 jz 17f
21489 1: movq (%rsi),%r8
21490 2: movq 1*8(%rsi),%r9
21491 -3: movq 2*8(%rsi),%r10
21492 +3: movq 2*8(%rsi),%rax
21493 4: movq 3*8(%rsi),%r11
21494 5: movq %r8,(%rdi)
21495 6: movq %r9,1*8(%rdi)
21496 -7: movq %r10,2*8(%rdi)
21497 +7: movq %rax,2*8(%rdi)
21498 8: movq %r11,3*8(%rdi)
21499 9: movq 4*8(%rsi),%r8
21500 10: movq 5*8(%rsi),%r9
21501 -11: movq 6*8(%rsi),%r10
21502 +11: movq 6*8(%rsi),%rax
21503 12: movq 7*8(%rsi),%r11
21504 13: movq %r8,4*8(%rdi)
21505 14: movq %r9,5*8(%rdi)
21506 -15: movq %r10,6*8(%rdi)
21507 +15: movq %rax,6*8(%rdi)
21508 16: movq %r11,7*8(%rdi)
21509 leaq 64(%rsi),%rsi
21510 leaq 64(%rdi),%rdi
21511 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21512 decl %ecx
21513 jnz 21b
21514 23: xor %eax,%eax
21515 + pax_force_retaddr
21516 ret
21517
21518 .section .fixup,"ax"
21519 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21520 3: rep
21521 movsb
21522 4: xorl %eax,%eax
21523 + pax_force_retaddr
21524 ret
21525
21526 .section .fixup,"ax"
21527 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21528 1: rep
21529 movsb
21530 2: xorl %eax,%eax
21531 + pax_force_retaddr
21532 ret
21533
21534 .section .fixup,"ax"
21535 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21536 index cacddc7..09d49e4 100644
21537 --- a/arch/x86/lib/copy_user_nocache_64.S
21538 +++ b/arch/x86/lib/copy_user_nocache_64.S
21539 @@ -8,6 +8,7 @@
21540
21541 #include <linux/linkage.h>
21542 #include <asm/dwarf2.h>
21543 +#include <asm/alternative-asm.h>
21544
21545 #define FIX_ALIGNMENT 1
21546
21547 @@ -15,6 +16,7 @@
21548 #include <asm/asm-offsets.h>
21549 #include <asm/thread_info.h>
21550 #include <asm/asm.h>
21551 +#include <asm/pgtable.h>
21552
21553 .macro ALIGN_DESTINATION
21554 #ifdef FIX_ALIGNMENT
21555 @@ -48,6 +50,15 @@
21556 */
21557 ENTRY(__copy_user_nocache)
21558 CFI_STARTPROC
21559 +
21560 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21561 + mov $PAX_USER_SHADOW_BASE,%rcx
21562 + cmp %rcx,%rsi
21563 + jae 1f
21564 + add %rcx,%rsi
21565 +1:
21566 +#endif
21567 +
21568 cmpl $8,%edx
21569 jb 20f /* less then 8 bytes, go to byte copy loop */
21570 ALIGN_DESTINATION
21571 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21572 jz 17f
21573 1: movq (%rsi),%r8
21574 2: movq 1*8(%rsi),%r9
21575 -3: movq 2*8(%rsi),%r10
21576 +3: movq 2*8(%rsi),%rax
21577 4: movq 3*8(%rsi),%r11
21578 5: movnti %r8,(%rdi)
21579 6: movnti %r9,1*8(%rdi)
21580 -7: movnti %r10,2*8(%rdi)
21581 +7: movnti %rax,2*8(%rdi)
21582 8: movnti %r11,3*8(%rdi)
21583 9: movq 4*8(%rsi),%r8
21584 10: movq 5*8(%rsi),%r9
21585 -11: movq 6*8(%rsi),%r10
21586 +11: movq 6*8(%rsi),%rax
21587 12: movq 7*8(%rsi),%r11
21588 13: movnti %r8,4*8(%rdi)
21589 14: movnti %r9,5*8(%rdi)
21590 -15: movnti %r10,6*8(%rdi)
21591 +15: movnti %rax,6*8(%rdi)
21592 16: movnti %r11,7*8(%rdi)
21593 leaq 64(%rsi),%rsi
21594 leaq 64(%rdi),%rdi
21595 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21596 jnz 21b
21597 23: xorl %eax,%eax
21598 sfence
21599 + pax_force_retaddr
21600 ret
21601
21602 .section .fixup,"ax"
21603 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21604 index 2419d5f..953ee51 100644
21605 --- a/arch/x86/lib/csum-copy_64.S
21606 +++ b/arch/x86/lib/csum-copy_64.S
21607 @@ -9,6 +9,7 @@
21608 #include <asm/dwarf2.h>
21609 #include <asm/errno.h>
21610 #include <asm/asm.h>
21611 +#include <asm/alternative-asm.h>
21612
21613 /*
21614 * Checksum copy with exception handling.
21615 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21616 CFI_RESTORE rbp
21617 addq $7*8, %rsp
21618 CFI_ADJUST_CFA_OFFSET -7*8
21619 + pax_force_retaddr 0, 1
21620 ret
21621 CFI_RESTORE_STATE
21622
21623 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21624 index 25b7ae8..3b52ccd 100644
21625 --- a/arch/x86/lib/csum-wrappers_64.c
21626 +++ b/arch/x86/lib/csum-wrappers_64.c
21627 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21628 len -= 2;
21629 }
21630 }
21631 - isum = csum_partial_copy_generic((__force const void *)src,
21632 +
21633 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21634 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21635 + src += PAX_USER_SHADOW_BASE;
21636 +#endif
21637 +
21638 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21639 dst, len, isum, errp, NULL);
21640 if (unlikely(*errp))
21641 goto out_err;
21642 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21643 }
21644
21645 *errp = 0;
21646 - return csum_partial_copy_generic(src, (void __force *)dst,
21647 +
21648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21649 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21650 + dst += PAX_USER_SHADOW_BASE;
21651 +#endif
21652 +
21653 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21654 len, isum, NULL, errp);
21655 }
21656 EXPORT_SYMBOL(csum_partial_copy_to_user);
21657 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21658 index b33b1fb..219f389 100644
21659 --- a/arch/x86/lib/getuser.S
21660 +++ b/arch/x86/lib/getuser.S
21661 @@ -33,15 +33,38 @@
21662 #include <asm/asm-offsets.h>
21663 #include <asm/thread_info.h>
21664 #include <asm/asm.h>
21665 +#include <asm/segment.h>
21666 +#include <asm/pgtable.h>
21667 +#include <asm/alternative-asm.h>
21668 +
21669 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21670 +#define __copyuser_seg gs;
21671 +#else
21672 +#define __copyuser_seg
21673 +#endif
21674
21675 .text
21676 ENTRY(__get_user_1)
21677 CFI_STARTPROC
21678 +
21679 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21680 GET_THREAD_INFO(%_ASM_DX)
21681 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21682 jae bad_get_user
21683 -1: movzb (%_ASM_AX),%edx
21684 +
21685 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21686 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21687 + cmp %_ASM_DX,%_ASM_AX
21688 + jae 1234f
21689 + add %_ASM_DX,%_ASM_AX
21690 +1234:
21691 +#endif
21692 +
21693 +#endif
21694 +
21695 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21696 xor %eax,%eax
21697 + pax_force_retaddr
21698 ret
21699 CFI_ENDPROC
21700 ENDPROC(__get_user_1)
21701 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21702 ENTRY(__get_user_2)
21703 CFI_STARTPROC
21704 add $1,%_ASM_AX
21705 +
21706 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21707 jc bad_get_user
21708 GET_THREAD_INFO(%_ASM_DX)
21709 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21710 jae bad_get_user
21711 -2: movzwl -1(%_ASM_AX),%edx
21712 +
21713 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21714 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21715 + cmp %_ASM_DX,%_ASM_AX
21716 + jae 1234f
21717 + add %_ASM_DX,%_ASM_AX
21718 +1234:
21719 +#endif
21720 +
21721 +#endif
21722 +
21723 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21724 xor %eax,%eax
21725 + pax_force_retaddr
21726 ret
21727 CFI_ENDPROC
21728 ENDPROC(__get_user_2)
21729 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21730 ENTRY(__get_user_4)
21731 CFI_STARTPROC
21732 add $3,%_ASM_AX
21733 +
21734 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21735 jc bad_get_user
21736 GET_THREAD_INFO(%_ASM_DX)
21737 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21738 jae bad_get_user
21739 -3: mov -3(%_ASM_AX),%edx
21740 +
21741 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21742 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21743 + cmp %_ASM_DX,%_ASM_AX
21744 + jae 1234f
21745 + add %_ASM_DX,%_ASM_AX
21746 +1234:
21747 +#endif
21748 +
21749 +#endif
21750 +
21751 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21752 xor %eax,%eax
21753 + pax_force_retaddr
21754 ret
21755 CFI_ENDPROC
21756 ENDPROC(__get_user_4)
21757 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21758 GET_THREAD_INFO(%_ASM_DX)
21759 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21760 jae bad_get_user
21761 +
21762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21763 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21764 + cmp %_ASM_DX,%_ASM_AX
21765 + jae 1234f
21766 + add %_ASM_DX,%_ASM_AX
21767 +1234:
21768 +#endif
21769 +
21770 4: movq -7(%_ASM_AX),%_ASM_DX
21771 xor %eax,%eax
21772 + pax_force_retaddr
21773 ret
21774 CFI_ENDPROC
21775 ENDPROC(__get_user_8)
21776 @@ -91,6 +152,7 @@ bad_get_user:
21777 CFI_STARTPROC
21778 xor %edx,%edx
21779 mov $(-EFAULT),%_ASM_AX
21780 + pax_force_retaddr
21781 ret
21782 CFI_ENDPROC
21783 END(bad_get_user)
21784 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21785 index b1e6c4b..21ae8fc 100644
21786 --- a/arch/x86/lib/insn.c
21787 +++ b/arch/x86/lib/insn.c
21788 @@ -21,6 +21,11 @@
21789 #include <linux/string.h>
21790 #include <asm/inat.h>
21791 #include <asm/insn.h>
21792 +#ifdef __KERNEL__
21793 +#include <asm/pgtable_types.h>
21794 +#else
21795 +#define ktla_ktva(addr) addr
21796 +#endif
21797
21798 /* Verify next sizeof(t) bytes can be on the same instruction */
21799 #define validate_next(t, insn, n) \
21800 @@ -49,8 +54,8 @@
21801 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21802 {
21803 memset(insn, 0, sizeof(*insn));
21804 - insn->kaddr = kaddr;
21805 - insn->next_byte = kaddr;
21806 + insn->kaddr = ktla_ktva(kaddr);
21807 + insn->next_byte = ktla_ktva(kaddr);
21808 insn->x86_64 = x86_64 ? 1 : 0;
21809 insn->opnd_bytes = 4;
21810 if (x86_64)
21811 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21812 index 05a95e7..326f2fa 100644
21813 --- a/arch/x86/lib/iomap_copy_64.S
21814 +++ b/arch/x86/lib/iomap_copy_64.S
21815 @@ -17,6 +17,7 @@
21816
21817 #include <linux/linkage.h>
21818 #include <asm/dwarf2.h>
21819 +#include <asm/alternative-asm.h>
21820
21821 /*
21822 * override generic version in lib/iomap_copy.c
21823 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21824 CFI_STARTPROC
21825 movl %edx,%ecx
21826 rep movsd
21827 + pax_force_retaddr
21828 ret
21829 CFI_ENDPROC
21830 ENDPROC(__iowrite32_copy)
21831 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21832 index 1c273be..da9cc0e 100644
21833 --- a/arch/x86/lib/memcpy_64.S
21834 +++ b/arch/x86/lib/memcpy_64.S
21835 @@ -33,6 +33,7 @@
21836 rep movsq
21837 movl %edx, %ecx
21838 rep movsb
21839 + pax_force_retaddr
21840 ret
21841 .Lmemcpy_e:
21842 .previous
21843 @@ -49,6 +50,7 @@
21844 movq %rdi, %rax
21845 movq %rdx, %rcx
21846 rep movsb
21847 + pax_force_retaddr
21848 ret
21849 .Lmemcpy_e_e:
21850 .previous
21851 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21852 */
21853 movq 0*8(%rsi), %r8
21854 movq 1*8(%rsi), %r9
21855 - movq 2*8(%rsi), %r10
21856 + movq 2*8(%rsi), %rcx
21857 movq 3*8(%rsi), %r11
21858 leaq 4*8(%rsi), %rsi
21859
21860 movq %r8, 0*8(%rdi)
21861 movq %r9, 1*8(%rdi)
21862 - movq %r10, 2*8(%rdi)
21863 + movq %rcx, 2*8(%rdi)
21864 movq %r11, 3*8(%rdi)
21865 leaq 4*8(%rdi), %rdi
21866 jae .Lcopy_forward_loop
21867 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21868 subq $0x20, %rdx
21869 movq -1*8(%rsi), %r8
21870 movq -2*8(%rsi), %r9
21871 - movq -3*8(%rsi), %r10
21872 + movq -3*8(%rsi), %rcx
21873 movq -4*8(%rsi), %r11
21874 leaq -4*8(%rsi), %rsi
21875 movq %r8, -1*8(%rdi)
21876 movq %r9, -2*8(%rdi)
21877 - movq %r10, -3*8(%rdi)
21878 + movq %rcx, -3*8(%rdi)
21879 movq %r11, -4*8(%rdi)
21880 leaq -4*8(%rdi), %rdi
21881 jae .Lcopy_backward_loop
21882 @@ -130,12 +132,13 @@ ENTRY(memcpy)
21883 */
21884 movq 0*8(%rsi), %r8
21885 movq 1*8(%rsi), %r9
21886 - movq -2*8(%rsi, %rdx), %r10
21887 + movq -2*8(%rsi, %rdx), %rcx
21888 movq -1*8(%rsi, %rdx), %r11
21889 movq %r8, 0*8(%rdi)
21890 movq %r9, 1*8(%rdi)
21891 - movq %r10, -2*8(%rdi, %rdx)
21892 + movq %rcx, -2*8(%rdi, %rdx)
21893 movq %r11, -1*8(%rdi, %rdx)
21894 + pax_force_retaddr
21895 retq
21896 .p2align 4
21897 .Lless_16bytes:
21898 @@ -148,6 +151,7 @@ ENTRY(memcpy)
21899 movq -1*8(%rsi, %rdx), %r9
21900 movq %r8, 0*8(%rdi)
21901 movq %r9, -1*8(%rdi, %rdx)
21902 + pax_force_retaddr
21903 retq
21904 .p2align 4
21905 .Lless_8bytes:
21906 @@ -161,6 +165,7 @@ ENTRY(memcpy)
21907 movl -4(%rsi, %rdx), %r8d
21908 movl %ecx, (%rdi)
21909 movl %r8d, -4(%rdi, %rdx)
21910 + pax_force_retaddr
21911 retq
21912 .p2align 4
21913 .Lless_3bytes:
21914 @@ -179,6 +184,7 @@ ENTRY(memcpy)
21915 movb %cl, (%rdi)
21916
21917 .Lend:
21918 + pax_force_retaddr
21919 retq
21920 CFI_ENDPROC
21921 ENDPROC(memcpy)
21922 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21923 index ee16461..c39c199 100644
21924 --- a/arch/x86/lib/memmove_64.S
21925 +++ b/arch/x86/lib/memmove_64.S
21926 @@ -61,13 +61,13 @@ ENTRY(memmove)
21927 5:
21928 sub $0x20, %rdx
21929 movq 0*8(%rsi), %r11
21930 - movq 1*8(%rsi), %r10
21931 + movq 1*8(%rsi), %rcx
21932 movq 2*8(%rsi), %r9
21933 movq 3*8(%rsi), %r8
21934 leaq 4*8(%rsi), %rsi
21935
21936 movq %r11, 0*8(%rdi)
21937 - movq %r10, 1*8(%rdi)
21938 + movq %rcx, 1*8(%rdi)
21939 movq %r9, 2*8(%rdi)
21940 movq %r8, 3*8(%rdi)
21941 leaq 4*8(%rdi), %rdi
21942 @@ -81,10 +81,10 @@ ENTRY(memmove)
21943 4:
21944 movq %rdx, %rcx
21945 movq -8(%rsi, %rdx), %r11
21946 - lea -8(%rdi, %rdx), %r10
21947 + lea -8(%rdi, %rdx), %r9
21948 shrq $3, %rcx
21949 rep movsq
21950 - movq %r11, (%r10)
21951 + movq %r11, (%r9)
21952 jmp 13f
21953 .Lmemmove_end_forward:
21954
21955 @@ -95,14 +95,14 @@ ENTRY(memmove)
21956 7:
21957 movq %rdx, %rcx
21958 movq (%rsi), %r11
21959 - movq %rdi, %r10
21960 + movq %rdi, %r9
21961 leaq -8(%rsi, %rdx), %rsi
21962 leaq -8(%rdi, %rdx), %rdi
21963 shrq $3, %rcx
21964 std
21965 rep movsq
21966 cld
21967 - movq %r11, (%r10)
21968 + movq %r11, (%r9)
21969 jmp 13f
21970
21971 /*
21972 @@ -127,13 +127,13 @@ ENTRY(memmove)
21973 8:
21974 subq $0x20, %rdx
21975 movq -1*8(%rsi), %r11
21976 - movq -2*8(%rsi), %r10
21977 + movq -2*8(%rsi), %rcx
21978 movq -3*8(%rsi), %r9
21979 movq -4*8(%rsi), %r8
21980 leaq -4*8(%rsi), %rsi
21981
21982 movq %r11, -1*8(%rdi)
21983 - movq %r10, -2*8(%rdi)
21984 + movq %rcx, -2*8(%rdi)
21985 movq %r9, -3*8(%rdi)
21986 movq %r8, -4*8(%rdi)
21987 leaq -4*8(%rdi), %rdi
21988 @@ -151,11 +151,11 @@ ENTRY(memmove)
21989 * Move data from 16 bytes to 31 bytes.
21990 */
21991 movq 0*8(%rsi), %r11
21992 - movq 1*8(%rsi), %r10
21993 + movq 1*8(%rsi), %rcx
21994 movq -2*8(%rsi, %rdx), %r9
21995 movq -1*8(%rsi, %rdx), %r8
21996 movq %r11, 0*8(%rdi)
21997 - movq %r10, 1*8(%rdi)
21998 + movq %rcx, 1*8(%rdi)
21999 movq %r9, -2*8(%rdi, %rdx)
22000 movq %r8, -1*8(%rdi, %rdx)
22001 jmp 13f
22002 @@ -167,9 +167,9 @@ ENTRY(memmove)
22003 * Move data from 8 bytes to 15 bytes.
22004 */
22005 movq 0*8(%rsi), %r11
22006 - movq -1*8(%rsi, %rdx), %r10
22007 + movq -1*8(%rsi, %rdx), %r9
22008 movq %r11, 0*8(%rdi)
22009 - movq %r10, -1*8(%rdi, %rdx)
22010 + movq %r9, -1*8(%rdi, %rdx)
22011 jmp 13f
22012 10:
22013 cmpq $4, %rdx
22014 @@ -178,9 +178,9 @@ ENTRY(memmove)
22015 * Move data from 4 bytes to 7 bytes.
22016 */
22017 movl (%rsi), %r11d
22018 - movl -4(%rsi, %rdx), %r10d
22019 + movl -4(%rsi, %rdx), %r9d
22020 movl %r11d, (%rdi)
22021 - movl %r10d, -4(%rdi, %rdx)
22022 + movl %r9d, -4(%rdi, %rdx)
22023 jmp 13f
22024 11:
22025 cmp $2, %rdx
22026 @@ -189,9 +189,9 @@ ENTRY(memmove)
22027 * Move data from 2 bytes to 3 bytes.
22028 */
22029 movw (%rsi), %r11w
22030 - movw -2(%rsi, %rdx), %r10w
22031 + movw -2(%rsi, %rdx), %r9w
22032 movw %r11w, (%rdi)
22033 - movw %r10w, -2(%rdi, %rdx)
22034 + movw %r9w, -2(%rdi, %rdx)
22035 jmp 13f
22036 12:
22037 cmp $1, %rdx
22038 @@ -202,6 +202,7 @@ ENTRY(memmove)
22039 movb (%rsi), %r11b
22040 movb %r11b, (%rdi)
22041 13:
22042 + pax_force_retaddr
22043 retq
22044 CFI_ENDPROC
22045
22046 @@ -210,6 +211,7 @@ ENTRY(memmove)
22047 /* Forward moving data. */
22048 movq %rdx, %rcx
22049 rep movsb
22050 + pax_force_retaddr
22051 retq
22052 .Lmemmove_end_forward_efs:
22053 .previous
22054 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22055 index 2dcb380..963660a 100644
22056 --- a/arch/x86/lib/memset_64.S
22057 +++ b/arch/x86/lib/memset_64.S
22058 @@ -30,6 +30,7 @@
22059 movl %edx,%ecx
22060 rep stosb
22061 movq %r9,%rax
22062 + pax_force_retaddr
22063 ret
22064 .Lmemset_e:
22065 .previous
22066 @@ -52,6 +53,7 @@
22067 movq %rdx,%rcx
22068 rep stosb
22069 movq %r9,%rax
22070 + pax_force_retaddr
22071 ret
22072 .Lmemset_e_e:
22073 .previous
22074 @@ -59,7 +61,7 @@
22075 ENTRY(memset)
22076 ENTRY(__memset)
22077 CFI_STARTPROC
22078 - movq %rdi,%r10
22079 + movq %rdi,%r11
22080
22081 /* expand byte value */
22082 movzbl %sil,%ecx
22083 @@ -117,7 +119,8 @@ ENTRY(__memset)
22084 jnz .Lloop_1
22085
22086 .Lende:
22087 - movq %r10,%rax
22088 + movq %r11,%rax
22089 + pax_force_retaddr
22090 ret
22091
22092 CFI_RESTORE_STATE
22093 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22094 index c9f2d9b..e7fd2c0 100644
22095 --- a/arch/x86/lib/mmx_32.c
22096 +++ b/arch/x86/lib/mmx_32.c
22097 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22098 {
22099 void *p;
22100 int i;
22101 + unsigned long cr0;
22102
22103 if (unlikely(in_interrupt()))
22104 return __memcpy(to, from, len);
22105 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22106 kernel_fpu_begin();
22107
22108 __asm__ __volatile__ (
22109 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22110 - " prefetch 64(%0)\n"
22111 - " prefetch 128(%0)\n"
22112 - " prefetch 192(%0)\n"
22113 - " prefetch 256(%0)\n"
22114 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22115 + " prefetch 64(%1)\n"
22116 + " prefetch 128(%1)\n"
22117 + " prefetch 192(%1)\n"
22118 + " prefetch 256(%1)\n"
22119 "2: \n"
22120 ".section .fixup, \"ax\"\n"
22121 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22122 + "3: \n"
22123 +
22124 +#ifdef CONFIG_PAX_KERNEXEC
22125 + " movl %%cr0, %0\n"
22126 + " movl %0, %%eax\n"
22127 + " andl $0xFFFEFFFF, %%eax\n"
22128 + " movl %%eax, %%cr0\n"
22129 +#endif
22130 +
22131 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22132 +
22133 +#ifdef CONFIG_PAX_KERNEXEC
22134 + " movl %0, %%cr0\n"
22135 +#endif
22136 +
22137 " jmp 2b\n"
22138 ".previous\n"
22139 _ASM_EXTABLE(1b, 3b)
22140 - : : "r" (from));
22141 + : "=&r" (cr0) : "r" (from) : "ax");
22142
22143 for ( ; i > 5; i--) {
22144 __asm__ __volatile__ (
22145 - "1: prefetch 320(%0)\n"
22146 - "2: movq (%0), %%mm0\n"
22147 - " movq 8(%0), %%mm1\n"
22148 - " movq 16(%0), %%mm2\n"
22149 - " movq 24(%0), %%mm3\n"
22150 - " movq %%mm0, (%1)\n"
22151 - " movq %%mm1, 8(%1)\n"
22152 - " movq %%mm2, 16(%1)\n"
22153 - " movq %%mm3, 24(%1)\n"
22154 - " movq 32(%0), %%mm0\n"
22155 - " movq 40(%0), %%mm1\n"
22156 - " movq 48(%0), %%mm2\n"
22157 - " movq 56(%0), %%mm3\n"
22158 - " movq %%mm0, 32(%1)\n"
22159 - " movq %%mm1, 40(%1)\n"
22160 - " movq %%mm2, 48(%1)\n"
22161 - " movq %%mm3, 56(%1)\n"
22162 + "1: prefetch 320(%1)\n"
22163 + "2: movq (%1), %%mm0\n"
22164 + " movq 8(%1), %%mm1\n"
22165 + " movq 16(%1), %%mm2\n"
22166 + " movq 24(%1), %%mm3\n"
22167 + " movq %%mm0, (%2)\n"
22168 + " movq %%mm1, 8(%2)\n"
22169 + " movq %%mm2, 16(%2)\n"
22170 + " movq %%mm3, 24(%2)\n"
22171 + " movq 32(%1), %%mm0\n"
22172 + " movq 40(%1), %%mm1\n"
22173 + " movq 48(%1), %%mm2\n"
22174 + " movq 56(%1), %%mm3\n"
22175 + " movq %%mm0, 32(%2)\n"
22176 + " movq %%mm1, 40(%2)\n"
22177 + " movq %%mm2, 48(%2)\n"
22178 + " movq %%mm3, 56(%2)\n"
22179 ".section .fixup, \"ax\"\n"
22180 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22181 + "3:\n"
22182 +
22183 +#ifdef CONFIG_PAX_KERNEXEC
22184 + " movl %%cr0, %0\n"
22185 + " movl %0, %%eax\n"
22186 + " andl $0xFFFEFFFF, %%eax\n"
22187 + " movl %%eax, %%cr0\n"
22188 +#endif
22189 +
22190 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22191 +
22192 +#ifdef CONFIG_PAX_KERNEXEC
22193 + " movl %0, %%cr0\n"
22194 +#endif
22195 +
22196 " jmp 2b\n"
22197 ".previous\n"
22198 _ASM_EXTABLE(1b, 3b)
22199 - : : "r" (from), "r" (to) : "memory");
22200 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22201
22202 from += 64;
22203 to += 64;
22204 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22205 static void fast_copy_page(void *to, void *from)
22206 {
22207 int i;
22208 + unsigned long cr0;
22209
22210 kernel_fpu_begin();
22211
22212 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22213 * but that is for later. -AV
22214 */
22215 __asm__ __volatile__(
22216 - "1: prefetch (%0)\n"
22217 - " prefetch 64(%0)\n"
22218 - " prefetch 128(%0)\n"
22219 - " prefetch 192(%0)\n"
22220 - " prefetch 256(%0)\n"
22221 + "1: prefetch (%1)\n"
22222 + " prefetch 64(%1)\n"
22223 + " prefetch 128(%1)\n"
22224 + " prefetch 192(%1)\n"
22225 + " prefetch 256(%1)\n"
22226 "2: \n"
22227 ".section .fixup, \"ax\"\n"
22228 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22229 + "3: \n"
22230 +
22231 +#ifdef CONFIG_PAX_KERNEXEC
22232 + " movl %%cr0, %0\n"
22233 + " movl %0, %%eax\n"
22234 + " andl $0xFFFEFFFF, %%eax\n"
22235 + " movl %%eax, %%cr0\n"
22236 +#endif
22237 +
22238 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22239 +
22240 +#ifdef CONFIG_PAX_KERNEXEC
22241 + " movl %0, %%cr0\n"
22242 +#endif
22243 +
22244 " jmp 2b\n"
22245 ".previous\n"
22246 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22247 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22248
22249 for (i = 0; i < (4096-320)/64; i++) {
22250 __asm__ __volatile__ (
22251 - "1: prefetch 320(%0)\n"
22252 - "2: movq (%0), %%mm0\n"
22253 - " movntq %%mm0, (%1)\n"
22254 - " movq 8(%0), %%mm1\n"
22255 - " movntq %%mm1, 8(%1)\n"
22256 - " movq 16(%0), %%mm2\n"
22257 - " movntq %%mm2, 16(%1)\n"
22258 - " movq 24(%0), %%mm3\n"
22259 - " movntq %%mm3, 24(%1)\n"
22260 - " movq 32(%0), %%mm4\n"
22261 - " movntq %%mm4, 32(%1)\n"
22262 - " movq 40(%0), %%mm5\n"
22263 - " movntq %%mm5, 40(%1)\n"
22264 - " movq 48(%0), %%mm6\n"
22265 - " movntq %%mm6, 48(%1)\n"
22266 - " movq 56(%0), %%mm7\n"
22267 - " movntq %%mm7, 56(%1)\n"
22268 + "1: prefetch 320(%1)\n"
22269 + "2: movq (%1), %%mm0\n"
22270 + " movntq %%mm0, (%2)\n"
22271 + " movq 8(%1), %%mm1\n"
22272 + " movntq %%mm1, 8(%2)\n"
22273 + " movq 16(%1), %%mm2\n"
22274 + " movntq %%mm2, 16(%2)\n"
22275 + " movq 24(%1), %%mm3\n"
22276 + " movntq %%mm3, 24(%2)\n"
22277 + " movq 32(%1), %%mm4\n"
22278 + " movntq %%mm4, 32(%2)\n"
22279 + " movq 40(%1), %%mm5\n"
22280 + " movntq %%mm5, 40(%2)\n"
22281 + " movq 48(%1), %%mm6\n"
22282 + " movntq %%mm6, 48(%2)\n"
22283 + " movq 56(%1), %%mm7\n"
22284 + " movntq %%mm7, 56(%2)\n"
22285 ".section .fixup, \"ax\"\n"
22286 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22287 + "3:\n"
22288 +
22289 +#ifdef CONFIG_PAX_KERNEXEC
22290 + " movl %%cr0, %0\n"
22291 + " movl %0, %%eax\n"
22292 + " andl $0xFFFEFFFF, %%eax\n"
22293 + " movl %%eax, %%cr0\n"
22294 +#endif
22295 +
22296 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22297 +
22298 +#ifdef CONFIG_PAX_KERNEXEC
22299 + " movl %0, %%cr0\n"
22300 +#endif
22301 +
22302 " jmp 2b\n"
22303 ".previous\n"
22304 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22305 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22306
22307 from += 64;
22308 to += 64;
22309 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22310 static void fast_copy_page(void *to, void *from)
22311 {
22312 int i;
22313 + unsigned long cr0;
22314
22315 kernel_fpu_begin();
22316
22317 __asm__ __volatile__ (
22318 - "1: prefetch (%0)\n"
22319 - " prefetch 64(%0)\n"
22320 - " prefetch 128(%0)\n"
22321 - " prefetch 192(%0)\n"
22322 - " prefetch 256(%0)\n"
22323 + "1: prefetch (%1)\n"
22324 + " prefetch 64(%1)\n"
22325 + " prefetch 128(%1)\n"
22326 + " prefetch 192(%1)\n"
22327 + " prefetch 256(%1)\n"
22328 "2: \n"
22329 ".section .fixup, \"ax\"\n"
22330 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22331 + "3: \n"
22332 +
22333 +#ifdef CONFIG_PAX_KERNEXEC
22334 + " movl %%cr0, %0\n"
22335 + " movl %0, %%eax\n"
22336 + " andl $0xFFFEFFFF, %%eax\n"
22337 + " movl %%eax, %%cr0\n"
22338 +#endif
22339 +
22340 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22341 +
22342 +#ifdef CONFIG_PAX_KERNEXEC
22343 + " movl %0, %%cr0\n"
22344 +#endif
22345 +
22346 " jmp 2b\n"
22347 ".previous\n"
22348 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22349 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22350
22351 for (i = 0; i < 4096/64; i++) {
22352 __asm__ __volatile__ (
22353 - "1: prefetch 320(%0)\n"
22354 - "2: movq (%0), %%mm0\n"
22355 - " movq 8(%0), %%mm1\n"
22356 - " movq 16(%0), %%mm2\n"
22357 - " movq 24(%0), %%mm3\n"
22358 - " movq %%mm0, (%1)\n"
22359 - " movq %%mm1, 8(%1)\n"
22360 - " movq %%mm2, 16(%1)\n"
22361 - " movq %%mm3, 24(%1)\n"
22362 - " movq 32(%0), %%mm0\n"
22363 - " movq 40(%0), %%mm1\n"
22364 - " movq 48(%0), %%mm2\n"
22365 - " movq 56(%0), %%mm3\n"
22366 - " movq %%mm0, 32(%1)\n"
22367 - " movq %%mm1, 40(%1)\n"
22368 - " movq %%mm2, 48(%1)\n"
22369 - " movq %%mm3, 56(%1)\n"
22370 + "1: prefetch 320(%1)\n"
22371 + "2: movq (%1), %%mm0\n"
22372 + " movq 8(%1), %%mm1\n"
22373 + " movq 16(%1), %%mm2\n"
22374 + " movq 24(%1), %%mm3\n"
22375 + " movq %%mm0, (%2)\n"
22376 + " movq %%mm1, 8(%2)\n"
22377 + " movq %%mm2, 16(%2)\n"
22378 + " movq %%mm3, 24(%2)\n"
22379 + " movq 32(%1), %%mm0\n"
22380 + " movq 40(%1), %%mm1\n"
22381 + " movq 48(%1), %%mm2\n"
22382 + " movq 56(%1), %%mm3\n"
22383 + " movq %%mm0, 32(%2)\n"
22384 + " movq %%mm1, 40(%2)\n"
22385 + " movq %%mm2, 48(%2)\n"
22386 + " movq %%mm3, 56(%2)\n"
22387 ".section .fixup, \"ax\"\n"
22388 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22389 + "3:\n"
22390 +
22391 +#ifdef CONFIG_PAX_KERNEXEC
22392 + " movl %%cr0, %0\n"
22393 + " movl %0, %%eax\n"
22394 + " andl $0xFFFEFFFF, %%eax\n"
22395 + " movl %%eax, %%cr0\n"
22396 +#endif
22397 +
22398 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22399 +
22400 +#ifdef CONFIG_PAX_KERNEXEC
22401 + " movl %0, %%cr0\n"
22402 +#endif
22403 +
22404 " jmp 2b\n"
22405 ".previous\n"
22406 _ASM_EXTABLE(1b, 3b)
22407 - : : "r" (from), "r" (to) : "memory");
22408 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22409
22410 from += 64;
22411 to += 64;
22412 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22413 index 69fa106..adda88b 100644
22414 --- a/arch/x86/lib/msr-reg.S
22415 +++ b/arch/x86/lib/msr-reg.S
22416 @@ -3,6 +3,7 @@
22417 #include <asm/dwarf2.h>
22418 #include <asm/asm.h>
22419 #include <asm/msr.h>
22420 +#include <asm/alternative-asm.h>
22421
22422 #ifdef CONFIG_X86_64
22423 /*
22424 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22425 CFI_STARTPROC
22426 pushq_cfi %rbx
22427 pushq_cfi %rbp
22428 - movq %rdi, %r10 /* Save pointer */
22429 + movq %rdi, %r9 /* Save pointer */
22430 xorl %r11d, %r11d /* Return value */
22431 movl (%rdi), %eax
22432 movl 4(%rdi), %ecx
22433 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22434 movl 28(%rdi), %edi
22435 CFI_REMEMBER_STATE
22436 1: \op
22437 -2: movl %eax, (%r10)
22438 +2: movl %eax, (%r9)
22439 movl %r11d, %eax /* Return value */
22440 - movl %ecx, 4(%r10)
22441 - movl %edx, 8(%r10)
22442 - movl %ebx, 12(%r10)
22443 - movl %ebp, 20(%r10)
22444 - movl %esi, 24(%r10)
22445 - movl %edi, 28(%r10)
22446 + movl %ecx, 4(%r9)
22447 + movl %edx, 8(%r9)
22448 + movl %ebx, 12(%r9)
22449 + movl %ebp, 20(%r9)
22450 + movl %esi, 24(%r9)
22451 + movl %edi, 28(%r9)
22452 popq_cfi %rbp
22453 popq_cfi %rbx
22454 + pax_force_retaddr
22455 ret
22456 3:
22457 CFI_RESTORE_STATE
22458 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22459 index 7f951c8..ebd573a 100644
22460 --- a/arch/x86/lib/putuser.S
22461 +++ b/arch/x86/lib/putuser.S
22462 @@ -15,7 +15,9 @@
22463 #include <asm/thread_info.h>
22464 #include <asm/errno.h>
22465 #include <asm/asm.h>
22466 -
22467 +#include <asm/segment.h>
22468 +#include <asm/pgtable.h>
22469 +#include <asm/alternative-asm.h>
22470
22471 /*
22472 * __put_user_X
22473 @@ -29,52 +31,119 @@
22474 * as they get called from within inline assembly.
22475 */
22476
22477 -#define ENTER CFI_STARTPROC ; \
22478 - GET_THREAD_INFO(%_ASM_BX)
22479 -#define EXIT ret ; \
22480 +#define ENTER CFI_STARTPROC
22481 +#define EXIT pax_force_retaddr; ret ; \
22482 CFI_ENDPROC
22483
22484 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22485 +#define _DEST %_ASM_CX,%_ASM_BX
22486 +#else
22487 +#define _DEST %_ASM_CX
22488 +#endif
22489 +
22490 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22491 +#define __copyuser_seg gs;
22492 +#else
22493 +#define __copyuser_seg
22494 +#endif
22495 +
22496 .text
22497 ENTRY(__put_user_1)
22498 ENTER
22499 +
22500 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22501 + GET_THREAD_INFO(%_ASM_BX)
22502 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22503 jae bad_put_user
22504 -1: movb %al,(%_ASM_CX)
22505 +
22506 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22507 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22508 + cmp %_ASM_BX,%_ASM_CX
22509 + jb 1234f
22510 + xor %ebx,%ebx
22511 +1234:
22512 +#endif
22513 +
22514 +#endif
22515 +
22516 +1: __copyuser_seg movb %al,(_DEST)
22517 xor %eax,%eax
22518 EXIT
22519 ENDPROC(__put_user_1)
22520
22521 ENTRY(__put_user_2)
22522 ENTER
22523 +
22524 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22525 + GET_THREAD_INFO(%_ASM_BX)
22526 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22527 sub $1,%_ASM_BX
22528 cmp %_ASM_BX,%_ASM_CX
22529 jae bad_put_user
22530 -2: movw %ax,(%_ASM_CX)
22531 +
22532 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22533 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22534 + cmp %_ASM_BX,%_ASM_CX
22535 + jb 1234f
22536 + xor %ebx,%ebx
22537 +1234:
22538 +#endif
22539 +
22540 +#endif
22541 +
22542 +2: __copyuser_seg movw %ax,(_DEST)
22543 xor %eax,%eax
22544 EXIT
22545 ENDPROC(__put_user_2)
22546
22547 ENTRY(__put_user_4)
22548 ENTER
22549 +
22550 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22551 + GET_THREAD_INFO(%_ASM_BX)
22552 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22553 sub $3,%_ASM_BX
22554 cmp %_ASM_BX,%_ASM_CX
22555 jae bad_put_user
22556 -3: movl %eax,(%_ASM_CX)
22557 +
22558 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22559 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22560 + cmp %_ASM_BX,%_ASM_CX
22561 + jb 1234f
22562 + xor %ebx,%ebx
22563 +1234:
22564 +#endif
22565 +
22566 +#endif
22567 +
22568 +3: __copyuser_seg movl %eax,(_DEST)
22569 xor %eax,%eax
22570 EXIT
22571 ENDPROC(__put_user_4)
22572
22573 ENTRY(__put_user_8)
22574 ENTER
22575 +
22576 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22577 + GET_THREAD_INFO(%_ASM_BX)
22578 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22579 sub $7,%_ASM_BX
22580 cmp %_ASM_BX,%_ASM_CX
22581 jae bad_put_user
22582 -4: mov %_ASM_AX,(%_ASM_CX)
22583 +
22584 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22585 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22586 + cmp %_ASM_BX,%_ASM_CX
22587 + jb 1234f
22588 + xor %ebx,%ebx
22589 +1234:
22590 +#endif
22591 +
22592 +#endif
22593 +
22594 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22595 #ifdef CONFIG_X86_32
22596 -5: movl %edx,4(%_ASM_CX)
22597 +5: __copyuser_seg movl %edx,4(_DEST)
22598 #endif
22599 xor %eax,%eax
22600 EXIT
22601 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22602 index 1cad221..de671ee 100644
22603 --- a/arch/x86/lib/rwlock.S
22604 +++ b/arch/x86/lib/rwlock.S
22605 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22606 FRAME
22607 0: LOCK_PREFIX
22608 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22609 +
22610 +#ifdef CONFIG_PAX_REFCOUNT
22611 + jno 1234f
22612 + LOCK_PREFIX
22613 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22614 + int $4
22615 +1234:
22616 + _ASM_EXTABLE(1234b, 1234b)
22617 +#endif
22618 +
22619 1: rep; nop
22620 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22621 jne 1b
22622 LOCK_PREFIX
22623 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22624 +
22625 +#ifdef CONFIG_PAX_REFCOUNT
22626 + jno 1234f
22627 + LOCK_PREFIX
22628 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22629 + int $4
22630 +1234:
22631 + _ASM_EXTABLE(1234b, 1234b)
22632 +#endif
22633 +
22634 jnz 0b
22635 ENDFRAME
22636 + pax_force_retaddr
22637 ret
22638 CFI_ENDPROC
22639 END(__write_lock_failed)
22640 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22641 FRAME
22642 0: LOCK_PREFIX
22643 READ_LOCK_SIZE(inc) (%__lock_ptr)
22644 +
22645 +#ifdef CONFIG_PAX_REFCOUNT
22646 + jno 1234f
22647 + LOCK_PREFIX
22648 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22649 + int $4
22650 +1234:
22651 + _ASM_EXTABLE(1234b, 1234b)
22652 +#endif
22653 +
22654 1: rep; nop
22655 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22656 js 1b
22657 LOCK_PREFIX
22658 READ_LOCK_SIZE(dec) (%__lock_ptr)
22659 +
22660 +#ifdef CONFIG_PAX_REFCOUNT
22661 + jno 1234f
22662 + LOCK_PREFIX
22663 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22664 + int $4
22665 +1234:
22666 + _ASM_EXTABLE(1234b, 1234b)
22667 +#endif
22668 +
22669 js 0b
22670 ENDFRAME
22671 + pax_force_retaddr
22672 ret
22673 CFI_ENDPROC
22674 END(__read_lock_failed)
22675 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22676 index 5dff5f0..cadebf4 100644
22677 --- a/arch/x86/lib/rwsem.S
22678 +++ b/arch/x86/lib/rwsem.S
22679 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22680 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22681 CFI_RESTORE __ASM_REG(dx)
22682 restore_common_regs
22683 + pax_force_retaddr
22684 ret
22685 CFI_ENDPROC
22686 ENDPROC(call_rwsem_down_read_failed)
22687 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22688 movq %rax,%rdi
22689 call rwsem_down_write_failed
22690 restore_common_regs
22691 + pax_force_retaddr
22692 ret
22693 CFI_ENDPROC
22694 ENDPROC(call_rwsem_down_write_failed)
22695 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22696 movq %rax,%rdi
22697 call rwsem_wake
22698 restore_common_regs
22699 -1: ret
22700 +1: pax_force_retaddr
22701 + ret
22702 CFI_ENDPROC
22703 ENDPROC(call_rwsem_wake)
22704
22705 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22706 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22707 CFI_RESTORE __ASM_REG(dx)
22708 restore_common_regs
22709 + pax_force_retaddr
22710 ret
22711 CFI_ENDPROC
22712 ENDPROC(call_rwsem_downgrade_wake)
22713 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22714 index a63efd6..ccecad8 100644
22715 --- a/arch/x86/lib/thunk_64.S
22716 +++ b/arch/x86/lib/thunk_64.S
22717 @@ -8,6 +8,7 @@
22718 #include <linux/linkage.h>
22719 #include <asm/dwarf2.h>
22720 #include <asm/calling.h>
22721 +#include <asm/alternative-asm.h>
22722
22723 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22724 .macro THUNK name, func, put_ret_addr_in_rdi=0
22725 @@ -41,5 +42,6 @@
22726 SAVE_ARGS
22727 restore:
22728 RESTORE_ARGS
22729 + pax_force_retaddr
22730 ret
22731 CFI_ENDPROC
22732 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22733 index 1781b2f..90368dd 100644
22734 --- a/arch/x86/lib/usercopy_32.c
22735 +++ b/arch/x86/lib/usercopy_32.c
22736 @@ -42,10 +42,12 @@ do { \
22737 int __d0; \
22738 might_fault(); \
22739 __asm__ __volatile__( \
22740 + __COPYUSER_SET_ES \
22741 "0: rep; stosl\n" \
22742 " movl %2,%0\n" \
22743 "1: rep; stosb\n" \
22744 "2:\n" \
22745 + __COPYUSER_RESTORE_ES \
22746 ".section .fixup,\"ax\"\n" \
22747 "3: lea 0(%2,%0,4),%0\n" \
22748 " jmp 2b\n" \
22749 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22750
22751 #ifdef CONFIG_X86_INTEL_USERCOPY
22752 static unsigned long
22753 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22754 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22755 {
22756 int d0, d1;
22757 __asm__ __volatile__(
22758 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22759 " .align 2,0x90\n"
22760 "3: movl 0(%4), %%eax\n"
22761 "4: movl 4(%4), %%edx\n"
22762 - "5: movl %%eax, 0(%3)\n"
22763 - "6: movl %%edx, 4(%3)\n"
22764 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22765 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22766 "7: movl 8(%4), %%eax\n"
22767 "8: movl 12(%4),%%edx\n"
22768 - "9: movl %%eax, 8(%3)\n"
22769 - "10: movl %%edx, 12(%3)\n"
22770 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22771 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22772 "11: movl 16(%4), %%eax\n"
22773 "12: movl 20(%4), %%edx\n"
22774 - "13: movl %%eax, 16(%3)\n"
22775 - "14: movl %%edx, 20(%3)\n"
22776 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22777 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22778 "15: movl 24(%4), %%eax\n"
22779 "16: movl 28(%4), %%edx\n"
22780 - "17: movl %%eax, 24(%3)\n"
22781 - "18: movl %%edx, 28(%3)\n"
22782 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22783 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22784 "19: movl 32(%4), %%eax\n"
22785 "20: movl 36(%4), %%edx\n"
22786 - "21: movl %%eax, 32(%3)\n"
22787 - "22: movl %%edx, 36(%3)\n"
22788 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22789 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22790 "23: movl 40(%4), %%eax\n"
22791 "24: movl 44(%4), %%edx\n"
22792 - "25: movl %%eax, 40(%3)\n"
22793 - "26: movl %%edx, 44(%3)\n"
22794 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22795 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22796 "27: movl 48(%4), %%eax\n"
22797 "28: movl 52(%4), %%edx\n"
22798 - "29: movl %%eax, 48(%3)\n"
22799 - "30: movl %%edx, 52(%3)\n"
22800 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22801 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22802 "31: movl 56(%4), %%eax\n"
22803 "32: movl 60(%4), %%edx\n"
22804 - "33: movl %%eax, 56(%3)\n"
22805 - "34: movl %%edx, 60(%3)\n"
22806 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22807 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22808 " addl $-64, %0\n"
22809 " addl $64, %4\n"
22810 " addl $64, %3\n"
22811 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22812 " shrl $2, %0\n"
22813 " andl $3, %%eax\n"
22814 " cld\n"
22815 + __COPYUSER_SET_ES
22816 "99: rep; movsl\n"
22817 "36: movl %%eax, %0\n"
22818 "37: rep; movsb\n"
22819 "100:\n"
22820 + __COPYUSER_RESTORE_ES
22821 ".section .fixup,\"ax\"\n"
22822 "101: lea 0(%%eax,%0,4),%0\n"
22823 " jmp 100b\n"
22824 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22825 }
22826
22827 static unsigned long
22828 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22829 +{
22830 + int d0, d1;
22831 + __asm__ __volatile__(
22832 + " .align 2,0x90\n"
22833 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22834 + " cmpl $67, %0\n"
22835 + " jbe 3f\n"
22836 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22837 + " .align 2,0x90\n"
22838 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22839 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22840 + "5: movl %%eax, 0(%3)\n"
22841 + "6: movl %%edx, 4(%3)\n"
22842 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22843 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22844 + "9: movl %%eax, 8(%3)\n"
22845 + "10: movl %%edx, 12(%3)\n"
22846 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22847 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22848 + "13: movl %%eax, 16(%3)\n"
22849 + "14: movl %%edx, 20(%3)\n"
22850 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22851 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22852 + "17: movl %%eax, 24(%3)\n"
22853 + "18: movl %%edx, 28(%3)\n"
22854 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22855 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22856 + "21: movl %%eax, 32(%3)\n"
22857 + "22: movl %%edx, 36(%3)\n"
22858 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22859 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22860 + "25: movl %%eax, 40(%3)\n"
22861 + "26: movl %%edx, 44(%3)\n"
22862 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22863 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22864 + "29: movl %%eax, 48(%3)\n"
22865 + "30: movl %%edx, 52(%3)\n"
22866 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22867 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22868 + "33: movl %%eax, 56(%3)\n"
22869 + "34: movl %%edx, 60(%3)\n"
22870 + " addl $-64, %0\n"
22871 + " addl $64, %4\n"
22872 + " addl $64, %3\n"
22873 + " cmpl $63, %0\n"
22874 + " ja 1b\n"
22875 + "35: movl %0, %%eax\n"
22876 + " shrl $2, %0\n"
22877 + " andl $3, %%eax\n"
22878 + " cld\n"
22879 + "99: rep; "__copyuser_seg" movsl\n"
22880 + "36: movl %%eax, %0\n"
22881 + "37: rep; "__copyuser_seg" movsb\n"
22882 + "100:\n"
22883 + ".section .fixup,\"ax\"\n"
22884 + "101: lea 0(%%eax,%0,4),%0\n"
22885 + " jmp 100b\n"
22886 + ".previous\n"
22887 + _ASM_EXTABLE(1b,100b)
22888 + _ASM_EXTABLE(2b,100b)
22889 + _ASM_EXTABLE(3b,100b)
22890 + _ASM_EXTABLE(4b,100b)
22891 + _ASM_EXTABLE(5b,100b)
22892 + _ASM_EXTABLE(6b,100b)
22893 + _ASM_EXTABLE(7b,100b)
22894 + _ASM_EXTABLE(8b,100b)
22895 + _ASM_EXTABLE(9b,100b)
22896 + _ASM_EXTABLE(10b,100b)
22897 + _ASM_EXTABLE(11b,100b)
22898 + _ASM_EXTABLE(12b,100b)
22899 + _ASM_EXTABLE(13b,100b)
22900 + _ASM_EXTABLE(14b,100b)
22901 + _ASM_EXTABLE(15b,100b)
22902 + _ASM_EXTABLE(16b,100b)
22903 + _ASM_EXTABLE(17b,100b)
22904 + _ASM_EXTABLE(18b,100b)
22905 + _ASM_EXTABLE(19b,100b)
22906 + _ASM_EXTABLE(20b,100b)
22907 + _ASM_EXTABLE(21b,100b)
22908 + _ASM_EXTABLE(22b,100b)
22909 + _ASM_EXTABLE(23b,100b)
22910 + _ASM_EXTABLE(24b,100b)
22911 + _ASM_EXTABLE(25b,100b)
22912 + _ASM_EXTABLE(26b,100b)
22913 + _ASM_EXTABLE(27b,100b)
22914 + _ASM_EXTABLE(28b,100b)
22915 + _ASM_EXTABLE(29b,100b)
22916 + _ASM_EXTABLE(30b,100b)
22917 + _ASM_EXTABLE(31b,100b)
22918 + _ASM_EXTABLE(32b,100b)
22919 + _ASM_EXTABLE(33b,100b)
22920 + _ASM_EXTABLE(34b,100b)
22921 + _ASM_EXTABLE(35b,100b)
22922 + _ASM_EXTABLE(36b,100b)
22923 + _ASM_EXTABLE(37b,100b)
22924 + _ASM_EXTABLE(99b,101b)
22925 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22926 + : "1"(to), "2"(from), "0"(size)
22927 + : "eax", "edx", "memory");
22928 + return size;
22929 +}
22930 +
22931 +static unsigned long __size_overflow(3)
22932 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22933 {
22934 int d0, d1;
22935 __asm__ __volatile__(
22936 " .align 2,0x90\n"
22937 - "0: movl 32(%4), %%eax\n"
22938 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22939 " cmpl $67, %0\n"
22940 " jbe 2f\n"
22941 - "1: movl 64(%4), %%eax\n"
22942 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22943 " .align 2,0x90\n"
22944 - "2: movl 0(%4), %%eax\n"
22945 - "21: movl 4(%4), %%edx\n"
22946 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22947 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22948 " movl %%eax, 0(%3)\n"
22949 " movl %%edx, 4(%3)\n"
22950 - "3: movl 8(%4), %%eax\n"
22951 - "31: movl 12(%4),%%edx\n"
22952 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22953 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22954 " movl %%eax, 8(%3)\n"
22955 " movl %%edx, 12(%3)\n"
22956 - "4: movl 16(%4), %%eax\n"
22957 - "41: movl 20(%4), %%edx\n"
22958 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22959 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22960 " movl %%eax, 16(%3)\n"
22961 " movl %%edx, 20(%3)\n"
22962 - "10: movl 24(%4), %%eax\n"
22963 - "51: movl 28(%4), %%edx\n"
22964 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22965 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22966 " movl %%eax, 24(%3)\n"
22967 " movl %%edx, 28(%3)\n"
22968 - "11: movl 32(%4), %%eax\n"
22969 - "61: movl 36(%4), %%edx\n"
22970 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22971 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22972 " movl %%eax, 32(%3)\n"
22973 " movl %%edx, 36(%3)\n"
22974 - "12: movl 40(%4), %%eax\n"
22975 - "71: movl 44(%4), %%edx\n"
22976 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22977 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22978 " movl %%eax, 40(%3)\n"
22979 " movl %%edx, 44(%3)\n"
22980 - "13: movl 48(%4), %%eax\n"
22981 - "81: movl 52(%4), %%edx\n"
22982 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22983 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22984 " movl %%eax, 48(%3)\n"
22985 " movl %%edx, 52(%3)\n"
22986 - "14: movl 56(%4), %%eax\n"
22987 - "91: movl 60(%4), %%edx\n"
22988 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22989 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22990 " movl %%eax, 56(%3)\n"
22991 " movl %%edx, 60(%3)\n"
22992 " addl $-64, %0\n"
22993 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22994 " shrl $2, %0\n"
22995 " andl $3, %%eax\n"
22996 " cld\n"
22997 - "6: rep; movsl\n"
22998 + "6: rep; "__copyuser_seg" movsl\n"
22999 " movl %%eax,%0\n"
23000 - "7: rep; movsb\n"
23001 + "7: rep; "__copyuser_seg" movsb\n"
23002 "8:\n"
23003 ".section .fixup,\"ax\"\n"
23004 "9: lea 0(%%eax,%0,4),%0\n"
23005 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23006 * hyoshiok@miraclelinux.com
23007 */
23008
23009 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23010 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23011 const void __user *from, unsigned long size)
23012 {
23013 int d0, d1;
23014
23015 __asm__ __volatile__(
23016 " .align 2,0x90\n"
23017 - "0: movl 32(%4), %%eax\n"
23018 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23019 " cmpl $67, %0\n"
23020 " jbe 2f\n"
23021 - "1: movl 64(%4), %%eax\n"
23022 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23023 " .align 2,0x90\n"
23024 - "2: movl 0(%4), %%eax\n"
23025 - "21: movl 4(%4), %%edx\n"
23026 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23027 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23028 " movnti %%eax, 0(%3)\n"
23029 " movnti %%edx, 4(%3)\n"
23030 - "3: movl 8(%4), %%eax\n"
23031 - "31: movl 12(%4),%%edx\n"
23032 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23033 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23034 " movnti %%eax, 8(%3)\n"
23035 " movnti %%edx, 12(%3)\n"
23036 - "4: movl 16(%4), %%eax\n"
23037 - "41: movl 20(%4), %%edx\n"
23038 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23039 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23040 " movnti %%eax, 16(%3)\n"
23041 " movnti %%edx, 20(%3)\n"
23042 - "10: movl 24(%4), %%eax\n"
23043 - "51: movl 28(%4), %%edx\n"
23044 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23045 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23046 " movnti %%eax, 24(%3)\n"
23047 " movnti %%edx, 28(%3)\n"
23048 - "11: movl 32(%4), %%eax\n"
23049 - "61: movl 36(%4), %%edx\n"
23050 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23051 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23052 " movnti %%eax, 32(%3)\n"
23053 " movnti %%edx, 36(%3)\n"
23054 - "12: movl 40(%4), %%eax\n"
23055 - "71: movl 44(%4), %%edx\n"
23056 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23057 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23058 " movnti %%eax, 40(%3)\n"
23059 " movnti %%edx, 44(%3)\n"
23060 - "13: movl 48(%4), %%eax\n"
23061 - "81: movl 52(%4), %%edx\n"
23062 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23063 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23064 " movnti %%eax, 48(%3)\n"
23065 " movnti %%edx, 52(%3)\n"
23066 - "14: movl 56(%4), %%eax\n"
23067 - "91: movl 60(%4), %%edx\n"
23068 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23069 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23070 " movnti %%eax, 56(%3)\n"
23071 " movnti %%edx, 60(%3)\n"
23072 " addl $-64, %0\n"
23073 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23074 " shrl $2, %0\n"
23075 " andl $3, %%eax\n"
23076 " cld\n"
23077 - "6: rep; movsl\n"
23078 + "6: rep; "__copyuser_seg" movsl\n"
23079 " movl %%eax,%0\n"
23080 - "7: rep; movsb\n"
23081 + "7: rep; "__copyuser_seg" movsb\n"
23082 "8:\n"
23083 ".section .fixup,\"ax\"\n"
23084 "9: lea 0(%%eax,%0,4),%0\n"
23085 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23086 return size;
23087 }
23088
23089 -static unsigned long __copy_user_intel_nocache(void *to,
23090 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23091 const void __user *from, unsigned long size)
23092 {
23093 int d0, d1;
23094
23095 __asm__ __volatile__(
23096 " .align 2,0x90\n"
23097 - "0: movl 32(%4), %%eax\n"
23098 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23099 " cmpl $67, %0\n"
23100 " jbe 2f\n"
23101 - "1: movl 64(%4), %%eax\n"
23102 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23103 " .align 2,0x90\n"
23104 - "2: movl 0(%4), %%eax\n"
23105 - "21: movl 4(%4), %%edx\n"
23106 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23107 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23108 " movnti %%eax, 0(%3)\n"
23109 " movnti %%edx, 4(%3)\n"
23110 - "3: movl 8(%4), %%eax\n"
23111 - "31: movl 12(%4),%%edx\n"
23112 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23113 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23114 " movnti %%eax, 8(%3)\n"
23115 " movnti %%edx, 12(%3)\n"
23116 - "4: movl 16(%4), %%eax\n"
23117 - "41: movl 20(%4), %%edx\n"
23118 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23119 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23120 " movnti %%eax, 16(%3)\n"
23121 " movnti %%edx, 20(%3)\n"
23122 - "10: movl 24(%4), %%eax\n"
23123 - "51: movl 28(%4), %%edx\n"
23124 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23125 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23126 " movnti %%eax, 24(%3)\n"
23127 " movnti %%edx, 28(%3)\n"
23128 - "11: movl 32(%4), %%eax\n"
23129 - "61: movl 36(%4), %%edx\n"
23130 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23131 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23132 " movnti %%eax, 32(%3)\n"
23133 " movnti %%edx, 36(%3)\n"
23134 - "12: movl 40(%4), %%eax\n"
23135 - "71: movl 44(%4), %%edx\n"
23136 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23137 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23138 " movnti %%eax, 40(%3)\n"
23139 " movnti %%edx, 44(%3)\n"
23140 - "13: movl 48(%4), %%eax\n"
23141 - "81: movl 52(%4), %%edx\n"
23142 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23143 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23144 " movnti %%eax, 48(%3)\n"
23145 " movnti %%edx, 52(%3)\n"
23146 - "14: movl 56(%4), %%eax\n"
23147 - "91: movl 60(%4), %%edx\n"
23148 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23149 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23150 " movnti %%eax, 56(%3)\n"
23151 " movnti %%edx, 60(%3)\n"
23152 " addl $-64, %0\n"
23153 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23154 " shrl $2, %0\n"
23155 " andl $3, %%eax\n"
23156 " cld\n"
23157 - "6: rep; movsl\n"
23158 + "6: rep; "__copyuser_seg" movsl\n"
23159 " movl %%eax,%0\n"
23160 - "7: rep; movsb\n"
23161 + "7: rep; "__copyuser_seg" movsb\n"
23162 "8:\n"
23163 ".section .fixup,\"ax\"\n"
23164 "9: lea 0(%%eax,%0,4),%0\n"
23165 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23166 */
23167 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23168 unsigned long size);
23169 -unsigned long __copy_user_intel(void __user *to, const void *from,
23170 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23171 + unsigned long size);
23172 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23173 unsigned long size);
23174 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23175 const void __user *from, unsigned long size);
23176 #endif /* CONFIG_X86_INTEL_USERCOPY */
23177
23178 /* Generic arbitrary sized copy. */
23179 -#define __copy_user(to, from, size) \
23180 +#define __copy_user(to, from, size, prefix, set, restore) \
23181 do { \
23182 int __d0, __d1, __d2; \
23183 __asm__ __volatile__( \
23184 + set \
23185 " cmp $7,%0\n" \
23186 " jbe 1f\n" \
23187 " movl %1,%0\n" \
23188 " negl %0\n" \
23189 " andl $7,%0\n" \
23190 " subl %0,%3\n" \
23191 - "4: rep; movsb\n" \
23192 + "4: rep; "prefix"movsb\n" \
23193 " movl %3,%0\n" \
23194 " shrl $2,%0\n" \
23195 " andl $3,%3\n" \
23196 " .align 2,0x90\n" \
23197 - "0: rep; movsl\n" \
23198 + "0: rep; "prefix"movsl\n" \
23199 " movl %3,%0\n" \
23200 - "1: rep; movsb\n" \
23201 + "1: rep; "prefix"movsb\n" \
23202 "2:\n" \
23203 + restore \
23204 ".section .fixup,\"ax\"\n" \
23205 "5: addl %3,%0\n" \
23206 " jmp 2b\n" \
23207 @@ -537,14 +649,14 @@ do { \
23208 " negl %0\n" \
23209 " andl $7,%0\n" \
23210 " subl %0,%3\n" \
23211 - "4: rep; movsb\n" \
23212 + "4: rep; "__copyuser_seg"movsb\n" \
23213 " movl %3,%0\n" \
23214 " shrl $2,%0\n" \
23215 " andl $3,%3\n" \
23216 " .align 2,0x90\n" \
23217 - "0: rep; movsl\n" \
23218 + "0: rep; "__copyuser_seg"movsl\n" \
23219 " movl %3,%0\n" \
23220 - "1: rep; movsb\n" \
23221 + "1: rep; "__copyuser_seg"movsb\n" \
23222 "2:\n" \
23223 ".section .fixup,\"ax\"\n" \
23224 "5: addl %3,%0\n" \
23225 @@ -627,9 +739,9 @@ survive:
23226 }
23227 #endif
23228 if (movsl_is_ok(to, from, n))
23229 - __copy_user(to, from, n);
23230 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23231 else
23232 - n = __copy_user_intel(to, from, n);
23233 + n = __generic_copy_to_user_intel(to, from, n);
23234 return n;
23235 }
23236 EXPORT_SYMBOL(__copy_to_user_ll);
23237 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23238 unsigned long n)
23239 {
23240 if (movsl_is_ok(to, from, n))
23241 - __copy_user(to, from, n);
23242 + __copy_user(to, from, n, __copyuser_seg, "", "");
23243 else
23244 - n = __copy_user_intel((void __user *)to,
23245 - (const void *)from, n);
23246 + n = __generic_copy_from_user_intel(to, from, n);
23247 return n;
23248 }
23249 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23250 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23251 if (n > 64 && cpu_has_xmm2)
23252 n = __copy_user_intel_nocache(to, from, n);
23253 else
23254 - __copy_user(to, from, n);
23255 + __copy_user(to, from, n, __copyuser_seg, "", "");
23256 #else
23257 - __copy_user(to, from, n);
23258 + __copy_user(to, from, n, __copyuser_seg, "", "");
23259 #endif
23260 return n;
23261 }
23262 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23263
23264 -/**
23265 - * copy_to_user: - Copy a block of data into user space.
23266 - * @to: Destination address, in user space.
23267 - * @from: Source address, in kernel space.
23268 - * @n: Number of bytes to copy.
23269 - *
23270 - * Context: User context only. This function may sleep.
23271 - *
23272 - * Copy data from kernel space to user space.
23273 - *
23274 - * Returns number of bytes that could not be copied.
23275 - * On success, this will be zero.
23276 - */
23277 -unsigned long
23278 -copy_to_user(void __user *to, const void *from, unsigned long n)
23279 -{
23280 - if (access_ok(VERIFY_WRITE, to, n))
23281 - n = __copy_to_user(to, from, n);
23282 - return n;
23283 -}
23284 -EXPORT_SYMBOL(copy_to_user);
23285 -
23286 -/**
23287 - * copy_from_user: - Copy a block of data from user space.
23288 - * @to: Destination address, in kernel space.
23289 - * @from: Source address, in user space.
23290 - * @n: Number of bytes to copy.
23291 - *
23292 - * Context: User context only. This function may sleep.
23293 - *
23294 - * Copy data from user space to kernel space.
23295 - *
23296 - * Returns number of bytes that could not be copied.
23297 - * On success, this will be zero.
23298 - *
23299 - * If some data could not be copied, this function will pad the copied
23300 - * data to the requested size using zero bytes.
23301 - */
23302 -unsigned long
23303 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23304 -{
23305 - if (access_ok(VERIFY_READ, from, n))
23306 - n = __copy_from_user(to, from, n);
23307 - else
23308 - memset(to, 0, n);
23309 - return n;
23310 -}
23311 -EXPORT_SYMBOL(_copy_from_user);
23312 -
23313 void copy_from_user_overflow(void)
23314 {
23315 WARN(1, "Buffer overflow detected!\n");
23316 }
23317 EXPORT_SYMBOL(copy_from_user_overflow);
23318 +
23319 +void copy_to_user_overflow(void)
23320 +{
23321 + WARN(1, "Buffer overflow detected!\n");
23322 +}
23323 +EXPORT_SYMBOL(copy_to_user_overflow);
23324 +
23325 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23326 +void __set_fs(mm_segment_t x)
23327 +{
23328 + switch (x.seg) {
23329 + case 0:
23330 + loadsegment(gs, 0);
23331 + break;
23332 + case TASK_SIZE_MAX:
23333 + loadsegment(gs, __USER_DS);
23334 + break;
23335 + case -1UL:
23336 + loadsegment(gs, __KERNEL_DS);
23337 + break;
23338 + default:
23339 + BUG();
23340 + }
23341 + return;
23342 +}
23343 +EXPORT_SYMBOL(__set_fs);
23344 +
23345 +void set_fs(mm_segment_t x)
23346 +{
23347 + current_thread_info()->addr_limit = x;
23348 + __set_fs(x);
23349 +}
23350 +EXPORT_SYMBOL(set_fs);
23351 +#endif
23352 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23353 index e5b130b..6690d31 100644
23354 --- a/arch/x86/lib/usercopy_64.c
23355 +++ b/arch/x86/lib/usercopy_64.c
23356 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23357 {
23358 long __d0;
23359 might_fault();
23360 +
23361 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23362 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23363 + addr += PAX_USER_SHADOW_BASE;
23364 +#endif
23365 +
23366 /* no memory constraint because it doesn't change any memory gcc knows
23367 about */
23368 asm volatile(
23369 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23370 }
23371 EXPORT_SYMBOL(clear_user);
23372
23373 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23374 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23375 {
23376 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23377 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23378 - }
23379 - return len;
23380 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23381 +
23382 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23383 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23384 + to += PAX_USER_SHADOW_BASE;
23385 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23386 + from += PAX_USER_SHADOW_BASE;
23387 +#endif
23388 +
23389 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23390 + }
23391 + return len;
23392 }
23393 EXPORT_SYMBOL(copy_in_user);
23394
23395 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23396 * it is not necessary to optimize tail handling.
23397 */
23398 unsigned long
23399 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23400 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23401 {
23402 char c;
23403 unsigned zero_len;
23404 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23405 break;
23406 return len;
23407 }
23408 +
23409 +void copy_from_user_overflow(void)
23410 +{
23411 + WARN(1, "Buffer overflow detected!\n");
23412 +}
23413 +EXPORT_SYMBOL(copy_from_user_overflow);
23414 +
23415 +void copy_to_user_overflow(void)
23416 +{
23417 + WARN(1, "Buffer overflow detected!\n");
23418 +}
23419 +EXPORT_SYMBOL(copy_to_user_overflow);
23420 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23421 index 903ec1e..af8e064 100644
23422 --- a/arch/x86/mm/extable.c
23423 +++ b/arch/x86/mm/extable.c
23424 @@ -6,12 +6,24 @@
23425 static inline unsigned long
23426 ex_insn_addr(const struct exception_table_entry *x)
23427 {
23428 - return (unsigned long)&x->insn + x->insn;
23429 + unsigned long reloc = 0;
23430 +
23431 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23432 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23433 +#endif
23434 +
23435 + return (unsigned long)&x->insn + x->insn + reloc;
23436 }
23437 static inline unsigned long
23438 ex_fixup_addr(const struct exception_table_entry *x)
23439 {
23440 - return (unsigned long)&x->fixup + x->fixup;
23441 + unsigned long reloc = 0;
23442 +
23443 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23444 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23445 +#endif
23446 +
23447 + return (unsigned long)&x->fixup + x->fixup + reloc;
23448 }
23449
23450 int fixup_exception(struct pt_regs *regs)
23451 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23452 unsigned long new_ip;
23453
23454 #ifdef CONFIG_PNPBIOS
23455 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23456 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23457 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23458 extern u32 pnp_bios_is_utter_crap;
23459 pnp_bios_is_utter_crap = 1;
23460 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23461 index 76dcd9d..e9dffde 100644
23462 --- a/arch/x86/mm/fault.c
23463 +++ b/arch/x86/mm/fault.c
23464 @@ -13,11 +13,18 @@
23465 #include <linux/perf_event.h> /* perf_sw_event */
23466 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23467 #include <linux/prefetch.h> /* prefetchw */
23468 +#include <linux/unistd.h>
23469 +#include <linux/compiler.h>
23470
23471 #include <asm/traps.h> /* dotraplinkage, ... */
23472 #include <asm/pgalloc.h> /* pgd_*(), ... */
23473 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23474 #include <asm/fixmap.h> /* VSYSCALL_START */
23475 +#include <asm/tlbflush.h>
23476 +
23477 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23478 +#include <asm/stacktrace.h>
23479 +#endif
23480
23481 /*
23482 * Page fault error code bits:
23483 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23484 int ret = 0;
23485
23486 /* kprobe_running() needs smp_processor_id() */
23487 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23488 + if (kprobes_built_in() && !user_mode(regs)) {
23489 preempt_disable();
23490 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23491 ret = 1;
23492 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23493 return !instr_lo || (instr_lo>>1) == 1;
23494 case 0x00:
23495 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23496 - if (probe_kernel_address(instr, opcode))
23497 + if (user_mode(regs)) {
23498 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23499 + return 0;
23500 + } else if (probe_kernel_address(instr, opcode))
23501 return 0;
23502
23503 *prefetch = (instr_lo == 0xF) &&
23504 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23505 while (instr < max_instr) {
23506 unsigned char opcode;
23507
23508 - if (probe_kernel_address(instr, opcode))
23509 + if (user_mode(regs)) {
23510 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23511 + break;
23512 + } else if (probe_kernel_address(instr, opcode))
23513 break;
23514
23515 instr++;
23516 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23517 force_sig_info(si_signo, &info, tsk);
23518 }
23519
23520 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23521 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23522 +#endif
23523 +
23524 +#ifdef CONFIG_PAX_EMUTRAMP
23525 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23526 +#endif
23527 +
23528 +#ifdef CONFIG_PAX_PAGEEXEC
23529 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23530 +{
23531 + pgd_t *pgd;
23532 + pud_t *pud;
23533 + pmd_t *pmd;
23534 +
23535 + pgd = pgd_offset(mm, address);
23536 + if (!pgd_present(*pgd))
23537 + return NULL;
23538 + pud = pud_offset(pgd, address);
23539 + if (!pud_present(*pud))
23540 + return NULL;
23541 + pmd = pmd_offset(pud, address);
23542 + if (!pmd_present(*pmd))
23543 + return NULL;
23544 + return pmd;
23545 +}
23546 +#endif
23547 +
23548 DEFINE_SPINLOCK(pgd_lock);
23549 LIST_HEAD(pgd_list);
23550
23551 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23552 for (address = VMALLOC_START & PMD_MASK;
23553 address >= TASK_SIZE && address < FIXADDR_TOP;
23554 address += PMD_SIZE) {
23555 +
23556 +#ifdef CONFIG_PAX_PER_CPU_PGD
23557 + unsigned long cpu;
23558 +#else
23559 struct page *page;
23560 +#endif
23561
23562 spin_lock(&pgd_lock);
23563 +
23564 +#ifdef CONFIG_PAX_PER_CPU_PGD
23565 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23566 + pgd_t *pgd = get_cpu_pgd(cpu);
23567 + pmd_t *ret;
23568 +#else
23569 list_for_each_entry(page, &pgd_list, lru) {
23570 + pgd_t *pgd = page_address(page);
23571 spinlock_t *pgt_lock;
23572 pmd_t *ret;
23573
23574 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23575 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23576
23577 spin_lock(pgt_lock);
23578 - ret = vmalloc_sync_one(page_address(page), address);
23579 +#endif
23580 +
23581 + ret = vmalloc_sync_one(pgd, address);
23582 +
23583 +#ifndef CONFIG_PAX_PER_CPU_PGD
23584 spin_unlock(pgt_lock);
23585 +#endif
23586
23587 if (!ret)
23588 break;
23589 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23590 * an interrupt in the middle of a task switch..
23591 */
23592 pgd_paddr = read_cr3();
23593 +
23594 +#ifdef CONFIG_PAX_PER_CPU_PGD
23595 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23596 +#endif
23597 +
23598 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23599 if (!pmd_k)
23600 return -1;
23601 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23602 * happen within a race in page table update. In the later
23603 * case just flush:
23604 */
23605 +
23606 +#ifdef CONFIG_PAX_PER_CPU_PGD
23607 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23608 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23609 +#else
23610 pgd = pgd_offset(current->active_mm, address);
23611 +#endif
23612 +
23613 pgd_ref = pgd_offset_k(address);
23614 if (pgd_none(*pgd_ref))
23615 return -1;
23616 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23617 static int is_errata100(struct pt_regs *regs, unsigned long address)
23618 {
23619 #ifdef CONFIG_X86_64
23620 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23621 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23622 return 1;
23623 #endif
23624 return 0;
23625 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23626 }
23627
23628 static const char nx_warning[] = KERN_CRIT
23629 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23630 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23631
23632 static void
23633 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23634 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23635 if (!oops_may_print())
23636 return;
23637
23638 - if (error_code & PF_INSTR) {
23639 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23640 unsigned int level;
23641
23642 pte_t *pte = lookup_address(address, &level);
23643
23644 if (pte && pte_present(*pte) && !pte_exec(*pte))
23645 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23646 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23647 }
23648
23649 +#ifdef CONFIG_PAX_KERNEXEC
23650 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23651 + if (current->signal->curr_ip)
23652 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23653 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23654 + else
23655 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23656 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23657 + }
23658 +#endif
23659 +
23660 printk(KERN_ALERT "BUG: unable to handle kernel ");
23661 if (address < PAGE_SIZE)
23662 printk(KERN_CONT "NULL pointer dereference");
23663 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23664 }
23665 #endif
23666
23667 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23668 + if (pax_is_fetch_fault(regs, error_code, address)) {
23669 +
23670 +#ifdef CONFIG_PAX_EMUTRAMP
23671 + switch (pax_handle_fetch_fault(regs)) {
23672 + case 2:
23673 + return;
23674 + }
23675 +#endif
23676 +
23677 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23678 + do_group_exit(SIGKILL);
23679 + }
23680 +#endif
23681 +
23682 if (unlikely(show_unhandled_signals))
23683 show_signal_msg(regs, error_code, address, tsk);
23684
23685 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23686 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23687 printk(KERN_ERR
23688 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23689 - tsk->comm, tsk->pid, address);
23690 + tsk->comm, task_pid_nr(tsk), address);
23691 code = BUS_MCEERR_AR;
23692 }
23693 #endif
23694 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23695 return 1;
23696 }
23697
23698 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23699 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23700 +{
23701 + pte_t *pte;
23702 + pmd_t *pmd;
23703 + spinlock_t *ptl;
23704 + unsigned char pte_mask;
23705 +
23706 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23707 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23708 + return 0;
23709 +
23710 + /* PaX: it's our fault, let's handle it if we can */
23711 +
23712 + /* PaX: take a look at read faults before acquiring any locks */
23713 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23714 + /* instruction fetch attempt from a protected page in user mode */
23715 + up_read(&mm->mmap_sem);
23716 +
23717 +#ifdef CONFIG_PAX_EMUTRAMP
23718 + switch (pax_handle_fetch_fault(regs)) {
23719 + case 2:
23720 + return 1;
23721 + }
23722 +#endif
23723 +
23724 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23725 + do_group_exit(SIGKILL);
23726 + }
23727 +
23728 + pmd = pax_get_pmd(mm, address);
23729 + if (unlikely(!pmd))
23730 + return 0;
23731 +
23732 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23733 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23734 + pte_unmap_unlock(pte, ptl);
23735 + return 0;
23736 + }
23737 +
23738 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23739 + /* write attempt to a protected page in user mode */
23740 + pte_unmap_unlock(pte, ptl);
23741 + return 0;
23742 + }
23743 +
23744 +#ifdef CONFIG_SMP
23745 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23746 +#else
23747 + if (likely(address > get_limit(regs->cs)))
23748 +#endif
23749 + {
23750 + set_pte(pte, pte_mkread(*pte));
23751 + __flush_tlb_one(address);
23752 + pte_unmap_unlock(pte, ptl);
23753 + up_read(&mm->mmap_sem);
23754 + return 1;
23755 + }
23756 +
23757 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23758 +
23759 + /*
23760 + * PaX: fill DTLB with user rights and retry
23761 + */
23762 + __asm__ __volatile__ (
23763 + "orb %2,(%1)\n"
23764 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23765 +/*
23766 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23767 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23768 + * page fault when examined during a TLB load attempt. this is true not only
23769 + * for PTEs holding a non-present entry but also present entries that will
23770 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23771 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23772 + * for our target pages since their PTEs are simply not in the TLBs at all.
23773 +
23774 + * the best thing in omitting it is that we gain around 15-20% speed in the
23775 + * fast path of the page fault handler and can get rid of tracing since we
23776 + * can no longer flush unintended entries.
23777 + */
23778 + "invlpg (%0)\n"
23779 +#endif
23780 + __copyuser_seg"testb $0,(%0)\n"
23781 + "xorb %3,(%1)\n"
23782 + :
23783 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23784 + : "memory", "cc");
23785 + pte_unmap_unlock(pte, ptl);
23786 + up_read(&mm->mmap_sem);
23787 + return 1;
23788 +}
23789 +#endif
23790 +
23791 /*
23792 * Handle a spurious fault caused by a stale TLB entry.
23793 *
23794 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23795 static inline int
23796 access_error(unsigned long error_code, struct vm_area_struct *vma)
23797 {
23798 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23799 + return 1;
23800 +
23801 if (error_code & PF_WRITE) {
23802 /* write, present and write, not present: */
23803 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23804 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23805 {
23806 struct vm_area_struct *vma;
23807 struct task_struct *tsk;
23808 - unsigned long address;
23809 struct mm_struct *mm;
23810 int fault;
23811 int write = error_code & PF_WRITE;
23812 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23813 (write ? FAULT_FLAG_WRITE : 0);
23814
23815 - tsk = current;
23816 - mm = tsk->mm;
23817 -
23818 /* Get the faulting address: */
23819 - address = read_cr2();
23820 + unsigned long address = read_cr2();
23821 +
23822 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23823 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23824 + if (!search_exception_tables(regs->ip)) {
23825 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23826 + bad_area_nosemaphore(regs, error_code, address);
23827 + return;
23828 + }
23829 + if (address < PAX_USER_SHADOW_BASE) {
23830 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23831 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23832 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23833 + } else
23834 + address -= PAX_USER_SHADOW_BASE;
23835 + }
23836 +#endif
23837 +
23838 + tsk = current;
23839 + mm = tsk->mm;
23840
23841 /*
23842 * Detect and handle instructions that would cause a page fault for
23843 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23844 * User-mode registers count as a user access even for any
23845 * potential system fault or CPU buglet:
23846 */
23847 - if (user_mode_vm(regs)) {
23848 + if (user_mode(regs)) {
23849 local_irq_enable();
23850 error_code |= PF_USER;
23851 } else {
23852 @@ -1132,6 +1339,11 @@ retry:
23853 might_sleep();
23854 }
23855
23856 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23857 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23858 + return;
23859 +#endif
23860 +
23861 vma = find_vma(mm, address);
23862 if (unlikely(!vma)) {
23863 bad_area(regs, error_code, address);
23864 @@ -1143,18 +1355,24 @@ retry:
23865 bad_area(regs, error_code, address);
23866 return;
23867 }
23868 - if (error_code & PF_USER) {
23869 - /*
23870 - * Accessing the stack below %sp is always a bug.
23871 - * The large cushion allows instructions like enter
23872 - * and pusha to work. ("enter $65535, $31" pushes
23873 - * 32 pointers and then decrements %sp by 65535.)
23874 - */
23875 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23876 - bad_area(regs, error_code, address);
23877 - return;
23878 - }
23879 + /*
23880 + * Accessing the stack below %sp is always a bug.
23881 + * The large cushion allows instructions like enter
23882 + * and pusha to work. ("enter $65535, $31" pushes
23883 + * 32 pointers and then decrements %sp by 65535.)
23884 + */
23885 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23886 + bad_area(regs, error_code, address);
23887 + return;
23888 }
23889 +
23890 +#ifdef CONFIG_PAX_SEGMEXEC
23891 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23892 + bad_area(regs, error_code, address);
23893 + return;
23894 + }
23895 +#endif
23896 +
23897 if (unlikely(expand_stack(vma, address))) {
23898 bad_area(regs, error_code, address);
23899 return;
23900 @@ -1209,3 +1427,292 @@ good_area:
23901
23902 up_read(&mm->mmap_sem);
23903 }
23904 +
23905 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23906 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23907 +{
23908 + struct mm_struct *mm = current->mm;
23909 + unsigned long ip = regs->ip;
23910 +
23911 + if (v8086_mode(regs))
23912 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23913 +
23914 +#ifdef CONFIG_PAX_PAGEEXEC
23915 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23916 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23917 + return true;
23918 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23919 + return true;
23920 + return false;
23921 + }
23922 +#endif
23923 +
23924 +#ifdef CONFIG_PAX_SEGMEXEC
23925 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23926 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23927 + return true;
23928 + return false;
23929 + }
23930 +#endif
23931 +
23932 + return false;
23933 +}
23934 +#endif
23935 +
23936 +#ifdef CONFIG_PAX_EMUTRAMP
23937 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23938 +{
23939 + int err;
23940 +
23941 + do { /* PaX: libffi trampoline emulation */
23942 + unsigned char mov, jmp;
23943 + unsigned int addr1, addr2;
23944 +
23945 +#ifdef CONFIG_X86_64
23946 + if ((regs->ip + 9) >> 32)
23947 + break;
23948 +#endif
23949 +
23950 + err = get_user(mov, (unsigned char __user *)regs->ip);
23951 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23952 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23953 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23954 +
23955 + if (err)
23956 + break;
23957 +
23958 + if (mov == 0xB8 && jmp == 0xE9) {
23959 + regs->ax = addr1;
23960 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23961 + return 2;
23962 + }
23963 + } while (0);
23964 +
23965 + do { /* PaX: gcc trampoline emulation #1 */
23966 + unsigned char mov1, mov2;
23967 + unsigned short jmp;
23968 + unsigned int addr1, addr2;
23969 +
23970 +#ifdef CONFIG_X86_64
23971 + if ((regs->ip + 11) >> 32)
23972 + break;
23973 +#endif
23974 +
23975 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23976 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23977 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23978 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23979 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23980 +
23981 + if (err)
23982 + break;
23983 +
23984 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23985 + regs->cx = addr1;
23986 + regs->ax = addr2;
23987 + regs->ip = addr2;
23988 + return 2;
23989 + }
23990 + } while (0);
23991 +
23992 + do { /* PaX: gcc trampoline emulation #2 */
23993 + unsigned char mov, jmp;
23994 + unsigned int addr1, addr2;
23995 +
23996 +#ifdef CONFIG_X86_64
23997 + if ((regs->ip + 9) >> 32)
23998 + break;
23999 +#endif
24000 +
24001 + err = get_user(mov, (unsigned char __user *)regs->ip);
24002 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24003 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24004 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24005 +
24006 + if (err)
24007 + break;
24008 +
24009 + if (mov == 0xB9 && jmp == 0xE9) {
24010 + regs->cx = addr1;
24011 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24012 + return 2;
24013 + }
24014 + } while (0);
24015 +
24016 + return 1; /* PaX in action */
24017 +}
24018 +
24019 +#ifdef CONFIG_X86_64
24020 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24021 +{
24022 + int err;
24023 +
24024 + do { /* PaX: libffi trampoline emulation */
24025 + unsigned short mov1, mov2, jmp1;
24026 + unsigned char stcclc, jmp2;
24027 + unsigned long addr1, addr2;
24028 +
24029 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24030 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24031 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24032 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24033 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24034 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24035 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24036 +
24037 + if (err)
24038 + break;
24039 +
24040 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24041 + regs->r11 = addr1;
24042 + regs->r10 = addr2;
24043 + if (stcclc == 0xF8)
24044 + regs->flags &= ~X86_EFLAGS_CF;
24045 + else
24046 + regs->flags |= X86_EFLAGS_CF;
24047 + regs->ip = addr1;
24048 + return 2;
24049 + }
24050 + } while (0);
24051 +
24052 + do { /* PaX: gcc trampoline emulation #1 */
24053 + unsigned short mov1, mov2, jmp1;
24054 + unsigned char jmp2;
24055 + unsigned int addr1;
24056 + unsigned long addr2;
24057 +
24058 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24059 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24060 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24061 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24062 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24063 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24064 +
24065 + if (err)
24066 + break;
24067 +
24068 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24069 + regs->r11 = addr1;
24070 + regs->r10 = addr2;
24071 + regs->ip = addr1;
24072 + return 2;
24073 + }
24074 + } while (0);
24075 +
24076 + do { /* PaX: gcc trampoline emulation #2 */
24077 + unsigned short mov1, mov2, jmp1;
24078 + unsigned char jmp2;
24079 + unsigned long addr1, addr2;
24080 +
24081 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24082 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24083 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24084 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24085 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24086 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24087 +
24088 + if (err)
24089 + break;
24090 +
24091 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24092 + regs->r11 = addr1;
24093 + regs->r10 = addr2;
24094 + regs->ip = addr1;
24095 + return 2;
24096 + }
24097 + } while (0);
24098 +
24099 + return 1; /* PaX in action */
24100 +}
24101 +#endif
24102 +
24103 +/*
24104 + * PaX: decide what to do with offenders (regs->ip = fault address)
24105 + *
24106 + * returns 1 when task should be killed
24107 + * 2 when gcc trampoline was detected
24108 + */
24109 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24110 +{
24111 + if (v8086_mode(regs))
24112 + return 1;
24113 +
24114 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24115 + return 1;
24116 +
24117 +#ifdef CONFIG_X86_32
24118 + return pax_handle_fetch_fault_32(regs);
24119 +#else
24120 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24121 + return pax_handle_fetch_fault_32(regs);
24122 + else
24123 + return pax_handle_fetch_fault_64(regs);
24124 +#endif
24125 +}
24126 +#endif
24127 +
24128 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24129 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24130 +{
24131 + long i;
24132 +
24133 + printk(KERN_ERR "PAX: bytes at PC: ");
24134 + for (i = 0; i < 20; i++) {
24135 + unsigned char c;
24136 + if (get_user(c, (unsigned char __force_user *)pc+i))
24137 + printk(KERN_CONT "?? ");
24138 + else
24139 + printk(KERN_CONT "%02x ", c);
24140 + }
24141 + printk("\n");
24142 +
24143 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24144 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24145 + unsigned long c;
24146 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24147 +#ifdef CONFIG_X86_32
24148 + printk(KERN_CONT "???????? ");
24149 +#else
24150 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24151 + printk(KERN_CONT "???????? ???????? ");
24152 + else
24153 + printk(KERN_CONT "???????????????? ");
24154 +#endif
24155 + } else {
24156 +#ifdef CONFIG_X86_64
24157 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24158 + printk(KERN_CONT "%08x ", (unsigned int)c);
24159 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24160 + } else
24161 +#endif
24162 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24163 + }
24164 + }
24165 + printk("\n");
24166 +}
24167 +#endif
24168 +
24169 +/**
24170 + * probe_kernel_write(): safely attempt to write to a location
24171 + * @dst: address to write to
24172 + * @src: pointer to the data that shall be written
24173 + * @size: size of the data chunk
24174 + *
24175 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24176 + * happens, handle that and return -EFAULT.
24177 + */
24178 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24179 +{
24180 + long ret;
24181 + mm_segment_t old_fs = get_fs();
24182 +
24183 + set_fs(KERNEL_DS);
24184 + pagefault_disable();
24185 + pax_open_kernel();
24186 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24187 + pax_close_kernel();
24188 + pagefault_enable();
24189 + set_fs(old_fs);
24190 +
24191 + return ret ? -EFAULT : 0;
24192 +}
24193 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24194 index dd74e46..7d26398 100644
24195 --- a/arch/x86/mm/gup.c
24196 +++ b/arch/x86/mm/gup.c
24197 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24198 addr = start;
24199 len = (unsigned long) nr_pages << PAGE_SHIFT;
24200 end = start + len;
24201 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24202 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24203 (void __user *)start, len)))
24204 return 0;
24205
24206 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24207 index 6f31ee5..8ee4164 100644
24208 --- a/arch/x86/mm/highmem_32.c
24209 +++ b/arch/x86/mm/highmem_32.c
24210 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24211 idx = type + KM_TYPE_NR*smp_processor_id();
24212 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24213 BUG_ON(!pte_none(*(kmap_pte-idx)));
24214 +
24215 + pax_open_kernel();
24216 set_pte(kmap_pte-idx, mk_pte(page, prot));
24217 + pax_close_kernel();
24218 +
24219 arch_flush_lazy_mmu_mode();
24220
24221 return (void *)vaddr;
24222 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24223 index f6679a7..8f795a3 100644
24224 --- a/arch/x86/mm/hugetlbpage.c
24225 +++ b/arch/x86/mm/hugetlbpage.c
24226 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24227 struct hstate *h = hstate_file(file);
24228 struct mm_struct *mm = current->mm;
24229 struct vm_area_struct *vma;
24230 - unsigned long start_addr;
24231 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24232 +
24233 +#ifdef CONFIG_PAX_SEGMEXEC
24234 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24235 + pax_task_size = SEGMEXEC_TASK_SIZE;
24236 +#endif
24237 +
24238 + pax_task_size -= PAGE_SIZE;
24239
24240 if (len > mm->cached_hole_size) {
24241 - start_addr = mm->free_area_cache;
24242 + start_addr = mm->free_area_cache;
24243 } else {
24244 - start_addr = TASK_UNMAPPED_BASE;
24245 - mm->cached_hole_size = 0;
24246 + start_addr = mm->mmap_base;
24247 + mm->cached_hole_size = 0;
24248 }
24249
24250 full_search:
24251 @@ -280,26 +287,27 @@ full_search:
24252
24253 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24254 /* At this point: (!vma || addr < vma->vm_end). */
24255 - if (TASK_SIZE - len < addr) {
24256 + if (pax_task_size - len < addr) {
24257 /*
24258 * Start a new search - just in case we missed
24259 * some holes.
24260 */
24261 - if (start_addr != TASK_UNMAPPED_BASE) {
24262 - start_addr = TASK_UNMAPPED_BASE;
24263 + if (start_addr != mm->mmap_base) {
24264 + start_addr = mm->mmap_base;
24265 mm->cached_hole_size = 0;
24266 goto full_search;
24267 }
24268 return -ENOMEM;
24269 }
24270 - if (!vma || addr + len <= vma->vm_start) {
24271 - mm->free_area_cache = addr + len;
24272 - return addr;
24273 - }
24274 + if (check_heap_stack_gap(vma, addr, len))
24275 + break;
24276 if (addr + mm->cached_hole_size < vma->vm_start)
24277 mm->cached_hole_size = vma->vm_start - addr;
24278 addr = ALIGN(vma->vm_end, huge_page_size(h));
24279 }
24280 +
24281 + mm->free_area_cache = addr + len;
24282 + return addr;
24283 }
24284
24285 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24286 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24287 struct mm_struct *mm = current->mm;
24288 struct vm_area_struct *vma;
24289 unsigned long base = mm->mmap_base;
24290 - unsigned long addr = addr0;
24291 + unsigned long addr;
24292 unsigned long largest_hole = mm->cached_hole_size;
24293 - unsigned long start_addr;
24294
24295 /* don't allow allocations above current base */
24296 if (mm->free_area_cache > base)
24297 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24298 largest_hole = 0;
24299 mm->free_area_cache = base;
24300 }
24301 -try_again:
24302 - start_addr = mm->free_area_cache;
24303
24304 /* make sure it can fit in the remaining address space */
24305 if (mm->free_area_cache < len)
24306 goto fail;
24307
24308 /* either no address requested or can't fit in requested address hole */
24309 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24310 + addr = mm->free_area_cache - len;
24311 do {
24312 + addr &= huge_page_mask(h);
24313 /*
24314 * Lookup failure means no vma is above this address,
24315 * i.e. return with success:
24316 @@ -340,10 +346,10 @@ try_again:
24317 if (!vma)
24318 return addr;
24319
24320 - if (addr + len <= vma->vm_start) {
24321 + if (check_heap_stack_gap(vma, addr, len)) {
24322 /* remember the address as a hint for next time */
24323 - mm->cached_hole_size = largest_hole;
24324 - return (mm->free_area_cache = addr);
24325 + mm->cached_hole_size = largest_hole;
24326 + return (mm->free_area_cache = addr);
24327 } else if (mm->free_area_cache == vma->vm_end) {
24328 /* pull free_area_cache down to the first hole */
24329 mm->free_area_cache = vma->vm_start;
24330 @@ -352,29 +358,34 @@ try_again:
24331
24332 /* remember the largest hole we saw so far */
24333 if (addr + largest_hole < vma->vm_start)
24334 - largest_hole = vma->vm_start - addr;
24335 + largest_hole = vma->vm_start - addr;
24336
24337 /* try just below the current vma->vm_start */
24338 - addr = (vma->vm_start - len) & huge_page_mask(h);
24339 - } while (len <= vma->vm_start);
24340 + addr = skip_heap_stack_gap(vma, len);
24341 + } while (!IS_ERR_VALUE(addr));
24342
24343 fail:
24344 /*
24345 - * if hint left us with no space for the requested
24346 - * mapping then try again:
24347 - */
24348 - if (start_addr != base) {
24349 - mm->free_area_cache = base;
24350 - largest_hole = 0;
24351 - goto try_again;
24352 - }
24353 - /*
24354 * A failed mmap() very likely causes application failure,
24355 * so fall back to the bottom-up function here. This scenario
24356 * can happen with large stack limits and large mmap()
24357 * allocations.
24358 */
24359 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24360 +
24361 +#ifdef CONFIG_PAX_SEGMEXEC
24362 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24363 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24364 + else
24365 +#endif
24366 +
24367 + mm->mmap_base = TASK_UNMAPPED_BASE;
24368 +
24369 +#ifdef CONFIG_PAX_RANDMMAP
24370 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24371 + mm->mmap_base += mm->delta_mmap;
24372 +#endif
24373 +
24374 + mm->free_area_cache = mm->mmap_base;
24375 mm->cached_hole_size = ~0UL;
24376 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24377 len, pgoff, flags);
24378 @@ -382,6 +393,7 @@ fail:
24379 /*
24380 * Restore the topdown base:
24381 */
24382 + mm->mmap_base = base;
24383 mm->free_area_cache = base;
24384 mm->cached_hole_size = ~0UL;
24385
24386 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24387 struct hstate *h = hstate_file(file);
24388 struct mm_struct *mm = current->mm;
24389 struct vm_area_struct *vma;
24390 + unsigned long pax_task_size = TASK_SIZE;
24391
24392 if (len & ~huge_page_mask(h))
24393 return -EINVAL;
24394 - if (len > TASK_SIZE)
24395 +
24396 +#ifdef CONFIG_PAX_SEGMEXEC
24397 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24398 + pax_task_size = SEGMEXEC_TASK_SIZE;
24399 +#endif
24400 +
24401 + pax_task_size -= PAGE_SIZE;
24402 +
24403 + if (len > pax_task_size)
24404 return -ENOMEM;
24405
24406 if (flags & MAP_FIXED) {
24407 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24408 if (addr) {
24409 addr = ALIGN(addr, huge_page_size(h));
24410 vma = find_vma(mm, addr);
24411 - if (TASK_SIZE - len >= addr &&
24412 - (!vma || addr + len <= vma->vm_start))
24413 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24414 return addr;
24415 }
24416 if (mm->get_unmapped_area == arch_get_unmapped_area)
24417 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24418 index bc4e9d8..ca4c14b 100644
24419 --- a/arch/x86/mm/init.c
24420 +++ b/arch/x86/mm/init.c
24421 @@ -16,6 +16,8 @@
24422 #include <asm/tlb.h>
24423 #include <asm/proto.h>
24424 #include <asm/dma.h> /* for MAX_DMA_PFN */
24425 +#include <asm/desc.h>
24426 +#include <asm/bios_ebda.h>
24427
24428 unsigned long __initdata pgt_buf_start;
24429 unsigned long __meminitdata pgt_buf_end;
24430 @@ -38,7 +40,7 @@ struct map_range {
24431 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24432 int use_pse, int use_gbpages)
24433 {
24434 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24435 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24436 phys_addr_t base;
24437
24438 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24439 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24440 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24441 * mmio resources as well as potential bios/acpi data regions.
24442 */
24443 +
24444 +#ifdef CONFIG_GRKERNSEC_KMEM
24445 +static unsigned int ebda_start __read_only;
24446 +static unsigned int ebda_end __read_only;
24447 +#endif
24448 +
24449 int devmem_is_allowed(unsigned long pagenr)
24450 {
24451 +#ifdef CONFIG_GRKERNSEC_KMEM
24452 + /* allow BDA */
24453 + if (!pagenr)
24454 + return 1;
24455 + /* allow EBDA */
24456 + if (pagenr >= ebda_start && pagenr < ebda_end)
24457 + return 1;
24458 +#else
24459 + if (!pagenr)
24460 + return 1;
24461 +#ifdef CONFIG_VM86
24462 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24463 + return 1;
24464 +#endif
24465 +#endif
24466 +
24467 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24468 + return 1;
24469 +#ifdef CONFIG_GRKERNSEC_KMEM
24470 + /* throw out everything else below 1MB */
24471 if (pagenr <= 256)
24472 - return 1;
24473 + return 0;
24474 +#endif
24475 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24476 return 0;
24477 if (!page_is_ram(pagenr))
24478 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24479 #endif
24480 }
24481
24482 +#ifdef CONFIG_GRKERNSEC_KMEM
24483 +static inline void gr_init_ebda(void)
24484 +{
24485 + unsigned int ebda_addr;
24486 + unsigned int ebda_size = 0;
24487 +
24488 + ebda_addr = get_bios_ebda();
24489 + if (ebda_addr) {
24490 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24491 + ebda_size <<= 10;
24492 + }
24493 + if (ebda_addr && ebda_size) {
24494 + ebda_start = ebda_addr >> PAGE_SHIFT;
24495 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24496 + } else {
24497 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24498 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24499 + }
24500 +}
24501 +#else
24502 +static inline void gr_init_ebda(void) { }
24503 +#endif
24504 +
24505 void free_initmem(void)
24506 {
24507 +#ifdef CONFIG_PAX_KERNEXEC
24508 +#ifdef CONFIG_X86_32
24509 + /* PaX: limit KERNEL_CS to actual size */
24510 + unsigned long addr, limit;
24511 + struct desc_struct d;
24512 + int cpu;
24513 +#else
24514 + pgd_t *pgd;
24515 + pud_t *pud;
24516 + pmd_t *pmd;
24517 + unsigned long addr, end;
24518 +#endif
24519 +#endif
24520 +
24521 + gr_init_ebda();
24522 +
24523 +#ifdef CONFIG_PAX_KERNEXEC
24524 +#ifdef CONFIG_X86_32
24525 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24526 + limit = (limit - 1UL) >> PAGE_SHIFT;
24527 +
24528 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24529 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24530 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24531 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24532 + }
24533 +
24534 + /* PaX: make KERNEL_CS read-only */
24535 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24536 + if (!paravirt_enabled())
24537 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24538 +/*
24539 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24540 + pgd = pgd_offset_k(addr);
24541 + pud = pud_offset(pgd, addr);
24542 + pmd = pmd_offset(pud, addr);
24543 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24544 + }
24545 +*/
24546 +#ifdef CONFIG_X86_PAE
24547 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24548 +/*
24549 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24550 + pgd = pgd_offset_k(addr);
24551 + pud = pud_offset(pgd, addr);
24552 + pmd = pmd_offset(pud, addr);
24553 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24554 + }
24555 +*/
24556 +#endif
24557 +
24558 +#ifdef CONFIG_MODULES
24559 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24560 +#endif
24561 +
24562 +#else
24563 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24564 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24565 + pgd = pgd_offset_k(addr);
24566 + pud = pud_offset(pgd, addr);
24567 + pmd = pmd_offset(pud, addr);
24568 + if (!pmd_present(*pmd))
24569 + continue;
24570 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24571 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24572 + else
24573 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24574 + }
24575 +
24576 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24577 + end = addr + KERNEL_IMAGE_SIZE;
24578 + for (; addr < end; addr += PMD_SIZE) {
24579 + pgd = pgd_offset_k(addr);
24580 + pud = pud_offset(pgd, addr);
24581 + pmd = pmd_offset(pud, addr);
24582 + if (!pmd_present(*pmd))
24583 + continue;
24584 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24585 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24586 + }
24587 +#endif
24588 +
24589 + flush_tlb_all();
24590 +#endif
24591 +
24592 free_init_pages("unused kernel memory",
24593 (unsigned long)(&__init_begin),
24594 (unsigned long)(&__init_end));
24595 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24596 index 575d86f..4987469 100644
24597 --- a/arch/x86/mm/init_32.c
24598 +++ b/arch/x86/mm/init_32.c
24599 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24600 }
24601
24602 /*
24603 - * Creates a middle page table and puts a pointer to it in the
24604 - * given global directory entry. This only returns the gd entry
24605 - * in non-PAE compilation mode, since the middle layer is folded.
24606 - */
24607 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24608 -{
24609 - pud_t *pud;
24610 - pmd_t *pmd_table;
24611 -
24612 -#ifdef CONFIG_X86_PAE
24613 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24614 - if (after_bootmem)
24615 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24616 - else
24617 - pmd_table = (pmd_t *)alloc_low_page();
24618 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24619 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24620 - pud = pud_offset(pgd, 0);
24621 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24622 -
24623 - return pmd_table;
24624 - }
24625 -#endif
24626 - pud = pud_offset(pgd, 0);
24627 - pmd_table = pmd_offset(pud, 0);
24628 -
24629 - return pmd_table;
24630 -}
24631 -
24632 -/*
24633 * Create a page table and place a pointer to it in a middle page
24634 * directory entry:
24635 */
24636 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24637 page_table = (pte_t *)alloc_low_page();
24638
24639 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24640 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24641 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24642 +#else
24643 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24644 +#endif
24645 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24646 }
24647
24648 return pte_offset_kernel(pmd, 0);
24649 }
24650
24651 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24652 +{
24653 + pud_t *pud;
24654 + pmd_t *pmd_table;
24655 +
24656 + pud = pud_offset(pgd, 0);
24657 + pmd_table = pmd_offset(pud, 0);
24658 +
24659 + return pmd_table;
24660 +}
24661 +
24662 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24663 {
24664 int pgd_idx = pgd_index(vaddr);
24665 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24666 int pgd_idx, pmd_idx;
24667 unsigned long vaddr;
24668 pgd_t *pgd;
24669 + pud_t *pud;
24670 pmd_t *pmd;
24671 pte_t *pte = NULL;
24672
24673 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24674 pgd = pgd_base + pgd_idx;
24675
24676 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24677 - pmd = one_md_table_init(pgd);
24678 - pmd = pmd + pmd_index(vaddr);
24679 + pud = pud_offset(pgd, vaddr);
24680 + pmd = pmd_offset(pud, vaddr);
24681 +
24682 +#ifdef CONFIG_X86_PAE
24683 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24684 +#endif
24685 +
24686 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24687 pmd++, pmd_idx++) {
24688 pte = page_table_kmap_check(one_page_table_init(pmd),
24689 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24690 }
24691 }
24692
24693 -static inline int is_kernel_text(unsigned long addr)
24694 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24695 {
24696 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24697 - return 1;
24698 - return 0;
24699 + if ((start > ktla_ktva((unsigned long)_etext) ||
24700 + end <= ktla_ktva((unsigned long)_stext)) &&
24701 + (start > ktla_ktva((unsigned long)_einittext) ||
24702 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24703 +
24704 +#ifdef CONFIG_ACPI_SLEEP
24705 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24706 +#endif
24707 +
24708 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24709 + return 0;
24710 + return 1;
24711 }
24712
24713 /*
24714 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24715 unsigned long last_map_addr = end;
24716 unsigned long start_pfn, end_pfn;
24717 pgd_t *pgd_base = swapper_pg_dir;
24718 - int pgd_idx, pmd_idx, pte_ofs;
24719 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24720 unsigned long pfn;
24721 pgd_t *pgd;
24722 + pud_t *pud;
24723 pmd_t *pmd;
24724 pte_t *pte;
24725 unsigned pages_2m, pages_4k;
24726 @@ -280,8 +281,13 @@ repeat:
24727 pfn = start_pfn;
24728 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24729 pgd = pgd_base + pgd_idx;
24730 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24731 - pmd = one_md_table_init(pgd);
24732 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24733 + pud = pud_offset(pgd, 0);
24734 + pmd = pmd_offset(pud, 0);
24735 +
24736 +#ifdef CONFIG_X86_PAE
24737 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24738 +#endif
24739
24740 if (pfn >= end_pfn)
24741 continue;
24742 @@ -293,14 +299,13 @@ repeat:
24743 #endif
24744 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24745 pmd++, pmd_idx++) {
24746 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24747 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24748
24749 /*
24750 * Map with big pages if possible, otherwise
24751 * create normal page tables:
24752 */
24753 if (use_pse) {
24754 - unsigned int addr2;
24755 pgprot_t prot = PAGE_KERNEL_LARGE;
24756 /*
24757 * first pass will use the same initial
24758 @@ -310,11 +315,7 @@ repeat:
24759 __pgprot(PTE_IDENT_ATTR |
24760 _PAGE_PSE);
24761
24762 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24763 - PAGE_OFFSET + PAGE_SIZE-1;
24764 -
24765 - if (is_kernel_text(addr) ||
24766 - is_kernel_text(addr2))
24767 + if (is_kernel_text(address, address + PMD_SIZE))
24768 prot = PAGE_KERNEL_LARGE_EXEC;
24769
24770 pages_2m++;
24771 @@ -331,7 +332,7 @@ repeat:
24772 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24773 pte += pte_ofs;
24774 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24775 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24776 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24777 pgprot_t prot = PAGE_KERNEL;
24778 /*
24779 * first pass will use the same initial
24780 @@ -339,7 +340,7 @@ repeat:
24781 */
24782 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24783
24784 - if (is_kernel_text(addr))
24785 + if (is_kernel_text(address, address + PAGE_SIZE))
24786 prot = PAGE_KERNEL_EXEC;
24787
24788 pages_4k++;
24789 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24790
24791 pud = pud_offset(pgd, va);
24792 pmd = pmd_offset(pud, va);
24793 - if (!pmd_present(*pmd))
24794 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24795 break;
24796
24797 pte = pte_offset_kernel(pmd, va);
24798 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24799
24800 static void __init pagetable_init(void)
24801 {
24802 - pgd_t *pgd_base = swapper_pg_dir;
24803 -
24804 - permanent_kmaps_init(pgd_base);
24805 + permanent_kmaps_init(swapper_pg_dir);
24806 }
24807
24808 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24809 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24810 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24811
24812 /* user-defined highmem size */
24813 @@ -734,6 +733,12 @@ void __init mem_init(void)
24814
24815 pci_iommu_alloc();
24816
24817 +#ifdef CONFIG_PAX_PER_CPU_PGD
24818 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24819 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24820 + KERNEL_PGD_PTRS);
24821 +#endif
24822 +
24823 #ifdef CONFIG_FLATMEM
24824 BUG_ON(!mem_map);
24825 #endif
24826 @@ -760,7 +765,7 @@ void __init mem_init(void)
24827 reservedpages++;
24828
24829 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24830 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24831 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24832 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24833
24834 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24835 @@ -801,10 +806,10 @@ void __init mem_init(void)
24836 ((unsigned long)&__init_end -
24837 (unsigned long)&__init_begin) >> 10,
24838
24839 - (unsigned long)&_etext, (unsigned long)&_edata,
24840 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24841 + (unsigned long)&_sdata, (unsigned long)&_edata,
24842 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24843
24844 - (unsigned long)&_text, (unsigned long)&_etext,
24845 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24846 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24847
24848 /*
24849 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24850 if (!kernel_set_to_readonly)
24851 return;
24852
24853 + start = ktla_ktva(start);
24854 pr_debug("Set kernel text: %lx - %lx for read write\n",
24855 start, start+size);
24856
24857 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24858 if (!kernel_set_to_readonly)
24859 return;
24860
24861 + start = ktla_ktva(start);
24862 pr_debug("Set kernel text: %lx - %lx for read only\n",
24863 start, start+size);
24864
24865 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24866 unsigned long start = PFN_ALIGN(_text);
24867 unsigned long size = PFN_ALIGN(_etext) - start;
24868
24869 + start = ktla_ktva(start);
24870 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24871 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24872 size >> 10);
24873 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24874 index 2b6b4a3..c17210d 100644
24875 --- a/arch/x86/mm/init_64.c
24876 +++ b/arch/x86/mm/init_64.c
24877 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24878 * around without checking the pgd every time.
24879 */
24880
24881 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24882 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24883 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24884
24885 int force_personality32;
24886 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24887
24888 for (address = start; address <= end; address += PGDIR_SIZE) {
24889 const pgd_t *pgd_ref = pgd_offset_k(address);
24890 +
24891 +#ifdef CONFIG_PAX_PER_CPU_PGD
24892 + unsigned long cpu;
24893 +#else
24894 struct page *page;
24895 +#endif
24896
24897 if (pgd_none(*pgd_ref))
24898 continue;
24899
24900 spin_lock(&pgd_lock);
24901 +
24902 +#ifdef CONFIG_PAX_PER_CPU_PGD
24903 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24904 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24905 +#else
24906 list_for_each_entry(page, &pgd_list, lru) {
24907 pgd_t *pgd;
24908 spinlock_t *pgt_lock;
24909 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24910 /* the pgt_lock only for Xen */
24911 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24912 spin_lock(pgt_lock);
24913 +#endif
24914
24915 if (pgd_none(*pgd))
24916 set_pgd(pgd, *pgd_ref);
24917 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24918 BUG_ON(pgd_page_vaddr(*pgd)
24919 != pgd_page_vaddr(*pgd_ref));
24920
24921 +#ifndef CONFIG_PAX_PER_CPU_PGD
24922 spin_unlock(pgt_lock);
24923 +#endif
24924 +
24925 }
24926 spin_unlock(&pgd_lock);
24927 }
24928 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24929 {
24930 if (pgd_none(*pgd)) {
24931 pud_t *pud = (pud_t *)spp_getpage();
24932 - pgd_populate(&init_mm, pgd, pud);
24933 + pgd_populate_kernel(&init_mm, pgd, pud);
24934 if (pud != pud_offset(pgd, 0))
24935 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24936 pud, pud_offset(pgd, 0));
24937 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24938 {
24939 if (pud_none(*pud)) {
24940 pmd_t *pmd = (pmd_t *) spp_getpage();
24941 - pud_populate(&init_mm, pud, pmd);
24942 + pud_populate_kernel(&init_mm, pud, pmd);
24943 if (pmd != pmd_offset(pud, 0))
24944 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24945 pmd, pmd_offset(pud, 0));
24946 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24947 pmd = fill_pmd(pud, vaddr);
24948 pte = fill_pte(pmd, vaddr);
24949
24950 + pax_open_kernel();
24951 set_pte(pte, new_pte);
24952 + pax_close_kernel();
24953
24954 /*
24955 * It's enough to flush this one mapping.
24956 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24957 pgd = pgd_offset_k((unsigned long)__va(phys));
24958 if (pgd_none(*pgd)) {
24959 pud = (pud_t *) spp_getpage();
24960 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24961 - _PAGE_USER));
24962 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24963 }
24964 pud = pud_offset(pgd, (unsigned long)__va(phys));
24965 if (pud_none(*pud)) {
24966 pmd = (pmd_t *) spp_getpage();
24967 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24968 - _PAGE_USER));
24969 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24970 }
24971 pmd = pmd_offset(pud, phys);
24972 BUG_ON(!pmd_none(*pmd));
24973 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24974 if (pfn >= pgt_buf_top)
24975 panic("alloc_low_page: ran out of memory");
24976
24977 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24978 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24979 clear_page(adr);
24980 *phys = pfn * PAGE_SIZE;
24981 return adr;
24982 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24983
24984 phys = __pa(virt);
24985 left = phys & (PAGE_SIZE - 1);
24986 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24987 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24988 adr = (void *)(((unsigned long)adr) | left);
24989
24990 return adr;
24991 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24992 unmap_low_page(pmd);
24993
24994 spin_lock(&init_mm.page_table_lock);
24995 - pud_populate(&init_mm, pud, __va(pmd_phys));
24996 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24997 spin_unlock(&init_mm.page_table_lock);
24998 }
24999 __flush_tlb_all();
25000 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25001 unmap_low_page(pud);
25002
25003 spin_lock(&init_mm.page_table_lock);
25004 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25005 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25006 spin_unlock(&init_mm.page_table_lock);
25007 pgd_changed = true;
25008 }
25009 @@ -686,6 +700,12 @@ void __init mem_init(void)
25010
25011 pci_iommu_alloc();
25012
25013 +#ifdef CONFIG_PAX_PER_CPU_PGD
25014 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25015 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25016 + KERNEL_PGD_PTRS);
25017 +#endif
25018 +
25019 /* clear_bss() already clear the empty_zero_page */
25020
25021 reservedpages = 0;
25022 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25023 static struct vm_area_struct gate_vma = {
25024 .vm_start = VSYSCALL_START,
25025 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25026 - .vm_page_prot = PAGE_READONLY_EXEC,
25027 - .vm_flags = VM_READ | VM_EXEC
25028 + .vm_page_prot = PAGE_READONLY,
25029 + .vm_flags = VM_READ
25030 };
25031
25032 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25033 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25034
25035 const char *arch_vma_name(struct vm_area_struct *vma)
25036 {
25037 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25038 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25039 return "[vdso]";
25040 if (vma == &gate_vma)
25041 return "[vsyscall]";
25042 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25043 index 7b179b4..6bd1777 100644
25044 --- a/arch/x86/mm/iomap_32.c
25045 +++ b/arch/x86/mm/iomap_32.c
25046 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25047 type = kmap_atomic_idx_push();
25048 idx = type + KM_TYPE_NR * smp_processor_id();
25049 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25050 +
25051 + pax_open_kernel();
25052 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25053 + pax_close_kernel();
25054 +
25055 arch_flush_lazy_mmu_mode();
25056
25057 return (void *)vaddr;
25058 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25059 index 78fe3f1..8293b6f 100644
25060 --- a/arch/x86/mm/ioremap.c
25061 +++ b/arch/x86/mm/ioremap.c
25062 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25063 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25064 int is_ram = page_is_ram(pfn);
25065
25066 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25067 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25068 return NULL;
25069 WARN_ON_ONCE(is_ram);
25070 }
25071 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25072
25073 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25074 if (page_is_ram(start >> PAGE_SHIFT))
25075 +#ifdef CONFIG_HIGHMEM
25076 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25077 +#endif
25078 return __va(phys);
25079
25080 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25081 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25082 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25083
25084 static __initdata int after_paging_init;
25085 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25086 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25087
25088 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25089 {
25090 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25091 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25092
25093 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25094 - memset(bm_pte, 0, sizeof(bm_pte));
25095 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25096 + pmd_populate_user(&init_mm, pmd, bm_pte);
25097
25098 /*
25099 * The boot-ioremap range spans multiple pmds, for which
25100 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25101 index d87dd6d..bf3fa66 100644
25102 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25103 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25104 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25105 * memory (e.g. tracked pages)? For now, we need this to avoid
25106 * invoking kmemcheck for PnP BIOS calls.
25107 */
25108 - if (regs->flags & X86_VM_MASK)
25109 + if (v8086_mode(regs))
25110 return false;
25111 - if (regs->cs != __KERNEL_CS)
25112 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25113 return false;
25114
25115 pte = kmemcheck_pte_lookup(address);
25116 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25117 index 845df68..1d8d29f 100644
25118 --- a/arch/x86/mm/mmap.c
25119 +++ b/arch/x86/mm/mmap.c
25120 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25121 * Leave an at least ~128 MB hole with possible stack randomization.
25122 */
25123 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25124 -#define MAX_GAP (TASK_SIZE/6*5)
25125 +#define MAX_GAP (pax_task_size/6*5)
25126
25127 static int mmap_is_legacy(void)
25128 {
25129 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25130 return rnd << PAGE_SHIFT;
25131 }
25132
25133 -static unsigned long mmap_base(void)
25134 +static unsigned long mmap_base(struct mm_struct *mm)
25135 {
25136 unsigned long gap = rlimit(RLIMIT_STACK);
25137 + unsigned long pax_task_size = TASK_SIZE;
25138 +
25139 +#ifdef CONFIG_PAX_SEGMEXEC
25140 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25141 + pax_task_size = SEGMEXEC_TASK_SIZE;
25142 +#endif
25143
25144 if (gap < MIN_GAP)
25145 gap = MIN_GAP;
25146 else if (gap > MAX_GAP)
25147 gap = MAX_GAP;
25148
25149 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25150 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25151 }
25152
25153 /*
25154 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25155 * does, but not when emulating X86_32
25156 */
25157 -static unsigned long mmap_legacy_base(void)
25158 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25159 {
25160 - if (mmap_is_ia32())
25161 + if (mmap_is_ia32()) {
25162 +
25163 +#ifdef CONFIG_PAX_SEGMEXEC
25164 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25165 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25166 + else
25167 +#endif
25168 +
25169 return TASK_UNMAPPED_BASE;
25170 - else
25171 + } else
25172 return TASK_UNMAPPED_BASE + mmap_rnd();
25173 }
25174
25175 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25176 void arch_pick_mmap_layout(struct mm_struct *mm)
25177 {
25178 if (mmap_is_legacy()) {
25179 - mm->mmap_base = mmap_legacy_base();
25180 + mm->mmap_base = mmap_legacy_base(mm);
25181 +
25182 +#ifdef CONFIG_PAX_RANDMMAP
25183 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25184 + mm->mmap_base += mm->delta_mmap;
25185 +#endif
25186 +
25187 mm->get_unmapped_area = arch_get_unmapped_area;
25188 mm->unmap_area = arch_unmap_area;
25189 } else {
25190 - mm->mmap_base = mmap_base();
25191 + mm->mmap_base = mmap_base(mm);
25192 +
25193 +#ifdef CONFIG_PAX_RANDMMAP
25194 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25195 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25196 +#endif
25197 +
25198 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25199 mm->unmap_area = arch_unmap_area_topdown;
25200 }
25201 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25202 index dc0b727..dc9d71a 100644
25203 --- a/arch/x86/mm/mmio-mod.c
25204 +++ b/arch/x86/mm/mmio-mod.c
25205 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25206 break;
25207 default:
25208 {
25209 - unsigned char *ip = (unsigned char *)instptr;
25210 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25211 my_trace->opcode = MMIO_UNKNOWN_OP;
25212 my_trace->width = 0;
25213 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25214 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25215 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25216 void __iomem *addr)
25217 {
25218 - static atomic_t next_id;
25219 + static atomic_unchecked_t next_id;
25220 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25221 /* These are page-unaligned. */
25222 struct mmiotrace_map map = {
25223 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25224 .private = trace
25225 },
25226 .phys = offset,
25227 - .id = atomic_inc_return(&next_id)
25228 + .id = atomic_inc_return_unchecked(&next_id)
25229 };
25230 map.map_id = trace->id;
25231
25232 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25233 index b008656..773eac2 100644
25234 --- a/arch/x86/mm/pageattr-test.c
25235 +++ b/arch/x86/mm/pageattr-test.c
25236 @@ -36,7 +36,7 @@ enum {
25237
25238 static int pte_testbit(pte_t pte)
25239 {
25240 - return pte_flags(pte) & _PAGE_UNUSED1;
25241 + return pte_flags(pte) & _PAGE_CPA_TEST;
25242 }
25243
25244 struct split_state {
25245 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25246 index a718e0d..45efc32 100644
25247 --- a/arch/x86/mm/pageattr.c
25248 +++ b/arch/x86/mm/pageattr.c
25249 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25250 */
25251 #ifdef CONFIG_PCI_BIOS
25252 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25253 - pgprot_val(forbidden) |= _PAGE_NX;
25254 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25255 #endif
25256
25257 /*
25258 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25259 * Does not cover __inittext since that is gone later on. On
25260 * 64bit we do not enforce !NX on the low mapping
25261 */
25262 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25263 - pgprot_val(forbidden) |= _PAGE_NX;
25264 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25265 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25266
25267 +#ifdef CONFIG_DEBUG_RODATA
25268 /*
25269 * The .rodata section needs to be read-only. Using the pfn
25270 * catches all aliases.
25271 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25272 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25273 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25274 pgprot_val(forbidden) |= _PAGE_RW;
25275 +#endif
25276
25277 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25278 /*
25279 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25280 }
25281 #endif
25282
25283 +#ifdef CONFIG_PAX_KERNEXEC
25284 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25285 + pgprot_val(forbidden) |= _PAGE_RW;
25286 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25287 + }
25288 +#endif
25289 +
25290 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25291
25292 return prot;
25293 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25294 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25295 {
25296 /* change init_mm */
25297 + pax_open_kernel();
25298 set_pte_atomic(kpte, pte);
25299 +
25300 #ifdef CONFIG_X86_32
25301 if (!SHARED_KERNEL_PMD) {
25302 +
25303 +#ifdef CONFIG_PAX_PER_CPU_PGD
25304 + unsigned long cpu;
25305 +#else
25306 struct page *page;
25307 +#endif
25308
25309 +#ifdef CONFIG_PAX_PER_CPU_PGD
25310 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25311 + pgd_t *pgd = get_cpu_pgd(cpu);
25312 +#else
25313 list_for_each_entry(page, &pgd_list, lru) {
25314 - pgd_t *pgd;
25315 + pgd_t *pgd = (pgd_t *)page_address(page);
25316 +#endif
25317 +
25318 pud_t *pud;
25319 pmd_t *pmd;
25320
25321 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25322 + pgd += pgd_index(address);
25323 pud = pud_offset(pgd, address);
25324 pmd = pmd_offset(pud, address);
25325 set_pte_atomic((pte_t *)pmd, pte);
25326 }
25327 }
25328 #endif
25329 + pax_close_kernel();
25330 }
25331
25332 static int
25333 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25334 index 3d68ef6..7f69136 100644
25335 --- a/arch/x86/mm/pat.c
25336 +++ b/arch/x86/mm/pat.c
25337 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25338
25339 if (!entry) {
25340 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25341 - current->comm, current->pid, start, end - 1);
25342 + current->comm, task_pid_nr(current), start, end - 1);
25343 return -EINVAL;
25344 }
25345
25346 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25347
25348 while (cursor < to) {
25349 if (!devmem_is_allowed(pfn)) {
25350 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25351 - current->comm, from, to - 1);
25352 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25353 + current->comm, from, to - 1, cursor);
25354 return 0;
25355 }
25356 cursor += PAGE_SIZE;
25357 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25358 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25359 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25360 "for [mem %#010Lx-%#010Lx]\n",
25361 - current->comm, current->pid,
25362 + current->comm, task_pid_nr(current),
25363 cattr_name(flags),
25364 base, (unsigned long long)(base + size-1));
25365 return -EINVAL;
25366 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25367 flags = lookup_memtype(paddr);
25368 if (want_flags != flags) {
25369 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25370 - current->comm, current->pid,
25371 + current->comm, task_pid_nr(current),
25372 cattr_name(want_flags),
25373 (unsigned long long)paddr,
25374 (unsigned long long)(paddr + size - 1),
25375 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25376 free_memtype(paddr, paddr + size);
25377 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25378 " for [mem %#010Lx-%#010Lx], got %s\n",
25379 - current->comm, current->pid,
25380 + current->comm, task_pid_nr(current),
25381 cattr_name(want_flags),
25382 (unsigned long long)paddr,
25383 (unsigned long long)(paddr + size - 1),
25384 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25385 index 9f0614d..92ae64a 100644
25386 --- a/arch/x86/mm/pf_in.c
25387 +++ b/arch/x86/mm/pf_in.c
25388 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25389 int i;
25390 enum reason_type rv = OTHERS;
25391
25392 - p = (unsigned char *)ins_addr;
25393 + p = (unsigned char *)ktla_ktva(ins_addr);
25394 p += skip_prefix(p, &prf);
25395 p += get_opcode(p, &opcode);
25396
25397 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25398 struct prefix_bits prf;
25399 int i;
25400
25401 - p = (unsigned char *)ins_addr;
25402 + p = (unsigned char *)ktla_ktva(ins_addr);
25403 p += skip_prefix(p, &prf);
25404 p += get_opcode(p, &opcode);
25405
25406 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25407 struct prefix_bits prf;
25408 int i;
25409
25410 - p = (unsigned char *)ins_addr;
25411 + p = (unsigned char *)ktla_ktva(ins_addr);
25412 p += skip_prefix(p, &prf);
25413 p += get_opcode(p, &opcode);
25414
25415 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25416 struct prefix_bits prf;
25417 int i;
25418
25419 - p = (unsigned char *)ins_addr;
25420 + p = (unsigned char *)ktla_ktva(ins_addr);
25421 p += skip_prefix(p, &prf);
25422 p += get_opcode(p, &opcode);
25423 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25424 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25425 struct prefix_bits prf;
25426 int i;
25427
25428 - p = (unsigned char *)ins_addr;
25429 + p = (unsigned char *)ktla_ktva(ins_addr);
25430 p += skip_prefix(p, &prf);
25431 p += get_opcode(p, &opcode);
25432 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25433 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25434 index 8573b83..4f3ed7e 100644
25435 --- a/arch/x86/mm/pgtable.c
25436 +++ b/arch/x86/mm/pgtable.c
25437 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25438 list_del(&page->lru);
25439 }
25440
25441 -#define UNSHARED_PTRS_PER_PGD \
25442 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25443 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25444 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25445
25446 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25447 +{
25448 + unsigned int count = USER_PGD_PTRS;
25449
25450 + while (count--)
25451 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25452 +}
25453 +#endif
25454 +
25455 +#ifdef CONFIG_PAX_PER_CPU_PGD
25456 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25457 +{
25458 + unsigned int count = USER_PGD_PTRS;
25459 +
25460 + while (count--) {
25461 + pgd_t pgd;
25462 +
25463 +#ifdef CONFIG_X86_64
25464 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25465 +#else
25466 + pgd = *src++;
25467 +#endif
25468 +
25469 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25470 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25471 +#endif
25472 +
25473 + *dst++ = pgd;
25474 + }
25475 +
25476 +}
25477 +#endif
25478 +
25479 +#ifdef CONFIG_X86_64
25480 +#define pxd_t pud_t
25481 +#define pyd_t pgd_t
25482 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25483 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25484 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25485 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25486 +#define PYD_SIZE PGDIR_SIZE
25487 +#else
25488 +#define pxd_t pmd_t
25489 +#define pyd_t pud_t
25490 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25491 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25492 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25493 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25494 +#define PYD_SIZE PUD_SIZE
25495 +#endif
25496 +
25497 +#ifdef CONFIG_PAX_PER_CPU_PGD
25498 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25499 +static inline void pgd_dtor(pgd_t *pgd) {}
25500 +#else
25501 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25502 {
25503 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25504 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25505 pgd_list_del(pgd);
25506 spin_unlock(&pgd_lock);
25507 }
25508 +#endif
25509
25510 /*
25511 * List of all pgd's needed for non-PAE so it can invalidate entries
25512 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25513 * -- wli
25514 */
25515
25516 -#ifdef CONFIG_X86_PAE
25517 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25518 /*
25519 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25520 * updating the top-level pagetable entries to guarantee the
25521 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25522 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25523 * and initialize the kernel pmds here.
25524 */
25525 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25526 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25527
25528 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25529 {
25530 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25531 */
25532 flush_tlb_mm(mm);
25533 }
25534 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25535 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25536 #else /* !CONFIG_X86_PAE */
25537
25538 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25539 -#define PREALLOCATED_PMDS 0
25540 +#define PREALLOCATED_PXDS 0
25541
25542 #endif /* CONFIG_X86_PAE */
25543
25544 -static void free_pmds(pmd_t *pmds[])
25545 +static void free_pxds(pxd_t *pxds[])
25546 {
25547 int i;
25548
25549 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25550 - if (pmds[i])
25551 - free_page((unsigned long)pmds[i]);
25552 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25553 + if (pxds[i])
25554 + free_page((unsigned long)pxds[i]);
25555 }
25556
25557 -static int preallocate_pmds(pmd_t *pmds[])
25558 +static int preallocate_pxds(pxd_t *pxds[])
25559 {
25560 int i;
25561 bool failed = false;
25562
25563 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25564 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25565 - if (pmd == NULL)
25566 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25567 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25568 + if (pxd == NULL)
25569 failed = true;
25570 - pmds[i] = pmd;
25571 + pxds[i] = pxd;
25572 }
25573
25574 if (failed) {
25575 - free_pmds(pmds);
25576 + free_pxds(pxds);
25577 return -ENOMEM;
25578 }
25579
25580 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25581 * preallocate which never got a corresponding vma will need to be
25582 * freed manually.
25583 */
25584 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25585 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25586 {
25587 int i;
25588
25589 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25590 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25591 pgd_t pgd = pgdp[i];
25592
25593 if (pgd_val(pgd) != 0) {
25594 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25595 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25596
25597 - pgdp[i] = native_make_pgd(0);
25598 + set_pgd(pgdp + i, native_make_pgd(0));
25599
25600 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25601 - pmd_free(mm, pmd);
25602 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25603 + pxd_free(mm, pxd);
25604 }
25605 }
25606 }
25607
25608 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25609 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25610 {
25611 - pud_t *pud;
25612 + pyd_t *pyd;
25613 unsigned long addr;
25614 int i;
25615
25616 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25617 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25618 return;
25619
25620 - pud = pud_offset(pgd, 0);
25621 +#ifdef CONFIG_X86_64
25622 + pyd = pyd_offset(mm, 0L);
25623 +#else
25624 + pyd = pyd_offset(pgd, 0L);
25625 +#endif
25626
25627 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25628 - i++, pud++, addr += PUD_SIZE) {
25629 - pmd_t *pmd = pmds[i];
25630 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25631 + i++, pyd++, addr += PYD_SIZE) {
25632 + pxd_t *pxd = pxds[i];
25633
25634 if (i >= KERNEL_PGD_BOUNDARY)
25635 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25636 - sizeof(pmd_t) * PTRS_PER_PMD);
25637 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25638 + sizeof(pxd_t) * PTRS_PER_PMD);
25639
25640 - pud_populate(mm, pud, pmd);
25641 + pyd_populate(mm, pyd, pxd);
25642 }
25643 }
25644
25645 pgd_t *pgd_alloc(struct mm_struct *mm)
25646 {
25647 pgd_t *pgd;
25648 - pmd_t *pmds[PREALLOCATED_PMDS];
25649 + pxd_t *pxds[PREALLOCATED_PXDS];
25650
25651 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25652
25653 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25654
25655 mm->pgd = pgd;
25656
25657 - if (preallocate_pmds(pmds) != 0)
25658 + if (preallocate_pxds(pxds) != 0)
25659 goto out_free_pgd;
25660
25661 if (paravirt_pgd_alloc(mm) != 0)
25662 - goto out_free_pmds;
25663 + goto out_free_pxds;
25664
25665 /*
25666 * Make sure that pre-populating the pmds is atomic with
25667 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25668 spin_lock(&pgd_lock);
25669
25670 pgd_ctor(mm, pgd);
25671 - pgd_prepopulate_pmd(mm, pgd, pmds);
25672 + pgd_prepopulate_pxd(mm, pgd, pxds);
25673
25674 spin_unlock(&pgd_lock);
25675
25676 return pgd;
25677
25678 -out_free_pmds:
25679 - free_pmds(pmds);
25680 +out_free_pxds:
25681 + free_pxds(pxds);
25682 out_free_pgd:
25683 free_page((unsigned long)pgd);
25684 out:
25685 @@ -295,7 +356,7 @@ out:
25686
25687 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25688 {
25689 - pgd_mop_up_pmds(mm, pgd);
25690 + pgd_mop_up_pxds(mm, pgd);
25691 pgd_dtor(pgd);
25692 paravirt_pgd_free(mm, pgd);
25693 free_page((unsigned long)pgd);
25694 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25695 index a69bcb8..19068ab 100644
25696 --- a/arch/x86/mm/pgtable_32.c
25697 +++ b/arch/x86/mm/pgtable_32.c
25698 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25699 return;
25700 }
25701 pte = pte_offset_kernel(pmd, vaddr);
25702 +
25703 + pax_open_kernel();
25704 if (pte_val(pteval))
25705 set_pte_at(&init_mm, vaddr, pte, pteval);
25706 else
25707 pte_clear(&init_mm, vaddr, pte);
25708 + pax_close_kernel();
25709
25710 /*
25711 * It's enough to flush this one mapping.
25712 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25713 index 410531d..0f16030 100644
25714 --- a/arch/x86/mm/setup_nx.c
25715 +++ b/arch/x86/mm/setup_nx.c
25716 @@ -5,8 +5,10 @@
25717 #include <asm/pgtable.h>
25718 #include <asm/proto.h>
25719
25720 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25721 static int disable_nx __cpuinitdata;
25722
25723 +#ifndef CONFIG_PAX_PAGEEXEC
25724 /*
25725 * noexec = on|off
25726 *
25727 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25728 return 0;
25729 }
25730 early_param("noexec", noexec_setup);
25731 +#endif
25732 +
25733 +#endif
25734
25735 void __cpuinit x86_configure_nx(void)
25736 {
25737 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25738 if (cpu_has_nx && !disable_nx)
25739 __supported_pte_mask |= _PAGE_NX;
25740 else
25741 +#endif
25742 __supported_pte_mask &= ~_PAGE_NX;
25743 }
25744
25745 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25746 index 5e57e11..64874249 100644
25747 --- a/arch/x86/mm/tlb.c
25748 +++ b/arch/x86/mm/tlb.c
25749 @@ -66,7 +66,11 @@ void leave_mm(int cpu)
25750 BUG();
25751 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25752 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25753 +
25754 +#ifndef CONFIG_PAX_PER_CPU_PGD
25755 load_cr3(swapper_pg_dir);
25756 +#endif
25757 +
25758 }
25759 }
25760 EXPORT_SYMBOL_GPL(leave_mm);
25761 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25762 index 877b9a1..a8ecf42 100644
25763 --- a/arch/x86/net/bpf_jit.S
25764 +++ b/arch/x86/net/bpf_jit.S
25765 @@ -9,6 +9,7 @@
25766 */
25767 #include <linux/linkage.h>
25768 #include <asm/dwarf2.h>
25769 +#include <asm/alternative-asm.h>
25770
25771 /*
25772 * Calling convention :
25773 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25774 jle bpf_slow_path_word
25775 mov (SKBDATA,%rsi),%eax
25776 bswap %eax /* ntohl() */
25777 + pax_force_retaddr
25778 ret
25779
25780 sk_load_half:
25781 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25782 jle bpf_slow_path_half
25783 movzwl (SKBDATA,%rsi),%eax
25784 rol $8,%ax # ntohs()
25785 + pax_force_retaddr
25786 ret
25787
25788 sk_load_byte:
25789 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25790 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25791 jle bpf_slow_path_byte
25792 movzbl (SKBDATA,%rsi),%eax
25793 + pax_force_retaddr
25794 ret
25795
25796 /**
25797 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25798 movzbl (SKBDATA,%rsi),%ebx
25799 and $15,%bl
25800 shl $2,%bl
25801 + pax_force_retaddr
25802 ret
25803
25804 /* rsi contains offset and can be scratched */
25805 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25806 js bpf_error
25807 mov -12(%rbp),%eax
25808 bswap %eax
25809 + pax_force_retaddr
25810 ret
25811
25812 bpf_slow_path_half:
25813 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25814 mov -12(%rbp),%ax
25815 rol $8,%ax
25816 movzwl %ax,%eax
25817 + pax_force_retaddr
25818 ret
25819
25820 bpf_slow_path_byte:
25821 bpf_slow_path_common(1)
25822 js bpf_error
25823 movzbl -12(%rbp),%eax
25824 + pax_force_retaddr
25825 ret
25826
25827 bpf_slow_path_byte_msh:
25828 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25829 and $15,%al
25830 shl $2,%al
25831 xchg %eax,%ebx
25832 + pax_force_retaddr
25833 ret
25834
25835 #define sk_negative_common(SIZE) \
25836 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25837 sk_negative_common(4)
25838 mov (%rax), %eax
25839 bswap %eax
25840 + pax_force_retaddr
25841 ret
25842
25843 bpf_slow_path_half_neg:
25844 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25845 mov (%rax),%ax
25846 rol $8,%ax
25847 movzwl %ax,%eax
25848 + pax_force_retaddr
25849 ret
25850
25851 bpf_slow_path_byte_neg:
25852 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25853 .globl sk_load_byte_negative_offset
25854 sk_negative_common(1)
25855 movzbl (%rax), %eax
25856 + pax_force_retaddr
25857 ret
25858
25859 bpf_slow_path_byte_msh_neg:
25860 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25861 and $15,%al
25862 shl $2,%al
25863 xchg %eax,%ebx
25864 + pax_force_retaddr
25865 ret
25866
25867 bpf_error:
25868 @@ -197,4 +210,5 @@ bpf_error:
25869 xor %eax,%eax
25870 mov -8(%rbp),%rbx
25871 leaveq
25872 + pax_force_retaddr
25873 ret
25874 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25875 index 0597f95..a12c36e 100644
25876 --- a/arch/x86/net/bpf_jit_comp.c
25877 +++ b/arch/x86/net/bpf_jit_comp.c
25878 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25879 set_fs(old_fs);
25880 }
25881
25882 +struct bpf_jit_work {
25883 + struct work_struct work;
25884 + void *image;
25885 +};
25886 +
25887 #define CHOOSE_LOAD_FUNC(K, func) \
25888 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25889
25890 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25891 if (addrs == NULL)
25892 return;
25893
25894 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25895 + if (!fp->work)
25896 + goto out;
25897 +
25898 /* Before first pass, make a rough estimation of addrs[]
25899 * each bpf instruction is translated to less than 64 bytes
25900 */
25901 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25902 break;
25903 default:
25904 /* hmm, too complex filter, give up with jit compiler */
25905 - goto out;
25906 + goto error;
25907 }
25908 ilen = prog - temp;
25909 if (image) {
25910 if (unlikely(proglen + ilen > oldproglen)) {
25911 pr_err("bpb_jit_compile fatal error\n");
25912 - kfree(addrs);
25913 - module_free(NULL, image);
25914 - return;
25915 + module_free_exec(NULL, image);
25916 + goto error;
25917 }
25918 + pax_open_kernel();
25919 memcpy(image + proglen, temp, ilen);
25920 + pax_close_kernel();
25921 }
25922 proglen += ilen;
25923 addrs[i] = proglen;
25924 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25925 break;
25926 }
25927 if (proglen == oldproglen) {
25928 - image = module_alloc(max_t(unsigned int,
25929 - proglen,
25930 - sizeof(struct work_struct)));
25931 + image = module_alloc_exec(proglen);
25932 if (!image)
25933 - goto out;
25934 + goto error;
25935 }
25936 oldproglen = proglen;
25937 }
25938 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25939 bpf_flush_icache(image, image + proglen);
25940
25941 fp->bpf_func = (void *)image;
25942 - }
25943 + } else
25944 +error:
25945 + kfree(fp->work);
25946 +
25947 out:
25948 kfree(addrs);
25949 return;
25950 @@ -648,18 +659,20 @@ out:
25951
25952 static void jit_free_defer(struct work_struct *arg)
25953 {
25954 - module_free(NULL, arg);
25955 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25956 + kfree(arg);
25957 }
25958
25959 /* run from softirq, we must use a work_struct to call
25960 - * module_free() from process context
25961 + * module_free_exec() from process context
25962 */
25963 void bpf_jit_free(struct sk_filter *fp)
25964 {
25965 if (fp->bpf_func != sk_run_filter) {
25966 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25967 + struct work_struct *work = &fp->work->work;
25968
25969 INIT_WORK(work, jit_free_defer);
25970 + fp->work->image = fp->bpf_func;
25971 schedule_work(work);
25972 }
25973 }
25974 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25975 index d6aa6e8..266395a 100644
25976 --- a/arch/x86/oprofile/backtrace.c
25977 +++ b/arch/x86/oprofile/backtrace.c
25978 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25979 struct stack_frame_ia32 *fp;
25980 unsigned long bytes;
25981
25982 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25983 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25984 if (bytes != sizeof(bufhead))
25985 return NULL;
25986
25987 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25988 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25989
25990 oprofile_add_trace(bufhead[0].return_address);
25991
25992 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25993 struct stack_frame bufhead[2];
25994 unsigned long bytes;
25995
25996 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25997 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25998 if (bytes != sizeof(bufhead))
25999 return NULL;
26000
26001 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26002 {
26003 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26004
26005 - if (!user_mode_vm(regs)) {
26006 + if (!user_mode(regs)) {
26007 unsigned long stack = kernel_stack_pointer(regs);
26008 if (depth)
26009 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26010 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26011 index 140942f..8a5cc55 100644
26012 --- a/arch/x86/pci/mrst.c
26013 +++ b/arch/x86/pci/mrst.c
26014 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26015 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26016 pci_mmcfg_late_init();
26017 pcibios_enable_irq = mrst_pci_irq_enable;
26018 - pci_root_ops = pci_mrst_ops;
26019 + pax_open_kernel();
26020 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26021 + pax_close_kernel();
26022 pci_soc_mode = 1;
26023 /* Continue with standard init */
26024 return 1;
26025 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26026 index da8fe05..7ee6704 100644
26027 --- a/arch/x86/pci/pcbios.c
26028 +++ b/arch/x86/pci/pcbios.c
26029 @@ -79,50 +79,93 @@ union bios32 {
26030 static struct {
26031 unsigned long address;
26032 unsigned short segment;
26033 -} bios32_indirect = { 0, __KERNEL_CS };
26034 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26035
26036 /*
26037 * Returns the entry point for the given service, NULL on error
26038 */
26039
26040 -static unsigned long bios32_service(unsigned long service)
26041 +static unsigned long __devinit bios32_service(unsigned long service)
26042 {
26043 unsigned char return_code; /* %al */
26044 unsigned long address; /* %ebx */
26045 unsigned long length; /* %ecx */
26046 unsigned long entry; /* %edx */
26047 unsigned long flags;
26048 + struct desc_struct d, *gdt;
26049
26050 local_irq_save(flags);
26051 - __asm__("lcall *(%%edi); cld"
26052 +
26053 + gdt = get_cpu_gdt_table(smp_processor_id());
26054 +
26055 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26056 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26057 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26058 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26059 +
26060 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26061 : "=a" (return_code),
26062 "=b" (address),
26063 "=c" (length),
26064 "=d" (entry)
26065 : "0" (service),
26066 "1" (0),
26067 - "D" (&bios32_indirect));
26068 + "D" (&bios32_indirect),
26069 + "r"(__PCIBIOS_DS)
26070 + : "memory");
26071 +
26072 + pax_open_kernel();
26073 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26074 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26075 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26076 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26077 + pax_close_kernel();
26078 +
26079 local_irq_restore(flags);
26080
26081 switch (return_code) {
26082 - case 0:
26083 - return address + entry;
26084 - case 0x80: /* Not present */
26085 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26086 - return 0;
26087 - default: /* Shouldn't happen */
26088 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26089 - service, return_code);
26090 + case 0: {
26091 + int cpu;
26092 + unsigned char flags;
26093 +
26094 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26095 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26096 + printk(KERN_WARNING "bios32_service: not valid\n");
26097 return 0;
26098 + }
26099 + address = address + PAGE_OFFSET;
26100 + length += 16UL; /* some BIOSs underreport this... */
26101 + flags = 4;
26102 + if (length >= 64*1024*1024) {
26103 + length >>= PAGE_SHIFT;
26104 + flags |= 8;
26105 + }
26106 +
26107 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26108 + gdt = get_cpu_gdt_table(cpu);
26109 + pack_descriptor(&d, address, length, 0x9b, flags);
26110 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26111 + pack_descriptor(&d, address, length, 0x93, flags);
26112 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26113 + }
26114 + return entry;
26115 + }
26116 + case 0x80: /* Not present */
26117 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26118 + return 0;
26119 + default: /* Shouldn't happen */
26120 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26121 + service, return_code);
26122 + return 0;
26123 }
26124 }
26125
26126 static struct {
26127 unsigned long address;
26128 unsigned short segment;
26129 -} pci_indirect = { 0, __KERNEL_CS };
26130 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26131
26132 -static int pci_bios_present;
26133 +static int pci_bios_present __read_only;
26134
26135 static int __devinit check_pcibios(void)
26136 {
26137 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26138 unsigned long flags, pcibios_entry;
26139
26140 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26141 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26142 + pci_indirect.address = pcibios_entry;
26143
26144 local_irq_save(flags);
26145 - __asm__(
26146 - "lcall *(%%edi); cld\n\t"
26147 + __asm__("movw %w6, %%ds\n\t"
26148 + "lcall *%%ss:(%%edi); cld\n\t"
26149 + "push %%ss\n\t"
26150 + "pop %%ds\n\t"
26151 "jc 1f\n\t"
26152 "xor %%ah, %%ah\n"
26153 "1:"
26154 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26155 "=b" (ebx),
26156 "=c" (ecx)
26157 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26158 - "D" (&pci_indirect)
26159 + "D" (&pci_indirect),
26160 + "r" (__PCIBIOS_DS)
26161 : "memory");
26162 local_irq_restore(flags);
26163
26164 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26165
26166 switch (len) {
26167 case 1:
26168 - __asm__("lcall *(%%esi); cld\n\t"
26169 + __asm__("movw %w6, %%ds\n\t"
26170 + "lcall *%%ss:(%%esi); cld\n\t"
26171 + "push %%ss\n\t"
26172 + "pop %%ds\n\t"
26173 "jc 1f\n\t"
26174 "xor %%ah, %%ah\n"
26175 "1:"
26176 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26177 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26178 "b" (bx),
26179 "D" ((long)reg),
26180 - "S" (&pci_indirect));
26181 + "S" (&pci_indirect),
26182 + "r" (__PCIBIOS_DS));
26183 /*
26184 * Zero-extend the result beyond 8 bits, do not trust the
26185 * BIOS having done it:
26186 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26187 *value &= 0xff;
26188 break;
26189 case 2:
26190 - __asm__("lcall *(%%esi); cld\n\t"
26191 + __asm__("movw %w6, %%ds\n\t"
26192 + "lcall *%%ss:(%%esi); cld\n\t"
26193 + "push %%ss\n\t"
26194 + "pop %%ds\n\t"
26195 "jc 1f\n\t"
26196 "xor %%ah, %%ah\n"
26197 "1:"
26198 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26199 : "1" (PCIBIOS_READ_CONFIG_WORD),
26200 "b" (bx),
26201 "D" ((long)reg),
26202 - "S" (&pci_indirect));
26203 + "S" (&pci_indirect),
26204 + "r" (__PCIBIOS_DS));
26205 /*
26206 * Zero-extend the result beyond 16 bits, do not trust the
26207 * BIOS having done it:
26208 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26209 *value &= 0xffff;
26210 break;
26211 case 4:
26212 - __asm__("lcall *(%%esi); cld\n\t"
26213 + __asm__("movw %w6, %%ds\n\t"
26214 + "lcall *%%ss:(%%esi); cld\n\t"
26215 + "push %%ss\n\t"
26216 + "pop %%ds\n\t"
26217 "jc 1f\n\t"
26218 "xor %%ah, %%ah\n"
26219 "1:"
26220 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26221 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26222 "b" (bx),
26223 "D" ((long)reg),
26224 - "S" (&pci_indirect));
26225 + "S" (&pci_indirect),
26226 + "r" (__PCIBIOS_DS));
26227 break;
26228 }
26229
26230 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26231
26232 switch (len) {
26233 case 1:
26234 - __asm__("lcall *(%%esi); cld\n\t"
26235 + __asm__("movw %w6, %%ds\n\t"
26236 + "lcall *%%ss:(%%esi); cld\n\t"
26237 + "push %%ss\n\t"
26238 + "pop %%ds\n\t"
26239 "jc 1f\n\t"
26240 "xor %%ah, %%ah\n"
26241 "1:"
26242 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26243 "c" (value),
26244 "b" (bx),
26245 "D" ((long)reg),
26246 - "S" (&pci_indirect));
26247 + "S" (&pci_indirect),
26248 + "r" (__PCIBIOS_DS));
26249 break;
26250 case 2:
26251 - __asm__("lcall *(%%esi); cld\n\t"
26252 + __asm__("movw %w6, %%ds\n\t"
26253 + "lcall *%%ss:(%%esi); cld\n\t"
26254 + "push %%ss\n\t"
26255 + "pop %%ds\n\t"
26256 "jc 1f\n\t"
26257 "xor %%ah, %%ah\n"
26258 "1:"
26259 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26260 "c" (value),
26261 "b" (bx),
26262 "D" ((long)reg),
26263 - "S" (&pci_indirect));
26264 + "S" (&pci_indirect),
26265 + "r" (__PCIBIOS_DS));
26266 break;
26267 case 4:
26268 - __asm__("lcall *(%%esi); cld\n\t"
26269 + __asm__("movw %w6, %%ds\n\t"
26270 + "lcall *%%ss:(%%esi); cld\n\t"
26271 + "push %%ss\n\t"
26272 + "pop %%ds\n\t"
26273 "jc 1f\n\t"
26274 "xor %%ah, %%ah\n"
26275 "1:"
26276 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26277 "c" (value),
26278 "b" (bx),
26279 "D" ((long)reg),
26280 - "S" (&pci_indirect));
26281 + "S" (&pci_indirect),
26282 + "r" (__PCIBIOS_DS));
26283 break;
26284 }
26285
26286 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26287
26288 DBG("PCI: Fetching IRQ routing table... ");
26289 __asm__("push %%es\n\t"
26290 + "movw %w8, %%ds\n\t"
26291 "push %%ds\n\t"
26292 "pop %%es\n\t"
26293 - "lcall *(%%esi); cld\n\t"
26294 + "lcall *%%ss:(%%esi); cld\n\t"
26295 "pop %%es\n\t"
26296 + "push %%ss\n\t"
26297 + "pop %%ds\n"
26298 "jc 1f\n\t"
26299 "xor %%ah, %%ah\n"
26300 "1:"
26301 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26302 "1" (0),
26303 "D" ((long) &opt),
26304 "S" (&pci_indirect),
26305 - "m" (opt)
26306 + "m" (opt),
26307 + "r" (__PCIBIOS_DS)
26308 : "memory");
26309 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26310 if (ret & 0xff00)
26311 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26312 {
26313 int ret;
26314
26315 - __asm__("lcall *(%%esi); cld\n\t"
26316 + __asm__("movw %w5, %%ds\n\t"
26317 + "lcall *%%ss:(%%esi); cld\n\t"
26318 + "push %%ss\n\t"
26319 + "pop %%ds\n"
26320 "jc 1f\n\t"
26321 "xor %%ah, %%ah\n"
26322 "1:"
26323 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26324 : "0" (PCIBIOS_SET_PCI_HW_INT),
26325 "b" ((dev->bus->number << 8) | dev->devfn),
26326 "c" ((irq << 8) | (pin + 10)),
26327 - "S" (&pci_indirect));
26328 + "S" (&pci_indirect),
26329 + "r" (__PCIBIOS_DS));
26330 return !(ret & 0xff00);
26331 }
26332 EXPORT_SYMBOL(pcibios_set_irq_routing);
26333 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26334 index 40e4469..1ab536e 100644
26335 --- a/arch/x86/platform/efi/efi_32.c
26336 +++ b/arch/x86/platform/efi/efi_32.c
26337 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26338 {
26339 struct desc_ptr gdt_descr;
26340
26341 +#ifdef CONFIG_PAX_KERNEXEC
26342 + struct desc_struct d;
26343 +#endif
26344 +
26345 local_irq_save(efi_rt_eflags);
26346
26347 load_cr3(initial_page_table);
26348 __flush_tlb_all();
26349
26350 +#ifdef CONFIG_PAX_KERNEXEC
26351 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26352 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26353 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26354 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26355 +#endif
26356 +
26357 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26358 gdt_descr.size = GDT_SIZE - 1;
26359 load_gdt(&gdt_descr);
26360 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26361 {
26362 struct desc_ptr gdt_descr;
26363
26364 +#ifdef CONFIG_PAX_KERNEXEC
26365 + struct desc_struct d;
26366 +
26367 + memset(&d, 0, sizeof d);
26368 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26369 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26370 +#endif
26371 +
26372 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26373 gdt_descr.size = GDT_SIZE - 1;
26374 load_gdt(&gdt_descr);
26375 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26376 index fbe66e6..eae5e38 100644
26377 --- a/arch/x86/platform/efi/efi_stub_32.S
26378 +++ b/arch/x86/platform/efi/efi_stub_32.S
26379 @@ -6,7 +6,9 @@
26380 */
26381
26382 #include <linux/linkage.h>
26383 +#include <linux/init.h>
26384 #include <asm/page_types.h>
26385 +#include <asm/segment.h>
26386
26387 /*
26388 * efi_call_phys(void *, ...) is a function with variable parameters.
26389 @@ -20,7 +22,7 @@
26390 * service functions will comply with gcc calling convention, too.
26391 */
26392
26393 -.text
26394 +__INIT
26395 ENTRY(efi_call_phys)
26396 /*
26397 * 0. The function can only be called in Linux kernel. So CS has been
26398 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26399 * The mapping of lower virtual memory has been created in prelog and
26400 * epilog.
26401 */
26402 - movl $1f, %edx
26403 - subl $__PAGE_OFFSET, %edx
26404 - jmp *%edx
26405 +#ifdef CONFIG_PAX_KERNEXEC
26406 + movl $(__KERNEXEC_EFI_DS), %edx
26407 + mov %edx, %ds
26408 + mov %edx, %es
26409 + mov %edx, %ss
26410 + addl $2f,(1f)
26411 + ljmp *(1f)
26412 +
26413 +__INITDATA
26414 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26415 +.previous
26416 +
26417 +2:
26418 + subl $2b,(1b)
26419 +#else
26420 + jmp 1f-__PAGE_OFFSET
26421 1:
26422 +#endif
26423
26424 /*
26425 * 2. Now on the top of stack is the return
26426 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26427 * parameter 2, ..., param n. To make things easy, we save the return
26428 * address of efi_call_phys in a global variable.
26429 */
26430 - popl %edx
26431 - movl %edx, saved_return_addr
26432 - /* get the function pointer into ECX*/
26433 - popl %ecx
26434 - movl %ecx, efi_rt_function_ptr
26435 - movl $2f, %edx
26436 - subl $__PAGE_OFFSET, %edx
26437 - pushl %edx
26438 + popl (saved_return_addr)
26439 + popl (efi_rt_function_ptr)
26440
26441 /*
26442 * 3. Clear PG bit in %CR0.
26443 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26444 /*
26445 * 5. Call the physical function.
26446 */
26447 - jmp *%ecx
26448 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26449
26450 -2:
26451 /*
26452 * 6. After EFI runtime service returns, control will return to
26453 * following instruction. We'd better readjust stack pointer first.
26454 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26455 movl %cr0, %edx
26456 orl $0x80000000, %edx
26457 movl %edx, %cr0
26458 - jmp 1f
26459 -1:
26460 +
26461 /*
26462 * 8. Now restore the virtual mode from flat mode by
26463 * adding EIP with PAGE_OFFSET.
26464 */
26465 - movl $1f, %edx
26466 - jmp *%edx
26467 +#ifdef CONFIG_PAX_KERNEXEC
26468 + movl $(__KERNEL_DS), %edx
26469 + mov %edx, %ds
26470 + mov %edx, %es
26471 + mov %edx, %ss
26472 + ljmp $(__KERNEL_CS),$1f
26473 +#else
26474 + jmp 1f+__PAGE_OFFSET
26475 +#endif
26476 1:
26477
26478 /*
26479 * 9. Balance the stack. And because EAX contain the return value,
26480 * we'd better not clobber it.
26481 */
26482 - leal efi_rt_function_ptr, %edx
26483 - movl (%edx), %ecx
26484 - pushl %ecx
26485 + pushl (efi_rt_function_ptr)
26486
26487 /*
26488 - * 10. Push the saved return address onto the stack and return.
26489 + * 10. Return to the saved return address.
26490 */
26491 - leal saved_return_addr, %edx
26492 - movl (%edx), %ecx
26493 - pushl %ecx
26494 - ret
26495 + jmpl *(saved_return_addr)
26496 ENDPROC(efi_call_phys)
26497 .previous
26498
26499 -.data
26500 +__INITDATA
26501 saved_return_addr:
26502 .long 0
26503 efi_rt_function_ptr:
26504 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26505 index 4c07cca..2c8427d 100644
26506 --- a/arch/x86/platform/efi/efi_stub_64.S
26507 +++ b/arch/x86/platform/efi/efi_stub_64.S
26508 @@ -7,6 +7,7 @@
26509 */
26510
26511 #include <linux/linkage.h>
26512 +#include <asm/alternative-asm.h>
26513
26514 #define SAVE_XMM \
26515 mov %rsp, %rax; \
26516 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26517 call *%rdi
26518 addq $32, %rsp
26519 RESTORE_XMM
26520 + pax_force_retaddr 0, 1
26521 ret
26522 ENDPROC(efi_call0)
26523
26524 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26525 call *%rdi
26526 addq $32, %rsp
26527 RESTORE_XMM
26528 + pax_force_retaddr 0, 1
26529 ret
26530 ENDPROC(efi_call1)
26531
26532 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26533 call *%rdi
26534 addq $32, %rsp
26535 RESTORE_XMM
26536 + pax_force_retaddr 0, 1
26537 ret
26538 ENDPROC(efi_call2)
26539
26540 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26541 call *%rdi
26542 addq $32, %rsp
26543 RESTORE_XMM
26544 + pax_force_retaddr 0, 1
26545 ret
26546 ENDPROC(efi_call3)
26547
26548 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26549 call *%rdi
26550 addq $32, %rsp
26551 RESTORE_XMM
26552 + pax_force_retaddr 0, 1
26553 ret
26554 ENDPROC(efi_call4)
26555
26556 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26557 call *%rdi
26558 addq $48, %rsp
26559 RESTORE_XMM
26560 + pax_force_retaddr 0, 1
26561 ret
26562 ENDPROC(efi_call5)
26563
26564 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26565 call *%rdi
26566 addq $48, %rsp
26567 RESTORE_XMM
26568 + pax_force_retaddr 0, 1
26569 ret
26570 ENDPROC(efi_call6)
26571 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26572 index fd41a92..9c33628 100644
26573 --- a/arch/x86/platform/mrst/mrst.c
26574 +++ b/arch/x86/platform/mrst/mrst.c
26575 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26576 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26577 int sfi_mrtc_num;
26578
26579 -static void mrst_power_off(void)
26580 +static __noreturn void mrst_power_off(void)
26581 {
26582 + BUG();
26583 }
26584
26585 -static void mrst_reboot(void)
26586 +static __noreturn void mrst_reboot(void)
26587 {
26588 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26589 + BUG();
26590 }
26591
26592 /* parse all the mtimer info to a static mtimer array */
26593 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26594 index 218cdb1..fd55c08 100644
26595 --- a/arch/x86/power/cpu.c
26596 +++ b/arch/x86/power/cpu.c
26597 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26598 static void fix_processor_context(void)
26599 {
26600 int cpu = smp_processor_id();
26601 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26602 + struct tss_struct *t = init_tss + cpu;
26603
26604 set_tss_desc(cpu, t); /*
26605 * This just modifies memory; should not be
26606 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26607 */
26608
26609 #ifdef CONFIG_X86_64
26610 + pax_open_kernel();
26611 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26612 + pax_close_kernel();
26613
26614 syscall_init(); /* This sets MSR_*STAR and related */
26615 #endif
26616 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26617 index cbca565..bae7133 100644
26618 --- a/arch/x86/realmode/init.c
26619 +++ b/arch/x86/realmode/init.c
26620 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26621 __va(real_mode_header->trampoline_header);
26622
26623 #ifdef CONFIG_X86_32
26624 - trampoline_header->start = __pa(startup_32_smp);
26625 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26626 +
26627 +#ifdef CONFIG_PAX_KERNEXEC
26628 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26629 +#endif
26630 +
26631 + trampoline_header->boot_cs = __BOOT_CS;
26632 trampoline_header->gdt_limit = __BOOT_DS + 7;
26633 trampoline_header->gdt_base = __pa(boot_gdt);
26634 #else
26635 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26636 index 5b84a2d..a004393 100644
26637 --- a/arch/x86/realmode/rm/Makefile
26638 +++ b/arch/x86/realmode/rm/Makefile
26639 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26640 $(call cc-option, -fno-unit-at-a-time)) \
26641 $(call cc-option, -fno-stack-protector) \
26642 $(call cc-option, -mpreferred-stack-boundary=2)
26643 +ifdef CONSTIFY_PLUGIN
26644 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26645 +endif
26646 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26647 GCOV_PROFILE := n
26648 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26649 index c1b2791..f9e31c7 100644
26650 --- a/arch/x86/realmode/rm/trampoline_32.S
26651 +++ b/arch/x86/realmode/rm/trampoline_32.S
26652 @@ -25,6 +25,12 @@
26653 #include <asm/page_types.h>
26654 #include "realmode.h"
26655
26656 +#ifdef CONFIG_PAX_KERNEXEC
26657 +#define ta(X) (X)
26658 +#else
26659 +#define ta(X) (pa_ ## X)
26660 +#endif
26661 +
26662 .text
26663 .code16
26664
26665 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26666
26667 cli # We should be safe anyway
26668
26669 - movl tr_start, %eax # where we need to go
26670 -
26671 movl $0xA5A5A5A5, trampoline_status
26672 # write marker for master knows we're running
26673
26674 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26675 movw $1, %dx # protected mode (PE) bit
26676 lmsw %dx # into protected mode
26677
26678 - ljmpl $__BOOT_CS, $pa_startup_32
26679 + ljmpl *(trampoline_header)
26680
26681 .section ".text32","ax"
26682 .code32
26683 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26684 .balign 8
26685 GLOBAL(trampoline_header)
26686 tr_start: .space 4
26687 - tr_gdt_pad: .space 2
26688 + tr_boot_cs: .space 2
26689 tr_gdt: .space 6
26690 END(trampoline_header)
26691
26692 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26693 index bb360dc..3e5945f 100644
26694 --- a/arch/x86/realmode/rm/trampoline_64.S
26695 +++ b/arch/x86/realmode/rm/trampoline_64.S
26696 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26697 wrmsr
26698
26699 # Enable paging and in turn activate Long Mode
26700 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26701 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26702 movl %eax, %cr0
26703
26704 /*
26705 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26706 index 5a1847d..deccb30 100644
26707 --- a/arch/x86/tools/relocs.c
26708 +++ b/arch/x86/tools/relocs.c
26709 @@ -12,10 +12,13 @@
26710 #include <regex.h>
26711 #include <tools/le_byteshift.h>
26712
26713 +#include "../../../include/generated/autoconf.h"
26714 +
26715 static void die(char *fmt, ...);
26716
26717 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26718 static Elf32_Ehdr ehdr;
26719 +static Elf32_Phdr *phdr;
26720 static unsigned long reloc_count, reloc_idx;
26721 static unsigned long *relocs;
26722 static unsigned long reloc16_count, reloc16_idx;
26723 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26724 }
26725 }
26726
26727 +static void read_phdrs(FILE *fp)
26728 +{
26729 + unsigned int i;
26730 +
26731 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26732 + if (!phdr) {
26733 + die("Unable to allocate %d program headers\n",
26734 + ehdr.e_phnum);
26735 + }
26736 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26737 + die("Seek to %d failed: %s\n",
26738 + ehdr.e_phoff, strerror(errno));
26739 + }
26740 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26741 + die("Cannot read ELF program headers: %s\n",
26742 + strerror(errno));
26743 + }
26744 + for(i = 0; i < ehdr.e_phnum; i++) {
26745 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26746 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26747 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26748 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26749 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26750 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26751 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26752 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26753 + }
26754 +
26755 +}
26756 +
26757 static void read_shdrs(FILE *fp)
26758 {
26759 - int i;
26760 + unsigned int i;
26761 Elf32_Shdr shdr;
26762
26763 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26764 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26765
26766 static void read_strtabs(FILE *fp)
26767 {
26768 - int i;
26769 + unsigned int i;
26770 for (i = 0; i < ehdr.e_shnum; i++) {
26771 struct section *sec = &secs[i];
26772 if (sec->shdr.sh_type != SHT_STRTAB) {
26773 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26774
26775 static void read_symtabs(FILE *fp)
26776 {
26777 - int i,j;
26778 + unsigned int i,j;
26779 for (i = 0; i < ehdr.e_shnum; i++) {
26780 struct section *sec = &secs[i];
26781 if (sec->shdr.sh_type != SHT_SYMTAB) {
26782 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26783 }
26784
26785
26786 -static void read_relocs(FILE *fp)
26787 +static void read_relocs(FILE *fp, int use_real_mode)
26788 {
26789 - int i,j;
26790 + unsigned int i,j;
26791 + uint32_t base;
26792 +
26793 for (i = 0; i < ehdr.e_shnum; i++) {
26794 struct section *sec = &secs[i];
26795 if (sec->shdr.sh_type != SHT_REL) {
26796 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26797 die("Cannot read symbol table: %s\n",
26798 strerror(errno));
26799 }
26800 + base = 0;
26801 +
26802 +#ifdef CONFIG_X86_32
26803 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26804 + if (phdr[j].p_type != PT_LOAD )
26805 + continue;
26806 + 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)
26807 + continue;
26808 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26809 + break;
26810 + }
26811 +#endif
26812 +
26813 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26814 Elf32_Rel *rel = &sec->reltab[j];
26815 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26816 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26817 rel->r_info = elf32_to_cpu(rel->r_info);
26818 }
26819 }
26820 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26821
26822 static void print_absolute_symbols(void)
26823 {
26824 - int i;
26825 + unsigned int i;
26826 printf("Absolute symbols\n");
26827 printf(" Num: Value Size Type Bind Visibility Name\n");
26828 for (i = 0; i < ehdr.e_shnum; i++) {
26829 struct section *sec = &secs[i];
26830 char *sym_strtab;
26831 - int j;
26832 + unsigned int j;
26833
26834 if (sec->shdr.sh_type != SHT_SYMTAB) {
26835 continue;
26836 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26837
26838 static void print_absolute_relocs(void)
26839 {
26840 - int i, printed = 0;
26841 + unsigned int i, printed = 0;
26842
26843 for (i = 0; i < ehdr.e_shnum; i++) {
26844 struct section *sec = &secs[i];
26845 struct section *sec_applies, *sec_symtab;
26846 char *sym_strtab;
26847 Elf32_Sym *sh_symtab;
26848 - int j;
26849 + unsigned int j;
26850 if (sec->shdr.sh_type != SHT_REL) {
26851 continue;
26852 }
26853 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26854 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26855 int use_real_mode)
26856 {
26857 - int i;
26858 + unsigned int i;
26859 /* Walk through the relocations */
26860 for (i = 0; i < ehdr.e_shnum; i++) {
26861 char *sym_strtab;
26862 Elf32_Sym *sh_symtab;
26863 struct section *sec_applies, *sec_symtab;
26864 - int j;
26865 + unsigned int j;
26866 struct section *sec = &secs[i];
26867
26868 if (sec->shdr.sh_type != SHT_REL) {
26869 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26870 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26871 r_type = ELF32_R_TYPE(rel->r_info);
26872
26873 + if (!use_real_mode) {
26874 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26875 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26876 + continue;
26877 +
26878 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26879 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26880 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26881 + continue;
26882 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26883 + continue;
26884 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26885 + continue;
26886 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26887 + continue;
26888 +#endif
26889 + }
26890 +
26891 shn_abs = sym->st_shndx == SHN_ABS;
26892
26893 switch (r_type) {
26894 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26895
26896 static void emit_relocs(int as_text, int use_real_mode)
26897 {
26898 - int i;
26899 + unsigned int i;
26900 /* Count how many relocations I have and allocate space for them. */
26901 reloc_count = 0;
26902 walk_relocs(count_reloc, use_real_mode);
26903 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
26904 fname, strerror(errno));
26905 }
26906 read_ehdr(fp);
26907 + read_phdrs(fp);
26908 read_shdrs(fp);
26909 read_strtabs(fp);
26910 read_symtabs(fp);
26911 - read_relocs(fp);
26912 + read_relocs(fp, use_real_mode);
26913 if (show_absolute_syms) {
26914 print_absolute_symbols();
26915 return 0;
26916 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26917 index fd14be1..e3c79c0 100644
26918 --- a/arch/x86/vdso/Makefile
26919 +++ b/arch/x86/vdso/Makefile
26920 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26921 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26922 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26923
26924 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26925 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26926 GCOV_PROFILE := n
26927
26928 #
26929 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26930 index 66e6d93..587f435 100644
26931 --- a/arch/x86/vdso/vdso32-setup.c
26932 +++ b/arch/x86/vdso/vdso32-setup.c
26933 @@ -25,6 +25,7 @@
26934 #include <asm/tlbflush.h>
26935 #include <asm/vdso.h>
26936 #include <asm/proto.h>
26937 +#include <asm/mman.h>
26938
26939 enum {
26940 VDSO_DISABLED = 0,
26941 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26942 void enable_sep_cpu(void)
26943 {
26944 int cpu = get_cpu();
26945 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26946 + struct tss_struct *tss = init_tss + cpu;
26947
26948 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26949 put_cpu();
26950 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26951 gate_vma.vm_start = FIXADDR_USER_START;
26952 gate_vma.vm_end = FIXADDR_USER_END;
26953 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26954 - gate_vma.vm_page_prot = __P101;
26955 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26956
26957 return 0;
26958 }
26959 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26960 if (compat)
26961 addr = VDSO_HIGH_BASE;
26962 else {
26963 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26964 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26965 if (IS_ERR_VALUE(addr)) {
26966 ret = addr;
26967 goto up_fail;
26968 }
26969 }
26970
26971 - current->mm->context.vdso = (void *)addr;
26972 + current->mm->context.vdso = addr;
26973
26974 if (compat_uses_vma || !compat) {
26975 /*
26976 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26977 }
26978
26979 current_thread_info()->sysenter_return =
26980 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26981 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26982
26983 up_fail:
26984 if (ret)
26985 - current->mm->context.vdso = NULL;
26986 + current->mm->context.vdso = 0;
26987
26988 up_write(&mm->mmap_sem);
26989
26990 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26991
26992 const char *arch_vma_name(struct vm_area_struct *vma)
26993 {
26994 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26995 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26996 return "[vdso]";
26997 +
26998 +#ifdef CONFIG_PAX_SEGMEXEC
26999 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27000 + return "[vdso]";
27001 +#endif
27002 +
27003 return NULL;
27004 }
27005
27006 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27007 * Check to see if the corresponding task was created in compat vdso
27008 * mode.
27009 */
27010 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27011 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27012 return &gate_vma;
27013 return NULL;
27014 }
27015 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27016 index 00aaf04..4a26505 100644
27017 --- a/arch/x86/vdso/vma.c
27018 +++ b/arch/x86/vdso/vma.c
27019 @@ -16,8 +16,6 @@
27020 #include <asm/vdso.h>
27021 #include <asm/page.h>
27022
27023 -unsigned int __read_mostly vdso_enabled = 1;
27024 -
27025 extern char vdso_start[], vdso_end[];
27026 extern unsigned short vdso_sync_cpuid;
27027
27028 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27029 * unaligned here as a result of stack start randomization.
27030 */
27031 addr = PAGE_ALIGN(addr);
27032 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27033
27034 return addr;
27035 }
27036 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27037 unsigned size)
27038 {
27039 struct mm_struct *mm = current->mm;
27040 - unsigned long addr;
27041 + unsigned long addr = 0;
27042 int ret;
27043
27044 - if (!vdso_enabled)
27045 - return 0;
27046 -
27047 down_write(&mm->mmap_sem);
27048 +
27049 +#ifdef CONFIG_PAX_RANDMMAP
27050 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27051 +#endif
27052 +
27053 addr = vdso_addr(mm->start_stack, size);
27054 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27055 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27056 if (IS_ERR_VALUE(addr)) {
27057 ret = addr;
27058 goto up_fail;
27059 }
27060
27061 - current->mm->context.vdso = (void *)addr;
27062 + mm->context.vdso = addr;
27063
27064 ret = install_special_mapping(mm, addr, size,
27065 VM_READ|VM_EXEC|
27066 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27067 pages);
27068 - if (ret) {
27069 - current->mm->context.vdso = NULL;
27070 - goto up_fail;
27071 - }
27072 + if (ret)
27073 + mm->context.vdso = 0;
27074
27075 up_fail:
27076 up_write(&mm->mmap_sem);
27077 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27078 vdsox32_size);
27079 }
27080 #endif
27081 -
27082 -static __init int vdso_setup(char *s)
27083 -{
27084 - vdso_enabled = simple_strtoul(s, NULL, 0);
27085 - return 0;
27086 -}
27087 -__setup("vdso=", vdso_setup);
27088 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27089 index ff962d4..2bb5e83 100644
27090 --- a/arch/x86/xen/enlighten.c
27091 +++ b/arch/x86/xen/enlighten.c
27092 @@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27093
27094 struct shared_info xen_dummy_shared_info;
27095
27096 -void *xen_initial_gdt;
27097 -
27098 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27099 __read_mostly int xen_have_vector_callback;
27100 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27101 @@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27102 #endif
27103 };
27104
27105 -static void xen_reboot(int reason)
27106 +static __noreturn void xen_reboot(int reason)
27107 {
27108 struct sched_shutdown r = { .reason = reason };
27109
27110 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27111 - BUG();
27112 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27113 + BUG();
27114 }
27115
27116 -static void xen_restart(char *msg)
27117 +static __noreturn void xen_restart(char *msg)
27118 {
27119 xen_reboot(SHUTDOWN_reboot);
27120 }
27121
27122 -static void xen_emergency_restart(void)
27123 +static __noreturn void xen_emergency_restart(void)
27124 {
27125 xen_reboot(SHUTDOWN_reboot);
27126 }
27127
27128 -static void xen_machine_halt(void)
27129 +static __noreturn void xen_machine_halt(void)
27130 {
27131 xen_reboot(SHUTDOWN_poweroff);
27132 }
27133
27134 -static void xen_machine_power_off(void)
27135 +static __noreturn void xen_machine_power_off(void)
27136 {
27137 if (pm_power_off)
27138 pm_power_off();
27139 @@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27140 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27141
27142 /* Work out if we support NX */
27143 - x86_configure_nx();
27144 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27145 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27146 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27147 + unsigned l, h;
27148 +
27149 + __supported_pte_mask |= _PAGE_NX;
27150 + rdmsr(MSR_EFER, l, h);
27151 + l |= EFER_NX;
27152 + wrmsr(MSR_EFER, l, h);
27153 + }
27154 +#endif
27155
27156 xen_setup_features();
27157
27158 @@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27159
27160 machine_ops = xen_machine_ops;
27161
27162 - /*
27163 - * The only reliable way to retain the initial address of the
27164 - * percpu gdt_page is to remember it here, so we can go and
27165 - * mark it RW later, when the initial percpu area is freed.
27166 - */
27167 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27168 -
27169 xen_smp_init();
27170
27171 #ifdef CONFIG_ACPI_NUMA
27172 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27173 index 3a73785..0d30df2 100644
27174 --- a/arch/x86/xen/mmu.c
27175 +++ b/arch/x86/xen/mmu.c
27176 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27177 convert_pfn_mfn(init_level4_pgt);
27178 convert_pfn_mfn(level3_ident_pgt);
27179 convert_pfn_mfn(level3_kernel_pgt);
27180 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27181 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27182 + convert_pfn_mfn(level3_vmemmap_pgt);
27183
27184 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27185 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27186 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27187 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27188 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27189 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27190 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27191 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27192 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27193 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27194 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27195 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27196 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27197
27198 @@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27199 pv_mmu_ops.set_pud = xen_set_pud;
27200 #if PAGETABLE_LEVELS == 4
27201 pv_mmu_ops.set_pgd = xen_set_pgd;
27202 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27203 #endif
27204
27205 /* This will work as long as patching hasn't happened yet
27206 @@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27207 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27208 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27209 .set_pgd = xen_set_pgd_hyper,
27210 + .set_pgd_batched = xen_set_pgd_hyper,
27211
27212 .alloc_pud = xen_alloc_pmd_init,
27213 .release_pud = xen_release_pmd_init,
27214 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27215 index afb250d..627075f 100644
27216 --- a/arch/x86/xen/smp.c
27217 +++ b/arch/x86/xen/smp.c
27218 @@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27219 {
27220 BUG_ON(smp_processor_id() != 0);
27221 native_smp_prepare_boot_cpu();
27222 -
27223 - /* We've switched to the "real" per-cpu gdt, so make sure the
27224 - old memory can be recycled */
27225 - make_lowmem_page_readwrite(xen_initial_gdt);
27226 -
27227 xen_filter_cpu_maps();
27228 xen_setup_vcpu_info_placement();
27229 }
27230 @@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27231 gdt = get_cpu_gdt_table(cpu);
27232
27233 ctxt->flags = VGCF_IN_KERNEL;
27234 - ctxt->user_regs.ds = __USER_DS;
27235 - ctxt->user_regs.es = __USER_DS;
27236 + ctxt->user_regs.ds = __KERNEL_DS;
27237 + ctxt->user_regs.es = __KERNEL_DS;
27238 ctxt->user_regs.ss = __KERNEL_DS;
27239 #ifdef CONFIG_X86_32
27240 ctxt->user_regs.fs = __KERNEL_PERCPU;
27241 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27242 + savesegment(gs, ctxt->user_regs.gs);
27243 #else
27244 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27245 #endif
27246 @@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27247 int rc;
27248
27249 per_cpu(current_task, cpu) = idle;
27250 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27251 #ifdef CONFIG_X86_32
27252 irq_ctx_init(cpu);
27253 #else
27254 clear_tsk_thread_flag(idle, TIF_FORK);
27255 - per_cpu(kernel_stack, cpu) =
27256 - (unsigned long)task_stack_page(idle) -
27257 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27258 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27259 #endif
27260 xen_setup_runstate_info(cpu);
27261 xen_setup_timer(cpu);
27262 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27263 index f9643fc..602e8af 100644
27264 --- a/arch/x86/xen/xen-asm_32.S
27265 +++ b/arch/x86/xen/xen-asm_32.S
27266 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27267 ESP_OFFSET=4 # bytes pushed onto stack
27268
27269 /*
27270 - * Store vcpu_info pointer for easy access. Do it this way to
27271 - * avoid having to reload %fs
27272 + * Store vcpu_info pointer for easy access.
27273 */
27274 #ifdef CONFIG_SMP
27275 - GET_THREAD_INFO(%eax)
27276 - movl TI_cpu(%eax), %eax
27277 - movl __per_cpu_offset(,%eax,4), %eax
27278 - mov xen_vcpu(%eax), %eax
27279 + push %fs
27280 + mov $(__KERNEL_PERCPU), %eax
27281 + mov %eax, %fs
27282 + mov PER_CPU_VAR(xen_vcpu), %eax
27283 + pop %fs
27284 #else
27285 movl xen_vcpu, %eax
27286 #endif
27287 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27288 index aaa7291..3f77960 100644
27289 --- a/arch/x86/xen/xen-head.S
27290 +++ b/arch/x86/xen/xen-head.S
27291 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27292 #ifdef CONFIG_X86_32
27293 mov %esi,xen_start_info
27294 mov $init_thread_union+THREAD_SIZE,%esp
27295 +#ifdef CONFIG_SMP
27296 + movl $cpu_gdt_table,%edi
27297 + movl $__per_cpu_load,%eax
27298 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27299 + rorl $16,%eax
27300 + movb %al,__KERNEL_PERCPU + 4(%edi)
27301 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27302 + movl $__per_cpu_end - 1,%eax
27303 + subl $__per_cpu_start,%eax
27304 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27305 +#endif
27306 #else
27307 mov %rsi,xen_start_info
27308 mov $init_thread_union+THREAD_SIZE,%rsp
27309 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27310 index 202d4c1..99b072a 100644
27311 --- a/arch/x86/xen/xen-ops.h
27312 +++ b/arch/x86/xen/xen-ops.h
27313 @@ -10,8 +10,6 @@
27314 extern const char xen_hypervisor_callback[];
27315 extern const char xen_failsafe_callback[];
27316
27317 -extern void *xen_initial_gdt;
27318 -
27319 struct trap_info;
27320 void xen_copy_trap_info(struct trap_info *traps);
27321
27322 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27323 index 525bd3d..ef888b1 100644
27324 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27325 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27326 @@ -119,9 +119,9 @@
27327 ----------------------------------------------------------------------*/
27328
27329 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27330 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27331 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27332 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27333 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27334
27335 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27336 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27337 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27338 index 2f33760..835e50a 100644
27339 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27340 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27341 @@ -11,6 +11,7 @@
27342 #ifndef _XTENSA_CORE_H
27343 #define _XTENSA_CORE_H
27344
27345 +#include <linux/const.h>
27346
27347 /****************************************************************************
27348 Parameters Useful for Any Code, USER or PRIVILEGED
27349 @@ -112,9 +113,9 @@
27350 ----------------------------------------------------------------------*/
27351
27352 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27353 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27354 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27355 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27356 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27357
27358 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27359 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27360 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27361 index af00795..2bb8105 100644
27362 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27363 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27364 @@ -11,6 +11,7 @@
27365 #ifndef _XTENSA_CORE_CONFIGURATION_H
27366 #define _XTENSA_CORE_CONFIGURATION_H
27367
27368 +#include <linux/const.h>
27369
27370 /****************************************************************************
27371 Parameters Useful for Any Code, USER or PRIVILEGED
27372 @@ -118,9 +119,9 @@
27373 ----------------------------------------------------------------------*/
27374
27375 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27376 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27377 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27378 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27379 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27380
27381 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27382 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27383 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27384 index 58916af..9cb880b 100644
27385 --- a/block/blk-iopoll.c
27386 +++ b/block/blk-iopoll.c
27387 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27388 }
27389 EXPORT_SYMBOL(blk_iopoll_complete);
27390
27391 -static void blk_iopoll_softirq(struct softirq_action *h)
27392 +static void blk_iopoll_softirq(void)
27393 {
27394 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27395 int rearm = 0, budget = blk_iopoll_budget;
27396 diff --git a/block/blk-map.c b/block/blk-map.c
27397 index 623e1cd..ca1e109 100644
27398 --- a/block/blk-map.c
27399 +++ b/block/blk-map.c
27400 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27401 if (!len || !kbuf)
27402 return -EINVAL;
27403
27404 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27405 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27406 if (do_copy)
27407 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27408 else
27409 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27410 index 467c8de..4bddc6d 100644
27411 --- a/block/blk-softirq.c
27412 +++ b/block/blk-softirq.c
27413 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27414 * Softirq action handler - move entries to local list and loop over them
27415 * while passing them to the queue registered handler.
27416 */
27417 -static void blk_done_softirq(struct softirq_action *h)
27418 +static void blk_done_softirq(void)
27419 {
27420 struct list_head *cpu_list, local_list;
27421
27422 diff --git a/block/bsg.c b/block/bsg.c
27423 index ff64ae3..593560c 100644
27424 --- a/block/bsg.c
27425 +++ b/block/bsg.c
27426 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27427 struct sg_io_v4 *hdr, struct bsg_device *bd,
27428 fmode_t has_write_perm)
27429 {
27430 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27431 + unsigned char *cmdptr;
27432 +
27433 if (hdr->request_len > BLK_MAX_CDB) {
27434 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27435 if (!rq->cmd)
27436 return -ENOMEM;
27437 - }
27438 + cmdptr = rq->cmd;
27439 + } else
27440 + cmdptr = tmpcmd;
27441
27442 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27443 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27444 hdr->request_len))
27445 return -EFAULT;
27446
27447 + if (cmdptr != rq->cmd)
27448 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27449 +
27450 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27451 if (blk_verify_command(rq->cmd, has_write_perm))
27452 return -EPERM;
27453 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27454 index 7c668c8..db3521c 100644
27455 --- a/block/compat_ioctl.c
27456 +++ b/block/compat_ioctl.c
27457 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27458 err |= __get_user(f->spec1, &uf->spec1);
27459 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27460 err |= __get_user(name, &uf->name);
27461 - f->name = compat_ptr(name);
27462 + f->name = (void __force_kernel *)compat_ptr(name);
27463 if (err) {
27464 err = -EFAULT;
27465 goto out;
27466 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27467 index 6296b40..417c00f 100644
27468 --- a/block/partitions/efi.c
27469 +++ b/block/partitions/efi.c
27470 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27471 if (!gpt)
27472 return NULL;
27473
27474 + if (!le32_to_cpu(gpt->num_partition_entries))
27475 + return NULL;
27476 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27477 + if (!pte)
27478 + return NULL;
27479 +
27480 count = le32_to_cpu(gpt->num_partition_entries) *
27481 le32_to_cpu(gpt->sizeof_partition_entry);
27482 - if (!count)
27483 - return NULL;
27484 - pte = kzalloc(count, GFP_KERNEL);
27485 - if (!pte)
27486 - return NULL;
27487 -
27488 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27489 (u8 *) pte,
27490 count) < count) {
27491 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27492 index 9a87daa..fb17486 100644
27493 --- a/block/scsi_ioctl.c
27494 +++ b/block/scsi_ioctl.c
27495 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27496 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27497 struct sg_io_hdr *hdr, fmode_t mode)
27498 {
27499 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27500 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27501 + unsigned char *cmdptr;
27502 +
27503 + if (rq->cmd != rq->__cmd)
27504 + cmdptr = rq->cmd;
27505 + else
27506 + cmdptr = tmpcmd;
27507 +
27508 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27509 return -EFAULT;
27510 +
27511 + if (cmdptr != rq->cmd)
27512 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27513 +
27514 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27515 return -EPERM;
27516
27517 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27518 int err;
27519 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27520 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27521 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27522 + unsigned char *cmdptr;
27523
27524 if (!sic)
27525 return -EINVAL;
27526 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27527 */
27528 err = -EFAULT;
27529 rq->cmd_len = cmdlen;
27530 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27531 +
27532 + if (rq->cmd != rq->__cmd)
27533 + cmdptr = rq->cmd;
27534 + else
27535 + cmdptr = tmpcmd;
27536 +
27537 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27538 goto error;
27539
27540 + if (rq->cmd != cmdptr)
27541 + memcpy(rq->cmd, cmdptr, cmdlen);
27542 +
27543 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27544 goto error;
27545
27546 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27547 index 671d4d6..5f24030 100644
27548 --- a/crypto/cryptd.c
27549 +++ b/crypto/cryptd.c
27550 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27551
27552 struct cryptd_blkcipher_request_ctx {
27553 crypto_completion_t complete;
27554 -};
27555 +} __no_const;
27556
27557 struct cryptd_hash_ctx {
27558 struct crypto_shash *child;
27559 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27560
27561 struct cryptd_aead_request_ctx {
27562 crypto_completion_t complete;
27563 -};
27564 +} __no_const;
27565
27566 static void cryptd_queue_worker(struct work_struct *work);
27567
27568 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27569 index e6defd8..c26a225 100644
27570 --- a/drivers/acpi/apei/cper.c
27571 +++ b/drivers/acpi/apei/cper.c
27572 @@ -38,12 +38,12 @@
27573 */
27574 u64 cper_next_record_id(void)
27575 {
27576 - static atomic64_t seq;
27577 + static atomic64_unchecked_t seq;
27578
27579 - if (!atomic64_read(&seq))
27580 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27581 + if (!atomic64_read_unchecked(&seq))
27582 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27583
27584 - return atomic64_inc_return(&seq);
27585 + return atomic64_inc_return_unchecked(&seq);
27586 }
27587 EXPORT_SYMBOL_GPL(cper_next_record_id);
27588
27589 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27590 index 7586544..636a2f0 100644
27591 --- a/drivers/acpi/ec_sys.c
27592 +++ b/drivers/acpi/ec_sys.c
27593 @@ -12,6 +12,7 @@
27594 #include <linux/acpi.h>
27595 #include <linux/debugfs.h>
27596 #include <linux/module.h>
27597 +#include <linux/uaccess.h>
27598 #include "internal.h"
27599
27600 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27601 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27602 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27603 */
27604 unsigned int size = EC_SPACE_SIZE;
27605 - u8 *data = (u8 *) buf;
27606 + u8 data;
27607 loff_t init_off = *off;
27608 int err = 0;
27609
27610 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27611 size = count;
27612
27613 while (size) {
27614 - err = ec_read(*off, &data[*off - init_off]);
27615 + err = ec_read(*off, &data);
27616 if (err)
27617 return err;
27618 + if (put_user(data, &buf[*off - init_off]))
27619 + return -EFAULT;
27620 *off += 1;
27621 size--;
27622 }
27623 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27624
27625 unsigned int size = count;
27626 loff_t init_off = *off;
27627 - u8 *data = (u8 *) buf;
27628 int err = 0;
27629
27630 if (*off >= EC_SPACE_SIZE)
27631 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27632 }
27633
27634 while (size) {
27635 - u8 byte_write = data[*off - init_off];
27636 + u8 byte_write;
27637 + if (get_user(byte_write, &buf[*off - init_off]))
27638 + return -EFAULT;
27639 err = ec_write(*off, byte_write);
27640 if (err)
27641 return err;
27642 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27643 index 251c7b62..000462d 100644
27644 --- a/drivers/acpi/proc.c
27645 +++ b/drivers/acpi/proc.c
27646 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27647 size_t count, loff_t * ppos)
27648 {
27649 struct list_head *node, *next;
27650 - char strbuf[5];
27651 - char str[5] = "";
27652 - unsigned int len = count;
27653 + char strbuf[5] = {0};
27654
27655 - if (len > 4)
27656 - len = 4;
27657 - if (len < 0)
27658 + if (count > 4)
27659 + count = 4;
27660 + if (copy_from_user(strbuf, buffer, count))
27661 return -EFAULT;
27662 -
27663 - if (copy_from_user(strbuf, buffer, len))
27664 - return -EFAULT;
27665 - strbuf[len] = '\0';
27666 - sscanf(strbuf, "%s", str);
27667 + strbuf[count] = '\0';
27668
27669 mutex_lock(&acpi_device_lock);
27670 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27671 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27672 if (!dev->wakeup.flags.valid)
27673 continue;
27674
27675 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27676 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27677 if (device_can_wakeup(&dev->dev)) {
27678 bool enable = !device_may_wakeup(&dev->dev);
27679 device_set_wakeup_enable(&dev->dev, enable);
27680 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27681 index bbac51e..4c094f9 100644
27682 --- a/drivers/acpi/processor_driver.c
27683 +++ b/drivers/acpi/processor_driver.c
27684 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27685 return 0;
27686 #endif
27687
27688 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27689 + BUG_ON(pr->id >= nr_cpu_ids);
27690
27691 /*
27692 * Buggy BIOS check
27693 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27694 index cece3a4..0845256 100644
27695 --- a/drivers/ata/libata-core.c
27696 +++ b/drivers/ata/libata-core.c
27697 @@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27698 struct ata_port *ap;
27699 unsigned int tag;
27700
27701 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27702 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27703 ap = qc->ap;
27704
27705 qc->flags = 0;
27706 @@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27707 struct ata_port *ap;
27708 struct ata_link *link;
27709
27710 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27711 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27712 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27713 ap = qc->ap;
27714 link = qc->dev->link;
27715 @@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27716 return;
27717
27718 spin_lock(&lock);
27719 + pax_open_kernel();
27720
27721 for (cur = ops->inherits; cur; cur = cur->inherits) {
27722 void **inherit = (void **)cur;
27723 @@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27724 if (IS_ERR(*pp))
27725 *pp = NULL;
27726
27727 - ops->inherits = NULL;
27728 + *(struct ata_port_operations **)&ops->inherits = NULL;
27729
27730 + pax_close_kernel();
27731 spin_unlock(&lock);
27732 }
27733
27734 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27735 index ac6a5be..c7176b1 100644
27736 --- a/drivers/ata/pata_arasan_cf.c
27737 +++ b/drivers/ata/pata_arasan_cf.c
27738 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27739 /* Handle platform specific quirks */
27740 if (pdata->quirk) {
27741 if (pdata->quirk & CF_BROKEN_PIO) {
27742 - ap->ops->set_piomode = NULL;
27743 + pax_open_kernel();
27744 + *(void **)&ap->ops->set_piomode = NULL;
27745 + pax_close_kernel();
27746 ap->pio_mask = 0;
27747 }
27748 if (pdata->quirk & CF_BROKEN_MWDMA)
27749 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27750 index f9b983a..887b9d8 100644
27751 --- a/drivers/atm/adummy.c
27752 +++ b/drivers/atm/adummy.c
27753 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27754 vcc->pop(vcc, skb);
27755 else
27756 dev_kfree_skb_any(skb);
27757 - atomic_inc(&vcc->stats->tx);
27758 + atomic_inc_unchecked(&vcc->stats->tx);
27759
27760 return 0;
27761 }
27762 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27763 index 89b30f3..7964211 100644
27764 --- a/drivers/atm/ambassador.c
27765 +++ b/drivers/atm/ambassador.c
27766 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27767 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27768
27769 // VC layer stats
27770 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27771 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27772
27773 // free the descriptor
27774 kfree (tx_descr);
27775 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27776 dump_skb ("<<<", vc, skb);
27777
27778 // VC layer stats
27779 - atomic_inc(&atm_vcc->stats->rx);
27780 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27781 __net_timestamp(skb);
27782 // end of our responsibility
27783 atm_vcc->push (atm_vcc, skb);
27784 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27785 } else {
27786 PRINTK (KERN_INFO, "dropped over-size frame");
27787 // should we count this?
27788 - atomic_inc(&atm_vcc->stats->rx_drop);
27789 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27790 }
27791
27792 } else {
27793 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27794 }
27795
27796 if (check_area (skb->data, skb->len)) {
27797 - atomic_inc(&atm_vcc->stats->tx_err);
27798 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27799 return -ENOMEM; // ?
27800 }
27801
27802 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27803 index b22d71c..d6e1049 100644
27804 --- a/drivers/atm/atmtcp.c
27805 +++ b/drivers/atm/atmtcp.c
27806 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27807 if (vcc->pop) vcc->pop(vcc,skb);
27808 else dev_kfree_skb(skb);
27809 if (dev_data) return 0;
27810 - atomic_inc(&vcc->stats->tx_err);
27811 + atomic_inc_unchecked(&vcc->stats->tx_err);
27812 return -ENOLINK;
27813 }
27814 size = skb->len+sizeof(struct atmtcp_hdr);
27815 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27816 if (!new_skb) {
27817 if (vcc->pop) vcc->pop(vcc,skb);
27818 else dev_kfree_skb(skb);
27819 - atomic_inc(&vcc->stats->tx_err);
27820 + atomic_inc_unchecked(&vcc->stats->tx_err);
27821 return -ENOBUFS;
27822 }
27823 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27824 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27825 if (vcc->pop) vcc->pop(vcc,skb);
27826 else dev_kfree_skb(skb);
27827 out_vcc->push(out_vcc,new_skb);
27828 - atomic_inc(&vcc->stats->tx);
27829 - atomic_inc(&out_vcc->stats->rx);
27830 + atomic_inc_unchecked(&vcc->stats->tx);
27831 + atomic_inc_unchecked(&out_vcc->stats->rx);
27832 return 0;
27833 }
27834
27835 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27836 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27837 read_unlock(&vcc_sklist_lock);
27838 if (!out_vcc) {
27839 - atomic_inc(&vcc->stats->tx_err);
27840 + atomic_inc_unchecked(&vcc->stats->tx_err);
27841 goto done;
27842 }
27843 skb_pull(skb,sizeof(struct atmtcp_hdr));
27844 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27845 __net_timestamp(new_skb);
27846 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27847 out_vcc->push(out_vcc,new_skb);
27848 - atomic_inc(&vcc->stats->tx);
27849 - atomic_inc(&out_vcc->stats->rx);
27850 + atomic_inc_unchecked(&vcc->stats->tx);
27851 + atomic_inc_unchecked(&out_vcc->stats->rx);
27852 done:
27853 if (vcc->pop) vcc->pop(vcc,skb);
27854 else dev_kfree_skb(skb);
27855 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27856 index 2059ee4..faf51c7 100644
27857 --- a/drivers/atm/eni.c
27858 +++ b/drivers/atm/eni.c
27859 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27860 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27861 vcc->dev->number);
27862 length = 0;
27863 - atomic_inc(&vcc->stats->rx_err);
27864 + atomic_inc_unchecked(&vcc->stats->rx_err);
27865 }
27866 else {
27867 length = ATM_CELL_SIZE-1; /* no HEC */
27868 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27869 size);
27870 }
27871 eff = length = 0;
27872 - atomic_inc(&vcc->stats->rx_err);
27873 + atomic_inc_unchecked(&vcc->stats->rx_err);
27874 }
27875 else {
27876 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27877 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27878 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27879 vcc->dev->number,vcc->vci,length,size << 2,descr);
27880 length = eff = 0;
27881 - atomic_inc(&vcc->stats->rx_err);
27882 + atomic_inc_unchecked(&vcc->stats->rx_err);
27883 }
27884 }
27885 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27886 @@ -767,7 +767,7 @@ rx_dequeued++;
27887 vcc->push(vcc,skb);
27888 pushed++;
27889 }
27890 - atomic_inc(&vcc->stats->rx);
27891 + atomic_inc_unchecked(&vcc->stats->rx);
27892 }
27893 wake_up(&eni_dev->rx_wait);
27894 }
27895 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27896 PCI_DMA_TODEVICE);
27897 if (vcc->pop) vcc->pop(vcc,skb);
27898 else dev_kfree_skb_irq(skb);
27899 - atomic_inc(&vcc->stats->tx);
27900 + atomic_inc_unchecked(&vcc->stats->tx);
27901 wake_up(&eni_dev->tx_wait);
27902 dma_complete++;
27903 }
27904 @@ -1567,7 +1567,7 @@ tx_complete++;
27905 /*--------------------------------- entries ---------------------------------*/
27906
27907
27908 -static const char *media_name[] __devinitdata = {
27909 +static const char *media_name[] __devinitconst = {
27910 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27911 "UTP", "05?", "06?", "07?", /* 4- 7 */
27912 "TAXI","09?", "10?", "11?", /* 8-11 */
27913 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27914 index 86fed1b..6dc4721 100644
27915 --- a/drivers/atm/firestream.c
27916 +++ b/drivers/atm/firestream.c
27917 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27918 }
27919 }
27920
27921 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27922 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27923
27924 fs_dprintk (FS_DEBUG_TXMEM, "i");
27925 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27926 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27927 #endif
27928 skb_put (skb, qe->p1 & 0xffff);
27929 ATM_SKB(skb)->vcc = atm_vcc;
27930 - atomic_inc(&atm_vcc->stats->rx);
27931 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27932 __net_timestamp(skb);
27933 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27934 atm_vcc->push (atm_vcc, skb);
27935 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27936 kfree (pe);
27937 }
27938 if (atm_vcc)
27939 - atomic_inc(&atm_vcc->stats->rx_drop);
27940 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27941 break;
27942 case 0x1f: /* Reassembly abort: no buffers. */
27943 /* Silently increment error counter. */
27944 if (atm_vcc)
27945 - atomic_inc(&atm_vcc->stats->rx_drop);
27946 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27947 break;
27948 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27949 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27950 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27951 index 361f5ae..7fc552d 100644
27952 --- a/drivers/atm/fore200e.c
27953 +++ b/drivers/atm/fore200e.c
27954 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27955 #endif
27956 /* check error condition */
27957 if (*entry->status & STATUS_ERROR)
27958 - atomic_inc(&vcc->stats->tx_err);
27959 + atomic_inc_unchecked(&vcc->stats->tx_err);
27960 else
27961 - atomic_inc(&vcc->stats->tx);
27962 + atomic_inc_unchecked(&vcc->stats->tx);
27963 }
27964 }
27965
27966 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27967 if (skb == NULL) {
27968 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27969
27970 - atomic_inc(&vcc->stats->rx_drop);
27971 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27972 return -ENOMEM;
27973 }
27974
27975 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27976
27977 dev_kfree_skb_any(skb);
27978
27979 - atomic_inc(&vcc->stats->rx_drop);
27980 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27981 return -ENOMEM;
27982 }
27983
27984 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27985
27986 vcc->push(vcc, skb);
27987 - atomic_inc(&vcc->stats->rx);
27988 + atomic_inc_unchecked(&vcc->stats->rx);
27989
27990 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27991
27992 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27993 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27994 fore200e->atm_dev->number,
27995 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27996 - atomic_inc(&vcc->stats->rx_err);
27997 + atomic_inc_unchecked(&vcc->stats->rx_err);
27998 }
27999 }
28000
28001 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28002 goto retry_here;
28003 }
28004
28005 - atomic_inc(&vcc->stats->tx_err);
28006 + atomic_inc_unchecked(&vcc->stats->tx_err);
28007
28008 fore200e->tx_sat++;
28009 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28010 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28011 index b182c2f..1c6fa8a 100644
28012 --- a/drivers/atm/he.c
28013 +++ b/drivers/atm/he.c
28014 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28015
28016 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28017 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28018 - atomic_inc(&vcc->stats->rx_drop);
28019 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28020 goto return_host_buffers;
28021 }
28022
28023 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28024 RBRQ_LEN_ERR(he_dev->rbrq_head)
28025 ? "LEN_ERR" : "",
28026 vcc->vpi, vcc->vci);
28027 - atomic_inc(&vcc->stats->rx_err);
28028 + atomic_inc_unchecked(&vcc->stats->rx_err);
28029 goto return_host_buffers;
28030 }
28031
28032 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28033 vcc->push(vcc, skb);
28034 spin_lock(&he_dev->global_lock);
28035
28036 - atomic_inc(&vcc->stats->rx);
28037 + atomic_inc_unchecked(&vcc->stats->rx);
28038
28039 return_host_buffers:
28040 ++pdus_assembled;
28041 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28042 tpd->vcc->pop(tpd->vcc, tpd->skb);
28043 else
28044 dev_kfree_skb_any(tpd->skb);
28045 - atomic_inc(&tpd->vcc->stats->tx_err);
28046 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28047 }
28048 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28049 return;
28050 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28051 vcc->pop(vcc, skb);
28052 else
28053 dev_kfree_skb_any(skb);
28054 - atomic_inc(&vcc->stats->tx_err);
28055 + atomic_inc_unchecked(&vcc->stats->tx_err);
28056 return -EINVAL;
28057 }
28058
28059 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28060 vcc->pop(vcc, skb);
28061 else
28062 dev_kfree_skb_any(skb);
28063 - atomic_inc(&vcc->stats->tx_err);
28064 + atomic_inc_unchecked(&vcc->stats->tx_err);
28065 return -EINVAL;
28066 }
28067 #endif
28068 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28069 vcc->pop(vcc, skb);
28070 else
28071 dev_kfree_skb_any(skb);
28072 - atomic_inc(&vcc->stats->tx_err);
28073 + atomic_inc_unchecked(&vcc->stats->tx_err);
28074 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28075 return -ENOMEM;
28076 }
28077 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28078 vcc->pop(vcc, skb);
28079 else
28080 dev_kfree_skb_any(skb);
28081 - atomic_inc(&vcc->stats->tx_err);
28082 + atomic_inc_unchecked(&vcc->stats->tx_err);
28083 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28084 return -ENOMEM;
28085 }
28086 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28087 __enqueue_tpd(he_dev, tpd, cid);
28088 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28089
28090 - atomic_inc(&vcc->stats->tx);
28091 + atomic_inc_unchecked(&vcc->stats->tx);
28092
28093 return 0;
28094 }
28095 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28096 index 7d01c2a..4e3ac01 100644
28097 --- a/drivers/atm/horizon.c
28098 +++ b/drivers/atm/horizon.c
28099 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28100 {
28101 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28102 // VC layer stats
28103 - atomic_inc(&vcc->stats->rx);
28104 + atomic_inc_unchecked(&vcc->stats->rx);
28105 __net_timestamp(skb);
28106 // end of our responsibility
28107 vcc->push (vcc, skb);
28108 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28109 dev->tx_iovec = NULL;
28110
28111 // VC layer stats
28112 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28113 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28114
28115 // free the skb
28116 hrz_kfree_skb (skb);
28117 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28118 index 8974bd2..b856f85 100644
28119 --- a/drivers/atm/idt77252.c
28120 +++ b/drivers/atm/idt77252.c
28121 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28122 else
28123 dev_kfree_skb(skb);
28124
28125 - atomic_inc(&vcc->stats->tx);
28126 + atomic_inc_unchecked(&vcc->stats->tx);
28127 }
28128
28129 atomic_dec(&scq->used);
28130 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28131 if ((sb = dev_alloc_skb(64)) == NULL) {
28132 printk("%s: Can't allocate buffers for aal0.\n",
28133 card->name);
28134 - atomic_add(i, &vcc->stats->rx_drop);
28135 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28136 break;
28137 }
28138 if (!atm_charge(vcc, sb->truesize)) {
28139 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28140 card->name);
28141 - atomic_add(i - 1, &vcc->stats->rx_drop);
28142 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28143 dev_kfree_skb(sb);
28144 break;
28145 }
28146 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28147 ATM_SKB(sb)->vcc = vcc;
28148 __net_timestamp(sb);
28149 vcc->push(vcc, sb);
28150 - atomic_inc(&vcc->stats->rx);
28151 + atomic_inc_unchecked(&vcc->stats->rx);
28152
28153 cell += ATM_CELL_PAYLOAD;
28154 }
28155 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28156 "(CDC: %08x)\n",
28157 card->name, len, rpp->len, readl(SAR_REG_CDC));
28158 recycle_rx_pool_skb(card, rpp);
28159 - atomic_inc(&vcc->stats->rx_err);
28160 + atomic_inc_unchecked(&vcc->stats->rx_err);
28161 return;
28162 }
28163 if (stat & SAR_RSQE_CRC) {
28164 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28165 recycle_rx_pool_skb(card, rpp);
28166 - atomic_inc(&vcc->stats->rx_err);
28167 + atomic_inc_unchecked(&vcc->stats->rx_err);
28168 return;
28169 }
28170 if (skb_queue_len(&rpp->queue) > 1) {
28171 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28172 RXPRINTK("%s: Can't alloc RX skb.\n",
28173 card->name);
28174 recycle_rx_pool_skb(card, rpp);
28175 - atomic_inc(&vcc->stats->rx_err);
28176 + atomic_inc_unchecked(&vcc->stats->rx_err);
28177 return;
28178 }
28179 if (!atm_charge(vcc, skb->truesize)) {
28180 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28181 __net_timestamp(skb);
28182
28183 vcc->push(vcc, skb);
28184 - atomic_inc(&vcc->stats->rx);
28185 + atomic_inc_unchecked(&vcc->stats->rx);
28186
28187 return;
28188 }
28189 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28190 __net_timestamp(skb);
28191
28192 vcc->push(vcc, skb);
28193 - atomic_inc(&vcc->stats->rx);
28194 + atomic_inc_unchecked(&vcc->stats->rx);
28195
28196 if (skb->truesize > SAR_FB_SIZE_3)
28197 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28198 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28199 if (vcc->qos.aal != ATM_AAL0) {
28200 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28201 card->name, vpi, vci);
28202 - atomic_inc(&vcc->stats->rx_drop);
28203 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28204 goto drop;
28205 }
28206
28207 if ((sb = dev_alloc_skb(64)) == NULL) {
28208 printk("%s: Can't allocate buffers for AAL0.\n",
28209 card->name);
28210 - atomic_inc(&vcc->stats->rx_err);
28211 + atomic_inc_unchecked(&vcc->stats->rx_err);
28212 goto drop;
28213 }
28214
28215 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28216 ATM_SKB(sb)->vcc = vcc;
28217 __net_timestamp(sb);
28218 vcc->push(vcc, sb);
28219 - atomic_inc(&vcc->stats->rx);
28220 + atomic_inc_unchecked(&vcc->stats->rx);
28221
28222 drop:
28223 skb_pull(queue, 64);
28224 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28225
28226 if (vc == NULL) {
28227 printk("%s: NULL connection in send().\n", card->name);
28228 - atomic_inc(&vcc->stats->tx_err);
28229 + atomic_inc_unchecked(&vcc->stats->tx_err);
28230 dev_kfree_skb(skb);
28231 return -EINVAL;
28232 }
28233 if (!test_bit(VCF_TX, &vc->flags)) {
28234 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28235 - atomic_inc(&vcc->stats->tx_err);
28236 + atomic_inc_unchecked(&vcc->stats->tx_err);
28237 dev_kfree_skb(skb);
28238 return -EINVAL;
28239 }
28240 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28241 break;
28242 default:
28243 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28244 - atomic_inc(&vcc->stats->tx_err);
28245 + atomic_inc_unchecked(&vcc->stats->tx_err);
28246 dev_kfree_skb(skb);
28247 return -EINVAL;
28248 }
28249
28250 if (skb_shinfo(skb)->nr_frags != 0) {
28251 printk("%s: No scatter-gather yet.\n", card->name);
28252 - atomic_inc(&vcc->stats->tx_err);
28253 + atomic_inc_unchecked(&vcc->stats->tx_err);
28254 dev_kfree_skb(skb);
28255 return -EINVAL;
28256 }
28257 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28258
28259 err = queue_skb(card, vc, skb, oam);
28260 if (err) {
28261 - atomic_inc(&vcc->stats->tx_err);
28262 + atomic_inc_unchecked(&vcc->stats->tx_err);
28263 dev_kfree_skb(skb);
28264 return err;
28265 }
28266 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28267 skb = dev_alloc_skb(64);
28268 if (!skb) {
28269 printk("%s: Out of memory in send_oam().\n", card->name);
28270 - atomic_inc(&vcc->stats->tx_err);
28271 + atomic_inc_unchecked(&vcc->stats->tx_err);
28272 return -ENOMEM;
28273 }
28274 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28275 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28276 index d438601..8b98495 100644
28277 --- a/drivers/atm/iphase.c
28278 +++ b/drivers/atm/iphase.c
28279 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28280 status = (u_short) (buf_desc_ptr->desc_mode);
28281 if (status & (RX_CER | RX_PTE | RX_OFL))
28282 {
28283 - atomic_inc(&vcc->stats->rx_err);
28284 + atomic_inc_unchecked(&vcc->stats->rx_err);
28285 IF_ERR(printk("IA: bad packet, dropping it");)
28286 if (status & RX_CER) {
28287 IF_ERR(printk(" cause: packet CRC error\n");)
28288 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28289 len = dma_addr - buf_addr;
28290 if (len > iadev->rx_buf_sz) {
28291 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28292 - atomic_inc(&vcc->stats->rx_err);
28293 + atomic_inc_unchecked(&vcc->stats->rx_err);
28294 goto out_free_desc;
28295 }
28296
28297 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28298 ia_vcc = INPH_IA_VCC(vcc);
28299 if (ia_vcc == NULL)
28300 {
28301 - atomic_inc(&vcc->stats->rx_err);
28302 + atomic_inc_unchecked(&vcc->stats->rx_err);
28303 atm_return(vcc, skb->truesize);
28304 dev_kfree_skb_any(skb);
28305 goto INCR_DLE;
28306 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28307 if ((length > iadev->rx_buf_sz) || (length >
28308 (skb->len - sizeof(struct cpcs_trailer))))
28309 {
28310 - atomic_inc(&vcc->stats->rx_err);
28311 + atomic_inc_unchecked(&vcc->stats->rx_err);
28312 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28313 length, skb->len);)
28314 atm_return(vcc, skb->truesize);
28315 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28316
28317 IF_RX(printk("rx_dle_intr: skb push");)
28318 vcc->push(vcc,skb);
28319 - atomic_inc(&vcc->stats->rx);
28320 + atomic_inc_unchecked(&vcc->stats->rx);
28321 iadev->rx_pkt_cnt++;
28322 }
28323 INCR_DLE:
28324 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28325 {
28326 struct k_sonet_stats *stats;
28327 stats = &PRIV(_ia_dev[board])->sonet_stats;
28328 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28329 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28330 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28331 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28332 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28333 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28334 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28335 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28336 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28337 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28338 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28339 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28340 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28341 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28342 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28343 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28344 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28345 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28346 }
28347 ia_cmds.status = 0;
28348 break;
28349 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28350 if ((desc == 0) || (desc > iadev->num_tx_desc))
28351 {
28352 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28353 - atomic_inc(&vcc->stats->tx);
28354 + atomic_inc_unchecked(&vcc->stats->tx);
28355 if (vcc->pop)
28356 vcc->pop(vcc, skb);
28357 else
28358 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28359 ATM_DESC(skb) = vcc->vci;
28360 skb_queue_tail(&iadev->tx_dma_q, skb);
28361
28362 - atomic_inc(&vcc->stats->tx);
28363 + atomic_inc_unchecked(&vcc->stats->tx);
28364 iadev->tx_pkt_cnt++;
28365 /* Increment transaction counter */
28366 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28367
28368 #if 0
28369 /* add flow control logic */
28370 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28371 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28372 if (iavcc->vc_desc_cnt > 10) {
28373 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28374 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28375 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28376 index 68c7588..7036683 100644
28377 --- a/drivers/atm/lanai.c
28378 +++ b/drivers/atm/lanai.c
28379 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28380 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28381 lanai_endtx(lanai, lvcc);
28382 lanai_free_skb(lvcc->tx.atmvcc, skb);
28383 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28384 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28385 }
28386
28387 /* Try to fill the buffer - don't call unless there is backlog */
28388 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28389 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28390 __net_timestamp(skb);
28391 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28392 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28393 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28394 out:
28395 lvcc->rx.buf.ptr = end;
28396 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28397 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28398 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28399 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28400 lanai->stats.service_rxnotaal5++;
28401 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28402 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28403 return 0;
28404 }
28405 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28406 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28407 int bytes;
28408 read_unlock(&vcc_sklist_lock);
28409 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28410 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28411 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28412 lvcc->stats.x.aal5.service_trash++;
28413 bytes = (SERVICE_GET_END(s) * 16) -
28414 (((unsigned long) lvcc->rx.buf.ptr) -
28415 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28416 }
28417 if (s & SERVICE_STREAM) {
28418 read_unlock(&vcc_sklist_lock);
28419 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28420 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28421 lvcc->stats.x.aal5.service_stream++;
28422 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28423 "PDU on VCI %d!\n", lanai->number, vci);
28424 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28425 return 0;
28426 }
28427 DPRINTK("got rx crc error on vci %d\n", vci);
28428 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28429 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28430 lvcc->stats.x.aal5.service_rxcrc++;
28431 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28432 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28433 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28434 index 1c70c45..300718d 100644
28435 --- a/drivers/atm/nicstar.c
28436 +++ b/drivers/atm/nicstar.c
28437 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28438 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28439 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28440 card->index);
28441 - atomic_inc(&vcc->stats->tx_err);
28442 + atomic_inc_unchecked(&vcc->stats->tx_err);
28443 dev_kfree_skb_any(skb);
28444 return -EINVAL;
28445 }
28446 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28447 if (!vc->tx) {
28448 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28449 card->index);
28450 - atomic_inc(&vcc->stats->tx_err);
28451 + atomic_inc_unchecked(&vcc->stats->tx_err);
28452 dev_kfree_skb_any(skb);
28453 return -EINVAL;
28454 }
28455 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28456 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28457 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28458 card->index);
28459 - atomic_inc(&vcc->stats->tx_err);
28460 + atomic_inc_unchecked(&vcc->stats->tx_err);
28461 dev_kfree_skb_any(skb);
28462 return -EINVAL;
28463 }
28464
28465 if (skb_shinfo(skb)->nr_frags != 0) {
28466 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28467 - atomic_inc(&vcc->stats->tx_err);
28468 + atomic_inc_unchecked(&vcc->stats->tx_err);
28469 dev_kfree_skb_any(skb);
28470 return -EINVAL;
28471 }
28472 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28473 }
28474
28475 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28476 - atomic_inc(&vcc->stats->tx_err);
28477 + atomic_inc_unchecked(&vcc->stats->tx_err);
28478 dev_kfree_skb_any(skb);
28479 return -EIO;
28480 }
28481 - atomic_inc(&vcc->stats->tx);
28482 + atomic_inc_unchecked(&vcc->stats->tx);
28483
28484 return 0;
28485 }
28486 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28487 printk
28488 ("nicstar%d: Can't allocate buffers for aal0.\n",
28489 card->index);
28490 - atomic_add(i, &vcc->stats->rx_drop);
28491 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28492 break;
28493 }
28494 if (!atm_charge(vcc, sb->truesize)) {
28495 RXPRINTK
28496 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28497 card->index);
28498 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28499 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28500 dev_kfree_skb_any(sb);
28501 break;
28502 }
28503 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28504 ATM_SKB(sb)->vcc = vcc;
28505 __net_timestamp(sb);
28506 vcc->push(vcc, sb);
28507 - atomic_inc(&vcc->stats->rx);
28508 + atomic_inc_unchecked(&vcc->stats->rx);
28509 cell += ATM_CELL_PAYLOAD;
28510 }
28511
28512 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28513 if (iovb == NULL) {
28514 printk("nicstar%d: Out of iovec buffers.\n",
28515 card->index);
28516 - atomic_inc(&vcc->stats->rx_drop);
28517 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28518 recycle_rx_buf(card, skb);
28519 return;
28520 }
28521 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28522 small or large buffer itself. */
28523 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28524 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28525 - atomic_inc(&vcc->stats->rx_err);
28526 + atomic_inc_unchecked(&vcc->stats->rx_err);
28527 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28528 NS_MAX_IOVECS);
28529 NS_PRV_IOVCNT(iovb) = 0;
28530 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28531 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28532 card->index);
28533 which_list(card, skb);
28534 - atomic_inc(&vcc->stats->rx_err);
28535 + atomic_inc_unchecked(&vcc->stats->rx_err);
28536 recycle_rx_buf(card, skb);
28537 vc->rx_iov = NULL;
28538 recycle_iov_buf(card, iovb);
28539 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28540 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28541 card->index);
28542 which_list(card, skb);
28543 - atomic_inc(&vcc->stats->rx_err);
28544 + atomic_inc_unchecked(&vcc->stats->rx_err);
28545 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28546 NS_PRV_IOVCNT(iovb));
28547 vc->rx_iov = NULL;
28548 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28549 printk(" - PDU size mismatch.\n");
28550 else
28551 printk(".\n");
28552 - atomic_inc(&vcc->stats->rx_err);
28553 + atomic_inc_unchecked(&vcc->stats->rx_err);
28554 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28555 NS_PRV_IOVCNT(iovb));
28556 vc->rx_iov = NULL;
28557 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28558 /* skb points to a small buffer */
28559 if (!atm_charge(vcc, skb->truesize)) {
28560 push_rxbufs(card, skb);
28561 - atomic_inc(&vcc->stats->rx_drop);
28562 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28563 } else {
28564 skb_put(skb, len);
28565 dequeue_sm_buf(card, skb);
28566 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28567 ATM_SKB(skb)->vcc = vcc;
28568 __net_timestamp(skb);
28569 vcc->push(vcc, skb);
28570 - atomic_inc(&vcc->stats->rx);
28571 + atomic_inc_unchecked(&vcc->stats->rx);
28572 }
28573 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28574 struct sk_buff *sb;
28575 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28576 if (len <= NS_SMBUFSIZE) {
28577 if (!atm_charge(vcc, sb->truesize)) {
28578 push_rxbufs(card, sb);
28579 - atomic_inc(&vcc->stats->rx_drop);
28580 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28581 } else {
28582 skb_put(sb, len);
28583 dequeue_sm_buf(card, sb);
28584 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28585 ATM_SKB(sb)->vcc = vcc;
28586 __net_timestamp(sb);
28587 vcc->push(vcc, sb);
28588 - atomic_inc(&vcc->stats->rx);
28589 + atomic_inc_unchecked(&vcc->stats->rx);
28590 }
28591
28592 push_rxbufs(card, skb);
28593 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28594
28595 if (!atm_charge(vcc, skb->truesize)) {
28596 push_rxbufs(card, skb);
28597 - atomic_inc(&vcc->stats->rx_drop);
28598 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28599 } else {
28600 dequeue_lg_buf(card, skb);
28601 #ifdef NS_USE_DESTRUCTORS
28602 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28603 ATM_SKB(skb)->vcc = vcc;
28604 __net_timestamp(skb);
28605 vcc->push(vcc, skb);
28606 - atomic_inc(&vcc->stats->rx);
28607 + atomic_inc_unchecked(&vcc->stats->rx);
28608 }
28609
28610 push_rxbufs(card, sb);
28611 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28612 printk
28613 ("nicstar%d: Out of huge buffers.\n",
28614 card->index);
28615 - atomic_inc(&vcc->stats->rx_drop);
28616 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28617 recycle_iovec_rx_bufs(card,
28618 (struct iovec *)
28619 iovb->data,
28620 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28621 card->hbpool.count++;
28622 } else
28623 dev_kfree_skb_any(hb);
28624 - atomic_inc(&vcc->stats->rx_drop);
28625 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28626 } else {
28627 /* Copy the small buffer to the huge buffer */
28628 sb = (struct sk_buff *)iov->iov_base;
28629 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28630 #endif /* NS_USE_DESTRUCTORS */
28631 __net_timestamp(hb);
28632 vcc->push(vcc, hb);
28633 - atomic_inc(&vcc->stats->rx);
28634 + atomic_inc_unchecked(&vcc->stats->rx);
28635 }
28636 }
28637
28638 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28639 index 9851093..adb2b1e 100644
28640 --- a/drivers/atm/solos-pci.c
28641 +++ b/drivers/atm/solos-pci.c
28642 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28643 }
28644 atm_charge(vcc, skb->truesize);
28645 vcc->push(vcc, skb);
28646 - atomic_inc(&vcc->stats->rx);
28647 + atomic_inc_unchecked(&vcc->stats->rx);
28648 break;
28649
28650 case PKT_STATUS:
28651 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28652 vcc = SKB_CB(oldskb)->vcc;
28653
28654 if (vcc) {
28655 - atomic_inc(&vcc->stats->tx);
28656 + atomic_inc_unchecked(&vcc->stats->tx);
28657 solos_pop(vcc, oldskb);
28658 } else
28659 dev_kfree_skb_irq(oldskb);
28660 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28661 index 0215934..ce9f5b1 100644
28662 --- a/drivers/atm/suni.c
28663 +++ b/drivers/atm/suni.c
28664 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28665
28666
28667 #define ADD_LIMITED(s,v) \
28668 - atomic_add((v),&stats->s); \
28669 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28670 + atomic_add_unchecked((v),&stats->s); \
28671 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28672
28673
28674 static void suni_hz(unsigned long from_timer)
28675 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28676 index 5120a96..e2572bd 100644
28677 --- a/drivers/atm/uPD98402.c
28678 +++ b/drivers/atm/uPD98402.c
28679 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28680 struct sonet_stats tmp;
28681 int error = 0;
28682
28683 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28684 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28685 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28686 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28687 if (zero && !error) {
28688 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28689
28690
28691 #define ADD_LIMITED(s,v) \
28692 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28693 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28694 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28695 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28696 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28697 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28698
28699
28700 static void stat_event(struct atm_dev *dev)
28701 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28702 if (reason & uPD98402_INT_PFM) stat_event(dev);
28703 if (reason & uPD98402_INT_PCO) {
28704 (void) GET(PCOCR); /* clear interrupt cause */
28705 - atomic_add(GET(HECCT),
28706 + atomic_add_unchecked(GET(HECCT),
28707 &PRIV(dev)->sonet_stats.uncorr_hcs);
28708 }
28709 if ((reason & uPD98402_INT_RFO) &&
28710 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28711 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28712 uPD98402_INT_LOS),PIMR); /* enable them */
28713 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28714 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28715 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28716 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28717 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28718 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28719 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28720 return 0;
28721 }
28722
28723 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28724 index abe4e20..83c4727 100644
28725 --- a/drivers/atm/zatm.c
28726 +++ b/drivers/atm/zatm.c
28727 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28728 }
28729 if (!size) {
28730 dev_kfree_skb_irq(skb);
28731 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28732 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28733 continue;
28734 }
28735 if (!atm_charge(vcc,skb->truesize)) {
28736 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28737 skb->len = size;
28738 ATM_SKB(skb)->vcc = vcc;
28739 vcc->push(vcc,skb);
28740 - atomic_inc(&vcc->stats->rx);
28741 + atomic_inc_unchecked(&vcc->stats->rx);
28742 }
28743 zout(pos & 0xffff,MTA(mbx));
28744 #if 0 /* probably a stupid idea */
28745 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28746 skb_queue_head(&zatm_vcc->backlog,skb);
28747 break;
28748 }
28749 - atomic_inc(&vcc->stats->tx);
28750 + atomic_inc_unchecked(&vcc->stats->tx);
28751 wake_up(&zatm_vcc->tx_wait);
28752 }
28753
28754 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28755 index 765c3a2..771ace6 100644
28756 --- a/drivers/base/devtmpfs.c
28757 +++ b/drivers/base/devtmpfs.c
28758 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28759 if (!thread)
28760 return 0;
28761
28762 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28763 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28764 if (err)
28765 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28766 else
28767 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28768 index cbb463b..babe2cf 100644
28769 --- a/drivers/base/power/wakeup.c
28770 +++ b/drivers/base/power/wakeup.c
28771 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28772 * They need to be modified together atomically, so it's better to use one
28773 * atomic variable to hold them both.
28774 */
28775 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28776 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28777
28778 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28779 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28780
28781 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28782 {
28783 - unsigned int comb = atomic_read(&combined_event_count);
28784 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28785
28786 *cnt = (comb >> IN_PROGRESS_BITS);
28787 *inpr = comb & MAX_IN_PROGRESS;
28788 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28789 ws->start_prevent_time = ws->last_time;
28790
28791 /* Increment the counter of events in progress. */
28792 - cec = atomic_inc_return(&combined_event_count);
28793 + cec = atomic_inc_return_unchecked(&combined_event_count);
28794
28795 trace_wakeup_source_activate(ws->name, cec);
28796 }
28797 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28798 * Increment the counter of registered wakeup events and decrement the
28799 * couter of wakeup events in progress simultaneously.
28800 */
28801 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28802 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28803 trace_wakeup_source_deactivate(ws->name, cec);
28804
28805 split_counters(&cnt, &inpr);
28806 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28807 index b0f553b..77b928b 100644
28808 --- a/drivers/block/cciss.c
28809 +++ b/drivers/block/cciss.c
28810 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28811 int err;
28812 u32 cp;
28813
28814 + memset(&arg64, 0, sizeof(arg64));
28815 +
28816 err = 0;
28817 err |=
28818 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28819 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28820 while (!list_empty(&h->reqQ)) {
28821 c = list_entry(h->reqQ.next, CommandList_struct, list);
28822 /* can't do anything if fifo is full */
28823 - if ((h->access.fifo_full(h))) {
28824 + if ((h->access->fifo_full(h))) {
28825 dev_warn(&h->pdev->dev, "fifo full\n");
28826 break;
28827 }
28828 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28829 h->Qdepth--;
28830
28831 /* Tell the controller execute command */
28832 - h->access.submit_command(h, c);
28833 + h->access->submit_command(h, c);
28834
28835 /* Put job onto the completed Q */
28836 addQ(&h->cmpQ, c);
28837 @@ -3443,17 +3445,17 @@ startio:
28838
28839 static inline unsigned long get_next_completion(ctlr_info_t *h)
28840 {
28841 - return h->access.command_completed(h);
28842 + return h->access->command_completed(h);
28843 }
28844
28845 static inline int interrupt_pending(ctlr_info_t *h)
28846 {
28847 - return h->access.intr_pending(h);
28848 + return h->access->intr_pending(h);
28849 }
28850
28851 static inline long interrupt_not_for_us(ctlr_info_t *h)
28852 {
28853 - return ((h->access.intr_pending(h) == 0) ||
28854 + return ((h->access->intr_pending(h) == 0) ||
28855 (h->interrupts_enabled == 0));
28856 }
28857
28858 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28859 u32 a;
28860
28861 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28862 - return h->access.command_completed(h);
28863 + return h->access->command_completed(h);
28864
28865 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28866 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28867 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28868 trans_support & CFGTBL_Trans_use_short_tags);
28869
28870 /* Change the access methods to the performant access methods */
28871 - h->access = SA5_performant_access;
28872 + h->access = &SA5_performant_access;
28873 h->transMethod = CFGTBL_Trans_Performant;
28874
28875 return;
28876 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28877 if (prod_index < 0)
28878 return -ENODEV;
28879 h->product_name = products[prod_index].product_name;
28880 - h->access = *(products[prod_index].access);
28881 + h->access = products[prod_index].access;
28882
28883 if (cciss_board_disabled(h)) {
28884 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28885 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28886 }
28887
28888 /* make sure the board interrupts are off */
28889 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28890 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28891 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28892 if (rc)
28893 goto clean2;
28894 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28895 * fake ones to scoop up any residual completions.
28896 */
28897 spin_lock_irqsave(&h->lock, flags);
28898 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28899 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28900 spin_unlock_irqrestore(&h->lock, flags);
28901 free_irq(h->intr[h->intr_mode], h);
28902 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28903 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28904 dev_info(&h->pdev->dev, "Board READY.\n");
28905 dev_info(&h->pdev->dev,
28906 "Waiting for stale completions to drain.\n");
28907 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28908 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28909 msleep(10000);
28910 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28911 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28912
28913 rc = controller_reset_failed(h->cfgtable);
28914 if (rc)
28915 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28916 cciss_scsi_setup(h);
28917
28918 /* Turn the interrupts on so we can service requests */
28919 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28920 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28921
28922 /* Get the firmware version */
28923 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28924 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28925 kfree(flush_buf);
28926 if (return_code != IO_OK)
28927 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28928 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28929 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28930 free_irq(h->intr[h->intr_mode], h);
28931 }
28932
28933 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28934 index 7fda30e..eb5dfe0 100644
28935 --- a/drivers/block/cciss.h
28936 +++ b/drivers/block/cciss.h
28937 @@ -101,7 +101,7 @@ struct ctlr_info
28938 /* information about each logical volume */
28939 drive_info_struct *drv[CISS_MAX_LUN];
28940
28941 - struct access_method access;
28942 + struct access_method *access;
28943
28944 /* queue and queue Info */
28945 struct list_head reqQ;
28946 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28947 index 9125bbe..eede5c8 100644
28948 --- a/drivers/block/cpqarray.c
28949 +++ b/drivers/block/cpqarray.c
28950 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28951 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28952 goto Enomem4;
28953 }
28954 - hba[i]->access.set_intr_mask(hba[i], 0);
28955 + hba[i]->access->set_intr_mask(hba[i], 0);
28956 if (request_irq(hba[i]->intr, do_ida_intr,
28957 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28958 {
28959 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28960 add_timer(&hba[i]->timer);
28961
28962 /* Enable IRQ now that spinlock and rate limit timer are set up */
28963 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28964 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28965
28966 for(j=0; j<NWD; j++) {
28967 struct gendisk *disk = ida_gendisk[i][j];
28968 @@ -694,7 +694,7 @@ DBGINFO(
28969 for(i=0; i<NR_PRODUCTS; i++) {
28970 if (board_id == products[i].board_id) {
28971 c->product_name = products[i].product_name;
28972 - c->access = *(products[i].access);
28973 + c->access = products[i].access;
28974 break;
28975 }
28976 }
28977 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28978 hba[ctlr]->intr = intr;
28979 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28980 hba[ctlr]->product_name = products[j].product_name;
28981 - hba[ctlr]->access = *(products[j].access);
28982 + hba[ctlr]->access = products[j].access;
28983 hba[ctlr]->ctlr = ctlr;
28984 hba[ctlr]->board_id = board_id;
28985 hba[ctlr]->pci_dev = NULL; /* not PCI */
28986 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28987
28988 while((c = h->reqQ) != NULL) {
28989 /* Can't do anything if we're busy */
28990 - if (h->access.fifo_full(h) == 0)
28991 + if (h->access->fifo_full(h) == 0)
28992 return;
28993
28994 /* Get the first entry from the request Q */
28995 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28996 h->Qdepth--;
28997
28998 /* Tell the controller to do our bidding */
28999 - h->access.submit_command(h, c);
29000 + h->access->submit_command(h, c);
29001
29002 /* Get onto the completion Q */
29003 addQ(&h->cmpQ, c);
29004 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29005 unsigned long flags;
29006 __u32 a,a1;
29007
29008 - istat = h->access.intr_pending(h);
29009 + istat = h->access->intr_pending(h);
29010 /* Is this interrupt for us? */
29011 if (istat == 0)
29012 return IRQ_NONE;
29013 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29014 */
29015 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29016 if (istat & FIFO_NOT_EMPTY) {
29017 - while((a = h->access.command_completed(h))) {
29018 + while((a = h->access->command_completed(h))) {
29019 a1 = a; a &= ~3;
29020 if ((c = h->cmpQ) == NULL)
29021 {
29022 @@ -1449,11 +1449,11 @@ static int sendcmd(
29023 /*
29024 * Disable interrupt
29025 */
29026 - info_p->access.set_intr_mask(info_p, 0);
29027 + info_p->access->set_intr_mask(info_p, 0);
29028 /* Make sure there is room in the command FIFO */
29029 /* Actually it should be completely empty at this time. */
29030 for (i = 200000; i > 0; i--) {
29031 - temp = info_p->access.fifo_full(info_p);
29032 + temp = info_p->access->fifo_full(info_p);
29033 if (temp != 0) {
29034 break;
29035 }
29036 @@ -1466,7 +1466,7 @@ DBG(
29037 /*
29038 * Send the cmd
29039 */
29040 - info_p->access.submit_command(info_p, c);
29041 + info_p->access->submit_command(info_p, c);
29042 complete = pollcomplete(ctlr);
29043
29044 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29045 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29046 * we check the new geometry. Then turn interrupts back on when
29047 * we're done.
29048 */
29049 - host->access.set_intr_mask(host, 0);
29050 + host->access->set_intr_mask(host, 0);
29051 getgeometry(ctlr);
29052 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29053 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29054
29055 for(i=0; i<NWD; i++) {
29056 struct gendisk *disk = ida_gendisk[ctlr][i];
29057 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29058 /* Wait (up to 2 seconds) for a command to complete */
29059
29060 for (i = 200000; i > 0; i--) {
29061 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29062 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29063 if (done == 0) {
29064 udelay(10); /* a short fixed delay */
29065 } else
29066 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29067 index be73e9d..7fbf140 100644
29068 --- a/drivers/block/cpqarray.h
29069 +++ b/drivers/block/cpqarray.h
29070 @@ -99,7 +99,7 @@ struct ctlr_info {
29071 drv_info_t drv[NWD];
29072 struct proc_dir_entry *proc;
29073
29074 - struct access_method access;
29075 + struct access_method *access;
29076
29077 cmdlist_t *reqQ;
29078 cmdlist_t *cmpQ;
29079 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29080 index 02f013a..afeba24 100644
29081 --- a/drivers/block/drbd/drbd_int.h
29082 +++ b/drivers/block/drbd/drbd_int.h
29083 @@ -735,7 +735,7 @@ struct drbd_request;
29084 struct drbd_epoch {
29085 struct list_head list;
29086 unsigned int barrier_nr;
29087 - atomic_t epoch_size; /* increased on every request added. */
29088 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29089 atomic_t active; /* increased on every req. added, and dec on every finished. */
29090 unsigned long flags;
29091 };
29092 @@ -1110,7 +1110,7 @@ struct drbd_conf {
29093 void *int_dig_in;
29094 void *int_dig_vv;
29095 wait_queue_head_t seq_wait;
29096 - atomic_t packet_seq;
29097 + atomic_unchecked_t packet_seq;
29098 unsigned int peer_seq;
29099 spinlock_t peer_seq_lock;
29100 unsigned int minor;
29101 @@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29102
29103 static inline void drbd_tcp_cork(struct socket *sock)
29104 {
29105 - int __user val = 1;
29106 + int val = 1;
29107 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29108 - (char __user *)&val, sizeof(val));
29109 + (char __force_user *)&val, sizeof(val));
29110 }
29111
29112 static inline void drbd_tcp_uncork(struct socket *sock)
29113 {
29114 - int __user val = 0;
29115 + int val = 0;
29116 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29117 - (char __user *)&val, sizeof(val));
29118 + (char __force_user *)&val, sizeof(val));
29119 }
29120
29121 static inline void drbd_tcp_nodelay(struct socket *sock)
29122 {
29123 - int __user val = 1;
29124 + int val = 1;
29125 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29126 - (char __user *)&val, sizeof(val));
29127 + (char __force_user *)&val, sizeof(val));
29128 }
29129
29130 static inline void drbd_tcp_quickack(struct socket *sock)
29131 {
29132 - int __user val = 2;
29133 + int val = 2;
29134 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29135 - (char __user *)&val, sizeof(val));
29136 + (char __force_user *)&val, sizeof(val));
29137 }
29138
29139 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29140 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29141 index 920ede2..cb827ba 100644
29142 --- a/drivers/block/drbd/drbd_main.c
29143 +++ b/drivers/block/drbd/drbd_main.c
29144 @@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29145 p.sector = sector;
29146 p.block_id = block_id;
29147 p.blksize = blksize;
29148 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29149 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29150
29151 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29152 return false;
29153 @@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29154
29155 p.sector = cpu_to_be64(req->sector);
29156 p.block_id = (unsigned long)req;
29157 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29158 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29159
29160 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29161
29162 @@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29163 atomic_set(&mdev->unacked_cnt, 0);
29164 atomic_set(&mdev->local_cnt, 0);
29165 atomic_set(&mdev->net_cnt, 0);
29166 - atomic_set(&mdev->packet_seq, 0);
29167 + atomic_set_unchecked(&mdev->packet_seq, 0);
29168 atomic_set(&mdev->pp_in_use, 0);
29169 atomic_set(&mdev->pp_in_use_by_net, 0);
29170 atomic_set(&mdev->rs_sect_in, 0);
29171 @@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29172 mdev->receiver.t_state);
29173
29174 /* no need to lock it, I'm the only thread alive */
29175 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29176 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29177 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29178 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29179 mdev->al_writ_cnt =
29180 mdev->bm_writ_cnt =
29181 mdev->read_cnt =
29182 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29183 index 6d4de6a..7b7ad4b 100644
29184 --- a/drivers/block/drbd/drbd_nl.c
29185 +++ b/drivers/block/drbd/drbd_nl.c
29186 @@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29187 module_put(THIS_MODULE);
29188 }
29189
29190 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29191 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29192
29193 static unsigned short *
29194 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29195 @@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29196 cn_reply->id.idx = CN_IDX_DRBD;
29197 cn_reply->id.val = CN_VAL_DRBD;
29198
29199 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29200 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29201 cn_reply->ack = 0; /* not used here. */
29202 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29203 (int)((char *)tl - (char *)reply->tag_list);
29204 @@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29205 cn_reply->id.idx = CN_IDX_DRBD;
29206 cn_reply->id.val = CN_VAL_DRBD;
29207
29208 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29209 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29210 cn_reply->ack = 0; /* not used here. */
29211 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29212 (int)((char *)tl - (char *)reply->tag_list);
29213 @@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29214 cn_reply->id.idx = CN_IDX_DRBD;
29215 cn_reply->id.val = CN_VAL_DRBD;
29216
29217 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29218 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29219 cn_reply->ack = 0; // not used here.
29220 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29221 (int)((char*)tl - (char*)reply->tag_list);
29222 @@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29223 cn_reply->id.idx = CN_IDX_DRBD;
29224 cn_reply->id.val = CN_VAL_DRBD;
29225
29226 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29227 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29228 cn_reply->ack = 0; /* not used here. */
29229 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29230 (int)((char *)tl - (char *)reply->tag_list);
29231 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29232 index ea4836e..272d72a 100644
29233 --- a/drivers/block/drbd/drbd_receiver.c
29234 +++ b/drivers/block/drbd/drbd_receiver.c
29235 @@ -893,7 +893,7 @@ retry:
29236 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29237 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29238
29239 - atomic_set(&mdev->packet_seq, 0);
29240 + atomic_set_unchecked(&mdev->packet_seq, 0);
29241 mdev->peer_seq = 0;
29242
29243 if (drbd_send_protocol(mdev) == -1)
29244 @@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29245 do {
29246 next_epoch = NULL;
29247
29248 - epoch_size = atomic_read(&epoch->epoch_size);
29249 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29250
29251 switch (ev & ~EV_CLEANUP) {
29252 case EV_PUT:
29253 @@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29254 rv = FE_DESTROYED;
29255 } else {
29256 epoch->flags = 0;
29257 - atomic_set(&epoch->epoch_size, 0);
29258 + atomic_set_unchecked(&epoch->epoch_size, 0);
29259 /* atomic_set(&epoch->active, 0); is already zero */
29260 if (rv == FE_STILL_LIVE)
29261 rv = FE_RECYCLED;
29262 @@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29263 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29264 drbd_flush(mdev);
29265
29266 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29267 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29268 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29269 if (epoch)
29270 break;
29271 }
29272
29273 epoch = mdev->current_epoch;
29274 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29275 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29276
29277 D_ASSERT(atomic_read(&epoch->active) == 0);
29278 D_ASSERT(epoch->flags == 0);
29279 @@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29280 }
29281
29282 epoch->flags = 0;
29283 - atomic_set(&epoch->epoch_size, 0);
29284 + atomic_set_unchecked(&epoch->epoch_size, 0);
29285 atomic_set(&epoch->active, 0);
29286
29287 spin_lock(&mdev->epoch_lock);
29288 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29289 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29290 list_add(&epoch->list, &mdev->current_epoch->list);
29291 mdev->current_epoch = epoch;
29292 mdev->epochs++;
29293 @@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29294 spin_unlock(&mdev->peer_seq_lock);
29295
29296 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29297 - atomic_inc(&mdev->current_epoch->epoch_size);
29298 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29299 return drbd_drain_block(mdev, data_size);
29300 }
29301
29302 @@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29303
29304 spin_lock(&mdev->epoch_lock);
29305 e->epoch = mdev->current_epoch;
29306 - atomic_inc(&e->epoch->epoch_size);
29307 + atomic_inc_unchecked(&e->epoch->epoch_size);
29308 atomic_inc(&e->epoch->active);
29309 spin_unlock(&mdev->epoch_lock);
29310
29311 @@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29312 D_ASSERT(list_empty(&mdev->done_ee));
29313
29314 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29315 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29316 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29317 D_ASSERT(list_empty(&mdev->current_epoch->list));
29318 }
29319
29320 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29321 index 3bba655..6151b66 100644
29322 --- a/drivers/block/loop.c
29323 +++ b/drivers/block/loop.c
29324 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29325 mm_segment_t old_fs = get_fs();
29326
29327 set_fs(get_ds());
29328 - bw = file->f_op->write(file, buf, len, &pos);
29329 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29330 set_fs(old_fs);
29331 if (likely(bw == len))
29332 return 0;
29333 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29334 index ea6f632..eafb192 100644
29335 --- a/drivers/char/Kconfig
29336 +++ b/drivers/char/Kconfig
29337 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29338
29339 config DEVKMEM
29340 bool "/dev/kmem virtual device support"
29341 - default y
29342 + default n
29343 + depends on !GRKERNSEC_KMEM
29344 help
29345 Say Y here if you want to support the /dev/kmem device. The
29346 /dev/kmem device is rarely used, but can be used for certain
29347 @@ -581,6 +582,7 @@ config DEVPORT
29348 bool
29349 depends on !M68K
29350 depends on ISA || PCI
29351 + depends on !GRKERNSEC_KMEM
29352 default y
29353
29354 source "drivers/s390/char/Kconfig"
29355 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29356 index 2e04433..22afc64 100644
29357 --- a/drivers/char/agp/frontend.c
29358 +++ b/drivers/char/agp/frontend.c
29359 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29360 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29361 return -EFAULT;
29362
29363 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29364 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29365 return -EFAULT;
29366
29367 client = agp_find_client_by_pid(reserve.pid);
29368 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29369 index 21cb980..f15107c 100644
29370 --- a/drivers/char/genrtc.c
29371 +++ b/drivers/char/genrtc.c
29372 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29373 switch (cmd) {
29374
29375 case RTC_PLL_GET:
29376 + memset(&pll, 0, sizeof(pll));
29377 if (get_rtc_pll(&pll))
29378 return -EINVAL;
29379 else
29380 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29381 index dfd7876..c0b0885 100644
29382 --- a/drivers/char/hpet.c
29383 +++ b/drivers/char/hpet.c
29384 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29385 }
29386
29387 static int
29388 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29389 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29390 struct hpet_info *info)
29391 {
29392 struct hpet_timer __iomem *timer;
29393 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29394 index 2c29942..604c5ba 100644
29395 --- a/drivers/char/ipmi/ipmi_msghandler.c
29396 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29397 @@ -420,7 +420,7 @@ struct ipmi_smi {
29398 struct proc_dir_entry *proc_dir;
29399 char proc_dir_name[10];
29400
29401 - atomic_t stats[IPMI_NUM_STATS];
29402 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29403
29404 /*
29405 * run_to_completion duplicate of smb_info, smi_info
29406 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29407
29408
29409 #define ipmi_inc_stat(intf, stat) \
29410 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29411 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29412 #define ipmi_get_stat(intf, stat) \
29413 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29414 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29415
29416 static int is_lan_addr(struct ipmi_addr *addr)
29417 {
29418 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29419 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29420 init_waitqueue_head(&intf->waitq);
29421 for (i = 0; i < IPMI_NUM_STATS; i++)
29422 - atomic_set(&intf->stats[i], 0);
29423 + atomic_set_unchecked(&intf->stats[i], 0);
29424
29425 intf->proc_dir = NULL;
29426
29427 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29428 index 1e638ff..a869ef5 100644
29429 --- a/drivers/char/ipmi/ipmi_si_intf.c
29430 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29431 @@ -275,7 +275,7 @@ struct smi_info {
29432 unsigned char slave_addr;
29433
29434 /* Counters and things for the proc filesystem. */
29435 - atomic_t stats[SI_NUM_STATS];
29436 + atomic_unchecked_t stats[SI_NUM_STATS];
29437
29438 struct task_struct *thread;
29439
29440 @@ -284,9 +284,9 @@ struct smi_info {
29441 };
29442
29443 #define smi_inc_stat(smi, stat) \
29444 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29445 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29446 #define smi_get_stat(smi, stat) \
29447 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29448 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29449
29450 #define SI_MAX_PARMS 4
29451
29452 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29453 atomic_set(&new_smi->req_events, 0);
29454 new_smi->run_to_completion = 0;
29455 for (i = 0; i < SI_NUM_STATS; i++)
29456 - atomic_set(&new_smi->stats[i], 0);
29457 + atomic_set_unchecked(&new_smi->stats[i], 0);
29458
29459 new_smi->interrupt_disabled = 1;
29460 atomic_set(&new_smi->stop_operation, 0);
29461 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29462 index 47ff7e4..0c7d340 100644
29463 --- a/drivers/char/mbcs.c
29464 +++ b/drivers/char/mbcs.c
29465 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29466 return 0;
29467 }
29468
29469 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29470 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29471 {
29472 .part_num = MBCS_PART_NUM,
29473 .mfg_num = MBCS_MFG_NUM,
29474 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29475 index 67c3371..ba8429d 100644
29476 --- a/drivers/char/mem.c
29477 +++ b/drivers/char/mem.c
29478 @@ -18,6 +18,7 @@
29479 #include <linux/raw.h>
29480 #include <linux/tty.h>
29481 #include <linux/capability.h>
29482 +#include <linux/security.h>
29483 #include <linux/ptrace.h>
29484 #include <linux/device.h>
29485 #include <linux/highmem.h>
29486 @@ -35,6 +36,10 @@
29487 # include <linux/efi.h>
29488 #endif
29489
29490 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29491 +extern const struct file_operations grsec_fops;
29492 +#endif
29493 +
29494 static inline unsigned long size_inside_page(unsigned long start,
29495 unsigned long size)
29496 {
29497 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29498
29499 while (cursor < to) {
29500 if (!devmem_is_allowed(pfn)) {
29501 +#ifdef CONFIG_GRKERNSEC_KMEM
29502 + gr_handle_mem_readwrite(from, to);
29503 +#else
29504 printk(KERN_INFO
29505 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29506 current->comm, from, to);
29507 +#endif
29508 return 0;
29509 }
29510 cursor += PAGE_SIZE;
29511 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29512 }
29513 return 1;
29514 }
29515 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29516 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29517 +{
29518 + return 0;
29519 +}
29520 #else
29521 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29522 {
29523 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29524
29525 while (count > 0) {
29526 unsigned long remaining;
29527 + char *temp;
29528
29529 sz = size_inside_page(p, count);
29530
29531 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29532 if (!ptr)
29533 return -EFAULT;
29534
29535 - remaining = copy_to_user(buf, ptr, sz);
29536 +#ifdef CONFIG_PAX_USERCOPY
29537 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29538 + if (!temp) {
29539 + unxlate_dev_mem_ptr(p, ptr);
29540 + return -ENOMEM;
29541 + }
29542 + memcpy(temp, ptr, sz);
29543 +#else
29544 + temp = ptr;
29545 +#endif
29546 +
29547 + remaining = copy_to_user(buf, temp, sz);
29548 +
29549 +#ifdef CONFIG_PAX_USERCOPY
29550 + kfree(temp);
29551 +#endif
29552 +
29553 unxlate_dev_mem_ptr(p, ptr);
29554 if (remaining)
29555 return -EFAULT;
29556 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29557 size_t count, loff_t *ppos)
29558 {
29559 unsigned long p = *ppos;
29560 - ssize_t low_count, read, sz;
29561 + ssize_t low_count, read, sz, err = 0;
29562 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29563 - int err = 0;
29564
29565 read = 0;
29566 if (p < (unsigned long) high_memory) {
29567 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29568 }
29569 #endif
29570 while (low_count > 0) {
29571 + char *temp;
29572 +
29573 sz = size_inside_page(p, low_count);
29574
29575 /*
29576 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29577 */
29578 kbuf = xlate_dev_kmem_ptr((char *)p);
29579
29580 - if (copy_to_user(buf, kbuf, sz))
29581 +#ifdef CONFIG_PAX_USERCOPY
29582 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29583 + if (!temp)
29584 + return -ENOMEM;
29585 + memcpy(temp, kbuf, sz);
29586 +#else
29587 + temp = kbuf;
29588 +#endif
29589 +
29590 + err = copy_to_user(buf, temp, sz);
29591 +
29592 +#ifdef CONFIG_PAX_USERCOPY
29593 + kfree(temp);
29594 +#endif
29595 +
29596 + if (err)
29597 return -EFAULT;
29598 buf += sz;
29599 p += sz;
29600 @@ -831,6 +878,9 @@ static const struct memdev {
29601 #ifdef CONFIG_CRASH_DUMP
29602 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29603 #endif
29604 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29605 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29606 +#endif
29607 };
29608
29609 static int memory_open(struct inode *inode, struct file *filp)
29610 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29611 index 9df78e2..01ba9ae 100644
29612 --- a/drivers/char/nvram.c
29613 +++ b/drivers/char/nvram.c
29614 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29615
29616 spin_unlock_irq(&rtc_lock);
29617
29618 - if (copy_to_user(buf, contents, tmp - contents))
29619 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29620 return -EFAULT;
29621
29622 *ppos = i;
29623 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29624 index 0a484b4..f48ccd1 100644
29625 --- a/drivers/char/pcmcia/synclink_cs.c
29626 +++ b/drivers/char/pcmcia/synclink_cs.c
29627 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29628
29629 if (debug_level >= DEBUG_LEVEL_INFO)
29630 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29631 - __FILE__,__LINE__, info->device_name, port->count);
29632 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29633
29634 - WARN_ON(!port->count);
29635 + WARN_ON(!atomic_read(&port->count));
29636
29637 if (tty_port_close_start(port, tty, filp) == 0)
29638 goto cleanup;
29639 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29640 cleanup:
29641 if (debug_level >= DEBUG_LEVEL_INFO)
29642 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29643 - tty->driver->name, port->count);
29644 + tty->driver->name, atomic_read(&port->count));
29645 }
29646
29647 /* Wait until the transmitter is empty.
29648 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29649
29650 if (debug_level >= DEBUG_LEVEL_INFO)
29651 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29652 - __FILE__,__LINE__,tty->driver->name, port->count);
29653 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29654
29655 /* If port is closing, signal caller to try again */
29656 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29657 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29658 goto cleanup;
29659 }
29660 spin_lock(&port->lock);
29661 - port->count++;
29662 + atomic_inc(&port->count);
29663 spin_unlock(&port->lock);
29664 spin_unlock_irqrestore(&info->netlock, flags);
29665
29666 - if (port->count == 1) {
29667 + if (atomic_read(&port->count) == 1) {
29668 /* 1st open on this device, init hardware */
29669 retval = startup(info, tty);
29670 if (retval < 0)
29671 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29672 unsigned short new_crctype;
29673
29674 /* return error if TTY interface open */
29675 - if (info->port.count)
29676 + if (atomic_read(&info->port.count))
29677 return -EBUSY;
29678
29679 switch (encoding)
29680 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29681
29682 /* arbitrate between network and tty opens */
29683 spin_lock_irqsave(&info->netlock, flags);
29684 - if (info->port.count != 0 || info->netcount != 0) {
29685 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29686 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29687 spin_unlock_irqrestore(&info->netlock, flags);
29688 return -EBUSY;
29689 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29690 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29691
29692 /* return error if TTY interface open */
29693 - if (info->port.count)
29694 + if (atomic_read(&info->port.count))
29695 return -EBUSY;
29696
29697 if (cmd != SIOCWANDEV)
29698 diff --git a/drivers/char/random.c b/drivers/char/random.c
29699 index d98b2a6..f0ceb97 100644
29700 --- a/drivers/char/random.c
29701 +++ b/drivers/char/random.c
29702 @@ -272,8 +272,13 @@
29703 /*
29704 * Configuration information
29705 */
29706 +#ifdef CONFIG_GRKERNSEC_RANDNET
29707 +#define INPUT_POOL_WORDS 512
29708 +#define OUTPUT_POOL_WORDS 128
29709 +#else
29710 #define INPUT_POOL_WORDS 128
29711 #define OUTPUT_POOL_WORDS 32
29712 +#endif
29713 #define SEC_XFER_SIZE 512
29714 #define EXTRACT_SIZE 10
29715
29716 @@ -313,10 +318,17 @@ static struct poolinfo {
29717 int poolwords;
29718 int tap1, tap2, tap3, tap4, tap5;
29719 } poolinfo_table[] = {
29720 +#ifdef CONFIG_GRKERNSEC_RANDNET
29721 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29722 + { 512, 411, 308, 208, 104, 1 },
29723 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29724 + { 128, 103, 76, 51, 25, 1 },
29725 +#else
29726 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29727 { 128, 103, 76, 51, 25, 1 },
29728 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29729 { 32, 26, 20, 14, 7, 1 },
29730 +#endif
29731 #if 0
29732 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29733 { 2048, 1638, 1231, 819, 411, 1 },
29734 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29735 input_rotate += i ? 7 : 14;
29736 }
29737
29738 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29739 - ACCESS_ONCE(r->add_ptr) = i;
29740 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29741 + ACCESS_ONCE_RW(r->add_ptr) = i;
29742 smp_wmb();
29743
29744 if (out)
29745 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29746 }
29747 #endif
29748
29749 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29750 +u64 latent_entropy;
29751 +
29752 +__init void transfer_latent_entropy(void)
29753 +{
29754 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29755 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29756 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29757 +}
29758 +#endif
29759 +
29760 /*********************************************************************
29761 *
29762 * Entropy extraction routines
29763 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29764
29765 extract_buf(r, tmp);
29766 i = min_t(int, nbytes, EXTRACT_SIZE);
29767 - if (copy_to_user(buf, tmp, i)) {
29768 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29769 ret = -EFAULT;
29770 break;
29771 }
29772 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29773 #include <linux/sysctl.h>
29774
29775 static int min_read_thresh = 8, min_write_thresh;
29776 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29777 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29778 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29779 static char sysctl_bootid[16];
29780
29781 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29782 index 45713f0..8286d21 100644
29783 --- a/drivers/char/sonypi.c
29784 +++ b/drivers/char/sonypi.c
29785 @@ -54,6 +54,7 @@
29786
29787 #include <asm/uaccess.h>
29788 #include <asm/io.h>
29789 +#include <asm/local.h>
29790
29791 #include <linux/sonypi.h>
29792
29793 @@ -490,7 +491,7 @@ static struct sonypi_device {
29794 spinlock_t fifo_lock;
29795 wait_queue_head_t fifo_proc_list;
29796 struct fasync_struct *fifo_async;
29797 - int open_count;
29798 + local_t open_count;
29799 int model;
29800 struct input_dev *input_jog_dev;
29801 struct input_dev *input_key_dev;
29802 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29803 static int sonypi_misc_release(struct inode *inode, struct file *file)
29804 {
29805 mutex_lock(&sonypi_device.lock);
29806 - sonypi_device.open_count--;
29807 + local_dec(&sonypi_device.open_count);
29808 mutex_unlock(&sonypi_device.lock);
29809 return 0;
29810 }
29811 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29812 {
29813 mutex_lock(&sonypi_device.lock);
29814 /* Flush input queue on first open */
29815 - if (!sonypi_device.open_count)
29816 + if (!local_read(&sonypi_device.open_count))
29817 kfifo_reset(&sonypi_device.fifo);
29818 - sonypi_device.open_count++;
29819 + local_inc(&sonypi_device.open_count);
29820 mutex_unlock(&sonypi_device.lock);
29821
29822 return 0;
29823 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29824 index 08427ab..1ab10b7 100644
29825 --- a/drivers/char/tpm/tpm.c
29826 +++ b/drivers/char/tpm/tpm.c
29827 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29828 chip->vendor.req_complete_val)
29829 goto out_recv;
29830
29831 - if ((status == chip->vendor.req_canceled)) {
29832 + if (status == chip->vendor.req_canceled) {
29833 dev_err(chip->dev, "Operation Canceled\n");
29834 rc = -ECANCELED;
29835 goto out;
29836 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29837 index 0636520..169c1d0 100644
29838 --- a/drivers/char/tpm/tpm_bios.c
29839 +++ b/drivers/char/tpm/tpm_bios.c
29840 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29841 event = addr;
29842
29843 if ((event->event_type == 0 && event->event_size == 0) ||
29844 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29845 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29846 return NULL;
29847
29848 return addr;
29849 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29850 return NULL;
29851
29852 if ((event->event_type == 0 && event->event_size == 0) ||
29853 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29854 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29855 return NULL;
29856
29857 (*pos)++;
29858 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29859 int i;
29860
29861 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29862 - seq_putc(m, data[i]);
29863 + if (!seq_putc(m, data[i]))
29864 + return -EFAULT;
29865
29866 return 0;
29867 }
29868 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29869 log->bios_event_log_end = log->bios_event_log + len;
29870
29871 virt = acpi_os_map_memory(start, len);
29872 + if (!virt) {
29873 + kfree(log->bios_event_log);
29874 + log->bios_event_log = NULL;
29875 + return -EFAULT;
29876 + }
29877
29878 - memcpy(log->bios_event_log, virt, len);
29879 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29880
29881 acpi_os_unmap_memory(virt, len);
29882 return 0;
29883 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29884 index cdf2f54..e55c197 100644
29885 --- a/drivers/char/virtio_console.c
29886 +++ b/drivers/char/virtio_console.c
29887 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29888 if (to_user) {
29889 ssize_t ret;
29890
29891 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29892 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29893 if (ret)
29894 return -EFAULT;
29895 } else {
29896 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29897 if (!port_has_data(port) && !port->host_connected)
29898 return 0;
29899
29900 - return fill_readbuf(port, ubuf, count, true);
29901 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29902 }
29903
29904 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29905 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29906 index 97f5064..202b6e6 100644
29907 --- a/drivers/edac/edac_pci_sysfs.c
29908 +++ b/drivers/edac/edac_pci_sysfs.c
29909 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29910 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29911 static int edac_pci_poll_msec = 1000; /* one second workq period */
29912
29913 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29914 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29915 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29916 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29917
29918 static struct kobject *edac_pci_top_main_kobj;
29919 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29920 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29921 edac_printk(KERN_CRIT, EDAC_PCI,
29922 "Signaled System Error on %s\n",
29923 pci_name(dev));
29924 - atomic_inc(&pci_nonparity_count);
29925 + atomic_inc_unchecked(&pci_nonparity_count);
29926 }
29927
29928 if (status & (PCI_STATUS_PARITY)) {
29929 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29930 "Master Data Parity Error on %s\n",
29931 pci_name(dev));
29932
29933 - atomic_inc(&pci_parity_count);
29934 + atomic_inc_unchecked(&pci_parity_count);
29935 }
29936
29937 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29938 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29939 "Detected Parity Error on %s\n",
29940 pci_name(dev));
29941
29942 - atomic_inc(&pci_parity_count);
29943 + atomic_inc_unchecked(&pci_parity_count);
29944 }
29945 }
29946
29947 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29948 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29949 "Signaled System Error on %s\n",
29950 pci_name(dev));
29951 - atomic_inc(&pci_nonparity_count);
29952 + atomic_inc_unchecked(&pci_nonparity_count);
29953 }
29954
29955 if (status & (PCI_STATUS_PARITY)) {
29956 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29957 "Master Data Parity Error on "
29958 "%s\n", pci_name(dev));
29959
29960 - atomic_inc(&pci_parity_count);
29961 + atomic_inc_unchecked(&pci_parity_count);
29962 }
29963
29964 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29965 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29966 "Detected Parity Error on %s\n",
29967 pci_name(dev));
29968
29969 - atomic_inc(&pci_parity_count);
29970 + atomic_inc_unchecked(&pci_parity_count);
29971 }
29972 }
29973 }
29974 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29975 if (!check_pci_errors)
29976 return;
29977
29978 - before_count = atomic_read(&pci_parity_count);
29979 + before_count = atomic_read_unchecked(&pci_parity_count);
29980
29981 /* scan all PCI devices looking for a Parity Error on devices and
29982 * bridges.
29983 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29984 /* Only if operator has selected panic on PCI Error */
29985 if (edac_pci_get_panic_on_pe()) {
29986 /* If the count is different 'after' from 'before' */
29987 - if (before_count != atomic_read(&pci_parity_count))
29988 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29989 panic("EDAC: PCI Parity Error");
29990 }
29991 }
29992 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29993 index 8c87a5e..a19cbd7 100644
29994 --- a/drivers/edac/mce_amd.h
29995 +++ b/drivers/edac/mce_amd.h
29996 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29997 struct amd_decoder_ops {
29998 bool (*dc_mce)(u16, u8);
29999 bool (*ic_mce)(u16, u8);
30000 -};
30001 +} __no_const;
30002
30003 void amd_report_gart_errors(bool);
30004 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30005 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30006 index 57ea7f4..789e3c3 100644
30007 --- a/drivers/firewire/core-card.c
30008 +++ b/drivers/firewire/core-card.c
30009 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30010
30011 void fw_core_remove_card(struct fw_card *card)
30012 {
30013 - struct fw_card_driver dummy_driver = dummy_driver_template;
30014 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30015
30016 card->driver->update_phy_reg(card, 4,
30017 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30018 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30019 index 2783f69..9f4b0cc 100644
30020 --- a/drivers/firewire/core-cdev.c
30021 +++ b/drivers/firewire/core-cdev.c
30022 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30023 int ret;
30024
30025 if ((request->channels == 0 && request->bandwidth == 0) ||
30026 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30027 - request->bandwidth < 0)
30028 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30029 return -EINVAL;
30030
30031 r = kmalloc(sizeof(*r), GFP_KERNEL);
30032 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30033 index 780708d..ad60a66 100644
30034 --- a/drivers/firewire/core-transaction.c
30035 +++ b/drivers/firewire/core-transaction.c
30036 @@ -37,6 +37,7 @@
30037 #include <linux/timer.h>
30038 #include <linux/types.h>
30039 #include <linux/workqueue.h>
30040 +#include <linux/sched.h>
30041
30042 #include <asm/byteorder.h>
30043
30044 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30045 index 515a42c..5ecf3ba 100644
30046 --- a/drivers/firewire/core.h
30047 +++ b/drivers/firewire/core.h
30048 @@ -111,6 +111,7 @@ struct fw_card_driver {
30049
30050 int (*stop_iso)(struct fw_iso_context *ctx);
30051 };
30052 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30053
30054 void fw_card_initialize(struct fw_card *card,
30055 const struct fw_card_driver *driver, struct device *device);
30056 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30057 index b298158..7ed8432 100644
30058 --- a/drivers/firmware/dmi_scan.c
30059 +++ b/drivers/firmware/dmi_scan.c
30060 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30061 }
30062 }
30063 else {
30064 - /*
30065 - * no iounmap() for that ioremap(); it would be a no-op, but
30066 - * it's so early in setup that sucker gets confused into doing
30067 - * what it shouldn't if we actually call it.
30068 - */
30069 p = dmi_ioremap(0xF0000, 0x10000);
30070 if (p == NULL)
30071 goto error;
30072 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30073 if (buf == NULL)
30074 return -1;
30075
30076 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30077 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30078
30079 iounmap(buf);
30080 return 0;
30081 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30082 index 82d5c20..44a7177 100644
30083 --- a/drivers/gpio/gpio-vr41xx.c
30084 +++ b/drivers/gpio/gpio-vr41xx.c
30085 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30086 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30087 maskl, pendl, maskh, pendh);
30088
30089 - atomic_inc(&irq_err_count);
30090 + atomic_inc_unchecked(&irq_err_count);
30091
30092 return -EINVAL;
30093 }
30094 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30095 index 3252e70..b5314ace 100644
30096 --- a/drivers/gpu/drm/drm_crtc_helper.c
30097 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30098 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30099 struct drm_crtc *tmp;
30100 int crtc_mask = 1;
30101
30102 - WARN(!crtc, "checking null crtc?\n");
30103 + BUG_ON(!crtc);
30104
30105 dev = crtc->dev;
30106
30107 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30108 index 8a9d079..606cdd5 100644
30109 --- a/drivers/gpu/drm/drm_drv.c
30110 +++ b/drivers/gpu/drm/drm_drv.c
30111 @@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30112 /**
30113 * Copy and IOCTL return string to user space
30114 */
30115 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30116 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30117 {
30118 int len;
30119
30120 @@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30121 return -ENODEV;
30122
30123 atomic_inc(&dev->ioctl_count);
30124 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30125 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30126 ++file_priv->ioctl_count;
30127
30128 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30129 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30130 index 123de28..43a0897 100644
30131 --- a/drivers/gpu/drm/drm_fops.c
30132 +++ b/drivers/gpu/drm/drm_fops.c
30133 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30134 }
30135
30136 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30137 - atomic_set(&dev->counts[i], 0);
30138 + atomic_set_unchecked(&dev->counts[i], 0);
30139
30140 dev->sigdata.lock = NULL;
30141
30142 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30143
30144 retcode = drm_open_helper(inode, filp, dev);
30145 if (!retcode) {
30146 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30147 - if (!dev->open_count++)
30148 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30149 + if (local_inc_return(&dev->open_count) == 1)
30150 retcode = drm_setup(dev);
30151 }
30152 if (!retcode) {
30153 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30154
30155 mutex_lock(&drm_global_mutex);
30156
30157 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30158 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30159
30160 if (dev->driver->preclose)
30161 dev->driver->preclose(dev, file_priv);
30162 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30163 * Begin inline drm_release
30164 */
30165
30166 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30167 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30168 task_pid_nr(current),
30169 (long)old_encode_dev(file_priv->minor->device),
30170 - dev->open_count);
30171 + local_read(&dev->open_count));
30172
30173 /* Release any auth tokens that might point to this file_priv,
30174 (do that under the drm_global_mutex) */
30175 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30176 * End inline drm_release
30177 */
30178
30179 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30180 - if (!--dev->open_count) {
30181 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30182 + if (local_dec_and_test(&dev->open_count)) {
30183 if (atomic_read(&dev->ioctl_count)) {
30184 DRM_ERROR("Device busy: %d\n",
30185 atomic_read(&dev->ioctl_count));
30186 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30187 index c87dc96..326055d 100644
30188 --- a/drivers/gpu/drm/drm_global.c
30189 +++ b/drivers/gpu/drm/drm_global.c
30190 @@ -36,7 +36,7 @@
30191 struct drm_global_item {
30192 struct mutex mutex;
30193 void *object;
30194 - int refcount;
30195 + atomic_t refcount;
30196 };
30197
30198 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30199 @@ -49,7 +49,7 @@ void drm_global_init(void)
30200 struct drm_global_item *item = &glob[i];
30201 mutex_init(&item->mutex);
30202 item->object = NULL;
30203 - item->refcount = 0;
30204 + atomic_set(&item->refcount, 0);
30205 }
30206 }
30207
30208 @@ -59,7 +59,7 @@ void drm_global_release(void)
30209 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30210 struct drm_global_item *item = &glob[i];
30211 BUG_ON(item->object != NULL);
30212 - BUG_ON(item->refcount != 0);
30213 + BUG_ON(atomic_read(&item->refcount) != 0);
30214 }
30215 }
30216
30217 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30218 void *object;
30219
30220 mutex_lock(&item->mutex);
30221 - if (item->refcount == 0) {
30222 + if (atomic_read(&item->refcount) == 0) {
30223 item->object = kzalloc(ref->size, GFP_KERNEL);
30224 if (unlikely(item->object == NULL)) {
30225 ret = -ENOMEM;
30226 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30227 goto out_err;
30228
30229 }
30230 - ++item->refcount;
30231 + atomic_inc(&item->refcount);
30232 ref->object = item->object;
30233 object = item->object;
30234 mutex_unlock(&item->mutex);
30235 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30236 struct drm_global_item *item = &glob[ref->global_type];
30237
30238 mutex_lock(&item->mutex);
30239 - BUG_ON(item->refcount == 0);
30240 + BUG_ON(atomic_read(&item->refcount) == 0);
30241 BUG_ON(ref->object != item->object);
30242 - if (--item->refcount == 0) {
30243 + if (atomic_dec_and_test(&item->refcount)) {
30244 ref->release(ref);
30245 item->object = NULL;
30246 }
30247 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30248 index ab1162d..42587b2 100644
30249 --- a/drivers/gpu/drm/drm_info.c
30250 +++ b/drivers/gpu/drm/drm_info.c
30251 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30252 struct drm_local_map *map;
30253 struct drm_map_list *r_list;
30254
30255 - /* Hardcoded from _DRM_FRAME_BUFFER,
30256 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30257 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30258 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30259 + static const char * const types[] = {
30260 + [_DRM_FRAME_BUFFER] = "FB",
30261 + [_DRM_REGISTERS] = "REG",
30262 + [_DRM_SHM] = "SHM",
30263 + [_DRM_AGP] = "AGP",
30264 + [_DRM_SCATTER_GATHER] = "SG",
30265 + [_DRM_CONSISTENT] = "PCI",
30266 + [_DRM_GEM] = "GEM" };
30267 const char *type;
30268 int i;
30269
30270 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30271 map = r_list->map;
30272 if (!map)
30273 continue;
30274 - if (map->type < 0 || map->type > 5)
30275 + if (map->type >= ARRAY_SIZE(types))
30276 type = "??";
30277 else
30278 type = types[map->type];
30279 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30280 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30281 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30282 vma->vm_flags & VM_IO ? 'i' : '-',
30283 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30284 + 0);
30285 +#else
30286 vma->vm_pgoff);
30287 +#endif
30288
30289 #if defined(__i386__)
30290 pgprot = pgprot_val(vma->vm_page_prot);
30291 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30292 index 637fcc3..e890b33 100644
30293 --- a/drivers/gpu/drm/drm_ioc32.c
30294 +++ b/drivers/gpu/drm/drm_ioc32.c
30295 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30296 request = compat_alloc_user_space(nbytes);
30297 if (!access_ok(VERIFY_WRITE, request, nbytes))
30298 return -EFAULT;
30299 - list = (struct drm_buf_desc *) (request + 1);
30300 + list = (struct drm_buf_desc __user *) (request + 1);
30301
30302 if (__put_user(count, &request->count)
30303 || __put_user(list, &request->list))
30304 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30305 request = compat_alloc_user_space(nbytes);
30306 if (!access_ok(VERIFY_WRITE, request, nbytes))
30307 return -EFAULT;
30308 - list = (struct drm_buf_pub *) (request + 1);
30309 + list = (struct drm_buf_pub __user *) (request + 1);
30310
30311 if (__put_user(count, &request->count)
30312 || __put_user(list, &request->list))
30313 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30314 index 64a62c6..ceab35e 100644
30315 --- a/drivers/gpu/drm/drm_ioctl.c
30316 +++ b/drivers/gpu/drm/drm_ioctl.c
30317 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30318 stats->data[i].value =
30319 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30320 else
30321 - stats->data[i].value = atomic_read(&dev->counts[i]);
30322 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30323 stats->data[i].type = dev->types[i];
30324 }
30325
30326 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30327 index 5211520..c744d85 100644
30328 --- a/drivers/gpu/drm/drm_lock.c
30329 +++ b/drivers/gpu/drm/drm_lock.c
30330 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30331 if (drm_lock_take(&master->lock, lock->context)) {
30332 master->lock.file_priv = file_priv;
30333 master->lock.lock_time = jiffies;
30334 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30335 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30336 break; /* Got lock */
30337 }
30338
30339 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30340 return -EINVAL;
30341 }
30342
30343 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30344 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30345
30346 if (drm_lock_free(&master->lock, lock->context)) {
30347 /* FIXME: Should really bail out here. */
30348 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30349 index 21bcd4a..8e074e0 100644
30350 --- a/drivers/gpu/drm/drm_stub.c
30351 +++ b/drivers/gpu/drm/drm_stub.c
30352 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30353
30354 drm_device_set_unplugged(dev);
30355
30356 - if (dev->open_count == 0) {
30357 + if (local_read(&dev->open_count) == 0) {
30358 drm_put_dev(dev);
30359 }
30360 mutex_unlock(&drm_global_mutex);
30361 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30362 index fa94391..ed26ec8 100644
30363 --- a/drivers/gpu/drm/i810/i810_dma.c
30364 +++ b/drivers/gpu/drm/i810/i810_dma.c
30365 @@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30366 dma->buflist[vertex->idx],
30367 vertex->discard, vertex->used);
30368
30369 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30370 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30371 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30372 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30373 sarea_priv->last_enqueue = dev_priv->counter - 1;
30374 sarea_priv->last_dispatch = (int)hw_status[5];
30375
30376 @@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30377 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30378 mc->last_render);
30379
30380 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30381 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30382 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30383 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30384 sarea_priv->last_enqueue = dev_priv->counter - 1;
30385 sarea_priv->last_dispatch = (int)hw_status[5];
30386
30387 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30388 index c9339f4..f5e1b9d 100644
30389 --- a/drivers/gpu/drm/i810/i810_drv.h
30390 +++ b/drivers/gpu/drm/i810/i810_drv.h
30391 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30392 int page_flipping;
30393
30394 wait_queue_head_t irq_queue;
30395 - atomic_t irq_received;
30396 - atomic_t irq_emitted;
30397 + atomic_unchecked_t irq_received;
30398 + atomic_unchecked_t irq_emitted;
30399
30400 int front_offset;
30401 } drm_i810_private_t;
30402 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30403 index 5363e9c..59360d1 100644
30404 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30405 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30406 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30407 I915_READ(GTIMR));
30408 }
30409 seq_printf(m, "Interrupts received: %d\n",
30410 - atomic_read(&dev_priv->irq_received));
30411 + atomic_read_unchecked(&dev_priv->irq_received));
30412 for (i = 0; i < I915_NUM_RINGS; i++) {
30413 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30414 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30415 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30416 index 36822b9..b725e1b 100644
30417 --- a/drivers/gpu/drm/i915/i915_dma.c
30418 +++ b/drivers/gpu/drm/i915/i915_dma.c
30419 @@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30420 bool can_switch;
30421
30422 spin_lock(&dev->count_lock);
30423 - can_switch = (dev->open_count == 0);
30424 + can_switch = (local_read(&dev->open_count) == 0);
30425 spin_unlock(&dev->count_lock);
30426 return can_switch;
30427 }
30428 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30429 index b0b676a..d107105 100644
30430 --- a/drivers/gpu/drm/i915/i915_drv.h
30431 +++ b/drivers/gpu/drm/i915/i915_drv.h
30432 @@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30433 /* render clock increase/decrease */
30434 /* display clock increase/decrease */
30435 /* pll clock increase/decrease */
30436 -};
30437 +} __no_const;
30438
30439 struct intel_device_info {
30440 u8 gen;
30441 @@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30442 int current_page;
30443 int page_flipping;
30444
30445 - atomic_t irq_received;
30446 + atomic_unchecked_t irq_received;
30447
30448 /* protects the irq masks */
30449 spinlock_t irq_lock;
30450 @@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30451 * will be page flipped away on the next vblank. When it
30452 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30453 */
30454 - atomic_t pending_flip;
30455 + atomic_unchecked_t pending_flip;
30456 };
30457
30458 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30459 @@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30460 struct drm_i915_private *dev_priv, unsigned port);
30461 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30462 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30463 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30464 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30465 {
30466 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30467 }
30468 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30469 index 974a9f1..b3ebd45 100644
30470 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30471 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30472 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30473 i915_gem_clflush_object(obj);
30474
30475 if (obj->base.pending_write_domain)
30476 - cd->flips |= atomic_read(&obj->pending_flip);
30477 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30478
30479 /* The actual obj->write_domain will be updated with
30480 * pending_write_domain after we emit the accumulated flush for all
30481 @@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30482
30483 static int
30484 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30485 - int count)
30486 + unsigned int count)
30487 {
30488 - int i;
30489 + unsigned int i;
30490
30491 for (i = 0; i < count; i++) {
30492 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30493 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30494 index ed3224c..6618589 100644
30495 --- a/drivers/gpu/drm/i915/i915_irq.c
30496 +++ b/drivers/gpu/drm/i915/i915_irq.c
30497 @@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30498 int vblank = 0;
30499 bool blc_event;
30500
30501 - atomic_inc(&dev_priv->irq_received);
30502 + atomic_inc_unchecked(&dev_priv->irq_received);
30503
30504 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30505 PIPE_VBLANK_INTERRUPT_STATUS;
30506 @@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30507 irqreturn_t ret = IRQ_NONE;
30508 int i;
30509
30510 - atomic_inc(&dev_priv->irq_received);
30511 + atomic_inc_unchecked(&dev_priv->irq_received);
30512
30513 /* disable master interrupt before clearing iir */
30514 de_ier = I915_READ(DEIER);
30515 @@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30516 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30517 u32 hotplug_mask;
30518
30519 - atomic_inc(&dev_priv->irq_received);
30520 + atomic_inc_unchecked(&dev_priv->irq_received);
30521
30522 /* disable master interrupt before clearing iir */
30523 de_ier = I915_READ(DEIER);
30524 @@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30525 {
30526 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30527
30528 - atomic_set(&dev_priv->irq_received, 0);
30529 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30530
30531
30532 I915_WRITE(HWSTAM, 0xeffe);
30533 @@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30534 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30535 int pipe;
30536
30537 - atomic_set(&dev_priv->irq_received, 0);
30538 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30539
30540 /* VLV magic */
30541 I915_WRITE(VLV_IMR, 0);
30542 @@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30543 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30544 int pipe;
30545
30546 - atomic_set(&dev_priv->irq_received, 0);
30547 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30548
30549 for_each_pipe(pipe)
30550 I915_WRITE(PIPESTAT(pipe), 0);
30551 @@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30552 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30553 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30554
30555 - atomic_inc(&dev_priv->irq_received);
30556 + atomic_inc_unchecked(&dev_priv->irq_received);
30557
30558 iir = I915_READ16(IIR);
30559 if (iir == 0)
30560 @@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30561 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30562 int pipe;
30563
30564 - atomic_set(&dev_priv->irq_received, 0);
30565 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30566
30567 if (I915_HAS_HOTPLUG(dev)) {
30568 I915_WRITE(PORT_HOTPLUG_EN, 0);
30569 @@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30570 };
30571 int pipe, ret = IRQ_NONE;
30572
30573 - atomic_inc(&dev_priv->irq_received);
30574 + atomic_inc_unchecked(&dev_priv->irq_received);
30575
30576 iir = I915_READ(IIR);
30577 do {
30578 @@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30579 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30580 int pipe;
30581
30582 - atomic_set(&dev_priv->irq_received, 0);
30583 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30584
30585 if (I915_HAS_HOTPLUG(dev)) {
30586 I915_WRITE(PORT_HOTPLUG_EN, 0);
30587 @@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30588 int irq_received;
30589 int ret = IRQ_NONE, pipe;
30590
30591 - atomic_inc(&dev_priv->irq_received);
30592 + atomic_inc_unchecked(&dev_priv->irq_received);
30593
30594 iir = I915_READ(IIR);
30595
30596 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30597 index 8a11131..46eeeaa 100644
30598 --- a/drivers/gpu/drm/i915/intel_display.c
30599 +++ b/drivers/gpu/drm/i915/intel_display.c
30600 @@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30601
30602 wait_event(dev_priv->pending_flip_queue,
30603 atomic_read(&dev_priv->mm.wedged) ||
30604 - atomic_read(&obj->pending_flip) == 0);
30605 + atomic_read_unchecked(&obj->pending_flip) == 0);
30606
30607 /* Big Hammer, we also need to ensure that any pending
30608 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30609 @@ -5914,9 +5914,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30610
30611 obj = work->old_fb_obj;
30612
30613 - atomic_clear_mask(1 << intel_crtc->plane,
30614 - &obj->pending_flip.counter);
30615 - if (atomic_read(&obj->pending_flip) == 0)
30616 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30617 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30618 wake_up(&dev_priv->pending_flip_queue);
30619
30620 schedule_work(&work->work);
30621 @@ -6253,7 +6252,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30622 /* Block clients from rendering to the new back buffer until
30623 * the flip occurs and the object is no longer visible.
30624 */
30625 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30626 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30627
30628 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30629 if (ret)
30630 @@ -6268,7 +6267,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30631 return 0;
30632
30633 cleanup_pending:
30634 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30635 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30636 drm_gem_object_unreference(&work->old_fb_obj->base);
30637 drm_gem_object_unreference(&obj->base);
30638 mutex_unlock(&dev->struct_mutex);
30639 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30640 index 54558a0..2d97005 100644
30641 --- a/drivers/gpu/drm/mga/mga_drv.h
30642 +++ b/drivers/gpu/drm/mga/mga_drv.h
30643 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30644 u32 clear_cmd;
30645 u32 maccess;
30646
30647 - atomic_t vbl_received; /**< Number of vblanks received. */
30648 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30649 wait_queue_head_t fence_queue;
30650 - atomic_t last_fence_retired;
30651 + atomic_unchecked_t last_fence_retired;
30652 u32 next_fence_to_post;
30653
30654 unsigned int fb_cpp;
30655 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30656 index 2581202..f230a8d9 100644
30657 --- a/drivers/gpu/drm/mga/mga_irq.c
30658 +++ b/drivers/gpu/drm/mga/mga_irq.c
30659 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30660 if (crtc != 0)
30661 return 0;
30662
30663 - return atomic_read(&dev_priv->vbl_received);
30664 + return atomic_read_unchecked(&dev_priv->vbl_received);
30665 }
30666
30667
30668 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30669 /* VBLANK interrupt */
30670 if (status & MGA_VLINEPEN) {
30671 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30672 - atomic_inc(&dev_priv->vbl_received);
30673 + atomic_inc_unchecked(&dev_priv->vbl_received);
30674 drm_handle_vblank(dev, 0);
30675 handled = 1;
30676 }
30677 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30678 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30679 MGA_WRITE(MGA_PRIMEND, prim_end);
30680
30681 - atomic_inc(&dev_priv->last_fence_retired);
30682 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30683 DRM_WAKEUP(&dev_priv->fence_queue);
30684 handled = 1;
30685 }
30686 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30687 * using fences.
30688 */
30689 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30690 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30691 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30692 - *sequence) <= (1 << 23)));
30693
30694 *sequence = cur_fence;
30695 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30696 index 2f11e16..191267e 100644
30697 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30698 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30699 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30700 struct bit_table {
30701 const char id;
30702 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30703 -};
30704 +} __no_const;
30705
30706 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30707
30708 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30709 index b863a3a..c55e0dc 100644
30710 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30711 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30712 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30713 u32 handle, u16 class);
30714 void (*set_tile_region)(struct drm_device *dev, int i);
30715 void (*tlb_flush)(struct drm_device *, int engine);
30716 -};
30717 +} __no_const;
30718
30719 struct nouveau_instmem_engine {
30720 void *priv;
30721 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30722 struct nouveau_mc_engine {
30723 int (*init)(struct drm_device *dev);
30724 void (*takedown)(struct drm_device *dev);
30725 -};
30726 +} __no_const;
30727
30728 struct nouveau_timer_engine {
30729 int (*init)(struct drm_device *dev);
30730 void (*takedown)(struct drm_device *dev);
30731 uint64_t (*read)(struct drm_device *dev);
30732 -};
30733 +} __no_const;
30734
30735 struct nouveau_fb_engine {
30736 int num_tiles;
30737 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30738 void (*put)(struct drm_device *, struct nouveau_mem **);
30739
30740 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30741 -};
30742 +} __no_const;
30743
30744 struct nouveau_engine {
30745 struct nouveau_instmem_engine instmem;
30746 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30747 struct drm_global_reference mem_global_ref;
30748 struct ttm_bo_global_ref bo_global_ref;
30749 struct ttm_bo_device bdev;
30750 - atomic_t validate_sequence;
30751 + atomic_unchecked_t validate_sequence;
30752 int (*move)(struct nouveau_channel *,
30753 struct ttm_buffer_object *,
30754 struct ttm_mem_reg *, struct ttm_mem_reg *);
30755 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30756 index 30f5423..abca136 100644
30757 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30758 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30759 @@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30760 int trycnt = 0;
30761 int ret, i;
30762
30763 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30764 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30765 retry:
30766 if (++trycnt > 100000) {
30767 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30768 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30769 index 19706f0..f257368 100644
30770 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30771 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30772 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30773 bool can_switch;
30774
30775 spin_lock(&dev->count_lock);
30776 - can_switch = (dev->open_count == 0);
30777 + can_switch = (local_read(&dev->open_count) == 0);
30778 spin_unlock(&dev->count_lock);
30779 return can_switch;
30780 }
30781 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30782 index a9514ea..369d511 100644
30783 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30784 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30785 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30786 }
30787
30788 if (nv_encoder->dcb->type == OUTPUT_DP) {
30789 - struct dp_train_func func = {
30790 + static struct dp_train_func func = {
30791 .link_set = nv50_sor_dp_link_set,
30792 .train_set = nv50_sor_dp_train_set,
30793 .train_adj = nv50_sor_dp_train_adj
30794 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30795 index c50b075..6b07dfc 100644
30796 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30797 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30798 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30799 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30800
30801 if (nv_encoder->dcb->type == OUTPUT_DP) {
30802 - struct dp_train_func func = {
30803 + static struct dp_train_func func = {
30804 .link_set = nvd0_sor_dp_link_set,
30805 .train_set = nvd0_sor_dp_train_set,
30806 .train_adj = nvd0_sor_dp_train_adj
30807 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30808 index bcac90b..53bfc76 100644
30809 --- a/drivers/gpu/drm/r128/r128_cce.c
30810 +++ b/drivers/gpu/drm/r128/r128_cce.c
30811 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30812
30813 /* GH: Simple idle check.
30814 */
30815 - atomic_set(&dev_priv->idle_count, 0);
30816 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30817
30818 /* We don't support anything other than bus-mastering ring mode,
30819 * but the ring can be in either AGP or PCI space for the ring
30820 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30821 index 930c71b..499aded 100644
30822 --- a/drivers/gpu/drm/r128/r128_drv.h
30823 +++ b/drivers/gpu/drm/r128/r128_drv.h
30824 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30825 int is_pci;
30826 unsigned long cce_buffers_offset;
30827
30828 - atomic_t idle_count;
30829 + atomic_unchecked_t idle_count;
30830
30831 int page_flipping;
30832 int current_page;
30833 u32 crtc_offset;
30834 u32 crtc_offset_cntl;
30835
30836 - atomic_t vbl_received;
30837 + atomic_unchecked_t vbl_received;
30838
30839 u32 color_fmt;
30840 unsigned int front_offset;
30841 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30842 index 429d5a0..7e899ed 100644
30843 --- a/drivers/gpu/drm/r128/r128_irq.c
30844 +++ b/drivers/gpu/drm/r128/r128_irq.c
30845 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30846 if (crtc != 0)
30847 return 0;
30848
30849 - return atomic_read(&dev_priv->vbl_received);
30850 + return atomic_read_unchecked(&dev_priv->vbl_received);
30851 }
30852
30853 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30854 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30855 /* VBLANK interrupt */
30856 if (status & R128_CRTC_VBLANK_INT) {
30857 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30858 - atomic_inc(&dev_priv->vbl_received);
30859 + atomic_inc_unchecked(&dev_priv->vbl_received);
30860 drm_handle_vblank(dev, 0);
30861 return IRQ_HANDLED;
30862 }
30863 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30864 index a9e33ce..09edd4b 100644
30865 --- a/drivers/gpu/drm/r128/r128_state.c
30866 +++ b/drivers/gpu/drm/r128/r128_state.c
30867 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30868
30869 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30870 {
30871 - if (atomic_read(&dev_priv->idle_count) == 0)
30872 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30873 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30874 else
30875 - atomic_set(&dev_priv->idle_count, 0);
30876 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30877 }
30878
30879 #endif
30880 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30881 index 5a82b6b..9e69c73 100644
30882 --- a/drivers/gpu/drm/radeon/mkregtable.c
30883 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30884 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30885 regex_t mask_rex;
30886 regmatch_t match[4];
30887 char buf[1024];
30888 - size_t end;
30889 + long end;
30890 int len;
30891 int done = 0;
30892 int r;
30893 unsigned o;
30894 struct offset *offset;
30895 char last_reg_s[10];
30896 - int last_reg;
30897 + unsigned long last_reg;
30898
30899 if (regcomp
30900 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30901 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30902 index fefcca5..20a5b90 100644
30903 --- a/drivers/gpu/drm/radeon/radeon.h
30904 +++ b/drivers/gpu/drm/radeon/radeon.h
30905 @@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30906 int x2, int y2);
30907 void (*draw_auto)(struct radeon_device *rdev);
30908 void (*set_default_state)(struct radeon_device *rdev);
30909 -};
30910 +} __no_const;
30911
30912 struct r600_blit {
30913 struct radeon_bo *shader_obj;
30914 @@ -1244,7 +1244,7 @@ struct radeon_asic {
30915 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30916 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30917 } pflip;
30918 -};
30919 +} __no_const;
30920
30921 /*
30922 * Asic structures
30923 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30924 index 066c98b..96ab858 100644
30925 --- a/drivers/gpu/drm/radeon/radeon_device.c
30926 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30927 @@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30928 bool can_switch;
30929
30930 spin_lock(&dev->count_lock);
30931 - can_switch = (dev->open_count == 0);
30932 + can_switch = (local_read(&dev->open_count) == 0);
30933 spin_unlock(&dev->count_lock);
30934 return can_switch;
30935 }
30936 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30937 index a1b59ca..86f2d44 100644
30938 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30939 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30940 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30941
30942 /* SW interrupt */
30943 wait_queue_head_t swi_queue;
30944 - atomic_t swi_emitted;
30945 + atomic_unchecked_t swi_emitted;
30946 int vblank_crtc;
30947 uint32_t irq_enable_reg;
30948 uint32_t r500_disp_irq_reg;
30949 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30950 index 48b7cea..342236f 100644
30951 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30952 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30953 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30954 request = compat_alloc_user_space(sizeof(*request));
30955 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30956 || __put_user(req32.param, &request->param)
30957 - || __put_user((void __user *)(unsigned long)req32.value,
30958 + || __put_user((unsigned long)req32.value,
30959 &request->value))
30960 return -EFAULT;
30961
30962 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30963 index 00da384..32f972d 100644
30964 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30965 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30966 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30967 unsigned int ret;
30968 RING_LOCALS;
30969
30970 - atomic_inc(&dev_priv->swi_emitted);
30971 - ret = atomic_read(&dev_priv->swi_emitted);
30972 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30973 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30974
30975 BEGIN_RING(4);
30976 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30977 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30978 drm_radeon_private_t *dev_priv =
30979 (drm_radeon_private_t *) dev->dev_private;
30980
30981 - atomic_set(&dev_priv->swi_emitted, 0);
30982 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30983 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30984
30985 dev->max_vblank_count = 0x001fffff;
30986 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30987 index e8422ae..d22d4a8 100644
30988 --- a/drivers/gpu/drm/radeon/radeon_state.c
30989 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30990 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30991 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30992 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30993
30994 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30995 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30996 sarea_priv->nbox * sizeof(depth_boxes[0])))
30997 return -EFAULT;
30998
30999 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31000 {
31001 drm_radeon_private_t *dev_priv = dev->dev_private;
31002 drm_radeon_getparam_t *param = data;
31003 - int value;
31004 + int value = 0;
31005
31006 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31007
31008 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31009 index c94a225..5795d34 100644
31010 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31011 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31012 @@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31013 }
31014 if (unlikely(ttm_vm_ops == NULL)) {
31015 ttm_vm_ops = vma->vm_ops;
31016 - radeon_ttm_vm_ops = *ttm_vm_ops;
31017 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31018 + pax_open_kernel();
31019 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31020 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31021 + pax_close_kernel();
31022 }
31023 vma->vm_ops = &radeon_ttm_vm_ops;
31024 return 0;
31025 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31026 index 159b6a4..fa82487 100644
31027 --- a/drivers/gpu/drm/radeon/rs690.c
31028 +++ b/drivers/gpu/drm/radeon/rs690.c
31029 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31030 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31031 rdev->pm.sideport_bandwidth.full)
31032 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31033 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31034 + read_delay_latency.full = dfixed_const(800 * 1000);
31035 read_delay_latency.full = dfixed_div(read_delay_latency,
31036 rdev->pm.igp_sideport_mclk);
31037 + a.full = dfixed_const(370);
31038 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31039 } else {
31040 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31041 rdev->pm.k8_bandwidth.full)
31042 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31043 index ebc6fac..a8313ed 100644
31044 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31045 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31046 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31047 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31048 struct shrink_control *sc)
31049 {
31050 - static atomic_t start_pool = ATOMIC_INIT(0);
31051 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31052 unsigned i;
31053 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31054 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31055 struct ttm_page_pool *pool;
31056 int shrink_pages = sc->nr_to_scan;
31057
31058 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31059 index 88edacc..1e5412b 100644
31060 --- a/drivers/gpu/drm/via/via_drv.h
31061 +++ b/drivers/gpu/drm/via/via_drv.h
31062 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31063 typedef uint32_t maskarray_t[5];
31064
31065 typedef struct drm_via_irq {
31066 - atomic_t irq_received;
31067 + atomic_unchecked_t irq_received;
31068 uint32_t pending_mask;
31069 uint32_t enable_mask;
31070 wait_queue_head_t irq_queue;
31071 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31072 struct timeval last_vblank;
31073 int last_vblank_valid;
31074 unsigned usec_per_vblank;
31075 - atomic_t vbl_received;
31076 + atomic_unchecked_t vbl_received;
31077 drm_via_state_t hc_state;
31078 char pci_buf[VIA_PCI_BUF_SIZE];
31079 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31080 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31081 index d391f48..10c8ca3 100644
31082 --- a/drivers/gpu/drm/via/via_irq.c
31083 +++ b/drivers/gpu/drm/via/via_irq.c
31084 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31085 if (crtc != 0)
31086 return 0;
31087
31088 - return atomic_read(&dev_priv->vbl_received);
31089 + return atomic_read_unchecked(&dev_priv->vbl_received);
31090 }
31091
31092 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31093 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31094
31095 status = VIA_READ(VIA_REG_INTERRUPT);
31096 if (status & VIA_IRQ_VBLANK_PENDING) {
31097 - atomic_inc(&dev_priv->vbl_received);
31098 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31099 + atomic_inc_unchecked(&dev_priv->vbl_received);
31100 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31101 do_gettimeofday(&cur_vblank);
31102 if (dev_priv->last_vblank_valid) {
31103 dev_priv->usec_per_vblank =
31104 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31105 dev_priv->last_vblank = cur_vblank;
31106 dev_priv->last_vblank_valid = 1;
31107 }
31108 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31109 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31110 DRM_DEBUG("US per vblank is: %u\n",
31111 dev_priv->usec_per_vblank);
31112 }
31113 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31114
31115 for (i = 0; i < dev_priv->num_irqs; ++i) {
31116 if (status & cur_irq->pending_mask) {
31117 - atomic_inc(&cur_irq->irq_received);
31118 + atomic_inc_unchecked(&cur_irq->irq_received);
31119 DRM_WAKEUP(&cur_irq->irq_queue);
31120 handled = 1;
31121 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31122 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31123 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31124 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31125 masks[irq][4]));
31126 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31127 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31128 } else {
31129 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31130 (((cur_irq_sequence =
31131 - atomic_read(&cur_irq->irq_received)) -
31132 + atomic_read_unchecked(&cur_irq->irq_received)) -
31133 *sequence) <= (1 << 23)));
31134 }
31135 *sequence = cur_irq_sequence;
31136 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31137 }
31138
31139 for (i = 0; i < dev_priv->num_irqs; ++i) {
31140 - atomic_set(&cur_irq->irq_received, 0);
31141 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31142 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31143 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31144 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31145 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31146 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31147 case VIA_IRQ_RELATIVE:
31148 irqwait->request.sequence +=
31149 - atomic_read(&cur_irq->irq_received);
31150 + atomic_read_unchecked(&cur_irq->irq_received);
31151 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31152 case VIA_IRQ_ABSOLUTE:
31153 break;
31154 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31155 index d0f2c07..9ebd9c3 100644
31156 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31157 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31158 @@ -263,7 +263,7 @@ struct vmw_private {
31159 * Fencing and IRQs.
31160 */
31161
31162 - atomic_t marker_seq;
31163 + atomic_unchecked_t marker_seq;
31164 wait_queue_head_t fence_queue;
31165 wait_queue_head_t fifo_queue;
31166 int fence_queue_waiters; /* Protected by hw_mutex */
31167 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31168 index a0c2f12..68ae6cb 100644
31169 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31170 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31171 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31172 (unsigned int) min,
31173 (unsigned int) fifo->capabilities);
31174
31175 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31176 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31177 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31178 vmw_marker_queue_init(&fifo->marker_queue);
31179 return vmw_fifo_send_fence(dev_priv, &dummy);
31180 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31181 if (reserveable)
31182 iowrite32(bytes, fifo_mem +
31183 SVGA_FIFO_RESERVED);
31184 - return fifo_mem + (next_cmd >> 2);
31185 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31186 } else {
31187 need_bounce = true;
31188 }
31189 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31190
31191 fm = vmw_fifo_reserve(dev_priv, bytes);
31192 if (unlikely(fm == NULL)) {
31193 - *seqno = atomic_read(&dev_priv->marker_seq);
31194 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31195 ret = -ENOMEM;
31196 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31197 false, 3*HZ);
31198 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31199 }
31200
31201 do {
31202 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31203 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31204 } while (*seqno == 0);
31205
31206 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31207 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31208 index cabc95f..14b3d77 100644
31209 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31210 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31211 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31212 * emitted. Then the fence is stale and signaled.
31213 */
31214
31215 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31216 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31217 > VMW_FENCE_WRAP);
31218
31219 return ret;
31220 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31221
31222 if (fifo_idle)
31223 down_read(&fifo_state->rwsem);
31224 - signal_seq = atomic_read(&dev_priv->marker_seq);
31225 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31226 ret = 0;
31227
31228 for (;;) {
31229 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31230 index 8a8725c..afed796 100644
31231 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31232 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31233 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31234 while (!vmw_lag_lt(queue, us)) {
31235 spin_lock(&queue->lock);
31236 if (list_empty(&queue->head))
31237 - seqno = atomic_read(&dev_priv->marker_seq);
31238 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31239 else {
31240 marker = list_first_entry(&queue->head,
31241 struct vmw_marker, head);
31242 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31243 index 1f6957c..b579481 100644
31244 --- a/drivers/hid/hid-core.c
31245 +++ b/drivers/hid/hid-core.c
31246 @@ -2153,7 +2153,7 @@ static bool hid_ignore(struct hid_device *hdev)
31247
31248 int hid_add_device(struct hid_device *hdev)
31249 {
31250 - static atomic_t id = ATOMIC_INIT(0);
31251 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31252 int ret;
31253
31254 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31255 @@ -2188,7 +2188,7 @@ int hid_add_device(struct hid_device *hdev)
31256 /* XXX hack, any other cleaner solution after the driver core
31257 * is converted to allow more than 20 bytes as the device name? */
31258 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31259 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31260 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31261
31262 hid_debug_register(hdev, dev_name(&hdev->dev));
31263 ret = device_add(&hdev->dev);
31264 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31265 index eec3291..8ed706b 100644
31266 --- a/drivers/hid/hid-wiimote-debug.c
31267 +++ b/drivers/hid/hid-wiimote-debug.c
31268 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31269 else if (size == 0)
31270 return -EIO;
31271
31272 - if (copy_to_user(u, buf, size))
31273 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31274 return -EFAULT;
31275
31276 *off += size;
31277 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31278 index 14599e2..711c965 100644
31279 --- a/drivers/hid/usbhid/hiddev.c
31280 +++ b/drivers/hid/usbhid/hiddev.c
31281 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31282 break;
31283
31284 case HIDIOCAPPLICATION:
31285 - if (arg < 0 || arg >= hid->maxapplication)
31286 + if (arg >= hid->maxapplication)
31287 break;
31288
31289 for (i = 0; i < hid->maxcollection; i++)
31290 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31291 index 4065374..10ed7dc 100644
31292 --- a/drivers/hv/channel.c
31293 +++ b/drivers/hv/channel.c
31294 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31295 int ret = 0;
31296 int t;
31297
31298 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31299 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31300 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31301 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31302
31303 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31304 if (ret)
31305 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31306 index 86f8885..ab9cb2b 100644
31307 --- a/drivers/hv/hv.c
31308 +++ b/drivers/hv/hv.c
31309 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31310 u64 output_address = (output) ? virt_to_phys(output) : 0;
31311 u32 output_address_hi = output_address >> 32;
31312 u32 output_address_lo = output_address & 0xFFFFFFFF;
31313 - void *hypercall_page = hv_context.hypercall_page;
31314 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31315
31316 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31317 "=a"(hv_status_lo) : "d" (control_hi),
31318 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31319 index b9426a6..677ce34 100644
31320 --- a/drivers/hv/hyperv_vmbus.h
31321 +++ b/drivers/hv/hyperv_vmbus.h
31322 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31323 struct vmbus_connection {
31324 enum vmbus_connect_state conn_state;
31325
31326 - atomic_t next_gpadl_handle;
31327 + atomic_unchecked_t next_gpadl_handle;
31328
31329 /*
31330 * Represents channel interrupts. Each bit position represents a
31331 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31332 index a220e57..428f54d 100644
31333 --- a/drivers/hv/vmbus_drv.c
31334 +++ b/drivers/hv/vmbus_drv.c
31335 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31336 {
31337 int ret = 0;
31338
31339 - static atomic_t device_num = ATOMIC_INIT(0);
31340 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31341
31342 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31343 - atomic_inc_return(&device_num));
31344 + atomic_inc_return_unchecked(&device_num));
31345
31346 child_device_obj->device.bus = &hv_bus;
31347 child_device_obj->device.parent = &hv_acpi_dev->dev;
31348 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31349 index 34ad5a2..e2b0ae8 100644
31350 --- a/drivers/hwmon/acpi_power_meter.c
31351 +++ b/drivers/hwmon/acpi_power_meter.c
31352 @@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31353 return res;
31354
31355 temp /= 1000;
31356 - if (temp < 0)
31357 - return -EINVAL;
31358
31359 mutex_lock(&resource->lock);
31360 resource->trip[attr->index - 7] = temp;
31361 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31362 index 8b011d0..3de24a1 100644
31363 --- a/drivers/hwmon/sht15.c
31364 +++ b/drivers/hwmon/sht15.c
31365 @@ -166,7 +166,7 @@ struct sht15_data {
31366 int supply_uV;
31367 bool supply_uV_valid;
31368 struct work_struct update_supply_work;
31369 - atomic_t interrupt_handled;
31370 + atomic_unchecked_t interrupt_handled;
31371 };
31372
31373 /**
31374 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31375 return ret;
31376
31377 gpio_direction_input(data->pdata->gpio_data);
31378 - atomic_set(&data->interrupt_handled, 0);
31379 + atomic_set_unchecked(&data->interrupt_handled, 0);
31380
31381 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31382 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31383 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31384 /* Only relevant if the interrupt hasn't occurred. */
31385 - if (!atomic_read(&data->interrupt_handled))
31386 + if (!atomic_read_unchecked(&data->interrupt_handled))
31387 schedule_work(&data->read_work);
31388 }
31389 ret = wait_event_timeout(data->wait_queue,
31390 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31391
31392 /* First disable the interrupt */
31393 disable_irq_nosync(irq);
31394 - atomic_inc(&data->interrupt_handled);
31395 + atomic_inc_unchecked(&data->interrupt_handled);
31396 /* Then schedule a reading work struct */
31397 if (data->state != SHT15_READING_NOTHING)
31398 schedule_work(&data->read_work);
31399 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31400 * If not, then start the interrupt again - care here as could
31401 * have gone low in meantime so verify it hasn't!
31402 */
31403 - atomic_set(&data->interrupt_handled, 0);
31404 + atomic_set_unchecked(&data->interrupt_handled, 0);
31405 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31406 /* If still not occurred or another handler was scheduled */
31407 if (gpio_get_value(data->pdata->gpio_data)
31408 - || atomic_read(&data->interrupt_handled))
31409 + || atomic_read_unchecked(&data->interrupt_handled))
31410 return;
31411 }
31412
31413 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31414 index 378fcb5..5e91fa8 100644
31415 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31416 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31417 @@ -43,7 +43,7 @@
31418 extern struct i2c_adapter amd756_smbus;
31419
31420 static struct i2c_adapter *s4882_adapter;
31421 -static struct i2c_algorithm *s4882_algo;
31422 +static i2c_algorithm_no_const *s4882_algo;
31423
31424 /* Wrapper access functions for multiplexed SMBus */
31425 static DEFINE_MUTEX(amd756_lock);
31426 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31427 index 29015eb..af2d8e9 100644
31428 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31429 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31430 @@ -41,7 +41,7 @@
31431 extern struct i2c_adapter *nforce2_smbus;
31432
31433 static struct i2c_adapter *s4985_adapter;
31434 -static struct i2c_algorithm *s4985_algo;
31435 +static i2c_algorithm_no_const *s4985_algo;
31436
31437 /* Wrapper access functions for multiplexed SMBus */
31438 static DEFINE_MUTEX(nforce2_lock);
31439 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31440 index 1038c38..eb92f51 100644
31441 --- a/drivers/i2c/i2c-mux.c
31442 +++ b/drivers/i2c/i2c-mux.c
31443 @@ -30,7 +30,7 @@
31444 /* multiplexer per channel data */
31445 struct i2c_mux_priv {
31446 struct i2c_adapter adap;
31447 - struct i2c_algorithm algo;
31448 + i2c_algorithm_no_const algo;
31449
31450 struct i2c_adapter *parent;
31451 void *mux_priv; /* the mux chip/device */
31452 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31453 index 57d00ca..0145194 100644
31454 --- a/drivers/ide/aec62xx.c
31455 +++ b/drivers/ide/aec62xx.c
31456 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31457 .cable_detect = atp86x_cable_detect,
31458 };
31459
31460 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31461 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31462 { /* 0: AEC6210 */
31463 .name = DRV_NAME,
31464 .init_chipset = init_chipset_aec62xx,
31465 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31466 index 2c8016a..911a27c 100644
31467 --- a/drivers/ide/alim15x3.c
31468 +++ b/drivers/ide/alim15x3.c
31469 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31470 .dma_sff_read_status = ide_dma_sff_read_status,
31471 };
31472
31473 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31474 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31475 .name = DRV_NAME,
31476 .init_chipset = init_chipset_ali15x3,
31477 .init_hwif = init_hwif_ali15x3,
31478 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31479 index 3747b25..56fc995 100644
31480 --- a/drivers/ide/amd74xx.c
31481 +++ b/drivers/ide/amd74xx.c
31482 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31483 .udma_mask = udma, \
31484 }
31485
31486 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31487 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31488 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31489 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31490 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31491 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31492 index 15f0ead..cb43480 100644
31493 --- a/drivers/ide/atiixp.c
31494 +++ b/drivers/ide/atiixp.c
31495 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31496 .cable_detect = atiixp_cable_detect,
31497 };
31498
31499 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31500 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31501 { /* 0: IXP200/300/400/700 */
31502 .name = DRV_NAME,
31503 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31504 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31505 index 5f80312..d1fc438 100644
31506 --- a/drivers/ide/cmd64x.c
31507 +++ b/drivers/ide/cmd64x.c
31508 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31509 .dma_sff_read_status = ide_dma_sff_read_status,
31510 };
31511
31512 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31513 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31514 { /* 0: CMD643 */
31515 .name = DRV_NAME,
31516 .init_chipset = init_chipset_cmd64x,
31517 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31518 index 2c1e5f7..1444762 100644
31519 --- a/drivers/ide/cs5520.c
31520 +++ b/drivers/ide/cs5520.c
31521 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31522 .set_dma_mode = cs5520_set_dma_mode,
31523 };
31524
31525 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31526 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31527 .name = DRV_NAME,
31528 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31529 .port_ops = &cs5520_port_ops,
31530 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31531 index 4dc4eb9..49b40ad 100644
31532 --- a/drivers/ide/cs5530.c
31533 +++ b/drivers/ide/cs5530.c
31534 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31535 .udma_filter = cs5530_udma_filter,
31536 };
31537
31538 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31539 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31540 .name = DRV_NAME,
31541 .init_chipset = init_chipset_cs5530,
31542 .init_hwif = init_hwif_cs5530,
31543 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31544 index 5059faf..18d4c85 100644
31545 --- a/drivers/ide/cs5535.c
31546 +++ b/drivers/ide/cs5535.c
31547 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31548 .cable_detect = cs5535_cable_detect,
31549 };
31550
31551 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31552 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31553 .name = DRV_NAME,
31554 .port_ops = &cs5535_port_ops,
31555 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31556 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31557 index 847553f..3ffb49d 100644
31558 --- a/drivers/ide/cy82c693.c
31559 +++ b/drivers/ide/cy82c693.c
31560 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31561 .set_dma_mode = cy82c693_set_dma_mode,
31562 };
31563
31564 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31565 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31566 .name = DRV_NAME,
31567 .init_iops = init_iops_cy82c693,
31568 .port_ops = &cy82c693_port_ops,
31569 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31570 index 58c51cd..4aec3b8 100644
31571 --- a/drivers/ide/hpt366.c
31572 +++ b/drivers/ide/hpt366.c
31573 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31574 }
31575 };
31576
31577 -static const struct hpt_info hpt36x __devinitdata = {
31578 +static const struct hpt_info hpt36x __devinitconst = {
31579 .chip_name = "HPT36x",
31580 .chip_type = HPT36x,
31581 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31582 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31583 .timings = &hpt36x_timings
31584 };
31585
31586 -static const struct hpt_info hpt370 __devinitdata = {
31587 +static const struct hpt_info hpt370 __devinitconst = {
31588 .chip_name = "HPT370",
31589 .chip_type = HPT370,
31590 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31591 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31592 .timings = &hpt37x_timings
31593 };
31594
31595 -static const struct hpt_info hpt370a __devinitdata = {
31596 +static const struct hpt_info hpt370a __devinitconst = {
31597 .chip_name = "HPT370A",
31598 .chip_type = HPT370A,
31599 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31600 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31601 .timings = &hpt37x_timings
31602 };
31603
31604 -static const struct hpt_info hpt374 __devinitdata = {
31605 +static const struct hpt_info hpt374 __devinitconst = {
31606 .chip_name = "HPT374",
31607 .chip_type = HPT374,
31608 .udma_mask = ATA_UDMA5,
31609 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31610 .timings = &hpt37x_timings
31611 };
31612
31613 -static const struct hpt_info hpt372 __devinitdata = {
31614 +static const struct hpt_info hpt372 __devinitconst = {
31615 .chip_name = "HPT372",
31616 .chip_type = HPT372,
31617 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31618 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31619 .timings = &hpt37x_timings
31620 };
31621
31622 -static const struct hpt_info hpt372a __devinitdata = {
31623 +static const struct hpt_info hpt372a __devinitconst = {
31624 .chip_name = "HPT372A",
31625 .chip_type = HPT372A,
31626 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31627 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31628 .timings = &hpt37x_timings
31629 };
31630
31631 -static const struct hpt_info hpt302 __devinitdata = {
31632 +static const struct hpt_info hpt302 __devinitconst = {
31633 .chip_name = "HPT302",
31634 .chip_type = HPT302,
31635 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31636 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31637 .timings = &hpt37x_timings
31638 };
31639
31640 -static const struct hpt_info hpt371 __devinitdata = {
31641 +static const struct hpt_info hpt371 __devinitconst = {
31642 .chip_name = "HPT371",
31643 .chip_type = HPT371,
31644 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31645 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31646 .timings = &hpt37x_timings
31647 };
31648
31649 -static const struct hpt_info hpt372n __devinitdata = {
31650 +static const struct hpt_info hpt372n __devinitconst = {
31651 .chip_name = "HPT372N",
31652 .chip_type = HPT372N,
31653 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31654 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31655 .timings = &hpt37x_timings
31656 };
31657
31658 -static const struct hpt_info hpt302n __devinitdata = {
31659 +static const struct hpt_info hpt302n __devinitconst = {
31660 .chip_name = "HPT302N",
31661 .chip_type = HPT302N,
31662 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31663 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31664 .timings = &hpt37x_timings
31665 };
31666
31667 -static const struct hpt_info hpt371n __devinitdata = {
31668 +static const struct hpt_info hpt371n __devinitconst = {
31669 .chip_name = "HPT371N",
31670 .chip_type = HPT371N,
31671 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31672 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31673 .dma_sff_read_status = ide_dma_sff_read_status,
31674 };
31675
31676 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31677 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31678 { /* 0: HPT36x */
31679 .name = DRV_NAME,
31680 .init_chipset = init_chipset_hpt366,
31681 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31682 index 8126824..55a2798 100644
31683 --- a/drivers/ide/ide-cd.c
31684 +++ b/drivers/ide/ide-cd.c
31685 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31686 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31687 if ((unsigned long)buf & alignment
31688 || blk_rq_bytes(rq) & q->dma_pad_mask
31689 - || object_is_on_stack(buf))
31690 + || object_starts_on_stack(buf))
31691 drive->dma = 0;
31692 }
31693 }
31694 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31695 index 7f56b73..dab5b67 100644
31696 --- a/drivers/ide/ide-pci-generic.c
31697 +++ b/drivers/ide/ide-pci-generic.c
31698 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31699 .udma_mask = ATA_UDMA6, \
31700 }
31701
31702 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31703 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31704 /* 0: Unknown */
31705 DECLARE_GENERIC_PCI_DEV(0),
31706
31707 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31708 index 560e66d..d5dd180 100644
31709 --- a/drivers/ide/it8172.c
31710 +++ b/drivers/ide/it8172.c
31711 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31712 .set_dma_mode = it8172_set_dma_mode,
31713 };
31714
31715 -static const struct ide_port_info it8172_port_info __devinitdata = {
31716 +static const struct ide_port_info it8172_port_info __devinitconst = {
31717 .name = DRV_NAME,
31718 .port_ops = &it8172_port_ops,
31719 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31720 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31721 index 46816ba..1847aeb 100644
31722 --- a/drivers/ide/it8213.c
31723 +++ b/drivers/ide/it8213.c
31724 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31725 .cable_detect = it8213_cable_detect,
31726 };
31727
31728 -static const struct ide_port_info it8213_chipset __devinitdata = {
31729 +static const struct ide_port_info it8213_chipset __devinitconst = {
31730 .name = DRV_NAME,
31731 .enablebits = { {0x41, 0x80, 0x80} },
31732 .port_ops = &it8213_port_ops,
31733 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31734 index 2e3169f..c5611db 100644
31735 --- a/drivers/ide/it821x.c
31736 +++ b/drivers/ide/it821x.c
31737 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31738 .cable_detect = it821x_cable_detect,
31739 };
31740
31741 -static const struct ide_port_info it821x_chipset __devinitdata = {
31742 +static const struct ide_port_info it821x_chipset __devinitconst = {
31743 .name = DRV_NAME,
31744 .init_chipset = init_chipset_it821x,
31745 .init_hwif = init_hwif_it821x,
31746 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31747 index 74c2c4a..efddd7d 100644
31748 --- a/drivers/ide/jmicron.c
31749 +++ b/drivers/ide/jmicron.c
31750 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31751 .cable_detect = jmicron_cable_detect,
31752 };
31753
31754 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31755 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31756 .name = DRV_NAME,
31757 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31758 .port_ops = &jmicron_port_ops,
31759 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31760 index 95327a2..73f78d8 100644
31761 --- a/drivers/ide/ns87415.c
31762 +++ b/drivers/ide/ns87415.c
31763 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31764 .dma_sff_read_status = superio_dma_sff_read_status,
31765 };
31766
31767 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31768 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31769 .name = DRV_NAME,
31770 .init_hwif = init_hwif_ns87415,
31771 .tp_ops = &ns87415_tp_ops,
31772 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31773 index 1a53a4c..39edc66 100644
31774 --- a/drivers/ide/opti621.c
31775 +++ b/drivers/ide/opti621.c
31776 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31777 .set_pio_mode = opti621_set_pio_mode,
31778 };
31779
31780 -static const struct ide_port_info opti621_chipset __devinitdata = {
31781 +static const struct ide_port_info opti621_chipset __devinitconst = {
31782 .name = DRV_NAME,
31783 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31784 .port_ops = &opti621_port_ops,
31785 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31786 index 9546fe2..2e5ceb6 100644
31787 --- a/drivers/ide/pdc202xx_new.c
31788 +++ b/drivers/ide/pdc202xx_new.c
31789 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31790 .udma_mask = udma, \
31791 }
31792
31793 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31794 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31795 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31796 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31797 };
31798 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31799 index 3a35ec6..5634510 100644
31800 --- a/drivers/ide/pdc202xx_old.c
31801 +++ b/drivers/ide/pdc202xx_old.c
31802 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31803 .max_sectors = sectors, \
31804 }
31805
31806 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31807 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31808 { /* 0: PDC20246 */
31809 .name = DRV_NAME,
31810 .init_chipset = init_chipset_pdc202xx,
31811 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31812 index 1892e81..fe0fd60 100644
31813 --- a/drivers/ide/piix.c
31814 +++ b/drivers/ide/piix.c
31815 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31816 .udma_mask = udma, \
31817 }
31818
31819 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31820 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31821 /* 0: MPIIX */
31822 { /*
31823 * MPIIX actually has only a single IDE channel mapped to
31824 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31825 index a6414a8..c04173e 100644
31826 --- a/drivers/ide/rz1000.c
31827 +++ b/drivers/ide/rz1000.c
31828 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31829 }
31830 }
31831
31832 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31833 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31834 .name = DRV_NAME,
31835 .host_flags = IDE_HFLAG_NO_DMA,
31836 };
31837 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31838 index 356b9b5..d4758eb 100644
31839 --- a/drivers/ide/sc1200.c
31840 +++ b/drivers/ide/sc1200.c
31841 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31842 .dma_sff_read_status = ide_dma_sff_read_status,
31843 };
31844
31845 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31846 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31847 .name = DRV_NAME,
31848 .port_ops = &sc1200_port_ops,
31849 .dma_ops = &sc1200_dma_ops,
31850 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31851 index b7f5b0c..9701038 100644
31852 --- a/drivers/ide/scc_pata.c
31853 +++ b/drivers/ide/scc_pata.c
31854 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31855 .dma_sff_read_status = scc_dma_sff_read_status,
31856 };
31857
31858 -static const struct ide_port_info scc_chipset __devinitdata = {
31859 +static const struct ide_port_info scc_chipset __devinitconst = {
31860 .name = "sccIDE",
31861 .init_iops = init_iops_scc,
31862 .init_dma = scc_init_dma,
31863 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31864 index 35fb8da..24d72ef 100644
31865 --- a/drivers/ide/serverworks.c
31866 +++ b/drivers/ide/serverworks.c
31867 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31868 .cable_detect = svwks_cable_detect,
31869 };
31870
31871 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31872 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31873 { /* 0: OSB4 */
31874 .name = DRV_NAME,
31875 .init_chipset = init_chipset_svwks,
31876 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31877 index ddeda44..46f7e30 100644
31878 --- a/drivers/ide/siimage.c
31879 +++ b/drivers/ide/siimage.c
31880 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31881 .udma_mask = ATA_UDMA6, \
31882 }
31883
31884 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31885 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31886 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31887 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31888 };
31889 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31890 index 4a00225..09e61b4 100644
31891 --- a/drivers/ide/sis5513.c
31892 +++ b/drivers/ide/sis5513.c
31893 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31894 .cable_detect = sis_cable_detect,
31895 };
31896
31897 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31898 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31899 .name = DRV_NAME,
31900 .init_chipset = init_chipset_sis5513,
31901 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31902 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31903 index f21dc2a..d051cd2 100644
31904 --- a/drivers/ide/sl82c105.c
31905 +++ b/drivers/ide/sl82c105.c
31906 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31907 .dma_sff_read_status = ide_dma_sff_read_status,
31908 };
31909
31910 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31911 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31912 .name = DRV_NAME,
31913 .init_chipset = init_chipset_sl82c105,
31914 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31915 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31916 index 864ffe0..863a5e9 100644
31917 --- a/drivers/ide/slc90e66.c
31918 +++ b/drivers/ide/slc90e66.c
31919 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31920 .cable_detect = slc90e66_cable_detect,
31921 };
31922
31923 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31924 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31925 .name = DRV_NAME,
31926 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31927 .port_ops = &slc90e66_port_ops,
31928 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31929 index 4799d5c..1794678 100644
31930 --- a/drivers/ide/tc86c001.c
31931 +++ b/drivers/ide/tc86c001.c
31932 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31933 .dma_sff_read_status = ide_dma_sff_read_status,
31934 };
31935
31936 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31937 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31938 .name = DRV_NAME,
31939 .init_hwif = init_hwif_tc86c001,
31940 .port_ops = &tc86c001_port_ops,
31941 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31942 index 281c914..55ce1b8 100644
31943 --- a/drivers/ide/triflex.c
31944 +++ b/drivers/ide/triflex.c
31945 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31946 .set_dma_mode = triflex_set_mode,
31947 };
31948
31949 -static const struct ide_port_info triflex_device __devinitdata = {
31950 +static const struct ide_port_info triflex_device __devinitconst = {
31951 .name = DRV_NAME,
31952 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31953 .port_ops = &triflex_port_ops,
31954 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31955 index 4b42ca0..e494a98 100644
31956 --- a/drivers/ide/trm290.c
31957 +++ b/drivers/ide/trm290.c
31958 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31959 .dma_check = trm290_dma_check,
31960 };
31961
31962 -static const struct ide_port_info trm290_chipset __devinitdata = {
31963 +static const struct ide_port_info trm290_chipset __devinitconst = {
31964 .name = DRV_NAME,
31965 .init_hwif = init_hwif_trm290,
31966 .tp_ops = &trm290_tp_ops,
31967 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31968 index f46f49c..eb77678 100644
31969 --- a/drivers/ide/via82cxxx.c
31970 +++ b/drivers/ide/via82cxxx.c
31971 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31972 .cable_detect = via82cxxx_cable_detect,
31973 };
31974
31975 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31976 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31977 .name = DRV_NAME,
31978 .init_chipset = init_chipset_via82cxxx,
31979 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31980 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31981 index 73d4531..c90cd2d 100644
31982 --- a/drivers/ieee802154/fakehard.c
31983 +++ b/drivers/ieee802154/fakehard.c
31984 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31985 phy->transmit_power = 0xbf;
31986
31987 dev->netdev_ops = &fake_ops;
31988 - dev->ml_priv = &fake_mlme;
31989 + dev->ml_priv = (void *)&fake_mlme;
31990
31991 priv = netdev_priv(dev);
31992 priv->phy = phy;
31993 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31994 index c889aae..6cf5aa7 100644
31995 --- a/drivers/infiniband/core/cm.c
31996 +++ b/drivers/infiniband/core/cm.c
31997 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31998
31999 struct cm_counter_group {
32000 struct kobject obj;
32001 - atomic_long_t counter[CM_ATTR_COUNT];
32002 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32003 };
32004
32005 struct cm_counter_attribute {
32006 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32007 struct ib_mad_send_buf *msg = NULL;
32008 int ret;
32009
32010 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32011 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32012 counter[CM_REQ_COUNTER]);
32013
32014 /* Quick state check to discard duplicate REQs. */
32015 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32016 if (!cm_id_priv)
32017 return;
32018
32019 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32020 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32021 counter[CM_REP_COUNTER]);
32022 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32023 if (ret)
32024 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32025 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32026 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32027 spin_unlock_irq(&cm_id_priv->lock);
32028 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32029 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32030 counter[CM_RTU_COUNTER]);
32031 goto out;
32032 }
32033 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32034 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32035 dreq_msg->local_comm_id);
32036 if (!cm_id_priv) {
32037 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32038 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32039 counter[CM_DREQ_COUNTER]);
32040 cm_issue_drep(work->port, work->mad_recv_wc);
32041 return -EINVAL;
32042 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32043 case IB_CM_MRA_REP_RCVD:
32044 break;
32045 case IB_CM_TIMEWAIT:
32046 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32047 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32048 counter[CM_DREQ_COUNTER]);
32049 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32050 goto unlock;
32051 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32052 cm_free_msg(msg);
32053 goto deref;
32054 case IB_CM_DREQ_RCVD:
32055 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32056 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32057 counter[CM_DREQ_COUNTER]);
32058 goto unlock;
32059 default:
32060 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32061 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32062 cm_id_priv->msg, timeout)) {
32063 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32064 - atomic_long_inc(&work->port->
32065 + atomic_long_inc_unchecked(&work->port->
32066 counter_group[CM_RECV_DUPLICATES].
32067 counter[CM_MRA_COUNTER]);
32068 goto out;
32069 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32070 break;
32071 case IB_CM_MRA_REQ_RCVD:
32072 case IB_CM_MRA_REP_RCVD:
32073 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32074 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32075 counter[CM_MRA_COUNTER]);
32076 /* fall through */
32077 default:
32078 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32079 case IB_CM_LAP_IDLE:
32080 break;
32081 case IB_CM_MRA_LAP_SENT:
32082 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32083 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32084 counter[CM_LAP_COUNTER]);
32085 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32086 goto unlock;
32087 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32088 cm_free_msg(msg);
32089 goto deref;
32090 case IB_CM_LAP_RCVD:
32091 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32092 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32093 counter[CM_LAP_COUNTER]);
32094 goto unlock;
32095 default:
32096 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32097 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32098 if (cur_cm_id_priv) {
32099 spin_unlock_irq(&cm.lock);
32100 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32101 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32102 counter[CM_SIDR_REQ_COUNTER]);
32103 goto out; /* Duplicate message. */
32104 }
32105 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32106 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32107 msg->retries = 1;
32108
32109 - atomic_long_add(1 + msg->retries,
32110 + atomic_long_add_unchecked(1 + msg->retries,
32111 &port->counter_group[CM_XMIT].counter[attr_index]);
32112 if (msg->retries)
32113 - atomic_long_add(msg->retries,
32114 + atomic_long_add_unchecked(msg->retries,
32115 &port->counter_group[CM_XMIT_RETRIES].
32116 counter[attr_index]);
32117
32118 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32119 }
32120
32121 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32122 - atomic_long_inc(&port->counter_group[CM_RECV].
32123 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32124 counter[attr_id - CM_ATTR_ID_OFFSET]);
32125
32126 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32127 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32128 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32129
32130 return sprintf(buf, "%ld\n",
32131 - atomic_long_read(&group->counter[cm_attr->index]));
32132 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32133 }
32134
32135 static const struct sysfs_ops cm_counter_ops = {
32136 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32137 index 176c8f9..2627b62 100644
32138 --- a/drivers/infiniband/core/fmr_pool.c
32139 +++ b/drivers/infiniband/core/fmr_pool.c
32140 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32141
32142 struct task_struct *thread;
32143
32144 - atomic_t req_ser;
32145 - atomic_t flush_ser;
32146 + atomic_unchecked_t req_ser;
32147 + atomic_unchecked_t flush_ser;
32148
32149 wait_queue_head_t force_wait;
32150 };
32151 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32152 struct ib_fmr_pool *pool = pool_ptr;
32153
32154 do {
32155 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32156 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32157 ib_fmr_batch_release(pool);
32158
32159 - atomic_inc(&pool->flush_ser);
32160 + atomic_inc_unchecked(&pool->flush_ser);
32161 wake_up_interruptible(&pool->force_wait);
32162
32163 if (pool->flush_function)
32164 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32165 }
32166
32167 set_current_state(TASK_INTERRUPTIBLE);
32168 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32169 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32170 !kthread_should_stop())
32171 schedule();
32172 __set_current_state(TASK_RUNNING);
32173 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32174 pool->dirty_watermark = params->dirty_watermark;
32175 pool->dirty_len = 0;
32176 spin_lock_init(&pool->pool_lock);
32177 - atomic_set(&pool->req_ser, 0);
32178 - atomic_set(&pool->flush_ser, 0);
32179 + atomic_set_unchecked(&pool->req_ser, 0);
32180 + atomic_set_unchecked(&pool->flush_ser, 0);
32181 init_waitqueue_head(&pool->force_wait);
32182
32183 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32184 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32185 }
32186 spin_unlock_irq(&pool->pool_lock);
32187
32188 - serial = atomic_inc_return(&pool->req_ser);
32189 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32190 wake_up_process(pool->thread);
32191
32192 if (wait_event_interruptible(pool->force_wait,
32193 - atomic_read(&pool->flush_ser) - serial >= 0))
32194 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32195 return -EINTR;
32196
32197 return 0;
32198 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32199 } else {
32200 list_add_tail(&fmr->list, &pool->dirty_list);
32201 if (++pool->dirty_len >= pool->dirty_watermark) {
32202 - atomic_inc(&pool->req_ser);
32203 + atomic_inc_unchecked(&pool->req_ser);
32204 wake_up_process(pool->thread);
32205 }
32206 }
32207 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32208 index 57e07c6..56d09d4 100644
32209 --- a/drivers/infiniband/hw/cxgb4/mem.c
32210 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32211 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32212 int err;
32213 struct fw_ri_tpte tpt;
32214 u32 stag_idx;
32215 - static atomic_t key;
32216 + static atomic_unchecked_t key;
32217
32218 if (c4iw_fatal_error(rdev))
32219 return -EIO;
32220 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32221 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32222 rdev->stats.stag.max = rdev->stats.stag.cur;
32223 mutex_unlock(&rdev->stats.lock);
32224 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32225 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32226 }
32227 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32228 __func__, stag_state, type, pdid, stag_idx);
32229 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32230 index 79b3dbc..96e5fcc 100644
32231 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32232 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32233 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32234 struct ib_atomic_eth *ateth;
32235 struct ipath_ack_entry *e;
32236 u64 vaddr;
32237 - atomic64_t *maddr;
32238 + atomic64_unchecked_t *maddr;
32239 u64 sdata;
32240 u32 rkey;
32241 u8 next;
32242 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32243 IB_ACCESS_REMOTE_ATOMIC)))
32244 goto nack_acc_unlck;
32245 /* Perform atomic OP and save result. */
32246 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32247 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32248 sdata = be64_to_cpu(ateth->swap_data);
32249 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32250 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32251 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32252 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32253 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32254 be64_to_cpu(ateth->compare_data),
32255 sdata);
32256 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32257 index 1f95bba..9530f87 100644
32258 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32259 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32260 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32261 unsigned long flags;
32262 struct ib_wc wc;
32263 u64 sdata;
32264 - atomic64_t *maddr;
32265 + atomic64_unchecked_t *maddr;
32266 enum ib_wc_status send_status;
32267
32268 /*
32269 @@ -382,11 +382,11 @@ again:
32270 IB_ACCESS_REMOTE_ATOMIC)))
32271 goto acc_err;
32272 /* Perform atomic OP and save result. */
32273 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32274 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32275 sdata = wqe->wr.wr.atomic.compare_add;
32276 *(u64 *) sqp->s_sge.sge.vaddr =
32277 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32278 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32279 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32280 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32281 sdata, wqe->wr.wr.atomic.swap);
32282 goto send_comp;
32283 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32284 index 7140199..da60063 100644
32285 --- a/drivers/infiniband/hw/nes/nes.c
32286 +++ b/drivers/infiniband/hw/nes/nes.c
32287 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32288 LIST_HEAD(nes_adapter_list);
32289 static LIST_HEAD(nes_dev_list);
32290
32291 -atomic_t qps_destroyed;
32292 +atomic_unchecked_t qps_destroyed;
32293
32294 static unsigned int ee_flsh_adapter;
32295 static unsigned int sysfs_nonidx_addr;
32296 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32297 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32298 struct nes_adapter *nesadapter = nesdev->nesadapter;
32299
32300 - atomic_inc(&qps_destroyed);
32301 + atomic_inc_unchecked(&qps_destroyed);
32302
32303 /* Free the control structures */
32304
32305 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32306 index c438e46..ca30356 100644
32307 --- a/drivers/infiniband/hw/nes/nes.h
32308 +++ b/drivers/infiniband/hw/nes/nes.h
32309 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32310 extern unsigned int wqm_quanta;
32311 extern struct list_head nes_adapter_list;
32312
32313 -extern atomic_t cm_connects;
32314 -extern atomic_t cm_accepts;
32315 -extern atomic_t cm_disconnects;
32316 -extern atomic_t cm_closes;
32317 -extern atomic_t cm_connecteds;
32318 -extern atomic_t cm_connect_reqs;
32319 -extern atomic_t cm_rejects;
32320 -extern atomic_t mod_qp_timouts;
32321 -extern atomic_t qps_created;
32322 -extern atomic_t qps_destroyed;
32323 -extern atomic_t sw_qps_destroyed;
32324 +extern atomic_unchecked_t cm_connects;
32325 +extern atomic_unchecked_t cm_accepts;
32326 +extern atomic_unchecked_t cm_disconnects;
32327 +extern atomic_unchecked_t cm_closes;
32328 +extern atomic_unchecked_t cm_connecteds;
32329 +extern atomic_unchecked_t cm_connect_reqs;
32330 +extern atomic_unchecked_t cm_rejects;
32331 +extern atomic_unchecked_t mod_qp_timouts;
32332 +extern atomic_unchecked_t qps_created;
32333 +extern atomic_unchecked_t qps_destroyed;
32334 +extern atomic_unchecked_t sw_qps_destroyed;
32335 extern u32 mh_detected;
32336 extern u32 mh_pauses_sent;
32337 extern u32 cm_packets_sent;
32338 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32339 extern u32 cm_packets_received;
32340 extern u32 cm_packets_dropped;
32341 extern u32 cm_packets_retrans;
32342 -extern atomic_t cm_listens_created;
32343 -extern atomic_t cm_listens_destroyed;
32344 +extern atomic_unchecked_t cm_listens_created;
32345 +extern atomic_unchecked_t cm_listens_destroyed;
32346 extern u32 cm_backlog_drops;
32347 -extern atomic_t cm_loopbacks;
32348 -extern atomic_t cm_nodes_created;
32349 -extern atomic_t cm_nodes_destroyed;
32350 -extern atomic_t cm_accel_dropped_pkts;
32351 -extern atomic_t cm_resets_recvd;
32352 -extern atomic_t pau_qps_created;
32353 -extern atomic_t pau_qps_destroyed;
32354 +extern atomic_unchecked_t cm_loopbacks;
32355 +extern atomic_unchecked_t cm_nodes_created;
32356 +extern atomic_unchecked_t cm_nodes_destroyed;
32357 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32358 +extern atomic_unchecked_t cm_resets_recvd;
32359 +extern atomic_unchecked_t pau_qps_created;
32360 +extern atomic_unchecked_t pau_qps_destroyed;
32361
32362 extern u32 int_mod_timer_init;
32363 extern u32 int_mod_cq_depth_256;
32364 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32365 index 020e95c..fbb3450 100644
32366 --- a/drivers/infiniband/hw/nes/nes_cm.c
32367 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32368 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32369 u32 cm_packets_retrans;
32370 u32 cm_packets_created;
32371 u32 cm_packets_received;
32372 -atomic_t cm_listens_created;
32373 -atomic_t cm_listens_destroyed;
32374 +atomic_unchecked_t cm_listens_created;
32375 +atomic_unchecked_t cm_listens_destroyed;
32376 u32 cm_backlog_drops;
32377 -atomic_t cm_loopbacks;
32378 -atomic_t cm_nodes_created;
32379 -atomic_t cm_nodes_destroyed;
32380 -atomic_t cm_accel_dropped_pkts;
32381 -atomic_t cm_resets_recvd;
32382 +atomic_unchecked_t cm_loopbacks;
32383 +atomic_unchecked_t cm_nodes_created;
32384 +atomic_unchecked_t cm_nodes_destroyed;
32385 +atomic_unchecked_t cm_accel_dropped_pkts;
32386 +atomic_unchecked_t cm_resets_recvd;
32387
32388 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32389 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32390 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32391
32392 static struct nes_cm_core *g_cm_core;
32393
32394 -atomic_t cm_connects;
32395 -atomic_t cm_accepts;
32396 -atomic_t cm_disconnects;
32397 -atomic_t cm_closes;
32398 -atomic_t cm_connecteds;
32399 -atomic_t cm_connect_reqs;
32400 -atomic_t cm_rejects;
32401 +atomic_unchecked_t cm_connects;
32402 +atomic_unchecked_t cm_accepts;
32403 +atomic_unchecked_t cm_disconnects;
32404 +atomic_unchecked_t cm_closes;
32405 +atomic_unchecked_t cm_connecteds;
32406 +atomic_unchecked_t cm_connect_reqs;
32407 +atomic_unchecked_t cm_rejects;
32408
32409 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32410 {
32411 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32412 kfree(listener);
32413 listener = NULL;
32414 ret = 0;
32415 - atomic_inc(&cm_listens_destroyed);
32416 + atomic_inc_unchecked(&cm_listens_destroyed);
32417 } else {
32418 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32419 }
32420 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32421 cm_node->rem_mac);
32422
32423 add_hte_node(cm_core, cm_node);
32424 - atomic_inc(&cm_nodes_created);
32425 + atomic_inc_unchecked(&cm_nodes_created);
32426
32427 return cm_node;
32428 }
32429 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32430 }
32431
32432 atomic_dec(&cm_core->node_cnt);
32433 - atomic_inc(&cm_nodes_destroyed);
32434 + atomic_inc_unchecked(&cm_nodes_destroyed);
32435 nesqp = cm_node->nesqp;
32436 if (nesqp) {
32437 nesqp->cm_node = NULL;
32438 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32439
32440 static void drop_packet(struct sk_buff *skb)
32441 {
32442 - atomic_inc(&cm_accel_dropped_pkts);
32443 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32444 dev_kfree_skb_any(skb);
32445 }
32446
32447 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32448 {
32449
32450 int reset = 0; /* whether to send reset in case of err.. */
32451 - atomic_inc(&cm_resets_recvd);
32452 + atomic_inc_unchecked(&cm_resets_recvd);
32453 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32454 " refcnt=%d\n", cm_node, cm_node->state,
32455 atomic_read(&cm_node->ref_count));
32456 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32457 rem_ref_cm_node(cm_node->cm_core, cm_node);
32458 return NULL;
32459 }
32460 - atomic_inc(&cm_loopbacks);
32461 + atomic_inc_unchecked(&cm_loopbacks);
32462 loopbackremotenode->loopbackpartner = cm_node;
32463 loopbackremotenode->tcp_cntxt.rcv_wscale =
32464 NES_CM_DEFAULT_RCV_WND_SCALE;
32465 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32466 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32467 else {
32468 rem_ref_cm_node(cm_core, cm_node);
32469 - atomic_inc(&cm_accel_dropped_pkts);
32470 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32471 dev_kfree_skb_any(skb);
32472 }
32473 break;
32474 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32475
32476 if ((cm_id) && (cm_id->event_handler)) {
32477 if (issue_disconn) {
32478 - atomic_inc(&cm_disconnects);
32479 + atomic_inc_unchecked(&cm_disconnects);
32480 cm_event.event = IW_CM_EVENT_DISCONNECT;
32481 cm_event.status = disconn_status;
32482 cm_event.local_addr = cm_id->local_addr;
32483 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32484 }
32485
32486 if (issue_close) {
32487 - atomic_inc(&cm_closes);
32488 + atomic_inc_unchecked(&cm_closes);
32489 nes_disconnect(nesqp, 1);
32490
32491 cm_id->provider_data = nesqp;
32492 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32493
32494 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32495 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32496 - atomic_inc(&cm_accepts);
32497 + atomic_inc_unchecked(&cm_accepts);
32498
32499 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32500 netdev_refcnt_read(nesvnic->netdev));
32501 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32502 struct nes_cm_core *cm_core;
32503 u8 *start_buff;
32504
32505 - atomic_inc(&cm_rejects);
32506 + atomic_inc_unchecked(&cm_rejects);
32507 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32508 loopback = cm_node->loopbackpartner;
32509 cm_core = cm_node->cm_core;
32510 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32511 ntohl(cm_id->local_addr.sin_addr.s_addr),
32512 ntohs(cm_id->local_addr.sin_port));
32513
32514 - atomic_inc(&cm_connects);
32515 + atomic_inc_unchecked(&cm_connects);
32516 nesqp->active_conn = 1;
32517
32518 /* cache the cm_id in the qp */
32519 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32520 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32521 return err;
32522 }
32523 - atomic_inc(&cm_listens_created);
32524 + atomic_inc_unchecked(&cm_listens_created);
32525 }
32526
32527 cm_id->add_ref(cm_id);
32528 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32529
32530 if (nesqp->destroyed)
32531 return;
32532 - atomic_inc(&cm_connecteds);
32533 + atomic_inc_unchecked(&cm_connecteds);
32534 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32535 " local port 0x%04X. jiffies = %lu.\n",
32536 nesqp->hwqp.qp_id,
32537 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32538
32539 cm_id->add_ref(cm_id);
32540 ret = cm_id->event_handler(cm_id, &cm_event);
32541 - atomic_inc(&cm_closes);
32542 + atomic_inc_unchecked(&cm_closes);
32543 cm_event.event = IW_CM_EVENT_CLOSE;
32544 cm_event.status = 0;
32545 cm_event.provider_data = cm_id->provider_data;
32546 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32547 return;
32548 cm_id = cm_node->cm_id;
32549
32550 - atomic_inc(&cm_connect_reqs);
32551 + atomic_inc_unchecked(&cm_connect_reqs);
32552 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32553 cm_node, cm_id, jiffies);
32554
32555 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32556 return;
32557 cm_id = cm_node->cm_id;
32558
32559 - atomic_inc(&cm_connect_reqs);
32560 + atomic_inc_unchecked(&cm_connect_reqs);
32561 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32562 cm_node, cm_id, jiffies);
32563
32564 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32565 index 3ba7be3..c81f6ff 100644
32566 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32567 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32568 @@ -40,8 +40,8 @@
32569 #include "nes.h"
32570 #include "nes_mgt.h"
32571
32572 -atomic_t pau_qps_created;
32573 -atomic_t pau_qps_destroyed;
32574 +atomic_unchecked_t pau_qps_created;
32575 +atomic_unchecked_t pau_qps_destroyed;
32576
32577 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32578 {
32579 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32580 {
32581 struct sk_buff *skb;
32582 unsigned long flags;
32583 - atomic_inc(&pau_qps_destroyed);
32584 + atomic_inc_unchecked(&pau_qps_destroyed);
32585
32586 /* Free packets that have not yet been forwarded */
32587 /* Lock is acquired by skb_dequeue when removing the skb */
32588 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32589 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32590 skb_queue_head_init(&nesqp->pau_list);
32591 spin_lock_init(&nesqp->pau_lock);
32592 - atomic_inc(&pau_qps_created);
32593 + atomic_inc_unchecked(&pau_qps_created);
32594 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32595 }
32596
32597 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32598 index f3a3ecf..57d311d 100644
32599 --- a/drivers/infiniband/hw/nes/nes_nic.c
32600 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32601 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32602 target_stat_values[++index] = mh_detected;
32603 target_stat_values[++index] = mh_pauses_sent;
32604 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32605 - target_stat_values[++index] = atomic_read(&cm_connects);
32606 - target_stat_values[++index] = atomic_read(&cm_accepts);
32607 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32608 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32609 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32610 - target_stat_values[++index] = atomic_read(&cm_rejects);
32611 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32612 - target_stat_values[++index] = atomic_read(&qps_created);
32613 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32614 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32615 - target_stat_values[++index] = atomic_read(&cm_closes);
32616 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32617 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32618 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32619 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32620 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32621 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32622 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32623 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32624 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32625 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32626 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32627 target_stat_values[++index] = cm_packets_sent;
32628 target_stat_values[++index] = cm_packets_bounced;
32629 target_stat_values[++index] = cm_packets_created;
32630 target_stat_values[++index] = cm_packets_received;
32631 target_stat_values[++index] = cm_packets_dropped;
32632 target_stat_values[++index] = cm_packets_retrans;
32633 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32634 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32635 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32636 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32637 target_stat_values[++index] = cm_backlog_drops;
32638 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32639 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32640 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32641 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32642 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32643 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32644 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32645 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32646 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32647 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32648 target_stat_values[++index] = nesadapter->free_4kpbl;
32649 target_stat_values[++index] = nesadapter->free_256pbl;
32650 target_stat_values[++index] = int_mod_timer_init;
32651 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32652 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32653 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32654 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32655 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32656 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32657 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32658 }
32659
32660 /**
32661 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32662 index 8b8812d..a5e1133 100644
32663 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32664 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32665 @@ -46,9 +46,9 @@
32666
32667 #include <rdma/ib_umem.h>
32668
32669 -atomic_t mod_qp_timouts;
32670 -atomic_t qps_created;
32671 -atomic_t sw_qps_destroyed;
32672 +atomic_unchecked_t mod_qp_timouts;
32673 +atomic_unchecked_t qps_created;
32674 +atomic_unchecked_t sw_qps_destroyed;
32675
32676 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32677
32678 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32679 if (init_attr->create_flags)
32680 return ERR_PTR(-EINVAL);
32681
32682 - atomic_inc(&qps_created);
32683 + atomic_inc_unchecked(&qps_created);
32684 switch (init_attr->qp_type) {
32685 case IB_QPT_RC:
32686 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32687 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32688 struct iw_cm_event cm_event;
32689 int ret = 0;
32690
32691 - atomic_inc(&sw_qps_destroyed);
32692 + atomic_inc_unchecked(&sw_qps_destroyed);
32693 nesqp->destroyed = 1;
32694
32695 /* Blow away the connection if it exists. */
32696 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32697 index 7e62f41..4c2b8e2 100644
32698 --- a/drivers/infiniband/hw/qib/qib.h
32699 +++ b/drivers/infiniband/hw/qib/qib.h
32700 @@ -51,6 +51,7 @@
32701 #include <linux/completion.h>
32702 #include <linux/kref.h>
32703 #include <linux/sched.h>
32704 +#include <linux/slab.h>
32705
32706 #include "qib_common.h"
32707 #include "qib_verbs.h"
32708 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32709 index da739d9..da1c7f4 100644
32710 --- a/drivers/input/gameport/gameport.c
32711 +++ b/drivers/input/gameport/gameport.c
32712 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32713 */
32714 static void gameport_init_port(struct gameport *gameport)
32715 {
32716 - static atomic_t gameport_no = ATOMIC_INIT(0);
32717 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32718
32719 __module_get(THIS_MODULE);
32720
32721 mutex_init(&gameport->drv_mutex);
32722 device_initialize(&gameport->dev);
32723 dev_set_name(&gameport->dev, "gameport%lu",
32724 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32725 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32726 gameport->dev.bus = &gameport_bus;
32727 gameport->dev.release = gameport_release_port;
32728 if (gameport->parent)
32729 diff --git a/drivers/input/input.c b/drivers/input/input.c
32730 index 8921c61..f5cd63d 100644
32731 --- a/drivers/input/input.c
32732 +++ b/drivers/input/input.c
32733 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32734 */
32735 int input_register_device(struct input_dev *dev)
32736 {
32737 - static atomic_t input_no = ATOMIC_INIT(0);
32738 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32739 struct input_handler *handler;
32740 const char *path;
32741 int error;
32742 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32743 dev->setkeycode = input_default_setkeycode;
32744
32745 dev_set_name(&dev->dev, "input%ld",
32746 - (unsigned long) atomic_inc_return(&input_no) - 1);
32747 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32748
32749 error = device_add(&dev->dev);
32750 if (error)
32751 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32752 index 04c69af..5f92d00 100644
32753 --- a/drivers/input/joystick/sidewinder.c
32754 +++ b/drivers/input/joystick/sidewinder.c
32755 @@ -30,6 +30,7 @@
32756 #include <linux/kernel.h>
32757 #include <linux/module.h>
32758 #include <linux/slab.h>
32759 +#include <linux/sched.h>
32760 #include <linux/init.h>
32761 #include <linux/input.h>
32762 #include <linux/gameport.h>
32763 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32764 index 83811e4..0822b90 100644
32765 --- a/drivers/input/joystick/xpad.c
32766 +++ b/drivers/input/joystick/xpad.c
32767 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32768
32769 static int xpad_led_probe(struct usb_xpad *xpad)
32770 {
32771 - static atomic_t led_seq = ATOMIC_INIT(0);
32772 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32773 long led_no;
32774 struct xpad_led *led;
32775 struct led_classdev *led_cdev;
32776 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32777 if (!led)
32778 return -ENOMEM;
32779
32780 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32781 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32782
32783 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32784 led->xpad = xpad;
32785 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32786 index 0110b5a..d3ad144 100644
32787 --- a/drivers/input/mousedev.c
32788 +++ b/drivers/input/mousedev.c
32789 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32790
32791 spin_unlock_irq(&client->packet_lock);
32792
32793 - if (copy_to_user(buffer, data, count))
32794 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32795 return -EFAULT;
32796
32797 return count;
32798 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32799 index d0f7533..fb8215b 100644
32800 --- a/drivers/input/serio/serio.c
32801 +++ b/drivers/input/serio/serio.c
32802 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32803 */
32804 static void serio_init_port(struct serio *serio)
32805 {
32806 - static atomic_t serio_no = ATOMIC_INIT(0);
32807 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32808
32809 __module_get(THIS_MODULE);
32810
32811 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32812 mutex_init(&serio->drv_mutex);
32813 device_initialize(&serio->dev);
32814 dev_set_name(&serio->dev, "serio%ld",
32815 - (long)atomic_inc_return(&serio_no) - 1);
32816 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32817 serio->dev.bus = &serio_bus;
32818 serio->dev.release = serio_release_port;
32819 serio->dev.groups = serio_device_attr_groups;
32820 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32821 index 38c4bd8..58965d9 100644
32822 --- a/drivers/isdn/capi/capi.c
32823 +++ b/drivers/isdn/capi/capi.c
32824 @@ -83,8 +83,8 @@ struct capiminor {
32825
32826 struct capi20_appl *ap;
32827 u32 ncci;
32828 - atomic_t datahandle;
32829 - atomic_t msgid;
32830 + atomic_unchecked_t datahandle;
32831 + atomic_unchecked_t msgid;
32832
32833 struct tty_port port;
32834 int ttyinstop;
32835 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32836 capimsg_setu16(s, 2, mp->ap->applid);
32837 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32838 capimsg_setu8 (s, 5, CAPI_RESP);
32839 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32840 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32841 capimsg_setu32(s, 8, mp->ncci);
32842 capimsg_setu16(s, 12, datahandle);
32843 }
32844 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32845 mp->outbytes -= len;
32846 spin_unlock_bh(&mp->outlock);
32847
32848 - datahandle = atomic_inc_return(&mp->datahandle);
32849 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32850 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32851 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32852 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32853 capimsg_setu16(skb->data, 2, mp->ap->applid);
32854 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32855 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32856 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32857 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32858 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32859 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32860 capimsg_setu16(skb->data, 16, len); /* Data length */
32861 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32862 index a6d9fd2..afdb8a3 100644
32863 --- a/drivers/isdn/gigaset/interface.c
32864 +++ b/drivers/isdn/gigaset/interface.c
32865 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32866 }
32867 tty->driver_data = cs;
32868
32869 - ++cs->port.count;
32870 + atomic_inc(&cs->port.count);
32871
32872 - if (cs->port.count == 1) {
32873 + if (atomic_read(&cs->port.count) == 1) {
32874 tty_port_tty_set(&cs->port, tty);
32875 tty->low_latency = 1;
32876 }
32877 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32878
32879 if (!cs->connected)
32880 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32881 - else if (!cs->port.count)
32882 + else if (!atomic_read(&cs->port.count))
32883 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32884 - else if (!--cs->port.count)
32885 + else if (!atomic_dec_return(&cs->port.count))
32886 tty_port_tty_set(&cs->port, NULL);
32887
32888 mutex_unlock(&cs->mutex);
32889 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32890 index 821f7ac..28d4030 100644
32891 --- a/drivers/isdn/hardware/avm/b1.c
32892 +++ b/drivers/isdn/hardware/avm/b1.c
32893 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32894 }
32895 if (left) {
32896 if (t4file->user) {
32897 - if (copy_from_user(buf, dp, left))
32898 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32899 return -EFAULT;
32900 } else {
32901 memcpy(buf, dp, left);
32902 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32903 }
32904 if (left) {
32905 if (config->user) {
32906 - if (copy_from_user(buf, dp, left))
32907 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32908 return -EFAULT;
32909 } else {
32910 memcpy(buf, dp, left);
32911 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32912 index dd6b53a..19d9ee6 100644
32913 --- a/drivers/isdn/hardware/eicon/divasync.h
32914 +++ b/drivers/isdn/hardware/eicon/divasync.h
32915 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32916 } diva_didd_add_adapter_t;
32917 typedef struct _diva_didd_remove_adapter {
32918 IDI_CALL p_request;
32919 -} diva_didd_remove_adapter_t;
32920 +} __no_const diva_didd_remove_adapter_t;
32921 typedef struct _diva_didd_read_adapter_array {
32922 void *buffer;
32923 dword length;
32924 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32925 index d303e65..28bcb7b 100644
32926 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32927 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32928 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32929 typedef struct _diva_os_idi_adapter_interface {
32930 diva_init_card_proc_t cleanup_adapter_proc;
32931 diva_cmd_card_proc_t cmd_proc;
32932 -} diva_os_idi_adapter_interface_t;
32933 +} __no_const diva_os_idi_adapter_interface_t;
32934
32935 typedef struct _diva_os_xdi_adapter {
32936 struct list_head link;
32937 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32938 index 7bc5067..fd36232 100644
32939 --- a/drivers/isdn/i4l/isdn_tty.c
32940 +++ b/drivers/isdn/i4l/isdn_tty.c
32941 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32942 port = &info->port;
32943 #ifdef ISDN_DEBUG_MODEM_OPEN
32944 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32945 - port->count);
32946 + atomic_read(&port->count))
32947 #endif
32948 - port->count++;
32949 + atomic_inc(&port->count);
32950 tty->driver_data = info;
32951 port->tty = tty;
32952 tty->port = port;
32953 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32954 #endif
32955 return;
32956 }
32957 - if ((tty->count == 1) && (port->count != 1)) {
32958 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32959 /*
32960 * Uh, oh. tty->count is 1, which means that the tty
32961 * structure will be freed. Info->count should always
32962 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32963 * serial port won't be shutdown.
32964 */
32965 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32966 - "info->count is %d\n", port->count);
32967 - port->count = 1;
32968 + "info->count is %d\n", atomic_read(&port->count));
32969 + atomic_set(&port->count, 1);
32970 }
32971 - if (--port->count < 0) {
32972 + if (atomic_dec_return(&port->count) < 0) {
32973 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32974 - info->line, port->count);
32975 - port->count = 0;
32976 + info->line, atomic_read(&port->count));
32977 + atomic_set(&port->count, 0);
32978 }
32979 - if (port->count) {
32980 + if (atomic_read(&port->count)) {
32981 #ifdef ISDN_DEBUG_MODEM_OPEN
32982 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32983 #endif
32984 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32985 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32986 return;
32987 isdn_tty_shutdown(info);
32988 - port->count = 0;
32989 + atomic_set(&port->count, 0);
32990 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32991 port->tty = NULL;
32992 wake_up_interruptible(&port->open_wait);
32993 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32994 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32995 modem_info *info = &dev->mdm.info[i];
32996
32997 - if (info->port.count == 0)
32998 + if (atomic_read(&info->port.count) == 0)
32999 continue;
33000 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33001 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33002 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33003 index e74df7c..03a03ba 100644
33004 --- a/drivers/isdn/icn/icn.c
33005 +++ b/drivers/isdn/icn/icn.c
33006 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33007 if (count > len)
33008 count = len;
33009 if (user) {
33010 - if (copy_from_user(msg, buf, count))
33011 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33012 return -EFAULT;
33013 } else
33014 memcpy(msg, buf, count);
33015 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33016 index b5fdcb7..5b6c59f 100644
33017 --- a/drivers/lguest/core.c
33018 +++ b/drivers/lguest/core.c
33019 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33020 * it's worked so far. The end address needs +1 because __get_vm_area
33021 * allocates an extra guard page, so we need space for that.
33022 */
33023 +
33024 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33025 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33026 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33027 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33028 +#else
33029 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33030 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33031 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33032 +#endif
33033 +
33034 if (!switcher_vma) {
33035 err = -ENOMEM;
33036 printk("lguest: could not map switcher pages high\n");
33037 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33038 * Now the Switcher is mapped at the right address, we can't fail!
33039 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33040 */
33041 - memcpy(switcher_vma->addr, start_switcher_text,
33042 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33043 end_switcher_text - start_switcher_text);
33044
33045 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33046 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33047 index 39809035..ce25c5e 100644
33048 --- a/drivers/lguest/x86/core.c
33049 +++ b/drivers/lguest/x86/core.c
33050 @@ -59,7 +59,7 @@ static struct {
33051 /* Offset from where switcher.S was compiled to where we've copied it */
33052 static unsigned long switcher_offset(void)
33053 {
33054 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33055 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33056 }
33057
33058 /* This cpu's struct lguest_pages. */
33059 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33060 * These copies are pretty cheap, so we do them unconditionally: */
33061 /* Save the current Host top-level page directory.
33062 */
33063 +
33064 +#ifdef CONFIG_PAX_PER_CPU_PGD
33065 + pages->state.host_cr3 = read_cr3();
33066 +#else
33067 pages->state.host_cr3 = __pa(current->mm->pgd);
33068 +#endif
33069 +
33070 /*
33071 * Set up the Guest's page tables to see this CPU's pages (and no
33072 * other CPU's pages).
33073 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33074 * compiled-in switcher code and the high-mapped copy we just made.
33075 */
33076 for (i = 0; i < IDT_ENTRIES; i++)
33077 - default_idt_entries[i] += switcher_offset();
33078 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33079
33080 /*
33081 * Set up the Switcher's per-cpu areas.
33082 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33083 * it will be undisturbed when we switch. To change %cs and jump we
33084 * need this structure to feed to Intel's "lcall" instruction.
33085 */
33086 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33087 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33088 lguest_entry.segment = LGUEST_CS;
33089
33090 /*
33091 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33092 index 40634b0..4f5855e 100644
33093 --- a/drivers/lguest/x86/switcher_32.S
33094 +++ b/drivers/lguest/x86/switcher_32.S
33095 @@ -87,6 +87,7 @@
33096 #include <asm/page.h>
33097 #include <asm/segment.h>
33098 #include <asm/lguest.h>
33099 +#include <asm/processor-flags.h>
33100
33101 // We mark the start of the code to copy
33102 // It's placed in .text tho it's never run here
33103 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33104 // Changes type when we load it: damn Intel!
33105 // For after we switch over our page tables
33106 // That entry will be read-only: we'd crash.
33107 +
33108 +#ifdef CONFIG_PAX_KERNEXEC
33109 + mov %cr0, %edx
33110 + xor $X86_CR0_WP, %edx
33111 + mov %edx, %cr0
33112 +#endif
33113 +
33114 movl $(GDT_ENTRY_TSS*8), %edx
33115 ltr %dx
33116
33117 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33118 // Let's clear it again for our return.
33119 // The GDT descriptor of the Host
33120 // Points to the table after two "size" bytes
33121 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33122 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33123 // Clear "used" from type field (byte 5, bit 2)
33124 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33125 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33126 +
33127 +#ifdef CONFIG_PAX_KERNEXEC
33128 + mov %cr0, %eax
33129 + xor $X86_CR0_WP, %eax
33130 + mov %eax, %cr0
33131 +#endif
33132
33133 // Once our page table's switched, the Guest is live!
33134 // The Host fades as we run this final step.
33135 @@ -295,13 +309,12 @@ deliver_to_host:
33136 // I consulted gcc, and it gave
33137 // These instructions, which I gladly credit:
33138 leal (%edx,%ebx,8), %eax
33139 - movzwl (%eax),%edx
33140 - movl 4(%eax), %eax
33141 - xorw %ax, %ax
33142 - orl %eax, %edx
33143 + movl 4(%eax), %edx
33144 + movw (%eax), %dx
33145 // Now the address of the handler's in %edx
33146 // We call it now: its "iret" drops us home.
33147 - jmp *%edx
33148 + ljmp $__KERNEL_CS, $1f
33149 +1: jmp *%edx
33150
33151 // Every interrupt can come to us here
33152 // But we must truly tell each apart.
33153 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33154 index 20e5c2c..9e849a9 100644
33155 --- a/drivers/macintosh/macio_asic.c
33156 +++ b/drivers/macintosh/macio_asic.c
33157 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33158 * MacIO is matched against any Apple ID, it's probe() function
33159 * will then decide wether it applies or not
33160 */
33161 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33162 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33163 .vendor = PCI_VENDOR_ID_APPLE,
33164 .device = PCI_ANY_ID,
33165 .subvendor = PCI_ANY_ID,
33166 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33167 index 15dbe03..743fc65 100644
33168 --- a/drivers/md/bitmap.c
33169 +++ b/drivers/md/bitmap.c
33170 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33171 chunk_kb ? "KB" : "B");
33172 if (bitmap->storage.file) {
33173 seq_printf(seq, ", file: ");
33174 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33175 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33176 }
33177
33178 seq_printf(seq, "\n");
33179 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33180 index a1a3e6d..1918bfc 100644
33181 --- a/drivers/md/dm-ioctl.c
33182 +++ b/drivers/md/dm-ioctl.c
33183 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33184 cmd == DM_LIST_VERSIONS_CMD)
33185 return 0;
33186
33187 - if ((cmd == DM_DEV_CREATE_CMD)) {
33188 + if (cmd == DM_DEV_CREATE_CMD) {
33189 if (!*param->name) {
33190 DMWARN("name not supplied when creating device");
33191 return -EINVAL;
33192 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33193 index b58b7a3..8018b19 100644
33194 --- a/drivers/md/dm-raid1.c
33195 +++ b/drivers/md/dm-raid1.c
33196 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33197
33198 struct mirror {
33199 struct mirror_set *ms;
33200 - atomic_t error_count;
33201 + atomic_unchecked_t error_count;
33202 unsigned long error_type;
33203 struct dm_dev *dev;
33204 sector_t offset;
33205 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33206 struct mirror *m;
33207
33208 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33209 - if (!atomic_read(&m->error_count))
33210 + if (!atomic_read_unchecked(&m->error_count))
33211 return m;
33212
33213 return NULL;
33214 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33215 * simple way to tell if a device has encountered
33216 * errors.
33217 */
33218 - atomic_inc(&m->error_count);
33219 + atomic_inc_unchecked(&m->error_count);
33220
33221 if (test_and_set_bit(error_type, &m->error_type))
33222 return;
33223 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33224 struct mirror *m = get_default_mirror(ms);
33225
33226 do {
33227 - if (likely(!atomic_read(&m->error_count)))
33228 + if (likely(!atomic_read_unchecked(&m->error_count)))
33229 return m;
33230
33231 if (m-- == ms->mirror)
33232 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33233 {
33234 struct mirror *default_mirror = get_default_mirror(m->ms);
33235
33236 - return !atomic_read(&default_mirror->error_count);
33237 + return !atomic_read_unchecked(&default_mirror->error_count);
33238 }
33239
33240 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33241 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33242 */
33243 if (likely(region_in_sync(ms, region, 1)))
33244 m = choose_mirror(ms, bio->bi_sector);
33245 - else if (m && atomic_read(&m->error_count))
33246 + else if (m && atomic_read_unchecked(&m->error_count))
33247 m = NULL;
33248
33249 if (likely(m))
33250 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33251 }
33252
33253 ms->mirror[mirror].ms = ms;
33254 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33255 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33256 ms->mirror[mirror].error_type = 0;
33257 ms->mirror[mirror].offset = offset;
33258
33259 @@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33260 */
33261 static char device_status_char(struct mirror *m)
33262 {
33263 - if (!atomic_read(&(m->error_count)))
33264 + if (!atomic_read_unchecked(&(m->error_count)))
33265 return 'A';
33266
33267 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33268 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33269 index 35c94ff..20d4c17 100644
33270 --- a/drivers/md/dm-stripe.c
33271 +++ b/drivers/md/dm-stripe.c
33272 @@ -20,7 +20,7 @@ struct stripe {
33273 struct dm_dev *dev;
33274 sector_t physical_start;
33275
33276 - atomic_t error_count;
33277 + atomic_unchecked_t error_count;
33278 };
33279
33280 struct stripe_c {
33281 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33282 kfree(sc);
33283 return r;
33284 }
33285 - atomic_set(&(sc->stripe[i].error_count), 0);
33286 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33287 }
33288
33289 ti->private = sc;
33290 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33291 DMEMIT("%d ", sc->stripes);
33292 for (i = 0; i < sc->stripes; i++) {
33293 DMEMIT("%s ", sc->stripe[i].dev->name);
33294 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33295 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33296 'D' : 'A';
33297 }
33298 buffer[i] = '\0';
33299 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33300 */
33301 for (i = 0; i < sc->stripes; i++)
33302 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33303 - atomic_inc(&(sc->stripe[i].error_count));
33304 - if (atomic_read(&(sc->stripe[i].error_count)) <
33305 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33306 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33307 DM_IO_ERROR_THRESHOLD)
33308 schedule_work(&sc->trigger_event);
33309 }
33310 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33311 index 2e227fb..44ead1f 100644
33312 --- a/drivers/md/dm-table.c
33313 +++ b/drivers/md/dm-table.c
33314 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33315 if (!dev_size)
33316 return 0;
33317
33318 - if ((start >= dev_size) || (start + len > dev_size)) {
33319 + if ((start >= dev_size) || (len > dev_size - start)) {
33320 DMWARN("%s: %s too small for target: "
33321 "start=%llu, len=%llu, dev_size=%llu",
33322 dm_device_name(ti->table->md), bdevname(bdev, b),
33323 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33324 index 3e2907f..c28851a 100644
33325 --- a/drivers/md/dm-thin-metadata.c
33326 +++ b/drivers/md/dm-thin-metadata.c
33327 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33328
33329 pmd->info.tm = tm;
33330 pmd->info.levels = 2;
33331 - pmd->info.value_type.context = pmd->data_sm;
33332 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33333 pmd->info.value_type.size = sizeof(__le64);
33334 pmd->info.value_type.inc = data_block_inc;
33335 pmd->info.value_type.dec = data_block_dec;
33336 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33337
33338 pmd->bl_info.tm = tm;
33339 pmd->bl_info.levels = 1;
33340 - pmd->bl_info.value_type.context = pmd->data_sm;
33341 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33342 pmd->bl_info.value_type.size = sizeof(__le64);
33343 pmd->bl_info.value_type.inc = data_block_inc;
33344 pmd->bl_info.value_type.dec = data_block_dec;
33345 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33346 index e24143c..ce2f21a1 100644
33347 --- a/drivers/md/dm.c
33348 +++ b/drivers/md/dm.c
33349 @@ -176,9 +176,9 @@ struct mapped_device {
33350 /*
33351 * Event handling.
33352 */
33353 - atomic_t event_nr;
33354 + atomic_unchecked_t event_nr;
33355 wait_queue_head_t eventq;
33356 - atomic_t uevent_seq;
33357 + atomic_unchecked_t uevent_seq;
33358 struct list_head uevent_list;
33359 spinlock_t uevent_lock; /* Protect access to uevent_list */
33360
33361 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33362 rwlock_init(&md->map_lock);
33363 atomic_set(&md->holders, 1);
33364 atomic_set(&md->open_count, 0);
33365 - atomic_set(&md->event_nr, 0);
33366 - atomic_set(&md->uevent_seq, 0);
33367 + atomic_set_unchecked(&md->event_nr, 0);
33368 + atomic_set_unchecked(&md->uevent_seq, 0);
33369 INIT_LIST_HEAD(&md->uevent_list);
33370 spin_lock_init(&md->uevent_lock);
33371
33372 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33373
33374 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33375
33376 - atomic_inc(&md->event_nr);
33377 + atomic_inc_unchecked(&md->event_nr);
33378 wake_up(&md->eventq);
33379 }
33380
33381 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33382
33383 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33384 {
33385 - return atomic_add_return(1, &md->uevent_seq);
33386 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33387 }
33388
33389 uint32_t dm_get_event_nr(struct mapped_device *md)
33390 {
33391 - return atomic_read(&md->event_nr);
33392 + return atomic_read_unchecked(&md->event_nr);
33393 }
33394
33395 int dm_wait_event(struct mapped_device *md, int event_nr)
33396 {
33397 return wait_event_interruptible(md->eventq,
33398 - (event_nr != atomic_read(&md->event_nr)));
33399 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33400 }
33401
33402 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33403 diff --git a/drivers/md/md.c b/drivers/md/md.c
33404 index d5ab449..7e9ed7b 100644
33405 --- a/drivers/md/md.c
33406 +++ b/drivers/md/md.c
33407 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33408 * start build, activate spare
33409 */
33410 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33411 -static atomic_t md_event_count;
33412 +static atomic_unchecked_t md_event_count;
33413 void md_new_event(struct mddev *mddev)
33414 {
33415 - atomic_inc(&md_event_count);
33416 + atomic_inc_unchecked(&md_event_count);
33417 wake_up(&md_event_waiters);
33418 }
33419 EXPORT_SYMBOL_GPL(md_new_event);
33420 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33421 */
33422 static void md_new_event_inintr(struct mddev *mddev)
33423 {
33424 - atomic_inc(&md_event_count);
33425 + atomic_inc_unchecked(&md_event_count);
33426 wake_up(&md_event_waiters);
33427 }
33428
33429 @@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33430 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33431 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33432 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33433 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33434 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33435
33436 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33437 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33438 @@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33439 else
33440 sb->resync_offset = cpu_to_le64(0);
33441
33442 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33443 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33444
33445 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33446 sb->size = cpu_to_le64(mddev->dev_sectors);
33447 @@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33448 static ssize_t
33449 errors_show(struct md_rdev *rdev, char *page)
33450 {
33451 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33452 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33453 }
33454
33455 static ssize_t
33456 @@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33457 char *e;
33458 unsigned long n = simple_strtoul(buf, &e, 10);
33459 if (*buf && (*e == 0 || *e == '\n')) {
33460 - atomic_set(&rdev->corrected_errors, n);
33461 + atomic_set_unchecked(&rdev->corrected_errors, n);
33462 return len;
33463 }
33464 return -EINVAL;
33465 @@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33466 rdev->sb_loaded = 0;
33467 rdev->bb_page = NULL;
33468 atomic_set(&rdev->nr_pending, 0);
33469 - atomic_set(&rdev->read_errors, 0);
33470 - atomic_set(&rdev->corrected_errors, 0);
33471 + atomic_set_unchecked(&rdev->read_errors, 0);
33472 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33473
33474 INIT_LIST_HEAD(&rdev->same_set);
33475 init_waitqueue_head(&rdev->blocked_wait);
33476 @@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33477
33478 spin_unlock(&pers_lock);
33479 seq_printf(seq, "\n");
33480 - seq->poll_event = atomic_read(&md_event_count);
33481 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33482 return 0;
33483 }
33484 if (v == (void*)2) {
33485 @@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33486 return error;
33487
33488 seq = file->private_data;
33489 - seq->poll_event = atomic_read(&md_event_count);
33490 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33491 return error;
33492 }
33493
33494 @@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33495 /* always allow read */
33496 mask = POLLIN | POLLRDNORM;
33497
33498 - if (seq->poll_event != atomic_read(&md_event_count))
33499 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33500 mask |= POLLERR | POLLPRI;
33501 return mask;
33502 }
33503 @@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33504 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33505 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33506 (int)part_stat_read(&disk->part0, sectors[1]) -
33507 - atomic_read(&disk->sync_io);
33508 + atomic_read_unchecked(&disk->sync_io);
33509 /* sync IO will cause sync_io to increase before the disk_stats
33510 * as sync_io is counted when a request starts, and
33511 * disk_stats is counted when it completes.
33512 diff --git a/drivers/md/md.h b/drivers/md/md.h
33513 index 7b4a3c3..994ad4f 100644
33514 --- a/drivers/md/md.h
33515 +++ b/drivers/md/md.h
33516 @@ -94,13 +94,13 @@ struct md_rdev {
33517 * only maintained for arrays that
33518 * support hot removal
33519 */
33520 - atomic_t read_errors; /* number of consecutive read errors that
33521 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33522 * we have tried to ignore.
33523 */
33524 struct timespec last_read_error; /* monotonic time since our
33525 * last read error
33526 */
33527 - atomic_t corrected_errors; /* number of corrected read errors,
33528 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33529 * for reporting to userspace and storing
33530 * in superblock.
33531 */
33532 @@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33533
33534 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33535 {
33536 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33537 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33538 }
33539
33540 struct md_personality
33541 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33542 index fc90c11..c8cd9a9 100644
33543 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33544 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33545 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33546 /*----------------------------------------------------------------*/
33547
33548 struct sm_checker {
33549 - struct dm_space_map sm;
33550 + dm_space_map_no_const sm;
33551
33552 struct count_array old_counts;
33553 struct count_array counts;
33554 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33555 index 3d0ed53..35dc592 100644
33556 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33557 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33558 @@ -23,7 +23,7 @@
33559 * Space map interface.
33560 */
33561 struct sm_disk {
33562 - struct dm_space_map sm;
33563 + dm_space_map_no_const sm;
33564
33565 struct ll_disk ll;
33566 struct ll_disk old_ll;
33567 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33568 index e89ae5e..062e4c2 100644
33569 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33570 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33571 @@ -43,7 +43,7 @@ struct block_op {
33572 };
33573
33574 struct sm_metadata {
33575 - struct dm_space_map sm;
33576 + dm_space_map_no_const sm;
33577
33578 struct ll_disk ll;
33579 struct ll_disk old_ll;
33580 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33581 index 1cbfc6b..56e1dbb 100644
33582 --- a/drivers/md/persistent-data/dm-space-map.h
33583 +++ b/drivers/md/persistent-data/dm-space-map.h
33584 @@ -60,6 +60,7 @@ struct dm_space_map {
33585 int (*root_size)(struct dm_space_map *sm, size_t *result);
33586 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33587 };
33588 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33589
33590 /*----------------------------------------------------------------*/
33591
33592 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33593 index 53aec45..250851c 100644
33594 --- a/drivers/md/raid1.c
33595 +++ b/drivers/md/raid1.c
33596 @@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33597 if (r1_sync_page_io(rdev, sect, s,
33598 bio->bi_io_vec[idx].bv_page,
33599 READ) != 0)
33600 - atomic_add(s, &rdev->corrected_errors);
33601 + atomic_add_unchecked(s, &rdev->corrected_errors);
33602 }
33603 sectors -= s;
33604 sect += s;
33605 @@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33606 test_bit(In_sync, &rdev->flags)) {
33607 if (r1_sync_page_io(rdev, sect, s,
33608 conf->tmppage, READ)) {
33609 - atomic_add(s, &rdev->corrected_errors);
33610 + atomic_add_unchecked(s, &rdev->corrected_errors);
33611 printk(KERN_INFO
33612 "md/raid1:%s: read error corrected "
33613 "(%d sectors at %llu on %s)\n",
33614 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33615 index 8da6282..8ec7103 100644
33616 --- a/drivers/md/raid10.c
33617 +++ b/drivers/md/raid10.c
33618 @@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33619 /* The write handler will notice the lack of
33620 * R10BIO_Uptodate and record any errors etc
33621 */
33622 - atomic_add(r10_bio->sectors,
33623 + atomic_add_unchecked(r10_bio->sectors,
33624 &conf->mirrors[d].rdev->corrected_errors);
33625
33626 /* for reconstruct, we always reschedule after a read.
33627 @@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33628 {
33629 struct timespec cur_time_mon;
33630 unsigned long hours_since_last;
33631 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33632 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33633
33634 ktime_get_ts(&cur_time_mon);
33635
33636 @@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33637 * overflowing the shift of read_errors by hours_since_last.
33638 */
33639 if (hours_since_last >= 8 * sizeof(read_errors))
33640 - atomic_set(&rdev->read_errors, 0);
33641 + atomic_set_unchecked(&rdev->read_errors, 0);
33642 else
33643 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33644 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33645 }
33646
33647 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33648 @@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33649 return;
33650
33651 check_decay_read_errors(mddev, rdev);
33652 - atomic_inc(&rdev->read_errors);
33653 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33654 + atomic_inc_unchecked(&rdev->read_errors);
33655 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33656 char b[BDEVNAME_SIZE];
33657 bdevname(rdev->bdev, b);
33658
33659 @@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33660 "md/raid10:%s: %s: Raid device exceeded "
33661 "read_error threshold [cur %d:max %d]\n",
33662 mdname(mddev), b,
33663 - atomic_read(&rdev->read_errors), max_read_errors);
33664 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33665 printk(KERN_NOTICE
33666 "md/raid10:%s: %s: Failing raid device\n",
33667 mdname(mddev), b);
33668 @@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33669 sect +
33670 choose_data_offset(r10_bio, rdev)),
33671 bdevname(rdev->bdev, b));
33672 - atomic_add(s, &rdev->corrected_errors);
33673 + atomic_add_unchecked(s, &rdev->corrected_errors);
33674 }
33675
33676 rdev_dec_pending(rdev, mddev);
33677 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33678 index 04348d7..62a4b9b 100644
33679 --- a/drivers/md/raid5.c
33680 +++ b/drivers/md/raid5.c
33681 @@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33682 mdname(conf->mddev), STRIPE_SECTORS,
33683 (unsigned long long)s,
33684 bdevname(rdev->bdev, b));
33685 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33686 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33687 clear_bit(R5_ReadError, &sh->dev[i].flags);
33688 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33689 }
33690 - if (atomic_read(&rdev->read_errors))
33691 - atomic_set(&rdev->read_errors, 0);
33692 + if (atomic_read_unchecked(&rdev->read_errors))
33693 + atomic_set_unchecked(&rdev->read_errors, 0);
33694 } else {
33695 const char *bdn = bdevname(rdev->bdev, b);
33696 int retry = 0;
33697 int set_bad = 0;
33698
33699 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33700 - atomic_inc(&rdev->read_errors);
33701 + atomic_inc_unchecked(&rdev->read_errors);
33702 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33703 printk_ratelimited(
33704 KERN_WARNING
33705 @@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33706 mdname(conf->mddev),
33707 (unsigned long long)s,
33708 bdn);
33709 - } else if (atomic_read(&rdev->read_errors)
33710 + } else if (atomic_read_unchecked(&rdev->read_errors)
33711 > conf->max_nr_stripes)
33712 printk(KERN_WARNING
33713 "md/raid:%s: Too many read errors, failing device %s.\n",
33714 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33715 index 131b938..8572ed1 100644
33716 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33717 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33718 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33719 .subvendor = _subvend, .subdevice = _subdev, \
33720 .driver_data = (unsigned long)&_driverdata }
33721
33722 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33723 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33724 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33725 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33726 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33727 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33728 index fa7188a..04a045e 100644
33729 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33730 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33731 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33732 union {
33733 dmx_ts_cb ts;
33734 dmx_section_cb sec;
33735 - } cb;
33736 + } __no_const cb;
33737
33738 struct dvb_demux *demux;
33739 void *priv;
33740 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33741 index 39eab73..60033e7 100644
33742 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33743 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33744 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33745 const struct dvb_device *template, void *priv, int type)
33746 {
33747 struct dvb_device *dvbdev;
33748 - struct file_operations *dvbdevfops;
33749 + file_operations_no_const *dvbdevfops;
33750 struct device *clsdev;
33751 int minor;
33752 int id;
33753 diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33754 index 4008b9c..ce714f5 100644
33755 --- a/drivers/media/dvb/dvb-usb/az6007.c
33756 +++ b/drivers/media/dvb/dvb-usb/az6007.c
33757 @@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33758 int ret;
33759
33760 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33761 - memcpy(mac, st->data, sizeof(mac));
33762 + memcpy(mac, st->data, 6);
33763
33764 if (ret > 0)
33765 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33766 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33767 index 3940bb0..fb3952a 100644
33768 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33769 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33770 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33771
33772 struct dib0700_adapter_state {
33773 int (*set_param_save) (struct dvb_frontend *);
33774 -};
33775 +} __no_const;
33776
33777 static int dib7070_set_param_override(struct dvb_frontend *fe)
33778 {
33779 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33780 index 9382895..ac8093c 100644
33781 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33782 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33783 @@ -95,7 +95,7 @@ struct su3000_state {
33784
33785 struct s6x0_state {
33786 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33787 -};
33788 +} __no_const;
33789
33790 /* debug */
33791 static int dvb_usb_dw2102_debug;
33792 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33793 index 404f63a..4796533 100644
33794 --- a/drivers/media/dvb/frontends/dib3000.h
33795 +++ b/drivers/media/dvb/frontends/dib3000.h
33796 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33797 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33798 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33799 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33800 -};
33801 +} __no_const;
33802
33803 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33804 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33805 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33806 index 7539a5d..06531a6 100644
33807 --- a/drivers/media/dvb/ngene/ngene-cards.c
33808 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33809 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33810
33811 /****************************************************************************/
33812
33813 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33814 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33815 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33816 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33817 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33818 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33819 index 16a089f..1661b11 100644
33820 --- a/drivers/media/radio/radio-cadet.c
33821 +++ b/drivers/media/radio/radio-cadet.c
33822 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33823 unsigned char readbuf[RDS_BUFFER];
33824 int i = 0;
33825
33826 + if (count > RDS_BUFFER)
33827 + return -EFAULT;
33828 mutex_lock(&dev->lock);
33829 if (dev->rdsstat == 0) {
33830 dev->rdsstat = 1;
33831 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33832 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33833 mutex_unlock(&dev->lock);
33834
33835 - if (copy_to_user(data, readbuf, i))
33836 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33837 return -EFAULT;
33838 return i;
33839 }
33840 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33841 index 9cde353..8c6a1c3 100644
33842 --- a/drivers/media/video/au0828/au0828.h
33843 +++ b/drivers/media/video/au0828/au0828.h
33844 @@ -191,7 +191,7 @@ struct au0828_dev {
33845
33846 /* I2C */
33847 struct i2c_adapter i2c_adap;
33848 - struct i2c_algorithm i2c_algo;
33849 + i2c_algorithm_no_const i2c_algo;
33850 struct i2c_client i2c_client;
33851 u32 i2c_rc;
33852
33853 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33854 index 04bf662..e0ac026 100644
33855 --- a/drivers/media/video/cx88/cx88-alsa.c
33856 +++ b/drivers/media/video/cx88/cx88-alsa.c
33857 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33858 * Only boards with eeprom and byte 1 at eeprom=1 have it
33859 */
33860
33861 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33862 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33863 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33864 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33865 {0, }
33866 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33867 index 88cf9d9..bbc4b2c 100644
33868 --- a/drivers/media/video/omap/omap_vout.c
33869 +++ b/drivers/media/video/omap/omap_vout.c
33870 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33871 OMAP_VIDEO2,
33872 };
33873
33874 -static struct videobuf_queue_ops video_vbq_ops;
33875 /* Variables configurable through module params*/
33876 static u32 video1_numbuffers = 3;
33877 static u32 video2_numbuffers = 3;
33878 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33879 {
33880 struct videobuf_queue *q;
33881 struct omap_vout_device *vout = NULL;
33882 + static struct videobuf_queue_ops video_vbq_ops = {
33883 + .buf_setup = omap_vout_buffer_setup,
33884 + .buf_prepare = omap_vout_buffer_prepare,
33885 + .buf_release = omap_vout_buffer_release,
33886 + .buf_queue = omap_vout_buffer_queue,
33887 + };
33888
33889 vout = video_drvdata(file);
33890 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33891 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33892 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33893
33894 q = &vout->vbq;
33895 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33896 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33897 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33898 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33899 spin_lock_init(&vout->vbq_lock);
33900
33901 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33902 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33903 index 036952f..80d356d 100644
33904 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33905 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33906 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33907
33908 /* I2C stuff */
33909 struct i2c_adapter i2c_adap;
33910 - struct i2c_algorithm i2c_algo;
33911 + i2c_algorithm_no_const i2c_algo;
33912 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33913 int i2c_cx25840_hack_state;
33914 int i2c_linked;
33915 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33916 index 02194c0..091733b 100644
33917 --- a/drivers/media/video/timblogiw.c
33918 +++ b/drivers/media/video/timblogiw.c
33919 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33920
33921 /* Platform device functions */
33922
33923 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33924 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33925 .vidioc_querycap = timblogiw_querycap,
33926 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33927 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33928 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33929 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33930 };
33931
33932 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33933 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33934 .owner = THIS_MODULE,
33935 .open = timblogiw_open,
33936 .release = timblogiw_close,
33937 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33938 index d99db56..a16b959 100644
33939 --- a/drivers/message/fusion/mptbase.c
33940 +++ b/drivers/message/fusion/mptbase.c
33941 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33942 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33943 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33944
33945 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33946 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33947 +#else
33948 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33949 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33950 +#endif
33951 +
33952 /*
33953 * Rounding UP to nearest 4-kB boundary here...
33954 */
33955 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33956 index 551262e..7551198 100644
33957 --- a/drivers/message/fusion/mptsas.c
33958 +++ b/drivers/message/fusion/mptsas.c
33959 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33960 return 0;
33961 }
33962
33963 +static inline void
33964 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33965 +{
33966 + if (phy_info->port_details) {
33967 + phy_info->port_details->rphy = rphy;
33968 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33969 + ioc->name, rphy));
33970 + }
33971 +
33972 + if (rphy) {
33973 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33974 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33975 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33976 + ioc->name, rphy, rphy->dev.release));
33977 + }
33978 +}
33979 +
33980 /* no mutex */
33981 static void
33982 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33983 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33984 return NULL;
33985 }
33986
33987 -static inline void
33988 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33989 -{
33990 - if (phy_info->port_details) {
33991 - phy_info->port_details->rphy = rphy;
33992 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33993 - ioc->name, rphy));
33994 - }
33995 -
33996 - if (rphy) {
33997 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33998 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33999 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34000 - ioc->name, rphy, rphy->dev.release));
34001 - }
34002 -}
34003 -
34004 static inline struct sas_port *
34005 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34006 {
34007 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34008 index 0c3ced7..1fe34ec 100644
34009 --- a/drivers/message/fusion/mptscsih.c
34010 +++ b/drivers/message/fusion/mptscsih.c
34011 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34012
34013 h = shost_priv(SChost);
34014
34015 - if (h) {
34016 - if (h->info_kbuf == NULL)
34017 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34018 - return h->info_kbuf;
34019 - h->info_kbuf[0] = '\0';
34020 + if (!h)
34021 + return NULL;
34022
34023 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34024 - h->info_kbuf[size-1] = '\0';
34025 - }
34026 + if (h->info_kbuf == NULL)
34027 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34028 + return h->info_kbuf;
34029 + h->info_kbuf[0] = '\0';
34030 +
34031 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34032 + h->info_kbuf[size-1] = '\0';
34033
34034 return h->info_kbuf;
34035 }
34036 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34037 index 506c36f..b137580 100644
34038 --- a/drivers/message/i2o/i2o_proc.c
34039 +++ b/drivers/message/i2o/i2o_proc.c
34040 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34041 "Array Controller Device"
34042 };
34043
34044 -static char *chtostr(u8 * chars, int n)
34045 -{
34046 - char tmp[256];
34047 - tmp[0] = 0;
34048 - return strncat(tmp, (char *)chars, n);
34049 -}
34050 -
34051 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34052 char *group)
34053 {
34054 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34055
34056 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34057 seq_printf(seq, "%-#8x", ddm_table.module_id);
34058 - seq_printf(seq, "%-29s",
34059 - chtostr(ddm_table.module_name_version, 28));
34060 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34061 seq_printf(seq, "%9d ", ddm_table.data_size);
34062 seq_printf(seq, "%8d", ddm_table.code_size);
34063
34064 @@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34065
34066 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34067 seq_printf(seq, "%-#8x", dst->module_id);
34068 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34069 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34070 + seq_printf(seq, "%-.28s", dst->module_name_version);
34071 + seq_printf(seq, "%-.8s", dst->date);
34072 seq_printf(seq, "%8d ", dst->module_size);
34073 seq_printf(seq, "%8d ", dst->mpb_size);
34074 seq_printf(seq, "0x%04x", dst->module_flags);
34075 @@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34076 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34077 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34078 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34079 - seq_printf(seq, "Vendor info : %s\n",
34080 - chtostr((u8 *) (work32 + 2), 16));
34081 - seq_printf(seq, "Product info : %s\n",
34082 - chtostr((u8 *) (work32 + 6), 16));
34083 - seq_printf(seq, "Description : %s\n",
34084 - chtostr((u8 *) (work32 + 10), 16));
34085 - seq_printf(seq, "Product rev. : %s\n",
34086 - chtostr((u8 *) (work32 + 14), 8));
34087 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34088 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34089 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34090 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34091
34092 seq_printf(seq, "Serial number : ");
34093 print_serial_number(seq, (u8 *) (work32 + 16),
34094 @@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34095 }
34096
34097 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34098 - seq_printf(seq, "Module name : %s\n",
34099 - chtostr(result.module_name, 24));
34100 - seq_printf(seq, "Module revision : %s\n",
34101 - chtostr(result.module_rev, 8));
34102 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34103 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34104
34105 seq_printf(seq, "Serial number : ");
34106 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34107 @@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34108 return 0;
34109 }
34110
34111 - seq_printf(seq, "Device name : %s\n",
34112 - chtostr(result.device_name, 64));
34113 - seq_printf(seq, "Service name : %s\n",
34114 - chtostr(result.service_name, 64));
34115 - seq_printf(seq, "Physical name : %s\n",
34116 - chtostr(result.physical_location, 64));
34117 - seq_printf(seq, "Instance number : %s\n",
34118 - chtostr(result.instance_number, 4));
34119 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34120 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34121 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34122 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34123
34124 return 0;
34125 }
34126 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34127 index a8c08f3..155fe3d 100644
34128 --- a/drivers/message/i2o/iop.c
34129 +++ b/drivers/message/i2o/iop.c
34130 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34131
34132 spin_lock_irqsave(&c->context_list_lock, flags);
34133
34134 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34135 - atomic_inc(&c->context_list_counter);
34136 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34137 + atomic_inc_unchecked(&c->context_list_counter);
34138
34139 - entry->context = atomic_read(&c->context_list_counter);
34140 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34141
34142 list_add(&entry->list, &c->context_list);
34143
34144 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34145
34146 #if BITS_PER_LONG == 64
34147 spin_lock_init(&c->context_list_lock);
34148 - atomic_set(&c->context_list_counter, 0);
34149 + atomic_set_unchecked(&c->context_list_counter, 0);
34150 INIT_LIST_HEAD(&c->context_list);
34151 #endif
34152
34153 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34154 index 7ce65f4..e66e9bc 100644
34155 --- a/drivers/mfd/abx500-core.c
34156 +++ b/drivers/mfd/abx500-core.c
34157 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34158
34159 struct abx500_device_entry {
34160 struct list_head list;
34161 - struct abx500_ops ops;
34162 + abx500_ops_no_const ops;
34163 struct device *dev;
34164 };
34165
34166 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34167 index 2ea9998..51dabee 100644
34168 --- a/drivers/mfd/janz-cmodio.c
34169 +++ b/drivers/mfd/janz-cmodio.c
34170 @@ -13,6 +13,7 @@
34171
34172 #include <linux/kernel.h>
34173 #include <linux/module.h>
34174 +#include <linux/slab.h>
34175 #include <linux/init.h>
34176 #include <linux/pci.h>
34177 #include <linux/interrupt.h>
34178 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34179 index a981e2a..5ca0c8b 100644
34180 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34181 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34182 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34183 * the lid is closed. This leads to interrupts as soon as a little move
34184 * is done.
34185 */
34186 - atomic_inc(&lis3->count);
34187 + atomic_inc_unchecked(&lis3->count);
34188
34189 wake_up_interruptible(&lis3->misc_wait);
34190 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34191 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34192 if (lis3->pm_dev)
34193 pm_runtime_get_sync(lis3->pm_dev);
34194
34195 - atomic_set(&lis3->count, 0);
34196 + atomic_set_unchecked(&lis3->count, 0);
34197 return 0;
34198 }
34199
34200 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34201 add_wait_queue(&lis3->misc_wait, &wait);
34202 while (true) {
34203 set_current_state(TASK_INTERRUPTIBLE);
34204 - data = atomic_xchg(&lis3->count, 0);
34205 + data = atomic_xchg_unchecked(&lis3->count, 0);
34206 if (data)
34207 break;
34208
34209 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34210 struct lis3lv02d, miscdev);
34211
34212 poll_wait(file, &lis3->misc_wait, wait);
34213 - if (atomic_read(&lis3->count))
34214 + if (atomic_read_unchecked(&lis3->count))
34215 return POLLIN | POLLRDNORM;
34216 return 0;
34217 }
34218 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34219 index 2b1482a..5d33616 100644
34220 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34221 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34222 @@ -266,7 +266,7 @@ struct lis3lv02d {
34223 struct input_polled_dev *idev; /* input device */
34224 struct platform_device *pdev; /* platform device */
34225 struct regulator_bulk_data regulators[2];
34226 - atomic_t count; /* interrupt count after last read */
34227 + atomic_unchecked_t count; /* interrupt count after last read */
34228 union axis_conversion ac; /* hw -> logical axis */
34229 int mapped_btns[3];
34230
34231 diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34232 index 28adefe..08aad69 100644
34233 --- a/drivers/misc/lkdtm.c
34234 +++ b/drivers/misc/lkdtm.c
34235 @@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34236 int i, n, out;
34237
34238 buf = (char *)__get_free_page(GFP_KERNEL);
34239 + if (buf == NULL)
34240 + return -ENOMEM;
34241
34242 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34243 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34244 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34245 index 2f30bad..c4c13d0 100644
34246 --- a/drivers/misc/sgi-gru/gruhandles.c
34247 +++ b/drivers/misc/sgi-gru/gruhandles.c
34248 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34249 unsigned long nsec;
34250
34251 nsec = CLKS2NSEC(clks);
34252 - atomic_long_inc(&mcs_op_statistics[op].count);
34253 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34254 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34255 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34256 if (mcs_op_statistics[op].max < nsec)
34257 mcs_op_statistics[op].max = nsec;
34258 }
34259 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34260 index 950dbe9..eeef0f8 100644
34261 --- a/drivers/misc/sgi-gru/gruprocfs.c
34262 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34263 @@ -32,9 +32,9 @@
34264
34265 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34266
34267 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34268 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34269 {
34270 - unsigned long val = atomic_long_read(v);
34271 + unsigned long val = atomic_long_read_unchecked(v);
34272
34273 seq_printf(s, "%16lu %s\n", val, id);
34274 }
34275 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34276
34277 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34278 for (op = 0; op < mcsop_last; op++) {
34279 - count = atomic_long_read(&mcs_op_statistics[op].count);
34280 - total = atomic_long_read(&mcs_op_statistics[op].total);
34281 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34282 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34283 max = mcs_op_statistics[op].max;
34284 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34285 count ? total / count : 0, max);
34286 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34287 index 5c3ce24..4915ccb 100644
34288 --- a/drivers/misc/sgi-gru/grutables.h
34289 +++ b/drivers/misc/sgi-gru/grutables.h
34290 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34291 * GRU statistics.
34292 */
34293 struct gru_stats_s {
34294 - atomic_long_t vdata_alloc;
34295 - atomic_long_t vdata_free;
34296 - atomic_long_t gts_alloc;
34297 - atomic_long_t gts_free;
34298 - atomic_long_t gms_alloc;
34299 - atomic_long_t gms_free;
34300 - atomic_long_t gts_double_allocate;
34301 - atomic_long_t assign_context;
34302 - atomic_long_t assign_context_failed;
34303 - atomic_long_t free_context;
34304 - atomic_long_t load_user_context;
34305 - atomic_long_t load_kernel_context;
34306 - atomic_long_t lock_kernel_context;
34307 - atomic_long_t unlock_kernel_context;
34308 - atomic_long_t steal_user_context;
34309 - atomic_long_t steal_kernel_context;
34310 - atomic_long_t steal_context_failed;
34311 - atomic_long_t nopfn;
34312 - atomic_long_t asid_new;
34313 - atomic_long_t asid_next;
34314 - atomic_long_t asid_wrap;
34315 - atomic_long_t asid_reuse;
34316 - atomic_long_t intr;
34317 - atomic_long_t intr_cbr;
34318 - atomic_long_t intr_tfh;
34319 - atomic_long_t intr_spurious;
34320 - atomic_long_t intr_mm_lock_failed;
34321 - atomic_long_t call_os;
34322 - atomic_long_t call_os_wait_queue;
34323 - atomic_long_t user_flush_tlb;
34324 - atomic_long_t user_unload_context;
34325 - atomic_long_t user_exception;
34326 - atomic_long_t set_context_option;
34327 - atomic_long_t check_context_retarget_intr;
34328 - atomic_long_t check_context_unload;
34329 - atomic_long_t tlb_dropin;
34330 - atomic_long_t tlb_preload_page;
34331 - atomic_long_t tlb_dropin_fail_no_asid;
34332 - atomic_long_t tlb_dropin_fail_upm;
34333 - atomic_long_t tlb_dropin_fail_invalid;
34334 - atomic_long_t tlb_dropin_fail_range_active;
34335 - atomic_long_t tlb_dropin_fail_idle;
34336 - atomic_long_t tlb_dropin_fail_fmm;
34337 - atomic_long_t tlb_dropin_fail_no_exception;
34338 - atomic_long_t tfh_stale_on_fault;
34339 - atomic_long_t mmu_invalidate_range;
34340 - atomic_long_t mmu_invalidate_page;
34341 - atomic_long_t flush_tlb;
34342 - atomic_long_t flush_tlb_gru;
34343 - atomic_long_t flush_tlb_gru_tgh;
34344 - atomic_long_t flush_tlb_gru_zero_asid;
34345 + atomic_long_unchecked_t vdata_alloc;
34346 + atomic_long_unchecked_t vdata_free;
34347 + atomic_long_unchecked_t gts_alloc;
34348 + atomic_long_unchecked_t gts_free;
34349 + atomic_long_unchecked_t gms_alloc;
34350 + atomic_long_unchecked_t gms_free;
34351 + atomic_long_unchecked_t gts_double_allocate;
34352 + atomic_long_unchecked_t assign_context;
34353 + atomic_long_unchecked_t assign_context_failed;
34354 + atomic_long_unchecked_t free_context;
34355 + atomic_long_unchecked_t load_user_context;
34356 + atomic_long_unchecked_t load_kernel_context;
34357 + atomic_long_unchecked_t lock_kernel_context;
34358 + atomic_long_unchecked_t unlock_kernel_context;
34359 + atomic_long_unchecked_t steal_user_context;
34360 + atomic_long_unchecked_t steal_kernel_context;
34361 + atomic_long_unchecked_t steal_context_failed;
34362 + atomic_long_unchecked_t nopfn;
34363 + atomic_long_unchecked_t asid_new;
34364 + atomic_long_unchecked_t asid_next;
34365 + atomic_long_unchecked_t asid_wrap;
34366 + atomic_long_unchecked_t asid_reuse;
34367 + atomic_long_unchecked_t intr;
34368 + atomic_long_unchecked_t intr_cbr;
34369 + atomic_long_unchecked_t intr_tfh;
34370 + atomic_long_unchecked_t intr_spurious;
34371 + atomic_long_unchecked_t intr_mm_lock_failed;
34372 + atomic_long_unchecked_t call_os;
34373 + atomic_long_unchecked_t call_os_wait_queue;
34374 + atomic_long_unchecked_t user_flush_tlb;
34375 + atomic_long_unchecked_t user_unload_context;
34376 + atomic_long_unchecked_t user_exception;
34377 + atomic_long_unchecked_t set_context_option;
34378 + atomic_long_unchecked_t check_context_retarget_intr;
34379 + atomic_long_unchecked_t check_context_unload;
34380 + atomic_long_unchecked_t tlb_dropin;
34381 + atomic_long_unchecked_t tlb_preload_page;
34382 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34383 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34384 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34385 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34386 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34387 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34388 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34389 + atomic_long_unchecked_t tfh_stale_on_fault;
34390 + atomic_long_unchecked_t mmu_invalidate_range;
34391 + atomic_long_unchecked_t mmu_invalidate_page;
34392 + atomic_long_unchecked_t flush_tlb;
34393 + atomic_long_unchecked_t flush_tlb_gru;
34394 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34395 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34396
34397 - atomic_long_t copy_gpa;
34398 - atomic_long_t read_gpa;
34399 + atomic_long_unchecked_t copy_gpa;
34400 + atomic_long_unchecked_t read_gpa;
34401
34402 - atomic_long_t mesq_receive;
34403 - atomic_long_t mesq_receive_none;
34404 - atomic_long_t mesq_send;
34405 - atomic_long_t mesq_send_failed;
34406 - atomic_long_t mesq_noop;
34407 - atomic_long_t mesq_send_unexpected_error;
34408 - atomic_long_t mesq_send_lb_overflow;
34409 - atomic_long_t mesq_send_qlimit_reached;
34410 - atomic_long_t mesq_send_amo_nacked;
34411 - atomic_long_t mesq_send_put_nacked;
34412 - atomic_long_t mesq_page_overflow;
34413 - atomic_long_t mesq_qf_locked;
34414 - atomic_long_t mesq_qf_noop_not_full;
34415 - atomic_long_t mesq_qf_switch_head_failed;
34416 - atomic_long_t mesq_qf_unexpected_error;
34417 - atomic_long_t mesq_noop_unexpected_error;
34418 - atomic_long_t mesq_noop_lb_overflow;
34419 - atomic_long_t mesq_noop_qlimit_reached;
34420 - atomic_long_t mesq_noop_amo_nacked;
34421 - atomic_long_t mesq_noop_put_nacked;
34422 - atomic_long_t mesq_noop_page_overflow;
34423 + atomic_long_unchecked_t mesq_receive;
34424 + atomic_long_unchecked_t mesq_receive_none;
34425 + atomic_long_unchecked_t mesq_send;
34426 + atomic_long_unchecked_t mesq_send_failed;
34427 + atomic_long_unchecked_t mesq_noop;
34428 + atomic_long_unchecked_t mesq_send_unexpected_error;
34429 + atomic_long_unchecked_t mesq_send_lb_overflow;
34430 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34431 + atomic_long_unchecked_t mesq_send_amo_nacked;
34432 + atomic_long_unchecked_t mesq_send_put_nacked;
34433 + atomic_long_unchecked_t mesq_page_overflow;
34434 + atomic_long_unchecked_t mesq_qf_locked;
34435 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34436 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34437 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34438 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34439 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34440 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34441 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34442 + atomic_long_unchecked_t mesq_noop_put_nacked;
34443 + atomic_long_unchecked_t mesq_noop_page_overflow;
34444
34445 };
34446
34447 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34448 tghop_invalidate, mcsop_last};
34449
34450 struct mcs_op_statistic {
34451 - atomic_long_t count;
34452 - atomic_long_t total;
34453 + atomic_long_unchecked_t count;
34454 + atomic_long_unchecked_t total;
34455 unsigned long max;
34456 };
34457
34458 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34459
34460 #define STAT(id) do { \
34461 if (gru_options & OPT_STATS) \
34462 - atomic_long_inc(&gru_stats.id); \
34463 + atomic_long_inc_unchecked(&gru_stats.id); \
34464 } while (0)
34465
34466 #ifdef CONFIG_SGI_GRU_DEBUG
34467 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34468 index c862cd4..0d176fe 100644
34469 --- a/drivers/misc/sgi-xp/xp.h
34470 +++ b/drivers/misc/sgi-xp/xp.h
34471 @@ -288,7 +288,7 @@ struct xpc_interface {
34472 xpc_notify_func, void *);
34473 void (*received) (short, int, void *);
34474 enum xp_retval (*partid_to_nasids) (short, void *);
34475 -};
34476 +} __no_const;
34477
34478 extern struct xpc_interface xpc_interface;
34479
34480 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34481 index b94d5f7..7f494c5 100644
34482 --- a/drivers/misc/sgi-xp/xpc.h
34483 +++ b/drivers/misc/sgi-xp/xpc.h
34484 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34485 void (*received_payload) (struct xpc_channel *, void *);
34486 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34487 };
34488 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34489
34490 /* struct xpc_partition act_state values (for XPC HB) */
34491
34492 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34493 /* found in xpc_main.c */
34494 extern struct device *xpc_part;
34495 extern struct device *xpc_chan;
34496 -extern struct xpc_arch_operations xpc_arch_ops;
34497 +extern xpc_arch_operations_no_const xpc_arch_ops;
34498 extern int xpc_disengage_timelimit;
34499 extern int xpc_disengage_timedout;
34500 extern int xpc_activate_IRQ_rcvd;
34501 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34502 index 8d082b4..aa749ae 100644
34503 --- a/drivers/misc/sgi-xp/xpc_main.c
34504 +++ b/drivers/misc/sgi-xp/xpc_main.c
34505 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34506 .notifier_call = xpc_system_die,
34507 };
34508
34509 -struct xpc_arch_operations xpc_arch_ops;
34510 +xpc_arch_operations_no_const xpc_arch_ops;
34511
34512 /*
34513 * Timer function to enforce the timelimit on the partition disengage.
34514 diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34515 index 2b62232..acfaeeb 100644
34516 --- a/drivers/misc/ti-st/st_core.c
34517 +++ b/drivers/misc/ti-st/st_core.c
34518 @@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34519 st_gdata->rx_skb = alloc_skb(
34520 st_gdata->list[type]->max_frame_size,
34521 GFP_ATOMIC);
34522 + if (st_gdata->rx_skb == NULL) {
34523 + pr_err("out of memory: dropping\n");
34524 + goto done;
34525 + }
34526 +
34527 skb_reserve(st_gdata->rx_skb,
34528 st_gdata->list[type]->reserve);
34529 /* next 2 required for BT only */
34530 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34531 index 504da71..9722d43 100644
34532 --- a/drivers/mmc/host/sdhci-pci.c
34533 +++ b/drivers/mmc/host/sdhci-pci.c
34534 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34535 .probe = via_probe,
34536 };
34537
34538 -static const struct pci_device_id pci_ids[] __devinitdata = {
34539 +static const struct pci_device_id pci_ids[] __devinitconst = {
34540 {
34541 .vendor = PCI_VENDOR_ID_RICOH,
34542 .device = PCI_DEVICE_ID_RICOH_R5C822,
34543 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34544 index a4eb8b5..8c0628f 100644
34545 --- a/drivers/mtd/devices/doc2000.c
34546 +++ b/drivers/mtd/devices/doc2000.c
34547 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34548
34549 /* The ECC will not be calculated correctly if less than 512 is written */
34550 /* DBB-
34551 - if (len != 0x200 && eccbuf)
34552 + if (len != 0x200)
34553 printk(KERN_WARNING
34554 "ECC needs a full sector write (adr: %lx size %lx)\n",
34555 (long) to, (long) len);
34556 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34557 index 0650aaf..7718762 100644
34558 --- a/drivers/mtd/nand/denali.c
34559 +++ b/drivers/mtd/nand/denali.c
34560 @@ -26,6 +26,7 @@
34561 #include <linux/pci.h>
34562 #include <linux/mtd/mtd.h>
34563 #include <linux/module.h>
34564 +#include <linux/slab.h>
34565
34566 #include "denali.h"
34567
34568 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34569 index 51b9d6a..52af9a7 100644
34570 --- a/drivers/mtd/nftlmount.c
34571 +++ b/drivers/mtd/nftlmount.c
34572 @@ -24,6 +24,7 @@
34573 #include <asm/errno.h>
34574 #include <linux/delay.h>
34575 #include <linux/slab.h>
34576 +#include <linux/sched.h>
34577 #include <linux/mtd/mtd.h>
34578 #include <linux/mtd/nand.h>
34579 #include <linux/mtd/nftl.h>
34580 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34581 index 6762dc4..9956862 100644
34582 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34583 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34584 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34585 */
34586
34587 #define ATL2_PARAM(X, desc) \
34588 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34589 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34590 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34591 MODULE_PARM_DESC(X, desc);
34592 #else
34593 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34594 index efd80bd..21fcff0 100644
34595 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34596 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34597 @@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34598
34599 int (*wait_comp)(struct bnx2x *bp,
34600 struct bnx2x_rx_mode_ramrod_params *p);
34601 -};
34602 +} __no_const;
34603
34604 /********************** Set multicast group ***********************************/
34605
34606 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34607 index 93865f8..5448741 100644
34608 --- a/drivers/net/ethernet/broadcom/tg3.h
34609 +++ b/drivers/net/ethernet/broadcom/tg3.h
34610 @@ -140,6 +140,7 @@
34611 #define CHIPREV_ID_5750_A0 0x4000
34612 #define CHIPREV_ID_5750_A1 0x4001
34613 #define CHIPREV_ID_5750_A3 0x4003
34614 +#define CHIPREV_ID_5750_C1 0x4201
34615 #define CHIPREV_ID_5750_C2 0x4202
34616 #define CHIPREV_ID_5752_A0_HW 0x5000
34617 #define CHIPREV_ID_5752_A0 0x6000
34618 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34619 index c4e8643..0979484 100644
34620 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34621 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34622 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34623 */
34624 struct l2t_skb_cb {
34625 arp_failure_handler_func arp_failure_handler;
34626 -};
34627 +} __no_const;
34628
34629 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34630
34631 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34632 index d3cd489..0fd52dd 100644
34633 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34634 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34635 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34636 for (i=0; i<ETH_ALEN; i++) {
34637 tmp.addr[i] = dev->dev_addr[i];
34638 }
34639 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34640 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34641 break;
34642
34643 case DE4X5_SET_HWADDR: /* Set the hardware address */
34644 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34645 spin_lock_irqsave(&lp->lock, flags);
34646 memcpy(&statbuf, &lp->pktStats, ioc->len);
34647 spin_unlock_irqrestore(&lp->lock, flags);
34648 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34649 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34650 return -EFAULT;
34651 break;
34652 }
34653 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34654 index ed7d1dc..d426748 100644
34655 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34656 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34657 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34658 {NULL}};
34659
34660
34661 -static const char *block_name[] __devinitdata = {
34662 +static const char *block_name[] __devinitconst = {
34663 "21140 non-MII",
34664 "21140 MII PHY",
34665 "21142 Serial PHY",
34666 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34667 index 75d45f8..3d9c55b 100644
34668 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34669 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34670 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34671 struct uli_phy_ops {
34672 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34673 u16 (*read)(struct uli526x_board_info *, u8, u8);
34674 - } phy;
34675 + } __no_const phy;
34676 struct net_device *next_dev; /* next device */
34677 struct pci_dev *pdev; /* PCI device */
34678 spinlock_t lock;
34679 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34680 index 4d1ffca..7c1ec4d 100644
34681 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34682 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34683 @@ -236,7 +236,7 @@ struct pci_id_info {
34684 int drv_flags; /* Driver use, intended as capability flags. */
34685 };
34686
34687 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34688 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34689 { /* Sometime a Level-One switch card. */
34690 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34691 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34692 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34693 index d7bb52a..3b83588 100644
34694 --- a/drivers/net/ethernet/dlink/sundance.c
34695 +++ b/drivers/net/ethernet/dlink/sundance.c
34696 @@ -218,7 +218,7 @@ enum {
34697 struct pci_id_info {
34698 const char *name;
34699 };
34700 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34701 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34702 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34703 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34704 {"D-Link DFE-580TX 4 port Server Adapter"},
34705 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34706 index bd5cf7e..c165651 100644
34707 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34708 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34709 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34710
34711 if (wrapped)
34712 newacc += 65536;
34713 - ACCESS_ONCE(*acc) = newacc;
34714 + ACCESS_ONCE_RW(*acc) = newacc;
34715 }
34716
34717 void be_parse_stats(struct be_adapter *adapter)
34718 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34719 index 16b0704..d2c07d7 100644
34720 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34721 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34722 @@ -31,6 +31,8 @@
34723 #include <linux/netdevice.h>
34724 #include <linux/phy.h>
34725 #include <linux/platform_device.h>
34726 +#include <linux/interrupt.h>
34727 +#include <linux/irqreturn.h>
34728 #include <net/ip.h>
34729
34730 #include "ftgmac100.h"
34731 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34732 index 829b109..4ae5f6a 100644
34733 --- a/drivers/net/ethernet/faraday/ftmac100.c
34734 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34735 @@ -31,6 +31,8 @@
34736 #include <linux/module.h>
34737 #include <linux/netdevice.h>
34738 #include <linux/platform_device.h>
34739 +#include <linux/interrupt.h>
34740 +#include <linux/irqreturn.h>
34741
34742 #include "ftmac100.h"
34743
34744 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34745 index 9d71c9c..0e4a0ac 100644
34746 --- a/drivers/net/ethernet/fealnx.c
34747 +++ b/drivers/net/ethernet/fealnx.c
34748 @@ -150,7 +150,7 @@ struct chip_info {
34749 int flags;
34750 };
34751
34752 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34753 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34754 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34755 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34756 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34757 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34758 index 6e6fffb..588f361 100644
34759 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34760 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34761 @@ -181,7 +181,7 @@ struct e1000_info;
34762 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34763 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34764 E1000_TXDCTL_COUNT_DESC | \
34765 - (5 << 16) | /* wthresh must be +1 more than desired */\
34766 + (1 << 16) | /* wthresh must be +1 more than desired */\
34767 (1 << 8) | /* hthresh */ \
34768 0x1f) /* pthresh */
34769
34770 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34771 index ed5b409..ec37828 100644
34772 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34773 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34774 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34775 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34776 s32 (*read_mac_addr)(struct e1000_hw *);
34777 };
34778 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34779
34780 /*
34781 * When to use various PHY register access functions:
34782 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34783 void (*power_up)(struct e1000_hw *);
34784 void (*power_down)(struct e1000_hw *);
34785 };
34786 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34787
34788 /* Function pointers for the NVM. */
34789 struct e1000_nvm_operations {
34790 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34791 s32 (*validate)(struct e1000_hw *);
34792 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34793 };
34794 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34795
34796 struct e1000_mac_info {
34797 - struct e1000_mac_operations ops;
34798 + e1000_mac_operations_no_const ops;
34799 u8 addr[ETH_ALEN];
34800 u8 perm_addr[ETH_ALEN];
34801
34802 @@ -892,7 +895,7 @@ struct e1000_mac_info {
34803 };
34804
34805 struct e1000_phy_info {
34806 - struct e1000_phy_operations ops;
34807 + e1000_phy_operations_no_const ops;
34808
34809 enum e1000_phy_type type;
34810
34811 @@ -926,7 +929,7 @@ struct e1000_phy_info {
34812 };
34813
34814 struct e1000_nvm_info {
34815 - struct e1000_nvm_operations ops;
34816 + e1000_nvm_operations_no_const ops;
34817
34818 enum e1000_nvm_type type;
34819 enum e1000_nvm_override override;
34820 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34821 index c2a51dc..c2bd262 100644
34822 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34823 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34824 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34825 void (*release_swfw_sync)(struct e1000_hw *, u16);
34826
34827 };
34828 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34829
34830 struct e1000_phy_operations {
34831 s32 (*acquire)(struct e1000_hw *);
34832 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34833 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34834 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34835 };
34836 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34837
34838 struct e1000_nvm_operations {
34839 s32 (*acquire)(struct e1000_hw *);
34840 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34841 s32 (*validate)(struct e1000_hw *);
34842 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34843 };
34844 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34845
34846 struct e1000_info {
34847 s32 (*get_invariants)(struct e1000_hw *);
34848 @@ -364,7 +367,7 @@ struct e1000_info {
34849 extern const struct e1000_info e1000_82575_info;
34850
34851 struct e1000_mac_info {
34852 - struct e1000_mac_operations ops;
34853 + e1000_mac_operations_no_const ops;
34854
34855 u8 addr[6];
34856 u8 perm_addr[6];
34857 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34858 };
34859
34860 struct e1000_phy_info {
34861 - struct e1000_phy_operations ops;
34862 + e1000_phy_operations_no_const ops;
34863
34864 enum e1000_phy_type type;
34865
34866 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34867 };
34868
34869 struct e1000_nvm_info {
34870 - struct e1000_nvm_operations ops;
34871 + e1000_nvm_operations_no_const ops;
34872 enum e1000_nvm_type type;
34873 enum e1000_nvm_override override;
34874
34875 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34876 s32 (*check_for_ack)(struct e1000_hw *, u16);
34877 s32 (*check_for_rst)(struct e1000_hw *, u16);
34878 };
34879 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34880
34881 struct e1000_mbx_stats {
34882 u32 msgs_tx;
34883 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34884 };
34885
34886 struct e1000_mbx_info {
34887 - struct e1000_mbx_operations ops;
34888 + e1000_mbx_operations_no_const ops;
34889 struct e1000_mbx_stats stats;
34890 u32 timeout;
34891 u32 usec_delay;
34892 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34893 index 57db3c6..aa825fc 100644
34894 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34895 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34896 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34897 s32 (*read_mac_addr)(struct e1000_hw *);
34898 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34899 };
34900 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34901
34902 struct e1000_mac_info {
34903 - struct e1000_mac_operations ops;
34904 + e1000_mac_operations_no_const ops;
34905 u8 addr[6];
34906 u8 perm_addr[6];
34907
34908 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34909 s32 (*check_for_ack)(struct e1000_hw *);
34910 s32 (*check_for_rst)(struct e1000_hw *);
34911 };
34912 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34913
34914 struct e1000_mbx_stats {
34915 u32 msgs_tx;
34916 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34917 };
34918
34919 struct e1000_mbx_info {
34920 - struct e1000_mbx_operations ops;
34921 + e1000_mbx_operations_no_const ops;
34922 struct e1000_mbx_stats stats;
34923 u32 timeout;
34924 u32 usec_delay;
34925 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34926 index dcebd12..c1fe8be 100644
34927 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34928 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34929 @@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34930 /* store the new cycle speed */
34931 adapter->cycle_speed = cycle_speed;
34932
34933 - ACCESS_ONCE(adapter->base_incval) = incval;
34934 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
34935 smp_mb();
34936
34937 /* grab the ptp lock */
34938 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34939 index 204848d..d8aeaec 100644
34940 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34941 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34942 @@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34943 s32 (*update_checksum)(struct ixgbe_hw *);
34944 u16 (*calc_checksum)(struct ixgbe_hw *);
34945 };
34946 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34947
34948 struct ixgbe_mac_operations {
34949 s32 (*init_hw)(struct ixgbe_hw *);
34950 @@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34951 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34952 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34953 };
34954 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34955
34956 struct ixgbe_phy_operations {
34957 s32 (*identify)(struct ixgbe_hw *);
34958 @@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34959 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34960 s32 (*check_overtemp)(struct ixgbe_hw *);
34961 };
34962 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34963
34964 struct ixgbe_eeprom_info {
34965 - struct ixgbe_eeprom_operations ops;
34966 + ixgbe_eeprom_operations_no_const ops;
34967 enum ixgbe_eeprom_type type;
34968 u32 semaphore_delay;
34969 u16 word_size;
34970 @@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34971
34972 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34973 struct ixgbe_mac_info {
34974 - struct ixgbe_mac_operations ops;
34975 + ixgbe_mac_operations_no_const ops;
34976 enum ixgbe_mac_type type;
34977 u8 addr[ETH_ALEN];
34978 u8 perm_addr[ETH_ALEN];
34979 @@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34980 };
34981
34982 struct ixgbe_phy_info {
34983 - struct ixgbe_phy_operations ops;
34984 + ixgbe_phy_operations_no_const ops;
34985 struct mdio_if_info mdio;
34986 enum ixgbe_phy_type type;
34987 u32 id;
34988 @@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34989 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34990 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34991 };
34992 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34993
34994 struct ixgbe_mbx_stats {
34995 u32 msgs_tx;
34996 @@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34997 };
34998
34999 struct ixgbe_mbx_info {
35000 - struct ixgbe_mbx_operations ops;
35001 + ixgbe_mbx_operations_no_const ops;
35002 struct ixgbe_mbx_stats stats;
35003 u32 timeout;
35004 u32 usec_delay;
35005 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35006 index 25c951d..cc7cf33 100644
35007 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35008 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35009 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35010 s32 (*clear_vfta)(struct ixgbe_hw *);
35011 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35012 };
35013 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35014
35015 enum ixgbe_mac_type {
35016 ixgbe_mac_unknown = 0,
35017 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35018 };
35019
35020 struct ixgbe_mac_info {
35021 - struct ixgbe_mac_operations ops;
35022 + ixgbe_mac_operations_no_const ops;
35023 u8 addr[6];
35024 u8 perm_addr[6];
35025
35026 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35027 s32 (*check_for_ack)(struct ixgbe_hw *);
35028 s32 (*check_for_rst)(struct ixgbe_hw *);
35029 };
35030 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35031
35032 struct ixgbe_mbx_stats {
35033 u32 msgs_tx;
35034 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35035 };
35036
35037 struct ixgbe_mbx_info {
35038 - struct ixgbe_mbx_operations ops;
35039 + ixgbe_mbx_operations_no_const ops;
35040 struct ixgbe_mbx_stats stats;
35041 u32 timeout;
35042 u32 udelay;
35043 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35044 index a0313de..e83a572 100644
35045 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35046 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35047 @@ -41,6 +41,7 @@
35048 #include <linux/slab.h>
35049 #include <linux/io-mapping.h>
35050 #include <linux/delay.h>
35051 +#include <linux/sched.h>
35052
35053 #include <linux/mlx4/device.h>
35054 #include <linux/mlx4/doorbell.h>
35055 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35056 index 5046a64..71ca936 100644
35057 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35058 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35059 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35060 void (*link_down)(struct __vxge_hw_device *devh);
35061 void (*crit_err)(struct __vxge_hw_device *devh,
35062 enum vxge_hw_event type, u64 ext_data);
35063 -};
35064 +} __no_const;
35065
35066 /*
35067 * struct __vxge_hw_blockpool_entry - Block private data structure
35068 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35069 index 4a518a3..936b334 100644
35070 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35071 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35072 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35073 struct vxge_hw_mempool_dma *dma_object,
35074 u32 index,
35075 u32 is_last);
35076 -};
35077 +} __no_const;
35078
35079 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35080 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35081 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35082 index eb81da4..1592b62 100644
35083 --- a/drivers/net/ethernet/realtek/r8169.c
35084 +++ b/drivers/net/ethernet/realtek/r8169.c
35085 @@ -723,22 +723,22 @@ struct rtl8169_private {
35086 struct mdio_ops {
35087 void (*write)(void __iomem *, int, int);
35088 int (*read)(void __iomem *, int);
35089 - } mdio_ops;
35090 + } __no_const mdio_ops;
35091
35092 struct pll_power_ops {
35093 void (*down)(struct rtl8169_private *);
35094 void (*up)(struct rtl8169_private *);
35095 - } pll_power_ops;
35096 + } __no_const pll_power_ops;
35097
35098 struct jumbo_ops {
35099 void (*enable)(struct rtl8169_private *);
35100 void (*disable)(struct rtl8169_private *);
35101 - } jumbo_ops;
35102 + } __no_const jumbo_ops;
35103
35104 struct csi_ops {
35105 void (*write)(void __iomem *, int, int);
35106 u32 (*read)(void __iomem *, int);
35107 - } csi_ops;
35108 + } __no_const csi_ops;
35109
35110 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35111 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35112 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35113 index 4613591..d816601 100644
35114 --- a/drivers/net/ethernet/sis/sis190.c
35115 +++ b/drivers/net/ethernet/sis/sis190.c
35116 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35117 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35118 struct net_device *dev)
35119 {
35120 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35121 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35122 struct sis190_private *tp = netdev_priv(dev);
35123 struct pci_dev *isa_bridge;
35124 u8 reg, tmp8;
35125 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35126 index c07cfe9..81cbf7e 100644
35127 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35128 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35129 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35130
35131 writel(value, ioaddr + MMC_CNTRL);
35132
35133 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35134 - MMC_CNTRL, value);
35135 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35136 +// MMC_CNTRL, value);
35137 }
35138
35139 /* To mask all all interrupts.*/
35140 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35141 index 2857ab0..9a1f9b0 100644
35142 --- a/drivers/net/hyperv/hyperv_net.h
35143 +++ b/drivers/net/hyperv/hyperv_net.h
35144 @@ -99,7 +99,7 @@ struct rndis_device {
35145
35146 enum rndis_device_state state;
35147 bool link_state;
35148 - atomic_t new_req_id;
35149 + atomic_unchecked_t new_req_id;
35150
35151 spinlock_t request_lock;
35152 struct list_head req_list;
35153 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35154 index 981ebb1..b34959b 100644
35155 --- a/drivers/net/hyperv/rndis_filter.c
35156 +++ b/drivers/net/hyperv/rndis_filter.c
35157 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35158 * template
35159 */
35160 set = &rndis_msg->msg.set_req;
35161 - set->req_id = atomic_inc_return(&dev->new_req_id);
35162 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35163
35164 /* Add to the request list */
35165 spin_lock_irqsave(&dev->request_lock, flags);
35166 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35167
35168 /* Setup the rndis set */
35169 halt = &request->request_msg.msg.halt_req;
35170 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35171 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35172
35173 /* Ignore return since this msg is optional. */
35174 rndis_filter_send_request(dev, request);
35175 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35176 index 5c05572..389610b 100644
35177 --- a/drivers/net/ppp/ppp_generic.c
35178 +++ b/drivers/net/ppp/ppp_generic.c
35179 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35180 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35181 struct ppp_stats stats;
35182 struct ppp_comp_stats cstats;
35183 - char *vers;
35184
35185 switch (cmd) {
35186 case SIOCGPPPSTATS:
35187 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35188 break;
35189
35190 case SIOCGPPPVER:
35191 - vers = PPP_VERSION;
35192 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35193 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35194 break;
35195 err = 0;
35196 break;
35197 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35198 index 62f30b4..ff99dfd 100644
35199 --- a/drivers/net/usb/hso.c
35200 +++ b/drivers/net/usb/hso.c
35201 @@ -71,7 +71,7 @@
35202 #include <asm/byteorder.h>
35203 #include <linux/serial_core.h>
35204 #include <linux/serial.h>
35205 -
35206 +#include <asm/local.h>
35207
35208 #define MOD_AUTHOR "Option Wireless"
35209 #define MOD_DESCRIPTION "USB High Speed Option driver"
35210 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35211 struct urb *urb;
35212
35213 urb = serial->rx_urb[0];
35214 - if (serial->port.count > 0) {
35215 + if (atomic_read(&serial->port.count) > 0) {
35216 count = put_rxbuf_data(urb, serial);
35217 if (count == -1)
35218 return;
35219 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35220 DUMP1(urb->transfer_buffer, urb->actual_length);
35221
35222 /* Anyone listening? */
35223 - if (serial->port.count == 0)
35224 + if (atomic_read(&serial->port.count) == 0)
35225 return;
35226
35227 if (status == 0) {
35228 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35229 tty_port_tty_set(&serial->port, tty);
35230
35231 /* check for port already opened, if not set the termios */
35232 - serial->port.count++;
35233 - if (serial->port.count == 1) {
35234 + if (atomic_inc_return(&serial->port.count) == 1) {
35235 serial->rx_state = RX_IDLE;
35236 /* Force default termio settings */
35237 _hso_serial_set_termios(tty, NULL);
35238 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35239 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35240 if (result) {
35241 hso_stop_serial_device(serial->parent);
35242 - serial->port.count--;
35243 + atomic_dec(&serial->port.count);
35244 kref_put(&serial->parent->ref, hso_serial_ref_free);
35245 }
35246 } else {
35247 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35248
35249 /* reset the rts and dtr */
35250 /* do the actual close */
35251 - serial->port.count--;
35252 + atomic_dec(&serial->port.count);
35253
35254 - if (serial->port.count <= 0) {
35255 - serial->port.count = 0;
35256 + if (atomic_read(&serial->port.count) <= 0) {
35257 + atomic_set(&serial->port.count, 0);
35258 tty_port_tty_set(&serial->port, NULL);
35259 if (!usb_gone)
35260 hso_stop_serial_device(serial->parent);
35261 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35262
35263 /* the actual setup */
35264 spin_lock_irqsave(&serial->serial_lock, flags);
35265 - if (serial->port.count)
35266 + if (atomic_read(&serial->port.count))
35267 _hso_serial_set_termios(tty, old);
35268 else
35269 tty->termios = old;
35270 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35271 D1("Pending read interrupt on port %d\n", i);
35272 spin_lock(&serial->serial_lock);
35273 if (serial->rx_state == RX_IDLE &&
35274 - serial->port.count > 0) {
35275 + atomic_read(&serial->port.count) > 0) {
35276 /* Setup and send a ctrl req read on
35277 * port i */
35278 if (!serial->rx_urb_filled[0]) {
35279 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35280 /* Start all serial ports */
35281 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35282 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35283 - if (dev2ser(serial_table[i])->port.count) {
35284 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35285 result =
35286 hso_start_serial_device(serial_table[i], GFP_NOIO);
35287 hso_kick_transmit(dev2ser(serial_table[i]));
35288 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35289 index 420d69b..74f90a2 100644
35290 --- a/drivers/net/wireless/ath/ath.h
35291 +++ b/drivers/net/wireless/ath/ath.h
35292 @@ -119,6 +119,7 @@ struct ath_ops {
35293 void (*write_flush) (void *);
35294 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35295 };
35296 +typedef struct ath_ops __no_const ath_ops_no_const;
35297
35298 struct ath_common;
35299 struct ath_bus_ops;
35300 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35301 index 8d78253..bebbb68 100644
35302 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35303 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35304 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35305 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35306 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35307
35308 - ACCESS_ONCE(ads->ds_link) = i->link;
35309 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35310 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35311 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35312
35313 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35314 ctl6 = SM(i->keytype, AR_EncrType);
35315 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35316
35317 if ((i->is_first || i->is_last) &&
35318 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35319 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35320 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35321 | set11nTries(i->rates, 1)
35322 | set11nTries(i->rates, 2)
35323 | set11nTries(i->rates, 3)
35324 | (i->dur_update ? AR_DurUpdateEna : 0)
35325 | SM(0, AR_BurstDur);
35326
35327 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35328 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35329 | set11nRate(i->rates, 1)
35330 | set11nRate(i->rates, 2)
35331 | set11nRate(i->rates, 3);
35332 } else {
35333 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35334 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35335 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35336 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35337 }
35338
35339 if (!i->is_first) {
35340 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35341 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35342 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35343 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35344 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35345 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35346 return;
35347 }
35348
35349 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35350 break;
35351 }
35352
35353 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35354 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35355 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35356 | SM(i->txpower, AR_XmitPower)
35357 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35358 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35359 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35360 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35361
35362 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35363 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35364 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35365 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35366
35367 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35368 return;
35369
35370 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35371 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35372 | set11nPktDurRTSCTS(i->rates, 1);
35373
35374 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35375 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35376 | set11nPktDurRTSCTS(i->rates, 3);
35377
35378 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35379 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35380 | set11nRateFlags(i->rates, 1)
35381 | set11nRateFlags(i->rates, 2)
35382 | set11nRateFlags(i->rates, 3)
35383 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35384 index d9e0824..1a874e7 100644
35385 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35386 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35387 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35388 (i->qcu << AR_TxQcuNum_S) | desc_len;
35389
35390 checksum += val;
35391 - ACCESS_ONCE(ads->info) = val;
35392 + ACCESS_ONCE_RW(ads->info) = val;
35393
35394 checksum += i->link;
35395 - ACCESS_ONCE(ads->link) = i->link;
35396 + ACCESS_ONCE_RW(ads->link) = i->link;
35397
35398 checksum += i->buf_addr[0];
35399 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35400 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35401 checksum += i->buf_addr[1];
35402 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35403 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35404 checksum += i->buf_addr[2];
35405 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35406 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35407 checksum += i->buf_addr[3];
35408 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35409 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35410
35411 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35412 - ACCESS_ONCE(ads->ctl3) = val;
35413 + ACCESS_ONCE_RW(ads->ctl3) = val;
35414 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35415 - ACCESS_ONCE(ads->ctl5) = val;
35416 + ACCESS_ONCE_RW(ads->ctl5) = val;
35417 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35418 - ACCESS_ONCE(ads->ctl7) = val;
35419 + ACCESS_ONCE_RW(ads->ctl7) = val;
35420 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35421 - ACCESS_ONCE(ads->ctl9) = val;
35422 + ACCESS_ONCE_RW(ads->ctl9) = val;
35423
35424 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35425 - ACCESS_ONCE(ads->ctl10) = checksum;
35426 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35427
35428 if (i->is_first || i->is_last) {
35429 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35430 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35431 | set11nTries(i->rates, 1)
35432 | set11nTries(i->rates, 2)
35433 | set11nTries(i->rates, 3)
35434 | (i->dur_update ? AR_DurUpdateEna : 0)
35435 | SM(0, AR_BurstDur);
35436
35437 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35438 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35439 | set11nRate(i->rates, 1)
35440 | set11nRate(i->rates, 2)
35441 | set11nRate(i->rates, 3);
35442 } else {
35443 - ACCESS_ONCE(ads->ctl13) = 0;
35444 - ACCESS_ONCE(ads->ctl14) = 0;
35445 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35446 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35447 }
35448
35449 ads->ctl20 = 0;
35450 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35451
35452 ctl17 = SM(i->keytype, AR_EncrType);
35453 if (!i->is_first) {
35454 - ACCESS_ONCE(ads->ctl11) = 0;
35455 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35456 - ACCESS_ONCE(ads->ctl15) = 0;
35457 - ACCESS_ONCE(ads->ctl16) = 0;
35458 - ACCESS_ONCE(ads->ctl17) = ctl17;
35459 - ACCESS_ONCE(ads->ctl18) = 0;
35460 - ACCESS_ONCE(ads->ctl19) = 0;
35461 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35462 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35463 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35464 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35465 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35466 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35467 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35468 return;
35469 }
35470
35471 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35472 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35473 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35474 | SM(i->txpower, AR_XmitPower)
35475 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35476 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35477 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35478 ctl12 |= SM(val, AR_PAPRDChainMask);
35479
35480 - ACCESS_ONCE(ads->ctl12) = ctl12;
35481 - ACCESS_ONCE(ads->ctl17) = ctl17;
35482 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35483 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35484
35485 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35486 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35487 | set11nPktDurRTSCTS(i->rates, 1);
35488
35489 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35490 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35491 | set11nPktDurRTSCTS(i->rates, 3);
35492
35493 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35494 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35495 | set11nRateFlags(i->rates, 1)
35496 | set11nRateFlags(i->rates, 2)
35497 | set11nRateFlags(i->rates, 3)
35498 | SM(i->rtscts_rate, AR_RTSCTSRate);
35499
35500 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35501 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35502 }
35503
35504 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35505 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35506 index 02f5007..bd0bd8f 100644
35507 --- a/drivers/net/wireless/ath/ath9k/hw.h
35508 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35509 @@ -610,7 +610,7 @@ struct ath_hw_private_ops {
35510
35511 /* ANI */
35512 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35513 -};
35514 +} __no_const;
35515
35516 /**
35517 * struct ath_hw_ops - callbacks used by hardware code and driver code
35518 @@ -640,7 +640,7 @@ struct ath_hw_ops {
35519 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35520 struct ath_hw_antcomb_conf *antconf);
35521
35522 -};
35523 +} __no_const;
35524
35525 struct ath_nf_limits {
35526 s16 max;
35527 @@ -660,7 +660,7 @@ enum ath_cal_list {
35528 #define AH_FASTCC 0x4
35529
35530 struct ath_hw {
35531 - struct ath_ops reg_ops;
35532 + ath_ops_no_const reg_ops;
35533
35534 struct ieee80211_hw *hw;
35535 struct ath_common common;
35536 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35537 index af00e2c..ab04d34 100644
35538 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35539 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35540 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35541 void (*carrsuppr)(struct brcms_phy *);
35542 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35543 void (*detach)(struct brcms_phy *);
35544 -};
35545 +} __no_const;
35546
35547 struct brcms_phy {
35548 struct brcms_phy_pub pubpi_ro;
35549 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35550 index faec404..a5277f1 100644
35551 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35552 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35553 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35554 */
35555 if (il3945_mod_params.disable_hw_scan) {
35556 D_INFO("Disabling hw_scan\n");
35557 - il3945_mac_ops.hw_scan = NULL;
35558 + pax_open_kernel();
35559 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35560 + pax_close_kernel();
35561 }
35562
35563 D_INFO("*** LOAD DRIVER ***\n");
35564 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35565 index a0b7cfd..20b49f7 100644
35566 --- a/drivers/net/wireless/mac80211_hwsim.c
35567 +++ b/drivers/net/wireless/mac80211_hwsim.c
35568 @@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35569 return -EINVAL;
35570
35571 if (fake_hw_scan) {
35572 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35573 - mac80211_hwsim_ops.sw_scan_start = NULL;
35574 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35575 + pax_open_kernel();
35576 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35577 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35578 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35579 + pax_close_kernel();
35580 }
35581
35582 spin_lock_init(&hwsim_radio_lock);
35583 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35584 index bd3b0bf..f9db92a 100644
35585 --- a/drivers/net/wireless/mwifiex/main.h
35586 +++ b/drivers/net/wireless/mwifiex/main.h
35587 @@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35588 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35589 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35590 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35591 -};
35592 +} __no_const;
35593
35594 struct mwifiex_adapter {
35595 u8 iface_type;
35596 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35597 index dfcd02a..a42a59d 100644
35598 --- a/drivers/net/wireless/rndis_wlan.c
35599 +++ b/drivers/net/wireless/rndis_wlan.c
35600 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35601
35602 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35603
35604 - if (rts_threshold < 0 || rts_threshold > 2347)
35605 + if (rts_threshold > 2347)
35606 rts_threshold = 2347;
35607
35608 tmp = cpu_to_le32(rts_threshold);
35609 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35610 index 8f75402..eed109d 100644
35611 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35612 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35613 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35614 * for hardware which doesn't support hardware
35615 * sequence counting.
35616 */
35617 - atomic_t seqno;
35618 + atomic_unchecked_t seqno;
35619 };
35620
35621 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35622 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35623 index 2fd8301..9767e8c 100644
35624 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35625 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35626 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35627 * sequence counter given by mac80211.
35628 */
35629 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35630 - seqno = atomic_add_return(0x10, &intf->seqno);
35631 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35632 else
35633 - seqno = atomic_read(&intf->seqno);
35634 + seqno = atomic_read_unchecked(&intf->seqno);
35635
35636 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35637 hdr->seq_ctrl |= cpu_to_le16(seqno);
35638 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35639 index 9d8f581..0f6589e 100644
35640 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35641 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35642 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35643 void (*reset)(struct wl1251 *wl);
35644 void (*enable_irq)(struct wl1251 *wl);
35645 void (*disable_irq)(struct wl1251 *wl);
35646 -};
35647 +} __no_const;
35648
35649 struct wl1251 {
35650 struct ieee80211_hw *hw;
35651 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35652 index 0b3f0b5..62f68bd 100644
35653 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35654 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35655 @@ -61,7 +61,7 @@ struct wlcore_ops {
35656 struct wl12xx_vif *wlvif);
35657 s8 (*get_pg_ver)(struct wl1271 *wl);
35658 void (*get_mac)(struct wl1271 *wl);
35659 -};
35660 +} __no_const;
35661
35662 enum wlcore_partitions {
35663 PART_DOWN,
35664 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35665 index f34b5b2..b5abb9f 100644
35666 --- a/drivers/oprofile/buffer_sync.c
35667 +++ b/drivers/oprofile/buffer_sync.c
35668 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35669 if (cookie == NO_COOKIE)
35670 offset = pc;
35671 if (cookie == INVALID_COOKIE) {
35672 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35673 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35674 offset = pc;
35675 }
35676 if (cookie != last_cookie) {
35677 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35678 /* add userspace sample */
35679
35680 if (!mm) {
35681 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35682 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35683 return 0;
35684 }
35685
35686 cookie = lookup_dcookie(mm, s->eip, &offset);
35687
35688 if (cookie == INVALID_COOKIE) {
35689 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35690 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35691 return 0;
35692 }
35693
35694 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35695 /* ignore backtraces if failed to add a sample */
35696 if (state == sb_bt_start) {
35697 state = sb_bt_ignore;
35698 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35699 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35700 }
35701 }
35702 release_mm(mm);
35703 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35704 index c0cc4e7..44d4e54 100644
35705 --- a/drivers/oprofile/event_buffer.c
35706 +++ b/drivers/oprofile/event_buffer.c
35707 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35708 }
35709
35710 if (buffer_pos == buffer_size) {
35711 - atomic_inc(&oprofile_stats.event_lost_overflow);
35712 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35713 return;
35714 }
35715
35716 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35717 index ed2c3ec..deda85a 100644
35718 --- a/drivers/oprofile/oprof.c
35719 +++ b/drivers/oprofile/oprof.c
35720 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35721 if (oprofile_ops.switch_events())
35722 return;
35723
35724 - atomic_inc(&oprofile_stats.multiplex_counter);
35725 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35726 start_switch_worker();
35727 }
35728
35729 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35730 index 917d28e..d62d981 100644
35731 --- a/drivers/oprofile/oprofile_stats.c
35732 +++ b/drivers/oprofile/oprofile_stats.c
35733 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35734 cpu_buf->sample_invalid_eip = 0;
35735 }
35736
35737 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35738 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35739 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35740 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35741 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35742 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35743 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35744 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35745 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35746 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35747 }
35748
35749
35750 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35751 index 38b6fc0..b5cbfce 100644
35752 --- a/drivers/oprofile/oprofile_stats.h
35753 +++ b/drivers/oprofile/oprofile_stats.h
35754 @@ -13,11 +13,11 @@
35755 #include <linux/atomic.h>
35756
35757 struct oprofile_stat_struct {
35758 - atomic_t sample_lost_no_mm;
35759 - atomic_t sample_lost_no_mapping;
35760 - atomic_t bt_lost_no_mapping;
35761 - atomic_t event_lost_overflow;
35762 - atomic_t multiplex_counter;
35763 + atomic_unchecked_t sample_lost_no_mm;
35764 + atomic_unchecked_t sample_lost_no_mapping;
35765 + atomic_unchecked_t bt_lost_no_mapping;
35766 + atomic_unchecked_t event_lost_overflow;
35767 + atomic_unchecked_t multiplex_counter;
35768 };
35769
35770 extern struct oprofile_stat_struct oprofile_stats;
35771 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35772 index 849357c..b83c1e0 100644
35773 --- a/drivers/oprofile/oprofilefs.c
35774 +++ b/drivers/oprofile/oprofilefs.c
35775 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35776
35777
35778 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35779 - char const *name, atomic_t *val)
35780 + char const *name, atomic_unchecked_t *val)
35781 {
35782 return __oprofilefs_create_file(sb, root, name,
35783 &atomic_ro_fops, 0444, val);
35784 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35785 index 3f56bc0..707d642 100644
35786 --- a/drivers/parport/procfs.c
35787 +++ b/drivers/parport/procfs.c
35788 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35789
35790 *ppos += len;
35791
35792 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35793 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35794 }
35795
35796 #ifdef CONFIG_PARPORT_1284
35797 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35798
35799 *ppos += len;
35800
35801 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35802 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35803 }
35804 #endif /* IEEE1284.3 support. */
35805
35806 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35807 index 9fff878..ad0ad53 100644
35808 --- a/drivers/pci/hotplug/cpci_hotplug.h
35809 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35810 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35811 int (*hardware_test) (struct slot* slot, u32 value);
35812 u8 (*get_power) (struct slot* slot);
35813 int (*set_power) (struct slot* slot, int value);
35814 -};
35815 +} __no_const;
35816
35817 struct cpci_hp_controller {
35818 unsigned int irq;
35819 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35820 index 76ba8a1..20ca857 100644
35821 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35822 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35823 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35824
35825 void compaq_nvram_init (void __iomem *rom_start)
35826 {
35827 +
35828 +#ifndef CONFIG_PAX_KERNEXEC
35829 if (rom_start) {
35830 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35831 }
35832 +#endif
35833 +
35834 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35835
35836 /* initialize our int15 lock */
35837 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35838 index b500840..d7159d3 100644
35839 --- a/drivers/pci/pcie/aspm.c
35840 +++ b/drivers/pci/pcie/aspm.c
35841 @@ -27,9 +27,9 @@
35842 #define MODULE_PARAM_PREFIX "pcie_aspm."
35843
35844 /* Note: those are not register definitions */
35845 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35846 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35847 -#define ASPM_STATE_L1 (4) /* L1 state */
35848 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35849 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35850 +#define ASPM_STATE_L1 (4U) /* L1 state */
35851 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35852 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35853
35854 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35855 index 658ac97..05e1b90 100644
35856 --- a/drivers/pci/probe.c
35857 +++ b/drivers/pci/probe.c
35858 @@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35859 u16 orig_cmd;
35860 struct pci_bus_region region;
35861
35862 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35863 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35864
35865 if (!dev->mmio_always_on) {
35866 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35867 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35868 index 27911b5..5b6db88 100644
35869 --- a/drivers/pci/proc.c
35870 +++ b/drivers/pci/proc.c
35871 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35872 static int __init pci_proc_init(void)
35873 {
35874 struct pci_dev *dev = NULL;
35875 +
35876 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35877 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35878 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35879 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35880 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35881 +#endif
35882 +#else
35883 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35884 +#endif
35885 proc_create("devices", 0, proc_bus_pci_dir,
35886 &proc_bus_pci_dev_operations);
35887 proc_initialized = 1;
35888 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35889 index 8b5610d..a4c22bb 100644
35890 --- a/drivers/platform/x86/thinkpad_acpi.c
35891 +++ b/drivers/platform/x86/thinkpad_acpi.c
35892 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35893 return 0;
35894 }
35895
35896 -void static hotkey_mask_warn_incomplete_mask(void)
35897 +static void hotkey_mask_warn_incomplete_mask(void)
35898 {
35899 /* log only what the user can fix... */
35900 const u32 wantedmask = hotkey_driver_mask &
35901 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35902 }
35903 }
35904
35905 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35906 - struct tp_nvram_state *newn,
35907 - const u32 event_mask)
35908 -{
35909 -
35910 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35911 do { \
35912 if ((event_mask & (1 << __scancode)) && \
35913 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35914 tpacpi_hotkey_send_key(__scancode); \
35915 } while (0)
35916
35917 - void issue_volchange(const unsigned int oldvol,
35918 - const unsigned int newvol)
35919 - {
35920 - unsigned int i = oldvol;
35921 +static void issue_volchange(const unsigned int oldvol,
35922 + const unsigned int newvol,
35923 + const u32 event_mask)
35924 +{
35925 + unsigned int i = oldvol;
35926
35927 - while (i > newvol) {
35928 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35929 - i--;
35930 - }
35931 - while (i < newvol) {
35932 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35933 - i++;
35934 - }
35935 + while (i > newvol) {
35936 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35937 + i--;
35938 }
35939 + while (i < newvol) {
35940 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35941 + i++;
35942 + }
35943 +}
35944
35945 - void issue_brightnesschange(const unsigned int oldbrt,
35946 - const unsigned int newbrt)
35947 - {
35948 - unsigned int i = oldbrt;
35949 +static void issue_brightnesschange(const unsigned int oldbrt,
35950 + const unsigned int newbrt,
35951 + const u32 event_mask)
35952 +{
35953 + unsigned int i = oldbrt;
35954
35955 - while (i > newbrt) {
35956 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35957 - i--;
35958 - }
35959 - while (i < newbrt) {
35960 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35961 - i++;
35962 - }
35963 + while (i > newbrt) {
35964 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35965 + i--;
35966 + }
35967 + while (i < newbrt) {
35968 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35969 + i++;
35970 }
35971 +}
35972
35973 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35974 + struct tp_nvram_state *newn,
35975 + const u32 event_mask)
35976 +{
35977 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35978 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35979 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35980 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35981 oldn->volume_level != newn->volume_level) {
35982 /* recently muted, or repeated mute keypress, or
35983 * multiple presses ending in mute */
35984 - issue_volchange(oldn->volume_level, newn->volume_level);
35985 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35986 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35987 }
35988 } else {
35989 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35990 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35991 }
35992 if (oldn->volume_level != newn->volume_level) {
35993 - issue_volchange(oldn->volume_level, newn->volume_level);
35994 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35995 } else if (oldn->volume_toggle != newn->volume_toggle) {
35996 /* repeated vol up/down keypress at end of scale ? */
35997 if (newn->volume_level == 0)
35998 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35999 /* handle brightness */
36000 if (oldn->brightness_level != newn->brightness_level) {
36001 issue_brightnesschange(oldn->brightness_level,
36002 - newn->brightness_level);
36003 + newn->brightness_level,
36004 + event_mask);
36005 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36006 /* repeated key presses that didn't change state */
36007 if (newn->brightness_level == 0)
36008 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36009 && !tp_features.bright_unkfw)
36010 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36011 }
36012 +}
36013
36014 #undef TPACPI_COMPARE_KEY
36015 #undef TPACPI_MAY_SEND_KEY
36016 -}
36017
36018 /*
36019 * Polling driver
36020 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36021 index 769d265..a3a05ca 100644
36022 --- a/drivers/pnp/pnpbios/bioscalls.c
36023 +++ b/drivers/pnp/pnpbios/bioscalls.c
36024 @@ -58,7 +58,7 @@ do { \
36025 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36026 } while(0)
36027
36028 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36029 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36030 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36031
36032 /*
36033 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36034
36035 cpu = get_cpu();
36036 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36037 +
36038 + pax_open_kernel();
36039 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36040 + pax_close_kernel();
36041
36042 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36043 spin_lock_irqsave(&pnp_bios_lock, flags);
36044 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36045 :"memory");
36046 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36047
36048 + pax_open_kernel();
36049 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36050 + pax_close_kernel();
36051 +
36052 put_cpu();
36053
36054 /* If we get here and this is set then the PnP BIOS faulted on us. */
36055 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36056 return status;
36057 }
36058
36059 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36060 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36061 {
36062 int i;
36063
36064 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36065 pnp_bios_callpoint.offset = header->fields.pm16offset;
36066 pnp_bios_callpoint.segment = PNP_CS16;
36067
36068 + pax_open_kernel();
36069 +
36070 for_each_possible_cpu(i) {
36071 struct desc_struct *gdt = get_cpu_gdt_table(i);
36072 if (!gdt)
36073 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36074 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36075 (unsigned long)__va(header->fields.pm16dseg));
36076 }
36077 +
36078 + pax_close_kernel();
36079 }
36080 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36081 index b0ecacb..7c9da2e 100644
36082 --- a/drivers/pnp/resource.c
36083 +++ b/drivers/pnp/resource.c
36084 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36085 return 1;
36086
36087 /* check if the resource is valid */
36088 - if (*irq < 0 || *irq > 15)
36089 + if (*irq > 15)
36090 return 0;
36091
36092 /* check if the resource is reserved */
36093 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36094 return 1;
36095
36096 /* check if the resource is valid */
36097 - if (*dma < 0 || *dma == 4 || *dma > 7)
36098 + if (*dma == 4 || *dma > 7)
36099 return 0;
36100
36101 /* check if the resource is reserved */
36102 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36103 index f5d6d37..739f6a9 100644
36104 --- a/drivers/power/bq27x00_battery.c
36105 +++ b/drivers/power/bq27x00_battery.c
36106 @@ -72,7 +72,7 @@
36107 struct bq27x00_device_info;
36108 struct bq27x00_access_methods {
36109 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36110 -};
36111 +} __no_const;
36112
36113 enum bq27x00_chip { BQ27000, BQ27500 };
36114
36115 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36116 index 8d53174..04c65de 100644
36117 --- a/drivers/regulator/max8660.c
36118 +++ b/drivers/regulator/max8660.c
36119 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36120 max8660->shadow_regs[MAX8660_OVER1] = 5;
36121 } else {
36122 /* Otherwise devices can be toggled via software */
36123 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36124 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36125 + pax_open_kernel();
36126 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36127 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36128 + pax_close_kernel();
36129 }
36130
36131 /*
36132 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36133 index 970a233..ee1f241 100644
36134 --- a/drivers/regulator/mc13892-regulator.c
36135 +++ b/drivers/regulator/mc13892-regulator.c
36136 @@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36137 }
36138 mc13xxx_unlock(mc13892);
36139
36140 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36141 + pax_open_kernel();
36142 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36143 = mc13892_vcam_set_mode;
36144 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36145 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36146 = mc13892_vcam_get_mode;
36147 + pax_close_kernel();
36148
36149 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36150 ARRAY_SIZE(mc13892_regulators));
36151 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36152 index cace6d3..f623fda 100644
36153 --- a/drivers/rtc/rtc-dev.c
36154 +++ b/drivers/rtc/rtc-dev.c
36155 @@ -14,6 +14,7 @@
36156 #include <linux/module.h>
36157 #include <linux/rtc.h>
36158 #include <linux/sched.h>
36159 +#include <linux/grsecurity.h>
36160 #include "rtc-core.h"
36161
36162 static dev_t rtc_devt;
36163 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36164 if (copy_from_user(&tm, uarg, sizeof(tm)))
36165 return -EFAULT;
36166
36167 + gr_log_timechange();
36168 +
36169 return rtc_set_time(rtc, &tm);
36170
36171 case RTC_PIE_ON:
36172 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36173 index 3fcf627..f334910 100644
36174 --- a/drivers/scsi/aacraid/aacraid.h
36175 +++ b/drivers/scsi/aacraid/aacraid.h
36176 @@ -492,7 +492,7 @@ struct adapter_ops
36177 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36178 /* Administrative operations */
36179 int (*adapter_comm)(struct aac_dev * dev, int comm);
36180 -};
36181 +} __no_const;
36182
36183 /*
36184 * Define which interrupt handler needs to be installed
36185 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36186 index 0d279c44..3d25a97 100644
36187 --- a/drivers/scsi/aacraid/linit.c
36188 +++ b/drivers/scsi/aacraid/linit.c
36189 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36190 #elif defined(__devinitconst)
36191 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36192 #else
36193 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36194 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36195 #endif
36196 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36197 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36198 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36199 index ff80552..1c4120c 100644
36200 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36201 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36202 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36203 .lldd_ata_set_dmamode = asd_set_dmamode,
36204 };
36205
36206 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36207 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36208 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36209 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36210 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36211 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36212 index 4ad7e36..d004679 100644
36213 --- a/drivers/scsi/bfa/bfa.h
36214 +++ b/drivers/scsi/bfa/bfa.h
36215 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36216 u32 *end);
36217 int cpe_vec_q0;
36218 int rme_vec_q0;
36219 -};
36220 +} __no_const;
36221 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36222
36223 struct bfa_faa_cbfn_s {
36224 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36225 index f0f80e2..8ec946b 100644
36226 --- a/drivers/scsi/bfa/bfa_fcpim.c
36227 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36228 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36229
36230 bfa_iotag_attach(fcp);
36231
36232 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36233 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36234 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36235 (fcp->num_itns * sizeof(struct bfa_itn_s));
36236 memset(fcp->itn_arr, 0,
36237 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36238 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36239 {
36240 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36241 - struct bfa_itn_s *itn;
36242 + bfa_itn_s_no_const *itn;
36243
36244 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36245 itn->isr = isr;
36246 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36247 index 36f26da..38a34a8 100644
36248 --- a/drivers/scsi/bfa/bfa_fcpim.h
36249 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36250 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36251 struct bfa_itn_s {
36252 bfa_isr_func_t isr;
36253 };
36254 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36255
36256 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36257 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36258 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36259 struct list_head iotag_tio_free_q; /* free IO resources */
36260 struct list_head iotag_unused_q; /* unused IO resources*/
36261 struct bfa_iotag_s *iotag_arr;
36262 - struct bfa_itn_s *itn_arr;
36263 + bfa_itn_s_no_const *itn_arr;
36264 int num_ioim_reqs;
36265 int num_fwtio_reqs;
36266 int num_itns;
36267 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36268 index 1a99d4b..e85d64b 100644
36269 --- a/drivers/scsi/bfa/bfa_ioc.h
36270 +++ b/drivers/scsi/bfa/bfa_ioc.h
36271 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36272 bfa_ioc_disable_cbfn_t disable_cbfn;
36273 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36274 bfa_ioc_reset_cbfn_t reset_cbfn;
36275 -};
36276 +} __no_const;
36277
36278 /*
36279 * IOC event notification mechanism.
36280 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36281 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36282 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36283 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36284 -};
36285 +} __no_const;
36286
36287 /*
36288 * Queue element to wait for room in request queue. FIFO order is
36289 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36290 index b48c24f..dac0fbc 100644
36291 --- a/drivers/scsi/hosts.c
36292 +++ b/drivers/scsi/hosts.c
36293 @@ -42,7 +42,7 @@
36294 #include "scsi_logging.h"
36295
36296
36297 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36298 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36299
36300
36301 static void scsi_host_cls_release(struct device *dev)
36302 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36303 * subtract one because we increment first then return, but we need to
36304 * know what the next host number was before increment
36305 */
36306 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36307 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36308 shost->dma_channel = 0xff;
36309
36310 /* These three are default values which can be overridden */
36311 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36312 index 796482b..d08435c 100644
36313 --- a/drivers/scsi/hpsa.c
36314 +++ b/drivers/scsi/hpsa.c
36315 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36316 unsigned long flags;
36317
36318 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36319 - return h->access.command_completed(h, q);
36320 + return h->access->command_completed(h, q);
36321
36322 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36323 a = rq->head[rq->current_entry];
36324 @@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36325 while (!list_empty(&h->reqQ)) {
36326 c = list_entry(h->reqQ.next, struct CommandList, list);
36327 /* can't do anything if fifo is full */
36328 - if ((h->access.fifo_full(h))) {
36329 + if ((h->access->fifo_full(h))) {
36330 dev_warn(&h->pdev->dev, "fifo full\n");
36331 break;
36332 }
36333 @@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36334
36335 /* Tell the controller execute command */
36336 spin_unlock_irqrestore(&h->lock, flags);
36337 - h->access.submit_command(h, c);
36338 + h->access->submit_command(h, c);
36339 spin_lock_irqsave(&h->lock, flags);
36340 }
36341 spin_unlock_irqrestore(&h->lock, flags);
36342 @@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36343
36344 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36345 {
36346 - return h->access.command_completed(h, q);
36347 + return h->access->command_completed(h, q);
36348 }
36349
36350 static inline bool interrupt_pending(struct ctlr_info *h)
36351 {
36352 - return h->access.intr_pending(h);
36353 + return h->access->intr_pending(h);
36354 }
36355
36356 static inline long interrupt_not_for_us(struct ctlr_info *h)
36357 {
36358 - return (h->access.intr_pending(h) == 0) ||
36359 + return (h->access->intr_pending(h) == 0) ||
36360 (h->interrupts_enabled == 0);
36361 }
36362
36363 @@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36364 if (prod_index < 0)
36365 return -ENODEV;
36366 h->product_name = products[prod_index].product_name;
36367 - h->access = *(products[prod_index].access);
36368 + h->access = products[prod_index].access;
36369
36370 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36371 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36372 @@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36373
36374 assert_spin_locked(&lockup_detector_lock);
36375 remove_ctlr_from_lockup_detector_list(h);
36376 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36377 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36378 spin_lock_irqsave(&h->lock, flags);
36379 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36380 spin_unlock_irqrestore(&h->lock, flags);
36381 @@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36382 }
36383
36384 /* make sure the board interrupts are off */
36385 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36386 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36387
36388 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36389 goto clean2;
36390 @@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36391 * fake ones to scoop up any residual completions.
36392 */
36393 spin_lock_irqsave(&h->lock, flags);
36394 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36395 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36396 spin_unlock_irqrestore(&h->lock, flags);
36397 free_irqs(h);
36398 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36399 @@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36400 dev_info(&h->pdev->dev, "Board READY.\n");
36401 dev_info(&h->pdev->dev,
36402 "Waiting for stale completions to drain.\n");
36403 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36404 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36405 msleep(10000);
36406 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36407 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36408
36409 rc = controller_reset_failed(h->cfgtable);
36410 if (rc)
36411 @@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36412 }
36413
36414 /* Turn the interrupts on so we can service requests */
36415 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36416 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36417
36418 hpsa_hba_inquiry(h);
36419 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36420 @@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36421 * To write all data in the battery backed cache to disks
36422 */
36423 hpsa_flush_cache(h);
36424 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36425 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36426 hpsa_free_irqs_and_disable_msix(h);
36427 }
36428
36429 @@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36430 return;
36431 }
36432 /* Change the access methods to the performant access methods */
36433 - h->access = SA5_performant_access;
36434 + h->access = &SA5_performant_access;
36435 h->transMethod = CFGTBL_Trans_Performant;
36436 }
36437
36438 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36439 index 9816479..c5d4e97 100644
36440 --- a/drivers/scsi/hpsa.h
36441 +++ b/drivers/scsi/hpsa.h
36442 @@ -79,7 +79,7 @@ struct ctlr_info {
36443 unsigned int msix_vector;
36444 unsigned int msi_vector;
36445 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36446 - struct access_method access;
36447 + struct access_method *access;
36448
36449 /* queue and queue Info */
36450 struct list_head reqQ;
36451 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36452 index f2df059..a3a9930 100644
36453 --- a/drivers/scsi/ips.h
36454 +++ b/drivers/scsi/ips.h
36455 @@ -1027,7 +1027,7 @@ typedef struct {
36456 int (*intr)(struct ips_ha *);
36457 void (*enableint)(struct ips_ha *);
36458 uint32_t (*statupd)(struct ips_ha *);
36459 -} ips_hw_func_t;
36460 +} __no_const ips_hw_func_t;
36461
36462 typedef struct ips_ha {
36463 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36464 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36465 index aceffad..c35c08d 100644
36466 --- a/drivers/scsi/libfc/fc_exch.c
36467 +++ b/drivers/scsi/libfc/fc_exch.c
36468 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36469 * all together if not used XXX
36470 */
36471 struct {
36472 - atomic_t no_free_exch;
36473 - atomic_t no_free_exch_xid;
36474 - atomic_t xid_not_found;
36475 - atomic_t xid_busy;
36476 - atomic_t seq_not_found;
36477 - atomic_t non_bls_resp;
36478 + atomic_unchecked_t no_free_exch;
36479 + atomic_unchecked_t no_free_exch_xid;
36480 + atomic_unchecked_t xid_not_found;
36481 + atomic_unchecked_t xid_busy;
36482 + atomic_unchecked_t seq_not_found;
36483 + atomic_unchecked_t non_bls_resp;
36484 } stats;
36485 };
36486
36487 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36488 /* allocate memory for exchange */
36489 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36490 if (!ep) {
36491 - atomic_inc(&mp->stats.no_free_exch);
36492 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36493 goto out;
36494 }
36495 memset(ep, 0, sizeof(*ep));
36496 @@ -780,7 +780,7 @@ out:
36497 return ep;
36498 err:
36499 spin_unlock_bh(&pool->lock);
36500 - atomic_inc(&mp->stats.no_free_exch_xid);
36501 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36502 mempool_free(ep, mp->ep_pool);
36503 return NULL;
36504 }
36505 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36506 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36507 ep = fc_exch_find(mp, xid);
36508 if (!ep) {
36509 - atomic_inc(&mp->stats.xid_not_found);
36510 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36511 reject = FC_RJT_OX_ID;
36512 goto out;
36513 }
36514 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36515 ep = fc_exch_find(mp, xid);
36516 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36517 if (ep) {
36518 - atomic_inc(&mp->stats.xid_busy);
36519 + atomic_inc_unchecked(&mp->stats.xid_busy);
36520 reject = FC_RJT_RX_ID;
36521 goto rel;
36522 }
36523 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36524 }
36525 xid = ep->xid; /* get our XID */
36526 } else if (!ep) {
36527 - atomic_inc(&mp->stats.xid_not_found);
36528 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36529 reject = FC_RJT_RX_ID; /* XID not found */
36530 goto out;
36531 }
36532 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36533 } else {
36534 sp = &ep->seq;
36535 if (sp->id != fh->fh_seq_id) {
36536 - atomic_inc(&mp->stats.seq_not_found);
36537 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36538 if (f_ctl & FC_FC_END_SEQ) {
36539 /*
36540 * Update sequence_id based on incoming last
36541 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36542
36543 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36544 if (!ep) {
36545 - atomic_inc(&mp->stats.xid_not_found);
36546 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36547 goto out;
36548 }
36549 if (ep->esb_stat & ESB_ST_COMPLETE) {
36550 - atomic_inc(&mp->stats.xid_not_found);
36551 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36552 goto rel;
36553 }
36554 if (ep->rxid == FC_XID_UNKNOWN)
36555 ep->rxid = ntohs(fh->fh_rx_id);
36556 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36557 - atomic_inc(&mp->stats.xid_not_found);
36558 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36559 goto rel;
36560 }
36561 if (ep->did != ntoh24(fh->fh_s_id) &&
36562 ep->did != FC_FID_FLOGI) {
36563 - atomic_inc(&mp->stats.xid_not_found);
36564 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36565 goto rel;
36566 }
36567 sof = fr_sof(fp);
36568 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36569 sp->ssb_stat |= SSB_ST_RESP;
36570 sp->id = fh->fh_seq_id;
36571 } else if (sp->id != fh->fh_seq_id) {
36572 - atomic_inc(&mp->stats.seq_not_found);
36573 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36574 goto rel;
36575 }
36576
36577 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36578 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36579
36580 if (!sp)
36581 - atomic_inc(&mp->stats.xid_not_found);
36582 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36583 else
36584 - atomic_inc(&mp->stats.non_bls_resp);
36585 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36586
36587 fc_frame_free(fp);
36588 }
36589 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36590 index d109cc3..09f4e7d 100644
36591 --- a/drivers/scsi/libsas/sas_ata.c
36592 +++ b/drivers/scsi/libsas/sas_ata.c
36593 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36594 .postreset = ata_std_postreset,
36595 .error_handler = ata_std_error_handler,
36596 .post_internal_cmd = sas_ata_post_internal,
36597 - .qc_defer = ata_std_qc_defer,
36598 + .qc_defer = ata_std_qc_defer,
36599 .qc_prep = ata_noop_qc_prep,
36600 .qc_issue = sas_ata_qc_issue,
36601 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36602 diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36603 index fe5d396..e93d526 100644
36604 --- a/drivers/scsi/lpfc/Makefile
36605 +++ b/drivers/scsi/lpfc/Makefile
36606 @@ -22,7 +22,7 @@
36607 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36608 ccflags-$(GCOV) += -O0
36609
36610 -ccflags-y += -Werror
36611 +#ccflags-y += -Werror
36612
36613 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36614
36615 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36616 index e5da6da..c888d48 100644
36617 --- a/drivers/scsi/lpfc/lpfc.h
36618 +++ b/drivers/scsi/lpfc/lpfc.h
36619 @@ -416,7 +416,7 @@ struct lpfc_vport {
36620 struct dentry *debug_nodelist;
36621 struct dentry *vport_debugfs_root;
36622 struct lpfc_debugfs_trc *disc_trc;
36623 - atomic_t disc_trc_cnt;
36624 + atomic_unchecked_t disc_trc_cnt;
36625 #endif
36626 uint8_t stat_data_enabled;
36627 uint8_t stat_data_blocked;
36628 @@ -830,8 +830,8 @@ struct lpfc_hba {
36629 struct timer_list fabric_block_timer;
36630 unsigned long bit_flags;
36631 #define FABRIC_COMANDS_BLOCKED 0
36632 - atomic_t num_rsrc_err;
36633 - atomic_t num_cmd_success;
36634 + atomic_unchecked_t num_rsrc_err;
36635 + atomic_unchecked_t num_cmd_success;
36636 unsigned long last_rsrc_error_time;
36637 unsigned long last_ramp_down_time;
36638 unsigned long last_ramp_up_time;
36639 @@ -867,7 +867,7 @@ struct lpfc_hba {
36640
36641 struct dentry *debug_slow_ring_trc;
36642 struct lpfc_debugfs_trc *slow_ring_trc;
36643 - atomic_t slow_ring_trc_cnt;
36644 + atomic_unchecked_t slow_ring_trc_cnt;
36645 /* iDiag debugfs sub-directory */
36646 struct dentry *idiag_root;
36647 struct dentry *idiag_pci_cfg;
36648 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36649 index 3217d63..c417981 100644
36650 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36651 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36652 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36653
36654 #include <linux/debugfs.h>
36655
36656 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36657 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36658 static unsigned long lpfc_debugfs_start_time = 0L;
36659
36660 /* iDiag */
36661 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36662 lpfc_debugfs_enable = 0;
36663
36664 len = 0;
36665 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36666 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36667 (lpfc_debugfs_max_disc_trc - 1);
36668 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36669 dtp = vport->disc_trc + i;
36670 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36671 lpfc_debugfs_enable = 0;
36672
36673 len = 0;
36674 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36675 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36676 (lpfc_debugfs_max_slow_ring_trc - 1);
36677 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36678 dtp = phba->slow_ring_trc + i;
36679 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36680 !vport || !vport->disc_trc)
36681 return;
36682
36683 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36684 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36685 (lpfc_debugfs_max_disc_trc - 1);
36686 dtp = vport->disc_trc + index;
36687 dtp->fmt = fmt;
36688 dtp->data1 = data1;
36689 dtp->data2 = data2;
36690 dtp->data3 = data3;
36691 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36692 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36693 dtp->jif = jiffies;
36694 #endif
36695 return;
36696 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36697 !phba || !phba->slow_ring_trc)
36698 return;
36699
36700 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36701 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36702 (lpfc_debugfs_max_slow_ring_trc - 1);
36703 dtp = phba->slow_ring_trc + index;
36704 dtp->fmt = fmt;
36705 dtp->data1 = data1;
36706 dtp->data2 = data2;
36707 dtp->data3 = data3;
36708 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36709 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36710 dtp->jif = jiffies;
36711 #endif
36712 return;
36713 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36714 "slow_ring buffer\n");
36715 goto debug_failed;
36716 }
36717 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36718 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36719 memset(phba->slow_ring_trc, 0,
36720 (sizeof(struct lpfc_debugfs_trc) *
36721 lpfc_debugfs_max_slow_ring_trc));
36722 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36723 "buffer\n");
36724 goto debug_failed;
36725 }
36726 - atomic_set(&vport->disc_trc_cnt, 0);
36727 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36728
36729 snprintf(name, sizeof(name), "discovery_trace");
36730 vport->debug_disc_trc =
36731 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36732 index 411ed48..967f553 100644
36733 --- a/drivers/scsi/lpfc/lpfc_init.c
36734 +++ b/drivers/scsi/lpfc/lpfc_init.c
36735 @@ -10341,8 +10341,10 @@ lpfc_init(void)
36736 "misc_register returned with status %d", error);
36737
36738 if (lpfc_enable_npiv) {
36739 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36740 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36741 + pax_open_kernel();
36742 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36743 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36744 + pax_close_kernel();
36745 }
36746 lpfc_transport_template =
36747 fc_attach_transport(&lpfc_transport_functions);
36748 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36749 index 66e0906..1620281 100644
36750 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36751 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36752 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36753 uint32_t evt_posted;
36754
36755 spin_lock_irqsave(&phba->hbalock, flags);
36756 - atomic_inc(&phba->num_rsrc_err);
36757 + atomic_inc_unchecked(&phba->num_rsrc_err);
36758 phba->last_rsrc_error_time = jiffies;
36759
36760 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36761 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36762 unsigned long flags;
36763 struct lpfc_hba *phba = vport->phba;
36764 uint32_t evt_posted;
36765 - atomic_inc(&phba->num_cmd_success);
36766 + atomic_inc_unchecked(&phba->num_cmd_success);
36767
36768 if (vport->cfg_lun_queue_depth <= queue_depth)
36769 return;
36770 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36771 unsigned long num_rsrc_err, num_cmd_success;
36772 int i;
36773
36774 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36775 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36776 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36777 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36778
36779 /*
36780 * The error and success command counters are global per
36781 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36782 }
36783 }
36784 lpfc_destroy_vport_work_array(phba, vports);
36785 - atomic_set(&phba->num_rsrc_err, 0);
36786 - atomic_set(&phba->num_cmd_success, 0);
36787 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36788 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36789 }
36790
36791 /**
36792 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36793 }
36794 }
36795 lpfc_destroy_vport_work_array(phba, vports);
36796 - atomic_set(&phba->num_rsrc_err, 0);
36797 - atomic_set(&phba->num_cmd_success, 0);
36798 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36799 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36800 }
36801
36802 /**
36803 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36804 index ea8a0b4..812a124 100644
36805 --- a/drivers/scsi/pmcraid.c
36806 +++ b/drivers/scsi/pmcraid.c
36807 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36808 res->scsi_dev = scsi_dev;
36809 scsi_dev->hostdata = res;
36810 res->change_detected = 0;
36811 - atomic_set(&res->read_failures, 0);
36812 - atomic_set(&res->write_failures, 0);
36813 + atomic_set_unchecked(&res->read_failures, 0);
36814 + atomic_set_unchecked(&res->write_failures, 0);
36815 rc = 0;
36816 }
36817 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36818 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36819
36820 /* If this was a SCSI read/write command keep count of errors */
36821 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36822 - atomic_inc(&res->read_failures);
36823 + atomic_inc_unchecked(&res->read_failures);
36824 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36825 - atomic_inc(&res->write_failures);
36826 + atomic_inc_unchecked(&res->write_failures);
36827
36828 if (!RES_IS_GSCSI(res->cfg_entry) &&
36829 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36830 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36831 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36832 * hrrq_id assigned here in queuecommand
36833 */
36834 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36835 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36836 pinstance->num_hrrq;
36837 cmd->cmd_done = pmcraid_io_done;
36838
36839 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36840 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36841 * hrrq_id assigned here in queuecommand
36842 */
36843 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36844 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36845 pinstance->num_hrrq;
36846
36847 if (request_size) {
36848 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36849
36850 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36851 /* add resources only after host is added into system */
36852 - if (!atomic_read(&pinstance->expose_resources))
36853 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36854 return;
36855
36856 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36857 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36858 init_waitqueue_head(&pinstance->reset_wait_q);
36859
36860 atomic_set(&pinstance->outstanding_cmds, 0);
36861 - atomic_set(&pinstance->last_message_id, 0);
36862 - atomic_set(&pinstance->expose_resources, 0);
36863 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36864 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36865
36866 INIT_LIST_HEAD(&pinstance->free_res_q);
36867 INIT_LIST_HEAD(&pinstance->used_res_q);
36868 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36869 /* Schedule worker thread to handle CCN and take care of adding and
36870 * removing devices to OS
36871 */
36872 - atomic_set(&pinstance->expose_resources, 1);
36873 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36874 schedule_work(&pinstance->worker_q);
36875 return rc;
36876
36877 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36878 index e1d150f..6c6df44 100644
36879 --- a/drivers/scsi/pmcraid.h
36880 +++ b/drivers/scsi/pmcraid.h
36881 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36882 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36883
36884 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36885 - atomic_t last_message_id;
36886 + atomic_unchecked_t last_message_id;
36887
36888 /* configuration table */
36889 struct pmcraid_config_table *cfg_table;
36890 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36891 atomic_t outstanding_cmds;
36892
36893 /* should add/delete resources to mid-layer now ?*/
36894 - atomic_t expose_resources;
36895 + atomic_unchecked_t expose_resources;
36896
36897
36898
36899 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36900 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36901 };
36902 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36903 - atomic_t read_failures; /* count of failed READ commands */
36904 - atomic_t write_failures; /* count of failed WRITE commands */
36905 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36906 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36907
36908 /* To indicate add/delete/modify during CCN */
36909 u8 change_detected;
36910 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36911 index 5ab9530..2dd80f7 100644
36912 --- a/drivers/scsi/qla2xxx/qla_attr.c
36913 +++ b/drivers/scsi/qla2xxx/qla_attr.c
36914 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36915 return 0;
36916 }
36917
36918 -struct fc_function_template qla2xxx_transport_functions = {
36919 +fc_function_template_no_const qla2xxx_transport_functions = {
36920
36921 .show_host_node_name = 1,
36922 .show_host_port_name = 1,
36923 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36924 .bsg_timeout = qla24xx_bsg_timeout,
36925 };
36926
36927 -struct fc_function_template qla2xxx_transport_vport_functions = {
36928 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
36929
36930 .show_host_node_name = 1,
36931 .show_host_port_name = 1,
36932 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36933 index 39007f5..7fafc64 100644
36934 --- a/drivers/scsi/qla2xxx/qla_def.h
36935 +++ b/drivers/scsi/qla2xxx/qla_def.h
36936 @@ -2284,7 +2284,7 @@ struct isp_operations {
36937 int (*start_scsi) (srb_t *);
36938 int (*abort_isp) (struct scsi_qla_host *);
36939 int (*iospace_config)(struct qla_hw_data*);
36940 -};
36941 +} __no_const;
36942
36943 /* MSI-X Support *************************************************************/
36944
36945 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36946 index 9eacd2d..d79629c 100644
36947 --- a/drivers/scsi/qla2xxx/qla_gbl.h
36948 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
36949 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36950 struct device_attribute;
36951 extern struct device_attribute *qla2x00_host_attrs[];
36952 struct fc_function_template;
36953 -extern struct fc_function_template qla2xxx_transport_functions;
36954 -extern struct fc_function_template qla2xxx_transport_vport_functions;
36955 +extern fc_function_template_no_const qla2xxx_transport_functions;
36956 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36957 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36958 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36959 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36960 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36961 index 96a5616..eeb185a 100644
36962 --- a/drivers/scsi/qla4xxx/ql4_def.h
36963 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36964 @@ -268,7 +268,7 @@ struct ddb_entry {
36965 * (4000 only) */
36966 atomic_t relogin_timer; /* Max Time to wait for
36967 * relogin to complete */
36968 - atomic_t relogin_retry_count; /* Num of times relogin has been
36969 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36970 * retried */
36971 uint32_t default_time2wait; /* Default Min time between
36972 * relogins (+aens) */
36973 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36974 index cd15678..f7e6846 100644
36975 --- a/drivers/scsi/qla4xxx/ql4_os.c
36976 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36977 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36978 */
36979 if (!iscsi_is_session_online(cls_sess)) {
36980 /* Reset retry relogin timer */
36981 - atomic_inc(&ddb_entry->relogin_retry_count);
36982 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36983 DEBUG2(ql4_printk(KERN_INFO, ha,
36984 "%s: index[%d] relogin timed out-retrying"
36985 " relogin (%d), retry (%d)\n", __func__,
36986 ddb_entry->fw_ddb_index,
36987 - atomic_read(&ddb_entry->relogin_retry_count),
36988 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36989 ddb_entry->default_time2wait + 4));
36990 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36991 atomic_set(&ddb_entry->retry_relogin_timer,
36992 @@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36993
36994 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36995 atomic_set(&ddb_entry->relogin_timer, 0);
36996 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36997 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36998 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36999 ddb_entry->default_relogin_timeout =
37000 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37001 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37002 index bbbc9c9..ce22f77 100644
37003 --- a/drivers/scsi/scsi.c
37004 +++ b/drivers/scsi/scsi.c
37005 @@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37006 unsigned long timeout;
37007 int rtn = 0;
37008
37009 - atomic_inc(&cmd->device->iorequest_cnt);
37010 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37011
37012 /* check if the device is still usable */
37013 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37014 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37015 index 495db80..fb37d59 100644
37016 --- a/drivers/scsi/scsi_lib.c
37017 +++ b/drivers/scsi/scsi_lib.c
37018 @@ -1422,7 +1422,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37019 shost = sdev->host;
37020 scsi_init_cmd_errh(cmd);
37021 cmd->result = DID_NO_CONNECT << 16;
37022 - atomic_inc(&cmd->device->iorequest_cnt);
37023 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37024
37025 /*
37026 * SCSI request completion path will do scsi_device_unbusy(),
37027 @@ -1448,9 +1448,9 @@ static void scsi_softirq_done(struct request *rq)
37028
37029 INIT_LIST_HEAD(&cmd->eh_entry);
37030
37031 - atomic_inc(&cmd->device->iodone_cnt);
37032 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37033 if (cmd->result)
37034 - atomic_inc(&cmd->device->ioerr_cnt);
37035 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37036
37037 disposition = scsi_decide_disposition(cmd);
37038 if (disposition != SUCCESS &&
37039 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37040 index bb7c482..7551a95 100644
37041 --- a/drivers/scsi/scsi_sysfs.c
37042 +++ b/drivers/scsi/scsi_sysfs.c
37043 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37044 char *buf) \
37045 { \
37046 struct scsi_device *sdev = to_scsi_device(dev); \
37047 - unsigned long long count = atomic_read(&sdev->field); \
37048 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37049 return snprintf(buf, 20, "0x%llx\n", count); \
37050 } \
37051 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37052 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37053 index 84a1fdf..693b0d6 100644
37054 --- a/drivers/scsi/scsi_tgt_lib.c
37055 +++ b/drivers/scsi/scsi_tgt_lib.c
37056 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37057 int err;
37058
37059 dprintk("%lx %u\n", uaddr, len);
37060 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37061 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37062 if (err) {
37063 /*
37064 * TODO: need to fixup sg_tablesize, max_segment_size,
37065 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37066 index 5797604..289a5b5 100644
37067 --- a/drivers/scsi/scsi_transport_fc.c
37068 +++ b/drivers/scsi/scsi_transport_fc.c
37069 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37070 * Netlink Infrastructure
37071 */
37072
37073 -static atomic_t fc_event_seq;
37074 +static atomic_unchecked_t fc_event_seq;
37075
37076 /**
37077 * fc_get_event_number - Obtain the next sequential FC event number
37078 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37079 u32
37080 fc_get_event_number(void)
37081 {
37082 - return atomic_add_return(1, &fc_event_seq);
37083 + return atomic_add_return_unchecked(1, &fc_event_seq);
37084 }
37085 EXPORT_SYMBOL(fc_get_event_number);
37086
37087 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37088 {
37089 int error;
37090
37091 - atomic_set(&fc_event_seq, 0);
37092 + atomic_set_unchecked(&fc_event_seq, 0);
37093
37094 error = transport_class_register(&fc_host_class);
37095 if (error)
37096 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37097 char *cp;
37098
37099 *val = simple_strtoul(buf, &cp, 0);
37100 - if ((*cp && (*cp != '\n')) || (*val < 0))
37101 + if (*cp && (*cp != '\n'))
37102 return -EINVAL;
37103 /*
37104 * Check for overflow; dev_loss_tmo is u32
37105 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37106 index 1cf640e..78e9014 100644
37107 --- a/drivers/scsi/scsi_transport_iscsi.c
37108 +++ b/drivers/scsi/scsi_transport_iscsi.c
37109 @@ -79,7 +79,7 @@ struct iscsi_internal {
37110 struct transport_container session_cont;
37111 };
37112
37113 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37114 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37115 static struct workqueue_struct *iscsi_eh_timer_workq;
37116
37117 static DEFINE_IDA(iscsi_sess_ida);
37118 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37119 int err;
37120
37121 ihost = shost->shost_data;
37122 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37123 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37124
37125 if (target_id == ISCSI_MAX_TARGET) {
37126 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37127 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37128 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37129 ISCSI_TRANSPORT_VERSION);
37130
37131 - atomic_set(&iscsi_session_nr, 0);
37132 + atomic_set_unchecked(&iscsi_session_nr, 0);
37133
37134 err = class_register(&iscsi_transport_class);
37135 if (err)
37136 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37137 index 21a045e..ec89e03 100644
37138 --- a/drivers/scsi/scsi_transport_srp.c
37139 +++ b/drivers/scsi/scsi_transport_srp.c
37140 @@ -33,7 +33,7 @@
37141 #include "scsi_transport_srp_internal.h"
37142
37143 struct srp_host_attrs {
37144 - atomic_t next_port_id;
37145 + atomic_unchecked_t next_port_id;
37146 };
37147 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37148
37149 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37150 struct Scsi_Host *shost = dev_to_shost(dev);
37151 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37152
37153 - atomic_set(&srp_host->next_port_id, 0);
37154 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37155 return 0;
37156 }
37157
37158 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37159 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37160 rport->roles = ids->roles;
37161
37162 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37163 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37164 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37165
37166 transport_setup_device(&rport->dev);
37167 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37168 index 9c5c5f2..8414557 100644
37169 --- a/drivers/scsi/sg.c
37170 +++ b/drivers/scsi/sg.c
37171 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37172 sdp->disk->disk_name,
37173 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37174 NULL,
37175 - (char *)arg);
37176 + (char __user *)arg);
37177 case BLKTRACESTART:
37178 return blk_trace_startstop(sdp->device->request_queue, 1);
37179 case BLKTRACESTOP:
37180 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37181 index 1041cb8..4a946fa 100644
37182 --- a/drivers/spi/spi.c
37183 +++ b/drivers/spi/spi.c
37184 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37185 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37186
37187 /* portable code must never pass more than 32 bytes */
37188 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37189 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37190
37191 static u8 *buf;
37192
37193 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37194 index 34afc16..ffe44dd 100644
37195 --- a/drivers/staging/octeon/ethernet-rx.c
37196 +++ b/drivers/staging/octeon/ethernet-rx.c
37197 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37198 /* Increment RX stats for virtual ports */
37199 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37200 #ifdef CONFIG_64BIT
37201 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37202 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37203 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37204 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37205 #else
37206 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37207 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37208 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37209 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37210 #endif
37211 }
37212 netif_receive_skb(skb);
37213 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37214 dev->name);
37215 */
37216 #ifdef CONFIG_64BIT
37217 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37218 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37219 #else
37220 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37221 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37222 #endif
37223 dev_kfree_skb_irq(skb);
37224 }
37225 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37226 index 18f7a79..cc3bc24 100644
37227 --- a/drivers/staging/octeon/ethernet.c
37228 +++ b/drivers/staging/octeon/ethernet.c
37229 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37230 * since the RX tasklet also increments it.
37231 */
37232 #ifdef CONFIG_64BIT
37233 - atomic64_add(rx_status.dropped_packets,
37234 - (atomic64_t *)&priv->stats.rx_dropped);
37235 + atomic64_add_unchecked(rx_status.dropped_packets,
37236 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37237 #else
37238 - atomic_add(rx_status.dropped_packets,
37239 - (atomic_t *)&priv->stats.rx_dropped);
37240 + atomic_add_unchecked(rx_status.dropped_packets,
37241 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37242 #endif
37243 }
37244
37245 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37246 index dc23395..cf7e9b1 100644
37247 --- a/drivers/staging/rtl8712/rtl871x_io.h
37248 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37249 @@ -108,7 +108,7 @@ struct _io_ops {
37250 u8 *pmem);
37251 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37252 u8 *pmem);
37253 -};
37254 +} __no_const;
37255
37256 struct io_req {
37257 struct list_head list;
37258 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37259 index c7b5e8b..783d6cb 100644
37260 --- a/drivers/staging/sbe-2t3e3/netdev.c
37261 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37262 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37263 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37264
37265 if (rlen)
37266 - if (copy_to_user(data, &resp, rlen))
37267 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37268 return -EFAULT;
37269
37270 return 0;
37271 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37272 index 42cdafe..2769103 100644
37273 --- a/drivers/staging/speakup/speakup_soft.c
37274 +++ b/drivers/staging/speakup/speakup_soft.c
37275 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37276 break;
37277 } else if (!initialized) {
37278 if (*init) {
37279 - ch = *init;
37280 init++;
37281 } else {
37282 initialized = 1;
37283 }
37284 + ch = *init;
37285 } else {
37286 ch = synth_buffer_getc();
37287 }
37288 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37289 index 5d89c0f..9261317 100644
37290 --- a/drivers/staging/usbip/usbip_common.h
37291 +++ b/drivers/staging/usbip/usbip_common.h
37292 @@ -289,7 +289,7 @@ struct usbip_device {
37293 void (*shutdown)(struct usbip_device *);
37294 void (*reset)(struct usbip_device *);
37295 void (*unusable)(struct usbip_device *);
37296 - } eh_ops;
37297 + } __no_const eh_ops;
37298 };
37299
37300 #define kthread_get_run(threadfn, data, namefmt, ...) \
37301 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37302 index 88b3298..3783eee 100644
37303 --- a/drivers/staging/usbip/vhci.h
37304 +++ b/drivers/staging/usbip/vhci.h
37305 @@ -88,7 +88,7 @@ struct vhci_hcd {
37306 unsigned resuming:1;
37307 unsigned long re_timeout;
37308
37309 - atomic_t seqnum;
37310 + atomic_unchecked_t seqnum;
37311
37312 /*
37313 * NOTE:
37314 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37315 index f708cba..2de6d72 100644
37316 --- a/drivers/staging/usbip/vhci_hcd.c
37317 +++ b/drivers/staging/usbip/vhci_hcd.c
37318 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37319 return;
37320 }
37321
37322 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37323 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37324 if (priv->seqnum == 0xffff)
37325 dev_info(&urb->dev->dev, "seqnum max\n");
37326
37327 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37328 return -ENOMEM;
37329 }
37330
37331 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37332 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37333 if (unlink->seqnum == 0xffff)
37334 pr_info("seqnum max\n");
37335
37336 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37337 vdev->rhport = rhport;
37338 }
37339
37340 - atomic_set(&vhci->seqnum, 0);
37341 + atomic_set_unchecked(&vhci->seqnum, 0);
37342 spin_lock_init(&vhci->lock);
37343
37344 hcd->power_budget = 0; /* no limit */
37345 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37346 index f0eaf04..5a82e06 100644
37347 --- a/drivers/staging/usbip/vhci_rx.c
37348 +++ b/drivers/staging/usbip/vhci_rx.c
37349 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37350 if (!urb) {
37351 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37352 pr_info("max seqnum %d\n",
37353 - atomic_read(&the_controller->seqnum));
37354 + atomic_read_unchecked(&the_controller->seqnum));
37355 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37356 return;
37357 }
37358 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37359 index 7735027..30eed13 100644
37360 --- a/drivers/staging/vt6655/hostap.c
37361 +++ b/drivers/staging/vt6655/hostap.c
37362 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37363 *
37364 */
37365
37366 +static net_device_ops_no_const apdev_netdev_ops;
37367 +
37368 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37369 {
37370 PSDevice apdev_priv;
37371 struct net_device *dev = pDevice->dev;
37372 int ret;
37373 - const struct net_device_ops apdev_netdev_ops = {
37374 - .ndo_start_xmit = pDevice->tx_80211,
37375 - };
37376
37377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37378
37379 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37380 *apdev_priv = *pDevice;
37381 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37382
37383 + /* only half broken now */
37384 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37385 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37386
37387 pDevice->apdev->type = ARPHRD_IEEE80211;
37388 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37389 index 51b5adf..098e320 100644
37390 --- a/drivers/staging/vt6656/hostap.c
37391 +++ b/drivers/staging/vt6656/hostap.c
37392 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37393 *
37394 */
37395
37396 +static net_device_ops_no_const apdev_netdev_ops;
37397 +
37398 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37399 {
37400 PSDevice apdev_priv;
37401 struct net_device *dev = pDevice->dev;
37402 int ret;
37403 - const struct net_device_ops apdev_netdev_ops = {
37404 - .ndo_start_xmit = pDevice->tx_80211,
37405 - };
37406
37407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37408
37409 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37410 *apdev_priv = *pDevice;
37411 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37412
37413 + /* only half broken now */
37414 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37415 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37416
37417 pDevice->apdev->type = ARPHRD_IEEE80211;
37418 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37419 index 7843dfd..3db105f 100644
37420 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37421 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37422 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37423
37424 struct usbctlx_completor {
37425 int (*complete) (struct usbctlx_completor *);
37426 -};
37427 +} __no_const;
37428
37429 static int
37430 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37431 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37432 index 1ca66ea..76f1343 100644
37433 --- a/drivers/staging/zcache/tmem.c
37434 +++ b/drivers/staging/zcache/tmem.c
37435 @@ -39,7 +39,7 @@
37436 * A tmem host implementation must use this function to register callbacks
37437 * for memory allocation.
37438 */
37439 -static struct tmem_hostops tmem_hostops;
37440 +static tmem_hostops_no_const tmem_hostops;
37441
37442 static void tmem_objnode_tree_init(void);
37443
37444 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37445 * A tmem host implementation must use this function to register
37446 * callbacks for a page-accessible memory (PAM) implementation
37447 */
37448 -static struct tmem_pamops tmem_pamops;
37449 +static tmem_pamops_no_const tmem_pamops;
37450
37451 void tmem_register_pamops(struct tmem_pamops *m)
37452 {
37453 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37454 index 0d4aa82..f7832d4 100644
37455 --- a/drivers/staging/zcache/tmem.h
37456 +++ b/drivers/staging/zcache/tmem.h
37457 @@ -180,6 +180,7 @@ struct tmem_pamops {
37458 void (*new_obj)(struct tmem_obj *);
37459 int (*replace_in_obj)(void *, struct tmem_obj *);
37460 };
37461 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37462 extern void tmem_register_pamops(struct tmem_pamops *m);
37463
37464 /* memory allocation methods provided by the host implementation */
37465 @@ -189,6 +190,7 @@ struct tmem_hostops {
37466 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37467 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37468 };
37469 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37470 extern void tmem_register_hostops(struct tmem_hostops *m);
37471
37472 /* core tmem accessor functions */
37473 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37474 index c6c385f..b23c65d 100644
37475 --- a/drivers/target/target_core_transport.c
37476 +++ b/drivers/target/target_core_transport.c
37477 @@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37478 spin_lock_init(&dev->se_port_lock);
37479 spin_lock_init(&dev->se_tmr_lock);
37480 spin_lock_init(&dev->qf_cmd_lock);
37481 - atomic_set(&dev->dev_ordered_id, 0);
37482 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37483
37484 se_dev_set_default_attribs(dev, dev_limits);
37485
37486 @@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37487 * Used to determine when ORDERED commands should go from
37488 * Dormant to Active status.
37489 */
37490 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37491 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37492 smp_mb__after_atomic_inc();
37493 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37494 cmd->se_ordered_id, cmd->sam_task_attr,
37495 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37496 index e61cabd..7617d26 100644
37497 --- a/drivers/tty/cyclades.c
37498 +++ b/drivers/tty/cyclades.c
37499 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37500 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37501 info->port.count);
37502 #endif
37503 - info->port.count++;
37504 + atomic_inc(&info->port.count);
37505 #ifdef CY_DEBUG_COUNT
37506 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37507 - current->pid, info->port.count);
37508 + current->pid, atomic_read(&info->port.count));
37509 #endif
37510
37511 /*
37512 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37513 for (j = 0; j < cy_card[i].nports; j++) {
37514 info = &cy_card[i].ports[j];
37515
37516 - if (info->port.count) {
37517 + if (atomic_read(&info->port.count)) {
37518 /* XXX is the ldisc num worth this? */
37519 struct tty_struct *tty;
37520 struct tty_ldisc *ld;
37521 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37522 index 2d691eb..be02ebd 100644
37523 --- a/drivers/tty/hvc/hvc_console.c
37524 +++ b/drivers/tty/hvc/hvc_console.c
37525 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37526
37527 spin_lock_irqsave(&hp->port.lock, flags);
37528 /* Check and then increment for fast path open. */
37529 - if (hp->port.count++ > 0) {
37530 + if (atomic_inc_return(&hp->port.count) > 1) {
37531 spin_unlock_irqrestore(&hp->port.lock, flags);
37532 hvc_kick();
37533 return 0;
37534 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37535
37536 spin_lock_irqsave(&hp->port.lock, flags);
37537
37538 - if (--hp->port.count == 0) {
37539 + if (atomic_dec_return(&hp->port.count) == 0) {
37540 spin_unlock_irqrestore(&hp->port.lock, flags);
37541 /* We are done with the tty pointer now. */
37542 tty_port_tty_set(&hp->port, NULL);
37543 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37544 */
37545 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37546 } else {
37547 - if (hp->port.count < 0)
37548 + if (atomic_read(&hp->port.count) < 0)
37549 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37550 - hp->vtermno, hp->port.count);
37551 + hp->vtermno, atomic_read(&hp->port.count));
37552 spin_unlock_irqrestore(&hp->port.lock, flags);
37553 }
37554
37555 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37556 * open->hangup case this can be called after the final close so prevent
37557 * that from happening for now.
37558 */
37559 - if (hp->port.count <= 0) {
37560 + if (atomic_read(&hp->port.count) <= 0) {
37561 spin_unlock_irqrestore(&hp->port.lock, flags);
37562 return;
37563 }
37564
37565 - temp_open_count = hp->port.count;
37566 - hp->port.count = 0;
37567 + temp_open_count = atomic_read(&hp->port.count);
37568 + atomic_set(&hp->port.count, 0);
37569 spin_unlock_irqrestore(&hp->port.lock, flags);
37570 tty_port_tty_set(&hp->port, NULL);
37571
37572 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37573 return -EPIPE;
37574
37575 /* FIXME what's this (unprotected) check for? */
37576 - if (hp->port.count <= 0)
37577 + if (atomic_read(&hp->port.count) <= 0)
37578 return -EIO;
37579
37580 spin_lock_irqsave(&hp->lock, flags);
37581 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37582 index d56788c..12d8f85 100644
37583 --- a/drivers/tty/hvc/hvcs.c
37584 +++ b/drivers/tty/hvc/hvcs.c
37585 @@ -83,6 +83,7 @@
37586 #include <asm/hvcserver.h>
37587 #include <asm/uaccess.h>
37588 #include <asm/vio.h>
37589 +#include <asm/local.h>
37590
37591 /*
37592 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37593 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37594
37595 spin_lock_irqsave(&hvcsd->lock, flags);
37596
37597 - if (hvcsd->port.count > 0) {
37598 + if (atomic_read(&hvcsd->port.count) > 0) {
37599 spin_unlock_irqrestore(&hvcsd->lock, flags);
37600 printk(KERN_INFO "HVCS: vterm state unchanged. "
37601 "The hvcs device node is still in use.\n");
37602 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37603 if ((retval = hvcs_partner_connect(hvcsd)))
37604 goto error_release;
37605
37606 - hvcsd->port.count = 1;
37607 + atomic_set(&hvcsd->port.count, 1);
37608 hvcsd->port.tty = tty;
37609 tty->driver_data = hvcsd;
37610
37611 @@ -1168,7 +1169,7 @@ fast_open:
37612
37613 spin_lock_irqsave(&hvcsd->lock, flags);
37614 tty_port_get(&hvcsd->port);
37615 - hvcsd->port.count++;
37616 + atomic_inc(&hvcsd->port.count);
37617 hvcsd->todo_mask |= HVCS_SCHED_READ;
37618 spin_unlock_irqrestore(&hvcsd->lock, flags);
37619
37620 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37621 hvcsd = tty->driver_data;
37622
37623 spin_lock_irqsave(&hvcsd->lock, flags);
37624 - if (--hvcsd->port.count == 0) {
37625 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37626
37627 vio_disable_interrupts(hvcsd->vdev);
37628
37629 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37630 free_irq(irq, hvcsd);
37631 tty_port_put(&hvcsd->port);
37632 return;
37633 - } else if (hvcsd->port.count < 0) {
37634 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37635 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37636 " is missmanaged.\n",
37637 - hvcsd->vdev->unit_address, hvcsd->port.count);
37638 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37639 }
37640
37641 spin_unlock_irqrestore(&hvcsd->lock, flags);
37642 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37643
37644 spin_lock_irqsave(&hvcsd->lock, flags);
37645 /* Preserve this so that we know how many kref refs to put */
37646 - temp_open_count = hvcsd->port.count;
37647 + temp_open_count = atomic_read(&hvcsd->port.count);
37648
37649 /*
37650 * Don't kref put inside the spinlock because the destruction
37651 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37652 tty->driver_data = NULL;
37653 hvcsd->port.tty = NULL;
37654
37655 - hvcsd->port.count = 0;
37656 + atomic_set(&hvcsd->port.count, 0);
37657
37658 /* This will drop any buffered data on the floor which is OK in a hangup
37659 * scenario. */
37660 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37661 * the middle of a write operation? This is a crummy place to do this
37662 * but we want to keep it all in the spinlock.
37663 */
37664 - if (hvcsd->port.count <= 0) {
37665 + if (atomic_read(&hvcsd->port.count) <= 0) {
37666 spin_unlock_irqrestore(&hvcsd->lock, flags);
37667 return -ENODEV;
37668 }
37669 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37670 {
37671 struct hvcs_struct *hvcsd = tty->driver_data;
37672
37673 - if (!hvcsd || hvcsd->port.count <= 0)
37674 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37675 return 0;
37676
37677 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37678 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37679 index f8b5fa0..4ba9f89 100644
37680 --- a/drivers/tty/ipwireless/tty.c
37681 +++ b/drivers/tty/ipwireless/tty.c
37682 @@ -29,6 +29,7 @@
37683 #include <linux/tty_driver.h>
37684 #include <linux/tty_flip.h>
37685 #include <linux/uaccess.h>
37686 +#include <asm/local.h>
37687
37688 #include "tty.h"
37689 #include "network.h"
37690 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37691 mutex_unlock(&tty->ipw_tty_mutex);
37692 return -ENODEV;
37693 }
37694 - if (tty->port.count == 0)
37695 + if (atomic_read(&tty->port.count) == 0)
37696 tty->tx_bytes_queued = 0;
37697
37698 - tty->port.count++;
37699 + atomic_inc(&tty->port.count);
37700
37701 tty->port.tty = linux_tty;
37702 linux_tty->driver_data = tty;
37703 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37704
37705 static void do_ipw_close(struct ipw_tty *tty)
37706 {
37707 - tty->port.count--;
37708 -
37709 - if (tty->port.count == 0) {
37710 + if (atomic_dec_return(&tty->port.count) == 0) {
37711 struct tty_struct *linux_tty = tty->port.tty;
37712
37713 if (linux_tty != NULL) {
37714 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37715 return;
37716
37717 mutex_lock(&tty->ipw_tty_mutex);
37718 - if (tty->port.count == 0) {
37719 + if (atomic_read(&tty->port.count) == 0) {
37720 mutex_unlock(&tty->ipw_tty_mutex);
37721 return;
37722 }
37723 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37724 return;
37725 }
37726
37727 - if (!tty->port.count) {
37728 + if (!atomic_read(&tty->port.count)) {
37729 mutex_unlock(&tty->ipw_tty_mutex);
37730 return;
37731 }
37732 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37733 return -ENODEV;
37734
37735 mutex_lock(&tty->ipw_tty_mutex);
37736 - if (!tty->port.count) {
37737 + if (!atomic_read(&tty->port.count)) {
37738 mutex_unlock(&tty->ipw_tty_mutex);
37739 return -EINVAL;
37740 }
37741 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37742 if (!tty)
37743 return -ENODEV;
37744
37745 - if (!tty->port.count)
37746 + if (!atomic_read(&tty->port.count))
37747 return -EINVAL;
37748
37749 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37750 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37751 if (!tty)
37752 return 0;
37753
37754 - if (!tty->port.count)
37755 + if (!atomic_read(&tty->port.count))
37756 return 0;
37757
37758 return tty->tx_bytes_queued;
37759 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37760 if (!tty)
37761 return -ENODEV;
37762
37763 - if (!tty->port.count)
37764 + if (!atomic_read(&tty->port.count))
37765 return -EINVAL;
37766
37767 return get_control_lines(tty);
37768 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37769 if (!tty)
37770 return -ENODEV;
37771
37772 - if (!tty->port.count)
37773 + if (!atomic_read(&tty->port.count))
37774 return -EINVAL;
37775
37776 return set_control_lines(tty, set, clear);
37777 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37778 if (!tty)
37779 return -ENODEV;
37780
37781 - if (!tty->port.count)
37782 + if (!atomic_read(&tty->port.count))
37783 return -EINVAL;
37784
37785 /* FIXME: Exactly how is the tty object locked here .. */
37786 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37787 * are gone */
37788 mutex_lock(&ttyj->ipw_tty_mutex);
37789 }
37790 - while (ttyj->port.count)
37791 + while (atomic_read(&ttyj->port.count))
37792 do_ipw_close(ttyj);
37793 ipwireless_disassociate_network_ttys(network,
37794 ttyj->channel_idx);
37795 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37796 index 324467d..504cc25 100644
37797 --- a/drivers/tty/moxa.c
37798 +++ b/drivers/tty/moxa.c
37799 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37800 }
37801
37802 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37803 - ch->port.count++;
37804 + atomic_inc(&ch->port.count);
37805 tty->driver_data = ch;
37806 tty_port_tty_set(&ch->port, tty);
37807 mutex_lock(&ch->port.mutex);
37808 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37809 index c43b683..4dab83e 100644
37810 --- a/drivers/tty/n_gsm.c
37811 +++ b/drivers/tty/n_gsm.c
37812 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37813 kref_init(&dlci->ref);
37814 mutex_init(&dlci->mutex);
37815 dlci->fifo = &dlci->_fifo;
37816 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37817 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37818 kfree(dlci);
37819 return NULL;
37820 }
37821 @@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37822 if (dlci == NULL)
37823 return -ENOMEM;
37824 port = &dlci->port;
37825 - port->count++;
37826 + atomic_inc(&port->count);
37827 tty->driver_data = dlci;
37828 dlci_get(dlci);
37829 dlci_get(dlci->gsm->dlci[0]);
37830 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37831 index ee1c268..0e97caf 100644
37832 --- a/drivers/tty/n_tty.c
37833 +++ b/drivers/tty/n_tty.c
37834 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37835 {
37836 *ops = tty_ldisc_N_TTY;
37837 ops->owner = NULL;
37838 - ops->refcount = ops->flags = 0;
37839 + atomic_set(&ops->refcount, 0);
37840 + ops->flags = 0;
37841 }
37842 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37843 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37844 index 5505ffc..7affff9 100644
37845 --- a/drivers/tty/pty.c
37846 +++ b/drivers/tty/pty.c
37847 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37848 panic("Couldn't register Unix98 pts driver");
37849
37850 /* Now create the /dev/ptmx special device */
37851 + pax_open_kernel();
37852 tty_default_fops(&ptmx_fops);
37853 - ptmx_fops.open = ptmx_open;
37854 + *(void **)&ptmx_fops.open = ptmx_open;
37855 + pax_close_kernel();
37856
37857 cdev_init(&ptmx_cdev, &ptmx_fops);
37858 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37859 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37860 index 777d5f9..56d67ca 100644
37861 --- a/drivers/tty/rocket.c
37862 +++ b/drivers/tty/rocket.c
37863 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37864 tty->driver_data = info;
37865 tty_port_tty_set(port, tty);
37866
37867 - if (port->count++ == 0) {
37868 + if (atomic_inc_return(&port->count) == 1) {
37869 atomic_inc(&rp_num_ports_open);
37870
37871 #ifdef ROCKET_DEBUG_OPEN
37872 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37873 #endif
37874 }
37875 #ifdef ROCKET_DEBUG_OPEN
37876 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37877 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37878 #endif
37879
37880 /*
37881 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37882 spin_unlock_irqrestore(&info->port.lock, flags);
37883 return;
37884 }
37885 - if (info->port.count)
37886 + if (atomic_read(&info->port.count))
37887 atomic_dec(&rp_num_ports_open);
37888 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37889 spin_unlock_irqrestore(&info->port.lock, flags);
37890 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37891 index 2b42a01..32a2ed3 100644
37892 --- a/drivers/tty/serial/kgdboc.c
37893 +++ b/drivers/tty/serial/kgdboc.c
37894 @@ -24,8 +24,9 @@
37895 #define MAX_CONFIG_LEN 40
37896
37897 static struct kgdb_io kgdboc_io_ops;
37898 +static struct kgdb_io kgdboc_io_ops_console;
37899
37900 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37901 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37902 static int configured = -1;
37903
37904 static char config[MAX_CONFIG_LEN];
37905 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37906 kgdboc_unregister_kbd();
37907 if (configured == 1)
37908 kgdb_unregister_io_module(&kgdboc_io_ops);
37909 + else if (configured == 2)
37910 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37911 }
37912
37913 static int configure_kgdboc(void)
37914 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37915 int err;
37916 char *cptr = config;
37917 struct console *cons;
37918 + int is_console = 0;
37919
37920 err = kgdboc_option_setup(config);
37921 if (err || !strlen(config) || isspace(config[0]))
37922 goto noconfig;
37923
37924 err = -ENODEV;
37925 - kgdboc_io_ops.is_console = 0;
37926 kgdb_tty_driver = NULL;
37927
37928 kgdboc_use_kms = 0;
37929 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37930 int idx;
37931 if (cons->device && cons->device(cons, &idx) == p &&
37932 idx == tty_line) {
37933 - kgdboc_io_ops.is_console = 1;
37934 + is_console = 1;
37935 break;
37936 }
37937 cons = cons->next;
37938 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37939 kgdb_tty_line = tty_line;
37940
37941 do_register:
37942 - err = kgdb_register_io_module(&kgdboc_io_ops);
37943 + if (is_console) {
37944 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37945 + configured = 2;
37946 + } else {
37947 + err = kgdb_register_io_module(&kgdboc_io_ops);
37948 + configured = 1;
37949 + }
37950 if (err)
37951 goto noconfig;
37952
37953 - configured = 1;
37954 -
37955 return 0;
37956
37957 noconfig:
37958 @@ -213,7 +220,7 @@ noconfig:
37959 static int __init init_kgdboc(void)
37960 {
37961 /* Already configured? */
37962 - if (configured == 1)
37963 + if (configured >= 1)
37964 return 0;
37965
37966 return configure_kgdboc();
37967 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37968 if (config[len - 1] == '\n')
37969 config[len - 1] = '\0';
37970
37971 - if (configured == 1)
37972 + if (configured >= 1)
37973 cleanup_kgdboc();
37974
37975 /* Go and configure with the new params. */
37976 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37977 .post_exception = kgdboc_post_exp_handler,
37978 };
37979
37980 +static struct kgdb_io kgdboc_io_ops_console = {
37981 + .name = "kgdboc",
37982 + .read_char = kgdboc_get_char,
37983 + .write_char = kgdboc_put_char,
37984 + .pre_exception = kgdboc_pre_exp_handler,
37985 + .post_exception = kgdboc_post_exp_handler,
37986 + .is_console = 1
37987 +};
37988 +
37989 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37990 /* This is only available if kgdboc is a built in for early debugging */
37991 static int __init kgdboc_early_init(char *opt)
37992 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37993 index 246b823..9e0db76 100644
37994 --- a/drivers/tty/serial/serial_core.c
37995 +++ b/drivers/tty/serial/serial_core.c
37996 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37997 uart_flush_buffer(tty);
37998 uart_shutdown(tty, state);
37999 spin_lock_irqsave(&port->lock, flags);
38000 - port->count = 0;
38001 + atomic_set(&port->count, 0);
38002 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38003 spin_unlock_irqrestore(&port->lock, flags);
38004 tty_port_tty_set(port, NULL);
38005 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38006 goto end;
38007 }
38008
38009 - port->count++;
38010 + atomic_inc(&port->count);
38011 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38012 retval = -ENXIO;
38013 goto err_dec_count;
38014 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38015 /*
38016 * Make sure the device is in D0 state.
38017 */
38018 - if (port->count == 1)
38019 + if (atomic_read(&port->count) == 1)
38020 uart_change_pm(state, 0);
38021
38022 /*
38023 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38024 end:
38025 return retval;
38026 err_dec_count:
38027 - port->count--;
38028 + atomic_inc(&port->count);
38029 mutex_unlock(&port->mutex);
38030 goto end;
38031 }
38032 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38033 index 593d40a..bdc61f3 100644
38034 --- a/drivers/tty/synclink.c
38035 +++ b/drivers/tty/synclink.c
38036 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38037
38038 if (debug_level >= DEBUG_LEVEL_INFO)
38039 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38040 - __FILE__,__LINE__, info->device_name, info->port.count);
38041 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38042
38043 if (tty_port_close_start(&info->port, tty, filp) == 0)
38044 goto cleanup;
38045 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38046 cleanup:
38047 if (debug_level >= DEBUG_LEVEL_INFO)
38048 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38049 - tty->driver->name, info->port.count);
38050 + tty->driver->name, atomic_read(&info->port.count));
38051
38052 } /* end of mgsl_close() */
38053
38054 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38055
38056 mgsl_flush_buffer(tty);
38057 shutdown(info);
38058 -
38059 - info->port.count = 0;
38060 +
38061 + atomic_set(&info->port.count, 0);
38062 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38063 info->port.tty = NULL;
38064
38065 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38066
38067 if (debug_level >= DEBUG_LEVEL_INFO)
38068 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38069 - __FILE__,__LINE__, tty->driver->name, port->count );
38070 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38071
38072 spin_lock_irqsave(&info->irq_spinlock, flags);
38073 if (!tty_hung_up_p(filp)) {
38074 extra_count = true;
38075 - port->count--;
38076 + atomic_dec(&port->count);
38077 }
38078 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38079 port->blocked_open++;
38080 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38081
38082 if (debug_level >= DEBUG_LEVEL_INFO)
38083 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38084 - __FILE__,__LINE__, tty->driver->name, port->count );
38085 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38086
38087 tty_unlock();
38088 schedule();
38089 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38090
38091 /* FIXME: Racy on hangup during close wait */
38092 if (extra_count)
38093 - port->count++;
38094 + atomic_inc(&port->count);
38095 port->blocked_open--;
38096
38097 if (debug_level >= DEBUG_LEVEL_INFO)
38098 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38099 - __FILE__,__LINE__, tty->driver->name, port->count );
38100 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38101
38102 if (!retval)
38103 port->flags |= ASYNC_NORMAL_ACTIVE;
38104 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38105
38106 if (debug_level >= DEBUG_LEVEL_INFO)
38107 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38108 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38109 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38110
38111 /* If port is closing, signal caller to try again */
38112 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38113 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38114 spin_unlock_irqrestore(&info->netlock, flags);
38115 goto cleanup;
38116 }
38117 - info->port.count++;
38118 + atomic_inc(&info->port.count);
38119 spin_unlock_irqrestore(&info->netlock, flags);
38120
38121 - if (info->port.count == 1) {
38122 + if (atomic_read(&info->port.count) == 1) {
38123 /* 1st open on this device, init hardware */
38124 retval = startup(info);
38125 if (retval < 0)
38126 @@ -3444,8 +3444,8 @@ cleanup:
38127 if (retval) {
38128 if (tty->count == 1)
38129 info->port.tty = NULL; /* tty layer will release tty struct */
38130 - if(info->port.count)
38131 - info->port.count--;
38132 + if (atomic_read(&info->port.count))
38133 + atomic_dec(&info->port.count);
38134 }
38135
38136 return retval;
38137 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38138 unsigned short new_crctype;
38139
38140 /* return error if TTY interface open */
38141 - if (info->port.count)
38142 + if (atomic_read(&info->port.count))
38143 return -EBUSY;
38144
38145 switch (encoding)
38146 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38147
38148 /* arbitrate between network and tty opens */
38149 spin_lock_irqsave(&info->netlock, flags);
38150 - if (info->port.count != 0 || info->netcount != 0) {
38151 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38152 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38153 spin_unlock_irqrestore(&info->netlock, flags);
38154 return -EBUSY;
38155 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38156 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38157
38158 /* return error if TTY interface open */
38159 - if (info->port.count)
38160 + if (atomic_read(&info->port.count))
38161 return -EBUSY;
38162
38163 if (cmd != SIOCWANDEV)
38164 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38165 index aa1debf..9297a16 100644
38166 --- a/drivers/tty/synclink_gt.c
38167 +++ b/drivers/tty/synclink_gt.c
38168 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38169 tty->driver_data = info;
38170 info->port.tty = tty;
38171
38172 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38173 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38174
38175 /* If port is closing, signal caller to try again */
38176 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38177 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38178 mutex_unlock(&info->port.mutex);
38179 goto cleanup;
38180 }
38181 - info->port.count++;
38182 + atomic_inc(&info->port.count);
38183 spin_unlock_irqrestore(&info->netlock, flags);
38184
38185 - if (info->port.count == 1) {
38186 + if (atomic_read(&info->port.count) == 1) {
38187 /* 1st open on this device, init hardware */
38188 retval = startup(info);
38189 if (retval < 0) {
38190 @@ -716,8 +716,8 @@ cleanup:
38191 if (retval) {
38192 if (tty->count == 1)
38193 info->port.tty = NULL; /* tty layer will release tty struct */
38194 - if(info->port.count)
38195 - info->port.count--;
38196 + if(atomic_read(&info->port.count))
38197 + atomic_dec(&info->port.count);
38198 }
38199
38200 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38201 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38202
38203 if (sanity_check(info, tty->name, "close"))
38204 return;
38205 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38206 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38207
38208 if (tty_port_close_start(&info->port, tty, filp) == 0)
38209 goto cleanup;
38210 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38211 tty_port_close_end(&info->port, tty);
38212 info->port.tty = NULL;
38213 cleanup:
38214 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38215 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38216 }
38217
38218 static void hangup(struct tty_struct *tty)
38219 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38220 shutdown(info);
38221
38222 spin_lock_irqsave(&info->port.lock, flags);
38223 - info->port.count = 0;
38224 + atomic_set(&info->port.count, 0);
38225 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38226 info->port.tty = NULL;
38227 spin_unlock_irqrestore(&info->port.lock, flags);
38228 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38229 unsigned short new_crctype;
38230
38231 /* return error if TTY interface open */
38232 - if (info->port.count)
38233 + if (atomic_read(&info->port.count))
38234 return -EBUSY;
38235
38236 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38237 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38238
38239 /* arbitrate between network and tty opens */
38240 spin_lock_irqsave(&info->netlock, flags);
38241 - if (info->port.count != 0 || info->netcount != 0) {
38242 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38243 DBGINFO(("%s hdlc_open busy\n", dev->name));
38244 spin_unlock_irqrestore(&info->netlock, flags);
38245 return -EBUSY;
38246 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38247 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38248
38249 /* return error if TTY interface open */
38250 - if (info->port.count)
38251 + if (atomic_read(&info->port.count))
38252 return -EBUSY;
38253
38254 if (cmd != SIOCWANDEV)
38255 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38256 if (port == NULL)
38257 continue;
38258 spin_lock(&port->lock);
38259 - if ((port->port.count || port->netcount) &&
38260 + if ((atomic_read(&port->port.count) || port->netcount) &&
38261 port->pending_bh && !port->bh_running &&
38262 !port->bh_requested) {
38263 DBGISR(("%s bh queued\n", port->device_name));
38264 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38265 spin_lock_irqsave(&info->lock, flags);
38266 if (!tty_hung_up_p(filp)) {
38267 extra_count = true;
38268 - port->count--;
38269 + atomic_dec(&port->count);
38270 }
38271 spin_unlock_irqrestore(&info->lock, flags);
38272 port->blocked_open++;
38273 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38274 remove_wait_queue(&port->open_wait, &wait);
38275
38276 if (extra_count)
38277 - port->count++;
38278 + atomic_inc(&port->count);
38279 port->blocked_open--;
38280
38281 if (!retval)
38282 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38283 index a3dddc1..8905ab2 100644
38284 --- a/drivers/tty/synclinkmp.c
38285 +++ b/drivers/tty/synclinkmp.c
38286 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38287
38288 if (debug_level >= DEBUG_LEVEL_INFO)
38289 printk("%s(%d):%s open(), old ref count = %d\n",
38290 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38291 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38292
38293 /* If port is closing, signal caller to try again */
38294 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38295 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38296 spin_unlock_irqrestore(&info->netlock, flags);
38297 goto cleanup;
38298 }
38299 - info->port.count++;
38300 + atomic_inc(&info->port.count);
38301 spin_unlock_irqrestore(&info->netlock, flags);
38302
38303 - if (info->port.count == 1) {
38304 + if (atomic_read(&info->port.count) == 1) {
38305 /* 1st open on this device, init hardware */
38306 retval = startup(info);
38307 if (retval < 0)
38308 @@ -788,8 +788,8 @@ cleanup:
38309 if (retval) {
38310 if (tty->count == 1)
38311 info->port.tty = NULL; /* tty layer will release tty struct */
38312 - if(info->port.count)
38313 - info->port.count--;
38314 + if(atomic_read(&info->port.count))
38315 + atomic_dec(&info->port.count);
38316 }
38317
38318 return retval;
38319 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38320
38321 if (debug_level >= DEBUG_LEVEL_INFO)
38322 printk("%s(%d):%s close() entry, count=%d\n",
38323 - __FILE__,__LINE__, info->device_name, info->port.count);
38324 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38325
38326 if (tty_port_close_start(&info->port, tty, filp) == 0)
38327 goto cleanup;
38328 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38329 cleanup:
38330 if (debug_level >= DEBUG_LEVEL_INFO)
38331 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38332 - tty->driver->name, info->port.count);
38333 + tty->driver->name, atomic_read(&info->port.count));
38334 }
38335
38336 /* Called by tty_hangup() when a hangup is signaled.
38337 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38338 shutdown(info);
38339
38340 spin_lock_irqsave(&info->port.lock, flags);
38341 - info->port.count = 0;
38342 + atomic_set(&info->port.count, 0);
38343 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38344 info->port.tty = NULL;
38345 spin_unlock_irqrestore(&info->port.lock, flags);
38346 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38347 unsigned short new_crctype;
38348
38349 /* return error if TTY interface open */
38350 - if (info->port.count)
38351 + if (atomic_read(&info->port.count))
38352 return -EBUSY;
38353
38354 switch (encoding)
38355 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38356
38357 /* arbitrate between network and tty opens */
38358 spin_lock_irqsave(&info->netlock, flags);
38359 - if (info->port.count != 0 || info->netcount != 0) {
38360 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38361 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38362 spin_unlock_irqrestore(&info->netlock, flags);
38363 return -EBUSY;
38364 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38365 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38366
38367 /* return error if TTY interface open */
38368 - if (info->port.count)
38369 + if (atomic_read(&info->port.count))
38370 return -EBUSY;
38371
38372 if (cmd != SIOCWANDEV)
38373 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38374 * do not request bottom half processing if the
38375 * device is not open in a normal mode.
38376 */
38377 - if ( port && (port->port.count || port->netcount) &&
38378 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38379 port->pending_bh && !port->bh_running &&
38380 !port->bh_requested ) {
38381 if ( debug_level >= DEBUG_LEVEL_ISR )
38382 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38383
38384 if (debug_level >= DEBUG_LEVEL_INFO)
38385 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38386 - __FILE__,__LINE__, tty->driver->name, port->count );
38387 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38388
38389 spin_lock_irqsave(&info->lock, flags);
38390 if (!tty_hung_up_p(filp)) {
38391 extra_count = true;
38392 - port->count--;
38393 + atomic_dec(&port->count);
38394 }
38395 spin_unlock_irqrestore(&info->lock, flags);
38396 port->blocked_open++;
38397 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38398
38399 if (debug_level >= DEBUG_LEVEL_INFO)
38400 printk("%s(%d):%s block_til_ready() count=%d\n",
38401 - __FILE__,__LINE__, tty->driver->name, port->count );
38402 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38403
38404 tty_unlock();
38405 schedule();
38406 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38407 remove_wait_queue(&port->open_wait, &wait);
38408
38409 if (extra_count)
38410 - port->count++;
38411 + atomic_inc(&port->count);
38412 port->blocked_open--;
38413
38414 if (debug_level >= DEBUG_LEVEL_INFO)
38415 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38416 - __FILE__,__LINE__, tty->driver->name, port->count );
38417 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38418
38419 if (!retval)
38420 port->flags |= ASYNC_NORMAL_ACTIVE;
38421 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38422 index 05728894..b9d44c6 100644
38423 --- a/drivers/tty/sysrq.c
38424 +++ b/drivers/tty/sysrq.c
38425 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38426 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38427 size_t count, loff_t *ppos)
38428 {
38429 - if (count) {
38430 + if (count && capable(CAP_SYS_ADMIN)) {
38431 char c;
38432
38433 if (get_user(c, buf))
38434 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38435 index b425c79..08a3f06 100644
38436 --- a/drivers/tty/tty_io.c
38437 +++ b/drivers/tty/tty_io.c
38438 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38439
38440 void tty_default_fops(struct file_operations *fops)
38441 {
38442 - *fops = tty_fops;
38443 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38444 }
38445
38446 /*
38447 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38448 index 9911eb6..5abe0e1 100644
38449 --- a/drivers/tty/tty_ldisc.c
38450 +++ b/drivers/tty/tty_ldisc.c
38451 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38452 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38453 struct tty_ldisc_ops *ldo = ld->ops;
38454
38455 - ldo->refcount--;
38456 + atomic_dec(&ldo->refcount);
38457 module_put(ldo->owner);
38458 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38459
38460 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38461 spin_lock_irqsave(&tty_ldisc_lock, flags);
38462 tty_ldiscs[disc] = new_ldisc;
38463 new_ldisc->num = disc;
38464 - new_ldisc->refcount = 0;
38465 + atomic_set(&new_ldisc->refcount, 0);
38466 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38467
38468 return ret;
38469 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38470 return -EINVAL;
38471
38472 spin_lock_irqsave(&tty_ldisc_lock, flags);
38473 - if (tty_ldiscs[disc]->refcount)
38474 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38475 ret = -EBUSY;
38476 else
38477 tty_ldiscs[disc] = NULL;
38478 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38479 if (ldops) {
38480 ret = ERR_PTR(-EAGAIN);
38481 if (try_module_get(ldops->owner)) {
38482 - ldops->refcount++;
38483 + atomic_inc(&ldops->refcount);
38484 ret = ldops;
38485 }
38486 }
38487 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38488 unsigned long flags;
38489
38490 spin_lock_irqsave(&tty_ldisc_lock, flags);
38491 - ldops->refcount--;
38492 + atomic_dec(&ldops->refcount);
38493 module_put(ldops->owner);
38494 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38495 }
38496 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38497 index bf6e238..d401c04 100644
38498 --- a/drivers/tty/tty_port.c
38499 +++ b/drivers/tty/tty_port.c
38500 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38501 unsigned long flags;
38502
38503 spin_lock_irqsave(&port->lock, flags);
38504 - port->count = 0;
38505 + atomic_set(&port->count, 0);
38506 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38507 if (port->tty) {
38508 set_bit(TTY_IO_ERROR, &port->tty->flags);
38509 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38510 /* The port lock protects the port counts */
38511 spin_lock_irqsave(&port->lock, flags);
38512 if (!tty_hung_up_p(filp))
38513 - port->count--;
38514 + atomic_dec(&port->count);
38515 port->blocked_open++;
38516 spin_unlock_irqrestore(&port->lock, flags);
38517
38518 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38519 we must not mess that up further */
38520 spin_lock_irqsave(&port->lock, flags);
38521 if (!tty_hung_up_p(filp))
38522 - port->count++;
38523 + atomic_inc(&port->count);
38524 port->blocked_open--;
38525 if (retval == 0)
38526 port->flags |= ASYNC_NORMAL_ACTIVE;
38527 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38528 return 0;
38529 }
38530
38531 - if (tty->count == 1 && port->count != 1) {
38532 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38533 printk(KERN_WARNING
38534 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38535 - port->count);
38536 - port->count = 1;
38537 + atomic_read(&port->count));
38538 + atomic_set(&port->count, 1);
38539 }
38540 - if (--port->count < 0) {
38541 + if (atomic_dec_return(&port->count) < 0) {
38542 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38543 - port->count);
38544 - port->count = 0;
38545 + atomic_read(&port->count));
38546 + atomic_set(&port->count, 0);
38547 }
38548
38549 - if (port->count) {
38550 + if (atomic_read(&port->count)) {
38551 spin_unlock_irqrestore(&port->lock, flags);
38552 if (port->ops->drop)
38553 port->ops->drop(port);
38554 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38555 {
38556 spin_lock_irq(&port->lock);
38557 if (!tty_hung_up_p(filp))
38558 - ++port->count;
38559 + atomic_inc(&port->count);
38560 spin_unlock_irq(&port->lock);
38561 tty_port_tty_set(port, tty);
38562
38563 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38564 index 48cc6f2..85584dd 100644
38565 --- a/drivers/tty/vt/keyboard.c
38566 +++ b/drivers/tty/vt/keyboard.c
38567 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38568 kbd->kbdmode == VC_OFF) &&
38569 value != KVAL(K_SAK))
38570 return; /* SAK is allowed even in raw mode */
38571 +
38572 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38573 + {
38574 + void *func = fn_handler[value];
38575 + if (func == fn_show_state || func == fn_show_ptregs ||
38576 + func == fn_show_mem)
38577 + return;
38578 + }
38579 +#endif
38580 +
38581 fn_handler[value](vc);
38582 }
38583
38584 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38585 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38586 return -EFAULT;
38587
38588 - if (!capable(CAP_SYS_TTY_CONFIG))
38589 - perm = 0;
38590 -
38591 switch (cmd) {
38592 case KDGKBENT:
38593 /* Ensure another thread doesn't free it under us */
38594 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38595 spin_unlock_irqrestore(&kbd_event_lock, flags);
38596 return put_user(val, &user_kbe->kb_value);
38597 case KDSKBENT:
38598 + if (!capable(CAP_SYS_TTY_CONFIG))
38599 + perm = 0;
38600 +
38601 if (!perm)
38602 return -EPERM;
38603 if (!i && v == K_NOSUCHMAP) {
38604 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38605 int i, j, k;
38606 int ret;
38607
38608 - if (!capable(CAP_SYS_TTY_CONFIG))
38609 - perm = 0;
38610 -
38611 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38612 if (!kbs) {
38613 ret = -ENOMEM;
38614 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38615 kfree(kbs);
38616 return ((p && *p) ? -EOVERFLOW : 0);
38617 case KDSKBSENT:
38618 + if (!capable(CAP_SYS_TTY_CONFIG))
38619 + perm = 0;
38620 +
38621 if (!perm) {
38622 ret = -EPERM;
38623 goto reterr;
38624 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38625 index a783d53..cb30d94 100644
38626 --- a/drivers/uio/uio.c
38627 +++ b/drivers/uio/uio.c
38628 @@ -25,6 +25,7 @@
38629 #include <linux/kobject.h>
38630 #include <linux/cdev.h>
38631 #include <linux/uio_driver.h>
38632 +#include <asm/local.h>
38633
38634 #define UIO_MAX_DEVICES (1U << MINORBITS)
38635
38636 @@ -32,10 +33,10 @@ struct uio_device {
38637 struct module *owner;
38638 struct device *dev;
38639 int minor;
38640 - atomic_t event;
38641 + atomic_unchecked_t event;
38642 struct fasync_struct *async_queue;
38643 wait_queue_head_t wait;
38644 - int vma_count;
38645 + local_t vma_count;
38646 struct uio_info *info;
38647 struct kobject *map_dir;
38648 struct kobject *portio_dir;
38649 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38650 struct device_attribute *attr, char *buf)
38651 {
38652 struct uio_device *idev = dev_get_drvdata(dev);
38653 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38654 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38655 }
38656
38657 static struct device_attribute uio_class_attributes[] = {
38658 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38659 {
38660 struct uio_device *idev = info->uio_dev;
38661
38662 - atomic_inc(&idev->event);
38663 + atomic_inc_unchecked(&idev->event);
38664 wake_up_interruptible(&idev->wait);
38665 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38666 }
38667 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38668 }
38669
38670 listener->dev = idev;
38671 - listener->event_count = atomic_read(&idev->event);
38672 + listener->event_count = atomic_read_unchecked(&idev->event);
38673 filep->private_data = listener;
38674
38675 if (idev->info->open) {
38676 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38677 return -EIO;
38678
38679 poll_wait(filep, &idev->wait, wait);
38680 - if (listener->event_count != atomic_read(&idev->event))
38681 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38682 return POLLIN | POLLRDNORM;
38683 return 0;
38684 }
38685 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38686 do {
38687 set_current_state(TASK_INTERRUPTIBLE);
38688
38689 - event_count = atomic_read(&idev->event);
38690 + event_count = atomic_read_unchecked(&idev->event);
38691 if (event_count != listener->event_count) {
38692 if (copy_to_user(buf, &event_count, count))
38693 retval = -EFAULT;
38694 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38695 static void uio_vma_open(struct vm_area_struct *vma)
38696 {
38697 struct uio_device *idev = vma->vm_private_data;
38698 - idev->vma_count++;
38699 + local_inc(&idev->vma_count);
38700 }
38701
38702 static void uio_vma_close(struct vm_area_struct *vma)
38703 {
38704 struct uio_device *idev = vma->vm_private_data;
38705 - idev->vma_count--;
38706 + local_dec(&idev->vma_count);
38707 }
38708
38709 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38710 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38711 idev->owner = owner;
38712 idev->info = info;
38713 init_waitqueue_head(&idev->wait);
38714 - atomic_set(&idev->event, 0);
38715 + atomic_set_unchecked(&idev->event, 0);
38716
38717 ret = uio_get_minor(idev);
38718 if (ret)
38719 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38720 index b7eb86a..36d28af 100644
38721 --- a/drivers/usb/atm/cxacru.c
38722 +++ b/drivers/usb/atm/cxacru.c
38723 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38724 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38725 if (ret < 2)
38726 return -EINVAL;
38727 - if (index < 0 || index > 0x7f)
38728 + if (index > 0x7f)
38729 return -EINVAL;
38730 pos += tmp;
38731
38732 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38733 index ee62b35..b663594 100644
38734 --- a/drivers/usb/atm/usbatm.c
38735 +++ b/drivers/usb/atm/usbatm.c
38736 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38737 if (printk_ratelimit())
38738 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38739 __func__, vpi, vci);
38740 - atomic_inc(&vcc->stats->rx_err);
38741 + atomic_inc_unchecked(&vcc->stats->rx_err);
38742 return;
38743 }
38744
38745 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38746 if (length > ATM_MAX_AAL5_PDU) {
38747 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38748 __func__, length, vcc);
38749 - atomic_inc(&vcc->stats->rx_err);
38750 + atomic_inc_unchecked(&vcc->stats->rx_err);
38751 goto out;
38752 }
38753
38754 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38755 if (sarb->len < pdu_length) {
38756 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38757 __func__, pdu_length, sarb->len, vcc);
38758 - atomic_inc(&vcc->stats->rx_err);
38759 + atomic_inc_unchecked(&vcc->stats->rx_err);
38760 goto out;
38761 }
38762
38763 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38764 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38765 __func__, vcc);
38766 - atomic_inc(&vcc->stats->rx_err);
38767 + atomic_inc_unchecked(&vcc->stats->rx_err);
38768 goto out;
38769 }
38770
38771 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38772 if (printk_ratelimit())
38773 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38774 __func__, length);
38775 - atomic_inc(&vcc->stats->rx_drop);
38776 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38777 goto out;
38778 }
38779
38780 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38781
38782 vcc->push(vcc, skb);
38783
38784 - atomic_inc(&vcc->stats->rx);
38785 + atomic_inc_unchecked(&vcc->stats->rx);
38786 out:
38787 skb_trim(sarb, 0);
38788 }
38789 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38790 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38791
38792 usbatm_pop(vcc, skb);
38793 - atomic_inc(&vcc->stats->tx);
38794 + atomic_inc_unchecked(&vcc->stats->tx);
38795
38796 skb = skb_dequeue(&instance->sndqueue);
38797 }
38798 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38799 if (!left--)
38800 return sprintf(page,
38801 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38802 - atomic_read(&atm_dev->stats.aal5.tx),
38803 - atomic_read(&atm_dev->stats.aal5.tx_err),
38804 - atomic_read(&atm_dev->stats.aal5.rx),
38805 - atomic_read(&atm_dev->stats.aal5.rx_err),
38806 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38807 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38808 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38809 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38810 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38811 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38812
38813 if (!left--) {
38814 if (instance->disconnected)
38815 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38816 index d956965..4179a77 100644
38817 --- a/drivers/usb/core/devices.c
38818 +++ b/drivers/usb/core/devices.c
38819 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38820 * time it gets called.
38821 */
38822 static struct device_connect_event {
38823 - atomic_t count;
38824 + atomic_unchecked_t count;
38825 wait_queue_head_t wait;
38826 } device_event = {
38827 .count = ATOMIC_INIT(1),
38828 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38829
38830 void usbfs_conn_disc_event(void)
38831 {
38832 - atomic_add(2, &device_event.count);
38833 + atomic_add_unchecked(2, &device_event.count);
38834 wake_up(&device_event.wait);
38835 }
38836
38837 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38838
38839 poll_wait(file, &device_event.wait, wait);
38840
38841 - event_count = atomic_read(&device_event.count);
38842 + event_count = atomic_read_unchecked(&device_event.count);
38843 if (file->f_version != event_count) {
38844 file->f_version = event_count;
38845 return POLLIN | POLLRDNORM;
38846 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38847 index 347bb05..63e1b73 100644
38848 --- a/drivers/usb/early/ehci-dbgp.c
38849 +++ b/drivers/usb/early/ehci-dbgp.c
38850 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38851
38852 #ifdef CONFIG_KGDB
38853 static struct kgdb_io kgdbdbgp_io_ops;
38854 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38855 +static struct kgdb_io kgdbdbgp_io_ops_console;
38856 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38857 #else
38858 #define dbgp_kgdb_mode (0)
38859 #endif
38860 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38861 .write_char = kgdbdbgp_write_char,
38862 };
38863
38864 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38865 + .name = "kgdbdbgp",
38866 + .read_char = kgdbdbgp_read_char,
38867 + .write_char = kgdbdbgp_write_char,
38868 + .is_console = 1
38869 +};
38870 +
38871 static int kgdbdbgp_wait_time;
38872
38873 static int __init kgdbdbgp_parse_config(char *str)
38874 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38875 ptr++;
38876 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38877 }
38878 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38879 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38880 + if (early_dbgp_console.index != -1)
38881 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38882 + else
38883 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38884
38885 return 0;
38886 }
38887 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38888 index 5b3f5ff..6e00893 100644
38889 --- a/drivers/usb/gadget/u_serial.c
38890 +++ b/drivers/usb/gadget/u_serial.c
38891 @@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38892 spin_lock_irq(&port->port_lock);
38893
38894 /* already open? Great. */
38895 - if (port->port.count) {
38896 + if (atomic_read(&port->port.count)) {
38897 status = 0;
38898 - port->port.count++;
38899 + atomic_inc(&port->port.count);
38900
38901 /* currently opening/closing? wait ... */
38902 } else if (port->openclose) {
38903 @@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38904 tty->driver_data = port;
38905 port->port.tty = tty;
38906
38907 - port->port.count = 1;
38908 + atomic_set(&port->port.count, 1);
38909 port->openclose = false;
38910
38911 /* if connected, start the I/O stream */
38912 @@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38913
38914 spin_lock_irq(&port->port_lock);
38915
38916 - if (port->port.count != 1) {
38917 - if (port->port.count == 0)
38918 + if (atomic_read(&port->port.count) != 1) {
38919 + if (atomic_read(&port->port.count) == 0)
38920 WARN_ON(1);
38921 else
38922 - --port->port.count;
38923 + atomic_dec(&port->port.count);
38924 goto exit;
38925 }
38926
38927 @@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38928 * and sleep if necessary
38929 */
38930 port->openclose = true;
38931 - port->port.count = 0;
38932 + atomic_set(&port->port.count, 0);
38933
38934 gser = port->port_usb;
38935 if (gser && gser->disconnect)
38936 @@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38937 int cond;
38938
38939 spin_lock_irq(&port->port_lock);
38940 - cond = (port->port.count == 0) && !port->openclose;
38941 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38942 spin_unlock_irq(&port->port_lock);
38943 return cond;
38944 }
38945 @@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38946 /* if it's already open, start I/O ... and notify the serial
38947 * protocol about open/close status (connect/disconnect).
38948 */
38949 - if (port->port.count) {
38950 + if (atomic_read(&port->port.count)) {
38951 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38952 gs_start_io(port);
38953 if (gser->connect)
38954 @@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38955
38956 port->port_usb = NULL;
38957 gser->ioport = NULL;
38958 - if (port->port.count > 0 || port->openclose) {
38959 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
38960 wake_up_interruptible(&port->drain_wait);
38961 if (port->port.tty)
38962 tty_hangup(port->port.tty);
38963 @@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38964
38965 /* finally, free any unused/unusable I/O buffers */
38966 spin_lock_irqsave(&port->port_lock, flags);
38967 - if (port->port.count == 0 && !port->openclose)
38968 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
38969 gs_buf_free(&port->port_write_buf);
38970 gs_free_requests(gser->out, &port->read_pool, NULL);
38971 gs_free_requests(gser->out, &port->read_queue, NULL);
38972 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38973 index b9cca6d..75c75df 100644
38974 --- a/drivers/usb/serial/console.c
38975 +++ b/drivers/usb/serial/console.c
38976 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38977
38978 info->port = port;
38979
38980 - ++port->port.count;
38981 + atomic_inc(&port->port.count);
38982 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38983 if (serial->type->set_termios) {
38984 /*
38985 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38986 }
38987 /* Now that any required fake tty operations are completed restore
38988 * the tty port count */
38989 - --port->port.count;
38990 + atomic_dec(&port->port.count);
38991 /* The console is special in terms of closing the device so
38992 * indicate this port is now acting as a system console. */
38993 port->port.console = 1;
38994 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38995 free_tty:
38996 kfree(tty);
38997 reset_open_count:
38998 - port->port.count = 0;
38999 + atomic_set(&port->port.count, 0);
39000 usb_autopm_put_interface(serial->interface);
39001 error_get_interface:
39002 usb_serial_put(serial);
39003 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39004 index d6bea3e..60b250e 100644
39005 --- a/drivers/usb/wusbcore/wa-hc.h
39006 +++ b/drivers/usb/wusbcore/wa-hc.h
39007 @@ -192,7 +192,7 @@ struct wahc {
39008 struct list_head xfer_delayed_list;
39009 spinlock_t xfer_list_lock;
39010 struct work_struct xfer_work;
39011 - atomic_t xfer_id_count;
39012 + atomic_unchecked_t xfer_id_count;
39013 };
39014
39015
39016 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39017 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39018 spin_lock_init(&wa->xfer_list_lock);
39019 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39020 - atomic_set(&wa->xfer_id_count, 1);
39021 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39022 }
39023
39024 /**
39025 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39026 index 57c01ab..8a05959 100644
39027 --- a/drivers/usb/wusbcore/wa-xfer.c
39028 +++ b/drivers/usb/wusbcore/wa-xfer.c
39029 @@ -296,7 +296,7 @@ out:
39030 */
39031 static void wa_xfer_id_init(struct wa_xfer *xfer)
39032 {
39033 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39034 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39035 }
39036
39037 /*
39038 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39039 index 112156f..eb81154 100644
39040 --- a/drivers/vhost/vhost.c
39041 +++ b/drivers/vhost/vhost.c
39042 @@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39043 return 0;
39044 }
39045
39046 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39047 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39048 {
39049 struct file *eventfp, *filep = NULL,
39050 *pollstart = NULL, *pollstop = NULL;
39051 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39052 index b0b2ac3..89a4399 100644
39053 --- a/drivers/video/aty/aty128fb.c
39054 +++ b/drivers/video/aty/aty128fb.c
39055 @@ -148,7 +148,7 @@ enum {
39056 };
39057
39058 /* Must match above enum */
39059 -static const char *r128_family[] __devinitdata = {
39060 +static const char *r128_family[] __devinitconst = {
39061 "AGP",
39062 "PCI",
39063 "PRO AGP",
39064 diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
39065 index 2e471c2..f00eb3e 100644
39066 --- a/drivers/video/console/fbcon.c
39067 +++ b/drivers/video/console/fbcon.c
39068 @@ -442,7 +442,7 @@ static int __init fb_console_setup(char *this_opt)
39069
39070 while ((options = strsep(&this_opt, ",")) != NULL) {
39071 if (!strncmp(options, "font:", 5))
39072 - strcpy(fontname, options + 5);
39073 + strlcpy(fontname, options + 5, sizeof(fontname));
39074
39075 if (!strncmp(options, "scrollback:", 11)) {
39076 options += 11;
39077 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39078 index 5c3960d..15cf8fc 100644
39079 --- a/drivers/video/fbcmap.c
39080 +++ b/drivers/video/fbcmap.c
39081 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39082 rc = -ENODEV;
39083 goto out;
39084 }
39085 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39086 - !info->fbops->fb_setcmap)) {
39087 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39088 rc = -EINVAL;
39089 goto out1;
39090 }
39091 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39092 index 0dff12a..2ef47b3 100644
39093 --- a/drivers/video/fbmem.c
39094 +++ b/drivers/video/fbmem.c
39095 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39096 image->dx += image->width + 8;
39097 }
39098 } else if (rotate == FB_ROTATE_UD) {
39099 - for (x = 0; x < num && image->dx >= 0; x++) {
39100 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39101 info->fbops->fb_imageblit(info, image);
39102 image->dx -= image->width + 8;
39103 }
39104 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39105 image->dy += image->height + 8;
39106 }
39107 } else if (rotate == FB_ROTATE_CCW) {
39108 - for (x = 0; x < num && image->dy >= 0; x++) {
39109 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39110 info->fbops->fb_imageblit(info, image);
39111 image->dy -= image->height + 8;
39112 }
39113 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39114 return -EFAULT;
39115 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39116 return -EINVAL;
39117 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39118 + if (con2fb.framebuffer >= FB_MAX)
39119 return -EINVAL;
39120 if (!registered_fb[con2fb.framebuffer])
39121 request_module("fb%d", con2fb.framebuffer);
39122 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39123 index 5a5d092..265c5ed 100644
39124 --- a/drivers/video/geode/gx1fb_core.c
39125 +++ b/drivers/video/geode/gx1fb_core.c
39126 @@ -29,7 +29,7 @@ static int crt_option = 1;
39127 static char panel_option[32] = "";
39128
39129 /* Modes relevant to the GX1 (taken from modedb.c) */
39130 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39131 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39132 /* 640x480-60 VESA */
39133 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39134 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39135 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39136 index 0fad23f..0e9afa4 100644
39137 --- a/drivers/video/gxt4500.c
39138 +++ b/drivers/video/gxt4500.c
39139 @@ -156,7 +156,7 @@ struct gxt4500_par {
39140 static char *mode_option;
39141
39142 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39143 -static const struct fb_videomode defaultmode __devinitdata = {
39144 +static const struct fb_videomode defaultmode __devinitconst = {
39145 .refresh = 60,
39146 .xres = 1280,
39147 .yres = 1024,
39148 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39149 return 0;
39150 }
39151
39152 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39153 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39154 .id = "IBM GXT4500P",
39155 .type = FB_TYPE_PACKED_PIXELS,
39156 .visual = FB_VISUAL_PSEUDOCOLOR,
39157 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39158 index 7672d2e..b56437f 100644
39159 --- a/drivers/video/i810/i810_accel.c
39160 +++ b/drivers/video/i810/i810_accel.c
39161 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39162 }
39163 }
39164 printk("ringbuffer lockup!!!\n");
39165 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39166 i810_report_error(mmio);
39167 par->dev_flags |= LOCKUP;
39168 info->pixmap.scan_align = 1;
39169 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39170 index b83f361..2b05a91 100644
39171 --- a/drivers/video/i810/i810_main.c
39172 +++ b/drivers/video/i810/i810_main.c
39173 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39174 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39175
39176 /* PCI */
39177 -static const char *i810_pci_list[] __devinitdata = {
39178 +static const char *i810_pci_list[] __devinitconst = {
39179 "Intel(R) 810 Framebuffer Device" ,
39180 "Intel(R) 810-DC100 Framebuffer Device" ,
39181 "Intel(R) 810E Framebuffer Device" ,
39182 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39183 index de36693..3c63fc2 100644
39184 --- a/drivers/video/jz4740_fb.c
39185 +++ b/drivers/video/jz4740_fb.c
39186 @@ -136,7 +136,7 @@ struct jzfb {
39187 uint32_t pseudo_palette[16];
39188 };
39189
39190 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39191 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39192 .id = "JZ4740 FB",
39193 .type = FB_TYPE_PACKED_PIXELS,
39194 .visual = FB_VISUAL_TRUECOLOR,
39195 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39196 index 3c14e43..eafa544 100644
39197 --- a/drivers/video/logo/logo_linux_clut224.ppm
39198 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39199 @@ -1,1604 +1,1123 @@
39200 P3
39201 -# Standard 224-color Linux logo
39202 80 80
39203 255
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 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 10 10 10 10 10 10
39214 - 10 10 10 6 6 6 6 6 6 6 6 6
39215 - 0 0 0 0 0 0 0 0 0 0 0 0
39216 - 0 0 0 0 0 0 0 0 0 0 0 0
39217 - 0 0 0 0 0 0 0 0 0 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 0 0 0
39221 - 0 0 0 0 0 0 0 0 0 0 0 0
39222 - 0 0 0 0 0 0 0 0 0 0 0 0
39223 - 0 0 0 0 0 0 0 0 0 0 0 0
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 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 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 6 6 6 10 10 10 14 14 14
39233 - 22 22 22 26 26 26 30 30 30 34 34 34
39234 - 30 30 30 30 30 30 26 26 26 18 18 18
39235 - 14 14 14 10 10 10 6 6 6 0 0 0
39236 - 0 0 0 0 0 0 0 0 0 0 0 0
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 0 0 0
39241 - 0 0 0 0 0 0 0 0 0 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 0 0 0
39243 - 0 0 0 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
39253 - 54 54 54 66 66 66 78 78 78 78 78 78
39254 - 78 78 78 74 74 74 66 66 66 54 54 54
39255 - 42 42 42 26 26 26 18 18 18 10 10 10
39256 - 6 6 6 0 0 0 0 0 0 0 0 0
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 0 0 0
39261 - 0 0 0 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 0 0 0
39263 - 0 0 0 0 0 0 0 0 0 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 1 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 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 10 10 10
39272 - 22 22 22 42 42 42 66 66 66 86 86 86
39273 - 66 66 66 38 38 38 38 38 38 22 22 22
39274 - 26 26 26 34 34 34 54 54 54 66 66 66
39275 - 86 86 86 70 70 70 46 46 46 26 26 26
39276 - 14 14 14 6 6 6 0 0 0 0 0 0
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 0 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 0 0 0 0
39281 - 0 0 0 0 0 0 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 10 10 10 26 26 26
39292 - 50 50 50 82 82 82 58 58 58 6 6 6
39293 - 2 2 6 2 2 6 2 2 6 2 2 6
39294 - 2 2 6 2 2 6 2 2 6 2 2 6
39295 - 6 6 6 54 54 54 86 86 86 66 66 66
39296 - 38 38 38 18 18 18 6 6 6 0 0 0
39297 - 0 0 0 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 0 0 0 0 0 0 0 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 0 0 0
39301 - 0 0 0 0 0 0 0 0 0 0 0 0
39302 - 0 0 0 0 0 0 0 0 0 0 0 0
39303 - 0 0 0 0 0 0 0 0 0 0 0 0
39304 - 0 0 0 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 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 0 0 0 0 0 0 0
39311 - 0 0 0 6 6 6 22 22 22 50 50 50
39312 - 78 78 78 34 34 34 2 2 6 2 2 6
39313 - 2 2 6 2 2 6 2 2 6 2 2 6
39314 - 2 2 6 2 2 6 2 2 6 2 2 6
39315 - 2 2 6 2 2 6 6 6 6 70 70 70
39316 - 78 78 78 46 46 46 22 22 22 6 6 6
39317 - 0 0 0 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 0 0 0 0
39321 - 0 0 0 0 0 0 0 0 0 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 0 0 0
39323 - 0 0 0 0 0 0 0 0 0 0 0 0
39324 - 0 0 0 0 0 0 0 0 0 0 0 0
39325 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
39331 - 6 6 6 18 18 18 42 42 42 82 82 82
39332 - 26 26 26 2 2 6 2 2 6 2 2 6
39333 - 2 2 6 2 2 6 2 2 6 2 2 6
39334 - 2 2 6 2 2 6 2 2 6 14 14 14
39335 - 46 46 46 34 34 34 6 6 6 2 2 6
39336 - 42 42 42 78 78 78 42 42 42 18 18 18
39337 - 6 6 6 0 0 0 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 0 0 0 0 0 0 0 0 0 0
39340 - 0 0 0 0 0 0 0 0 0 0 0 0
39341 - 0 0 0 0 0 0 0 0 0 0 0 0
39342 - 0 0 0 0 0 0 0 0 0 0 0 0
39343 - 0 0 0 0 0 0 0 0 0 0 0 0
39344 - 0 0 0 0 0 0 0 0 0 0 0 0
39345 - 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0 0
39351 - 10 10 10 30 30 30 66 66 66 58 58 58
39352 - 2 2 6 2 2 6 2 2 6 2 2 6
39353 - 2 2 6 2 2 6 2 2 6 2 2 6
39354 - 2 2 6 2 2 6 2 2 6 26 26 26
39355 - 86 86 86 101 101 101 46 46 46 10 10 10
39356 - 2 2 6 58 58 58 70 70 70 34 34 34
39357 - 10 10 10 0 0 0 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 0 0 0 0 0 0
39361 - 0 0 0 0 0 0 0 0 0 0 0 0
39362 - 0 0 0 0 0 0 0 0 0 0 0 0
39363 - 0 0 0 0 0 0 0 0 0 0 0 0
39364 - 0 0 0 0 0 0 0 0 0 0 0 0
39365 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
39372 - 2 2 6 2 2 6 2 2 6 2 2 6
39373 - 2 2 6 2 2 6 2 2 6 2 2 6
39374 - 2 2 6 2 2 6 2 2 6 30 30 30
39375 - 94 94 94 94 94 94 58 58 58 26 26 26
39376 - 2 2 6 6 6 6 78 78 78 54 54 54
39377 - 22 22 22 6 6 6 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 0 0 0
39381 - 0 0 0 0 0 0 0 0 0 0 0 0
39382 - 0 0 0 0 0 0 0 0 0 0 0 0
39383 - 0 0 0 0 0 0 0 0 0 0 0 0
39384 - 0 0 0 0 0 0 0 0 0 0 0 0
39385 - 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 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 6 6 6
39391 - 22 22 22 62 62 62 62 62 62 2 2 6
39392 - 2 2 6 2 2 6 2 2 6 2 2 6
39393 - 2 2 6 2 2 6 2 2 6 2 2 6
39394 - 2 2 6 2 2 6 2 2 6 26 26 26
39395 - 54 54 54 38 38 38 18 18 18 10 10 10
39396 - 2 2 6 2 2 6 34 34 34 82 82 82
39397 - 38 38 38 14 14 14 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 0 0 0 0 0 0
39401 - 0 0 0 0 0 0 0 0 0 0 0 0
39402 - 0 0 0 0 0 0 0 0 0 0 0 0
39403 - 0 0 0 0 0 0 0 0 0 0 0 0
39404 - 0 0 0 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 1 0 0 1 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 6 6 6
39411 - 30 30 30 78 78 78 30 30 30 2 2 6
39412 - 2 2 6 2 2 6 2 2 6 2 2 6
39413 - 2 2 6 2 2 6 2 2 6 2 2 6
39414 - 2 2 6 2 2 6 2 2 6 10 10 10
39415 - 10 10 10 2 2 6 2 2 6 2 2 6
39416 - 2 2 6 2 2 6 2 2 6 78 78 78
39417 - 50 50 50 18 18 18 6 6 6 0 0 0
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 0 0 0 0 0 0 0
39420 - 0 0 0 0 0 0 0 0 0 0 0 0
39421 - 0 0 0 0 0 0 0 0 0 0 0 0
39422 - 0 0 0 0 0 0 0 0 0 0 0 0
39423 - 0 0 0 0 0 0 0 0 0 0 0 0
39424 - 0 0 0 0 0 0 0 0 0 0 0 0
39425 - 0 0 1 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 0 0 0 0
39430 - 0 0 0 0 0 0 0 0 0 10 10 10
39431 - 38 38 38 86 86 86 14 14 14 2 2 6
39432 - 2 2 6 2 2 6 2 2 6 2 2 6
39433 - 2 2 6 2 2 6 2 2 6 2 2 6
39434 - 2 2 6 2 2 6 2 2 6 2 2 6
39435 - 2 2 6 2 2 6 2 2 6 2 2 6
39436 - 2 2 6 2 2 6 2 2 6 54 54 54
39437 - 66 66 66 26 26 26 6 6 6 0 0 0
39438 - 0 0 0 0 0 0 0 0 0 0 0 0
39439 - 0 0 0 0 0 0 0 0 0 0 0 0
39440 - 0 0 0 0 0 0 0 0 0 0 0 0
39441 - 0 0 0 0 0 0 0 0 0 0 0 0
39442 - 0 0 0 0 0 0 0 0 0 0 0 0
39443 - 0 0 0 0 0 0 0 0 0 0 0 0
39444 - 0 0 0 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 1 0 0 1 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 0 0 0 0
39450 - 0 0 0 0 0 0 0 0 0 14 14 14
39451 - 42 42 42 82 82 82 2 2 6 2 2 6
39452 - 2 2 6 6 6 6 10 10 10 2 2 6
39453 - 2 2 6 2 2 6 2 2 6 2 2 6
39454 - 2 2 6 2 2 6 2 2 6 6 6 6
39455 - 14 14 14 10 10 10 2 2 6 2 2 6
39456 - 2 2 6 2 2 6 2 2 6 18 18 18
39457 - 82 82 82 34 34 34 10 10 10 0 0 0
39458 - 0 0 0 0 0 0 0 0 0 0 0 0
39459 - 0 0 0 0 0 0 0 0 0 0 0 0
39460 - 0 0 0 0 0 0 0 0 0 0 0 0
39461 - 0 0 0 0 0 0 0 0 0 0 0 0
39462 - 0 0 0 0 0 0 0 0 0 0 0 0
39463 - 0 0 0 0 0 0 0 0 0 0 0 0
39464 - 0 0 0 0 0 0 0 0 0 0 0 0
39465 - 0 0 1 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 0 0 0 0
39470 - 0 0 0 0 0 0 0 0 0 14 14 14
39471 - 46 46 46 86 86 86 2 2 6 2 2 6
39472 - 6 6 6 6 6 6 22 22 22 34 34 34
39473 - 6 6 6 2 2 6 2 2 6 2 2 6
39474 - 2 2 6 2 2 6 18 18 18 34 34 34
39475 - 10 10 10 50 50 50 22 22 22 2 2 6
39476 - 2 2 6 2 2 6 2 2 6 10 10 10
39477 - 86 86 86 42 42 42 14 14 14 0 0 0
39478 - 0 0 0 0 0 0 0 0 0 0 0 0
39479 - 0 0 0 0 0 0 0 0 0 0 0 0
39480 - 0 0 0 0 0 0 0 0 0 0 0 0
39481 - 0 0 0 0 0 0 0 0 0 0 0 0
39482 - 0 0 0 0 0 0 0 0 0 0 0 0
39483 - 0 0 0 0 0 0 0 0 0 0 0 0
39484 - 0 0 0 0 0 0 0 0 0 0 0 0
39485 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39491 - 46 46 46 86 86 86 2 2 6 2 2 6
39492 - 38 38 38 116 116 116 94 94 94 22 22 22
39493 - 22 22 22 2 2 6 2 2 6 2 2 6
39494 - 14 14 14 86 86 86 138 138 138 162 162 162
39495 -154 154 154 38 38 38 26 26 26 6 6 6
39496 - 2 2 6 2 2 6 2 2 6 2 2 6
39497 - 86 86 86 46 46 46 14 14 14 0 0 0
39498 - 0 0 0 0 0 0 0 0 0 0 0 0
39499 - 0 0 0 0 0 0 0 0 0 0 0 0
39500 - 0 0 0 0 0 0 0 0 0 0 0 0
39501 - 0 0 0 0 0 0 0 0 0 0 0 0
39502 - 0 0 0 0 0 0 0 0 0 0 0 0
39503 - 0 0 0 0 0 0 0 0 0 0 0 0
39504 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39511 - 46 46 46 86 86 86 2 2 6 14 14 14
39512 -134 134 134 198 198 198 195 195 195 116 116 116
39513 - 10 10 10 2 2 6 2 2 6 6 6 6
39514 -101 98 89 187 187 187 210 210 210 218 218 218
39515 -214 214 214 134 134 134 14 14 14 6 6 6
39516 - 2 2 6 2 2 6 2 2 6 2 2 6
39517 - 86 86 86 50 50 50 18 18 18 6 6 6
39518 - 0 0 0 0 0 0 0 0 0 0 0 0
39519 - 0 0 0 0 0 0 0 0 0 0 0 0
39520 - 0 0 0 0 0 0 0 0 0 0 0 0
39521 - 0 0 0 0 0 0 0 0 0 0 0 0
39522 - 0 0 0 0 0 0 0 0 0 0 0 0
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 1 0 0 0
39525 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39531 - 46 46 46 86 86 86 2 2 6 54 54 54
39532 -218 218 218 195 195 195 226 226 226 246 246 246
39533 - 58 58 58 2 2 6 2 2 6 30 30 30
39534 -210 210 210 253 253 253 174 174 174 123 123 123
39535 -221 221 221 234 234 234 74 74 74 2 2 6
39536 - 2 2 6 2 2 6 2 2 6 2 2 6
39537 - 70 70 70 58 58 58 22 22 22 6 6 6
39538 - 0 0 0 0 0 0 0 0 0 0 0 0
39539 - 0 0 0 0 0 0 0 0 0 0 0 0
39540 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 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 14 14 14
39551 - 46 46 46 82 82 82 2 2 6 106 106 106
39552 -170 170 170 26 26 26 86 86 86 226 226 226
39553 -123 123 123 10 10 10 14 14 14 46 46 46
39554 -231 231 231 190 190 190 6 6 6 70 70 70
39555 - 90 90 90 238 238 238 158 158 158 2 2 6
39556 - 2 2 6 2 2 6 2 2 6 2 2 6
39557 - 70 70 70 58 58 58 22 22 22 6 6 6
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 1 0 0 0
39565 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39571 - 42 42 42 86 86 86 6 6 6 116 116 116
39572 -106 106 106 6 6 6 70 70 70 149 149 149
39573 -128 128 128 18 18 18 38 38 38 54 54 54
39574 -221 221 221 106 106 106 2 2 6 14 14 14
39575 - 46 46 46 190 190 190 198 198 198 2 2 6
39576 - 2 2 6 2 2 6 2 2 6 2 2 6
39577 - 74 74 74 62 62 62 22 22 22 6 6 6
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 1 0 0 0
39585 - 0 0 1 0 0 0 0 0 1 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 14 14 14
39591 - 42 42 42 94 94 94 14 14 14 101 101 101
39592 -128 128 128 2 2 6 18 18 18 116 116 116
39593 -118 98 46 121 92 8 121 92 8 98 78 10
39594 -162 162 162 106 106 106 2 2 6 2 2 6
39595 - 2 2 6 195 195 195 195 195 195 6 6 6
39596 - 2 2 6 2 2 6 2 2 6 2 2 6
39597 - 74 74 74 62 62 62 22 22 22 6 6 6
39598 - 0 0 0 0 0 0 0 0 0 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 1 0 0 1
39605 - 0 0 1 0 0 0 0 0 1 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 10 10 10
39611 - 38 38 38 90 90 90 14 14 14 58 58 58
39612 -210 210 210 26 26 26 54 38 6 154 114 10
39613 -226 170 11 236 186 11 225 175 15 184 144 12
39614 -215 174 15 175 146 61 37 26 9 2 2 6
39615 - 70 70 70 246 246 246 138 138 138 2 2 6
39616 - 2 2 6 2 2 6 2 2 6 2 2 6
39617 - 70 70 70 66 66 66 26 26 26 6 6 6
39618 - 0 0 0 0 0 0 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39631 - 38 38 38 86 86 86 14 14 14 10 10 10
39632 -195 195 195 188 164 115 192 133 9 225 175 15
39633 -239 182 13 234 190 10 232 195 16 232 200 30
39634 -245 207 45 241 208 19 232 195 16 184 144 12
39635 -218 194 134 211 206 186 42 42 42 2 2 6
39636 - 2 2 6 2 2 6 2 2 6 2 2 6
39637 - 50 50 50 74 74 74 30 30 30 6 6 6
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39651 - 34 34 34 86 86 86 14 14 14 2 2 6
39652 -121 87 25 192 133 9 219 162 10 239 182 13
39653 -236 186 11 232 195 16 241 208 19 244 214 54
39654 -246 218 60 246 218 38 246 215 20 241 208 19
39655 -241 208 19 226 184 13 121 87 25 2 2 6
39656 - 2 2 6 2 2 6 2 2 6 2 2 6
39657 - 50 50 50 82 82 82 34 34 34 10 10 10
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39671 - 34 34 34 82 82 82 30 30 30 61 42 6
39672 -180 123 7 206 145 10 230 174 11 239 182 13
39673 -234 190 10 238 202 15 241 208 19 246 218 74
39674 -246 218 38 246 215 20 246 215 20 246 215 20
39675 -226 184 13 215 174 15 184 144 12 6 6 6
39676 - 2 2 6 2 2 6 2 2 6 2 2 6
39677 - 26 26 26 94 94 94 42 42 42 14 14 14
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39691 - 30 30 30 78 78 78 50 50 50 104 69 6
39692 -192 133 9 216 158 10 236 178 12 236 186 11
39693 -232 195 16 241 208 19 244 214 54 245 215 43
39694 -246 215 20 246 215 20 241 208 19 198 155 10
39695 -200 144 11 216 158 10 156 118 10 2 2 6
39696 - 2 2 6 2 2 6 2 2 6 2 2 6
39697 - 6 6 6 90 90 90 54 54 54 18 18 18
39698 - 6 6 6 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39711 - 30 30 30 78 78 78 46 46 46 22 22 22
39712 -137 92 6 210 162 10 239 182 13 238 190 10
39713 -238 202 15 241 208 19 246 215 20 246 215 20
39714 -241 208 19 203 166 17 185 133 11 210 150 10
39715 -216 158 10 210 150 10 102 78 10 2 2 6
39716 - 6 6 6 54 54 54 14 14 14 2 2 6
39717 - 2 2 6 62 62 62 74 74 74 30 30 30
39718 - 10 10 10 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39731 - 34 34 34 78 78 78 50 50 50 6 6 6
39732 - 94 70 30 139 102 15 190 146 13 226 184 13
39733 -232 200 30 232 195 16 215 174 15 190 146 13
39734 -168 122 10 192 133 9 210 150 10 213 154 11
39735 -202 150 34 182 157 106 101 98 89 2 2 6
39736 - 2 2 6 78 78 78 116 116 116 58 58 58
39737 - 2 2 6 22 22 22 90 90 90 46 46 46
39738 - 18 18 18 6 6 6 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39751 - 38 38 38 86 86 86 50 50 50 6 6 6
39752 -128 128 128 174 154 114 156 107 11 168 122 10
39753 -198 155 10 184 144 12 197 138 11 200 144 11
39754 -206 145 10 206 145 10 197 138 11 188 164 115
39755 -195 195 195 198 198 198 174 174 174 14 14 14
39756 - 2 2 6 22 22 22 116 116 116 116 116 116
39757 - 22 22 22 2 2 6 74 74 74 70 70 70
39758 - 30 30 30 10 10 10 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
39771 - 50 50 50 101 101 101 26 26 26 10 10 10
39772 -138 138 138 190 190 190 174 154 114 156 107 11
39773 -197 138 11 200 144 11 197 138 11 192 133 9
39774 -180 123 7 190 142 34 190 178 144 187 187 187
39775 -202 202 202 221 221 221 214 214 214 66 66 66
39776 - 2 2 6 2 2 6 50 50 50 62 62 62
39777 - 6 6 6 2 2 6 10 10 10 90 90 90
39778 - 50 50 50 18 18 18 6 6 6 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
39791 - 74 74 74 74 74 74 2 2 6 6 6 6
39792 -144 144 144 198 198 198 190 190 190 178 166 146
39793 -154 121 60 156 107 11 156 107 11 168 124 44
39794 -174 154 114 187 187 187 190 190 190 210 210 210
39795 -246 246 246 253 253 253 253 253 253 182 182 182
39796 - 6 6 6 2 2 6 2 2 6 2 2 6
39797 - 2 2 6 2 2 6 2 2 6 62 62 62
39798 - 74 74 74 34 34 34 14 14 14 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 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 10 10 10 22 22 22 54 54 54
39811 - 94 94 94 18 18 18 2 2 6 46 46 46
39812 -234 234 234 221 221 221 190 190 190 190 190 190
39813 -190 190 190 187 187 187 187 187 187 190 190 190
39814 -190 190 190 195 195 195 214 214 214 242 242 242
39815 -253 253 253 253 253 253 253 253 253 253 253 253
39816 - 82 82 82 2 2 6 2 2 6 2 2 6
39817 - 2 2 6 2 2 6 2 2 6 14 14 14
39818 - 86 86 86 54 54 54 22 22 22 6 6 6
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
39831 - 46 46 46 18 18 18 6 6 6 182 182 182
39832 -253 253 253 246 246 246 206 206 206 190 190 190
39833 -190 190 190 190 190 190 190 190 190 190 190 190
39834 -206 206 206 231 231 231 250 250 250 253 253 253
39835 -253 253 253 253 253 253 253 253 253 253 253 253
39836 -202 202 202 14 14 14 2 2 6 2 2 6
39837 - 2 2 6 2 2 6 2 2 6 2 2 6
39838 - 42 42 42 86 86 86 42 42 42 18 18 18
39839 - 6 6 6 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 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 6 6 6
39850 - 14 14 14 38 38 38 74 74 74 66 66 66
39851 - 2 2 6 6 6 6 90 90 90 250 250 250
39852 -253 253 253 253 253 253 238 238 238 198 198 198
39853 -190 190 190 190 190 190 195 195 195 221 221 221
39854 -246 246 246 253 253 253 253 253 253 253 253 253
39855 -253 253 253 253 253 253 253 253 253 253 253 253
39856 -253 253 253 82 82 82 2 2 6 2 2 6
39857 - 2 2 6 2 2 6 2 2 6 2 2 6
39858 - 2 2 6 78 78 78 70 70 70 34 34 34
39859 - 14 14 14 6 6 6 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 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 14 14 14
39870 - 34 34 34 66 66 66 78 78 78 6 6 6
39871 - 2 2 6 18 18 18 218 218 218 253 253 253
39872 -253 253 253 253 253 253 253 253 253 246 246 246
39873 -226 226 226 231 231 231 246 246 246 253 253 253
39874 -253 253 253 253 253 253 253 253 253 253 253 253
39875 -253 253 253 253 253 253 253 253 253 253 253 253
39876 -253 253 253 178 178 178 2 2 6 2 2 6
39877 - 2 2 6 2 2 6 2 2 6 2 2 6
39878 - 2 2 6 18 18 18 90 90 90 62 62 62
39879 - 30 30 30 10 10 10 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 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 10 10 10 26 26 26
39890 - 58 58 58 90 90 90 18 18 18 2 2 6
39891 - 2 2 6 110 110 110 253 253 253 253 253 253
39892 -253 253 253 253 253 253 253 253 253 253 253 253
39893 -250 250 250 253 253 253 253 253 253 253 253 253
39894 -253 253 253 253 253 253 253 253 253 253 253 253
39895 -253 253 253 253 253 253 253 253 253 253 253 253
39896 -253 253 253 231 231 231 18 18 18 2 2 6
39897 - 2 2 6 2 2 6 2 2 6 2 2 6
39898 - 2 2 6 2 2 6 18 18 18 94 94 94
39899 - 54 54 54 26 26 26 10 10 10 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
39910 - 90 90 90 26 26 26 2 2 6 2 2 6
39911 - 14 14 14 195 195 195 250 250 250 253 253 253
39912 -253 253 253 253 253 253 253 253 253 253 253 253
39913 -253 253 253 253 253 253 253 253 253 253 253 253
39914 -253 253 253 253 253 253 253 253 253 253 253 253
39915 -253 253 253 253 253 253 253 253 253 253 253 253
39916 -250 250 250 242 242 242 54 54 54 2 2 6
39917 - 2 2 6 2 2 6 2 2 6 2 2 6
39918 - 2 2 6 2 2 6 2 2 6 38 38 38
39919 - 86 86 86 50 50 50 22 22 22 6 6 6
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 38 38 38 82 82 82
39930 - 34 34 34 2 2 6 2 2 6 2 2 6
39931 - 42 42 42 195 195 195 246 246 246 253 253 253
39932 -253 253 253 253 253 253 253 253 253 250 250 250
39933 -242 242 242 242 242 242 250 250 250 253 253 253
39934 -253 253 253 253 253 253 253 253 253 253 253 253
39935 -253 253 253 250 250 250 246 246 246 238 238 238
39936 -226 226 226 231 231 231 101 101 101 6 6 6
39937 - 2 2 6 2 2 6 2 2 6 2 2 6
39938 - 2 2 6 2 2 6 2 2 6 2 2 6
39939 - 38 38 38 82 82 82 42 42 42 14 14 14
39940 - 6 6 6 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 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 - 10 10 10 26 26 26 62 62 62 66 66 66
39950 - 2 2 6 2 2 6 2 2 6 6 6 6
39951 - 70 70 70 170 170 170 206 206 206 234 234 234
39952 -246 246 246 250 250 250 250 250 250 238 238 238
39953 -226 226 226 231 231 231 238 238 238 250 250 250
39954 -250 250 250 250 250 250 246 246 246 231 231 231
39955 -214 214 214 206 206 206 202 202 202 202 202 202
39956 -198 198 198 202 202 202 182 182 182 18 18 18
39957 - 2 2 6 2 2 6 2 2 6 2 2 6
39958 - 2 2 6 2 2 6 2 2 6 2 2 6
39959 - 2 2 6 62 62 62 66 66 66 30 30 30
39960 - 10 10 10 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 14 14 14 42 42 42 82 82 82 18 18 18
39970 - 2 2 6 2 2 6 2 2 6 10 10 10
39971 - 94 94 94 182 182 182 218 218 218 242 242 242
39972 -250 250 250 253 253 253 253 253 253 250 250 250
39973 -234 234 234 253 253 253 253 253 253 253 253 253
39974 -253 253 253 253 253 253 253 253 253 246 246 246
39975 -238 238 238 226 226 226 210 210 210 202 202 202
39976 -195 195 195 195 195 195 210 210 210 158 158 158
39977 - 6 6 6 14 14 14 50 50 50 14 14 14
39978 - 2 2 6 2 2 6 2 2 6 2 2 6
39979 - 2 2 6 6 6 6 86 86 86 46 46 46
39980 - 18 18 18 6 6 6 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39989 - 22 22 22 54 54 54 70 70 70 2 2 6
39990 - 2 2 6 10 10 10 2 2 6 22 22 22
39991 -166 166 166 231 231 231 250 250 250 253 253 253
39992 -253 253 253 253 253 253 253 253 253 250 250 250
39993 -242 242 242 253 253 253 253 253 253 253 253 253
39994 -253 253 253 253 253 253 253 253 253 253 253 253
39995 -253 253 253 253 253 253 253 253 253 246 246 246
39996 -231 231 231 206 206 206 198 198 198 226 226 226
39997 - 94 94 94 2 2 6 6 6 6 38 38 38
39998 - 30 30 30 2 2 6 2 2 6 2 2 6
39999 - 2 2 6 2 2 6 62 62 62 66 66 66
40000 - 26 26 26 10 10 10 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
40009 - 30 30 30 74 74 74 50 50 50 2 2 6
40010 - 26 26 26 26 26 26 2 2 6 106 106 106
40011 -238 238 238 253 253 253 253 253 253 253 253 253
40012 -253 253 253 253 253 253 253 253 253 253 253 253
40013 -253 253 253 253 253 253 253 253 253 253 253 253
40014 -253 253 253 253 253 253 253 253 253 253 253 253
40015 -253 253 253 253 253 253 253 253 253 253 253 253
40016 -253 253 253 246 246 246 218 218 218 202 202 202
40017 -210 210 210 14 14 14 2 2 6 2 2 6
40018 - 30 30 30 22 22 22 2 2 6 2 2 6
40019 - 2 2 6 2 2 6 18 18 18 86 86 86
40020 - 42 42 42 14 14 14 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
40029 - 42 42 42 90 90 90 22 22 22 2 2 6
40030 - 42 42 42 2 2 6 18 18 18 218 218 218
40031 -253 253 253 253 253 253 253 253 253 253 253 253
40032 -253 253 253 253 253 253 253 253 253 253 253 253
40033 -253 253 253 253 253 253 253 253 253 253 253 253
40034 -253 253 253 253 253 253 253 253 253 253 253 253
40035 -253 253 253 253 253 253 253 253 253 253 253 253
40036 -253 253 253 253 253 253 250 250 250 221 221 221
40037 -218 218 218 101 101 101 2 2 6 14 14 14
40038 - 18 18 18 38 38 38 10 10 10 2 2 6
40039 - 2 2 6 2 2 6 2 2 6 78 78 78
40040 - 58 58 58 22 22 22 6 6 6 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 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 6 6 6 18 18 18
40049 - 54 54 54 82 82 82 2 2 6 26 26 26
40050 - 22 22 22 2 2 6 123 123 123 253 253 253
40051 -253 253 253 253 253 253 253 253 253 253 253 253
40052 -253 253 253 253 253 253 253 253 253 253 253 253
40053 -253 253 253 253 253 253 253 253 253 253 253 253
40054 -253 253 253 253 253 253 253 253 253 253 253 253
40055 -253 253 253 253 253 253 253 253 253 253 253 253
40056 -253 253 253 253 253 253 253 253 253 250 250 250
40057 -238 238 238 198 198 198 6 6 6 38 38 38
40058 - 58 58 58 26 26 26 38 38 38 2 2 6
40059 - 2 2 6 2 2 6 2 2 6 46 46 46
40060 - 78 78 78 30 30 30 10 10 10 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 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 10 10 10 30 30 30
40069 - 74 74 74 58 58 58 2 2 6 42 42 42
40070 - 2 2 6 22 22 22 231 231 231 253 253 253
40071 -253 253 253 253 253 253 253 253 253 253 253 253
40072 -253 253 253 253 253 253 253 253 253 250 250 250
40073 -253 253 253 253 253 253 253 253 253 253 253 253
40074 -253 253 253 253 253 253 253 253 253 253 253 253
40075 -253 253 253 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 246 246 246 46 46 46 38 38 38
40078 - 42 42 42 14 14 14 38 38 38 14 14 14
40079 - 2 2 6 2 2 6 2 2 6 6 6 6
40080 - 86 86 86 46 46 46 14 14 14 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 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 6 6 6 14 14 14 42 42 42
40089 - 90 90 90 18 18 18 18 18 18 26 26 26
40090 - 2 2 6 116 116 116 253 253 253 253 253 253
40091 -253 253 253 253 253 253 253 253 253 253 253 253
40092 -253 253 253 253 253 253 250 250 250 238 238 238
40093 -253 253 253 253 253 253 253 253 253 253 253 253
40094 -253 253 253 253 253 253 253 253 253 253 253 253
40095 -253 253 253 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 94 94 94 6 6 6
40098 - 2 2 6 2 2 6 10 10 10 34 34 34
40099 - 2 2 6 2 2 6 2 2 6 2 2 6
40100 - 74 74 74 58 58 58 22 22 22 6 6 6
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 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 10 10 10 26 26 26 66 66 66
40109 - 82 82 82 2 2 6 38 38 38 6 6 6
40110 - 14 14 14 210 210 210 253 253 253 253 253 253
40111 -253 253 253 253 253 253 253 253 253 253 253 253
40112 -253 253 253 253 253 253 246 246 246 242 242 242
40113 -253 253 253 253 253 253 253 253 253 253 253 253
40114 -253 253 253 253 253 253 253 253 253 253 253 253
40115 -253 253 253 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 144 144 144 2 2 6
40118 - 2 2 6 2 2 6 2 2 6 46 46 46
40119 - 2 2 6 2 2 6 2 2 6 2 2 6
40120 - 42 42 42 74 74 74 30 30 30 10 10 10
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 6 6 6 14 14 14 42 42 42 90 90 90
40129 - 26 26 26 6 6 6 42 42 42 2 2 6
40130 - 74 74 74 250 250 250 253 253 253 253 253 253
40131 -253 253 253 253 253 253 253 253 253 253 253 253
40132 -253 253 253 253 253 253 242 242 242 242 242 242
40133 -253 253 253 253 253 253 253 253 253 253 253 253
40134 -253 253 253 253 253 253 253 253 253 253 253 253
40135 -253 253 253 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 182 182 182 2 2 6
40138 - 2 2 6 2 2 6 2 2 6 46 46 46
40139 - 2 2 6 2 2 6 2 2 6 2 2 6
40140 - 10 10 10 86 86 86 38 38 38 10 10 10
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 10 10 10 26 26 26 66 66 66 82 82 82
40149 - 2 2 6 22 22 22 18 18 18 2 2 6
40150 -149 149 149 253 253 253 253 253 253 253 253 253
40151 -253 253 253 253 253 253 253 253 253 253 253 253
40152 -253 253 253 253 253 253 234 234 234 242 242 242
40153 -253 253 253 253 253 253 253 253 253 253 253 253
40154 -253 253 253 253 253 253 253 253 253 253 253 253
40155 -253 253 253 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 206 206 206 2 2 6
40158 - 2 2 6 2 2 6 2 2 6 38 38 38
40159 - 2 2 6 2 2 6 2 2 6 2 2 6
40160 - 6 6 6 86 86 86 46 46 46 14 14 14
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 6 6 6
40168 - 18 18 18 46 46 46 86 86 86 18 18 18
40169 - 2 2 6 34 34 34 10 10 10 6 6 6
40170 -210 210 210 253 253 253 253 253 253 253 253 253
40171 -253 253 253 253 253 253 253 253 253 253 253 253
40172 -253 253 253 253 253 253 234 234 234 242 242 242
40173 -253 253 253 253 253 253 253 253 253 253 253 253
40174 -253 253 253 253 253 253 253 253 253 253 253 253
40175 -253 253 253 253 253 253 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 221 221 221 6 6 6
40178 - 2 2 6 2 2 6 6 6 6 30 30 30
40179 - 2 2 6 2 2 6 2 2 6 2 2 6
40180 - 2 2 6 82 82 82 54 54 54 18 18 18
40181 - 6 6 6 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 10 10 10
40188 - 26 26 26 66 66 66 62 62 62 2 2 6
40189 - 2 2 6 38 38 38 10 10 10 26 26 26
40190 -238 238 238 253 253 253 253 253 253 253 253 253
40191 -253 253 253 253 253 253 253 253 253 253 253 253
40192 -253 253 253 253 253 253 231 231 231 238 238 238
40193 -253 253 253 253 253 253 253 253 253 253 253 253
40194 -253 253 253 253 253 253 253 253 253 253 253 253
40195 -253 253 253 253 253 253 253 253 253 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 6 6 6
40198 - 2 2 6 2 2 6 10 10 10 30 30 30
40199 - 2 2 6 2 2 6 2 2 6 2 2 6
40200 - 2 2 6 66 66 66 58 58 58 22 22 22
40201 - 6 6 6 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 10 10 10
40208 - 38 38 38 78 78 78 6 6 6 2 2 6
40209 - 2 2 6 46 46 46 14 14 14 42 42 42
40210 -246 246 246 253 253 253 253 253 253 253 253 253
40211 -253 253 253 253 253 253 253 253 253 253 253 253
40212 -253 253 253 253 253 253 231 231 231 242 242 242
40213 -253 253 253 253 253 253 253 253 253 253 253 253
40214 -253 253 253 253 253 253 253 253 253 253 253 253
40215 -253 253 253 253 253 253 253 253 253 253 253 253
40216 -253 253 253 253 253 253 253 253 253 253 253 253
40217 -253 253 253 253 253 253 234 234 234 10 10 10
40218 - 2 2 6 2 2 6 22 22 22 14 14 14
40219 - 2 2 6 2 2 6 2 2 6 2 2 6
40220 - 2 2 6 66 66 66 62 62 62 22 22 22
40221 - 6 6 6 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 6 6 6 18 18 18
40228 - 50 50 50 74 74 74 2 2 6 2 2 6
40229 - 14 14 14 70 70 70 34 34 34 62 62 62
40230 -250 250 250 253 253 253 253 253 253 253 253 253
40231 -253 253 253 253 253 253 253 253 253 253 253 253
40232 -253 253 253 253 253 253 231 231 231 246 246 246
40233 -253 253 253 253 253 253 253 253 253 253 253 253
40234 -253 253 253 253 253 253 253 253 253 253 253 253
40235 -253 253 253 253 253 253 253 253 253 253 253 253
40236 -253 253 253 253 253 253 253 253 253 253 253 253
40237 -253 253 253 253 253 253 234 234 234 14 14 14
40238 - 2 2 6 2 2 6 30 30 30 2 2 6
40239 - 2 2 6 2 2 6 2 2 6 2 2 6
40240 - 2 2 6 66 66 66 62 62 62 22 22 22
40241 - 6 6 6 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 6 6 6 18 18 18
40248 - 54 54 54 62 62 62 2 2 6 2 2 6
40249 - 2 2 6 30 30 30 46 46 46 70 70 70
40250 -250 250 250 253 253 253 253 253 253 253 253 253
40251 -253 253 253 253 253 253 253 253 253 253 253 253
40252 -253 253 253 253 253 253 231 231 231 246 246 246
40253 -253 253 253 253 253 253 253 253 253 253 253 253
40254 -253 253 253 253 253 253 253 253 253 253 253 253
40255 -253 253 253 253 253 253 253 253 253 253 253 253
40256 -253 253 253 253 253 253 253 253 253 253 253 253
40257 -253 253 253 253 253 253 226 226 226 10 10 10
40258 - 2 2 6 6 6 6 30 30 30 2 2 6
40259 - 2 2 6 2 2 6 2 2 6 2 2 6
40260 - 2 2 6 66 66 66 58 58 58 22 22 22
40261 - 6 6 6 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 6 6 6 22 22 22
40268 - 58 58 58 62 62 62 2 2 6 2 2 6
40269 - 2 2 6 2 2 6 30 30 30 78 78 78
40270 -250 250 250 253 253 253 253 253 253 253 253 253
40271 -253 253 253 253 253 253 253 253 253 253 253 253
40272 -253 253 253 253 253 253 231 231 231 246 246 246
40273 -253 253 253 253 253 253 253 253 253 253 253 253
40274 -253 253 253 253 253 253 253 253 253 253 253 253
40275 -253 253 253 253 253 253 253 253 253 253 253 253
40276 -253 253 253 253 253 253 253 253 253 253 253 253
40277 -253 253 253 253 253 253 206 206 206 2 2 6
40278 - 22 22 22 34 34 34 18 14 6 22 22 22
40279 - 26 26 26 18 18 18 6 6 6 2 2 6
40280 - 2 2 6 82 82 82 54 54 54 18 18 18
40281 - 6 6 6 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 6 6 6 26 26 26
40288 - 62 62 62 106 106 106 74 54 14 185 133 11
40289 -210 162 10 121 92 8 6 6 6 62 62 62
40290 -238 238 238 253 253 253 253 253 253 253 253 253
40291 -253 253 253 253 253 253 253 253 253 253 253 253
40292 -253 253 253 253 253 253 231 231 231 246 246 246
40293 -253 253 253 253 253 253 253 253 253 253 253 253
40294 -253 253 253 253 253 253 253 253 253 253 253 253
40295 -253 253 253 253 253 253 253 253 253 253 253 253
40296 -253 253 253 253 253 253 253 253 253 253 253 253
40297 -253 253 253 253 253 253 158 158 158 18 18 18
40298 - 14 14 14 2 2 6 2 2 6 2 2 6
40299 - 6 6 6 18 18 18 66 66 66 38 38 38
40300 - 6 6 6 94 94 94 50 50 50 18 18 18
40301 - 6 6 6 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 6 6 6
40307 - 10 10 10 10 10 10 18 18 18 38 38 38
40308 - 78 78 78 142 134 106 216 158 10 242 186 14
40309 -246 190 14 246 190 14 156 118 10 10 10 10
40310 - 90 90 90 238 238 238 253 253 253 253 253 253
40311 -253 253 253 253 253 253 253 253 253 253 253 253
40312 -253 253 253 253 253 253 231 231 231 250 250 250
40313 -253 253 253 253 253 253 253 253 253 253 253 253
40314 -253 253 253 253 253 253 253 253 253 253 253 253
40315 -253 253 253 253 253 253 253 253 253 253 253 253
40316 -253 253 253 253 253 253 253 253 253 246 230 190
40317 -238 204 91 238 204 91 181 142 44 37 26 9
40318 - 2 2 6 2 2 6 2 2 6 2 2 6
40319 - 2 2 6 2 2 6 38 38 38 46 46 46
40320 - 26 26 26 106 106 106 54 54 54 18 18 18
40321 - 6 6 6 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 6 6 6 14 14 14 22 22 22
40327 - 30 30 30 38 38 38 50 50 50 70 70 70
40328 -106 106 106 190 142 34 226 170 11 242 186 14
40329 -246 190 14 246 190 14 246 190 14 154 114 10
40330 - 6 6 6 74 74 74 226 226 226 253 253 253
40331 -253 253 253 253 253 253 253 253 253 253 253 253
40332 -253 253 253 253 253 253 231 231 231 250 250 250
40333 -253 253 253 253 253 253 253 253 253 253 253 253
40334 -253 253 253 253 253 253 253 253 253 253 253 253
40335 -253 253 253 253 253 253 253 253 253 253 253 253
40336 -253 253 253 253 253 253 253 253 253 228 184 62
40337 -241 196 14 241 208 19 232 195 16 38 30 10
40338 - 2 2 6 2 2 6 2 2 6 2 2 6
40339 - 2 2 6 6 6 6 30 30 30 26 26 26
40340 -203 166 17 154 142 90 66 66 66 26 26 26
40341 - 6 6 6 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 6 6 6 18 18 18 38 38 38 58 58 58
40347 - 78 78 78 86 86 86 101 101 101 123 123 123
40348 -175 146 61 210 150 10 234 174 13 246 186 14
40349 -246 190 14 246 190 14 246 190 14 238 190 10
40350 -102 78 10 2 2 6 46 46 46 198 198 198
40351 -253 253 253 253 253 253 253 253 253 253 253 253
40352 -253 253 253 253 253 253 234 234 234 242 242 242
40353 -253 253 253 253 253 253 253 253 253 253 253 253
40354 -253 253 253 253 253 253 253 253 253 253 253 253
40355 -253 253 253 253 253 253 253 253 253 253 253 253
40356 -253 253 253 253 253 253 253 253 253 224 178 62
40357 -242 186 14 241 196 14 210 166 10 22 18 6
40358 - 2 2 6 2 2 6 2 2 6 2 2 6
40359 - 2 2 6 2 2 6 6 6 6 121 92 8
40360 -238 202 15 232 195 16 82 82 82 34 34 34
40361 - 10 10 10 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 0 0 0
40366 - 14 14 14 38 38 38 70 70 70 154 122 46
40367 -190 142 34 200 144 11 197 138 11 197 138 11
40368 -213 154 11 226 170 11 242 186 14 246 190 14
40369 -246 190 14 246 190 14 246 190 14 246 190 14
40370 -225 175 15 46 32 6 2 2 6 22 22 22
40371 -158 158 158 250 250 250 253 253 253 253 253 253
40372 -253 253 253 253 253 253 253 253 253 253 253 253
40373 -253 253 253 253 253 253 253 253 253 253 253 253
40374 -253 253 253 253 253 253 253 253 253 253 253 253
40375 -253 253 253 253 253 253 253 253 253 253 253 253
40376 -253 253 253 250 250 250 242 242 242 224 178 62
40377 -239 182 13 236 186 11 213 154 11 46 32 6
40378 - 2 2 6 2 2 6 2 2 6 2 2 6
40379 - 2 2 6 2 2 6 61 42 6 225 175 15
40380 -238 190 10 236 186 11 112 100 78 42 42 42
40381 - 14 14 14 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 6 6 6
40386 - 22 22 22 54 54 54 154 122 46 213 154 11
40387 -226 170 11 230 174 11 226 170 11 226 170 11
40388 -236 178 12 242 186 14 246 190 14 246 190 14
40389 -246 190 14 246 190 14 246 190 14 246 190 14
40390 -241 196 14 184 144 12 10 10 10 2 2 6
40391 - 6 6 6 116 116 116 242 242 242 253 253 253
40392 -253 253 253 253 253 253 253 253 253 253 253 253
40393 -253 253 253 253 253 253 253 253 253 253 253 253
40394 -253 253 253 253 253 253 253 253 253 253 253 253
40395 -253 253 253 253 253 253 253 253 253 253 253 253
40396 -253 253 253 231 231 231 198 198 198 214 170 54
40397 -236 178 12 236 178 12 210 150 10 137 92 6
40398 - 18 14 6 2 2 6 2 2 6 2 2 6
40399 - 6 6 6 70 47 6 200 144 11 236 178 12
40400 -239 182 13 239 182 13 124 112 88 58 58 58
40401 - 22 22 22 6 6 6 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 10 10 10
40406 - 30 30 30 70 70 70 180 133 36 226 170 11
40407 -239 182 13 242 186 14 242 186 14 246 186 14
40408 -246 190 14 246 190 14 246 190 14 246 190 14
40409 -246 190 14 246 190 14 246 190 14 246 190 14
40410 -246 190 14 232 195 16 98 70 6 2 2 6
40411 - 2 2 6 2 2 6 66 66 66 221 221 221
40412 -253 253 253 253 253 253 253 253 253 253 253 253
40413 -253 253 253 253 253 253 253 253 253 253 253 253
40414 -253 253 253 253 253 253 253 253 253 253 253 253
40415 -253 253 253 253 253 253 253 253 253 253 253 253
40416 -253 253 253 206 206 206 198 198 198 214 166 58
40417 -230 174 11 230 174 11 216 158 10 192 133 9
40418 -163 110 8 116 81 8 102 78 10 116 81 8
40419 -167 114 7 197 138 11 226 170 11 239 182 13
40420 -242 186 14 242 186 14 162 146 94 78 78 78
40421 - 34 34 34 14 14 14 6 6 6 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 6 6 6
40426 - 30 30 30 78 78 78 190 142 34 226 170 11
40427 -239 182 13 246 190 14 246 190 14 246 190 14
40428 -246 190 14 246 190 14 246 190 14 246 190 14
40429 -246 190 14 246 190 14 246 190 14 246 190 14
40430 -246 190 14 241 196 14 203 166 17 22 18 6
40431 - 2 2 6 2 2 6 2 2 6 38 38 38
40432 -218 218 218 253 253 253 253 253 253 253 253 253
40433 -253 253 253 253 253 253 253 253 253 253 253 253
40434 -253 253 253 253 253 253 253 253 253 253 253 253
40435 -253 253 253 253 253 253 253 253 253 253 253 253
40436 -250 250 250 206 206 206 198 198 198 202 162 69
40437 -226 170 11 236 178 12 224 166 10 210 150 10
40438 -200 144 11 197 138 11 192 133 9 197 138 11
40439 -210 150 10 226 170 11 242 186 14 246 190 14
40440 -246 190 14 246 186 14 225 175 15 124 112 88
40441 - 62 62 62 30 30 30 14 14 14 6 6 6
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 0 0 0 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 0 0 0 0 0 0 10 10 10
40446 - 30 30 30 78 78 78 174 135 50 224 166 10
40447 -239 182 13 246 190 14 246 190 14 246 190 14
40448 -246 190 14 246 190 14 246 190 14 246 190 14
40449 -246 190 14 246 190 14 246 190 14 246 190 14
40450 -246 190 14 246 190 14 241 196 14 139 102 15
40451 - 2 2 6 2 2 6 2 2 6 2 2 6
40452 - 78 78 78 250 250 250 253 253 253 253 253 253
40453 -253 253 253 253 253 253 253 253 253 253 253 253
40454 -253 253 253 253 253 253 253 253 253 253 253 253
40455 -253 253 253 253 253 253 253 253 253 253 253 253
40456 -250 250 250 214 214 214 198 198 198 190 150 46
40457 -219 162 10 236 178 12 234 174 13 224 166 10
40458 -216 158 10 213 154 11 213 154 11 216 158 10
40459 -226 170 11 239 182 13 246 190 14 246 190 14
40460 -246 190 14 246 190 14 242 186 14 206 162 42
40461 -101 101 101 58 58 58 30 30 30 14 14 14
40462 - 6 6 6 0 0 0 0 0 0 0 0 0
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 0 0 0 0 0 0 0 0 0 0 0 0
40465 - 0 0 0 0 0 0 0 0 0 10 10 10
40466 - 30 30 30 74 74 74 174 135 50 216 158 10
40467 -236 178 12 246 190 14 246 190 14 246 190 14
40468 -246 190 14 246 190 14 246 190 14 246 190 14
40469 -246 190 14 246 190 14 246 190 14 246 190 14
40470 -246 190 14 246 190 14 241 196 14 226 184 13
40471 - 61 42 6 2 2 6 2 2 6 2 2 6
40472 - 22 22 22 238 238 238 253 253 253 253 253 253
40473 -253 253 253 253 253 253 253 253 253 253 253 253
40474 -253 253 253 253 253 253 253 253 253 253 253 253
40475 -253 253 253 253 253 253 253 253 253 253 253 253
40476 -253 253 253 226 226 226 187 187 187 180 133 36
40477 -216 158 10 236 178 12 239 182 13 236 178 12
40478 -230 174 11 226 170 11 226 170 11 230 174 11
40479 -236 178 12 242 186 14 246 190 14 246 190 14
40480 -246 190 14 246 190 14 246 186 14 239 182 13
40481 -206 162 42 106 106 106 66 66 66 34 34 34
40482 - 14 14 14 6 6 6 0 0 0 0 0 0
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 0 0 0 0 0 0
40485 - 0 0 0 0 0 0 0 0 0 6 6 6
40486 - 26 26 26 70 70 70 163 133 67 213 154 11
40487 -236 178 12 246 190 14 246 190 14 246 190 14
40488 -246 190 14 246 190 14 246 190 14 246 190 14
40489 -246 190 14 246 190 14 246 190 14 246 190 14
40490 -246 190 14 246 190 14 246 190 14 241 196 14
40491 -190 146 13 18 14 6 2 2 6 2 2 6
40492 - 46 46 46 246 246 246 253 253 253 253 253 253
40493 -253 253 253 253 253 253 253 253 253 253 253 253
40494 -253 253 253 253 253 253 253 253 253 253 253 253
40495 -253 253 253 253 253 253 253 253 253 253 253 253
40496 -253 253 253 221 221 221 86 86 86 156 107 11
40497 -216 158 10 236 178 12 242 186 14 246 186 14
40498 -242 186 14 239 182 13 239 182 13 242 186 14
40499 -242 186 14 246 186 14 246 190 14 246 190 14
40500 -246 190 14 246 190 14 246 190 14 246 190 14
40501 -242 186 14 225 175 15 142 122 72 66 66 66
40502 - 30 30 30 10 10 10 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 0 0 0
40505 - 0 0 0 0 0 0 0 0 0 6 6 6
40506 - 26 26 26 70 70 70 163 133 67 210 150 10
40507 -236 178 12 246 190 14 246 190 14 246 190 14
40508 -246 190 14 246 190 14 246 190 14 246 190 14
40509 -246 190 14 246 190 14 246 190 14 246 190 14
40510 -246 190 14 246 190 14 246 190 14 246 190 14
40511 -232 195 16 121 92 8 34 34 34 106 106 106
40512 -221 221 221 253 253 253 253 253 253 253 253 253
40513 -253 253 253 253 253 253 253 253 253 253 253 253
40514 -253 253 253 253 253 253 253 253 253 253 253 253
40515 -253 253 253 253 253 253 253 253 253 253 253 253
40516 -242 242 242 82 82 82 18 14 6 163 110 8
40517 -216 158 10 236 178 12 242 186 14 246 190 14
40518 -246 190 14 246 190 14 246 190 14 246 190 14
40519 -246 190 14 246 190 14 246 190 14 246 190 14
40520 -246 190 14 246 190 14 246 190 14 246 190 14
40521 -246 190 14 246 190 14 242 186 14 163 133 67
40522 - 46 46 46 18 18 18 6 6 6 0 0 0
40523 - 0 0 0 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 0 0 0 0 0 0 0 0 0 10 10 10
40526 - 30 30 30 78 78 78 163 133 67 210 150 10
40527 -236 178 12 246 186 14 246 190 14 246 190 14
40528 -246 190 14 246 190 14 246 190 14 246 190 14
40529 -246 190 14 246 190 14 246 190 14 246 190 14
40530 -246 190 14 246 190 14 246 190 14 246 190 14
40531 -241 196 14 215 174 15 190 178 144 253 253 253
40532 -253 253 253 253 253 253 253 253 253 253 253 253
40533 -253 253 253 253 253 253 253 253 253 253 253 253
40534 -253 253 253 253 253 253 253 253 253 253 253 253
40535 -253 253 253 253 253 253 253 253 253 218 218 218
40536 - 58 58 58 2 2 6 22 18 6 167 114 7
40537 -216 158 10 236 178 12 246 186 14 246 190 14
40538 -246 190 14 246 190 14 246 190 14 246 190 14
40539 -246 190 14 246 190 14 246 190 14 246 190 14
40540 -246 190 14 246 190 14 246 190 14 246 190 14
40541 -246 190 14 246 186 14 242 186 14 190 150 46
40542 - 54 54 54 22 22 22 6 6 6 0 0 0
40543 - 0 0 0 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 0 0 0 14 14 14
40546 - 38 38 38 86 86 86 180 133 36 213 154 11
40547 -236 178 12 246 186 14 246 190 14 246 190 14
40548 -246 190 14 246 190 14 246 190 14 246 190 14
40549 -246 190 14 246 190 14 246 190 14 246 190 14
40550 -246 190 14 246 190 14 246 190 14 246 190 14
40551 -246 190 14 232 195 16 190 146 13 214 214 214
40552 -253 253 253 253 253 253 253 253 253 253 253 253
40553 -253 253 253 253 253 253 253 253 253 253 253 253
40554 -253 253 253 253 253 253 253 253 253 253 253 253
40555 -253 253 253 250 250 250 170 170 170 26 26 26
40556 - 2 2 6 2 2 6 37 26 9 163 110 8
40557 -219 162 10 239 182 13 246 186 14 246 190 14
40558 -246 190 14 246 190 14 246 190 14 246 190 14
40559 -246 190 14 246 190 14 246 190 14 246 190 14
40560 -246 190 14 246 190 14 246 190 14 246 190 14
40561 -246 186 14 236 178 12 224 166 10 142 122 72
40562 - 46 46 46 18 18 18 6 6 6 0 0 0
40563 - 0 0 0 0 0 0 0 0 0 0 0 0
40564 - 0 0 0 0 0 0 0 0 0 0 0 0
40565 - 0 0 0 0 0 0 6 6 6 18 18 18
40566 - 50 50 50 109 106 95 192 133 9 224 166 10
40567 -242 186 14 246 190 14 246 190 14 246 190 14
40568 -246 190 14 246 190 14 246 190 14 246 190 14
40569 -246 190 14 246 190 14 246 190 14 246 190 14
40570 -246 190 14 246 190 14 246 190 14 246 190 14
40571 -242 186 14 226 184 13 210 162 10 142 110 46
40572 -226 226 226 253 253 253 253 253 253 253 253 253
40573 -253 253 253 253 253 253 253 253 253 253 253 253
40574 -253 253 253 253 253 253 253 253 253 253 253 253
40575 -198 198 198 66 66 66 2 2 6 2 2 6
40576 - 2 2 6 2 2 6 50 34 6 156 107 11
40577 -219 162 10 239 182 13 246 186 14 246 190 14
40578 -246 190 14 246 190 14 246 190 14 246 190 14
40579 -246 190 14 246 190 14 246 190 14 246 190 14
40580 -246 190 14 246 190 14 246 190 14 242 186 14
40581 -234 174 13 213 154 11 154 122 46 66 66 66
40582 - 30 30 30 10 10 10 0 0 0 0 0 0
40583 - 0 0 0 0 0 0 0 0 0 0 0 0
40584 - 0 0 0 0 0 0 0 0 0 0 0 0
40585 - 0 0 0 0 0 0 6 6 6 22 22 22
40586 - 58 58 58 154 121 60 206 145 10 234 174 13
40587 -242 186 14 246 186 14 246 190 14 246 190 14
40588 -246 190 14 246 190 14 246 190 14 246 190 14
40589 -246 190 14 246 190 14 246 190 14 246 190 14
40590 -246 190 14 246 190 14 246 190 14 246 190 14
40591 -246 186 14 236 178 12 210 162 10 163 110 8
40592 - 61 42 6 138 138 138 218 218 218 250 250 250
40593 -253 253 253 253 253 253 253 253 253 250 250 250
40594 -242 242 242 210 210 210 144 144 144 66 66 66
40595 - 6 6 6 2 2 6 2 2 6 2 2 6
40596 - 2 2 6 2 2 6 61 42 6 163 110 8
40597 -216 158 10 236 178 12 246 190 14 246 190 14
40598 -246 190 14 246 190 14 246 190 14 246 190 14
40599 -246 190 14 246 190 14 246 190 14 246 190 14
40600 -246 190 14 239 182 13 230 174 11 216 158 10
40601 -190 142 34 124 112 88 70 70 70 38 38 38
40602 - 18 18 18 6 6 6 0 0 0 0 0 0
40603 - 0 0 0 0 0 0 0 0 0 0 0 0
40604 - 0 0 0 0 0 0 0 0 0 0 0 0
40605 - 0 0 0 0 0 0 6 6 6 22 22 22
40606 - 62 62 62 168 124 44 206 145 10 224 166 10
40607 -236 178 12 239 182 13 242 186 14 242 186 14
40608 -246 186 14 246 190 14 246 190 14 246 190 14
40609 -246 190 14 246 190 14 246 190 14 246 190 14
40610 -246 190 14 246 190 14 246 190 14 246 190 14
40611 -246 190 14 236 178 12 216 158 10 175 118 6
40612 - 80 54 7 2 2 6 6 6 6 30 30 30
40613 - 54 54 54 62 62 62 50 50 50 38 38 38
40614 - 14 14 14 2 2 6 2 2 6 2 2 6
40615 - 2 2 6 2 2 6 2 2 6 2 2 6
40616 - 2 2 6 6 6 6 80 54 7 167 114 7
40617 -213 154 11 236 178 12 246 190 14 246 190 14
40618 -246 190 14 246 190 14 246 190 14 246 190 14
40619 -246 190 14 242 186 14 239 182 13 239 182 13
40620 -230 174 11 210 150 10 174 135 50 124 112 88
40621 - 82 82 82 54 54 54 34 34 34 18 18 18
40622 - 6 6 6 0 0 0 0 0 0 0 0 0
40623 - 0 0 0 0 0 0 0 0 0 0 0 0
40624 - 0 0 0 0 0 0 0 0 0 0 0 0
40625 - 0 0 0 0 0 0 6 6 6 18 18 18
40626 - 50 50 50 158 118 36 192 133 9 200 144 11
40627 -216 158 10 219 162 10 224 166 10 226 170 11
40628 -230 174 11 236 178 12 239 182 13 239 182 13
40629 -242 186 14 246 186 14 246 190 14 246 190 14
40630 -246 190 14 246 190 14 246 190 14 246 190 14
40631 -246 186 14 230 174 11 210 150 10 163 110 8
40632 -104 69 6 10 10 10 2 2 6 2 2 6
40633 - 2 2 6 2 2 6 2 2 6 2 2 6
40634 - 2 2 6 2 2 6 2 2 6 2 2 6
40635 - 2 2 6 2 2 6 2 2 6 2 2 6
40636 - 2 2 6 6 6 6 91 60 6 167 114 7
40637 -206 145 10 230 174 11 242 186 14 246 190 14
40638 -246 190 14 246 190 14 246 186 14 242 186 14
40639 -239 182 13 230 174 11 224 166 10 213 154 11
40640 -180 133 36 124 112 88 86 86 86 58 58 58
40641 - 38 38 38 22 22 22 10 10 10 6 6 6
40642 - 0 0 0 0 0 0 0 0 0 0 0 0
40643 - 0 0 0 0 0 0 0 0 0 0 0 0
40644 - 0 0 0 0 0 0 0 0 0 0 0 0
40645 - 0 0 0 0 0 0 0 0 0 14 14 14
40646 - 34 34 34 70 70 70 138 110 50 158 118 36
40647 -167 114 7 180 123 7 192 133 9 197 138 11
40648 -200 144 11 206 145 10 213 154 11 219 162 10
40649 -224 166 10 230 174 11 239 182 13 242 186 14
40650 -246 186 14 246 186 14 246 186 14 246 186 14
40651 -239 182 13 216 158 10 185 133 11 152 99 6
40652 -104 69 6 18 14 6 2 2 6 2 2 6
40653 - 2 2 6 2 2 6 2 2 6 2 2 6
40654 - 2 2 6 2 2 6 2 2 6 2 2 6
40655 - 2 2 6 2 2 6 2 2 6 2 2 6
40656 - 2 2 6 6 6 6 80 54 7 152 99 6
40657 -192 133 9 219 162 10 236 178 12 239 182 13
40658 -246 186 14 242 186 14 239 182 13 236 178 12
40659 -224 166 10 206 145 10 192 133 9 154 121 60
40660 - 94 94 94 62 62 62 42 42 42 22 22 22
40661 - 14 14 14 6 6 6 0 0 0 0 0 0
40662 - 0 0 0 0 0 0 0 0 0 0 0 0
40663 - 0 0 0 0 0 0 0 0 0 0 0 0
40664 - 0 0 0 0 0 0 0 0 0 0 0 0
40665 - 0 0 0 0 0 0 0 0 0 6 6 6
40666 - 18 18 18 34 34 34 58 58 58 78 78 78
40667 -101 98 89 124 112 88 142 110 46 156 107 11
40668 -163 110 8 167 114 7 175 118 6 180 123 7
40669 -185 133 11 197 138 11 210 150 10 219 162 10
40670 -226 170 11 236 178 12 236 178 12 234 174 13
40671 -219 162 10 197 138 11 163 110 8 130 83 6
40672 - 91 60 6 10 10 10 2 2 6 2 2 6
40673 - 18 18 18 38 38 38 38 38 38 38 38 38
40674 - 38 38 38 38 38 38 38 38 38 38 38 38
40675 - 38 38 38 38 38 38 26 26 26 2 2 6
40676 - 2 2 6 6 6 6 70 47 6 137 92 6
40677 -175 118 6 200 144 11 219 162 10 230 174 11
40678 -234 174 13 230 174 11 219 162 10 210 150 10
40679 -192 133 9 163 110 8 124 112 88 82 82 82
40680 - 50 50 50 30 30 30 14 14 14 6 6 6
40681 - 0 0 0 0 0 0 0 0 0 0 0 0
40682 - 0 0 0 0 0 0 0 0 0 0 0 0
40683 - 0 0 0 0 0 0 0 0 0 0 0 0
40684 - 0 0 0 0 0 0 0 0 0 0 0 0
40685 - 0 0 0 0 0 0 0 0 0 0 0 0
40686 - 6 6 6 14 14 14 22 22 22 34 34 34
40687 - 42 42 42 58 58 58 74 74 74 86 86 86
40688 -101 98 89 122 102 70 130 98 46 121 87 25
40689 -137 92 6 152 99 6 163 110 8 180 123 7
40690 -185 133 11 197 138 11 206 145 10 200 144 11
40691 -180 123 7 156 107 11 130 83 6 104 69 6
40692 - 50 34 6 54 54 54 110 110 110 101 98 89
40693 - 86 86 86 82 82 82 78 78 78 78 78 78
40694 - 78 78 78 78 78 78 78 78 78 78 78 78
40695 - 78 78 78 82 82 82 86 86 86 94 94 94
40696 -106 106 106 101 101 101 86 66 34 124 80 6
40697 -156 107 11 180 123 7 192 133 9 200 144 11
40698 -206 145 10 200 144 11 192 133 9 175 118 6
40699 -139 102 15 109 106 95 70 70 70 42 42 42
40700 - 22 22 22 10 10 10 0 0 0 0 0 0
40701 - 0 0 0 0 0 0 0 0 0 0 0 0
40702 - 0 0 0 0 0 0 0 0 0 0 0 0
40703 - 0 0 0 0 0 0 0 0 0 0 0 0
40704 - 0 0 0 0 0 0 0 0 0 0 0 0
40705 - 0 0 0 0 0 0 0 0 0 0 0 0
40706 - 0 0 0 0 0 0 6 6 6 10 10 10
40707 - 14 14 14 22 22 22 30 30 30 38 38 38
40708 - 50 50 50 62 62 62 74 74 74 90 90 90
40709 -101 98 89 112 100 78 121 87 25 124 80 6
40710 -137 92 6 152 99 6 152 99 6 152 99 6
40711 -138 86 6 124 80 6 98 70 6 86 66 30
40712 -101 98 89 82 82 82 58 58 58 46 46 46
40713 - 38 38 38 34 34 34 34 34 34 34 34 34
40714 - 34 34 34 34 34 34 34 34 34 34 34 34
40715 - 34 34 34 34 34 34 38 38 38 42 42 42
40716 - 54 54 54 82 82 82 94 86 76 91 60 6
40717 -134 86 6 156 107 11 167 114 7 175 118 6
40718 -175 118 6 167 114 7 152 99 6 121 87 25
40719 -101 98 89 62 62 62 34 34 34 18 18 18
40720 - 6 6 6 0 0 0 0 0 0 0 0 0
40721 - 0 0 0 0 0 0 0 0 0 0 0 0
40722 - 0 0 0 0 0 0 0 0 0 0 0 0
40723 - 0 0 0 0 0 0 0 0 0 0 0 0
40724 - 0 0 0 0 0 0 0 0 0 0 0 0
40725 - 0 0 0 0 0 0 0 0 0 0 0 0
40726 - 0 0 0 0 0 0 0 0 0 0 0 0
40727 - 0 0 0 6 6 6 6 6 6 10 10 10
40728 - 18 18 18 22 22 22 30 30 30 42 42 42
40729 - 50 50 50 66 66 66 86 86 86 101 98 89
40730 -106 86 58 98 70 6 104 69 6 104 69 6
40731 -104 69 6 91 60 6 82 62 34 90 90 90
40732 - 62 62 62 38 38 38 22 22 22 14 14 14
40733 - 10 10 10 10 10 10 10 10 10 10 10 10
40734 - 10 10 10 10 10 10 6 6 6 10 10 10
40735 - 10 10 10 10 10 10 10 10 10 14 14 14
40736 - 22 22 22 42 42 42 70 70 70 89 81 66
40737 - 80 54 7 104 69 6 124 80 6 137 92 6
40738 -134 86 6 116 81 8 100 82 52 86 86 86
40739 - 58 58 58 30 30 30 14 14 14 6 6 6
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 0 0 0 0 0 0 0 0 0
40742 - 0 0 0 0 0 0 0 0 0 0 0 0
40743 - 0 0 0 0 0 0 0 0 0 0 0 0
40744 - 0 0 0 0 0 0 0 0 0 0 0 0
40745 - 0 0 0 0 0 0 0 0 0 0 0 0
40746 - 0 0 0 0 0 0 0 0 0 0 0 0
40747 - 0 0 0 0 0 0 0 0 0 0 0 0
40748 - 0 0 0 6 6 6 10 10 10 14 14 14
40749 - 18 18 18 26 26 26 38 38 38 54 54 54
40750 - 70 70 70 86 86 86 94 86 76 89 81 66
40751 - 89 81 66 86 86 86 74 74 74 50 50 50
40752 - 30 30 30 14 14 14 6 6 6 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 0 0 0
40754 - 0 0 0 0 0 0 0 0 0 0 0 0
40755 - 0 0 0 0 0 0 0 0 0 0 0 0
40756 - 6 6 6 18 18 18 34 34 34 58 58 58
40757 - 82 82 82 89 81 66 89 81 66 89 81 66
40758 - 94 86 66 94 86 76 74 74 74 50 50 50
40759 - 26 26 26 14 14 14 6 6 6 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 0 0 0
40761 - 0 0 0 0 0 0 0 0 0 0 0 0
40762 - 0 0 0 0 0 0 0 0 0 0 0 0
40763 - 0 0 0 0 0 0 0 0 0 0 0 0
40764 - 0 0 0 0 0 0 0 0 0 0 0 0
40765 - 0 0 0 0 0 0 0 0 0 0 0 0
40766 - 0 0 0 0 0 0 0 0 0 0 0 0
40767 - 0 0 0 0 0 0 0 0 0 0 0 0
40768 - 0 0 0 0 0 0 0 0 0 0 0 0
40769 - 6 6 6 6 6 6 14 14 14 18 18 18
40770 - 30 30 30 38 38 38 46 46 46 54 54 54
40771 - 50 50 50 42 42 42 30 30 30 18 18 18
40772 - 10 10 10 0 0 0 0 0 0 0 0 0
40773 - 0 0 0 0 0 0 0 0 0 0 0 0
40774 - 0 0 0 0 0 0 0 0 0 0 0 0
40775 - 0 0 0 0 0 0 0 0 0 0 0 0
40776 - 0 0 0 6 6 6 14 14 14 26 26 26
40777 - 38 38 38 50 50 50 58 58 58 58 58 58
40778 - 54 54 54 42 42 42 30 30 30 18 18 18
40779 - 10 10 10 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 0 0 0 0 0 0
40782 - 0 0 0 0 0 0 0 0 0 0 0 0
40783 - 0 0 0 0 0 0 0 0 0 0 0 0
40784 - 0 0 0 0 0 0 0 0 0 0 0 0
40785 - 0 0 0 0 0 0 0 0 0 0 0 0
40786 - 0 0 0 0 0 0 0 0 0 0 0 0
40787 - 0 0 0 0 0 0 0 0 0 0 0 0
40788 - 0 0 0 0 0 0 0 0 0 0 0 0
40789 - 0 0 0 0 0 0 0 0 0 6 6 6
40790 - 6 6 6 10 10 10 14 14 14 18 18 18
40791 - 18 18 18 14 14 14 10 10 10 6 6 6
40792 - 0 0 0 0 0 0 0 0 0 0 0 0
40793 - 0 0 0 0 0 0 0 0 0 0 0 0
40794 - 0 0 0 0 0 0 0 0 0 0 0 0
40795 - 0 0 0 0 0 0 0 0 0 0 0 0
40796 - 0 0 0 0 0 0 0 0 0 6 6 6
40797 - 14 14 14 18 18 18 22 22 22 22 22 22
40798 - 18 18 18 14 14 14 10 10 10 6 6 6
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 0 0 0
40801 - 0 0 0 0 0 0 0 0 0 0 0 0
40802 - 0 0 0 0 0 0 0 0 0 0 0 0
40803 - 0 0 0 0 0 0 0 0 0 0 0 0
40804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40808 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40817 +4 4 4 4 4 4
40818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40831 +4 4 4 4 4 4
40832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40845 +4 4 4 4 4 4
40846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40859 +4 4 4 4 4 4
40860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40873 +4 4 4 4 4 4
40874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40887 +4 4 4 4 4 4
40888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40892 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40893 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40897 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40898 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40899 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40901 +4 4 4 4 4 4
40902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40906 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40907 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40908 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40911 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40912 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40913 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40914 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40915 +4 4 4 4 4 4
40916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40920 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40921 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40922 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40925 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40926 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40927 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40928 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40929 +4 4 4 4 4 4
40930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40934 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40935 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40936 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40938 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40939 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40940 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40941 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40942 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40943 +4 4 4 4 4 4
40944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40947 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40948 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40949 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40950 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40951 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40952 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40953 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40954 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40955 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40956 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40957 +4 4 4 4 4 4
40958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40961 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40962 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40963 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40964 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40965 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40966 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40967 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40968 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40969 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40970 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40971 +4 4 4 4 4 4
40972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40974 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40975 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40976 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40977 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40978 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40979 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40980 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40981 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40982 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40983 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40984 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40985 +4 4 4 4 4 4
40986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40988 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40989 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40990 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40991 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40992 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40993 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40994 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40995 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40996 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40997 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40998 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40999 +4 4 4 4 4 4
41000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41002 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41003 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41004 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41005 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41006 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41007 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41008 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41009 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41010 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41011 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41012 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41013 +4 4 4 4 4 4
41014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41016 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41017 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41018 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41019 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41020 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41021 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41022 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41023 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41024 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41025 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41026 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41027 +4 4 4 4 4 4
41028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41029 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41030 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41031 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41032 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41033 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41034 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41035 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41036 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41037 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41038 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41039 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41040 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41041 +4 4 4 4 4 4
41042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41043 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41044 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41045 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41046 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41047 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41048 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41049 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41050 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41051 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41052 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41053 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41054 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41055 +0 0 0 4 4 4
41056 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41057 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41058 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41059 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41060 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41061 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41062 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41063 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41064 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41065 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41066 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41067 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41068 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41069 +2 0 0 0 0 0
41070 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41071 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41072 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41073 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41074 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41075 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41076 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41077 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41078 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41079 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41080 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41081 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41082 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41083 +37 38 37 0 0 0
41084 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41085 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41086 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41087 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41088 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41089 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41090 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41091 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41092 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41093 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41094 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41095 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41096 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41097 +85 115 134 4 0 0
41098 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41099 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41100 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41101 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41102 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41103 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41104 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41105 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41106 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41107 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41108 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41109 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41110 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41111 +60 73 81 4 0 0
41112 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41113 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41114 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41115 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41116 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41117 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41118 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41119 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41120 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41121 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41122 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41123 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41124 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41125 +16 19 21 4 0 0
41126 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41127 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41128 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41129 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41130 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41131 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41132 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41133 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41134 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41135 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41136 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41137 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41138 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41139 +4 0 0 4 3 3
41140 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41141 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41142 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41144 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41145 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41146 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41147 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41148 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41149 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41150 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41151 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41152 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41153 +3 2 2 4 4 4
41154 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41155 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41156 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41157 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41158 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41159 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41160 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41161 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41162 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41163 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41164 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41165 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41166 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41167 +4 4 4 4 4 4
41168 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41169 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41170 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41171 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41172 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41173 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41174 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41175 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41176 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41177 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41178 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41179 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41180 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41181 +4 4 4 4 4 4
41182 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41183 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41184 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41185 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41186 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41187 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41188 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41189 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41190 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41191 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41192 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41193 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41194 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41195 +5 5 5 5 5 5
41196 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41197 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41198 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41199 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41200 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41201 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41202 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41203 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41204 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41205 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41206 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41207 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41208 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41209 +5 5 5 4 4 4
41210 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41211 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41212 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41213 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41214 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41215 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41216 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41217 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41218 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41219 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41220 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41221 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4
41224 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41225 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41226 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41227 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41228 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41229 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41230 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41231 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41232 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41233 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41234 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41235 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4
41238 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41239 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41240 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41241 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41242 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41243 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41244 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41245 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41246 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41247 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41248 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4
41252 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41253 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41254 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41255 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41256 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41257 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41258 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41259 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41260 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41261 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41262 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4
41266 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41267 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41268 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41269 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41270 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41271 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41272 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41273 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41274 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41275 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41276 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4
41280 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41281 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41282 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41283 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41284 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41285 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41286 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41287 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41288 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41289 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41290 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4
41294 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41295 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41296 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41297 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41298 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41299 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41300 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41301 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41302 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41303 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41304 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4
41308 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41309 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41310 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41311 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41312 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41313 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41314 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41315 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41316 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41317 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41318 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4
41322 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41323 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41324 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41325 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41326 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41327 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41328 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41329 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41330 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41331 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41332 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4
41336 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41337 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41338 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41339 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41340 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41341 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41342 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41343 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41344 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41345 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41346 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4
41350 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41351 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41352 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41353 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41354 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41355 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41356 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41357 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41358 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41359 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41360 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4
41364 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41365 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41366 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41367 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41368 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41369 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41370 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41371 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41372 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41373 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41374 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4
41378 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41379 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41380 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41381 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41382 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41383 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41384 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41385 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41386 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41387 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41388 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41391 +4 4 4 4 4 4
41392 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41393 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41394 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41395 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41396 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41397 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41398 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41399 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41400 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41401 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41402 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4
41406 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41407 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41408 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41409 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41410 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41411 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41412 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41413 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41414 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41415 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41416 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4
41420 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41421 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41422 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41423 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41424 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41425 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41426 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41427 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41428 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41429 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41430 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41433 +4 4 4 4 4 4
41434 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41435 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41436 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41437 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41438 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41439 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41440 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41441 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41442 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41443 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41444 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4
41448 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41449 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41450 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41451 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41452 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41453 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41454 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41455 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41456 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41457 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41458 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41461 +4 4 4 4 4 4
41462 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41463 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41464 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41465 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41466 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41467 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41468 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41469 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41470 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41471 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41472 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4
41476 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41477 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41478 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41479 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41480 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41481 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41482 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41483 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41484 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41485 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41486 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 4 4 4
41490 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41491 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41492 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41493 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41494 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41495 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41496 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41497 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41498 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41499 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41500 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4
41504 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41505 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41506 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41507 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41508 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41509 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41510 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41511 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41512 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41513 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41514 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4
41518 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41519 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41520 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41521 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41522 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41523 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41524 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41525 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41526 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41527 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41528 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41531 +4 4 4 4 4 4
41532 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41533 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41534 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41535 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41536 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41537 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41538 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41539 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41540 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41541 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41542 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545 +4 4 4 4 4 4
41546 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41547 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41548 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41549 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41550 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41551 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41552 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41553 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41554 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41555 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41556 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4
41560 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41561 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41562 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41563 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41564 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41565 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41566 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41567 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41568 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41569 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41570 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573 +4 4 4 4 4 4
41574 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41575 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41576 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41577 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41578 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41579 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41580 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41581 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41582 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41583 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41584 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587 +4 4 4 4 4 4
41588 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41589 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41590 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41591 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41593 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41594 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41596 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41597 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41598 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601 +4 4 4 4 4 4
41602 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41603 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41604 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41605 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41606 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41607 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41608 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41609 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41610 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41611 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41612 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41615 +4 4 4 4 4 4
41616 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41617 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41618 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41619 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41620 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41621 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41622 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41623 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41624 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41625 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41629 +4 4 4 4 4 4
41630 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41631 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41632 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41633 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41634 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41635 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41636 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41637 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41638 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41639 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41643 +4 4 4 4 4 4
41644 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41645 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41646 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41647 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41648 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41649 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41650 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41651 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41652 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41653 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41657 +4 4 4 4 4 4
41658 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41659 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41660 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41661 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41662 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41663 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41664 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41665 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41666 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41667 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41671 +4 4 4 4 4 4
41672 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41673 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41674 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41675 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41676 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41677 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41678 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41679 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41680 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685 +4 4 4 4 4 4
41686 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41687 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41688 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41689 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41690 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41691 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41692 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41693 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41694 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41699 +4 4 4 4 4 4
41700 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41701 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41702 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41703 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41704 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41705 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41706 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41707 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41708 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41713 +4 4 4 4 4 4
41714 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41715 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41716 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41717 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41718 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41719 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41720 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41721 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727 +4 4 4 4 4 4
41728 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41729 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41730 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41731 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41732 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41733 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41734 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41735 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741 +4 4 4 4 4 4
41742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41743 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41744 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41745 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41746 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41747 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41748 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41749 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755 +4 4 4 4 4 4
41756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41757 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41758 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41759 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41760 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41761 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41762 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41763 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769 +4 4 4 4 4 4
41770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41772 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41773 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41774 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41775 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41776 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41777 +5 5 5 5 5 5 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 4 4 4 4 4 4
41780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41783 +4 4 4 4 4 4
41784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41787 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41788 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41789 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41790 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41791 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41797 +4 4 4 4 4 4
41798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41801 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41802 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41803 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41804 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811 +4 4 4 4 4 4
41812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41816 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41817 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41818 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41825 +4 4 4 4 4 4
41826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41830 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41831 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41832 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41839 +4 4 4 4 4 4
41840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41844 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41845 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41846 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41853 +4 4 4 4 4 4
41854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41858 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41859 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41860 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41867 +4 4 4 4 4 4
41868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41873 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41874 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41881 +4 4 4 4 4 4
41882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41887 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41888 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41895 +4 4 4 4 4 4
41896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41901 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41909 +4 4 4 4 4 4
41910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41915 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41923 +4 4 4 4 4 4
41924 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41925 index 8af6414..658c030 100644
41926 --- a/drivers/video/udlfb.c
41927 +++ b/drivers/video/udlfb.c
41928 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41929 dlfb_urb_completion(urb);
41930
41931 error:
41932 - atomic_add(bytes_sent, &dev->bytes_sent);
41933 - atomic_add(bytes_identical, &dev->bytes_identical);
41934 - atomic_add(width*height*2, &dev->bytes_rendered);
41935 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41936 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41937 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41938 end_cycles = get_cycles();
41939 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41940 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41941 >> 10)), /* Kcycles */
41942 &dev->cpu_kcycles_used);
41943
41944 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41945 dlfb_urb_completion(urb);
41946
41947 error:
41948 - atomic_add(bytes_sent, &dev->bytes_sent);
41949 - atomic_add(bytes_identical, &dev->bytes_identical);
41950 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41951 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41952 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41953 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41954 end_cycles = get_cycles();
41955 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41956 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41957 >> 10)), /* Kcycles */
41958 &dev->cpu_kcycles_used);
41959 }
41960 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41961 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41962 struct dlfb_data *dev = fb_info->par;
41963 return snprintf(buf, PAGE_SIZE, "%u\n",
41964 - atomic_read(&dev->bytes_rendered));
41965 + atomic_read_unchecked(&dev->bytes_rendered));
41966 }
41967
41968 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41969 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41970 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41971 struct dlfb_data *dev = fb_info->par;
41972 return snprintf(buf, PAGE_SIZE, "%u\n",
41973 - atomic_read(&dev->bytes_identical));
41974 + atomic_read_unchecked(&dev->bytes_identical));
41975 }
41976
41977 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41978 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41979 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41980 struct dlfb_data *dev = fb_info->par;
41981 return snprintf(buf, PAGE_SIZE, "%u\n",
41982 - atomic_read(&dev->bytes_sent));
41983 + atomic_read_unchecked(&dev->bytes_sent));
41984 }
41985
41986 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41987 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41988 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41989 struct dlfb_data *dev = fb_info->par;
41990 return snprintf(buf, PAGE_SIZE, "%u\n",
41991 - atomic_read(&dev->cpu_kcycles_used));
41992 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41993 }
41994
41995 static ssize_t edid_show(
41996 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41997 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41998 struct dlfb_data *dev = fb_info->par;
41999
42000 - atomic_set(&dev->bytes_rendered, 0);
42001 - atomic_set(&dev->bytes_identical, 0);
42002 - atomic_set(&dev->bytes_sent, 0);
42003 - atomic_set(&dev->cpu_kcycles_used, 0);
42004 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42005 + atomic_set_unchecked(&dev->bytes_identical, 0);
42006 + atomic_set_unchecked(&dev->bytes_sent, 0);
42007 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42008
42009 return count;
42010 }
42011 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42012 index b0e2a42..e2df3ad 100644
42013 --- a/drivers/video/uvesafb.c
42014 +++ b/drivers/video/uvesafb.c
42015 @@ -19,6 +19,7 @@
42016 #include <linux/io.h>
42017 #include <linux/mutex.h>
42018 #include <linux/slab.h>
42019 +#include <linux/moduleloader.h>
42020 #include <video/edid.h>
42021 #include <video/uvesafb.h>
42022 #ifdef CONFIG_X86
42023 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42024 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42025 par->pmi_setpal = par->ypan = 0;
42026 } else {
42027 +
42028 +#ifdef CONFIG_PAX_KERNEXEC
42029 +#ifdef CONFIG_MODULES
42030 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42031 +#endif
42032 + if (!par->pmi_code) {
42033 + par->pmi_setpal = par->ypan = 0;
42034 + return 0;
42035 + }
42036 +#endif
42037 +
42038 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42039 + task->t.regs.edi);
42040 +
42041 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42042 + pax_open_kernel();
42043 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42044 + pax_close_kernel();
42045 +
42046 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42047 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42048 +#else
42049 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42050 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42051 +#endif
42052 +
42053 printk(KERN_INFO "uvesafb: protected mode interface info at "
42054 "%04x:%04x\n",
42055 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42056 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42057 par->ypan = ypan;
42058
42059 if (par->pmi_setpal || par->ypan) {
42060 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42061 if (__supported_pte_mask & _PAGE_NX) {
42062 par->pmi_setpal = par->ypan = 0;
42063 printk(KERN_WARNING "uvesafb: NX protection is actively."
42064 "We have better not to use the PMI.\n");
42065 - } else {
42066 + } else
42067 +#endif
42068 uvesafb_vbe_getpmi(task, par);
42069 - }
42070 }
42071 #else
42072 /* The protected mode interface is not available on non-x86. */
42073 @@ -1836,6 +1860,11 @@ out:
42074 if (par->vbe_modes)
42075 kfree(par->vbe_modes);
42076
42077 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42078 + if (par->pmi_code)
42079 + module_free_exec(NULL, par->pmi_code);
42080 +#endif
42081 +
42082 framebuffer_release(info);
42083 return err;
42084 }
42085 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42086 kfree(par->vbe_state_orig);
42087 if (par->vbe_state_saved)
42088 kfree(par->vbe_state_saved);
42089 +
42090 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42091 + if (par->pmi_code)
42092 + module_free_exec(NULL, par->pmi_code);
42093 +#endif
42094 +
42095 }
42096
42097 framebuffer_release(info);
42098 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42099 index 501b340..86bd4cf 100644
42100 --- a/drivers/video/vesafb.c
42101 +++ b/drivers/video/vesafb.c
42102 @@ -9,6 +9,7 @@
42103 */
42104
42105 #include <linux/module.h>
42106 +#include <linux/moduleloader.h>
42107 #include <linux/kernel.h>
42108 #include <linux/errno.h>
42109 #include <linux/string.h>
42110 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42111 static int vram_total __initdata; /* Set total amount of memory */
42112 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42113 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42114 -static void (*pmi_start)(void) __read_mostly;
42115 -static void (*pmi_pal) (void) __read_mostly;
42116 +static void (*pmi_start)(void) __read_only;
42117 +static void (*pmi_pal) (void) __read_only;
42118 static int depth __read_mostly;
42119 static int vga_compat __read_mostly;
42120 /* --------------------------------------------------------------------- */
42121 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42122 unsigned int size_vmode;
42123 unsigned int size_remap;
42124 unsigned int size_total;
42125 + void *pmi_code = NULL;
42126
42127 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42128 return -ENODEV;
42129 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42130 size_remap = size_total;
42131 vesafb_fix.smem_len = size_remap;
42132
42133 -#ifndef __i386__
42134 - screen_info.vesapm_seg = 0;
42135 -#endif
42136 -
42137 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42138 printk(KERN_WARNING
42139 "vesafb: cannot reserve video memory at 0x%lx\n",
42140 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42141 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42142 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42143
42144 +#ifdef __i386__
42145 +
42146 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42147 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42148 + if (!pmi_code)
42149 +#elif !defined(CONFIG_PAX_KERNEXEC)
42150 + if (0)
42151 +#endif
42152 +
42153 +#endif
42154 + screen_info.vesapm_seg = 0;
42155 +
42156 if (screen_info.vesapm_seg) {
42157 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42158 - screen_info.vesapm_seg,screen_info.vesapm_off);
42159 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42160 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42161 }
42162
42163 if (screen_info.vesapm_seg < 0xc000)
42164 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42165
42166 if (ypan || pmi_setpal) {
42167 unsigned short *pmi_base;
42168 +
42169 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42170 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42171 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42172 +
42173 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42174 + pax_open_kernel();
42175 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42176 +#else
42177 + pmi_code = pmi_base;
42178 +#endif
42179 +
42180 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42181 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42182 +
42183 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42184 + pmi_start = ktva_ktla(pmi_start);
42185 + pmi_pal = ktva_ktla(pmi_pal);
42186 + pax_close_kernel();
42187 +#endif
42188 +
42189 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42190 if (pmi_base[3]) {
42191 printk(KERN_INFO "vesafb: pmi: ports = ");
42192 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42193 info->node, info->fix.id);
42194 return 0;
42195 err:
42196 +
42197 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42198 + module_free_exec(NULL, pmi_code);
42199 +#endif
42200 +
42201 if (info->screen_base)
42202 iounmap(info->screen_base);
42203 framebuffer_release(info);
42204 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42205 index 88714ae..16c2e11 100644
42206 --- a/drivers/video/via/via_clock.h
42207 +++ b/drivers/video/via/via_clock.h
42208 @@ -56,7 +56,7 @@ struct via_clock {
42209
42210 void (*set_engine_pll_state)(u8 state);
42211 void (*set_engine_pll)(struct via_pll_config config);
42212 -};
42213 +} __no_const;
42214
42215
42216 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42217 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42218 index e56c934..fc22f4b 100644
42219 --- a/drivers/xen/xen-pciback/conf_space.h
42220 +++ b/drivers/xen/xen-pciback/conf_space.h
42221 @@ -44,15 +44,15 @@ struct config_field {
42222 struct {
42223 conf_dword_write write;
42224 conf_dword_read read;
42225 - } dw;
42226 + } __no_const dw;
42227 struct {
42228 conf_word_write write;
42229 conf_word_read read;
42230 - } w;
42231 + } __no_const w;
42232 struct {
42233 conf_byte_write write;
42234 conf_byte_read read;
42235 - } b;
42236 + } __no_const b;
42237 } u;
42238 struct list_head list;
42239 };
42240 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42241 index 57ccb75..f6d05f8 100644
42242 --- a/fs/9p/vfs_inode.c
42243 +++ b/fs/9p/vfs_inode.c
42244 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42245 void
42246 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42247 {
42248 - char *s = nd_get_link(nd);
42249 + const char *s = nd_get_link(nd);
42250
42251 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42252 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42253 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42254 index 0225742..1cd4732 100644
42255 --- a/fs/Kconfig.binfmt
42256 +++ b/fs/Kconfig.binfmt
42257 @@ -89,7 +89,7 @@ config HAVE_AOUT
42258
42259 config BINFMT_AOUT
42260 tristate "Kernel support for a.out and ECOFF binaries"
42261 - depends on HAVE_AOUT
42262 + depends on HAVE_AOUT && BROKEN
42263 ---help---
42264 A.out (Assembler.OUTput) is a set of formats for libraries and
42265 executables used in the earliest versions of UNIX. Linux used
42266 diff --git a/fs/aio.c b/fs/aio.c
42267 index 55c4c76..11aee6f 100644
42268 --- a/fs/aio.c
42269 +++ b/fs/aio.c
42270 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42271 size += sizeof(struct io_event) * nr_events;
42272 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42273
42274 - if (nr_pages < 0)
42275 + if (nr_pages <= 0)
42276 return -EINVAL;
42277
42278 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42279 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42280 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42281 {
42282 ssize_t ret;
42283 + struct iovec iovstack;
42284
42285 #ifdef CONFIG_COMPAT
42286 if (compat)
42287 ret = compat_rw_copy_check_uvector(type,
42288 (struct compat_iovec __user *)kiocb->ki_buf,
42289 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42290 + kiocb->ki_nbytes, 1, &iovstack,
42291 &kiocb->ki_iovec);
42292 else
42293 #endif
42294 ret = rw_copy_check_uvector(type,
42295 (struct iovec __user *)kiocb->ki_buf,
42296 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42297 + kiocb->ki_nbytes, 1, &iovstack,
42298 &kiocb->ki_iovec);
42299 if (ret < 0)
42300 goto out;
42301 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42302 if (ret < 0)
42303 goto out;
42304
42305 + if (kiocb->ki_iovec == &iovstack) {
42306 + kiocb->ki_inline_vec = iovstack;
42307 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42308 + }
42309 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42310 kiocb->ki_cur_seg = 0;
42311 /* ki_nbytes/left now reflect bytes instead of segs */
42312 diff --git a/fs/attr.c b/fs/attr.c
42313 index 0da9095..1386693 100644
42314 --- a/fs/attr.c
42315 +++ b/fs/attr.c
42316 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42317 unsigned long limit;
42318
42319 limit = rlimit(RLIMIT_FSIZE);
42320 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42321 if (limit != RLIM_INFINITY && offset > limit)
42322 goto out_sig;
42323 if (offset > inode->i_sb->s_maxbytes)
42324 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42325 index da8876d..4456166 100644
42326 --- a/fs/autofs4/waitq.c
42327 +++ b/fs/autofs4/waitq.c
42328 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42329 {
42330 unsigned long sigpipe, flags;
42331 mm_segment_t fs;
42332 - const char *data = (const char *)addr;
42333 + const char __user *data = (const char __force_user *)addr;
42334 ssize_t wr = 0;
42335
42336 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42337 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42338 return 1;
42339 }
42340
42341 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42342 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42343 +#endif
42344 +
42345 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42346 enum autofs_notify notify)
42347 {
42348 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42349
42350 /* If this is a direct mount request create a dummy name */
42351 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42352 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42353 + /* this name does get written to userland via autofs4_write() */
42354 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42355 +#else
42356 qstr.len = sprintf(name, "%p", dentry);
42357 +#endif
42358 else {
42359 qstr.len = autofs4_getpath(sbi, dentry, &name);
42360 if (!qstr.len) {
42361 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42362 index e18da23..affc30e 100644
42363 --- a/fs/befs/linuxvfs.c
42364 +++ b/fs/befs/linuxvfs.c
42365 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42366 {
42367 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42368 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42369 - char *link = nd_get_link(nd);
42370 + const char *link = nd_get_link(nd);
42371 if (!IS_ERR(link))
42372 kfree(link);
42373 }
42374 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42375 index d146e18..12d1bd1 100644
42376 --- a/fs/binfmt_aout.c
42377 +++ b/fs/binfmt_aout.c
42378 @@ -16,6 +16,7 @@
42379 #include <linux/string.h>
42380 #include <linux/fs.h>
42381 #include <linux/file.h>
42382 +#include <linux/security.h>
42383 #include <linux/stat.h>
42384 #include <linux/fcntl.h>
42385 #include <linux/ptrace.h>
42386 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42387 #endif
42388 # define START_STACK(u) ((void __user *)u.start_stack)
42389
42390 + memset(&dump, 0, sizeof(dump));
42391 +
42392 fs = get_fs();
42393 set_fs(KERNEL_DS);
42394 has_dumped = 1;
42395 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42396
42397 /* If the size of the dump file exceeds the rlimit, then see what would happen
42398 if we wrote the stack, but not the data area. */
42399 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42400 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42401 dump.u_dsize = 0;
42402
42403 /* Make sure we have enough room to write the stack and data areas. */
42404 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42405 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42406 dump.u_ssize = 0;
42407
42408 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42409 rlim = rlimit(RLIMIT_DATA);
42410 if (rlim >= RLIM_INFINITY)
42411 rlim = ~0;
42412 +
42413 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42414 if (ex.a_data + ex.a_bss > rlim)
42415 return -ENOMEM;
42416
42417 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42418
42419 install_exec_creds(bprm);
42420
42421 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42422 + current->mm->pax_flags = 0UL;
42423 +#endif
42424 +
42425 +#ifdef CONFIG_PAX_PAGEEXEC
42426 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42427 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42428 +
42429 +#ifdef CONFIG_PAX_EMUTRAMP
42430 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42431 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42432 +#endif
42433 +
42434 +#ifdef CONFIG_PAX_MPROTECT
42435 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42436 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42437 +#endif
42438 +
42439 + }
42440 +#endif
42441 +
42442 if (N_MAGIC(ex) == OMAGIC) {
42443 unsigned long text_addr, map_size;
42444 loff_t pos;
42445 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42446 }
42447
42448 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42449 - PROT_READ | PROT_WRITE | PROT_EXEC,
42450 + PROT_READ | PROT_WRITE,
42451 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42452 fd_offset + ex.a_text);
42453 if (error != N_DATADDR(ex)) {
42454 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42455 index 1b52956..271266e 100644
42456 --- a/fs/binfmt_elf.c
42457 +++ b/fs/binfmt_elf.c
42458 @@ -32,6 +32,7 @@
42459 #include <linux/elf.h>
42460 #include <linux/utsname.h>
42461 #include <linux/coredump.h>
42462 +#include <linux/xattr.h>
42463 #include <asm/uaccess.h>
42464 #include <asm/param.h>
42465 #include <asm/page.h>
42466 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42467 #define elf_core_dump NULL
42468 #endif
42469
42470 +#ifdef CONFIG_PAX_MPROTECT
42471 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42472 +#endif
42473 +
42474 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42475 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42476 #else
42477 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42478 .load_binary = load_elf_binary,
42479 .load_shlib = load_elf_library,
42480 .core_dump = elf_core_dump,
42481 +
42482 +#ifdef CONFIG_PAX_MPROTECT
42483 + .handle_mprotect= elf_handle_mprotect,
42484 +#endif
42485 +
42486 .min_coredump = ELF_EXEC_PAGESIZE,
42487 };
42488
42489 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42490
42491 static int set_brk(unsigned long start, unsigned long end)
42492 {
42493 + unsigned long e = end;
42494 +
42495 start = ELF_PAGEALIGN(start);
42496 end = ELF_PAGEALIGN(end);
42497 if (end > start) {
42498 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42499 if (BAD_ADDR(addr))
42500 return addr;
42501 }
42502 - current->mm->start_brk = current->mm->brk = end;
42503 + current->mm->start_brk = current->mm->brk = e;
42504 return 0;
42505 }
42506
42507 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42508 elf_addr_t __user *u_rand_bytes;
42509 const char *k_platform = ELF_PLATFORM;
42510 const char *k_base_platform = ELF_BASE_PLATFORM;
42511 - unsigned char k_rand_bytes[16];
42512 + u32 k_rand_bytes[4];
42513 int items;
42514 elf_addr_t *elf_info;
42515 int ei_index = 0;
42516 const struct cred *cred = current_cred();
42517 struct vm_area_struct *vma;
42518 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42519
42520 /*
42521 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42522 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42523 * Generate 16 random bytes for userspace PRNG seeding.
42524 */
42525 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42526 - u_rand_bytes = (elf_addr_t __user *)
42527 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42528 + srandom32(k_rand_bytes[0] ^ random32());
42529 + srandom32(k_rand_bytes[1] ^ random32());
42530 + srandom32(k_rand_bytes[2] ^ random32());
42531 + srandom32(k_rand_bytes[3] ^ random32());
42532 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42533 + u_rand_bytes = (elf_addr_t __user *) p;
42534 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42535 return -EFAULT;
42536
42537 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42538 return -EFAULT;
42539 current->mm->env_end = p;
42540
42541 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42542 +
42543 /* Put the elf_info on the stack in the right place. */
42544 sp = (elf_addr_t __user *)envp + 1;
42545 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42546 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42547 return -EFAULT;
42548 return 0;
42549 }
42550 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42551 {
42552 struct elf_phdr *elf_phdata;
42553 struct elf_phdr *eppnt;
42554 - unsigned long load_addr = 0;
42555 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42556 int load_addr_set = 0;
42557 unsigned long last_bss = 0, elf_bss = 0;
42558 - unsigned long error = ~0UL;
42559 + unsigned long error = -EINVAL;
42560 unsigned long total_size;
42561 int retval, i, size;
42562
42563 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42564 goto out_close;
42565 }
42566
42567 +#ifdef CONFIG_PAX_SEGMEXEC
42568 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42569 + pax_task_size = SEGMEXEC_TASK_SIZE;
42570 +#endif
42571 +
42572 eppnt = elf_phdata;
42573 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42574 if (eppnt->p_type == PT_LOAD) {
42575 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42576 k = load_addr + eppnt->p_vaddr;
42577 if (BAD_ADDR(k) ||
42578 eppnt->p_filesz > eppnt->p_memsz ||
42579 - eppnt->p_memsz > TASK_SIZE ||
42580 - TASK_SIZE - eppnt->p_memsz < k) {
42581 + eppnt->p_memsz > pax_task_size ||
42582 + pax_task_size - eppnt->p_memsz < k) {
42583 error = -ENOMEM;
42584 goto out_close;
42585 }
42586 @@ -523,6 +547,311 @@ out:
42587 return error;
42588 }
42589
42590 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42591 +#ifdef CONFIG_PAX_SOFTMODE
42592 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42593 +{
42594 + unsigned long pax_flags = 0UL;
42595 +
42596 +#ifdef CONFIG_PAX_PAGEEXEC
42597 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42598 + pax_flags |= MF_PAX_PAGEEXEC;
42599 +#endif
42600 +
42601 +#ifdef CONFIG_PAX_SEGMEXEC
42602 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42603 + pax_flags |= MF_PAX_SEGMEXEC;
42604 +#endif
42605 +
42606 +#ifdef CONFIG_PAX_EMUTRAMP
42607 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42608 + pax_flags |= MF_PAX_EMUTRAMP;
42609 +#endif
42610 +
42611 +#ifdef CONFIG_PAX_MPROTECT
42612 + if (elf_phdata->p_flags & PF_MPROTECT)
42613 + pax_flags |= MF_PAX_MPROTECT;
42614 +#endif
42615 +
42616 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42617 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42618 + pax_flags |= MF_PAX_RANDMMAP;
42619 +#endif
42620 +
42621 + return pax_flags;
42622 +}
42623 +#endif
42624 +
42625 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42626 +{
42627 + unsigned long pax_flags = 0UL;
42628 +
42629 +#ifdef CONFIG_PAX_PAGEEXEC
42630 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42631 + pax_flags |= MF_PAX_PAGEEXEC;
42632 +#endif
42633 +
42634 +#ifdef CONFIG_PAX_SEGMEXEC
42635 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42636 + pax_flags |= MF_PAX_SEGMEXEC;
42637 +#endif
42638 +
42639 +#ifdef CONFIG_PAX_EMUTRAMP
42640 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42641 + pax_flags |= MF_PAX_EMUTRAMP;
42642 +#endif
42643 +
42644 +#ifdef CONFIG_PAX_MPROTECT
42645 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42646 + pax_flags |= MF_PAX_MPROTECT;
42647 +#endif
42648 +
42649 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42650 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42651 + pax_flags |= MF_PAX_RANDMMAP;
42652 +#endif
42653 +
42654 + return pax_flags;
42655 +}
42656 +#endif
42657 +
42658 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42659 +#ifdef CONFIG_PAX_SOFTMODE
42660 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42661 +{
42662 + unsigned long pax_flags = 0UL;
42663 +
42664 +#ifdef CONFIG_PAX_PAGEEXEC
42665 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42666 + pax_flags |= MF_PAX_PAGEEXEC;
42667 +#endif
42668 +
42669 +#ifdef CONFIG_PAX_SEGMEXEC
42670 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42671 + pax_flags |= MF_PAX_SEGMEXEC;
42672 +#endif
42673 +
42674 +#ifdef CONFIG_PAX_EMUTRAMP
42675 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42676 + pax_flags |= MF_PAX_EMUTRAMP;
42677 +#endif
42678 +
42679 +#ifdef CONFIG_PAX_MPROTECT
42680 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42681 + pax_flags |= MF_PAX_MPROTECT;
42682 +#endif
42683 +
42684 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42685 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42686 + pax_flags |= MF_PAX_RANDMMAP;
42687 +#endif
42688 +
42689 + return pax_flags;
42690 +}
42691 +#endif
42692 +
42693 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42694 +{
42695 + unsigned long pax_flags = 0UL;
42696 +
42697 +#ifdef CONFIG_PAX_PAGEEXEC
42698 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42699 + pax_flags |= MF_PAX_PAGEEXEC;
42700 +#endif
42701 +
42702 +#ifdef CONFIG_PAX_SEGMEXEC
42703 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42704 + pax_flags |= MF_PAX_SEGMEXEC;
42705 +#endif
42706 +
42707 +#ifdef CONFIG_PAX_EMUTRAMP
42708 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42709 + pax_flags |= MF_PAX_EMUTRAMP;
42710 +#endif
42711 +
42712 +#ifdef CONFIG_PAX_MPROTECT
42713 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42714 + pax_flags |= MF_PAX_MPROTECT;
42715 +#endif
42716 +
42717 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42718 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42719 + pax_flags |= MF_PAX_RANDMMAP;
42720 +#endif
42721 +
42722 + return pax_flags;
42723 +}
42724 +#endif
42725 +
42726 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42727 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42728 +{
42729 + unsigned long pax_flags = 0UL;
42730 +
42731 +#ifdef CONFIG_PAX_EI_PAX
42732 +
42733 +#ifdef CONFIG_PAX_PAGEEXEC
42734 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42735 + pax_flags |= MF_PAX_PAGEEXEC;
42736 +#endif
42737 +
42738 +#ifdef CONFIG_PAX_SEGMEXEC
42739 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42740 + pax_flags |= MF_PAX_SEGMEXEC;
42741 +#endif
42742 +
42743 +#ifdef CONFIG_PAX_EMUTRAMP
42744 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42745 + pax_flags |= MF_PAX_EMUTRAMP;
42746 +#endif
42747 +
42748 +#ifdef CONFIG_PAX_MPROTECT
42749 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42750 + pax_flags |= MF_PAX_MPROTECT;
42751 +#endif
42752 +
42753 +#ifdef CONFIG_PAX_ASLR
42754 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42755 + pax_flags |= MF_PAX_RANDMMAP;
42756 +#endif
42757 +
42758 +#else
42759 +
42760 +#ifdef CONFIG_PAX_PAGEEXEC
42761 + pax_flags |= MF_PAX_PAGEEXEC;
42762 +#endif
42763 +
42764 +#ifdef CONFIG_PAX_SEGMEXEC
42765 + pax_flags |= MF_PAX_SEGMEXEC;
42766 +#endif
42767 +
42768 +#ifdef CONFIG_PAX_MPROTECT
42769 + pax_flags |= MF_PAX_MPROTECT;
42770 +#endif
42771 +
42772 +#ifdef CONFIG_PAX_RANDMMAP
42773 + if (randomize_va_space)
42774 + pax_flags |= MF_PAX_RANDMMAP;
42775 +#endif
42776 +
42777 +#endif
42778 +
42779 + return pax_flags;
42780 +}
42781 +
42782 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42783 +{
42784 +
42785 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42786 + unsigned long i;
42787 +
42788 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42789 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42790 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42791 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42792 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42793 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42794 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42795 + return ~0UL;
42796 +
42797 +#ifdef CONFIG_PAX_SOFTMODE
42798 + if (pax_softmode)
42799 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42800 + else
42801 +#endif
42802 +
42803 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42804 + break;
42805 + }
42806 +#endif
42807 +
42808 + return ~0UL;
42809 +}
42810 +
42811 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42812 +{
42813 +
42814 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42815 + ssize_t xattr_size, i;
42816 + unsigned char xattr_value[5];
42817 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42818 +
42819 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42820 + if (xattr_size <= 0)
42821 + return ~0UL;
42822 +
42823 + for (i = 0; i < xattr_size; i++)
42824 + switch (xattr_value[i]) {
42825 + default:
42826 + return ~0UL;
42827 +
42828 +#define parse_flag(option1, option2, flag) \
42829 + case option1: \
42830 + pax_flags_hardmode |= MF_PAX_##flag; \
42831 + break; \
42832 + case option2: \
42833 + pax_flags_softmode |= MF_PAX_##flag; \
42834 + break;
42835 +
42836 + parse_flag('p', 'P', PAGEEXEC);
42837 + parse_flag('e', 'E', EMUTRAMP);
42838 + parse_flag('m', 'M', MPROTECT);
42839 + parse_flag('r', 'R', RANDMMAP);
42840 + parse_flag('s', 'S', SEGMEXEC);
42841 +
42842 +#undef parse_flag
42843 + }
42844 +
42845 + if (pax_flags_hardmode & pax_flags_softmode)
42846 + return ~0UL;
42847 +
42848 +#ifdef CONFIG_PAX_SOFTMODE
42849 + if (pax_softmode)
42850 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42851 + else
42852 +#endif
42853 +
42854 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42855 +#else
42856 + return ~0UL;
42857 +#endif
42858 +
42859 +}
42860 +
42861 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42862 +{
42863 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42864 +
42865 + pax_flags = pax_parse_ei_pax(elf_ex);
42866 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42867 + xattr_pax_flags = pax_parse_xattr_pax(file);
42868 +
42869 + if (pt_pax_flags == ~0UL)
42870 + pt_pax_flags = xattr_pax_flags;
42871 + else if (xattr_pax_flags == ~0UL)
42872 + xattr_pax_flags = pt_pax_flags;
42873 + if (pt_pax_flags != xattr_pax_flags)
42874 + return -EINVAL;
42875 + if (pt_pax_flags != ~0UL)
42876 + pax_flags = pt_pax_flags;
42877 +
42878 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42879 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42880 + if ((__supported_pte_mask & _PAGE_NX))
42881 + pax_flags &= ~MF_PAX_SEGMEXEC;
42882 + else
42883 + pax_flags &= ~MF_PAX_PAGEEXEC;
42884 + }
42885 +#endif
42886 +
42887 + if (0 > pax_check_flags(&pax_flags))
42888 + return -EINVAL;
42889 +
42890 + current->mm->pax_flags = pax_flags;
42891 + return 0;
42892 +}
42893 +#endif
42894 +
42895 /*
42896 * These are the functions used to load ELF style executables and shared
42897 * libraries. There is no binary dependent code anywhere else.
42898 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42899 {
42900 unsigned int random_variable = 0;
42901
42902 +#ifdef CONFIG_PAX_RANDUSTACK
42903 + if (randomize_va_space)
42904 + return stack_top - current->mm->delta_stack;
42905 +#endif
42906 +
42907 if ((current->flags & PF_RANDOMIZE) &&
42908 !(current->personality & ADDR_NO_RANDOMIZE)) {
42909 random_variable = get_random_int() & STACK_RND_MASK;
42910 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42911 unsigned long load_addr = 0, load_bias = 0;
42912 int load_addr_set = 0;
42913 char * elf_interpreter = NULL;
42914 - unsigned long error;
42915 + unsigned long error = 0;
42916 struct elf_phdr *elf_ppnt, *elf_phdata;
42917 unsigned long elf_bss, elf_brk;
42918 int retval, i;
42919 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42920 unsigned long start_code, end_code, start_data, end_data;
42921 unsigned long reloc_func_desc __maybe_unused = 0;
42922 int executable_stack = EXSTACK_DEFAULT;
42923 - unsigned long def_flags = 0;
42924 struct {
42925 struct elfhdr elf_ex;
42926 struct elfhdr interp_elf_ex;
42927 } *loc;
42928 + unsigned long pax_task_size = TASK_SIZE;
42929
42930 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42931 if (!loc) {
42932 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42933 goto out_free_dentry;
42934
42935 /* OK, This is the point of no return */
42936 - current->mm->def_flags = def_flags;
42937 +
42938 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42939 + current->mm->pax_flags = 0UL;
42940 +#endif
42941 +
42942 +#ifdef CONFIG_PAX_DLRESOLVE
42943 + current->mm->call_dl_resolve = 0UL;
42944 +#endif
42945 +
42946 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42947 + current->mm->call_syscall = 0UL;
42948 +#endif
42949 +
42950 +#ifdef CONFIG_PAX_ASLR
42951 + current->mm->delta_mmap = 0UL;
42952 + current->mm->delta_stack = 0UL;
42953 +#endif
42954 +
42955 + current->mm->def_flags = 0;
42956 +
42957 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42958 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42959 + send_sig(SIGKILL, current, 0);
42960 + goto out_free_dentry;
42961 + }
42962 +#endif
42963 +
42964 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42965 + pax_set_initial_flags(bprm);
42966 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42967 + if (pax_set_initial_flags_func)
42968 + (pax_set_initial_flags_func)(bprm);
42969 +#endif
42970 +
42971 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42972 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42973 + current->mm->context.user_cs_limit = PAGE_SIZE;
42974 + current->mm->def_flags |= VM_PAGEEXEC;
42975 + }
42976 +#endif
42977 +
42978 +#ifdef CONFIG_PAX_SEGMEXEC
42979 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42980 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42981 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42982 + pax_task_size = SEGMEXEC_TASK_SIZE;
42983 + current->mm->def_flags |= VM_NOHUGEPAGE;
42984 + }
42985 +#endif
42986 +
42987 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42988 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42989 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42990 + put_cpu();
42991 + }
42992 +#endif
42993
42994 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42995 may depend on the personality. */
42996 SET_PERSONALITY(loc->elf_ex);
42997 +
42998 +#ifdef CONFIG_PAX_ASLR
42999 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43000 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43001 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43002 + }
43003 +#endif
43004 +
43005 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43006 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43007 + executable_stack = EXSTACK_DISABLE_X;
43008 + current->personality &= ~READ_IMPLIES_EXEC;
43009 + } else
43010 +#endif
43011 +
43012 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43013 current->personality |= READ_IMPLIES_EXEC;
43014
43015 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43016 #else
43017 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43018 #endif
43019 +
43020 +#ifdef CONFIG_PAX_RANDMMAP
43021 + /* PaX: randomize base address at the default exe base if requested */
43022 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43023 +#ifdef CONFIG_SPARC64
43024 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43025 +#else
43026 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43027 +#endif
43028 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43029 + elf_flags |= MAP_FIXED;
43030 + }
43031 +#endif
43032 +
43033 }
43034
43035 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43036 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43037 * allowed task size. Note that p_filesz must always be
43038 * <= p_memsz so it is only necessary to check p_memsz.
43039 */
43040 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43041 - elf_ppnt->p_memsz > TASK_SIZE ||
43042 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43043 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43044 + elf_ppnt->p_memsz > pax_task_size ||
43045 + pax_task_size - elf_ppnt->p_memsz < k) {
43046 /* set_brk can never work. Avoid overflows. */
43047 send_sig(SIGKILL, current, 0);
43048 retval = -EINVAL;
43049 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43050 goto out_free_dentry;
43051 }
43052 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43053 - send_sig(SIGSEGV, current, 0);
43054 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43055 - goto out_free_dentry;
43056 + /*
43057 + * This bss-zeroing can fail if the ELF
43058 + * file specifies odd protections. So
43059 + * we don't check the return value
43060 + */
43061 }
43062
43063 +#ifdef CONFIG_PAX_RANDMMAP
43064 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43065 + unsigned long start, size;
43066 +
43067 + start = ELF_PAGEALIGN(elf_brk);
43068 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43069 + down_read(&current->mm->mmap_sem);
43070 + retval = -ENOMEM;
43071 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43072 + unsigned long prot = PROT_NONE;
43073 +
43074 + up_read(&current->mm->mmap_sem);
43075 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43076 +// if (current->personality & ADDR_NO_RANDOMIZE)
43077 +// prot = PROT_READ;
43078 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43079 + retval = IS_ERR_VALUE(start) ? start : 0;
43080 + } else
43081 + up_read(&current->mm->mmap_sem);
43082 + if (retval == 0)
43083 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43084 + if (retval < 0) {
43085 + send_sig(SIGKILL, current, 0);
43086 + goto out_free_dentry;
43087 + }
43088 + }
43089 +#endif
43090 +
43091 if (elf_interpreter) {
43092 unsigned long uninitialized_var(interp_map_addr);
43093
43094 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43095 * Decide what to dump of a segment, part, all or none.
43096 */
43097 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43098 - unsigned long mm_flags)
43099 + unsigned long mm_flags, long signr)
43100 {
43101 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43102
43103 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43104 if (vma->vm_file == NULL)
43105 return 0;
43106
43107 - if (FILTER(MAPPED_PRIVATE))
43108 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43109 goto whole;
43110
43111 /*
43112 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43113 {
43114 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43115 int i = 0;
43116 - do
43117 + do {
43118 i += 2;
43119 - while (auxv[i - 2] != AT_NULL);
43120 + } while (auxv[i - 2] != AT_NULL);
43121 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43122 }
43123
43124 @@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43125 }
43126
43127 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43128 - unsigned long mm_flags)
43129 + struct coredump_params *cprm)
43130 {
43131 struct vm_area_struct *vma;
43132 size_t size = 0;
43133
43134 for (vma = first_vma(current, gate_vma); vma != NULL;
43135 vma = next_vma(vma, gate_vma))
43136 - size += vma_dump_size(vma, mm_flags);
43137 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43138 return size;
43139 }
43140
43141 @@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43142
43143 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43144
43145 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43146 + offset += elf_core_vma_data_size(gate_vma, cprm);
43147 offset += elf_core_extra_data_size();
43148 e_shoff = offset;
43149
43150 @@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43151 offset = dataoff;
43152
43153 size += sizeof(*elf);
43154 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43155 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43156 goto end_coredump;
43157
43158 size += sizeof(*phdr4note);
43159 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43160 if (size > cprm->limit
43161 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43162 goto end_coredump;
43163 @@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43164 phdr.p_offset = offset;
43165 phdr.p_vaddr = vma->vm_start;
43166 phdr.p_paddr = 0;
43167 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43168 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43169 phdr.p_memsz = vma->vm_end - vma->vm_start;
43170 offset += phdr.p_filesz;
43171 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43172 @@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43173 phdr.p_align = ELF_EXEC_PAGESIZE;
43174
43175 size += sizeof(phdr);
43176 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43177 if (size > cprm->limit
43178 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43179 goto end_coredump;
43180 @@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43181 unsigned long addr;
43182 unsigned long end;
43183
43184 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43185 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43186
43187 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43188 struct page *page;
43189 @@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43190 page = get_dump_page(addr);
43191 if (page) {
43192 void *kaddr = kmap(page);
43193 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43194 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43195 !dump_write(cprm->file, kaddr,
43196 PAGE_SIZE);
43197 @@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43198
43199 if (e_phnum == PN_XNUM) {
43200 size += sizeof(*shdr4extnum);
43201 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43202 if (size > cprm->limit
43203 || !dump_write(cprm->file, shdr4extnum,
43204 sizeof(*shdr4extnum)))
43205 @@ -2103,6 +2556,97 @@ out:
43206
43207 #endif /* CONFIG_ELF_CORE */
43208
43209 +#ifdef CONFIG_PAX_MPROTECT
43210 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43211 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43212 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43213 + *
43214 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43215 + * basis because we want to allow the common case and not the special ones.
43216 + */
43217 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43218 +{
43219 + struct elfhdr elf_h;
43220 + struct elf_phdr elf_p;
43221 + unsigned long i;
43222 + unsigned long oldflags;
43223 + bool is_textrel_rw, is_textrel_rx, is_relro;
43224 +
43225 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43226 + return;
43227 +
43228 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43229 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43230 +
43231 +#ifdef CONFIG_PAX_ELFRELOCS
43232 + /* possible TEXTREL */
43233 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43234 + 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);
43235 +#else
43236 + is_textrel_rw = false;
43237 + is_textrel_rx = false;
43238 +#endif
43239 +
43240 + /* possible RELRO */
43241 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43242 +
43243 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43244 + return;
43245 +
43246 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43247 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43248 +
43249 +#ifdef CONFIG_PAX_ETEXECRELOCS
43250 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43251 +#else
43252 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43253 +#endif
43254 +
43255 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43256 + !elf_check_arch(&elf_h) ||
43257 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43258 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43259 + return;
43260 +
43261 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43262 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43263 + return;
43264 + switch (elf_p.p_type) {
43265 + case PT_DYNAMIC:
43266 + if (!is_textrel_rw && !is_textrel_rx)
43267 + continue;
43268 + i = 0UL;
43269 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43270 + elf_dyn dyn;
43271 +
43272 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43273 + return;
43274 + if (dyn.d_tag == DT_NULL)
43275 + return;
43276 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43277 + gr_log_textrel(vma);
43278 + if (is_textrel_rw)
43279 + vma->vm_flags |= VM_MAYWRITE;
43280 + else
43281 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43282 + vma->vm_flags &= ~VM_MAYWRITE;
43283 + return;
43284 + }
43285 + i++;
43286 + }
43287 + return;
43288 +
43289 + case PT_GNU_RELRO:
43290 + if (!is_relro)
43291 + continue;
43292 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43293 + vma->vm_flags &= ~VM_MAYWRITE;
43294 + return;
43295 + }
43296 + }
43297 +}
43298 +#endif
43299 +
43300 static int __init init_elf_binfmt(void)
43301 {
43302 register_binfmt(&elf_format);
43303 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43304 index 178cb70..8972997 100644
43305 --- a/fs/binfmt_flat.c
43306 +++ b/fs/binfmt_flat.c
43307 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43308 realdatastart = (unsigned long) -ENOMEM;
43309 printk("Unable to allocate RAM for process data, errno %d\n",
43310 (int)-realdatastart);
43311 + down_write(&current->mm->mmap_sem);
43312 vm_munmap(textpos, text_len);
43313 + up_write(&current->mm->mmap_sem);
43314 ret = realdatastart;
43315 goto err;
43316 }
43317 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43318 }
43319 if (IS_ERR_VALUE(result)) {
43320 printk("Unable to read data+bss, errno %d\n", (int)-result);
43321 + down_write(&current->mm->mmap_sem);
43322 vm_munmap(textpos, text_len);
43323 vm_munmap(realdatastart, len);
43324 + up_write(&current->mm->mmap_sem);
43325 ret = result;
43326 goto err;
43327 }
43328 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43329 }
43330 if (IS_ERR_VALUE(result)) {
43331 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43332 + down_write(&current->mm->mmap_sem);
43333 vm_munmap(textpos, text_len + data_len + extra +
43334 MAX_SHARED_LIBS * sizeof(unsigned long));
43335 + up_write(&current->mm->mmap_sem);
43336 ret = result;
43337 goto err;
43338 }
43339 diff --git a/fs/bio.c b/fs/bio.c
43340 index 73922ab..16642dd 100644
43341 --- a/fs/bio.c
43342 +++ b/fs/bio.c
43343 @@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43344 /*
43345 * Overflow, abort
43346 */
43347 - if (end < start)
43348 + if (end < start || end - start > INT_MAX - nr_pages)
43349 return ERR_PTR(-EINVAL);
43350
43351 nr_pages += end - start;
43352 @@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43353 /*
43354 * Overflow, abort
43355 */
43356 - if (end < start)
43357 + if (end < start || end - start > INT_MAX - nr_pages)
43358 return ERR_PTR(-EINVAL);
43359
43360 nr_pages += end - start;
43361 @@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43362 const int read = bio_data_dir(bio) == READ;
43363 struct bio_map_data *bmd = bio->bi_private;
43364 int i;
43365 - char *p = bmd->sgvecs[0].iov_base;
43366 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43367
43368 __bio_for_each_segment(bvec, bio, i, 0) {
43369 char *addr = page_address(bvec->bv_page);
43370 diff --git a/fs/block_dev.c b/fs/block_dev.c
43371 index c2bbe1f..9dfbc23 100644
43372 --- a/fs/block_dev.c
43373 +++ b/fs/block_dev.c
43374 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43375 else if (bdev->bd_contains == bdev)
43376 return true; /* is a whole device which isn't held */
43377
43378 - else if (whole->bd_holder == bd_may_claim)
43379 + else if (whole->bd_holder == (void *)bd_may_claim)
43380 return true; /* is a partition of a device that is being partitioned */
43381 else if (whole->bd_holder != NULL)
43382 return false; /* is a partition of a held device */
43383 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43384 index da6e936..1598dd0 100644
43385 --- a/fs/btrfs/check-integrity.c
43386 +++ b/fs/btrfs/check-integrity.c
43387 @@ -155,7 +155,7 @@ struct btrfsic_block {
43388 union {
43389 bio_end_io_t *bio;
43390 bh_end_io_t *bh;
43391 - } orig_bio_bh_end_io;
43392 + } __no_const orig_bio_bh_end_io;
43393 int submit_bio_bh_rw;
43394 u64 flush_gen; /* only valid if !never_written */
43395 };
43396 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43397 index 8206b39..06d5654 100644
43398 --- a/fs/btrfs/ctree.c
43399 +++ b/fs/btrfs/ctree.c
43400 @@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43401 free_extent_buffer(buf);
43402 add_root_to_dirty_list(root);
43403 } else {
43404 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43405 - parent_start = parent->start;
43406 - else
43407 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43408 + if (parent)
43409 + parent_start = parent->start;
43410 + else
43411 + parent_start = 0;
43412 + } else
43413 parent_start = 0;
43414
43415 WARN_ON(trans->transid != btrfs_header_generation(parent));
43416 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43417 index a7d1921..a32dba2 100644
43418 --- a/fs/btrfs/inode.c
43419 +++ b/fs/btrfs/inode.c
43420 @@ -7111,7 +7111,7 @@ fail:
43421 return -ENOMEM;
43422 }
43423
43424 -static int btrfs_getattr(struct vfsmount *mnt,
43425 +int btrfs_getattr(struct vfsmount *mnt,
43426 struct dentry *dentry, struct kstat *stat)
43427 {
43428 struct inode *inode = dentry->d_inode;
43429 @@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43430 return 0;
43431 }
43432
43433 +EXPORT_SYMBOL(btrfs_getattr);
43434 +
43435 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43436 +{
43437 + return BTRFS_I(inode)->root->anon_dev;
43438 +}
43439 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43440 +
43441 /*
43442 * If a file is moved, it will inherit the cow and compression flags of the new
43443 * directory.
43444 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43445 index 0e92e57..8b560de 100644
43446 --- a/fs/btrfs/ioctl.c
43447 +++ b/fs/btrfs/ioctl.c
43448 @@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43449 for (i = 0; i < num_types; i++) {
43450 struct btrfs_space_info *tmp;
43451
43452 + /* Don't copy in more than we allocated */
43453 if (!slot_count)
43454 break;
43455
43456 + slot_count--;
43457 +
43458 info = NULL;
43459 rcu_read_lock();
43460 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43461 @@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43462 memcpy(dest, &space, sizeof(space));
43463 dest++;
43464 space_args.total_spaces++;
43465 - slot_count--;
43466 }
43467 - if (!slot_count)
43468 - break;
43469 }
43470 up_read(&info->groups_sem);
43471 }
43472 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43473 index 646ee21..f020f87 100644
43474 --- a/fs/btrfs/relocation.c
43475 +++ b/fs/btrfs/relocation.c
43476 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43477 }
43478 spin_unlock(&rc->reloc_root_tree.lock);
43479
43480 - BUG_ON((struct btrfs_root *)node->data != root);
43481 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43482
43483 if (!del) {
43484 spin_lock(&rc->reloc_root_tree.lock);
43485 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43486 index 622f469..e8d2d55 100644
43487 --- a/fs/cachefiles/bind.c
43488 +++ b/fs/cachefiles/bind.c
43489 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43490 args);
43491
43492 /* start by checking things over */
43493 - ASSERT(cache->fstop_percent >= 0 &&
43494 - cache->fstop_percent < cache->fcull_percent &&
43495 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43496 cache->fcull_percent < cache->frun_percent &&
43497 cache->frun_percent < 100);
43498
43499 - ASSERT(cache->bstop_percent >= 0 &&
43500 - cache->bstop_percent < cache->bcull_percent &&
43501 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43502 cache->bcull_percent < cache->brun_percent &&
43503 cache->brun_percent < 100);
43504
43505 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43506 index 0a1467b..6a53245 100644
43507 --- a/fs/cachefiles/daemon.c
43508 +++ b/fs/cachefiles/daemon.c
43509 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43510 if (n > buflen)
43511 return -EMSGSIZE;
43512
43513 - if (copy_to_user(_buffer, buffer, n) != 0)
43514 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43515 return -EFAULT;
43516
43517 return n;
43518 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43519 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43520 return -EIO;
43521
43522 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43523 + if (datalen > PAGE_SIZE - 1)
43524 return -EOPNOTSUPP;
43525
43526 /* drag the command string into the kernel so we can parse it */
43527 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43528 if (args[0] != '%' || args[1] != '\0')
43529 return -EINVAL;
43530
43531 - if (fstop < 0 || fstop >= cache->fcull_percent)
43532 + if (fstop >= cache->fcull_percent)
43533 return cachefiles_daemon_range_error(cache, args);
43534
43535 cache->fstop_percent = fstop;
43536 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43537 if (args[0] != '%' || args[1] != '\0')
43538 return -EINVAL;
43539
43540 - if (bstop < 0 || bstop >= cache->bcull_percent)
43541 + if (bstop >= cache->bcull_percent)
43542 return cachefiles_daemon_range_error(cache, args);
43543
43544 cache->bstop_percent = bstop;
43545 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43546 index bd6bc1b..b627b53 100644
43547 --- a/fs/cachefiles/internal.h
43548 +++ b/fs/cachefiles/internal.h
43549 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43550 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43551 struct rb_root active_nodes; /* active nodes (can't be culled) */
43552 rwlock_t active_lock; /* lock for active_nodes */
43553 - atomic_t gravecounter; /* graveyard uniquifier */
43554 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43555 unsigned frun_percent; /* when to stop culling (% files) */
43556 unsigned fcull_percent; /* when to start culling (% files) */
43557 unsigned fstop_percent; /* when to stop allocating (% files) */
43558 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43559 * proc.c
43560 */
43561 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43562 -extern atomic_t cachefiles_lookup_histogram[HZ];
43563 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43564 -extern atomic_t cachefiles_create_histogram[HZ];
43565 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43566 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43567 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43568
43569 extern int __init cachefiles_proc_init(void);
43570 extern void cachefiles_proc_cleanup(void);
43571 static inline
43572 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43573 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43574 {
43575 unsigned long jif = jiffies - start_jif;
43576 if (jif >= HZ)
43577 jif = HZ - 1;
43578 - atomic_inc(&histogram[jif]);
43579 + atomic_inc_unchecked(&histogram[jif]);
43580 }
43581
43582 #else
43583 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43584 index 7f0771d..87d4f36 100644
43585 --- a/fs/cachefiles/namei.c
43586 +++ b/fs/cachefiles/namei.c
43587 @@ -318,7 +318,7 @@ try_again:
43588 /* first step is to make up a grave dentry in the graveyard */
43589 sprintf(nbuffer, "%08x%08x",
43590 (uint32_t) get_seconds(),
43591 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43592 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43593
43594 /* do the multiway lock magic */
43595 trap = lock_rename(cache->graveyard, dir);
43596 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43597 index eccd339..4c1d995 100644
43598 --- a/fs/cachefiles/proc.c
43599 +++ b/fs/cachefiles/proc.c
43600 @@ -14,9 +14,9 @@
43601 #include <linux/seq_file.h>
43602 #include "internal.h"
43603
43604 -atomic_t cachefiles_lookup_histogram[HZ];
43605 -atomic_t cachefiles_mkdir_histogram[HZ];
43606 -atomic_t cachefiles_create_histogram[HZ];
43607 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43608 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43609 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43610
43611 /*
43612 * display the latency histogram
43613 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43614 return 0;
43615 default:
43616 index = (unsigned long) v - 3;
43617 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43618 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43619 - z = atomic_read(&cachefiles_create_histogram[index]);
43620 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43621 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43622 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43623 if (x == 0 && y == 0 && z == 0)
43624 return 0;
43625
43626 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43627 index 0e3c092..818480e 100644
43628 --- a/fs/cachefiles/rdwr.c
43629 +++ b/fs/cachefiles/rdwr.c
43630 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43631 old_fs = get_fs();
43632 set_fs(KERNEL_DS);
43633 ret = file->f_op->write(
43634 - file, (const void __user *) data, len, &pos);
43635 + file, (const void __force_user *) data, len, &pos);
43636 set_fs(old_fs);
43637 kunmap(page);
43638 if (ret != len)
43639 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43640 index 3e8094b..cb3ff3d 100644
43641 --- a/fs/ceph/dir.c
43642 +++ b/fs/ceph/dir.c
43643 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43644 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43645 struct ceph_mds_client *mdsc = fsc->mdsc;
43646 unsigned frag = fpos_frag(filp->f_pos);
43647 - int off = fpos_off(filp->f_pos);
43648 + unsigned int off = fpos_off(filp->f_pos);
43649 int err;
43650 u32 ftype;
43651 struct ceph_mds_reply_info_parsed *rinfo;
43652 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43653 if (nd &&
43654 (nd->flags & LOOKUP_OPEN) &&
43655 !(nd->intent.open.flags & O_CREAT)) {
43656 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43657 + int mode = nd->intent.open.create_mode & ~current_umask();
43658 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43659 }
43660
43661 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43662 index e814052..28dcdf7 100644
43663 --- a/fs/cifs/cifs_debug.c
43664 +++ b/fs/cifs/cifs_debug.c
43665 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43666
43667 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43668 #ifdef CONFIG_CIFS_STATS2
43669 - atomic_set(&totBufAllocCount, 0);
43670 - atomic_set(&totSmBufAllocCount, 0);
43671 + atomic_set_unchecked(&totBufAllocCount, 0);
43672 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43673 #endif /* CONFIG_CIFS_STATS2 */
43674 spin_lock(&cifs_tcp_ses_lock);
43675 list_for_each(tmp1, &cifs_tcp_ses_list) {
43676 @@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43677 tcon = list_entry(tmp3,
43678 struct cifs_tcon,
43679 tcon_list);
43680 - atomic_set(&tcon->num_smbs_sent, 0);
43681 - atomic_set(&tcon->num_writes, 0);
43682 - atomic_set(&tcon->num_reads, 0);
43683 - atomic_set(&tcon->num_oplock_brks, 0);
43684 - atomic_set(&tcon->num_opens, 0);
43685 - atomic_set(&tcon->num_posixopens, 0);
43686 - atomic_set(&tcon->num_posixmkdirs, 0);
43687 - atomic_set(&tcon->num_closes, 0);
43688 - atomic_set(&tcon->num_deletes, 0);
43689 - atomic_set(&tcon->num_mkdirs, 0);
43690 - atomic_set(&tcon->num_rmdirs, 0);
43691 - atomic_set(&tcon->num_renames, 0);
43692 - atomic_set(&tcon->num_t2renames, 0);
43693 - atomic_set(&tcon->num_ffirst, 0);
43694 - atomic_set(&tcon->num_fnext, 0);
43695 - atomic_set(&tcon->num_fclose, 0);
43696 - atomic_set(&tcon->num_hardlinks, 0);
43697 - atomic_set(&tcon->num_symlinks, 0);
43698 - atomic_set(&tcon->num_locks, 0);
43699 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43700 + atomic_set_unchecked(&tcon->num_writes, 0);
43701 + atomic_set_unchecked(&tcon->num_reads, 0);
43702 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43703 + atomic_set_unchecked(&tcon->num_opens, 0);
43704 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43705 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43706 + atomic_set_unchecked(&tcon->num_closes, 0);
43707 + atomic_set_unchecked(&tcon->num_deletes, 0);
43708 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43709 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43710 + atomic_set_unchecked(&tcon->num_renames, 0);
43711 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43712 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43713 + atomic_set_unchecked(&tcon->num_fnext, 0);
43714 + atomic_set_unchecked(&tcon->num_fclose, 0);
43715 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43716 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43717 + atomic_set_unchecked(&tcon->num_locks, 0);
43718 }
43719 }
43720 }
43721 @@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43722 smBufAllocCount.counter, cifs_min_small);
43723 #ifdef CONFIG_CIFS_STATS2
43724 seq_printf(m, "Total Large %d Small %d Allocations\n",
43725 - atomic_read(&totBufAllocCount),
43726 - atomic_read(&totSmBufAllocCount));
43727 + atomic_read_unchecked(&totBufAllocCount),
43728 + atomic_read_unchecked(&totSmBufAllocCount));
43729 #endif /* CONFIG_CIFS_STATS2 */
43730
43731 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43732 @@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43733 if (tcon->need_reconnect)
43734 seq_puts(m, "\tDISCONNECTED ");
43735 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43736 - atomic_read(&tcon->num_smbs_sent),
43737 - atomic_read(&tcon->num_oplock_brks));
43738 + atomic_read_unchecked(&tcon->num_smbs_sent),
43739 + atomic_read_unchecked(&tcon->num_oplock_brks));
43740 seq_printf(m, "\nReads: %d Bytes: %lld",
43741 - atomic_read(&tcon->num_reads),
43742 + atomic_read_unchecked(&tcon->num_reads),
43743 (long long)(tcon->bytes_read));
43744 seq_printf(m, "\nWrites: %d Bytes: %lld",
43745 - atomic_read(&tcon->num_writes),
43746 + atomic_read_unchecked(&tcon->num_writes),
43747 (long long)(tcon->bytes_written));
43748 seq_printf(m, "\nFlushes: %d",
43749 - atomic_read(&tcon->num_flushes));
43750 + atomic_read_unchecked(&tcon->num_flushes));
43751 seq_printf(m, "\nLocks: %d HardLinks: %d "
43752 "Symlinks: %d",
43753 - atomic_read(&tcon->num_locks),
43754 - atomic_read(&tcon->num_hardlinks),
43755 - atomic_read(&tcon->num_symlinks));
43756 + atomic_read_unchecked(&tcon->num_locks),
43757 + atomic_read_unchecked(&tcon->num_hardlinks),
43758 + atomic_read_unchecked(&tcon->num_symlinks));
43759 seq_printf(m, "\nOpens: %d Closes: %d "
43760 "Deletes: %d",
43761 - atomic_read(&tcon->num_opens),
43762 - atomic_read(&tcon->num_closes),
43763 - atomic_read(&tcon->num_deletes));
43764 + atomic_read_unchecked(&tcon->num_opens),
43765 + atomic_read_unchecked(&tcon->num_closes),
43766 + atomic_read_unchecked(&tcon->num_deletes));
43767 seq_printf(m, "\nPosix Opens: %d "
43768 "Posix Mkdirs: %d",
43769 - atomic_read(&tcon->num_posixopens),
43770 - atomic_read(&tcon->num_posixmkdirs));
43771 + atomic_read_unchecked(&tcon->num_posixopens),
43772 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43773 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43774 - atomic_read(&tcon->num_mkdirs),
43775 - atomic_read(&tcon->num_rmdirs));
43776 + atomic_read_unchecked(&tcon->num_mkdirs),
43777 + atomic_read_unchecked(&tcon->num_rmdirs));
43778 seq_printf(m, "\nRenames: %d T2 Renames %d",
43779 - atomic_read(&tcon->num_renames),
43780 - atomic_read(&tcon->num_t2renames));
43781 + atomic_read_unchecked(&tcon->num_renames),
43782 + atomic_read_unchecked(&tcon->num_t2renames));
43783 seq_printf(m, "\nFindFirst: %d FNext %d "
43784 "FClose %d",
43785 - atomic_read(&tcon->num_ffirst),
43786 - atomic_read(&tcon->num_fnext),
43787 - atomic_read(&tcon->num_fclose));
43788 + atomic_read_unchecked(&tcon->num_ffirst),
43789 + atomic_read_unchecked(&tcon->num_fnext),
43790 + atomic_read_unchecked(&tcon->num_fclose));
43791 }
43792 }
43793 }
43794 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43795 index 8b6e344..303a662 100644
43796 --- a/fs/cifs/cifsfs.c
43797 +++ b/fs/cifs/cifsfs.c
43798 @@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43799 cifs_req_cachep = kmem_cache_create("cifs_request",
43800 CIFSMaxBufSize +
43801 MAX_CIFS_HDR_SIZE, 0,
43802 - SLAB_HWCACHE_ALIGN, NULL);
43803 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43804 if (cifs_req_cachep == NULL)
43805 return -ENOMEM;
43806
43807 @@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43808 efficient to alloc 1 per page off the slab compared to 17K (5page)
43809 alloc of large cifs buffers even when page debugging is on */
43810 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43811 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43812 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43813 NULL);
43814 if (cifs_sm_req_cachep == NULL) {
43815 mempool_destroy(cifs_req_poolp);
43816 @@ -1106,8 +1106,8 @@ init_cifs(void)
43817 atomic_set(&bufAllocCount, 0);
43818 atomic_set(&smBufAllocCount, 0);
43819 #ifdef CONFIG_CIFS_STATS2
43820 - atomic_set(&totBufAllocCount, 0);
43821 - atomic_set(&totSmBufAllocCount, 0);
43822 + atomic_set_unchecked(&totBufAllocCount, 0);
43823 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43824 #endif /* CONFIG_CIFS_STATS2 */
43825
43826 atomic_set(&midCount, 0);
43827 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43828 index d86ba9f..e80049d 100644
43829 --- a/fs/cifs/cifsglob.h
43830 +++ b/fs/cifs/cifsglob.h
43831 @@ -491,28 +491,28 @@ struct cifs_tcon {
43832 __u16 Flags; /* optional support bits */
43833 enum statusEnum tidStatus;
43834 #ifdef CONFIG_CIFS_STATS
43835 - atomic_t num_smbs_sent;
43836 - atomic_t num_writes;
43837 - atomic_t num_reads;
43838 - atomic_t num_flushes;
43839 - atomic_t num_oplock_brks;
43840 - atomic_t num_opens;
43841 - atomic_t num_closes;
43842 - atomic_t num_deletes;
43843 - atomic_t num_mkdirs;
43844 - atomic_t num_posixopens;
43845 - atomic_t num_posixmkdirs;
43846 - atomic_t num_rmdirs;
43847 - atomic_t num_renames;
43848 - atomic_t num_t2renames;
43849 - atomic_t num_ffirst;
43850 - atomic_t num_fnext;
43851 - atomic_t num_fclose;
43852 - atomic_t num_hardlinks;
43853 - atomic_t num_symlinks;
43854 - atomic_t num_locks;
43855 - atomic_t num_acl_get;
43856 - atomic_t num_acl_set;
43857 + atomic_unchecked_t num_smbs_sent;
43858 + atomic_unchecked_t num_writes;
43859 + atomic_unchecked_t num_reads;
43860 + atomic_unchecked_t num_flushes;
43861 + atomic_unchecked_t num_oplock_brks;
43862 + atomic_unchecked_t num_opens;
43863 + atomic_unchecked_t num_closes;
43864 + atomic_unchecked_t num_deletes;
43865 + atomic_unchecked_t num_mkdirs;
43866 + atomic_unchecked_t num_posixopens;
43867 + atomic_unchecked_t num_posixmkdirs;
43868 + atomic_unchecked_t num_rmdirs;
43869 + atomic_unchecked_t num_renames;
43870 + atomic_unchecked_t num_t2renames;
43871 + atomic_unchecked_t num_ffirst;
43872 + atomic_unchecked_t num_fnext;
43873 + atomic_unchecked_t num_fclose;
43874 + atomic_unchecked_t num_hardlinks;
43875 + atomic_unchecked_t num_symlinks;
43876 + atomic_unchecked_t num_locks;
43877 + atomic_unchecked_t num_acl_get;
43878 + atomic_unchecked_t num_acl_set;
43879 #ifdef CONFIG_CIFS_STATS2
43880 unsigned long long time_writes;
43881 unsigned long long time_reads;
43882 @@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43883 }
43884
43885 #ifdef CONFIG_CIFS_STATS
43886 -#define cifs_stats_inc atomic_inc
43887 +#define cifs_stats_inc atomic_inc_unchecked
43888
43889 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43890 unsigned int bytes)
43891 @@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43892 /* Various Debug counters */
43893 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43894 #ifdef CONFIG_CIFS_STATS2
43895 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43896 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43897 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43898 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43899 #endif
43900 GLOBAL_EXTERN atomic_t smBufAllocCount;
43901 GLOBAL_EXTERN atomic_t midCount;
43902 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43903 index 6b0e064..94e6c3c 100644
43904 --- a/fs/cifs/link.c
43905 +++ b/fs/cifs/link.c
43906 @@ -600,7 +600,7 @@ symlink_exit:
43907
43908 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43909 {
43910 - char *p = nd_get_link(nd);
43911 + const char *p = nd_get_link(nd);
43912 if (!IS_ERR(p))
43913 kfree(p);
43914 }
43915 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43916 index 557506a..2fd3816 100644
43917 --- a/fs/cifs/misc.c
43918 +++ b/fs/cifs/misc.c
43919 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43920 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43921 atomic_inc(&bufAllocCount);
43922 #ifdef CONFIG_CIFS_STATS2
43923 - atomic_inc(&totBufAllocCount);
43924 + atomic_inc_unchecked(&totBufAllocCount);
43925 #endif /* CONFIG_CIFS_STATS2 */
43926 }
43927
43928 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43929 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43930 atomic_inc(&smBufAllocCount);
43931 #ifdef CONFIG_CIFS_STATS2
43932 - atomic_inc(&totSmBufAllocCount);
43933 + atomic_inc_unchecked(&totSmBufAllocCount);
43934 #endif /* CONFIG_CIFS_STATS2 */
43935
43936 }
43937 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43938 index 6901578..d402eb5 100644
43939 --- a/fs/coda/cache.c
43940 +++ b/fs/coda/cache.c
43941 @@ -24,7 +24,7 @@
43942 #include "coda_linux.h"
43943 #include "coda_cache.h"
43944
43945 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43946 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43947
43948 /* replace or extend an acl cache hit */
43949 void coda_cache_enter(struct inode *inode, int mask)
43950 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43951 struct coda_inode_info *cii = ITOC(inode);
43952
43953 spin_lock(&cii->c_lock);
43954 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43955 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43956 if (cii->c_uid != current_fsuid()) {
43957 cii->c_uid = current_fsuid();
43958 cii->c_cached_perm = mask;
43959 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43960 {
43961 struct coda_inode_info *cii = ITOC(inode);
43962 spin_lock(&cii->c_lock);
43963 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43964 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43965 spin_unlock(&cii->c_lock);
43966 }
43967
43968 /* remove all acl caches */
43969 void coda_cache_clear_all(struct super_block *sb)
43970 {
43971 - atomic_inc(&permission_epoch);
43972 + atomic_inc_unchecked(&permission_epoch);
43973 }
43974
43975
43976 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43977 spin_lock(&cii->c_lock);
43978 hit = (mask & cii->c_cached_perm) == mask &&
43979 cii->c_uid == current_fsuid() &&
43980 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43981 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43982 spin_unlock(&cii->c_lock);
43983
43984 return hit;
43985 diff --git a/fs/compat.c b/fs/compat.c
43986 index 6161255..9f28287 100644
43987 --- a/fs/compat.c
43988 +++ b/fs/compat.c
43989 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43990
43991 set_fs(KERNEL_DS);
43992 /* The __user pointer cast is valid because of the set_fs() */
43993 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43994 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43995 set_fs(oldfs);
43996 /* truncating is ok because it's a user address */
43997 if (!ret)
43998 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43999 goto out;
44000
44001 ret = -EINVAL;
44002 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44003 + if (nr_segs > UIO_MAXIOV)
44004 goto out;
44005 if (nr_segs > fast_segs) {
44006 ret = -ENOMEM;
44007 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44008
44009 struct compat_readdir_callback {
44010 struct compat_old_linux_dirent __user *dirent;
44011 + struct file * file;
44012 int result;
44013 };
44014
44015 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44016 buf->result = -EOVERFLOW;
44017 return -EOVERFLOW;
44018 }
44019 +
44020 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44021 + return 0;
44022 +
44023 buf->result++;
44024 dirent = buf->dirent;
44025 if (!access_ok(VERIFY_WRITE, dirent,
44026 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44027
44028 buf.result = 0;
44029 buf.dirent = dirent;
44030 + buf.file = file;
44031
44032 error = vfs_readdir(file, compat_fillonedir, &buf);
44033 if (buf.result)
44034 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44035 struct compat_getdents_callback {
44036 struct compat_linux_dirent __user *current_dir;
44037 struct compat_linux_dirent __user *previous;
44038 + struct file * file;
44039 int count;
44040 int error;
44041 };
44042 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44043 buf->error = -EOVERFLOW;
44044 return -EOVERFLOW;
44045 }
44046 +
44047 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44048 + return 0;
44049 +
44050 dirent = buf->previous;
44051 if (dirent) {
44052 if (__put_user(offset, &dirent->d_off))
44053 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44054 buf.previous = NULL;
44055 buf.count = count;
44056 buf.error = 0;
44057 + buf.file = file;
44058
44059 error = vfs_readdir(file, compat_filldir, &buf);
44060 if (error >= 0)
44061 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44062 struct compat_getdents_callback64 {
44063 struct linux_dirent64 __user *current_dir;
44064 struct linux_dirent64 __user *previous;
44065 + struct file * file;
44066 int count;
44067 int error;
44068 };
44069 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44070 buf->error = -EINVAL; /* only used if we fail.. */
44071 if (reclen > buf->count)
44072 return -EINVAL;
44073 +
44074 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44075 + return 0;
44076 +
44077 dirent = buf->previous;
44078
44079 if (dirent) {
44080 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44081 buf.previous = NULL;
44082 buf.count = count;
44083 buf.error = 0;
44084 + buf.file = file;
44085
44086 error = vfs_readdir(file, compat_filldir64, &buf);
44087 if (error >= 0)
44088 error = buf.error;
44089 lastdirent = buf.previous;
44090 if (lastdirent) {
44091 - typeof(lastdirent->d_off) d_off = file->f_pos;
44092 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44093 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44094 error = -EFAULT;
44095 else
44096 @@ -1155,11 +1173,14 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
44097 struct file *file;
44098 int fput_needed;
44099 ssize_t ret;
44100 + loff_t pos;
44101
44102 file = fget_light(fd, &fput_needed);
44103 if (!file)
44104 return -EBADF;
44105 - ret = compat_readv(file, vec, vlen, &file->f_pos);
44106 + pos = file->f_pos;
44107 + ret = compat_readv(file, vec, vlen, &pos);
44108 + file->f_pos = pos;
44109 fput_light(file, fput_needed);
44110 return ret;
44111 }
44112 @@ -1221,11 +1242,14 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
44113 struct file *file;
44114 int fput_needed;
44115 ssize_t ret;
44116 + loff_t pos;
44117
44118 file = fget_light(fd, &fput_needed);
44119 if (!file)
44120 return -EBADF;
44121 - ret = compat_writev(file, vec, vlen, &file->f_pos);
44122 + pos = file->f_pos;
44123 + ret = compat_writev(file, vec, vlen, &pos);
44124 + file->f_pos = pos;
44125 fput_light(file, fput_needed);
44126 return ret;
44127 }
44128 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44129 index 112e45a..b59845b 100644
44130 --- a/fs/compat_binfmt_elf.c
44131 +++ b/fs/compat_binfmt_elf.c
44132 @@ -30,11 +30,13 @@
44133 #undef elf_phdr
44134 #undef elf_shdr
44135 #undef elf_note
44136 +#undef elf_dyn
44137 #undef elf_addr_t
44138 #define elfhdr elf32_hdr
44139 #define elf_phdr elf32_phdr
44140 #define elf_shdr elf32_shdr
44141 #define elf_note elf32_note
44142 +#define elf_dyn Elf32_Dyn
44143 #define elf_addr_t Elf32_Addr
44144
44145 /*
44146 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44147 index debdfe0..75d31d4 100644
44148 --- a/fs/compat_ioctl.c
44149 +++ b/fs/compat_ioctl.c
44150 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44151
44152 err = get_user(palp, &up->palette);
44153 err |= get_user(length, &up->length);
44154 + if (err)
44155 + return -EFAULT;
44156
44157 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44158 err = put_user(compat_ptr(palp), &up_native->palette);
44159 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44160 return -EFAULT;
44161 if (__get_user(udata, &ss32->iomem_base))
44162 return -EFAULT;
44163 - ss.iomem_base = compat_ptr(udata);
44164 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44165 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44166 __get_user(ss.port_high, &ss32->port_high))
44167 return -EFAULT;
44168 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44169 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44170 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44171 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44172 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44173 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44174 return -EFAULT;
44175
44176 return ioctl_preallocate(file, p);
44177 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44178 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44179 {
44180 unsigned int a, b;
44181 - a = *(unsigned int *)p;
44182 - b = *(unsigned int *)q;
44183 + a = *(const unsigned int *)p;
44184 + b = *(const unsigned int *)q;
44185 if (a > b)
44186 return 1;
44187 if (a < b)
44188 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44189 index 7e6c52d..94bc756 100644
44190 --- a/fs/configfs/dir.c
44191 +++ b/fs/configfs/dir.c
44192 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44193 }
44194 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44195 struct configfs_dirent *next;
44196 - const char * name;
44197 + const unsigned char * name;
44198 + char d_name[sizeof(next->s_dentry->d_iname)];
44199 int len;
44200 struct inode *inode = NULL;
44201
44202 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44203 continue;
44204
44205 name = configfs_get_name(next);
44206 - len = strlen(name);
44207 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44208 + len = next->s_dentry->d_name.len;
44209 + memcpy(d_name, name, len);
44210 + name = d_name;
44211 + } else
44212 + len = strlen(name);
44213
44214 /*
44215 * We'll have a dentry and an inode for
44216 diff --git a/fs/dcache.c b/fs/dcache.c
44217 index 4046904..5e31505 100644
44218 --- a/fs/dcache.c
44219 +++ b/fs/dcache.c
44220 @@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44221 mempages -= reserve;
44222
44223 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44224 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44225 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44226
44227 dcache_init();
44228 inode_init();
44229 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44230 index b80bc84..0d46d1a 100644
44231 --- a/fs/debugfs/inode.c
44232 +++ b/fs/debugfs/inode.c
44233 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44234 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44235 {
44236 return debugfs_create_file(name,
44237 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44238 + S_IFDIR | S_IRWXU,
44239 +#else
44240 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44241 +#endif
44242 parent, NULL, NULL);
44243 }
44244 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44245 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44246 index a07441a..046fc0d 100644
44247 --- a/fs/ecryptfs/inode.c
44248 +++ b/fs/ecryptfs/inode.c
44249 @@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44250 old_fs = get_fs();
44251 set_fs(get_ds());
44252 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44253 - (char __user *)lower_buf,
44254 + (char __force_user *)lower_buf,
44255 PATH_MAX);
44256 set_fs(old_fs);
44257 if (rc < 0)
44258 @@ -703,7 +703,7 @@ out:
44259 static void
44260 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44261 {
44262 - char *buf = nd_get_link(nd);
44263 + const char *buf = nd_get_link(nd);
44264 if (!IS_ERR(buf)) {
44265 /* Free the char* */
44266 kfree(buf);
44267 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44268 index c0038f6..47ab347 100644
44269 --- a/fs/ecryptfs/miscdev.c
44270 +++ b/fs/ecryptfs/miscdev.c
44271 @@ -355,7 +355,7 @@ check_list:
44272 goto out_unlock_msg_ctx;
44273 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44274 if (msg_ctx->msg) {
44275 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44276 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44277 goto out_unlock_msg_ctx;
44278 i += packet_length_size;
44279 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44280 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44281 index b2a34a1..162fa69 100644
44282 --- a/fs/ecryptfs/read_write.c
44283 +++ b/fs/ecryptfs/read_write.c
44284 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44285 return -EIO;
44286 fs_save = get_fs();
44287 set_fs(get_ds());
44288 - rc = vfs_write(lower_file, data, size, &offset);
44289 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44290 set_fs(fs_save);
44291 mark_inode_dirty_sync(ecryptfs_inode);
44292 return rc;
44293 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44294 return -EIO;
44295 fs_save = get_fs();
44296 set_fs(get_ds());
44297 - rc = vfs_read(lower_file, data, size, &offset);
44298 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44299 set_fs(fs_save);
44300 return rc;
44301 }
44302 diff --git a/fs/eventpoll.c b/fs/eventpoll.c
44303 index 1c8b556..eedec84 100644
44304 --- a/fs/eventpoll.c
44305 +++ b/fs/eventpoll.c
44306 @@ -1654,8 +1654,8 @@ SYSCALL_DEFINE1(epoll_create1, int, flags)
44307 error = PTR_ERR(file);
44308 goto out_free_fd;
44309 }
44310 - fd_install(fd, file);
44311 ep->file = file;
44312 + fd_install(fd, file);
44313 return fd;
44314
44315 out_free_fd:
44316 diff --git a/fs/exec.c b/fs/exec.c
44317 index e95aeed..a943469 100644
44318 --- a/fs/exec.c
44319 +++ b/fs/exec.c
44320 @@ -55,6 +55,15 @@
44321 #include <linux/pipe_fs_i.h>
44322 #include <linux/oom.h>
44323 #include <linux/compat.h>
44324 +#include <linux/random.h>
44325 +#include <linux/seq_file.h>
44326 +
44327 +#ifdef CONFIG_PAX_REFCOUNT
44328 +#include <linux/kallsyms.h>
44329 +#include <linux/kdebug.h>
44330 +#endif
44331 +
44332 +#include <trace/events/fs.h>
44333
44334 #include <asm/uaccess.h>
44335 #include <asm/mmu_context.h>
44336 @@ -66,6 +75,18 @@
44337
44338 #include <trace/events/sched.h>
44339
44340 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44341 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44342 +{
44343 + 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");
44344 +}
44345 +#endif
44346 +
44347 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44348 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44349 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44350 +#endif
44351 +
44352 int core_uses_pid;
44353 char core_pattern[CORENAME_MAX_SIZE] = "core";
44354 unsigned int core_pipe_limit;
44355 @@ -75,7 +96,7 @@ struct core_name {
44356 char *corename;
44357 int used, size;
44358 };
44359 -static atomic_t call_count = ATOMIC_INIT(1);
44360 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44361
44362 /* The maximal length of core_pattern is also specified in sysctl.c */
44363
44364 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44365 int write)
44366 {
44367 struct page *page;
44368 - int ret;
44369
44370 -#ifdef CONFIG_STACK_GROWSUP
44371 - if (write) {
44372 - ret = expand_downwards(bprm->vma, pos);
44373 - if (ret < 0)
44374 - return NULL;
44375 - }
44376 -#endif
44377 - ret = get_user_pages(current, bprm->mm, pos,
44378 - 1, write, 1, &page, NULL);
44379 - if (ret <= 0)
44380 + if (0 > expand_downwards(bprm->vma, pos))
44381 + return NULL;
44382 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44383 return NULL;
44384
44385 if (write) {
44386 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44387 if (size <= ARG_MAX)
44388 return page;
44389
44390 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44391 + // only allow 512KB for argv+env on suid/sgid binaries
44392 + // to prevent easy ASLR exhaustion
44393 + if (((bprm->cred->euid != current_euid()) ||
44394 + (bprm->cred->egid != current_egid())) &&
44395 + (size > (512 * 1024))) {
44396 + put_page(page);
44397 + return NULL;
44398 + }
44399 +#endif
44400 +
44401 /*
44402 * Limit to 1/4-th the stack size for the argv+env strings.
44403 * This ensures that:
44404 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44405 vma->vm_end = STACK_TOP_MAX;
44406 vma->vm_start = vma->vm_end - PAGE_SIZE;
44407 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44408 +
44409 +#ifdef CONFIG_PAX_SEGMEXEC
44410 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44411 +#endif
44412 +
44413 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44414 INIT_LIST_HEAD(&vma->anon_vma_chain);
44415
44416 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44417 mm->stack_vm = mm->total_vm = 1;
44418 up_write(&mm->mmap_sem);
44419 bprm->p = vma->vm_end - sizeof(void *);
44420 +
44421 +#ifdef CONFIG_PAX_RANDUSTACK
44422 + if (randomize_va_space)
44423 + bprm->p ^= random32() & ~PAGE_MASK;
44424 +#endif
44425 +
44426 return 0;
44427 err:
44428 up_write(&mm->mmap_sem);
44429 @@ -395,19 +430,7 @@ err:
44430 return err;
44431 }
44432
44433 -struct user_arg_ptr {
44434 -#ifdef CONFIG_COMPAT
44435 - bool is_compat;
44436 -#endif
44437 - union {
44438 - const char __user *const __user *native;
44439 -#ifdef CONFIG_COMPAT
44440 - compat_uptr_t __user *compat;
44441 -#endif
44442 - } ptr;
44443 -};
44444 -
44445 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44446 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44447 {
44448 const char __user *native;
44449
44450 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44451 compat_uptr_t compat;
44452
44453 if (get_user(compat, argv.ptr.compat + nr))
44454 - return ERR_PTR(-EFAULT);
44455 + return (const char __force_user *)ERR_PTR(-EFAULT);
44456
44457 return compat_ptr(compat);
44458 }
44459 #endif
44460
44461 if (get_user(native, argv.ptr.native + nr))
44462 - return ERR_PTR(-EFAULT);
44463 + return (const char __force_user *)ERR_PTR(-EFAULT);
44464
44465 return native;
44466 }
44467 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44468 if (!p)
44469 break;
44470
44471 - if (IS_ERR(p))
44472 + if (IS_ERR((const char __force_kernel *)p))
44473 return -EFAULT;
44474
44475 if (i++ >= max)
44476 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44477
44478 ret = -EFAULT;
44479 str = get_user_arg_ptr(argv, argc);
44480 - if (IS_ERR(str))
44481 + if (IS_ERR((const char __force_kernel *)str))
44482 goto out;
44483
44484 len = strnlen_user(str, MAX_ARG_STRLEN);
44485 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44486 int r;
44487 mm_segment_t oldfs = get_fs();
44488 struct user_arg_ptr argv = {
44489 - .ptr.native = (const char __user *const __user *)__argv,
44490 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44491 };
44492
44493 set_fs(KERNEL_DS);
44494 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44495 unsigned long new_end = old_end - shift;
44496 struct mmu_gather tlb;
44497
44498 - BUG_ON(new_start > new_end);
44499 + if (new_start >= new_end || new_start < mmap_min_addr)
44500 + return -ENOMEM;
44501
44502 /*
44503 * ensure there are no vmas between where we want to go
44504 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44505 if (vma != find_vma(mm, new_start))
44506 return -EFAULT;
44507
44508 +#ifdef CONFIG_PAX_SEGMEXEC
44509 + BUG_ON(pax_find_mirror_vma(vma));
44510 +#endif
44511 +
44512 /*
44513 * cover the whole range: [new_start, old_end)
44514 */
44515 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44516 stack_top = arch_align_stack(stack_top);
44517 stack_top = PAGE_ALIGN(stack_top);
44518
44519 - if (unlikely(stack_top < mmap_min_addr) ||
44520 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44521 - return -ENOMEM;
44522 -
44523 stack_shift = vma->vm_end - stack_top;
44524
44525 bprm->p -= stack_shift;
44526 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44527 bprm->exec -= stack_shift;
44528
44529 down_write(&mm->mmap_sem);
44530 +
44531 + /* Move stack pages down in memory. */
44532 + if (stack_shift) {
44533 + ret = shift_arg_pages(vma, stack_shift);
44534 + if (ret)
44535 + goto out_unlock;
44536 + }
44537 +
44538 vm_flags = VM_STACK_FLAGS;
44539
44540 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44541 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44542 + vm_flags &= ~VM_EXEC;
44543 +
44544 +#ifdef CONFIG_PAX_MPROTECT
44545 + if (mm->pax_flags & MF_PAX_MPROTECT)
44546 + vm_flags &= ~VM_MAYEXEC;
44547 +#endif
44548 +
44549 + }
44550 +#endif
44551 +
44552 /*
44553 * Adjust stack execute permissions; explicitly enable for
44554 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44555 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44556 goto out_unlock;
44557 BUG_ON(prev != vma);
44558
44559 - /* Move stack pages down in memory. */
44560 - if (stack_shift) {
44561 - ret = shift_arg_pages(vma, stack_shift);
44562 - if (ret)
44563 - goto out_unlock;
44564 - }
44565 -
44566 /* mprotect_fixup is overkill to remove the temporary stack flags */
44567 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44568
44569 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44570
44571 fsnotify_open(file);
44572
44573 + trace_open_exec(name);
44574 +
44575 err = deny_write_access(file);
44576 if (err)
44577 goto exit;
44578 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44579 old_fs = get_fs();
44580 set_fs(get_ds());
44581 /* The cast to a user pointer is valid due to the set_fs() */
44582 - result = vfs_read(file, (void __user *)addr, count, &pos);
44583 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44584 set_fs(old_fs);
44585 return result;
44586 }
44587 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44588 }
44589 rcu_read_unlock();
44590
44591 - if (p->fs->users > n_fs) {
44592 + if (atomic_read(&p->fs->users) > n_fs) {
44593 bprm->unsafe |= LSM_UNSAFE_SHARE;
44594 } else {
44595 res = -EAGAIN;
44596 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44597
44598 EXPORT_SYMBOL(search_binary_handler);
44599
44600 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44601 +static DEFINE_PER_CPU(u64, exec_counter);
44602 +static int __init init_exec_counters(void)
44603 +{
44604 + unsigned int cpu;
44605 +
44606 + for_each_possible_cpu(cpu) {
44607 + per_cpu(exec_counter, cpu) = (u64)cpu;
44608 + }
44609 +
44610 + return 0;
44611 +}
44612 +early_initcall(init_exec_counters);
44613 +static inline void increment_exec_counter(void)
44614 +{
44615 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44616 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44617 +}
44618 +#else
44619 +static inline void increment_exec_counter(void) {}
44620 +#endif
44621 +
44622 /*
44623 * sys_execve() executes a new program.
44624 */
44625 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44626 struct user_arg_ptr envp,
44627 struct pt_regs *regs)
44628 {
44629 +#ifdef CONFIG_GRKERNSEC
44630 + struct file *old_exec_file;
44631 + struct acl_subject_label *old_acl;
44632 + struct rlimit old_rlim[RLIM_NLIMITS];
44633 +#endif
44634 struct linux_binprm *bprm;
44635 struct file *file;
44636 struct files_struct *displaced;
44637 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44638 int retval;
44639 const struct cred *cred = current_cred();
44640
44641 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44642 +
44643 /*
44644 * We move the actual failure in case of RLIMIT_NPROC excess from
44645 * set*uid() to execve() because too many poorly written programs
44646 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44647 if (IS_ERR(file))
44648 goto out_unmark;
44649
44650 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44651 + retval = -EPERM;
44652 + goto out_file;
44653 + }
44654 +
44655 sched_exec();
44656
44657 bprm->file = file;
44658 bprm->filename = filename;
44659 bprm->interp = filename;
44660
44661 + if (gr_process_user_ban()) {
44662 + retval = -EPERM;
44663 + goto out_file;
44664 + }
44665 +
44666 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44667 + retval = -EACCES;
44668 + goto out_file;
44669 + }
44670 +
44671 retval = bprm_mm_init(bprm);
44672 if (retval)
44673 goto out_file;
44674 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44675 if (retval < 0)
44676 goto out;
44677
44678 +#ifdef CONFIG_GRKERNSEC
44679 + old_acl = current->acl;
44680 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44681 + old_exec_file = current->exec_file;
44682 + get_file(file);
44683 + current->exec_file = file;
44684 +#endif
44685 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44686 + /* limit suid stack to 8MB
44687 + we saved the old limits above and will restore them if this exec fails
44688 + */
44689 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44690 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44691 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44692 +#endif
44693 +
44694 + if (!gr_tpe_allow(file)) {
44695 + retval = -EACCES;
44696 + goto out_fail;
44697 + }
44698 +
44699 + if (gr_check_crash_exec(file)) {
44700 + retval = -EACCES;
44701 + goto out_fail;
44702 + }
44703 +
44704 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44705 + bprm->unsafe);
44706 + if (retval < 0)
44707 + goto out_fail;
44708 +
44709 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44710 if (retval < 0)
44711 - goto out;
44712 + goto out_fail;
44713
44714 bprm->exec = bprm->p;
44715 retval = copy_strings(bprm->envc, envp, bprm);
44716 if (retval < 0)
44717 - goto out;
44718 + goto out_fail;
44719
44720 retval = copy_strings(bprm->argc, argv, bprm);
44721 if (retval < 0)
44722 - goto out;
44723 + goto out_fail;
44724 +
44725 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44726 +
44727 + gr_handle_exec_args(bprm, argv);
44728
44729 retval = search_binary_handler(bprm,regs);
44730 if (retval < 0)
44731 - goto out;
44732 + goto out_fail;
44733 +#ifdef CONFIG_GRKERNSEC
44734 + if (old_exec_file)
44735 + fput(old_exec_file);
44736 +#endif
44737
44738 /* execve succeeded */
44739 +
44740 + increment_exec_counter();
44741 current->fs->in_exec = 0;
44742 current->in_execve = 0;
44743 acct_update_integrals(current);
44744 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44745 put_files_struct(displaced);
44746 return retval;
44747
44748 +out_fail:
44749 +#ifdef CONFIG_GRKERNSEC
44750 + current->acl = old_acl;
44751 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44752 + fput(current->exec_file);
44753 + current->exec_file = old_exec_file;
44754 +#endif
44755 +
44756 out:
44757 if (bprm->mm) {
44758 acct_arg_size(bprm, 0);
44759 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44760 {
44761 char *old_corename = cn->corename;
44762
44763 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44764 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44765 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44766
44767 if (!cn->corename) {
44768 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44769 int pid_in_pattern = 0;
44770 int err = 0;
44771
44772 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44773 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44774 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44775 cn->used = 0;
44776
44777 @@ -1830,6 +1962,250 @@ out:
44778 return ispipe;
44779 }
44780
44781 +int pax_check_flags(unsigned long *flags)
44782 +{
44783 + int retval = 0;
44784 +
44785 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44786 + if (*flags & MF_PAX_SEGMEXEC)
44787 + {
44788 + *flags &= ~MF_PAX_SEGMEXEC;
44789 + retval = -EINVAL;
44790 + }
44791 +#endif
44792 +
44793 + if ((*flags & MF_PAX_PAGEEXEC)
44794 +
44795 +#ifdef CONFIG_PAX_PAGEEXEC
44796 + && (*flags & MF_PAX_SEGMEXEC)
44797 +#endif
44798 +
44799 + )
44800 + {
44801 + *flags &= ~MF_PAX_PAGEEXEC;
44802 + retval = -EINVAL;
44803 + }
44804 +
44805 + if ((*flags & MF_PAX_MPROTECT)
44806 +
44807 +#ifdef CONFIG_PAX_MPROTECT
44808 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44809 +#endif
44810 +
44811 + )
44812 + {
44813 + *flags &= ~MF_PAX_MPROTECT;
44814 + retval = -EINVAL;
44815 + }
44816 +
44817 + if ((*flags & MF_PAX_EMUTRAMP)
44818 +
44819 +#ifdef CONFIG_PAX_EMUTRAMP
44820 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44821 +#endif
44822 +
44823 + )
44824 + {
44825 + *flags &= ~MF_PAX_EMUTRAMP;
44826 + retval = -EINVAL;
44827 + }
44828 +
44829 + return retval;
44830 +}
44831 +
44832 +EXPORT_SYMBOL(pax_check_flags);
44833 +
44834 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44835 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44836 +{
44837 + struct task_struct *tsk = current;
44838 + struct mm_struct *mm = current->mm;
44839 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44840 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44841 + char *path_exec = NULL;
44842 + char *path_fault = NULL;
44843 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44844 +
44845 + if (buffer_exec && buffer_fault) {
44846 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44847 +
44848 + down_read(&mm->mmap_sem);
44849 + vma = mm->mmap;
44850 + while (vma && (!vma_exec || !vma_fault)) {
44851 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44852 + vma_exec = vma;
44853 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44854 + vma_fault = vma;
44855 + vma = vma->vm_next;
44856 + }
44857 + if (vma_exec) {
44858 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44859 + if (IS_ERR(path_exec))
44860 + path_exec = "<path too long>";
44861 + else {
44862 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44863 + if (path_exec) {
44864 + *path_exec = 0;
44865 + path_exec = buffer_exec;
44866 + } else
44867 + path_exec = "<path too long>";
44868 + }
44869 + }
44870 + if (vma_fault) {
44871 + start = vma_fault->vm_start;
44872 + end = vma_fault->vm_end;
44873 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44874 + if (vma_fault->vm_file) {
44875 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44876 + if (IS_ERR(path_fault))
44877 + path_fault = "<path too long>";
44878 + else {
44879 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44880 + if (path_fault) {
44881 + *path_fault = 0;
44882 + path_fault = buffer_fault;
44883 + } else
44884 + path_fault = "<path too long>";
44885 + }
44886 + } else
44887 + path_fault = "<anonymous mapping>";
44888 + }
44889 + up_read(&mm->mmap_sem);
44890 + }
44891 + if (tsk->signal->curr_ip)
44892 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44893 + else
44894 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44895 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44896 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44897 + task_uid(tsk), task_euid(tsk), pc, sp);
44898 + free_page((unsigned long)buffer_exec);
44899 + free_page((unsigned long)buffer_fault);
44900 + pax_report_insns(regs, pc, sp);
44901 + do_coredump(SIGKILL, SIGKILL, regs);
44902 +}
44903 +#endif
44904 +
44905 +#ifdef CONFIG_PAX_REFCOUNT
44906 +void pax_report_refcount_overflow(struct pt_regs *regs)
44907 +{
44908 + if (current->signal->curr_ip)
44909 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44910 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44911 + else
44912 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44913 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44914 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44915 + show_regs(regs);
44916 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44917 +}
44918 +#endif
44919 +
44920 +#ifdef CONFIG_PAX_USERCOPY
44921 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44922 +static noinline int check_stack_object(const void *obj, unsigned long len)
44923 +{
44924 + const void * const stack = task_stack_page(current);
44925 + const void * const stackend = stack + THREAD_SIZE;
44926 +
44927 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44928 + const void *frame = NULL;
44929 + const void *oldframe;
44930 +#endif
44931 +
44932 + if (obj + len < obj)
44933 + return -1;
44934 +
44935 + if (obj + len <= stack || stackend <= obj)
44936 + return 0;
44937 +
44938 + if (obj < stack || stackend < obj + len)
44939 + return -1;
44940 +
44941 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44942 + oldframe = __builtin_frame_address(1);
44943 + if (oldframe)
44944 + frame = __builtin_frame_address(2);
44945 + /*
44946 + low ----------------------------------------------> high
44947 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44948 + ^----------------^
44949 + allow copies only within here
44950 + */
44951 + while (stack <= frame && frame < stackend) {
44952 + /* if obj + len extends past the last frame, this
44953 + check won't pass and the next frame will be 0,
44954 + causing us to bail out and correctly report
44955 + the copy as invalid
44956 + */
44957 + if (obj + len <= frame)
44958 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44959 + oldframe = frame;
44960 + frame = *(const void * const *)frame;
44961 + }
44962 + return -1;
44963 +#else
44964 + return 1;
44965 +#endif
44966 +}
44967 +
44968 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44969 +{
44970 + if (current->signal->curr_ip)
44971 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44972 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44973 + else
44974 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44975 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44976 + dump_stack();
44977 + gr_handle_kernel_exploit();
44978 + do_group_exit(SIGKILL);
44979 +}
44980 +#endif
44981 +
44982 +void check_object_size(const void *ptr, unsigned long n, bool to)
44983 +{
44984 +
44985 +#ifdef CONFIG_PAX_USERCOPY
44986 + const char *type;
44987 +
44988 + if (!n)
44989 + return;
44990 +
44991 + type = check_heap_object(ptr, n, to);
44992 + if (!type) {
44993 + if (check_stack_object(ptr, n) != -1)
44994 + return;
44995 + type = "<process stack>";
44996 + }
44997 +
44998 + pax_report_usercopy(ptr, n, to, type);
44999 +#endif
45000 +
45001 +}
45002 +EXPORT_SYMBOL(check_object_size);
45003 +
45004 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45005 +void pax_track_stack(void)
45006 +{
45007 + unsigned long sp = (unsigned long)&sp;
45008 + if (sp < current_thread_info()->lowest_stack &&
45009 + sp > (unsigned long)task_stack_page(current))
45010 + current_thread_info()->lowest_stack = sp;
45011 +}
45012 +EXPORT_SYMBOL(pax_track_stack);
45013 +#endif
45014 +
45015 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45016 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45017 +{
45018 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45019 + dump_stack();
45020 + do_group_exit(SIGKILL);
45021 +}
45022 +EXPORT_SYMBOL(report_size_overflow);
45023 +#endif
45024 +
45025 static int zap_process(struct task_struct *start, int exit_code)
45026 {
45027 struct task_struct *t;
45028 @@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
45029 void set_dumpable(struct mm_struct *mm, int value)
45030 {
45031 switch (value) {
45032 - case 0:
45033 + case SUID_DUMPABLE_DISABLED:
45034 clear_bit(MMF_DUMPABLE, &mm->flags);
45035 smp_wmb();
45036 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45037 break;
45038 - case 1:
45039 + case SUID_DUMPABLE_ENABLED:
45040 set_bit(MMF_DUMPABLE, &mm->flags);
45041 smp_wmb();
45042 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45043 break;
45044 - case 2:
45045 + case SUID_DUMPABLE_SAFE:
45046 set_bit(MMF_DUMP_SECURELY, &mm->flags);
45047 smp_wmb();
45048 set_bit(MMF_DUMPABLE, &mm->flags);
45049 @@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
45050 int ret;
45051
45052 ret = mm_flags & MMF_DUMPABLE_MASK;
45053 - return (ret >= 2) ? 2 : ret;
45054 + return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
45055 }
45056
45057 int get_dumpable(struct mm_struct *mm)
45058 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45059 pipe = file->f_path.dentry->d_inode->i_pipe;
45060
45061 pipe_lock(pipe);
45062 - pipe->readers++;
45063 - pipe->writers--;
45064 + atomic_inc(&pipe->readers);
45065 + atomic_dec(&pipe->writers);
45066
45067 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45068 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45069 wake_up_interruptible_sync(&pipe->wait);
45070 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45071 pipe_wait(pipe);
45072 }
45073
45074 - pipe->readers--;
45075 - pipe->writers++;
45076 + atomic_dec(&pipe->readers);
45077 + atomic_inc(&pipe->writers);
45078 pipe_unlock(pipe);
45079
45080 }
45081 @@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45082 int retval = 0;
45083 int flag = 0;
45084 int ispipe;
45085 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45086 + bool need_nonrelative = false;
45087 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45088 struct coredump_params cprm = {
45089 .signr = signr,
45090 .regs = regs,
45091 @@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45092
45093 audit_core_dumps(signr);
45094
45095 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45096 + gr_handle_brute_attach(current, cprm.mm_flags);
45097 +
45098 binfmt = mm->binfmt;
45099 if (!binfmt || !binfmt->core_dump)
45100 goto fail;
45101 @@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45102 if (!cred)
45103 goto fail;
45104 /*
45105 - * We cannot trust fsuid as being the "true" uid of the
45106 - * process nor do we know its entire history. We only know it
45107 - * was tainted so we dump it as root in mode 2.
45108 + * We cannot trust fsuid as being the "true" uid of the process
45109 + * nor do we know its entire history. We only know it was tainted
45110 + * so we dump it as root in mode 2, and only into a controlled
45111 + * environment (pipe handler or fully qualified path).
45112 */
45113 - if (__get_dumpable(cprm.mm_flags) == 2) {
45114 + if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
45115 /* Setuid core dump mode */
45116 flag = O_EXCL; /* Stop rewrite attacks */
45117 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
45118 + need_nonrelative = true;
45119 }
45120
45121 retval = coredump_wait(exit_code, &core_state);
45122 @@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45123 }
45124 cprm.limit = RLIM_INFINITY;
45125
45126 - dump_count = atomic_inc_return(&core_dump_count);
45127 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45128 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45129 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45130 task_tgid_vnr(current), current->comm);
45131 @@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45132 } else {
45133 struct inode *inode;
45134
45135 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45136 +
45137 if (cprm.limit < binfmt->min_coredump)
45138 goto fail_unlock;
45139
45140 + if (need_nonrelative && cn.corename[0] != '/') {
45141 + printk(KERN_WARNING "Pid %d(%s) can only dump core "\
45142 + "to fully qualified path!\n",
45143 + task_tgid_vnr(current), current->comm);
45144 + printk(KERN_WARNING "Skipping core dump\n");
45145 + goto fail_unlock;
45146 + }
45147 +
45148 cprm.file = filp_open(cn.corename,
45149 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
45150 0600);
45151 @@ -2263,7 +2655,7 @@ close_fail:
45152 filp_close(cprm.file, NULL);
45153 fail_dropcount:
45154 if (ispipe)
45155 - atomic_dec(&core_dump_count);
45156 + atomic_dec_unchecked(&core_dump_count);
45157 fail_unlock:
45158 kfree(cn.corename);
45159 fail_corename:
45160 @@ -2282,7 +2674,7 @@ fail:
45161 */
45162 int dump_write(struct file *file, const void *addr, int nr)
45163 {
45164 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45165 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45166 }
45167 EXPORT_SYMBOL(dump_write);
45168
45169 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45170 index 1c36139..cf6b350 100644
45171 --- a/fs/ext2/balloc.c
45172 +++ b/fs/ext2/balloc.c
45173 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45174
45175 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45176 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45177 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45178 + if (free_blocks < root_blocks + 1 &&
45179 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45180 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45181 - !in_group_p (sbi->s_resgid))) {
45182 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45183 return 0;
45184 }
45185 return 1;
45186 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45187 index 25cd608..9ed5294 100644
45188 --- a/fs/ext3/balloc.c
45189 +++ b/fs/ext3/balloc.c
45190 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45191
45192 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45193 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45194 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45195 + if (free_blocks < root_blocks + 1 &&
45196 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45197 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45198 - !in_group_p (sbi->s_resgid))) {
45199 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45200 return 0;
45201 }
45202 return 1;
45203 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45204 index 1b50890..e56c5ad 100644
45205 --- a/fs/ext4/balloc.c
45206 +++ b/fs/ext4/balloc.c
45207 @@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45208 /* Hm, nope. Are (enough) root reserved clusters available? */
45209 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45210 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45211 - capable(CAP_SYS_RESOURCE) ||
45212 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45213 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45214 + capable_nolog(CAP_SYS_RESOURCE)) {
45215
45216 if (free_clusters >= (nclusters + dirty_clusters))
45217 return 1;
45218 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45219 index 01434f2..bd995b4 100644
45220 --- a/fs/ext4/ext4.h
45221 +++ b/fs/ext4/ext4.h
45222 @@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45223 unsigned long s_mb_last_start;
45224
45225 /* stats for buddy allocator */
45226 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45227 - atomic_t s_bal_success; /* we found long enough chunks */
45228 - atomic_t s_bal_allocated; /* in blocks */
45229 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45230 - atomic_t s_bal_goals; /* goal hits */
45231 - atomic_t s_bal_breaks; /* too long searches */
45232 - atomic_t s_bal_2orders; /* 2^order hits */
45233 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45234 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45235 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45236 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45237 + atomic_unchecked_t s_bal_goals; /* goal hits */
45238 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45239 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45240 spinlock_t s_bal_lock;
45241 unsigned long s_mb_buddies_generated;
45242 unsigned long long s_mb_generation_time;
45243 - atomic_t s_mb_lost_chunks;
45244 - atomic_t s_mb_preallocated;
45245 - atomic_t s_mb_discarded;
45246 + atomic_unchecked_t s_mb_lost_chunks;
45247 + atomic_unchecked_t s_mb_preallocated;
45248 + atomic_unchecked_t s_mb_discarded;
45249 atomic_t s_lock_busy;
45250
45251 /* locality groups */
45252 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45253 index 1cd6994..5799d45 100644
45254 --- a/fs/ext4/mballoc.c
45255 +++ b/fs/ext4/mballoc.c
45256 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45257 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45258
45259 if (EXT4_SB(sb)->s_mb_stats)
45260 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45261 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45262
45263 break;
45264 }
45265 @@ -2041,7 +2041,7 @@ repeat:
45266 ac->ac_status = AC_STATUS_CONTINUE;
45267 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45268 cr = 3;
45269 - atomic_inc(&sbi->s_mb_lost_chunks);
45270 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45271 goto repeat;
45272 }
45273 }
45274 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45275 if (sbi->s_mb_stats) {
45276 ext4_msg(sb, KERN_INFO,
45277 "mballoc: %u blocks %u reqs (%u success)",
45278 - atomic_read(&sbi->s_bal_allocated),
45279 - atomic_read(&sbi->s_bal_reqs),
45280 - atomic_read(&sbi->s_bal_success));
45281 + atomic_read_unchecked(&sbi->s_bal_allocated),
45282 + atomic_read_unchecked(&sbi->s_bal_reqs),
45283 + atomic_read_unchecked(&sbi->s_bal_success));
45284 ext4_msg(sb, KERN_INFO,
45285 "mballoc: %u extents scanned, %u goal hits, "
45286 "%u 2^N hits, %u breaks, %u lost",
45287 - atomic_read(&sbi->s_bal_ex_scanned),
45288 - atomic_read(&sbi->s_bal_goals),
45289 - atomic_read(&sbi->s_bal_2orders),
45290 - atomic_read(&sbi->s_bal_breaks),
45291 - atomic_read(&sbi->s_mb_lost_chunks));
45292 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45293 + atomic_read_unchecked(&sbi->s_bal_goals),
45294 + atomic_read_unchecked(&sbi->s_bal_2orders),
45295 + atomic_read_unchecked(&sbi->s_bal_breaks),
45296 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45297 ext4_msg(sb, KERN_INFO,
45298 "mballoc: %lu generated and it took %Lu",
45299 sbi->s_mb_buddies_generated,
45300 sbi->s_mb_generation_time);
45301 ext4_msg(sb, KERN_INFO,
45302 "mballoc: %u preallocated, %u discarded",
45303 - atomic_read(&sbi->s_mb_preallocated),
45304 - atomic_read(&sbi->s_mb_discarded));
45305 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45306 + atomic_read_unchecked(&sbi->s_mb_discarded));
45307 }
45308
45309 free_percpu(sbi->s_locality_groups);
45310 @@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45311 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45312
45313 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45314 - atomic_inc(&sbi->s_bal_reqs);
45315 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45316 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45317 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45318 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45319 - atomic_inc(&sbi->s_bal_success);
45320 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45321 + atomic_inc_unchecked(&sbi->s_bal_success);
45322 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45323 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45324 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45325 - atomic_inc(&sbi->s_bal_goals);
45326 + atomic_inc_unchecked(&sbi->s_bal_goals);
45327 if (ac->ac_found > sbi->s_mb_max_to_scan)
45328 - atomic_inc(&sbi->s_bal_breaks);
45329 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45330 }
45331
45332 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45333 @@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45334 trace_ext4_mb_new_inode_pa(ac, pa);
45335
45336 ext4_mb_use_inode_pa(ac, pa);
45337 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45338 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45339
45340 ei = EXT4_I(ac->ac_inode);
45341 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45342 @@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45343 trace_ext4_mb_new_group_pa(ac, pa);
45344
45345 ext4_mb_use_group_pa(ac, pa);
45346 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45347 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45348
45349 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45350 lg = ac->ac_lg;
45351 @@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45352 * from the bitmap and continue.
45353 */
45354 }
45355 - atomic_add(free, &sbi->s_mb_discarded);
45356 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45357
45358 return err;
45359 }
45360 @@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45361 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45362 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45363 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45364 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45365 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45366 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45367
45368 return 0;
45369 diff --git a/fs/fcntl.c b/fs/fcntl.c
45370 index 81b70e6..d9ae6cf 100644
45371 --- a/fs/fcntl.c
45372 +++ b/fs/fcntl.c
45373 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45374 if (err)
45375 return err;
45376
45377 + if (gr_handle_chroot_fowner(pid, type))
45378 + return -ENOENT;
45379 + if (gr_check_protected_task_fowner(pid, type))
45380 + return -EACCES;
45381 +
45382 f_modown(filp, pid, type, force);
45383 return 0;
45384 }
45385 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45386
45387 static int f_setown_ex(struct file *filp, unsigned long arg)
45388 {
45389 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45390 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45391 struct f_owner_ex owner;
45392 struct pid *pid;
45393 int type;
45394 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45395
45396 static int f_getown_ex(struct file *filp, unsigned long arg)
45397 {
45398 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45399 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45400 struct f_owner_ex owner;
45401 int ret = 0;
45402
45403 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45404 switch (cmd) {
45405 case F_DUPFD:
45406 case F_DUPFD_CLOEXEC:
45407 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45408 if (arg >= rlimit(RLIMIT_NOFILE))
45409 break;
45410 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45411 diff --git a/fs/fifo.c b/fs/fifo.c
45412 index cf6f434..3d7942c 100644
45413 --- a/fs/fifo.c
45414 +++ b/fs/fifo.c
45415 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45416 */
45417 filp->f_op = &read_pipefifo_fops;
45418 pipe->r_counter++;
45419 - if (pipe->readers++ == 0)
45420 + if (atomic_inc_return(&pipe->readers) == 1)
45421 wake_up_partner(inode);
45422
45423 - if (!pipe->writers) {
45424 + if (!atomic_read(&pipe->writers)) {
45425 if ((filp->f_flags & O_NONBLOCK)) {
45426 /* suppress POLLHUP until we have
45427 * seen a writer */
45428 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45429 * errno=ENXIO when there is no process reading the FIFO.
45430 */
45431 ret = -ENXIO;
45432 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45433 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45434 goto err;
45435
45436 filp->f_op = &write_pipefifo_fops;
45437 pipe->w_counter++;
45438 - if (!pipe->writers++)
45439 + if (atomic_inc_return(&pipe->writers) == 1)
45440 wake_up_partner(inode);
45441
45442 - if (!pipe->readers) {
45443 + if (!atomic_read(&pipe->readers)) {
45444 if (wait_for_partner(inode, &pipe->r_counter))
45445 goto err_wr;
45446 }
45447 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45448 */
45449 filp->f_op = &rdwr_pipefifo_fops;
45450
45451 - pipe->readers++;
45452 - pipe->writers++;
45453 + atomic_inc(&pipe->readers);
45454 + atomic_inc(&pipe->writers);
45455 pipe->r_counter++;
45456 pipe->w_counter++;
45457 - if (pipe->readers == 1 || pipe->writers == 1)
45458 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45459 wake_up_partner(inode);
45460 break;
45461
45462 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45463 return 0;
45464
45465 err_rd:
45466 - if (!--pipe->readers)
45467 + if (atomic_dec_and_test(&pipe->readers))
45468 wake_up_interruptible(&pipe->wait);
45469 ret = -ERESTARTSYS;
45470 goto err;
45471
45472 err_wr:
45473 - if (!--pipe->writers)
45474 + if (atomic_dec_and_test(&pipe->writers))
45475 wake_up_interruptible(&pipe->wait);
45476 ret = -ERESTARTSYS;
45477 goto err;
45478
45479 err:
45480 - if (!pipe->readers && !pipe->writers)
45481 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45482 free_pipe_info(inode);
45483
45484 err_nocleanup:
45485 diff --git a/fs/file.c b/fs/file.c
45486 index ba3f605..fade102 100644
45487 --- a/fs/file.c
45488 +++ b/fs/file.c
45489 @@ -15,6 +15,7 @@
45490 #include <linux/slab.h>
45491 #include <linux/vmalloc.h>
45492 #include <linux/file.h>
45493 +#include <linux/security.h>
45494 #include <linux/fdtable.h>
45495 #include <linux/bitops.h>
45496 #include <linux/interrupt.h>
45497 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45498 * N.B. For clone tasks sharing a files structure, this test
45499 * will limit the total number of files that can be opened.
45500 */
45501 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45502 if (nr >= rlimit(RLIMIT_NOFILE))
45503 return -EMFILE;
45504
45505 diff --git a/fs/filesystems.c b/fs/filesystems.c
45506 index 96f2428..f5eeb8e 100644
45507 --- a/fs/filesystems.c
45508 +++ b/fs/filesystems.c
45509 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45510 int len = dot ? dot - name : strlen(name);
45511
45512 fs = __get_fs_type(name, len);
45513 +
45514 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45515 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45516 +#else
45517 if (!fs && (request_module("%.*s", len, name) == 0))
45518 +#endif
45519 fs = __get_fs_type(name, len);
45520
45521 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45522 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45523 index e159e68..e7d2a6f 100644
45524 --- a/fs/fs_struct.c
45525 +++ b/fs/fs_struct.c
45526 @@ -4,6 +4,7 @@
45527 #include <linux/path.h>
45528 #include <linux/slab.h>
45529 #include <linux/fs_struct.h>
45530 +#include <linux/grsecurity.h>
45531 #include "internal.h"
45532
45533 static inline void path_get_longterm(struct path *path)
45534 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45535 write_seqcount_begin(&fs->seq);
45536 old_root = fs->root;
45537 fs->root = *path;
45538 + gr_set_chroot_entries(current, path);
45539 write_seqcount_end(&fs->seq);
45540 spin_unlock(&fs->lock);
45541 if (old_root.dentry)
45542 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45543 return 1;
45544 }
45545
45546 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45547 +{
45548 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45549 + return 0;
45550 + *p = *new;
45551 +
45552 + gr_set_chroot_entries(task, new);
45553 +
45554 + return 1;
45555 +}
45556 +
45557 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45558 {
45559 struct task_struct *g, *p;
45560 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45561 int hits = 0;
45562 spin_lock(&fs->lock);
45563 write_seqcount_begin(&fs->seq);
45564 - hits += replace_path(&fs->root, old_root, new_root);
45565 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45566 hits += replace_path(&fs->pwd, old_root, new_root);
45567 write_seqcount_end(&fs->seq);
45568 while (hits--) {
45569 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45570 task_lock(tsk);
45571 spin_lock(&fs->lock);
45572 tsk->fs = NULL;
45573 - kill = !--fs->users;
45574 + gr_clear_chroot_entries(tsk);
45575 + kill = !atomic_dec_return(&fs->users);
45576 spin_unlock(&fs->lock);
45577 task_unlock(tsk);
45578 if (kill)
45579 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45580 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45581 /* We don't need to lock fs - think why ;-) */
45582 if (fs) {
45583 - fs->users = 1;
45584 + atomic_set(&fs->users, 1);
45585 fs->in_exec = 0;
45586 spin_lock_init(&fs->lock);
45587 seqcount_init(&fs->seq);
45588 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45589 spin_lock(&old->lock);
45590 fs->root = old->root;
45591 path_get_longterm(&fs->root);
45592 + /* instead of calling gr_set_chroot_entries here,
45593 + we call it from every caller of this function
45594 + */
45595 fs->pwd = old->pwd;
45596 path_get_longterm(&fs->pwd);
45597 spin_unlock(&old->lock);
45598 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45599
45600 task_lock(current);
45601 spin_lock(&fs->lock);
45602 - kill = !--fs->users;
45603 + kill = !atomic_dec_return(&fs->users);
45604 current->fs = new_fs;
45605 + gr_set_chroot_entries(current, &new_fs->root);
45606 spin_unlock(&fs->lock);
45607 task_unlock(current);
45608
45609 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45610
45611 int current_umask(void)
45612 {
45613 - return current->fs->umask;
45614 + return current->fs->umask | gr_acl_umask();
45615 }
45616 EXPORT_SYMBOL(current_umask);
45617
45618 /* to be mentioned only in INIT_TASK */
45619 struct fs_struct init_fs = {
45620 - .users = 1,
45621 + .users = ATOMIC_INIT(1),
45622 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45623 .seq = SEQCNT_ZERO,
45624 .umask = 0022,
45625 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45626 task_lock(current);
45627
45628 spin_lock(&init_fs.lock);
45629 - init_fs.users++;
45630 + atomic_inc(&init_fs.users);
45631 spin_unlock(&init_fs.lock);
45632
45633 spin_lock(&fs->lock);
45634 current->fs = &init_fs;
45635 - kill = !--fs->users;
45636 + gr_set_chroot_entries(current, &current->fs->root);
45637 + kill = !atomic_dec_return(&fs->users);
45638 spin_unlock(&fs->lock);
45639
45640 task_unlock(current);
45641 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45642 index 9905350..02eaec4 100644
45643 --- a/fs/fscache/cookie.c
45644 +++ b/fs/fscache/cookie.c
45645 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45646 parent ? (char *) parent->def->name : "<no-parent>",
45647 def->name, netfs_data);
45648
45649 - fscache_stat(&fscache_n_acquires);
45650 + fscache_stat_unchecked(&fscache_n_acquires);
45651
45652 /* if there's no parent cookie, then we don't create one here either */
45653 if (!parent) {
45654 - fscache_stat(&fscache_n_acquires_null);
45655 + fscache_stat_unchecked(&fscache_n_acquires_null);
45656 _leave(" [no parent]");
45657 return NULL;
45658 }
45659 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45660 /* allocate and initialise a cookie */
45661 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45662 if (!cookie) {
45663 - fscache_stat(&fscache_n_acquires_oom);
45664 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45665 _leave(" [ENOMEM]");
45666 return NULL;
45667 }
45668 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45669
45670 switch (cookie->def->type) {
45671 case FSCACHE_COOKIE_TYPE_INDEX:
45672 - fscache_stat(&fscache_n_cookie_index);
45673 + fscache_stat_unchecked(&fscache_n_cookie_index);
45674 break;
45675 case FSCACHE_COOKIE_TYPE_DATAFILE:
45676 - fscache_stat(&fscache_n_cookie_data);
45677 + fscache_stat_unchecked(&fscache_n_cookie_data);
45678 break;
45679 default:
45680 - fscache_stat(&fscache_n_cookie_special);
45681 + fscache_stat_unchecked(&fscache_n_cookie_special);
45682 break;
45683 }
45684
45685 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45686 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45687 atomic_dec(&parent->n_children);
45688 __fscache_cookie_put(cookie);
45689 - fscache_stat(&fscache_n_acquires_nobufs);
45690 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45691 _leave(" = NULL");
45692 return NULL;
45693 }
45694 }
45695
45696 - fscache_stat(&fscache_n_acquires_ok);
45697 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45698 _leave(" = %p", cookie);
45699 return cookie;
45700 }
45701 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45702 cache = fscache_select_cache_for_object(cookie->parent);
45703 if (!cache) {
45704 up_read(&fscache_addremove_sem);
45705 - fscache_stat(&fscache_n_acquires_no_cache);
45706 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45707 _leave(" = -ENOMEDIUM [no cache]");
45708 return -ENOMEDIUM;
45709 }
45710 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45711 object = cache->ops->alloc_object(cache, cookie);
45712 fscache_stat_d(&fscache_n_cop_alloc_object);
45713 if (IS_ERR(object)) {
45714 - fscache_stat(&fscache_n_object_no_alloc);
45715 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45716 ret = PTR_ERR(object);
45717 goto error;
45718 }
45719
45720 - fscache_stat(&fscache_n_object_alloc);
45721 + fscache_stat_unchecked(&fscache_n_object_alloc);
45722
45723 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45724
45725 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45726 struct fscache_object *object;
45727 struct hlist_node *_p;
45728
45729 - fscache_stat(&fscache_n_updates);
45730 + fscache_stat_unchecked(&fscache_n_updates);
45731
45732 if (!cookie) {
45733 - fscache_stat(&fscache_n_updates_null);
45734 + fscache_stat_unchecked(&fscache_n_updates_null);
45735 _leave(" [no cookie]");
45736 return;
45737 }
45738 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45739 struct fscache_object *object;
45740 unsigned long event;
45741
45742 - fscache_stat(&fscache_n_relinquishes);
45743 + fscache_stat_unchecked(&fscache_n_relinquishes);
45744 if (retire)
45745 - fscache_stat(&fscache_n_relinquishes_retire);
45746 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45747
45748 if (!cookie) {
45749 - fscache_stat(&fscache_n_relinquishes_null);
45750 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45751 _leave(" [no cookie]");
45752 return;
45753 }
45754 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45755
45756 /* wait for the cookie to finish being instantiated (or to fail) */
45757 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45758 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45759 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45760 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45761 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45762 }
45763 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45764 index f6aad48..88dcf26 100644
45765 --- a/fs/fscache/internal.h
45766 +++ b/fs/fscache/internal.h
45767 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45768 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45769 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45770
45771 -extern atomic_t fscache_n_op_pend;
45772 -extern atomic_t fscache_n_op_run;
45773 -extern atomic_t fscache_n_op_enqueue;
45774 -extern atomic_t fscache_n_op_deferred_release;
45775 -extern atomic_t fscache_n_op_release;
45776 -extern atomic_t fscache_n_op_gc;
45777 -extern atomic_t fscache_n_op_cancelled;
45778 -extern atomic_t fscache_n_op_rejected;
45779 +extern atomic_unchecked_t fscache_n_op_pend;
45780 +extern atomic_unchecked_t fscache_n_op_run;
45781 +extern atomic_unchecked_t fscache_n_op_enqueue;
45782 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45783 +extern atomic_unchecked_t fscache_n_op_release;
45784 +extern atomic_unchecked_t fscache_n_op_gc;
45785 +extern atomic_unchecked_t fscache_n_op_cancelled;
45786 +extern atomic_unchecked_t fscache_n_op_rejected;
45787
45788 -extern atomic_t fscache_n_attr_changed;
45789 -extern atomic_t fscache_n_attr_changed_ok;
45790 -extern atomic_t fscache_n_attr_changed_nobufs;
45791 -extern atomic_t fscache_n_attr_changed_nomem;
45792 -extern atomic_t fscache_n_attr_changed_calls;
45793 +extern atomic_unchecked_t fscache_n_attr_changed;
45794 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45795 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45796 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45797 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45798
45799 -extern atomic_t fscache_n_allocs;
45800 -extern atomic_t fscache_n_allocs_ok;
45801 -extern atomic_t fscache_n_allocs_wait;
45802 -extern atomic_t fscache_n_allocs_nobufs;
45803 -extern atomic_t fscache_n_allocs_intr;
45804 -extern atomic_t fscache_n_allocs_object_dead;
45805 -extern atomic_t fscache_n_alloc_ops;
45806 -extern atomic_t fscache_n_alloc_op_waits;
45807 +extern atomic_unchecked_t fscache_n_allocs;
45808 +extern atomic_unchecked_t fscache_n_allocs_ok;
45809 +extern atomic_unchecked_t fscache_n_allocs_wait;
45810 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45811 +extern atomic_unchecked_t fscache_n_allocs_intr;
45812 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45813 +extern atomic_unchecked_t fscache_n_alloc_ops;
45814 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45815
45816 -extern atomic_t fscache_n_retrievals;
45817 -extern atomic_t fscache_n_retrievals_ok;
45818 -extern atomic_t fscache_n_retrievals_wait;
45819 -extern atomic_t fscache_n_retrievals_nodata;
45820 -extern atomic_t fscache_n_retrievals_nobufs;
45821 -extern atomic_t fscache_n_retrievals_intr;
45822 -extern atomic_t fscache_n_retrievals_nomem;
45823 -extern atomic_t fscache_n_retrievals_object_dead;
45824 -extern atomic_t fscache_n_retrieval_ops;
45825 -extern atomic_t fscache_n_retrieval_op_waits;
45826 +extern atomic_unchecked_t fscache_n_retrievals;
45827 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45828 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45829 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45830 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45831 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45832 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45833 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45834 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45835 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45836
45837 -extern atomic_t fscache_n_stores;
45838 -extern atomic_t fscache_n_stores_ok;
45839 -extern atomic_t fscache_n_stores_again;
45840 -extern atomic_t fscache_n_stores_nobufs;
45841 -extern atomic_t fscache_n_stores_oom;
45842 -extern atomic_t fscache_n_store_ops;
45843 -extern atomic_t fscache_n_store_calls;
45844 -extern atomic_t fscache_n_store_pages;
45845 -extern atomic_t fscache_n_store_radix_deletes;
45846 -extern atomic_t fscache_n_store_pages_over_limit;
45847 +extern atomic_unchecked_t fscache_n_stores;
45848 +extern atomic_unchecked_t fscache_n_stores_ok;
45849 +extern atomic_unchecked_t fscache_n_stores_again;
45850 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45851 +extern atomic_unchecked_t fscache_n_stores_oom;
45852 +extern atomic_unchecked_t fscache_n_store_ops;
45853 +extern atomic_unchecked_t fscache_n_store_calls;
45854 +extern atomic_unchecked_t fscache_n_store_pages;
45855 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45856 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45857
45858 -extern atomic_t fscache_n_store_vmscan_not_storing;
45859 -extern atomic_t fscache_n_store_vmscan_gone;
45860 -extern atomic_t fscache_n_store_vmscan_busy;
45861 -extern atomic_t fscache_n_store_vmscan_cancelled;
45862 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45863 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45864 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45865 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45866
45867 -extern atomic_t fscache_n_marks;
45868 -extern atomic_t fscache_n_uncaches;
45869 +extern atomic_unchecked_t fscache_n_marks;
45870 +extern atomic_unchecked_t fscache_n_uncaches;
45871
45872 -extern atomic_t fscache_n_acquires;
45873 -extern atomic_t fscache_n_acquires_null;
45874 -extern atomic_t fscache_n_acquires_no_cache;
45875 -extern atomic_t fscache_n_acquires_ok;
45876 -extern atomic_t fscache_n_acquires_nobufs;
45877 -extern atomic_t fscache_n_acquires_oom;
45878 +extern atomic_unchecked_t fscache_n_acquires;
45879 +extern atomic_unchecked_t fscache_n_acquires_null;
45880 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45881 +extern atomic_unchecked_t fscache_n_acquires_ok;
45882 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45883 +extern atomic_unchecked_t fscache_n_acquires_oom;
45884
45885 -extern atomic_t fscache_n_updates;
45886 -extern atomic_t fscache_n_updates_null;
45887 -extern atomic_t fscache_n_updates_run;
45888 +extern atomic_unchecked_t fscache_n_updates;
45889 +extern atomic_unchecked_t fscache_n_updates_null;
45890 +extern atomic_unchecked_t fscache_n_updates_run;
45891
45892 -extern atomic_t fscache_n_relinquishes;
45893 -extern atomic_t fscache_n_relinquishes_null;
45894 -extern atomic_t fscache_n_relinquishes_waitcrt;
45895 -extern atomic_t fscache_n_relinquishes_retire;
45896 +extern atomic_unchecked_t fscache_n_relinquishes;
45897 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45898 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45899 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45900
45901 -extern atomic_t fscache_n_cookie_index;
45902 -extern atomic_t fscache_n_cookie_data;
45903 -extern atomic_t fscache_n_cookie_special;
45904 +extern atomic_unchecked_t fscache_n_cookie_index;
45905 +extern atomic_unchecked_t fscache_n_cookie_data;
45906 +extern atomic_unchecked_t fscache_n_cookie_special;
45907
45908 -extern atomic_t fscache_n_object_alloc;
45909 -extern atomic_t fscache_n_object_no_alloc;
45910 -extern atomic_t fscache_n_object_lookups;
45911 -extern atomic_t fscache_n_object_lookups_negative;
45912 -extern atomic_t fscache_n_object_lookups_positive;
45913 -extern atomic_t fscache_n_object_lookups_timed_out;
45914 -extern atomic_t fscache_n_object_created;
45915 -extern atomic_t fscache_n_object_avail;
45916 -extern atomic_t fscache_n_object_dead;
45917 +extern atomic_unchecked_t fscache_n_object_alloc;
45918 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45919 +extern atomic_unchecked_t fscache_n_object_lookups;
45920 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45921 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45922 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45923 +extern atomic_unchecked_t fscache_n_object_created;
45924 +extern atomic_unchecked_t fscache_n_object_avail;
45925 +extern atomic_unchecked_t fscache_n_object_dead;
45926
45927 -extern atomic_t fscache_n_checkaux_none;
45928 -extern atomic_t fscache_n_checkaux_okay;
45929 -extern atomic_t fscache_n_checkaux_update;
45930 -extern atomic_t fscache_n_checkaux_obsolete;
45931 +extern atomic_unchecked_t fscache_n_checkaux_none;
45932 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45933 +extern atomic_unchecked_t fscache_n_checkaux_update;
45934 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45935
45936 extern atomic_t fscache_n_cop_alloc_object;
45937 extern atomic_t fscache_n_cop_lookup_object;
45938 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45939 atomic_inc(stat);
45940 }
45941
45942 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45943 +{
45944 + atomic_inc_unchecked(stat);
45945 +}
45946 +
45947 static inline void fscache_stat_d(atomic_t *stat)
45948 {
45949 atomic_dec(stat);
45950 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45951
45952 #define __fscache_stat(stat) (NULL)
45953 #define fscache_stat(stat) do {} while (0)
45954 +#define fscache_stat_unchecked(stat) do {} while (0)
45955 #define fscache_stat_d(stat) do {} while (0)
45956 #endif
45957
45958 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45959 index b6b897c..0ffff9c 100644
45960 --- a/fs/fscache/object.c
45961 +++ b/fs/fscache/object.c
45962 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45963 /* update the object metadata on disk */
45964 case FSCACHE_OBJECT_UPDATING:
45965 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45966 - fscache_stat(&fscache_n_updates_run);
45967 + fscache_stat_unchecked(&fscache_n_updates_run);
45968 fscache_stat(&fscache_n_cop_update_object);
45969 object->cache->ops->update_object(object);
45970 fscache_stat_d(&fscache_n_cop_update_object);
45971 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45972 spin_lock(&object->lock);
45973 object->state = FSCACHE_OBJECT_DEAD;
45974 spin_unlock(&object->lock);
45975 - fscache_stat(&fscache_n_object_dead);
45976 + fscache_stat_unchecked(&fscache_n_object_dead);
45977 goto terminal_transit;
45978
45979 /* handle the parent cache of this object being withdrawn from
45980 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45981 spin_lock(&object->lock);
45982 object->state = FSCACHE_OBJECT_DEAD;
45983 spin_unlock(&object->lock);
45984 - fscache_stat(&fscache_n_object_dead);
45985 + fscache_stat_unchecked(&fscache_n_object_dead);
45986 goto terminal_transit;
45987
45988 /* complain about the object being woken up once it is
45989 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45990 parent->cookie->def->name, cookie->def->name,
45991 object->cache->tag->name);
45992
45993 - fscache_stat(&fscache_n_object_lookups);
45994 + fscache_stat_unchecked(&fscache_n_object_lookups);
45995 fscache_stat(&fscache_n_cop_lookup_object);
45996 ret = object->cache->ops->lookup_object(object);
45997 fscache_stat_d(&fscache_n_cop_lookup_object);
45998 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45999 if (ret == -ETIMEDOUT) {
46000 /* probably stuck behind another object, so move this one to
46001 * the back of the queue */
46002 - fscache_stat(&fscache_n_object_lookups_timed_out);
46003 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46004 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46005 }
46006
46007 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46008
46009 spin_lock(&object->lock);
46010 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46011 - fscache_stat(&fscache_n_object_lookups_negative);
46012 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46013
46014 /* transit here to allow write requests to begin stacking up
46015 * and read requests to begin returning ENODATA */
46016 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46017 * result, in which case there may be data available */
46018 spin_lock(&object->lock);
46019 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46020 - fscache_stat(&fscache_n_object_lookups_positive);
46021 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46022
46023 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46024
46025 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46026 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46027 } else {
46028 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46029 - fscache_stat(&fscache_n_object_created);
46030 + fscache_stat_unchecked(&fscache_n_object_created);
46031
46032 object->state = FSCACHE_OBJECT_AVAILABLE;
46033 spin_unlock(&object->lock);
46034 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46035 fscache_enqueue_dependents(object);
46036
46037 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46038 - fscache_stat(&fscache_n_object_avail);
46039 + fscache_stat_unchecked(&fscache_n_object_avail);
46040
46041 _leave("");
46042 }
46043 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46044 enum fscache_checkaux result;
46045
46046 if (!object->cookie->def->check_aux) {
46047 - fscache_stat(&fscache_n_checkaux_none);
46048 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46049 return FSCACHE_CHECKAUX_OKAY;
46050 }
46051
46052 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46053 switch (result) {
46054 /* entry okay as is */
46055 case FSCACHE_CHECKAUX_OKAY:
46056 - fscache_stat(&fscache_n_checkaux_okay);
46057 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46058 break;
46059
46060 /* entry requires update */
46061 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46062 - fscache_stat(&fscache_n_checkaux_update);
46063 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46064 break;
46065
46066 /* entry requires deletion */
46067 case FSCACHE_CHECKAUX_OBSOLETE:
46068 - fscache_stat(&fscache_n_checkaux_obsolete);
46069 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46070 break;
46071
46072 default:
46073 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46074 index 30afdfa..2256596 100644
46075 --- a/fs/fscache/operation.c
46076 +++ b/fs/fscache/operation.c
46077 @@ -17,7 +17,7 @@
46078 #include <linux/slab.h>
46079 #include "internal.h"
46080
46081 -atomic_t fscache_op_debug_id;
46082 +atomic_unchecked_t fscache_op_debug_id;
46083 EXPORT_SYMBOL(fscache_op_debug_id);
46084
46085 /**
46086 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46087 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46088 ASSERTCMP(atomic_read(&op->usage), >, 0);
46089
46090 - fscache_stat(&fscache_n_op_enqueue);
46091 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46092 switch (op->flags & FSCACHE_OP_TYPE) {
46093 case FSCACHE_OP_ASYNC:
46094 _debug("queue async");
46095 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46096 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46097 if (op->processor)
46098 fscache_enqueue_operation(op);
46099 - fscache_stat(&fscache_n_op_run);
46100 + fscache_stat_unchecked(&fscache_n_op_run);
46101 }
46102
46103 /*
46104 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46105 if (object->n_ops > 1) {
46106 atomic_inc(&op->usage);
46107 list_add_tail(&op->pend_link, &object->pending_ops);
46108 - fscache_stat(&fscache_n_op_pend);
46109 + fscache_stat_unchecked(&fscache_n_op_pend);
46110 } else if (!list_empty(&object->pending_ops)) {
46111 atomic_inc(&op->usage);
46112 list_add_tail(&op->pend_link, &object->pending_ops);
46113 - fscache_stat(&fscache_n_op_pend);
46114 + fscache_stat_unchecked(&fscache_n_op_pend);
46115 fscache_start_operations(object);
46116 } else {
46117 ASSERTCMP(object->n_in_progress, ==, 0);
46118 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46119 object->n_exclusive++; /* reads and writes must wait */
46120 atomic_inc(&op->usage);
46121 list_add_tail(&op->pend_link, &object->pending_ops);
46122 - fscache_stat(&fscache_n_op_pend);
46123 + fscache_stat_unchecked(&fscache_n_op_pend);
46124 ret = 0;
46125 } else {
46126 /* not allowed to submit ops in any other state */
46127 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46128 if (object->n_exclusive > 0) {
46129 atomic_inc(&op->usage);
46130 list_add_tail(&op->pend_link, &object->pending_ops);
46131 - fscache_stat(&fscache_n_op_pend);
46132 + fscache_stat_unchecked(&fscache_n_op_pend);
46133 } else if (!list_empty(&object->pending_ops)) {
46134 atomic_inc(&op->usage);
46135 list_add_tail(&op->pend_link, &object->pending_ops);
46136 - fscache_stat(&fscache_n_op_pend);
46137 + fscache_stat_unchecked(&fscache_n_op_pend);
46138 fscache_start_operations(object);
46139 } else {
46140 ASSERTCMP(object->n_exclusive, ==, 0);
46141 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46142 object->n_ops++;
46143 atomic_inc(&op->usage);
46144 list_add_tail(&op->pend_link, &object->pending_ops);
46145 - fscache_stat(&fscache_n_op_pend);
46146 + fscache_stat_unchecked(&fscache_n_op_pend);
46147 ret = 0;
46148 } else if (object->state == FSCACHE_OBJECT_DYING ||
46149 object->state == FSCACHE_OBJECT_LC_DYING ||
46150 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46151 - fscache_stat(&fscache_n_op_rejected);
46152 + fscache_stat_unchecked(&fscache_n_op_rejected);
46153 ret = -ENOBUFS;
46154 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46155 fscache_report_unexpected_submission(object, op, ostate);
46156 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46157
46158 ret = -EBUSY;
46159 if (!list_empty(&op->pend_link)) {
46160 - fscache_stat(&fscache_n_op_cancelled);
46161 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46162 list_del_init(&op->pend_link);
46163 object->n_ops--;
46164 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46165 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46166 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46167 BUG();
46168
46169 - fscache_stat(&fscache_n_op_release);
46170 + fscache_stat_unchecked(&fscache_n_op_release);
46171
46172 if (op->release) {
46173 op->release(op);
46174 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46175 * lock, and defer it otherwise */
46176 if (!spin_trylock(&object->lock)) {
46177 _debug("defer put");
46178 - fscache_stat(&fscache_n_op_deferred_release);
46179 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46180
46181 cache = object->cache;
46182 spin_lock(&cache->op_gc_list_lock);
46183 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46184
46185 _debug("GC DEFERRED REL OBJ%x OP%x",
46186 object->debug_id, op->debug_id);
46187 - fscache_stat(&fscache_n_op_gc);
46188 + fscache_stat_unchecked(&fscache_n_op_gc);
46189
46190 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46191
46192 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46193 index 3f7a59b..cf196cc 100644
46194 --- a/fs/fscache/page.c
46195 +++ b/fs/fscache/page.c
46196 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46197 val = radix_tree_lookup(&cookie->stores, page->index);
46198 if (!val) {
46199 rcu_read_unlock();
46200 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46201 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46202 __fscache_uncache_page(cookie, page);
46203 return true;
46204 }
46205 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46206 spin_unlock(&cookie->stores_lock);
46207
46208 if (xpage) {
46209 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46210 - fscache_stat(&fscache_n_store_radix_deletes);
46211 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46212 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46213 ASSERTCMP(xpage, ==, page);
46214 } else {
46215 - fscache_stat(&fscache_n_store_vmscan_gone);
46216 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46217 }
46218
46219 wake_up_bit(&cookie->flags, 0);
46220 @@ -107,7 +107,7 @@ page_busy:
46221 /* we might want to wait here, but that could deadlock the allocator as
46222 * the work threads writing to the cache may all end up sleeping
46223 * on memory allocation */
46224 - fscache_stat(&fscache_n_store_vmscan_busy);
46225 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46226 return false;
46227 }
46228 EXPORT_SYMBOL(__fscache_maybe_release_page);
46229 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46230 FSCACHE_COOKIE_STORING_TAG);
46231 if (!radix_tree_tag_get(&cookie->stores, page->index,
46232 FSCACHE_COOKIE_PENDING_TAG)) {
46233 - fscache_stat(&fscache_n_store_radix_deletes);
46234 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46235 xpage = radix_tree_delete(&cookie->stores, page->index);
46236 }
46237 spin_unlock(&cookie->stores_lock);
46238 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46239
46240 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46241
46242 - fscache_stat(&fscache_n_attr_changed_calls);
46243 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46244
46245 if (fscache_object_is_active(object)) {
46246 fscache_stat(&fscache_n_cop_attr_changed);
46247 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46248
46249 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46250
46251 - fscache_stat(&fscache_n_attr_changed);
46252 + fscache_stat_unchecked(&fscache_n_attr_changed);
46253
46254 op = kzalloc(sizeof(*op), GFP_KERNEL);
46255 if (!op) {
46256 - fscache_stat(&fscache_n_attr_changed_nomem);
46257 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46258 _leave(" = -ENOMEM");
46259 return -ENOMEM;
46260 }
46261 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46262 if (fscache_submit_exclusive_op(object, op) < 0)
46263 goto nobufs;
46264 spin_unlock(&cookie->lock);
46265 - fscache_stat(&fscache_n_attr_changed_ok);
46266 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46267 fscache_put_operation(op);
46268 _leave(" = 0");
46269 return 0;
46270 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46271 nobufs:
46272 spin_unlock(&cookie->lock);
46273 kfree(op);
46274 - fscache_stat(&fscache_n_attr_changed_nobufs);
46275 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46276 _leave(" = %d", -ENOBUFS);
46277 return -ENOBUFS;
46278 }
46279 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46280 /* allocate a retrieval operation and attempt to submit it */
46281 op = kzalloc(sizeof(*op), GFP_NOIO);
46282 if (!op) {
46283 - fscache_stat(&fscache_n_retrievals_nomem);
46284 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46285 return NULL;
46286 }
46287
46288 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46289 return 0;
46290 }
46291
46292 - fscache_stat(&fscache_n_retrievals_wait);
46293 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46294
46295 jif = jiffies;
46296 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46297 fscache_wait_bit_interruptible,
46298 TASK_INTERRUPTIBLE) != 0) {
46299 - fscache_stat(&fscache_n_retrievals_intr);
46300 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46301 _leave(" = -ERESTARTSYS");
46302 return -ERESTARTSYS;
46303 }
46304 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46305 */
46306 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46307 struct fscache_retrieval *op,
46308 - atomic_t *stat_op_waits,
46309 - atomic_t *stat_object_dead)
46310 + atomic_unchecked_t *stat_op_waits,
46311 + atomic_unchecked_t *stat_object_dead)
46312 {
46313 int ret;
46314
46315 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46316 goto check_if_dead;
46317
46318 _debug(">>> WT");
46319 - fscache_stat(stat_op_waits);
46320 + fscache_stat_unchecked(stat_op_waits);
46321 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46322 fscache_wait_bit_interruptible,
46323 TASK_INTERRUPTIBLE) < 0) {
46324 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46325
46326 check_if_dead:
46327 if (unlikely(fscache_object_is_dead(object))) {
46328 - fscache_stat(stat_object_dead);
46329 + fscache_stat_unchecked(stat_object_dead);
46330 return -ENOBUFS;
46331 }
46332 return 0;
46333 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46334
46335 _enter("%p,%p,,,", cookie, page);
46336
46337 - fscache_stat(&fscache_n_retrievals);
46338 + fscache_stat_unchecked(&fscache_n_retrievals);
46339
46340 if (hlist_empty(&cookie->backing_objects))
46341 goto nobufs;
46342 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46343 goto nobufs_unlock;
46344 spin_unlock(&cookie->lock);
46345
46346 - fscache_stat(&fscache_n_retrieval_ops);
46347 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46348
46349 /* pin the netfs read context in case we need to do the actual netfs
46350 * read because we've encountered a cache read failure */
46351 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46352
46353 error:
46354 if (ret == -ENOMEM)
46355 - fscache_stat(&fscache_n_retrievals_nomem);
46356 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46357 else if (ret == -ERESTARTSYS)
46358 - fscache_stat(&fscache_n_retrievals_intr);
46359 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46360 else if (ret == -ENODATA)
46361 - fscache_stat(&fscache_n_retrievals_nodata);
46362 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46363 else if (ret < 0)
46364 - fscache_stat(&fscache_n_retrievals_nobufs);
46365 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46366 else
46367 - fscache_stat(&fscache_n_retrievals_ok);
46368 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46369
46370 fscache_put_retrieval(op);
46371 _leave(" = %d", ret);
46372 @@ -429,7 +429,7 @@ nobufs_unlock:
46373 spin_unlock(&cookie->lock);
46374 kfree(op);
46375 nobufs:
46376 - fscache_stat(&fscache_n_retrievals_nobufs);
46377 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46378 _leave(" = -ENOBUFS");
46379 return -ENOBUFS;
46380 }
46381 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46382
46383 _enter("%p,,%d,,,", cookie, *nr_pages);
46384
46385 - fscache_stat(&fscache_n_retrievals);
46386 + fscache_stat_unchecked(&fscache_n_retrievals);
46387
46388 if (hlist_empty(&cookie->backing_objects))
46389 goto nobufs;
46390 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46391 goto nobufs_unlock;
46392 spin_unlock(&cookie->lock);
46393
46394 - fscache_stat(&fscache_n_retrieval_ops);
46395 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46396
46397 /* pin the netfs read context in case we need to do the actual netfs
46398 * read because we've encountered a cache read failure */
46399 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46400
46401 error:
46402 if (ret == -ENOMEM)
46403 - fscache_stat(&fscache_n_retrievals_nomem);
46404 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46405 else if (ret == -ERESTARTSYS)
46406 - fscache_stat(&fscache_n_retrievals_intr);
46407 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46408 else if (ret == -ENODATA)
46409 - fscache_stat(&fscache_n_retrievals_nodata);
46410 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46411 else if (ret < 0)
46412 - fscache_stat(&fscache_n_retrievals_nobufs);
46413 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46414 else
46415 - fscache_stat(&fscache_n_retrievals_ok);
46416 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46417
46418 fscache_put_retrieval(op);
46419 _leave(" = %d", ret);
46420 @@ -545,7 +545,7 @@ nobufs_unlock:
46421 spin_unlock(&cookie->lock);
46422 kfree(op);
46423 nobufs:
46424 - fscache_stat(&fscache_n_retrievals_nobufs);
46425 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46426 _leave(" = -ENOBUFS");
46427 return -ENOBUFS;
46428 }
46429 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46430
46431 _enter("%p,%p,,,", cookie, page);
46432
46433 - fscache_stat(&fscache_n_allocs);
46434 + fscache_stat_unchecked(&fscache_n_allocs);
46435
46436 if (hlist_empty(&cookie->backing_objects))
46437 goto nobufs;
46438 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46439 goto nobufs_unlock;
46440 spin_unlock(&cookie->lock);
46441
46442 - fscache_stat(&fscache_n_alloc_ops);
46443 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46444
46445 ret = fscache_wait_for_retrieval_activation(
46446 object, op,
46447 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46448
46449 error:
46450 if (ret == -ERESTARTSYS)
46451 - fscache_stat(&fscache_n_allocs_intr);
46452 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46453 else if (ret < 0)
46454 - fscache_stat(&fscache_n_allocs_nobufs);
46455 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46456 else
46457 - fscache_stat(&fscache_n_allocs_ok);
46458 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46459
46460 fscache_put_retrieval(op);
46461 _leave(" = %d", ret);
46462 @@ -625,7 +625,7 @@ nobufs_unlock:
46463 spin_unlock(&cookie->lock);
46464 kfree(op);
46465 nobufs:
46466 - fscache_stat(&fscache_n_allocs_nobufs);
46467 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46468 _leave(" = -ENOBUFS");
46469 return -ENOBUFS;
46470 }
46471 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46472
46473 spin_lock(&cookie->stores_lock);
46474
46475 - fscache_stat(&fscache_n_store_calls);
46476 + fscache_stat_unchecked(&fscache_n_store_calls);
46477
46478 /* find a page to store */
46479 page = NULL;
46480 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46481 page = results[0];
46482 _debug("gang %d [%lx]", n, page->index);
46483 if (page->index > op->store_limit) {
46484 - fscache_stat(&fscache_n_store_pages_over_limit);
46485 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46486 goto superseded;
46487 }
46488
46489 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46490 spin_unlock(&cookie->stores_lock);
46491 spin_unlock(&object->lock);
46492
46493 - fscache_stat(&fscache_n_store_pages);
46494 + fscache_stat_unchecked(&fscache_n_store_pages);
46495 fscache_stat(&fscache_n_cop_write_page);
46496 ret = object->cache->ops->write_page(op, page);
46497 fscache_stat_d(&fscache_n_cop_write_page);
46498 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46499 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46500 ASSERT(PageFsCache(page));
46501
46502 - fscache_stat(&fscache_n_stores);
46503 + fscache_stat_unchecked(&fscache_n_stores);
46504
46505 op = kzalloc(sizeof(*op), GFP_NOIO);
46506 if (!op)
46507 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46508 spin_unlock(&cookie->stores_lock);
46509 spin_unlock(&object->lock);
46510
46511 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46512 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46513 op->store_limit = object->store_limit;
46514
46515 if (fscache_submit_op(object, &op->op) < 0)
46516 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46517
46518 spin_unlock(&cookie->lock);
46519 radix_tree_preload_end();
46520 - fscache_stat(&fscache_n_store_ops);
46521 - fscache_stat(&fscache_n_stores_ok);
46522 + fscache_stat_unchecked(&fscache_n_store_ops);
46523 + fscache_stat_unchecked(&fscache_n_stores_ok);
46524
46525 /* the work queue now carries its own ref on the object */
46526 fscache_put_operation(&op->op);
46527 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46528 return 0;
46529
46530 already_queued:
46531 - fscache_stat(&fscache_n_stores_again);
46532 + fscache_stat_unchecked(&fscache_n_stores_again);
46533 already_pending:
46534 spin_unlock(&cookie->stores_lock);
46535 spin_unlock(&object->lock);
46536 spin_unlock(&cookie->lock);
46537 radix_tree_preload_end();
46538 kfree(op);
46539 - fscache_stat(&fscache_n_stores_ok);
46540 + fscache_stat_unchecked(&fscache_n_stores_ok);
46541 _leave(" = 0");
46542 return 0;
46543
46544 @@ -851,14 +851,14 @@ nobufs:
46545 spin_unlock(&cookie->lock);
46546 radix_tree_preload_end();
46547 kfree(op);
46548 - fscache_stat(&fscache_n_stores_nobufs);
46549 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46550 _leave(" = -ENOBUFS");
46551 return -ENOBUFS;
46552
46553 nomem_free:
46554 kfree(op);
46555 nomem:
46556 - fscache_stat(&fscache_n_stores_oom);
46557 + fscache_stat_unchecked(&fscache_n_stores_oom);
46558 _leave(" = -ENOMEM");
46559 return -ENOMEM;
46560 }
46561 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46562 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46563 ASSERTCMP(page, !=, NULL);
46564
46565 - fscache_stat(&fscache_n_uncaches);
46566 + fscache_stat_unchecked(&fscache_n_uncaches);
46567
46568 /* cache withdrawal may beat us to it */
46569 if (!PageFsCache(page))
46570 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46571 unsigned long loop;
46572
46573 #ifdef CONFIG_FSCACHE_STATS
46574 - atomic_add(pagevec->nr, &fscache_n_marks);
46575 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46576 #endif
46577
46578 for (loop = 0; loop < pagevec->nr; loop++) {
46579 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46580 index 4765190..2a067f2 100644
46581 --- a/fs/fscache/stats.c
46582 +++ b/fs/fscache/stats.c
46583 @@ -18,95 +18,95 @@
46584 /*
46585 * operation counters
46586 */
46587 -atomic_t fscache_n_op_pend;
46588 -atomic_t fscache_n_op_run;
46589 -atomic_t fscache_n_op_enqueue;
46590 -atomic_t fscache_n_op_requeue;
46591 -atomic_t fscache_n_op_deferred_release;
46592 -atomic_t fscache_n_op_release;
46593 -atomic_t fscache_n_op_gc;
46594 -atomic_t fscache_n_op_cancelled;
46595 -atomic_t fscache_n_op_rejected;
46596 +atomic_unchecked_t fscache_n_op_pend;
46597 +atomic_unchecked_t fscache_n_op_run;
46598 +atomic_unchecked_t fscache_n_op_enqueue;
46599 +atomic_unchecked_t fscache_n_op_requeue;
46600 +atomic_unchecked_t fscache_n_op_deferred_release;
46601 +atomic_unchecked_t fscache_n_op_release;
46602 +atomic_unchecked_t fscache_n_op_gc;
46603 +atomic_unchecked_t fscache_n_op_cancelled;
46604 +atomic_unchecked_t fscache_n_op_rejected;
46605
46606 -atomic_t fscache_n_attr_changed;
46607 -atomic_t fscache_n_attr_changed_ok;
46608 -atomic_t fscache_n_attr_changed_nobufs;
46609 -atomic_t fscache_n_attr_changed_nomem;
46610 -atomic_t fscache_n_attr_changed_calls;
46611 +atomic_unchecked_t fscache_n_attr_changed;
46612 +atomic_unchecked_t fscache_n_attr_changed_ok;
46613 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46614 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46615 +atomic_unchecked_t fscache_n_attr_changed_calls;
46616
46617 -atomic_t fscache_n_allocs;
46618 -atomic_t fscache_n_allocs_ok;
46619 -atomic_t fscache_n_allocs_wait;
46620 -atomic_t fscache_n_allocs_nobufs;
46621 -atomic_t fscache_n_allocs_intr;
46622 -atomic_t fscache_n_allocs_object_dead;
46623 -atomic_t fscache_n_alloc_ops;
46624 -atomic_t fscache_n_alloc_op_waits;
46625 +atomic_unchecked_t fscache_n_allocs;
46626 +atomic_unchecked_t fscache_n_allocs_ok;
46627 +atomic_unchecked_t fscache_n_allocs_wait;
46628 +atomic_unchecked_t fscache_n_allocs_nobufs;
46629 +atomic_unchecked_t fscache_n_allocs_intr;
46630 +atomic_unchecked_t fscache_n_allocs_object_dead;
46631 +atomic_unchecked_t fscache_n_alloc_ops;
46632 +atomic_unchecked_t fscache_n_alloc_op_waits;
46633
46634 -atomic_t fscache_n_retrievals;
46635 -atomic_t fscache_n_retrievals_ok;
46636 -atomic_t fscache_n_retrievals_wait;
46637 -atomic_t fscache_n_retrievals_nodata;
46638 -atomic_t fscache_n_retrievals_nobufs;
46639 -atomic_t fscache_n_retrievals_intr;
46640 -atomic_t fscache_n_retrievals_nomem;
46641 -atomic_t fscache_n_retrievals_object_dead;
46642 -atomic_t fscache_n_retrieval_ops;
46643 -atomic_t fscache_n_retrieval_op_waits;
46644 +atomic_unchecked_t fscache_n_retrievals;
46645 +atomic_unchecked_t fscache_n_retrievals_ok;
46646 +atomic_unchecked_t fscache_n_retrievals_wait;
46647 +atomic_unchecked_t fscache_n_retrievals_nodata;
46648 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46649 +atomic_unchecked_t fscache_n_retrievals_intr;
46650 +atomic_unchecked_t fscache_n_retrievals_nomem;
46651 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46652 +atomic_unchecked_t fscache_n_retrieval_ops;
46653 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46654
46655 -atomic_t fscache_n_stores;
46656 -atomic_t fscache_n_stores_ok;
46657 -atomic_t fscache_n_stores_again;
46658 -atomic_t fscache_n_stores_nobufs;
46659 -atomic_t fscache_n_stores_oom;
46660 -atomic_t fscache_n_store_ops;
46661 -atomic_t fscache_n_store_calls;
46662 -atomic_t fscache_n_store_pages;
46663 -atomic_t fscache_n_store_radix_deletes;
46664 -atomic_t fscache_n_store_pages_over_limit;
46665 +atomic_unchecked_t fscache_n_stores;
46666 +atomic_unchecked_t fscache_n_stores_ok;
46667 +atomic_unchecked_t fscache_n_stores_again;
46668 +atomic_unchecked_t fscache_n_stores_nobufs;
46669 +atomic_unchecked_t fscache_n_stores_oom;
46670 +atomic_unchecked_t fscache_n_store_ops;
46671 +atomic_unchecked_t fscache_n_store_calls;
46672 +atomic_unchecked_t fscache_n_store_pages;
46673 +atomic_unchecked_t fscache_n_store_radix_deletes;
46674 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46675
46676 -atomic_t fscache_n_store_vmscan_not_storing;
46677 -atomic_t fscache_n_store_vmscan_gone;
46678 -atomic_t fscache_n_store_vmscan_busy;
46679 -atomic_t fscache_n_store_vmscan_cancelled;
46680 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46681 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46682 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46683 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46684
46685 -atomic_t fscache_n_marks;
46686 -atomic_t fscache_n_uncaches;
46687 +atomic_unchecked_t fscache_n_marks;
46688 +atomic_unchecked_t fscache_n_uncaches;
46689
46690 -atomic_t fscache_n_acquires;
46691 -atomic_t fscache_n_acquires_null;
46692 -atomic_t fscache_n_acquires_no_cache;
46693 -atomic_t fscache_n_acquires_ok;
46694 -atomic_t fscache_n_acquires_nobufs;
46695 -atomic_t fscache_n_acquires_oom;
46696 +atomic_unchecked_t fscache_n_acquires;
46697 +atomic_unchecked_t fscache_n_acquires_null;
46698 +atomic_unchecked_t fscache_n_acquires_no_cache;
46699 +atomic_unchecked_t fscache_n_acquires_ok;
46700 +atomic_unchecked_t fscache_n_acquires_nobufs;
46701 +atomic_unchecked_t fscache_n_acquires_oom;
46702
46703 -atomic_t fscache_n_updates;
46704 -atomic_t fscache_n_updates_null;
46705 -atomic_t fscache_n_updates_run;
46706 +atomic_unchecked_t fscache_n_updates;
46707 +atomic_unchecked_t fscache_n_updates_null;
46708 +atomic_unchecked_t fscache_n_updates_run;
46709
46710 -atomic_t fscache_n_relinquishes;
46711 -atomic_t fscache_n_relinquishes_null;
46712 -atomic_t fscache_n_relinquishes_waitcrt;
46713 -atomic_t fscache_n_relinquishes_retire;
46714 +atomic_unchecked_t fscache_n_relinquishes;
46715 +atomic_unchecked_t fscache_n_relinquishes_null;
46716 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46717 +atomic_unchecked_t fscache_n_relinquishes_retire;
46718
46719 -atomic_t fscache_n_cookie_index;
46720 -atomic_t fscache_n_cookie_data;
46721 -atomic_t fscache_n_cookie_special;
46722 +atomic_unchecked_t fscache_n_cookie_index;
46723 +atomic_unchecked_t fscache_n_cookie_data;
46724 +atomic_unchecked_t fscache_n_cookie_special;
46725
46726 -atomic_t fscache_n_object_alloc;
46727 -atomic_t fscache_n_object_no_alloc;
46728 -atomic_t fscache_n_object_lookups;
46729 -atomic_t fscache_n_object_lookups_negative;
46730 -atomic_t fscache_n_object_lookups_positive;
46731 -atomic_t fscache_n_object_lookups_timed_out;
46732 -atomic_t fscache_n_object_created;
46733 -atomic_t fscache_n_object_avail;
46734 -atomic_t fscache_n_object_dead;
46735 +atomic_unchecked_t fscache_n_object_alloc;
46736 +atomic_unchecked_t fscache_n_object_no_alloc;
46737 +atomic_unchecked_t fscache_n_object_lookups;
46738 +atomic_unchecked_t fscache_n_object_lookups_negative;
46739 +atomic_unchecked_t fscache_n_object_lookups_positive;
46740 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46741 +atomic_unchecked_t fscache_n_object_created;
46742 +atomic_unchecked_t fscache_n_object_avail;
46743 +atomic_unchecked_t fscache_n_object_dead;
46744
46745 -atomic_t fscache_n_checkaux_none;
46746 -atomic_t fscache_n_checkaux_okay;
46747 -atomic_t fscache_n_checkaux_update;
46748 -atomic_t fscache_n_checkaux_obsolete;
46749 +atomic_unchecked_t fscache_n_checkaux_none;
46750 +atomic_unchecked_t fscache_n_checkaux_okay;
46751 +atomic_unchecked_t fscache_n_checkaux_update;
46752 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46753
46754 atomic_t fscache_n_cop_alloc_object;
46755 atomic_t fscache_n_cop_lookup_object;
46756 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46757 seq_puts(m, "FS-Cache statistics\n");
46758
46759 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46760 - atomic_read(&fscache_n_cookie_index),
46761 - atomic_read(&fscache_n_cookie_data),
46762 - atomic_read(&fscache_n_cookie_special));
46763 + atomic_read_unchecked(&fscache_n_cookie_index),
46764 + atomic_read_unchecked(&fscache_n_cookie_data),
46765 + atomic_read_unchecked(&fscache_n_cookie_special));
46766
46767 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46768 - atomic_read(&fscache_n_object_alloc),
46769 - atomic_read(&fscache_n_object_no_alloc),
46770 - atomic_read(&fscache_n_object_avail),
46771 - atomic_read(&fscache_n_object_dead));
46772 + atomic_read_unchecked(&fscache_n_object_alloc),
46773 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46774 + atomic_read_unchecked(&fscache_n_object_avail),
46775 + atomic_read_unchecked(&fscache_n_object_dead));
46776 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46777 - atomic_read(&fscache_n_checkaux_none),
46778 - atomic_read(&fscache_n_checkaux_okay),
46779 - atomic_read(&fscache_n_checkaux_update),
46780 - atomic_read(&fscache_n_checkaux_obsolete));
46781 + atomic_read_unchecked(&fscache_n_checkaux_none),
46782 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46783 + atomic_read_unchecked(&fscache_n_checkaux_update),
46784 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46785
46786 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46787 - atomic_read(&fscache_n_marks),
46788 - atomic_read(&fscache_n_uncaches));
46789 + atomic_read_unchecked(&fscache_n_marks),
46790 + atomic_read_unchecked(&fscache_n_uncaches));
46791
46792 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46793 " oom=%u\n",
46794 - atomic_read(&fscache_n_acquires),
46795 - atomic_read(&fscache_n_acquires_null),
46796 - atomic_read(&fscache_n_acquires_no_cache),
46797 - atomic_read(&fscache_n_acquires_ok),
46798 - atomic_read(&fscache_n_acquires_nobufs),
46799 - atomic_read(&fscache_n_acquires_oom));
46800 + atomic_read_unchecked(&fscache_n_acquires),
46801 + atomic_read_unchecked(&fscache_n_acquires_null),
46802 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46803 + atomic_read_unchecked(&fscache_n_acquires_ok),
46804 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46805 + atomic_read_unchecked(&fscache_n_acquires_oom));
46806
46807 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46808 - atomic_read(&fscache_n_object_lookups),
46809 - atomic_read(&fscache_n_object_lookups_negative),
46810 - atomic_read(&fscache_n_object_lookups_positive),
46811 - atomic_read(&fscache_n_object_created),
46812 - atomic_read(&fscache_n_object_lookups_timed_out));
46813 + atomic_read_unchecked(&fscache_n_object_lookups),
46814 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46815 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46816 + atomic_read_unchecked(&fscache_n_object_created),
46817 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46818
46819 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46820 - atomic_read(&fscache_n_updates),
46821 - atomic_read(&fscache_n_updates_null),
46822 - atomic_read(&fscache_n_updates_run));
46823 + atomic_read_unchecked(&fscache_n_updates),
46824 + atomic_read_unchecked(&fscache_n_updates_null),
46825 + atomic_read_unchecked(&fscache_n_updates_run));
46826
46827 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46828 - atomic_read(&fscache_n_relinquishes),
46829 - atomic_read(&fscache_n_relinquishes_null),
46830 - atomic_read(&fscache_n_relinquishes_waitcrt),
46831 - atomic_read(&fscache_n_relinquishes_retire));
46832 + atomic_read_unchecked(&fscache_n_relinquishes),
46833 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46834 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46835 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46836
46837 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46838 - atomic_read(&fscache_n_attr_changed),
46839 - atomic_read(&fscache_n_attr_changed_ok),
46840 - atomic_read(&fscache_n_attr_changed_nobufs),
46841 - atomic_read(&fscache_n_attr_changed_nomem),
46842 - atomic_read(&fscache_n_attr_changed_calls));
46843 + atomic_read_unchecked(&fscache_n_attr_changed),
46844 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46845 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46846 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46847 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46848
46849 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46850 - atomic_read(&fscache_n_allocs),
46851 - atomic_read(&fscache_n_allocs_ok),
46852 - atomic_read(&fscache_n_allocs_wait),
46853 - atomic_read(&fscache_n_allocs_nobufs),
46854 - atomic_read(&fscache_n_allocs_intr));
46855 + atomic_read_unchecked(&fscache_n_allocs),
46856 + atomic_read_unchecked(&fscache_n_allocs_ok),
46857 + atomic_read_unchecked(&fscache_n_allocs_wait),
46858 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46859 + atomic_read_unchecked(&fscache_n_allocs_intr));
46860 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46861 - atomic_read(&fscache_n_alloc_ops),
46862 - atomic_read(&fscache_n_alloc_op_waits),
46863 - atomic_read(&fscache_n_allocs_object_dead));
46864 + atomic_read_unchecked(&fscache_n_alloc_ops),
46865 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46866 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46867
46868 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46869 " int=%u oom=%u\n",
46870 - atomic_read(&fscache_n_retrievals),
46871 - atomic_read(&fscache_n_retrievals_ok),
46872 - atomic_read(&fscache_n_retrievals_wait),
46873 - atomic_read(&fscache_n_retrievals_nodata),
46874 - atomic_read(&fscache_n_retrievals_nobufs),
46875 - atomic_read(&fscache_n_retrievals_intr),
46876 - atomic_read(&fscache_n_retrievals_nomem));
46877 + atomic_read_unchecked(&fscache_n_retrievals),
46878 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46879 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46880 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46881 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46882 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46883 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46884 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46885 - atomic_read(&fscache_n_retrieval_ops),
46886 - atomic_read(&fscache_n_retrieval_op_waits),
46887 - atomic_read(&fscache_n_retrievals_object_dead));
46888 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46889 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46890 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46891
46892 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46893 - atomic_read(&fscache_n_stores),
46894 - atomic_read(&fscache_n_stores_ok),
46895 - atomic_read(&fscache_n_stores_again),
46896 - atomic_read(&fscache_n_stores_nobufs),
46897 - atomic_read(&fscache_n_stores_oom));
46898 + atomic_read_unchecked(&fscache_n_stores),
46899 + atomic_read_unchecked(&fscache_n_stores_ok),
46900 + atomic_read_unchecked(&fscache_n_stores_again),
46901 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46902 + atomic_read_unchecked(&fscache_n_stores_oom));
46903 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46904 - atomic_read(&fscache_n_store_ops),
46905 - atomic_read(&fscache_n_store_calls),
46906 - atomic_read(&fscache_n_store_pages),
46907 - atomic_read(&fscache_n_store_radix_deletes),
46908 - atomic_read(&fscache_n_store_pages_over_limit));
46909 + atomic_read_unchecked(&fscache_n_store_ops),
46910 + atomic_read_unchecked(&fscache_n_store_calls),
46911 + atomic_read_unchecked(&fscache_n_store_pages),
46912 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46913 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46914
46915 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46916 - atomic_read(&fscache_n_store_vmscan_not_storing),
46917 - atomic_read(&fscache_n_store_vmscan_gone),
46918 - atomic_read(&fscache_n_store_vmscan_busy),
46919 - atomic_read(&fscache_n_store_vmscan_cancelled));
46920 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46921 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46922 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46923 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46924
46925 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46926 - atomic_read(&fscache_n_op_pend),
46927 - atomic_read(&fscache_n_op_run),
46928 - atomic_read(&fscache_n_op_enqueue),
46929 - atomic_read(&fscache_n_op_cancelled),
46930 - atomic_read(&fscache_n_op_rejected));
46931 + atomic_read_unchecked(&fscache_n_op_pend),
46932 + atomic_read_unchecked(&fscache_n_op_run),
46933 + atomic_read_unchecked(&fscache_n_op_enqueue),
46934 + atomic_read_unchecked(&fscache_n_op_cancelled),
46935 + atomic_read_unchecked(&fscache_n_op_rejected));
46936 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46937 - atomic_read(&fscache_n_op_deferred_release),
46938 - atomic_read(&fscache_n_op_release),
46939 - atomic_read(&fscache_n_op_gc));
46940 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46941 + atomic_read_unchecked(&fscache_n_op_release),
46942 + atomic_read_unchecked(&fscache_n_op_gc));
46943
46944 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46945 atomic_read(&fscache_n_cop_alloc_object),
46946 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46947 index 3426521..3b75162 100644
46948 --- a/fs/fuse/cuse.c
46949 +++ b/fs/fuse/cuse.c
46950 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46951 INIT_LIST_HEAD(&cuse_conntbl[i]);
46952
46953 /* inherit and extend fuse_dev_operations */
46954 - cuse_channel_fops = fuse_dev_operations;
46955 - cuse_channel_fops.owner = THIS_MODULE;
46956 - cuse_channel_fops.open = cuse_channel_open;
46957 - cuse_channel_fops.release = cuse_channel_release;
46958 + pax_open_kernel();
46959 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46960 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46961 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46962 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46963 + pax_close_kernel();
46964
46965 cuse_class = class_create(THIS_MODULE, "cuse");
46966 if (IS_ERR(cuse_class))
46967 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46968 index 7df2b5e..5804aa7 100644
46969 --- a/fs/fuse/dev.c
46970 +++ b/fs/fuse/dev.c
46971 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46972 ret = 0;
46973 pipe_lock(pipe);
46974
46975 - if (!pipe->readers) {
46976 + if (!atomic_read(&pipe->readers)) {
46977 send_sig(SIGPIPE, current, 0);
46978 if (!ret)
46979 ret = -EPIPE;
46980 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46981 index 334e0b1..fc571e8 100644
46982 --- a/fs/fuse/dir.c
46983 +++ b/fs/fuse/dir.c
46984 @@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46985 return link;
46986 }
46987
46988 -static void free_link(char *link)
46989 +static void free_link(const char *link)
46990 {
46991 if (!IS_ERR(link))
46992 free_page((unsigned long) link);
46993 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46994 index a9ba244..d9df391 100644
46995 --- a/fs/gfs2/inode.c
46996 +++ b/fs/gfs2/inode.c
46997 @@ -1496,7 +1496,7 @@ out:
46998
46999 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47000 {
47001 - char *s = nd_get_link(nd);
47002 + const char *s = nd_get_link(nd);
47003 if (!IS_ERR(s))
47004 kfree(s);
47005 }
47006 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47007 index cc9281b..58996fb 100644
47008 --- a/fs/hugetlbfs/inode.c
47009 +++ b/fs/hugetlbfs/inode.c
47010 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47011 .kill_sb = kill_litter_super,
47012 };
47013
47014 -static struct vfsmount *hugetlbfs_vfsmount;
47015 +struct vfsmount *hugetlbfs_vfsmount;
47016
47017 static int can_do_hugetlb_shm(void)
47018 {
47019 diff --git a/fs/inode.c b/fs/inode.c
47020 index c99163b..a11ad40 100644
47021 --- a/fs/inode.c
47022 +++ b/fs/inode.c
47023 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47024
47025 #ifdef CONFIG_SMP
47026 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47027 - static atomic_t shared_last_ino;
47028 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47029 + static atomic_unchecked_t shared_last_ino;
47030 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47031
47032 res = next - LAST_INO_BATCH;
47033 }
47034 diff --git a/fs/isofs/export.c b/fs/isofs/export.c
47035 index aa4356d..1d38044 100644
47036 --- a/fs/isofs/export.c
47037 +++ b/fs/isofs/export.c
47038 @@ -134,6 +134,7 @@ isofs_export_encode_fh(struct inode *inode,
47039 len = 3;
47040 fh32[0] = ei->i_iget5_block;
47041 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
47042 + fh16[3] = 0; /* avoid leaking uninitialized data */
47043 fh32[2] = inode->i_generation;
47044 if (parent) {
47045 struct iso_inode_info *eparent;
47046 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47047 index 4a6cf28..d3a29d3 100644
47048 --- a/fs/jffs2/erase.c
47049 +++ b/fs/jffs2/erase.c
47050 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47051 struct jffs2_unknown_node marker = {
47052 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47053 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47054 - .totlen = cpu_to_je32(c->cleanmarker_size)
47055 + .totlen = cpu_to_je32(c->cleanmarker_size),
47056 + .hdr_crc = cpu_to_je32(0)
47057 };
47058
47059 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47060 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47061 index 6f4529d..bf12806 100644
47062 --- a/fs/jffs2/wbuf.c
47063 +++ b/fs/jffs2/wbuf.c
47064 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47065 {
47066 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47067 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47068 - .totlen = constant_cpu_to_je32(8)
47069 + .totlen = constant_cpu_to_je32(8),
47070 + .hdr_crc = constant_cpu_to_je32(0)
47071 };
47072
47073 /*
47074 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47075 index 4a82950..bcaa0cb 100644
47076 --- a/fs/jfs/super.c
47077 +++ b/fs/jfs/super.c
47078 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
47079
47080 jfs_inode_cachep =
47081 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47082 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47083 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47084 init_once);
47085 if (jfs_inode_cachep == NULL)
47086 return -ENOMEM;
47087 diff --git a/fs/libfs.c b/fs/libfs.c
47088 index f86ec27..4734776 100644
47089 --- a/fs/libfs.c
47090 +++ b/fs/libfs.c
47091 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47092
47093 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47094 struct dentry *next;
47095 + char d_name[sizeof(next->d_iname)];
47096 + const unsigned char *name;
47097 +
47098 next = list_entry(p, struct dentry, d_u.d_child);
47099 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47100 if (!simple_positive(next)) {
47101 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47102
47103 spin_unlock(&next->d_lock);
47104 spin_unlock(&dentry->d_lock);
47105 - if (filldir(dirent, next->d_name.name,
47106 + name = next->d_name.name;
47107 + if (name == next->d_iname) {
47108 + memcpy(d_name, name, next->d_name.len);
47109 + name = d_name;
47110 + }
47111 + if (filldir(dirent, name,
47112 next->d_name.len, filp->f_pos,
47113 next->d_inode->i_ino,
47114 dt_type(next->d_inode)) < 0)
47115 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47116 index 8392cb8..80d6193 100644
47117 --- a/fs/lockd/clntproc.c
47118 +++ b/fs/lockd/clntproc.c
47119 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47120 /*
47121 * Cookie counter for NLM requests
47122 */
47123 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47124 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47125
47126 void nlmclnt_next_cookie(struct nlm_cookie *c)
47127 {
47128 - u32 cookie = atomic_inc_return(&nlm_cookie);
47129 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47130
47131 memcpy(c->data, &cookie, 4);
47132 c->len=4;
47133 diff --git a/fs/locks.c b/fs/locks.c
47134 index 82c3533..34e929c 100644
47135 --- a/fs/locks.c
47136 +++ b/fs/locks.c
47137 @@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
47138 return;
47139
47140 if (filp->f_op && filp->f_op->flock) {
47141 - struct file_lock fl = {
47142 + struct file_lock flock = {
47143 .fl_pid = current->tgid,
47144 .fl_file = filp,
47145 .fl_flags = FL_FLOCK,
47146 .fl_type = F_UNLCK,
47147 .fl_end = OFFSET_MAX,
47148 };
47149 - filp->f_op->flock(filp, F_SETLKW, &fl);
47150 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47151 - fl.fl_ops->fl_release_private(&fl);
47152 + filp->f_op->flock(filp, F_SETLKW, &flock);
47153 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47154 + flock.fl_ops->fl_release_private(&flock);
47155 }
47156
47157 lock_flocks();
47158 diff --git a/fs/namei.c b/fs/namei.c
47159 index 7d69419..10c6af6 100644
47160 --- a/fs/namei.c
47161 +++ b/fs/namei.c
47162 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47163 if (ret != -EACCES)
47164 return ret;
47165
47166 +#ifdef CONFIG_GRKERNSEC
47167 + /* we'll block if we have to log due to a denied capability use */
47168 + if (mask & MAY_NOT_BLOCK)
47169 + return -ECHILD;
47170 +#endif
47171 +
47172 if (S_ISDIR(inode->i_mode)) {
47173 /* DACs are overridable for directories */
47174 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47175 - return 0;
47176 if (!(mask & MAY_WRITE))
47177 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47178 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47179 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47180 return 0;
47181 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47182 + return 0;
47183 return -EACCES;
47184 }
47185 /*
47186 + * Searching includes executable on directories, else just read.
47187 + */
47188 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47189 + if (mask == MAY_READ)
47190 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47191 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47192 + return 0;
47193 +
47194 + /*
47195 * Read/write DACs are always overridable.
47196 * Executable DACs are overridable when there is
47197 * at least one exec bit set.
47198 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47199 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47200 return 0;
47201
47202 - /*
47203 - * Searching includes executable on directories, else just read.
47204 - */
47205 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47206 - if (mask == MAY_READ)
47207 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47208 - return 0;
47209 -
47210 return -EACCES;
47211 }
47212
47213 @@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47214 return error;
47215 }
47216
47217 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47218 + dentry->d_inode, dentry, nd->path.mnt)) {
47219 + error = -EACCES;
47220 + *p = ERR_PTR(error); /* no ->put_link(), please */
47221 + path_put(&nd->path);
47222 + return error;
47223 + }
47224 +
47225 nd->last_type = LAST_BIND;
47226 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47227 error = PTR_ERR(*p);
47228 if (!IS_ERR(*p)) {
47229 - char *s = nd_get_link(nd);
47230 + const char *s = nd_get_link(nd);
47231 error = 0;
47232 if (s)
47233 error = __vfs_follow_link(nd, s);
47234 @@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47235 if (!res)
47236 res = walk_component(nd, path, &nd->last,
47237 nd->last_type, LOOKUP_FOLLOW);
47238 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47239 + res = -EACCES;
47240 put_link(nd, &link, cookie);
47241 } while (res > 0);
47242
47243 @@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47244 err = follow_link(&link, nd, &cookie);
47245 if (!err)
47246 err = lookup_last(nd, &path);
47247 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47248 + err = -EACCES;
47249 put_link(nd, &link, cookie);
47250 }
47251 }
47252 @@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47253 if (!err)
47254 err = complete_walk(nd);
47255
47256 + if (!(nd->flags & LOOKUP_PARENT)) {
47257 +#ifdef CONFIG_GRKERNSEC
47258 + if (flags & LOOKUP_RCU) {
47259 + if (!err)
47260 + path_put(&nd->path);
47261 + err = -ECHILD;
47262 + } else
47263 +#endif
47264 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47265 + if (!err)
47266 + path_put(&nd->path);
47267 + err = -ENOENT;
47268 + }
47269 + }
47270 +
47271 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47272 if (!nd->inode->i_op->lookup) {
47273 path_put(&nd->path);
47274 @@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47275 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47276
47277 if (likely(!retval)) {
47278 + if (*name != '/' && nd->path.dentry && nd->inode) {
47279 +#ifdef CONFIG_GRKERNSEC
47280 + if (flags & LOOKUP_RCU)
47281 + return -ECHILD;
47282 +#endif
47283 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47284 + return -ENOENT;
47285 + }
47286 +
47287 if (unlikely(!audit_dummy_context())) {
47288 if (nd->path.dentry && nd->inode)
47289 audit_inode(name, nd->path.dentry);
47290 @@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47291 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47292 return -EPERM;
47293
47294 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47295 + return -EPERM;
47296 + if (gr_handle_rawio(inode))
47297 + return -EPERM;
47298 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47299 + return -EACCES;
47300 +
47301 return 0;
47302 }
47303
47304 @@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47305 /*
47306 * Handle the last step of open()
47307 */
47308 -static struct file *do_last(struct nameidata *nd, struct path *path,
47309 +static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47310 const struct open_flags *op, const char *pathname)
47311 {
47312 struct dentry *dir = nd->path.dentry;
47313 @@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47314 error = complete_walk(nd);
47315 if (error)
47316 return ERR_PTR(error);
47317 +#ifdef CONFIG_GRKERNSEC
47318 + if (nd->flags & LOOKUP_RCU) {
47319 + error = -ECHILD;
47320 + goto exit;
47321 + }
47322 +#endif
47323 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47324 + error = -ENOENT;
47325 + goto exit;
47326 + }
47327 audit_inode(pathname, nd->path.dentry);
47328 if (open_flag & O_CREAT) {
47329 error = -EISDIR;
47330 goto exit;
47331 }
47332 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47333 + error = -EACCES;
47334 + goto exit;
47335 + }
47336 goto ok;
47337 case LAST_BIND:
47338 error = complete_walk(nd);
47339 if (error)
47340 return ERR_PTR(error);
47341 +#ifdef CONFIG_GRKERNSEC
47342 + if (nd->flags & LOOKUP_RCU) {
47343 + error = -ECHILD;
47344 + goto exit;
47345 + }
47346 +#endif
47347 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47348 + error = -ENOENT;
47349 + goto exit;
47350 + }
47351 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47352 + error = -EACCES;
47353 + goto exit;
47354 + }
47355 audit_inode(pathname, dir);
47356 goto ok;
47357 }
47358 @@ -2285,6 +2364,12 @@ retry_lookup:
47359 /* Negative dentry, just create the file */
47360 if (!dentry->d_inode) {
47361 umode_t mode = op->mode;
47362 +
47363 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47364 + error = -EACCES;
47365 + goto exit_mutex_unlock;
47366 + }
47367 +
47368 if (!IS_POSIXACL(dir->d_inode))
47369 mode &= ~current_umask();
47370 /*
47371 @@ -2308,6 +2393,8 @@ retry_lookup:
47372 error = vfs_create(dir->d_inode, dentry, mode, nd);
47373 if (error)
47374 goto exit_mutex_unlock;
47375 + else
47376 + gr_handle_create(path->dentry, path->mnt);
47377 mutex_unlock(&dir->d_inode->i_mutex);
47378 dput(nd->path.dentry);
47379 nd->path.dentry = dentry;
47380 @@ -2317,6 +2404,23 @@ retry_lookup:
47381 /*
47382 * It already exists.
47383 */
47384 +
47385 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47386 + error = -ENOENT;
47387 + goto exit_mutex_unlock;
47388 + }
47389 + if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47390 + error = -EACCES;
47391 + goto exit_mutex_unlock;
47392 + }
47393 +
47394 + /* only check if O_CREAT is specified, all other checks need to go
47395 + into may_open */
47396 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47397 + error = -EACCES;
47398 + goto exit_mutex_unlock;
47399 + }
47400 +
47401 mutex_unlock(&dir->d_inode->i_mutex);
47402 audit_inode(pathname, path->dentry);
47403
47404 @@ -2349,6 +2453,11 @@ finish_lookup:
47405 }
47406 }
47407 BUG_ON(inode != path->dentry->d_inode);
47408 + /* if we're resolving a symlink to another symlink */
47409 + if (link && gr_handle_symlink_owner(link, inode)) {
47410 + error = -EACCES;
47411 + goto exit;
47412 + }
47413 return NULL;
47414 }
47415
47416 @@ -2358,7 +2467,6 @@ finish_lookup:
47417 save_parent.dentry = nd->path.dentry;
47418 save_parent.mnt = mntget(path->mnt);
47419 nd->path.dentry = path->dentry;
47420 -
47421 }
47422 nd->inode = inode;
47423 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47424 @@ -2367,6 +2475,21 @@ finish_lookup:
47425 path_put(&save_parent);
47426 return ERR_PTR(error);
47427 }
47428 +#ifdef CONFIG_GRKERNSEC
47429 + if (nd->flags & LOOKUP_RCU) {
47430 + error = -ECHILD;
47431 + goto exit;
47432 + }
47433 +#endif
47434 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47435 + error = -ENOENT;
47436 + goto exit;
47437 + }
47438 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47439 + error = -EACCES;
47440 + goto exit;
47441 + }
47442 +
47443 error = -EISDIR;
47444 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47445 goto exit;
47446 @@ -2461,7 +2584,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47447 if (unlikely(error))
47448 goto out_filp;
47449
47450 - filp = do_last(nd, &path, op, pathname);
47451 + filp = do_last(nd, &path, NULL, op, pathname);
47452 while (unlikely(!filp)) { /* trailing symlink */
47453 struct path link = path;
47454 void *cookie;
47455 @@ -2476,8 +2599,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47456 error = follow_link(&link, nd, &cookie);
47457 if (unlikely(error))
47458 filp = ERR_PTR(error);
47459 - else
47460 - filp = do_last(nd, &path, op, pathname);
47461 + else {
47462 + filp = do_last(nd, &path, &link, op, pathname);
47463 + }
47464 put_link(nd, &link, cookie);
47465 }
47466 out:
47467 @@ -2577,6 +2701,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47468 *path = nd.path;
47469 return dentry;
47470 eexist:
47471 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47472 + dput(dentry);
47473 + dentry = ERR_PTR(-ENOENT);
47474 + goto fail;
47475 + }
47476 dput(dentry);
47477 dentry = ERR_PTR(-EEXIST);
47478 fail:
47479 @@ -2599,6 +2728,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47480 }
47481 EXPORT_SYMBOL(user_path_create);
47482
47483 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47484 +{
47485 + char *tmp = getname(pathname);
47486 + struct dentry *res;
47487 + if (IS_ERR(tmp))
47488 + return ERR_CAST(tmp);
47489 + res = kern_path_create(dfd, tmp, path, is_dir);
47490 + if (IS_ERR(res))
47491 + putname(tmp);
47492 + else
47493 + *to = tmp;
47494 + return res;
47495 +}
47496 +
47497 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47498 {
47499 int error = may_create(dir, dentry);
47500 @@ -2665,6 +2808,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47501 error = mnt_want_write(path.mnt);
47502 if (error)
47503 goto out_dput;
47504 +
47505 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47506 + error = -EPERM;
47507 + goto out_drop_write;
47508 + }
47509 +
47510 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47511 + error = -EACCES;
47512 + goto out_drop_write;
47513 + }
47514 +
47515 error = security_path_mknod(&path, dentry, mode, dev);
47516 if (error)
47517 goto out_drop_write;
47518 @@ -2682,6 +2836,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47519 }
47520 out_drop_write:
47521 mnt_drop_write(path.mnt);
47522 +
47523 + if (!error)
47524 + gr_handle_create(dentry, path.mnt);
47525 out_dput:
47526 dput(dentry);
47527 mutex_unlock(&path.dentry->d_inode->i_mutex);
47528 @@ -2735,12 +2892,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47529 error = mnt_want_write(path.mnt);
47530 if (error)
47531 goto out_dput;
47532 +
47533 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47534 + error = -EACCES;
47535 + goto out_drop_write;
47536 + }
47537 +
47538 error = security_path_mkdir(&path, dentry, mode);
47539 if (error)
47540 goto out_drop_write;
47541 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47542 out_drop_write:
47543 mnt_drop_write(path.mnt);
47544 +
47545 + if (!error)
47546 + gr_handle_create(dentry, path.mnt);
47547 out_dput:
47548 dput(dentry);
47549 mutex_unlock(&path.dentry->d_inode->i_mutex);
47550 @@ -2820,6 +2986,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47551 char * name;
47552 struct dentry *dentry;
47553 struct nameidata nd;
47554 + ino_t saved_ino = 0;
47555 + dev_t saved_dev = 0;
47556
47557 error = user_path_parent(dfd, pathname, &nd, &name);
47558 if (error)
47559 @@ -2848,6 +3016,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47560 error = -ENOENT;
47561 goto exit3;
47562 }
47563 +
47564 + saved_ino = dentry->d_inode->i_ino;
47565 + saved_dev = gr_get_dev_from_dentry(dentry);
47566 +
47567 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47568 + error = -EACCES;
47569 + goto exit3;
47570 + }
47571 +
47572 error = mnt_want_write(nd.path.mnt);
47573 if (error)
47574 goto exit3;
47575 @@ -2855,6 +3032,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47576 if (error)
47577 goto exit4;
47578 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47579 + if (!error && (saved_dev || saved_ino))
47580 + gr_handle_delete(saved_ino, saved_dev);
47581 exit4:
47582 mnt_drop_write(nd.path.mnt);
47583 exit3:
47584 @@ -2917,6 +3096,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47585 struct dentry *dentry;
47586 struct nameidata nd;
47587 struct inode *inode = NULL;
47588 + ino_t saved_ino = 0;
47589 + dev_t saved_dev = 0;
47590
47591 error = user_path_parent(dfd, pathname, &nd, &name);
47592 if (error)
47593 @@ -2939,6 +3120,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47594 if (!inode)
47595 goto slashes;
47596 ihold(inode);
47597 +
47598 + if (inode->i_nlink <= 1) {
47599 + saved_ino = inode->i_ino;
47600 + saved_dev = gr_get_dev_from_dentry(dentry);
47601 + }
47602 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47603 + error = -EACCES;
47604 + goto exit2;
47605 + }
47606 +
47607 error = mnt_want_write(nd.path.mnt);
47608 if (error)
47609 goto exit2;
47610 @@ -2946,6 +3137,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47611 if (error)
47612 goto exit3;
47613 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47614 + if (!error && (saved_ino || saved_dev))
47615 + gr_handle_delete(saved_ino, saved_dev);
47616 exit3:
47617 mnt_drop_write(nd.path.mnt);
47618 exit2:
47619 @@ -3021,10 +3214,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47620 error = mnt_want_write(path.mnt);
47621 if (error)
47622 goto out_dput;
47623 +
47624 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47625 + error = -EACCES;
47626 + goto out_drop_write;
47627 + }
47628 +
47629 error = security_path_symlink(&path, dentry, from);
47630 if (error)
47631 goto out_drop_write;
47632 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47633 + if (!error)
47634 + gr_handle_create(dentry, path.mnt);
47635 out_drop_write:
47636 mnt_drop_write(path.mnt);
47637 out_dput:
47638 @@ -3099,6 +3300,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47639 {
47640 struct dentry *new_dentry;
47641 struct path old_path, new_path;
47642 + char *to = NULL;
47643 int how = 0;
47644 int error;
47645
47646 @@ -3122,7 +3324,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47647 if (error)
47648 return error;
47649
47650 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47651 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47652 error = PTR_ERR(new_dentry);
47653 if (IS_ERR(new_dentry))
47654 goto out;
47655 @@ -3133,13 +3335,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47656 error = mnt_want_write(new_path.mnt);
47657 if (error)
47658 goto out_dput;
47659 +
47660 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47661 + old_path.dentry->d_inode,
47662 + old_path.dentry->d_inode->i_mode, to)) {
47663 + error = -EACCES;
47664 + goto out_drop_write;
47665 + }
47666 +
47667 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47668 + old_path.dentry, old_path.mnt, to)) {
47669 + error = -EACCES;
47670 + goto out_drop_write;
47671 + }
47672 +
47673 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47674 if (error)
47675 goto out_drop_write;
47676 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47677 + if (!error)
47678 + gr_handle_create(new_dentry, new_path.mnt);
47679 out_drop_write:
47680 mnt_drop_write(new_path.mnt);
47681 out_dput:
47682 + putname(to);
47683 dput(new_dentry);
47684 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47685 path_put(&new_path);
47686 @@ -3373,6 +3592,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47687 if (new_dentry == trap)
47688 goto exit5;
47689
47690 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47691 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47692 + to);
47693 + if (error)
47694 + goto exit5;
47695 +
47696 error = mnt_want_write(oldnd.path.mnt);
47697 if (error)
47698 goto exit5;
47699 @@ -3382,6 +3607,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47700 goto exit6;
47701 error = vfs_rename(old_dir->d_inode, old_dentry,
47702 new_dir->d_inode, new_dentry);
47703 + if (!error)
47704 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47705 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47706 exit6:
47707 mnt_drop_write(oldnd.path.mnt);
47708 exit5:
47709 @@ -3407,6 +3635,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47710
47711 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47712 {
47713 + char tmpbuf[64];
47714 + const char *newlink;
47715 int len;
47716
47717 len = PTR_ERR(link);
47718 @@ -3416,7 +3646,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47719 len = strlen(link);
47720 if (len > (unsigned) buflen)
47721 len = buflen;
47722 - if (copy_to_user(buffer, link, len))
47723 +
47724 + if (len < sizeof(tmpbuf)) {
47725 + memcpy(tmpbuf, link, len);
47726 + newlink = tmpbuf;
47727 + } else
47728 + newlink = link;
47729 +
47730 + if (copy_to_user(buffer, newlink, len))
47731 len = -EFAULT;
47732 out:
47733 return len;
47734 diff --git a/fs/namespace.c b/fs/namespace.c
47735 index 1e4a5fe..a5ce747 100644
47736 --- a/fs/namespace.c
47737 +++ b/fs/namespace.c
47738 @@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47739 if (!(sb->s_flags & MS_RDONLY))
47740 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47741 up_write(&sb->s_umount);
47742 +
47743 + gr_log_remount(mnt->mnt_devname, retval);
47744 +
47745 return retval;
47746 }
47747
47748 @@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47749 br_write_unlock(&vfsmount_lock);
47750 up_write(&namespace_sem);
47751 release_mounts(&umount_list);
47752 +
47753 + gr_log_unmount(mnt->mnt_devname, retval);
47754 +
47755 return retval;
47756 }
47757
47758 @@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47759 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47760 MS_STRICTATIME);
47761
47762 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47763 + retval = -EPERM;
47764 + goto dput_out;
47765 + }
47766 +
47767 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47768 + retval = -EPERM;
47769 + goto dput_out;
47770 + }
47771 +
47772 if (flags & MS_REMOUNT)
47773 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47774 data_page);
47775 @@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47776 dev_name, data_page);
47777 dput_out:
47778 path_put(&path);
47779 +
47780 + gr_log_mount(dev_name, dir_name, retval);
47781 +
47782 return retval;
47783 }
47784
47785 @@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47786 if (error)
47787 goto out2;
47788
47789 + if (gr_handle_chroot_pivot()) {
47790 + error = -EPERM;
47791 + goto out2;
47792 + }
47793 +
47794 get_fs_root(current->fs, &root);
47795 error = lock_mount(&old);
47796 if (error)
47797 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47798 index f729698..2bac081 100644
47799 --- a/fs/nfs/inode.c
47800 +++ b/fs/nfs/inode.c
47801 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47802 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47803 nfsi->attrtimeo_timestamp = jiffies;
47804
47805 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47806 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47807 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47808 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47809 else
47810 @@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47811 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47812 }
47813
47814 -static atomic_long_t nfs_attr_generation_counter;
47815 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47816
47817 static unsigned long nfs_read_attr_generation_counter(void)
47818 {
47819 - return atomic_long_read(&nfs_attr_generation_counter);
47820 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47821 }
47822
47823 unsigned long nfs_inc_attr_generation_counter(void)
47824 {
47825 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47826 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47827 }
47828
47829 void nfs_fattr_init(struct nfs_fattr *fattr)
47830 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47831 index c8bd9c3..4f83416 100644
47832 --- a/fs/nfsd/vfs.c
47833 +++ b/fs/nfsd/vfs.c
47834 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47835 } else {
47836 oldfs = get_fs();
47837 set_fs(KERNEL_DS);
47838 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47839 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47840 set_fs(oldfs);
47841 }
47842
47843 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47844
47845 /* Write the data. */
47846 oldfs = get_fs(); set_fs(KERNEL_DS);
47847 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47848 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47849 set_fs(oldfs);
47850 if (host_err < 0)
47851 goto out_nfserr;
47852 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47853 */
47854
47855 oldfs = get_fs(); set_fs(KERNEL_DS);
47856 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47857 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47858 set_fs(oldfs);
47859
47860 if (host_err < 0)
47861 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47862 index 3568c8a..e0240d8 100644
47863 --- a/fs/notify/fanotify/fanotify_user.c
47864 +++ b/fs/notify/fanotify/fanotify_user.c
47865 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47866 goto out_close_fd;
47867
47868 ret = -EFAULT;
47869 - if (copy_to_user(buf, &fanotify_event_metadata,
47870 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47871 + copy_to_user(buf, &fanotify_event_metadata,
47872 fanotify_event_metadata.event_len))
47873 goto out_kill_access_response;
47874
47875 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47876 index c887b13..0fdf472 100644
47877 --- a/fs/notify/notification.c
47878 +++ b/fs/notify/notification.c
47879 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47880 * get set to 0 so it will never get 'freed'
47881 */
47882 static struct fsnotify_event *q_overflow_event;
47883 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47884 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47885
47886 /**
47887 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47888 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47889 */
47890 u32 fsnotify_get_cookie(void)
47891 {
47892 - return atomic_inc_return(&fsnotify_sync_cookie);
47893 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47894 }
47895 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47896
47897 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47898 index 99e3610..02c1068 100644
47899 --- a/fs/ntfs/dir.c
47900 +++ b/fs/ntfs/dir.c
47901 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47902 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47903 ~(s64)(ndir->itype.index.block_size - 1)));
47904 /* Bounds checks. */
47905 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47906 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47907 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47908 "inode 0x%lx or driver bug.", vdir->i_ino);
47909 goto err_out;
47910 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47911 index 7389d2d..dfd5dbe 100644
47912 --- a/fs/ntfs/file.c
47913 +++ b/fs/ntfs/file.c
47914 @@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47915 #endif /* NTFS_RW */
47916 };
47917
47918 -const struct file_operations ntfs_empty_file_ops = {};
47919 +const struct file_operations ntfs_empty_file_ops __read_only;
47920
47921 -const struct inode_operations ntfs_empty_inode_ops = {};
47922 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47923 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47924 index 210c352..a174f83 100644
47925 --- a/fs/ocfs2/localalloc.c
47926 +++ b/fs/ocfs2/localalloc.c
47927 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47928 goto bail;
47929 }
47930
47931 - atomic_inc(&osb->alloc_stats.moves);
47932 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47933
47934 bail:
47935 if (handle)
47936 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47937 index d355e6e..578d905 100644
47938 --- a/fs/ocfs2/ocfs2.h
47939 +++ b/fs/ocfs2/ocfs2.h
47940 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47941
47942 struct ocfs2_alloc_stats
47943 {
47944 - atomic_t moves;
47945 - atomic_t local_data;
47946 - atomic_t bitmap_data;
47947 - atomic_t bg_allocs;
47948 - atomic_t bg_extends;
47949 + atomic_unchecked_t moves;
47950 + atomic_unchecked_t local_data;
47951 + atomic_unchecked_t bitmap_data;
47952 + atomic_unchecked_t bg_allocs;
47953 + atomic_unchecked_t bg_extends;
47954 };
47955
47956 enum ocfs2_local_alloc_state
47957 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47958 index f169da4..9112253 100644
47959 --- a/fs/ocfs2/suballoc.c
47960 +++ b/fs/ocfs2/suballoc.c
47961 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47962 mlog_errno(status);
47963 goto bail;
47964 }
47965 - atomic_inc(&osb->alloc_stats.bg_extends);
47966 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47967
47968 /* You should never ask for this much metadata */
47969 BUG_ON(bits_wanted >
47970 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47971 mlog_errno(status);
47972 goto bail;
47973 }
47974 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47975 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47976
47977 *suballoc_loc = res.sr_bg_blkno;
47978 *suballoc_bit_start = res.sr_bit_offset;
47979 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47980 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47981 res->sr_bits);
47982
47983 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47984 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47985
47986 BUG_ON(res->sr_bits != 1);
47987
47988 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47989 mlog_errno(status);
47990 goto bail;
47991 }
47992 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47993 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47994
47995 BUG_ON(res.sr_bits != 1);
47996
47997 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47998 cluster_start,
47999 num_clusters);
48000 if (!status)
48001 - atomic_inc(&osb->alloc_stats.local_data);
48002 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48003 } else {
48004 if (min_clusters > (osb->bitmap_cpg - 1)) {
48005 /* The only paths asking for contiguousness
48006 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48007 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48008 res.sr_bg_blkno,
48009 res.sr_bit_offset);
48010 - atomic_inc(&osb->alloc_stats.bitmap_data);
48011 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48012 *num_clusters = res.sr_bits;
48013 }
48014 }
48015 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48016 index 68f4541..89cfe6a 100644
48017 --- a/fs/ocfs2/super.c
48018 +++ b/fs/ocfs2/super.c
48019 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48020 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48021 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48022 "Stats",
48023 - atomic_read(&osb->alloc_stats.bitmap_data),
48024 - atomic_read(&osb->alloc_stats.local_data),
48025 - atomic_read(&osb->alloc_stats.bg_allocs),
48026 - atomic_read(&osb->alloc_stats.moves),
48027 - atomic_read(&osb->alloc_stats.bg_extends));
48028 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48029 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48030 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48031 + atomic_read_unchecked(&osb->alloc_stats.moves),
48032 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48033
48034 out += snprintf(buf + out, len - out,
48035 "%10s => State: %u Descriptor: %llu Size: %u bits "
48036 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48037 spin_lock_init(&osb->osb_xattr_lock);
48038 ocfs2_init_steal_slots(osb);
48039
48040 - atomic_set(&osb->alloc_stats.moves, 0);
48041 - atomic_set(&osb->alloc_stats.local_data, 0);
48042 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48043 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48044 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48045 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48046 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48047 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48048 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48049 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48050
48051 /* Copy the blockcheck stats from the superblock probe */
48052 osb->osb_ecc_stats = *stats;
48053 diff --git a/fs/open.c b/fs/open.c
48054 index 1540632..79d7242 100644
48055 --- a/fs/open.c
48056 +++ b/fs/open.c
48057 @@ -31,6 +31,8 @@
48058 #include <linux/ima.h>
48059 #include <linux/dnotify.h>
48060
48061 +#define CREATE_TRACE_POINTS
48062 +#include <trace/events/fs.h>
48063 #include "internal.h"
48064
48065 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48066 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48067 error = locks_verify_truncate(inode, NULL, length);
48068 if (!error)
48069 error = security_path_truncate(&path);
48070 +
48071 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48072 + error = -EACCES;
48073 +
48074 if (!error)
48075 error = do_truncate(path.dentry, length, 0, NULL);
48076
48077 @@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48078 if (__mnt_is_readonly(path.mnt))
48079 res = -EROFS;
48080
48081 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48082 + res = -EACCES;
48083 +
48084 out_path_release:
48085 path_put(&path);
48086 out:
48087 @@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48088 if (error)
48089 goto dput_and_out;
48090
48091 + gr_log_chdir(path.dentry, path.mnt);
48092 +
48093 set_fs_pwd(current->fs, &path);
48094
48095 dput_and_out:
48096 @@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48097 goto out_putf;
48098
48099 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48100 +
48101 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48102 + error = -EPERM;
48103 +
48104 + if (!error)
48105 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48106 +
48107 if (!error)
48108 set_fs_pwd(current->fs, &file->f_path);
48109 out_putf:
48110 @@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48111 if (error)
48112 goto dput_and_out;
48113
48114 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48115 + goto dput_and_out;
48116 +
48117 set_fs_root(current->fs, &path);
48118 +
48119 + gr_handle_chroot_chdir(&path);
48120 +
48121 error = 0;
48122 dput_and_out:
48123 path_put(&path);
48124 @@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
48125 if (error)
48126 return error;
48127 mutex_lock(&inode->i_mutex);
48128 +
48129 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48130 + error = -EACCES;
48131 + goto out_unlock;
48132 + }
48133 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48134 + error = -EACCES;
48135 + goto out_unlock;
48136 + }
48137 +
48138 error = security_path_chmod(path, mode);
48139 if (error)
48140 goto out_unlock;
48141 @@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48142 uid = make_kuid(current_user_ns(), user);
48143 gid = make_kgid(current_user_ns(), group);
48144
48145 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48146 + return -EACCES;
48147 +
48148 newattrs.ia_valid = ATTR_CTIME;
48149 if (user != (uid_t) -1) {
48150 if (!uid_valid(uid))
48151 @@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48152 } else {
48153 fsnotify_open(f);
48154 fd_install(fd, f);
48155 + trace_do_sys_open(tmp, flags, mode);
48156 }
48157 }
48158 putname(tmp);
48159 diff --git a/fs/pipe.c b/fs/pipe.c
48160 index 49c1065..13b9e12 100644
48161 --- a/fs/pipe.c
48162 +++ b/fs/pipe.c
48163 @@ -438,9 +438,9 @@ redo:
48164 }
48165 if (bufs) /* More to do? */
48166 continue;
48167 - if (!pipe->writers)
48168 + if (!atomic_read(&pipe->writers))
48169 break;
48170 - if (!pipe->waiting_writers) {
48171 + if (!atomic_read(&pipe->waiting_writers)) {
48172 /* syscall merging: Usually we must not sleep
48173 * if O_NONBLOCK is set, or if we got some data.
48174 * But if a writer sleeps in kernel space, then
48175 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48176 mutex_lock(&inode->i_mutex);
48177 pipe = inode->i_pipe;
48178
48179 - if (!pipe->readers) {
48180 + if (!atomic_read(&pipe->readers)) {
48181 send_sig(SIGPIPE, current, 0);
48182 ret = -EPIPE;
48183 goto out;
48184 @@ -553,7 +553,7 @@ redo1:
48185 for (;;) {
48186 int bufs;
48187
48188 - if (!pipe->readers) {
48189 + if (!atomic_read(&pipe->readers)) {
48190 send_sig(SIGPIPE, current, 0);
48191 if (!ret)
48192 ret = -EPIPE;
48193 @@ -644,9 +644,9 @@ redo2:
48194 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48195 do_wakeup = 0;
48196 }
48197 - pipe->waiting_writers++;
48198 + atomic_inc(&pipe->waiting_writers);
48199 pipe_wait(pipe);
48200 - pipe->waiting_writers--;
48201 + atomic_dec(&pipe->waiting_writers);
48202 }
48203 out:
48204 mutex_unlock(&inode->i_mutex);
48205 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48206 mask = 0;
48207 if (filp->f_mode & FMODE_READ) {
48208 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48209 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48210 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48211 mask |= POLLHUP;
48212 }
48213
48214 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48215 * Most Unices do not set POLLERR for FIFOs but on Linux they
48216 * behave exactly like pipes for poll().
48217 */
48218 - if (!pipe->readers)
48219 + if (!atomic_read(&pipe->readers))
48220 mask |= POLLERR;
48221 }
48222
48223 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48224
48225 mutex_lock(&inode->i_mutex);
48226 pipe = inode->i_pipe;
48227 - pipe->readers -= decr;
48228 - pipe->writers -= decw;
48229 + atomic_sub(decr, &pipe->readers);
48230 + atomic_sub(decw, &pipe->writers);
48231
48232 - if (!pipe->readers && !pipe->writers) {
48233 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48234 free_pipe_info(inode);
48235 } else {
48236 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48237 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48238
48239 if (inode->i_pipe) {
48240 ret = 0;
48241 - inode->i_pipe->readers++;
48242 + atomic_inc(&inode->i_pipe->readers);
48243 }
48244
48245 mutex_unlock(&inode->i_mutex);
48246 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48247
48248 if (inode->i_pipe) {
48249 ret = 0;
48250 - inode->i_pipe->writers++;
48251 + atomic_inc(&inode->i_pipe->writers);
48252 }
48253
48254 mutex_unlock(&inode->i_mutex);
48255 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48256 if (inode->i_pipe) {
48257 ret = 0;
48258 if (filp->f_mode & FMODE_READ)
48259 - inode->i_pipe->readers++;
48260 + atomic_inc(&inode->i_pipe->readers);
48261 if (filp->f_mode & FMODE_WRITE)
48262 - inode->i_pipe->writers++;
48263 + atomic_inc(&inode->i_pipe->writers);
48264 }
48265
48266 mutex_unlock(&inode->i_mutex);
48267 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48268 inode->i_pipe = NULL;
48269 }
48270
48271 -static struct vfsmount *pipe_mnt __read_mostly;
48272 +struct vfsmount *pipe_mnt __read_mostly;
48273
48274 /*
48275 * pipefs_dname() is called from d_path().
48276 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48277 goto fail_iput;
48278 inode->i_pipe = pipe;
48279
48280 - pipe->readers = pipe->writers = 1;
48281 + atomic_set(&pipe->readers, 1);
48282 + atomic_set(&pipe->writers, 1);
48283 inode->i_fop = &rdwr_pipefifo_fops;
48284
48285 /*
48286 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48287 index 15af622..0e9f4467 100644
48288 --- a/fs/proc/Kconfig
48289 +++ b/fs/proc/Kconfig
48290 @@ -30,12 +30,12 @@ config PROC_FS
48291
48292 config PROC_KCORE
48293 bool "/proc/kcore support" if !ARM
48294 - depends on PROC_FS && MMU
48295 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48296
48297 config PROC_VMCORE
48298 bool "/proc/vmcore support"
48299 - depends on PROC_FS && CRASH_DUMP
48300 - default y
48301 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48302 + default n
48303 help
48304 Exports the dump image of crashed kernel in ELF format.
48305
48306 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48307 limited in memory.
48308
48309 config PROC_PAGE_MONITOR
48310 - default y
48311 - depends on PROC_FS && MMU
48312 + default n
48313 + depends on PROC_FS && MMU && !GRKERNSEC
48314 bool "Enable /proc page monitoring" if EXPERT
48315 help
48316 Various /proc files exist to monitor process memory utilization:
48317 diff --git a/fs/proc/array.c b/fs/proc/array.c
48318 index c1c207c..5179411 100644
48319 --- a/fs/proc/array.c
48320 +++ b/fs/proc/array.c
48321 @@ -60,6 +60,7 @@
48322 #include <linux/tty.h>
48323 #include <linux/string.h>
48324 #include <linux/mman.h>
48325 +#include <linux/grsecurity.h>
48326 #include <linux/proc_fs.h>
48327 #include <linux/ioport.h>
48328 #include <linux/uaccess.h>
48329 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48330 seq_putc(m, '\n');
48331 }
48332
48333 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48334 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48335 +{
48336 + if (p->mm)
48337 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48338 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48339 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48340 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48341 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48342 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48343 + else
48344 + seq_printf(m, "PaX:\t-----\n");
48345 +}
48346 +#endif
48347 +
48348 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48349 struct pid *pid, struct task_struct *task)
48350 {
48351 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48352 task_cpus_allowed(m, task);
48353 cpuset_task_status_allowed(m, task);
48354 task_context_switch_counts(m, task);
48355 +
48356 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48357 + task_pax(m, task);
48358 +#endif
48359 +
48360 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48361 + task_grsec_rbac(m, task);
48362 +#endif
48363 +
48364 return 0;
48365 }
48366
48367 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48368 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48369 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48370 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48371 +#endif
48372 +
48373 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48374 struct pid *pid, struct task_struct *task, int whole)
48375 {
48376 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48377 char tcomm[sizeof(task->comm)];
48378 unsigned long flags;
48379
48380 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48381 + if (current->exec_id != m->exec_id) {
48382 + gr_log_badprocpid("stat");
48383 + return 0;
48384 + }
48385 +#endif
48386 +
48387 state = *get_task_state(task);
48388 vsize = eip = esp = 0;
48389 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48390 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48391 gtime = task->gtime;
48392 }
48393
48394 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48395 + if (PAX_RAND_FLAGS(mm)) {
48396 + eip = 0;
48397 + esp = 0;
48398 + wchan = 0;
48399 + }
48400 +#endif
48401 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48402 + wchan = 0;
48403 + eip =0;
48404 + esp =0;
48405 +#endif
48406 +
48407 /* scale priority and nice values from timeslices to -20..20 */
48408 /* to make it look like a "normal" Unix priority/nice value */
48409 priority = task_prio(task);
48410 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48411 seq_put_decimal_ull(m, ' ', vsize);
48412 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48413 seq_put_decimal_ull(m, ' ', rsslim);
48414 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48415 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48416 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48417 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48418 +#else
48419 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48420 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48421 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48422 +#endif
48423 seq_put_decimal_ull(m, ' ', esp);
48424 seq_put_decimal_ull(m, ' ', eip);
48425 /* The signal information here is obsolete.
48426 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48427 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48428 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48429
48430 - if (mm && permitted) {
48431 + if (mm && permitted
48432 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48433 + && !PAX_RAND_FLAGS(mm)
48434 +#endif
48435 + ) {
48436 seq_put_decimal_ull(m, ' ', mm->start_data);
48437 seq_put_decimal_ull(m, ' ', mm->end_data);
48438 seq_put_decimal_ull(m, ' ', mm->start_brk);
48439 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48440 struct pid *pid, struct task_struct *task)
48441 {
48442 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48443 - struct mm_struct *mm = get_task_mm(task);
48444 + struct mm_struct *mm;
48445
48446 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48447 + if (current->exec_id != m->exec_id) {
48448 + gr_log_badprocpid("statm");
48449 + return 0;
48450 + }
48451 +#endif
48452 + mm = get_task_mm(task);
48453 if (mm) {
48454 size = task_statm(mm, &shared, &text, &data, &resident);
48455 mmput(mm);
48456 @@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48457 return 0;
48458 }
48459
48460 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48461 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48462 +{
48463 + u32 curr_ip = 0;
48464 + unsigned long flags;
48465 +
48466 + if (lock_task_sighand(task, &flags)) {
48467 + curr_ip = task->signal->curr_ip;
48468 + unlock_task_sighand(task, &flags);
48469 + }
48470 +
48471 + return sprintf(buffer, "%pI4\n", &curr_ip);
48472 +}
48473 +#endif
48474 +
48475 #ifdef CONFIG_CHECKPOINT_RESTORE
48476 static struct pid *
48477 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48478 diff --git a/fs/proc/base.c b/fs/proc/base.c
48479 index 437195f..cd2210d 100644
48480 --- a/fs/proc/base.c
48481 +++ b/fs/proc/base.c
48482 @@ -110,6 +110,14 @@ struct pid_entry {
48483 union proc_op op;
48484 };
48485
48486 +struct getdents_callback {
48487 + struct linux_dirent __user * current_dir;
48488 + struct linux_dirent __user * previous;
48489 + struct file * file;
48490 + int count;
48491 + int error;
48492 +};
48493 +
48494 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48495 .name = (NAME), \
48496 .len = sizeof(NAME) - 1, \
48497 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48498 if (!mm->arg_end)
48499 goto out_mm; /* Shh! No looking before we're done */
48500
48501 + if (gr_acl_handle_procpidmem(task))
48502 + goto out_mm;
48503 +
48504 len = mm->arg_end - mm->arg_start;
48505
48506 if (len > PAGE_SIZE)
48507 @@ -236,12 +247,28 @@ out:
48508 return res;
48509 }
48510
48511 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48512 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48513 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48514 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48515 +#endif
48516 +
48517 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48518 {
48519 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48520 int res = PTR_ERR(mm);
48521 if (mm && !IS_ERR(mm)) {
48522 unsigned int nwords = 0;
48523 +
48524 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48525 + /* allow if we're currently ptracing this task */
48526 + if (PAX_RAND_FLAGS(mm) &&
48527 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48528 + mmput(mm);
48529 + return 0;
48530 + }
48531 +#endif
48532 +
48533 do {
48534 nwords += 2;
48535 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48536 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48537 }
48538
48539
48540 -#ifdef CONFIG_KALLSYMS
48541 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48542 /*
48543 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48544 * Returns the resolved symbol. If that fails, simply return the address.
48545 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48546 mutex_unlock(&task->signal->cred_guard_mutex);
48547 }
48548
48549 -#ifdef CONFIG_STACKTRACE
48550 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48551
48552 #define MAX_STACK_TRACE_DEPTH 64
48553
48554 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48555 return count;
48556 }
48557
48558 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48559 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48560 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48561 {
48562 long nr;
48563 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48564 /************************************************************************/
48565
48566 /* permission checks */
48567 -static int proc_fd_access_allowed(struct inode *inode)
48568 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48569 {
48570 struct task_struct *task;
48571 int allowed = 0;
48572 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48573 */
48574 task = get_proc_task(inode);
48575 if (task) {
48576 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48577 + if (log)
48578 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48579 + else
48580 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48581 put_task_struct(task);
48582 }
48583 return allowed;
48584 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48585 struct task_struct *task,
48586 int hide_pid_min)
48587 {
48588 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48589 + return false;
48590 +
48591 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48592 + rcu_read_lock();
48593 + {
48594 + const struct cred *tmpcred = current_cred();
48595 + const struct cred *cred = __task_cred(task);
48596 +
48597 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48598 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48599 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48600 +#endif
48601 + ) {
48602 + rcu_read_unlock();
48603 + return true;
48604 + }
48605 + }
48606 + rcu_read_unlock();
48607 +
48608 + if (!pid->hide_pid)
48609 + return false;
48610 +#endif
48611 +
48612 if (pid->hide_pid < hide_pid_min)
48613 return true;
48614 if (in_group_p(pid->pid_gid))
48615 return true;
48616 +
48617 return ptrace_may_access(task, PTRACE_MODE_READ);
48618 }
48619
48620 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48621 put_task_struct(task);
48622
48623 if (!has_perms) {
48624 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48625 + {
48626 +#else
48627 if (pid->hide_pid == 2) {
48628 +#endif
48629 /*
48630 * Let's make getdents(), stat(), and open()
48631 * consistent with each other. If a process
48632 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48633 if (!task)
48634 return -ESRCH;
48635
48636 + if (gr_acl_handle_procpidmem(task)) {
48637 + put_task_struct(task);
48638 + return -EPERM;
48639 + }
48640 +
48641 mm = mm_access(task, mode);
48642 put_task_struct(task);
48643
48644 @@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48645 mmput(mm);
48646 }
48647
48648 - /* OK to pass negative loff_t, we can catch out-of-range */
48649 - file->f_mode |= FMODE_UNSIGNED_OFFSET;
48650 file->private_data = mm;
48651
48652 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48653 + file->f_version = current->exec_id;
48654 +#endif
48655 +
48656 return 0;
48657 }
48658
48659 static int mem_open(struct inode *inode, struct file *file)
48660 {
48661 - return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48662 + int ret;
48663 + ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48664 +
48665 + /* OK to pass negative loff_t, we can catch out-of-range */
48666 + file->f_mode |= FMODE_UNSIGNED_OFFSET;
48667 +
48668 + return ret;
48669 }
48670
48671 static ssize_t mem_rw(struct file *file, char __user *buf,
48672 @@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48673 ssize_t copied;
48674 char *page;
48675
48676 +#ifdef CONFIG_GRKERNSEC
48677 + if (write)
48678 + return -EPERM;
48679 +#endif
48680 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48681 + if (file->f_version != current->exec_id) {
48682 + gr_log_badprocpid("mem");
48683 + return 0;
48684 + }
48685 +#endif
48686 +
48687 if (!mm)
48688 return 0;
48689
48690 @@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48691 if (!mm)
48692 return 0;
48693
48694 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48695 + if (file->f_version != current->exec_id) {
48696 + gr_log_badprocpid("environ");
48697 + return 0;
48698 + }
48699 +#endif
48700 +
48701 page = (char *)__get_free_page(GFP_TEMPORARY);
48702 if (!page)
48703 return -ENOMEM;
48704 @@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48705 if (!atomic_inc_not_zero(&mm->mm_users))
48706 goto free;
48707 while (count > 0) {
48708 - int this_len, retval, max_len;
48709 + size_t this_len, max_len;
48710 + int retval;
48711 +
48712 + if (src >= (mm->env_end - mm->env_start))
48713 + break;
48714
48715 this_len = mm->env_end - (mm->env_start + src);
48716
48717 - if (this_len <= 0)
48718 - break;
48719
48720 - max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48721 - this_len = (this_len > max_len) ? max_len : this_len;
48722 + max_len = min_t(size_t, PAGE_SIZE, count);
48723 + this_len = min(max_len, this_len);
48724
48725 retval = access_remote_vm(mm, (mm->env_start + src),
48726 page, this_len, 0);
48727 @@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48728 path_put(&nd->path);
48729
48730 /* Are we allowed to snoop on the tasks file descriptors? */
48731 - if (!proc_fd_access_allowed(inode))
48732 + if (!proc_fd_access_allowed(inode, 0))
48733 goto out;
48734
48735 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48736 @@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48737 struct path path;
48738
48739 /* Are we allowed to snoop on the tasks file descriptors? */
48740 - if (!proc_fd_access_allowed(inode))
48741 - goto out;
48742 + /* logging this is needed for learning on chromium to work properly,
48743 + but we don't want to flood the logs from 'ps' which does a readlink
48744 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48745 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48746 + */
48747 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48748 + if (!proc_fd_access_allowed(inode,0))
48749 + goto out;
48750 + } else {
48751 + if (!proc_fd_access_allowed(inode,1))
48752 + goto out;
48753 + }
48754
48755 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48756 if (error)
48757 @@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48758 rcu_read_lock();
48759 cred = __task_cred(task);
48760 inode->i_uid = cred->euid;
48761 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48762 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48763 +#else
48764 inode->i_gid = cred->egid;
48765 +#endif
48766 rcu_read_unlock();
48767 }
48768 security_task_to_inode(task, inode);
48769 @@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48770 return -ENOENT;
48771 }
48772 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48773 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48774 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48775 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48776 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48777 +#endif
48778 task_dumpable(task)) {
48779 cred = __task_cred(task);
48780 stat->uid = cred->euid;
48781 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48782 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48783 +#else
48784 stat->gid = cred->egid;
48785 +#endif
48786 }
48787 }
48788 rcu_read_unlock();
48789 @@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48790
48791 if (task) {
48792 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48793 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48794 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48795 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48796 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48797 +#endif
48798 task_dumpable(task)) {
48799 rcu_read_lock();
48800 cred = __task_cred(task);
48801 inode->i_uid = cred->euid;
48802 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48803 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48804 +#else
48805 inode->i_gid = cred->egid;
48806 +#endif
48807 rcu_read_unlock();
48808 } else {
48809 inode->i_uid = GLOBAL_ROOT_UID;
48810 @@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48811 int fd = proc_fd(inode);
48812
48813 if (task) {
48814 - files = get_files_struct(task);
48815 + if (!gr_acl_handle_procpidmem(task))
48816 + files = get_files_struct(task);
48817 put_task_struct(task);
48818 }
48819 if (files) {
48820 @@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48821 */
48822 static int proc_fd_permission(struct inode *inode, int mask)
48823 {
48824 + struct task_struct *task;
48825 int rv = generic_permission(inode, mask);
48826 - if (rv == 0)
48827 - return 0;
48828 +
48829 if (task_pid(current) == proc_pid(inode))
48830 rv = 0;
48831 +
48832 + task = get_proc_task(inode);
48833 + if (task == NULL)
48834 + return rv;
48835 +
48836 + if (gr_acl_handle_procpidmem(task))
48837 + rv = -EACCES;
48838 +
48839 + put_task_struct(task);
48840 +
48841 return rv;
48842 }
48843
48844 @@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48845 if (!task)
48846 goto out_no_task;
48847
48848 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48849 + goto out;
48850 +
48851 /*
48852 * Yes, it does not scale. And it should not. Don't add
48853 * new entries into /proc/<tgid>/ without very good reasons.
48854 @@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48855 if (!task)
48856 goto out_no_task;
48857
48858 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48859 + goto out;
48860 +
48861 ret = 0;
48862 i = filp->f_pos;
48863 switch (i) {
48864 @@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48865 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48866 void *cookie)
48867 {
48868 - char *s = nd_get_link(nd);
48869 + const char *s = nd_get_link(nd);
48870 if (!IS_ERR(s))
48871 __putname(s);
48872 }
48873 @@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48874 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48875 #endif
48876 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48877 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48878 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48879 INF("syscall", S_IRUGO, proc_pid_syscall),
48880 #endif
48881 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48882 @@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48883 #ifdef CONFIG_SECURITY
48884 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48885 #endif
48886 -#ifdef CONFIG_KALLSYMS
48887 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48888 INF("wchan", S_IRUGO, proc_pid_wchan),
48889 #endif
48890 -#ifdef CONFIG_STACKTRACE
48891 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48892 ONE("stack", S_IRUGO, proc_pid_stack),
48893 #endif
48894 #ifdef CONFIG_SCHEDSTATS
48895 @@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48896 #ifdef CONFIG_HARDWALL
48897 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48898 #endif
48899 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48900 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48901 +#endif
48902 #ifdef CONFIG_USER_NS
48903 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48904 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48905 @@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48906 if (!inode)
48907 goto out;
48908
48909 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48910 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48911 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48912 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48913 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48914 +#else
48915 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48916 +#endif
48917 inode->i_op = &proc_tgid_base_inode_operations;
48918 inode->i_fop = &proc_tgid_base_operations;
48919 inode->i_flags|=S_IMMUTABLE;
48920 @@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48921 if (!task)
48922 goto out;
48923
48924 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48925 + goto out_put_task;
48926 +
48927 result = proc_pid_instantiate(dir, dentry, task, NULL);
48928 +out_put_task:
48929 put_task_struct(task);
48930 out:
48931 return result;
48932 @@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48933 static int fake_filldir(void *buf, const char *name, int namelen,
48934 loff_t offset, u64 ino, unsigned d_type)
48935 {
48936 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48937 + __buf->error = -EINVAL;
48938 return 0;
48939 }
48940
48941 @@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48942 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48943 #endif
48944 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48945 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48946 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48947 INF("syscall", S_IRUGO, proc_pid_syscall),
48948 #endif
48949 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48950 @@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48951 #ifdef CONFIG_SECURITY
48952 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48953 #endif
48954 -#ifdef CONFIG_KALLSYMS
48955 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48956 INF("wchan", S_IRUGO, proc_pid_wchan),
48957 #endif
48958 -#ifdef CONFIG_STACKTRACE
48959 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48960 ONE("stack", S_IRUGO, proc_pid_stack),
48961 #endif
48962 #ifdef CONFIG_SCHEDSTATS
48963 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48964 index 82676e3..5f8518a 100644
48965 --- a/fs/proc/cmdline.c
48966 +++ b/fs/proc/cmdline.c
48967 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48968
48969 static int __init proc_cmdline_init(void)
48970 {
48971 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48972 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48973 +#else
48974 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48975 +#endif
48976 return 0;
48977 }
48978 module_init(proc_cmdline_init);
48979 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48980 index b143471..bb105e5 100644
48981 --- a/fs/proc/devices.c
48982 +++ b/fs/proc/devices.c
48983 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48984
48985 static int __init proc_devices_init(void)
48986 {
48987 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48988 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48989 +#else
48990 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48991 +#endif
48992 return 0;
48993 }
48994 module_init(proc_devices_init);
48995 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48996 index 7ac817b..abab1a5 100644
48997 --- a/fs/proc/inode.c
48998 +++ b/fs/proc/inode.c
48999 @@ -21,11 +21,17 @@
49000 #include <linux/seq_file.h>
49001 #include <linux/slab.h>
49002 #include <linux/mount.h>
49003 +#include <linux/grsecurity.h>
49004
49005 #include <asm/uaccess.h>
49006
49007 #include "internal.h"
49008
49009 +#ifdef CONFIG_PROC_SYSCTL
49010 +extern const struct inode_operations proc_sys_inode_operations;
49011 +extern const struct inode_operations proc_sys_dir_operations;
49012 +#endif
49013 +
49014 static void proc_evict_inode(struct inode *inode)
49015 {
49016 struct proc_dir_entry *de;
49017 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49018 ns_ops = PROC_I(inode)->ns_ops;
49019 if (ns_ops && ns_ops->put)
49020 ns_ops->put(PROC_I(inode)->ns);
49021 +
49022 +#ifdef CONFIG_PROC_SYSCTL
49023 + if (inode->i_op == &proc_sys_inode_operations ||
49024 + inode->i_op == &proc_sys_dir_operations)
49025 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49026 +#endif
49027 +
49028 }
49029
49030 static struct kmem_cache * proc_inode_cachep;
49031 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49032 if (de->mode) {
49033 inode->i_mode = de->mode;
49034 inode->i_uid = de->uid;
49035 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49036 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49037 +#else
49038 inode->i_gid = de->gid;
49039 +#endif
49040 }
49041 if (de->size)
49042 inode->i_size = de->size;
49043 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49044 index eca4aca..19166b2 100644
49045 --- a/fs/proc/internal.h
49046 +++ b/fs/proc/internal.h
49047 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49048 struct pid *pid, struct task_struct *task);
49049 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49050 struct pid *pid, struct task_struct *task);
49051 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49052 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49053 +#endif
49054 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49055
49056 extern const struct file_operations proc_tid_children_operations;
49057 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49058 index 86c67ee..cdca321 100644
49059 --- a/fs/proc/kcore.c
49060 +++ b/fs/proc/kcore.c
49061 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49062 * the addresses in the elf_phdr on our list.
49063 */
49064 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49065 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49066 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49067 + if (tsz > buflen)
49068 tsz = buflen;
49069 -
49070 +
49071 while (buflen) {
49072 struct kcore_list *m;
49073
49074 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49075 kfree(elf_buf);
49076 } else {
49077 if (kern_addr_valid(start)) {
49078 - unsigned long n;
49079 + char *elf_buf;
49080 + mm_segment_t oldfs;
49081
49082 - n = copy_to_user(buffer, (char *)start, tsz);
49083 - /*
49084 - * We cannot distinguish between fault on source
49085 - * and fault on destination. When this happens
49086 - * we clear too and hope it will trigger the
49087 - * EFAULT again.
49088 - */
49089 - if (n) {
49090 - if (clear_user(buffer + tsz - n,
49091 - n))
49092 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49093 + if (!elf_buf)
49094 + return -ENOMEM;
49095 + oldfs = get_fs();
49096 + set_fs(KERNEL_DS);
49097 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49098 + set_fs(oldfs);
49099 + if (copy_to_user(buffer, elf_buf, tsz)) {
49100 + kfree(elf_buf);
49101 return -EFAULT;
49102 + }
49103 }
49104 + set_fs(oldfs);
49105 + kfree(elf_buf);
49106 } else {
49107 if (clear_user(buffer, tsz))
49108 return -EFAULT;
49109 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49110
49111 static int open_kcore(struct inode *inode, struct file *filp)
49112 {
49113 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49114 + return -EPERM;
49115 +#endif
49116 if (!capable(CAP_SYS_RAWIO))
49117 return -EPERM;
49118 if (kcore_need_update)
49119 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49120 index 80e4645..53e5fcf 100644
49121 --- a/fs/proc/meminfo.c
49122 +++ b/fs/proc/meminfo.c
49123 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49124 vmi.used >> 10,
49125 vmi.largest_chunk >> 10
49126 #ifdef CONFIG_MEMORY_FAILURE
49127 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49128 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49129 #endif
49130 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49131 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49132 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49133 index b1822dd..df622cb 100644
49134 --- a/fs/proc/nommu.c
49135 +++ b/fs/proc/nommu.c
49136 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49137 if (len < 1)
49138 len = 1;
49139 seq_printf(m, "%*c", len, ' ');
49140 - seq_path(m, &file->f_path, "");
49141 + seq_path(m, &file->f_path, "\n\\");
49142 }
49143
49144 seq_putc(m, '\n');
49145 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49146 index 06e1cc1..177cd98 100644
49147 --- a/fs/proc/proc_net.c
49148 +++ b/fs/proc/proc_net.c
49149 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49150 struct task_struct *task;
49151 struct nsproxy *ns;
49152 struct net *net = NULL;
49153 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49154 + const struct cred *cred = current_cred();
49155 +#endif
49156 +
49157 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49158 + if (cred->fsuid)
49159 + return net;
49160 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49161 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49162 + return net;
49163 +#endif
49164
49165 rcu_read_lock();
49166 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49167 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49168 index 3476bca..cb6d86a 100644
49169 --- a/fs/proc/proc_sysctl.c
49170 +++ b/fs/proc/proc_sysctl.c
49171 @@ -12,11 +12,15 @@
49172 #include <linux/module.h>
49173 #include "internal.h"
49174
49175 +extern int gr_handle_chroot_sysctl(const int op);
49176 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49177 + const int op);
49178 +
49179 static const struct dentry_operations proc_sys_dentry_operations;
49180 static const struct file_operations proc_sys_file_operations;
49181 -static const struct inode_operations proc_sys_inode_operations;
49182 +const struct inode_operations proc_sys_inode_operations;
49183 static const struct file_operations proc_sys_dir_file_operations;
49184 -static const struct inode_operations proc_sys_dir_operations;
49185 +const struct inode_operations proc_sys_dir_operations;
49186
49187 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49188 {
49189 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49190
49191 err = NULL;
49192 d_set_d_op(dentry, &proc_sys_dentry_operations);
49193 +
49194 + gr_handle_proc_create(dentry, inode);
49195 +
49196 d_add(dentry, inode);
49197
49198 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49199 + err = ERR_PTR(-ENOENT);
49200 +
49201 out:
49202 sysctl_head_finish(head);
49203 return err;
49204 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49205 struct inode *inode = filp->f_path.dentry->d_inode;
49206 struct ctl_table_header *head = grab_header(inode);
49207 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49208 + int op = write ? MAY_WRITE : MAY_READ;
49209 ssize_t error;
49210 size_t res;
49211
49212 if (IS_ERR(head))
49213 return PTR_ERR(head);
49214
49215 +
49216 /*
49217 * At this point we know that the sysctl was not unregistered
49218 * and won't be until we finish.
49219 */
49220 error = -EPERM;
49221 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49222 + if (sysctl_perm(head->root, table, op))
49223 goto out;
49224
49225 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49226 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49227 if (!table->proc_handler)
49228 goto out;
49229
49230 +#ifdef CONFIG_GRKERNSEC
49231 + error = -EPERM;
49232 + if (gr_handle_chroot_sysctl(op))
49233 + goto out;
49234 + dget(filp->f_path.dentry);
49235 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49236 + dput(filp->f_path.dentry);
49237 + goto out;
49238 + }
49239 + dput(filp->f_path.dentry);
49240 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49241 + goto out;
49242 + if (write && !capable(CAP_SYS_ADMIN))
49243 + goto out;
49244 +#endif
49245 +
49246 /* careful: calling conventions are nasty here */
49247 res = count;
49248 error = table->proc_handler(table, write, buf, &res, ppos);
49249 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49250 return -ENOMEM;
49251 } else {
49252 d_set_d_op(child, &proc_sys_dentry_operations);
49253 +
49254 + gr_handle_proc_create(child, inode);
49255 +
49256 d_add(child, inode);
49257 }
49258 } else {
49259 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49260 if ((*pos)++ < file->f_pos)
49261 return 0;
49262
49263 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49264 + return 0;
49265 +
49266 if (unlikely(S_ISLNK(table->mode)))
49267 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49268 else
49269 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49270 if (IS_ERR(head))
49271 return PTR_ERR(head);
49272
49273 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49274 + return -ENOENT;
49275 +
49276 generic_fillattr(inode, stat);
49277 if (table)
49278 stat->mode = (stat->mode & S_IFMT) | table->mode;
49279 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49280 .llseek = generic_file_llseek,
49281 };
49282
49283 -static const struct inode_operations proc_sys_inode_operations = {
49284 +const struct inode_operations proc_sys_inode_operations = {
49285 .permission = proc_sys_permission,
49286 .setattr = proc_sys_setattr,
49287 .getattr = proc_sys_getattr,
49288 };
49289
49290 -static const struct inode_operations proc_sys_dir_operations = {
49291 +const struct inode_operations proc_sys_dir_operations = {
49292 .lookup = proc_sys_lookup,
49293 .permission = proc_sys_permission,
49294 .setattr = proc_sys_setattr,
49295 diff --git a/fs/proc/root.c b/fs/proc/root.c
49296 index 7c30fce..b3d3aa2 100644
49297 --- a/fs/proc/root.c
49298 +++ b/fs/proc/root.c
49299 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
49300 #ifdef CONFIG_PROC_DEVICETREE
49301 proc_device_tree_init();
49302 #endif
49303 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49304 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49305 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49306 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49307 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49308 +#endif
49309 +#else
49310 proc_mkdir("bus", NULL);
49311 +#endif
49312 proc_sys_init();
49313 }
49314
49315 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49316 index 4540b8f..1b9772f 100644
49317 --- a/fs/proc/task_mmu.c
49318 +++ b/fs/proc/task_mmu.c
49319 @@ -11,12 +11,19 @@
49320 #include <linux/rmap.h>
49321 #include <linux/swap.h>
49322 #include <linux/swapops.h>
49323 +#include <linux/grsecurity.h>
49324
49325 #include <asm/elf.h>
49326 #include <asm/uaccess.h>
49327 #include <asm/tlbflush.h>
49328 #include "internal.h"
49329
49330 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49331 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49332 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49333 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49334 +#endif
49335 +
49336 void task_mem(struct seq_file *m, struct mm_struct *mm)
49337 {
49338 unsigned long data, text, lib, swap;
49339 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49340 "VmExe:\t%8lu kB\n"
49341 "VmLib:\t%8lu kB\n"
49342 "VmPTE:\t%8lu kB\n"
49343 - "VmSwap:\t%8lu kB\n",
49344 - hiwater_vm << (PAGE_SHIFT-10),
49345 + "VmSwap:\t%8lu kB\n"
49346 +
49347 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49348 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49349 +#endif
49350 +
49351 + ,hiwater_vm << (PAGE_SHIFT-10),
49352 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49353 mm->locked_vm << (PAGE_SHIFT-10),
49354 mm->pinned_vm << (PAGE_SHIFT-10),
49355 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49356 data << (PAGE_SHIFT-10),
49357 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49358 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49359 - swap << (PAGE_SHIFT-10));
49360 + swap << (PAGE_SHIFT-10)
49361 +
49362 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49363 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49364 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49365 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49366 +#else
49367 + , mm->context.user_cs_base
49368 + , mm->context.user_cs_limit
49369 +#endif
49370 +#endif
49371 +
49372 + );
49373 }
49374
49375 unsigned long task_vsize(struct mm_struct *mm)
49376 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49377 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49378 }
49379
49380 - /* We don't show the stack guard page in /proc/maps */
49381 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49382 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49383 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49384 +#else
49385 start = vma->vm_start;
49386 - if (stack_guard_page_start(vma, start))
49387 - start += PAGE_SIZE;
49388 end = vma->vm_end;
49389 - if (stack_guard_page_end(vma, end))
49390 - end -= PAGE_SIZE;
49391 +#endif
49392
49393 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49394 start,
49395 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49396 flags & VM_WRITE ? 'w' : '-',
49397 flags & VM_EXEC ? 'x' : '-',
49398 flags & VM_MAYSHARE ? 's' : 'p',
49399 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49400 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49401 +#else
49402 pgoff,
49403 +#endif
49404 MAJOR(dev), MINOR(dev), ino, &len);
49405
49406 /*
49407 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49408 */
49409 if (file) {
49410 pad_len_spaces(m, len);
49411 - seq_path(m, &file->f_path, "\n");
49412 + seq_path(m, &file->f_path, "\n\\");
49413 goto done;
49414 }
49415
49416 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49417 * Thread stack in /proc/PID/task/TID/maps or
49418 * the main process stack.
49419 */
49420 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49421 - vma->vm_end >= mm->start_stack)) {
49422 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49423 + (vma->vm_start <= mm->start_stack &&
49424 + vma->vm_end >= mm->start_stack)) {
49425 name = "[stack]";
49426 } else {
49427 /* Thread stack in /proc/PID/maps */
49428 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49429 struct proc_maps_private *priv = m->private;
49430 struct task_struct *task = priv->task;
49431
49432 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49433 + if (current->exec_id != m->exec_id) {
49434 + gr_log_badprocpid("maps");
49435 + return 0;
49436 + }
49437 +#endif
49438 +
49439 show_map_vma(m, vma, is_pid);
49440
49441 if (m->count < m->size) /* vma is copied successfully */
49442 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49443 .private = &mss,
49444 };
49445
49446 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49447 + if (current->exec_id != m->exec_id) {
49448 + gr_log_badprocpid("smaps");
49449 + return 0;
49450 + }
49451 +#endif
49452 memset(&mss, 0, sizeof mss);
49453 - mss.vma = vma;
49454 - /* mmap_sem is held in m_start */
49455 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49456 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49457 -
49458 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49459 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49460 +#endif
49461 + mss.vma = vma;
49462 + /* mmap_sem is held in m_start */
49463 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49464 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49465 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49466 + }
49467 +#endif
49468 show_map_vma(m, vma, is_pid);
49469
49470 seq_printf(m,
49471 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49472 "KernelPageSize: %8lu kB\n"
49473 "MMUPageSize: %8lu kB\n"
49474 "Locked: %8lu kB\n",
49475 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49476 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49477 +#else
49478 (vma->vm_end - vma->vm_start) >> 10,
49479 +#endif
49480 mss.resident >> 10,
49481 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49482 mss.shared_clean >> 10,
49483 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49484 int n;
49485 char buffer[50];
49486
49487 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49488 + if (current->exec_id != m->exec_id) {
49489 + gr_log_badprocpid("numa_maps");
49490 + return 0;
49491 + }
49492 +#endif
49493 +
49494 if (!mm)
49495 return 0;
49496
49497 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49498 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49499 mpol_cond_put(pol);
49500
49501 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49502 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49503 +#else
49504 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49505 +#endif
49506
49507 if (file) {
49508 seq_printf(m, " file=");
49509 - seq_path(m, &file->f_path, "\n\t= ");
49510 + seq_path(m, &file->f_path, "\n\t\\= ");
49511 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49512 seq_printf(m, " heap");
49513 } else {
49514 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49515 index 1ccfa53..0848f95 100644
49516 --- a/fs/proc/task_nommu.c
49517 +++ b/fs/proc/task_nommu.c
49518 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49519 else
49520 bytes += kobjsize(mm);
49521
49522 - if (current->fs && current->fs->users > 1)
49523 + if (current->fs && atomic_read(&current->fs->users) > 1)
49524 sbytes += kobjsize(current->fs);
49525 else
49526 bytes += kobjsize(current->fs);
49527 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49528
49529 if (file) {
49530 pad_len_spaces(m, len);
49531 - seq_path(m, &file->f_path, "");
49532 + seq_path(m, &file->f_path, "\n\\");
49533 } else if (mm) {
49534 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49535
49536 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49537 index d67908b..d13f6a6 100644
49538 --- a/fs/quota/netlink.c
49539 +++ b/fs/quota/netlink.c
49540 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49541 void quota_send_warning(short type, unsigned int id, dev_t dev,
49542 const char warntype)
49543 {
49544 - static atomic_t seq;
49545 + static atomic_unchecked_t seq;
49546 struct sk_buff *skb;
49547 void *msg_head;
49548 int ret;
49549 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49550 "VFS: Not enough memory to send quota warning.\n");
49551 return;
49552 }
49553 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49554 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49555 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49556 if (!msg_head) {
49557 printk(KERN_ERR
49558 diff --git a/fs/readdir.c b/fs/readdir.c
49559 index 39e3370..20d446d 100644
49560 --- a/fs/readdir.c
49561 +++ b/fs/readdir.c
49562 @@ -17,6 +17,7 @@
49563 #include <linux/security.h>
49564 #include <linux/syscalls.h>
49565 #include <linux/unistd.h>
49566 +#include <linux/namei.h>
49567
49568 #include <asm/uaccess.h>
49569
49570 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49571
49572 struct readdir_callback {
49573 struct old_linux_dirent __user * dirent;
49574 + struct file * file;
49575 int result;
49576 };
49577
49578 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49579 buf->result = -EOVERFLOW;
49580 return -EOVERFLOW;
49581 }
49582 +
49583 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49584 + return 0;
49585 +
49586 buf->result++;
49587 dirent = buf->dirent;
49588 if (!access_ok(VERIFY_WRITE, dirent,
49589 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49590
49591 buf.result = 0;
49592 buf.dirent = dirent;
49593 + buf.file = file;
49594
49595 error = vfs_readdir(file, fillonedir, &buf);
49596 if (buf.result)
49597 @@ -141,6 +148,7 @@ struct linux_dirent {
49598 struct getdents_callback {
49599 struct linux_dirent __user * current_dir;
49600 struct linux_dirent __user * previous;
49601 + struct file * file;
49602 int count;
49603 int error;
49604 };
49605 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49606 buf->error = -EOVERFLOW;
49607 return -EOVERFLOW;
49608 }
49609 +
49610 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49611 + return 0;
49612 +
49613 dirent = buf->previous;
49614 if (dirent) {
49615 if (__put_user(offset, &dirent->d_off))
49616 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49617 buf.previous = NULL;
49618 buf.count = count;
49619 buf.error = 0;
49620 + buf.file = file;
49621
49622 error = vfs_readdir(file, filldir, &buf);
49623 if (error >= 0)
49624 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49625 struct getdents_callback64 {
49626 struct linux_dirent64 __user * current_dir;
49627 struct linux_dirent64 __user * previous;
49628 + struct file *file;
49629 int count;
49630 int error;
49631 };
49632 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49633 buf->error = -EINVAL; /* only used if we fail.. */
49634 if (reclen > buf->count)
49635 return -EINVAL;
49636 +
49637 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49638 + return 0;
49639 +
49640 dirent = buf->previous;
49641 if (dirent) {
49642 if (__put_user(offset, &dirent->d_off))
49643 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49644
49645 buf.current_dir = dirent;
49646 buf.previous = NULL;
49647 + buf.file = file;
49648 buf.count = count;
49649 buf.error = 0;
49650
49651 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49652 error = buf.error;
49653 lastdirent = buf.previous;
49654 if (lastdirent) {
49655 - typeof(lastdirent->d_off) d_off = file->f_pos;
49656 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49657 if (__put_user(d_off, &lastdirent->d_off))
49658 error = -EFAULT;
49659 else
49660 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49661 index 2b7882b..1c5ef48 100644
49662 --- a/fs/reiserfs/do_balan.c
49663 +++ b/fs/reiserfs/do_balan.c
49664 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49665 return;
49666 }
49667
49668 - atomic_inc(&(fs_generation(tb->tb_sb)));
49669 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49670 do_balance_starts(tb);
49671
49672 /* balance leaf returns 0 except if combining L R and S into
49673 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49674 index 2c1ade6..8c59d8d 100644
49675 --- a/fs/reiserfs/procfs.c
49676 +++ b/fs/reiserfs/procfs.c
49677 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49678 "SMALL_TAILS " : "NO_TAILS ",
49679 replay_only(sb) ? "REPLAY_ONLY " : "",
49680 convert_reiserfs(sb) ? "CONV " : "",
49681 - atomic_read(&r->s_generation_counter),
49682 + atomic_read_unchecked(&r->s_generation_counter),
49683 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49684 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49685 SF(s_good_search_by_key_reada), SF(s_bmaps),
49686 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49687 index 33215f5..c5d427a 100644
49688 --- a/fs/reiserfs/reiserfs.h
49689 +++ b/fs/reiserfs/reiserfs.h
49690 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49691 /* Comment? -Hans */
49692 wait_queue_head_t s_wait;
49693 /* To be obsoleted soon by per buffer seals.. -Hans */
49694 - atomic_t s_generation_counter; // increased by one every time the
49695 + atomic_unchecked_t s_generation_counter; // increased by one every time the
49696 // tree gets re-balanced
49697 unsigned long s_properties; /* File system properties. Currently holds
49698 on-disk FS format */
49699 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49700 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49701
49702 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49703 -#define get_generation(s) atomic_read (&fs_generation(s))
49704 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49705 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49706 #define __fs_changed(gen,s) (gen != get_generation (s))
49707 #define fs_changed(gen,s) \
49708 diff --git a/fs/select.c b/fs/select.c
49709 index db14c78..3aae1bd 100644
49710 --- a/fs/select.c
49711 +++ b/fs/select.c
49712 @@ -20,6 +20,7 @@
49713 #include <linux/export.h>
49714 #include <linux/slab.h>
49715 #include <linux/poll.h>
49716 +#include <linux/security.h>
49717 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49718 #include <linux/file.h>
49719 #include <linux/fdtable.h>
49720 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49721 struct poll_list *walk = head;
49722 unsigned long todo = nfds;
49723
49724 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49725 if (nfds > rlimit(RLIMIT_NOFILE))
49726 return -EINVAL;
49727
49728 diff --git a/fs/seq_file.c b/fs/seq_file.c
49729 index 0cbd049..64e705c 100644
49730 --- a/fs/seq_file.c
49731 +++ b/fs/seq_file.c
49732 @@ -9,6 +9,7 @@
49733 #include <linux/export.h>
49734 #include <linux/seq_file.h>
49735 #include <linux/slab.h>
49736 +#include <linux/sched.h>
49737
49738 #include <asm/uaccess.h>
49739 #include <asm/page.h>
49740 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49741 memset(p, 0, sizeof(*p));
49742 mutex_init(&p->lock);
49743 p->op = op;
49744 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49745 + p->exec_id = current->exec_id;
49746 +#endif
49747
49748 /*
49749 * Wrappers around seq_open(e.g. swaps_open) need to be
49750 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49751 return 0;
49752 }
49753 if (!m->buf) {
49754 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49755 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49756 if (!m->buf)
49757 return -ENOMEM;
49758 }
49759 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49760 Eoverflow:
49761 m->op->stop(m, p);
49762 kfree(m->buf);
49763 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49764 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49765 return !m->buf ? -ENOMEM : -EAGAIN;
49766 }
49767
49768 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49769
49770 /* grab buffer if we didn't have one */
49771 if (!m->buf) {
49772 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49773 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49774 if (!m->buf)
49775 goto Enomem;
49776 }
49777 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49778 goto Fill;
49779 m->op->stop(m, p);
49780 kfree(m->buf);
49781 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49782 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49783 if (!m->buf)
49784 goto Enomem;
49785 m->count = 0;
49786 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49787 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49788 void *data)
49789 {
49790 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49791 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49792 int res = -ENOMEM;
49793
49794 if (op) {
49795 diff --git a/fs/splice.c b/fs/splice.c
49796 index 7bf08fa..eb35c2f 100644
49797 --- a/fs/splice.c
49798 +++ b/fs/splice.c
49799 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49800 pipe_lock(pipe);
49801
49802 for (;;) {
49803 - if (!pipe->readers) {
49804 + if (!atomic_read(&pipe->readers)) {
49805 send_sig(SIGPIPE, current, 0);
49806 if (!ret)
49807 ret = -EPIPE;
49808 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49809 do_wakeup = 0;
49810 }
49811
49812 - pipe->waiting_writers++;
49813 + atomic_inc(&pipe->waiting_writers);
49814 pipe_wait(pipe);
49815 - pipe->waiting_writers--;
49816 + atomic_dec(&pipe->waiting_writers);
49817 }
49818
49819 pipe_unlock(pipe);
49820 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49821 old_fs = get_fs();
49822 set_fs(get_ds());
49823 /* The cast to a user pointer is valid due to the set_fs() */
49824 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49825 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49826 set_fs(old_fs);
49827
49828 return res;
49829 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49830 old_fs = get_fs();
49831 set_fs(get_ds());
49832 /* The cast to a user pointer is valid due to the set_fs() */
49833 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49834 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49835 set_fs(old_fs);
49836
49837 return res;
49838 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49839 goto err;
49840
49841 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49842 - vec[i].iov_base = (void __user *) page_address(page);
49843 + vec[i].iov_base = (void __force_user *) page_address(page);
49844 vec[i].iov_len = this_len;
49845 spd.pages[i] = page;
49846 spd.nr_pages++;
49847 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49848 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49849 {
49850 while (!pipe->nrbufs) {
49851 - if (!pipe->writers)
49852 + if (!atomic_read(&pipe->writers))
49853 return 0;
49854
49855 - if (!pipe->waiting_writers && sd->num_spliced)
49856 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49857 return 0;
49858
49859 if (sd->flags & SPLICE_F_NONBLOCK)
49860 @@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49861 * out of the pipe right after the splice_to_pipe(). So set
49862 * PIPE_READERS appropriately.
49863 */
49864 - pipe->readers = 1;
49865 + atomic_set(&pipe->readers, 1);
49866
49867 current->splice_pipe = pipe;
49868 }
49869 @@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49870 ret = -ERESTARTSYS;
49871 break;
49872 }
49873 - if (!pipe->writers)
49874 + if (!atomic_read(&pipe->writers))
49875 break;
49876 - if (!pipe->waiting_writers) {
49877 + if (!atomic_read(&pipe->waiting_writers)) {
49878 if (flags & SPLICE_F_NONBLOCK) {
49879 ret = -EAGAIN;
49880 break;
49881 @@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49882 pipe_lock(pipe);
49883
49884 while (pipe->nrbufs >= pipe->buffers) {
49885 - if (!pipe->readers) {
49886 + if (!atomic_read(&pipe->readers)) {
49887 send_sig(SIGPIPE, current, 0);
49888 ret = -EPIPE;
49889 break;
49890 @@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49891 ret = -ERESTARTSYS;
49892 break;
49893 }
49894 - pipe->waiting_writers++;
49895 + atomic_inc(&pipe->waiting_writers);
49896 pipe_wait(pipe);
49897 - pipe->waiting_writers--;
49898 + atomic_dec(&pipe->waiting_writers);
49899 }
49900
49901 pipe_unlock(pipe);
49902 @@ -1825,14 +1825,14 @@ retry:
49903 pipe_double_lock(ipipe, opipe);
49904
49905 do {
49906 - if (!opipe->readers) {
49907 + if (!atomic_read(&opipe->readers)) {
49908 send_sig(SIGPIPE, current, 0);
49909 if (!ret)
49910 ret = -EPIPE;
49911 break;
49912 }
49913
49914 - if (!ipipe->nrbufs && !ipipe->writers)
49915 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49916 break;
49917
49918 /*
49919 @@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49920 pipe_double_lock(ipipe, opipe);
49921
49922 do {
49923 - if (!opipe->readers) {
49924 + if (!atomic_read(&opipe->readers)) {
49925 send_sig(SIGPIPE, current, 0);
49926 if (!ret)
49927 ret = -EPIPE;
49928 @@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49929 * return EAGAIN if we have the potential of some data in the
49930 * future, otherwise just return 0
49931 */
49932 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49933 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49934 ret = -EAGAIN;
49935
49936 pipe_unlock(ipipe);
49937 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49938 index e6bb9b2..d8e3951 100644
49939 --- a/fs/sysfs/dir.c
49940 +++ b/fs/sysfs/dir.c
49941 @@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49942 struct sysfs_dirent *sd;
49943 int rc;
49944
49945 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49946 + const char *parent_name = parent_sd->s_name;
49947 +
49948 + mode = S_IFDIR | S_IRWXU;
49949 +
49950 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49951 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49952 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49953 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49954 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49955 +#endif
49956 +
49957 /* allocate */
49958 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49959 if (!sd)
49960 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49961 index 00012e3..8392349 100644
49962 --- a/fs/sysfs/file.c
49963 +++ b/fs/sysfs/file.c
49964 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49965
49966 struct sysfs_open_dirent {
49967 atomic_t refcnt;
49968 - atomic_t event;
49969 + atomic_unchecked_t event;
49970 wait_queue_head_t poll;
49971 struct list_head buffers; /* goes through sysfs_buffer.list */
49972 };
49973 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49974 if (!sysfs_get_active(attr_sd))
49975 return -ENODEV;
49976
49977 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49978 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49979 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49980
49981 sysfs_put_active(attr_sd);
49982 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49983 return -ENOMEM;
49984
49985 atomic_set(&new_od->refcnt, 0);
49986 - atomic_set(&new_od->event, 1);
49987 + atomic_set_unchecked(&new_od->event, 1);
49988 init_waitqueue_head(&new_od->poll);
49989 INIT_LIST_HEAD(&new_od->buffers);
49990 goto retry;
49991 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49992
49993 sysfs_put_active(attr_sd);
49994
49995 - if (buffer->event != atomic_read(&od->event))
49996 + if (buffer->event != atomic_read_unchecked(&od->event))
49997 goto trigger;
49998
49999 return DEFAULT_POLLMASK;
50000 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50001
50002 od = sd->s_attr.open;
50003 if (od) {
50004 - atomic_inc(&od->event);
50005 + atomic_inc_unchecked(&od->event);
50006 wake_up_interruptible(&od->poll);
50007 }
50008
50009 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50010 index a7ac78f..02158e1 100644
50011 --- a/fs/sysfs/symlink.c
50012 +++ b/fs/sysfs/symlink.c
50013 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50014
50015 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50016 {
50017 - char *page = nd_get_link(nd);
50018 + const char *page = nd_get_link(nd);
50019 if (!IS_ERR(page))
50020 free_page((unsigned long)page);
50021 }
50022 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50023 index c175b4d..8f36a16 100644
50024 --- a/fs/udf/misc.c
50025 +++ b/fs/udf/misc.c
50026 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50027
50028 u8 udf_tag_checksum(const struct tag *t)
50029 {
50030 - u8 *data = (u8 *)t;
50031 + const u8 *data = (const u8 *)t;
50032 u8 checksum = 0;
50033 int i;
50034 for (i = 0; i < sizeof(struct tag); ++i)
50035 diff --git a/fs/udf/namei.c b/fs/udf/namei.c
50036 index 1802417..c31deb3 100644
50037 --- a/fs/udf/namei.c
50038 +++ b/fs/udf/namei.c
50039 @@ -1279,6 +1279,7 @@ static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
50040 *lenp = 3;
50041 fid->udf.block = location.logicalBlockNum;
50042 fid->udf.partref = location.partitionReferenceNum;
50043 + fid->udf.parent_partref = 0;
50044 fid->udf.generation = inode->i_generation;
50045
50046 if (parent) {
50047 diff --git a/fs/utimes.c b/fs/utimes.c
50048 index fa4dbe4..e12d1b9 100644
50049 --- a/fs/utimes.c
50050 +++ b/fs/utimes.c
50051 @@ -1,6 +1,7 @@
50052 #include <linux/compiler.h>
50053 #include <linux/file.h>
50054 #include <linux/fs.h>
50055 +#include <linux/security.h>
50056 #include <linux/linkage.h>
50057 #include <linux/mount.h>
50058 #include <linux/namei.h>
50059 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50060 goto mnt_drop_write_and_out;
50061 }
50062 }
50063 +
50064 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50065 + error = -EACCES;
50066 + goto mnt_drop_write_and_out;
50067 + }
50068 +
50069 mutex_lock(&inode->i_mutex);
50070 error = notify_change(path->dentry, &newattrs);
50071 mutex_unlock(&inode->i_mutex);
50072 diff --git a/fs/xattr.c b/fs/xattr.c
50073 index 1d7ac37..23cb9ec 100644
50074 --- a/fs/xattr.c
50075 +++ b/fs/xattr.c
50076 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50077 * Extended attribute SET operations
50078 */
50079 static long
50080 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50081 +setxattr(struct path *path, const char __user *name, const void __user *value,
50082 size_t size, int flags)
50083 {
50084 int error;
50085 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50086 }
50087 }
50088
50089 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50090 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50091 + error = -EACCES;
50092 + goto out;
50093 + }
50094 +
50095 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50096 out:
50097 if (vvalue)
50098 vfree(vvalue);
50099 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50100 return error;
50101 error = mnt_want_write(path.mnt);
50102 if (!error) {
50103 - error = setxattr(path.dentry, name, value, size, flags);
50104 + error = setxattr(&path, name, value, size, flags);
50105 mnt_drop_write(path.mnt);
50106 }
50107 path_put(&path);
50108 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50109 return error;
50110 error = mnt_want_write(path.mnt);
50111 if (!error) {
50112 - error = setxattr(path.dentry, name, value, size, flags);
50113 + error = setxattr(&path, name, value, size, flags);
50114 mnt_drop_write(path.mnt);
50115 }
50116 path_put(&path);
50117 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50118 {
50119 int fput_needed;
50120 struct file *f;
50121 - struct dentry *dentry;
50122 int error = -EBADF;
50123
50124 f = fget_light(fd, &fput_needed);
50125 if (!f)
50126 return error;
50127 - dentry = f->f_path.dentry;
50128 - audit_inode(NULL, dentry);
50129 + audit_inode(NULL, f->f_path.dentry);
50130 error = mnt_want_write_file(f);
50131 if (!error) {
50132 - error = setxattr(dentry, name, value, size, flags);
50133 + error = setxattr(&f->f_path, name, value, size, flags);
50134 mnt_drop_write_file(f);
50135 }
50136 fput_light(f, fput_needed);
50137 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50138 index 69d06b0..c0996e5 100644
50139 --- a/fs/xattr_acl.c
50140 +++ b/fs/xattr_acl.c
50141 @@ -17,8 +17,8 @@
50142 struct posix_acl *
50143 posix_acl_from_xattr(const void *value, size_t size)
50144 {
50145 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50146 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50147 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50148 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50149 int count;
50150 struct posix_acl *acl;
50151 struct posix_acl_entry *acl_e;
50152 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50153 index 58b815e..595ddee 100644
50154 --- a/fs/xfs/xfs_bmap.c
50155 +++ b/fs/xfs/xfs_bmap.c
50156 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50157 int nmap,
50158 int ret_nmap);
50159 #else
50160 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50161 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50162 #endif /* DEBUG */
50163
50164 STATIC int
50165 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50166 index 19bf0c5..9f26b02 100644
50167 --- a/fs/xfs/xfs_dir2_sf.c
50168 +++ b/fs/xfs/xfs_dir2_sf.c
50169 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50170 }
50171
50172 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50173 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50174 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50175 + char name[sfep->namelen];
50176 + memcpy(name, sfep->name, sfep->namelen);
50177 + if (filldir(dirent, name, sfep->namelen,
50178 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50179 + *offset = off & 0x7fffffff;
50180 + return 0;
50181 + }
50182 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50183 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50184 *offset = off & 0x7fffffff;
50185 return 0;
50186 diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
50187 index f9c3fe3..69cf4fc 100644
50188 --- a/fs/xfs/xfs_discard.c
50189 +++ b/fs/xfs/xfs_discard.c
50190 @@ -179,12 +179,14 @@ xfs_ioc_trim(
50191 * used by the fstrim application. In the end it really doesn't
50192 * matter as trimming blocks is an advisory interface.
50193 */
50194 + if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) ||
50195 + range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)))
50196 + return -XFS_ERROR(EINVAL);
50197 +
50198 start = BTOBB(range.start);
50199 end = start + BTOBBT(range.len) - 1;
50200 minlen = BTOBB(max_t(u64, granularity, range.minlen));
50201
50202 - if (XFS_BB_TO_FSB(mp, start) >= mp->m_sb.sb_dblocks)
50203 - return -XFS_ERROR(EINVAL);
50204 if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
50205 end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1;
50206
50207 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50208 index 3a05a41..320bec6 100644
50209 --- a/fs/xfs/xfs_ioctl.c
50210 +++ b/fs/xfs/xfs_ioctl.c
50211 @@ -126,7 +126,7 @@ xfs_find_handle(
50212 }
50213
50214 error = -EFAULT;
50215 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50216 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50217 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50218 goto out_put;
50219
50220 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50221 index 1a25fd8..e935581 100644
50222 --- a/fs/xfs/xfs_iops.c
50223 +++ b/fs/xfs/xfs_iops.c
50224 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50225 struct nameidata *nd,
50226 void *p)
50227 {
50228 - char *s = nd_get_link(nd);
50229 + const char *s = nd_get_link(nd);
50230
50231 if (!IS_ERR(s))
50232 kfree(s);
50233 diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
50234 index 92d4331..ca28a4b 100644
50235 --- a/fs/xfs/xfs_rtalloc.c
50236 +++ b/fs/xfs/xfs_rtalloc.c
50237 @@ -857,7 +857,7 @@ xfs_rtbuf_get(
50238 xfs_buf_t *bp; /* block buffer, result */
50239 xfs_inode_t *ip; /* bitmap or summary inode */
50240 xfs_bmbt_irec_t map;
50241 - int nmap;
50242 + int nmap = 1;
50243 int error; /* error value */
50244
50245 ip = issum ? mp->m_rsumip : mp->m_rbmip;
50246 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50247 new file mode 100644
50248 index 0000000..4d533f1
50249 --- /dev/null
50250 +++ b/grsecurity/Kconfig
50251 @@ -0,0 +1,941 @@
50252 +#
50253 +# grecurity configuration
50254 +#
50255 +menu "Memory Protections"
50256 +depends on GRKERNSEC
50257 +
50258 +config GRKERNSEC_KMEM
50259 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50260 + default y if GRKERNSEC_CONFIG_AUTO
50261 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50262 + help
50263 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50264 + be written to or read from to modify or leak the contents of the running
50265 + kernel. /dev/port will also not be allowed to be opened. If you have module
50266 + support disabled, enabling this will close up four ways that are
50267 + currently used to insert malicious code into the running kernel.
50268 + Even with all these features enabled, we still highly recommend that
50269 + you use the RBAC system, as it is still possible for an attacker to
50270 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50271 + If you are not using XFree86, you may be able to stop this additional
50272 + case by enabling the 'Disable privileged I/O' option. Though nothing
50273 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50274 + but only to video memory, which is the only writing we allow in this
50275 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50276 + not be allowed to mprotect it with PROT_WRITE later.
50277 + It is highly recommended that you say Y here if you meet all the
50278 + conditions above.
50279 +
50280 +config GRKERNSEC_VM86
50281 + bool "Restrict VM86 mode"
50282 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50283 + depends on X86_32
50284 +
50285 + help
50286 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50287 + make use of a special execution mode on 32bit x86 processors called
50288 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50289 + video cards and will still work with this option enabled. The purpose
50290 + of the option is to prevent exploitation of emulation errors in
50291 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50292 + Nearly all users should be able to enable this option.
50293 +
50294 +config GRKERNSEC_IO
50295 + bool "Disable privileged I/O"
50296 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50297 + depends on X86
50298 + select RTC_CLASS
50299 + select RTC_INTF_DEV
50300 + select RTC_DRV_CMOS
50301 +
50302 + help
50303 + If you say Y here, all ioperm and iopl calls will return an error.
50304 + Ioperm and iopl can be used to modify the running kernel.
50305 + Unfortunately, some programs need this access to operate properly,
50306 + the most notable of which are XFree86 and hwclock. hwclock can be
50307 + remedied by having RTC support in the kernel, so real-time
50308 + clock support is enabled if this option is enabled, to ensure
50309 + that hwclock operates correctly. XFree86 still will not
50310 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50311 + IF YOU USE XFree86. If you use XFree86 and you still want to
50312 + protect your kernel against modification, use the RBAC system.
50313 +
50314 +config GRKERNSEC_PROC_MEMMAP
50315 + bool "Harden ASLR against information leaks and entropy reduction"
50316 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50317 + depends on PAX_NOEXEC || PAX_ASLR
50318 + help
50319 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50320 + give no information about the addresses of its mappings if
50321 + PaX features that rely on random addresses are enabled on the task.
50322 + In addition to sanitizing this information and disabling other
50323 + dangerous sources of information, this option causes reads of sensitive
50324 + /proc/<pid> entries where the file descriptor was opened in a different
50325 + task than the one performing the read. Such attempts are logged.
50326 + This option also limits argv/env strings for suid/sgid binaries
50327 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50328 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50329 + binaries to prevent alternative mmap layouts from being abused.
50330 +
50331 + If you use PaX it is essential that you say Y here as it closes up
50332 + several holes that make full ASLR useless locally.
50333 +
50334 +config GRKERNSEC_BRUTE
50335 + bool "Deter exploit bruteforcing"
50336 + default y if GRKERNSEC_CONFIG_AUTO
50337 + help
50338 + If you say Y here, attempts to bruteforce exploits against forking
50339 + daemons such as apache or sshd, as well as against suid/sgid binaries
50340 + will be deterred. When a child of a forking daemon is killed by PaX
50341 + or crashes due to an illegal instruction or other suspicious signal,
50342 + the parent process will be delayed 30 seconds upon every subsequent
50343 + fork until the administrator is able to assess the situation and
50344 + restart the daemon.
50345 + In the suid/sgid case, the attempt is logged, the user has all their
50346 + processes terminated, and they are prevented from executing any further
50347 + processes for 15 minutes.
50348 + It is recommended that you also enable signal logging in the auditing
50349 + section so that logs are generated when a process triggers a suspicious
50350 + signal.
50351 + If the sysctl option is enabled, a sysctl option with name
50352 + "deter_bruteforce" is created.
50353 +
50354 +
50355 +config GRKERNSEC_MODHARDEN
50356 + bool "Harden module auto-loading"
50357 + default y if GRKERNSEC_CONFIG_AUTO
50358 + depends on MODULES
50359 + help
50360 + If you say Y here, module auto-loading in response to use of some
50361 + feature implemented by an unloaded module will be restricted to
50362 + root users. Enabling this option helps defend against attacks
50363 + by unprivileged users who abuse the auto-loading behavior to
50364 + cause a vulnerable module to load that is then exploited.
50365 +
50366 + If this option prevents a legitimate use of auto-loading for a
50367 + non-root user, the administrator can execute modprobe manually
50368 + with the exact name of the module mentioned in the alert log.
50369 + Alternatively, the administrator can add the module to the list
50370 + of modules loaded at boot by modifying init scripts.
50371 +
50372 + Modification of init scripts will most likely be needed on
50373 + Ubuntu servers with encrypted home directory support enabled,
50374 + as the first non-root user logging in will cause the ecb(aes),
50375 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50376 +
50377 +config GRKERNSEC_HIDESYM
50378 + bool "Hide kernel symbols"
50379 + default y if GRKERNSEC_CONFIG_AUTO
50380 + select PAX_USERCOPY_SLABS
50381 + help
50382 + If you say Y here, getting information on loaded modules, and
50383 + displaying all kernel symbols through a syscall will be restricted
50384 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50385 + /proc/kallsyms will be restricted to the root user. The RBAC
50386 + system can hide that entry even from root.
50387 +
50388 + This option also prevents leaking of kernel addresses through
50389 + several /proc entries.
50390 +
50391 + Note that this option is only effective provided the following
50392 + conditions are met:
50393 + 1) The kernel using grsecurity is not precompiled by some distribution
50394 + 2) You have also enabled GRKERNSEC_DMESG
50395 + 3) You are using the RBAC system and hiding other files such as your
50396 + kernel image and System.map. Alternatively, enabling this option
50397 + causes the permissions on /boot, /lib/modules, and the kernel
50398 + source directory to change at compile time to prevent
50399 + reading by non-root users.
50400 + If the above conditions are met, this option will aid in providing a
50401 + useful protection against local kernel exploitation of overflows
50402 + and arbitrary read/write vulnerabilities.
50403 +
50404 +config GRKERNSEC_KERN_LOCKOUT
50405 + bool "Active kernel exploit response"
50406 + default y if GRKERNSEC_CONFIG_AUTO
50407 + depends on X86 || ARM || PPC || SPARC
50408 + help
50409 + If you say Y here, when a PaX alert is triggered due to suspicious
50410 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50411 + or an OOPS occurs due to bad memory accesses, instead of just
50412 + terminating the offending process (and potentially allowing
50413 + a subsequent exploit from the same user), we will take one of two
50414 + actions:
50415 + If the user was root, we will panic the system
50416 + If the user was non-root, we will log the attempt, terminate
50417 + all processes owned by the user, then prevent them from creating
50418 + any new processes until the system is restarted
50419 + This deters repeated kernel exploitation/bruteforcing attempts
50420 + and is useful for later forensics.
50421 +
50422 +endmenu
50423 +menu "Role Based Access Control Options"
50424 +depends on GRKERNSEC
50425 +
50426 +config GRKERNSEC_RBAC_DEBUG
50427 + bool
50428 +
50429 +config GRKERNSEC_NO_RBAC
50430 + bool "Disable RBAC system"
50431 + help
50432 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50433 + preventing the RBAC system from being enabled. You should only say Y
50434 + here if you have no intention of using the RBAC system, so as to prevent
50435 + an attacker with root access from misusing the RBAC system to hide files
50436 + and processes when loadable module support and /dev/[k]mem have been
50437 + locked down.
50438 +
50439 +config GRKERNSEC_ACL_HIDEKERN
50440 + bool "Hide kernel processes"
50441 + help
50442 + If you say Y here, all kernel threads will be hidden to all
50443 + processes but those whose subject has the "view hidden processes"
50444 + flag.
50445 +
50446 +config GRKERNSEC_ACL_MAXTRIES
50447 + int "Maximum tries before password lockout"
50448 + default 3
50449 + help
50450 + This option enforces the maximum number of times a user can attempt
50451 + to authorize themselves with the grsecurity RBAC system before being
50452 + denied the ability to attempt authorization again for a specified time.
50453 + The lower the number, the harder it will be to brute-force a password.
50454 +
50455 +config GRKERNSEC_ACL_TIMEOUT
50456 + int "Time to wait after max password tries, in seconds"
50457 + default 30
50458 + help
50459 + This option specifies the time the user must wait after attempting to
50460 + authorize to the RBAC system with the maximum number of invalid
50461 + passwords. The higher the number, the harder it will be to brute-force
50462 + a password.
50463 +
50464 +endmenu
50465 +menu "Filesystem Protections"
50466 +depends on GRKERNSEC
50467 +
50468 +config GRKERNSEC_PROC
50469 + bool "Proc restrictions"
50470 + default y if GRKERNSEC_CONFIG_AUTO
50471 + help
50472 + If you say Y here, the permissions of the /proc filesystem
50473 + will be altered to enhance system security and privacy. You MUST
50474 + choose either a user only restriction or a user and group restriction.
50475 + Depending upon the option you choose, you can either restrict users to
50476 + see only the processes they themselves run, or choose a group that can
50477 + view all processes and files normally restricted to root if you choose
50478 + the "restrict to user only" option. NOTE: If you're running identd or
50479 + ntpd as a non-root user, you will have to run it as the group you
50480 + specify here.
50481 +
50482 +config GRKERNSEC_PROC_USER
50483 + bool "Restrict /proc to user only"
50484 + depends on GRKERNSEC_PROC
50485 + help
50486 + If you say Y here, non-root users will only be able to view their own
50487 + processes, and restricts them from viewing network-related information,
50488 + and viewing kernel symbol and module information.
50489 +
50490 +config GRKERNSEC_PROC_USERGROUP
50491 + bool "Allow special group"
50492 + default y if GRKERNSEC_CONFIG_AUTO
50493 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50494 + help
50495 + If you say Y here, you will be able to select a group that will be
50496 + able to view all processes and network-related information. If you've
50497 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50498 + remain hidden. This option is useful if you want to run identd as
50499 + a non-root user.
50500 +
50501 +config GRKERNSEC_PROC_GID
50502 + int "GID for special group"
50503 + depends on GRKERNSEC_PROC_USERGROUP
50504 + default 1001
50505 +
50506 +config GRKERNSEC_PROC_ADD
50507 + bool "Additional restrictions"
50508 + default y if GRKERNSEC_CONFIG_AUTO
50509 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50510 + help
50511 + If you say Y here, additional restrictions will be placed on
50512 + /proc that keep normal users from viewing device information and
50513 + slabinfo information that could be useful for exploits.
50514 +
50515 +config GRKERNSEC_LINK
50516 + bool "Linking restrictions"
50517 + default y if GRKERNSEC_CONFIG_AUTO
50518 + help
50519 + If you say Y here, /tmp race exploits will be prevented, since users
50520 + will no longer be able to follow symlinks owned by other users in
50521 + world-writable +t directories (e.g. /tmp), unless the owner of the
50522 + symlink is the owner of the directory. users will also not be
50523 + able to hardlink to files they do not own. If the sysctl option is
50524 + enabled, a sysctl option with name "linking_restrictions" is created.
50525 +
50526 +config GRKERNSEC_SYMLINKOWN
50527 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50528 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50529 + help
50530 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50531 + that prevents it from being used as a security feature. As Apache
50532 + verifies the symlink by performing a stat() against the target of
50533 + the symlink before it is followed, an attacker can setup a symlink
50534 + to point to a same-owned file, then replace the symlink with one
50535 + that targets another user's file just after Apache "validates" the
50536 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50537 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50538 + will be in place for the group you specify. If the sysctl option
50539 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50540 + created.
50541 +
50542 +config GRKERNSEC_SYMLINKOWN_GID
50543 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50544 + depends on GRKERNSEC_SYMLINKOWN
50545 + default 1006
50546 + help
50547 + Setting this GID determines what group kernel-enforced
50548 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50549 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50550 +
50551 +config GRKERNSEC_FIFO
50552 + bool "FIFO restrictions"
50553 + default y if GRKERNSEC_CONFIG_AUTO
50554 + help
50555 + If you say Y here, users will not be able to write to FIFOs they don't
50556 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50557 + the FIFO is the same owner of the directory it's held in. If the sysctl
50558 + option is enabled, a sysctl option with name "fifo_restrictions" is
50559 + created.
50560 +
50561 +config GRKERNSEC_SYSFS_RESTRICT
50562 + bool "Sysfs/debugfs restriction"
50563 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50564 + depends on SYSFS
50565 + help
50566 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50567 + any filesystem normally mounted under it (e.g. debugfs) will be
50568 + mostly accessible only by root. These filesystems generally provide access
50569 + to hardware and debug information that isn't appropriate for unprivileged
50570 + users of the system. Sysfs and debugfs have also become a large source
50571 + of new vulnerabilities, ranging from infoleaks to local compromise.
50572 + There has been very little oversight with an eye toward security involved
50573 + in adding new exporters of information to these filesystems, so their
50574 + use is discouraged.
50575 + For reasons of compatibility, a few directories have been whitelisted
50576 + for access by non-root users:
50577 + /sys/fs/selinux
50578 + /sys/fs/fuse
50579 + /sys/devices/system/cpu
50580 +
50581 +config GRKERNSEC_ROFS
50582 + bool "Runtime read-only mount protection"
50583 + help
50584 + If you say Y here, a sysctl option with name "romount_protect" will
50585 + be created. By setting this option to 1 at runtime, filesystems
50586 + will be protected in the following ways:
50587 + * No new writable mounts will be allowed
50588 + * Existing read-only mounts won't be able to be remounted read/write
50589 + * Write operations will be denied on all block devices
50590 + This option acts independently of grsec_lock: once it is set to 1,
50591 + it cannot be turned off. Therefore, please be mindful of the resulting
50592 + behavior if this option is enabled in an init script on a read-only
50593 + filesystem. This feature is mainly intended for secure embedded systems.
50594 +
50595 +config GRKERNSEC_CHROOT
50596 + bool "Chroot jail restrictions"
50597 + default y if GRKERNSEC_CONFIG_AUTO
50598 + help
50599 + If you say Y here, you will be able to choose several options that will
50600 + make breaking out of a chrooted jail much more difficult. If you
50601 + encounter no software incompatibilities with the following options, it
50602 + is recommended that you enable each one.
50603 +
50604 +config GRKERNSEC_CHROOT_MOUNT
50605 + bool "Deny mounts"
50606 + default y if GRKERNSEC_CONFIG_AUTO
50607 + depends on GRKERNSEC_CHROOT
50608 + help
50609 + If you say Y here, processes inside a chroot will not be able to
50610 + mount or remount filesystems. If the sysctl option is enabled, a
50611 + sysctl option with name "chroot_deny_mount" is created.
50612 +
50613 +config GRKERNSEC_CHROOT_DOUBLE
50614 + bool "Deny double-chroots"
50615 + default y if GRKERNSEC_CONFIG_AUTO
50616 + depends on GRKERNSEC_CHROOT
50617 + help
50618 + If you say Y here, processes inside a chroot will not be able to chroot
50619 + again outside the chroot. This is a widely used method of breaking
50620 + out of a chroot jail and should not be allowed. If the sysctl
50621 + option is enabled, a sysctl option with name
50622 + "chroot_deny_chroot" is created.
50623 +
50624 +config GRKERNSEC_CHROOT_PIVOT
50625 + bool "Deny pivot_root in chroot"
50626 + default y if GRKERNSEC_CONFIG_AUTO
50627 + depends on GRKERNSEC_CHROOT
50628 + help
50629 + If you say Y here, processes inside a chroot will not be able to use
50630 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50631 + works similar to chroot in that it changes the root filesystem. This
50632 + function could be misused in a chrooted process to attempt to break out
50633 + of the chroot, and therefore should not be allowed. If the sysctl
50634 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50635 + created.
50636 +
50637 +config GRKERNSEC_CHROOT_CHDIR
50638 + bool "Enforce chdir(\"/\") on all chroots"
50639 + default y if GRKERNSEC_CONFIG_AUTO
50640 + depends on GRKERNSEC_CHROOT
50641 + help
50642 + If you say Y here, the current working directory of all newly-chrooted
50643 + applications will be set to the the root directory of the chroot.
50644 + The man page on chroot(2) states:
50645 + Note that this call does not change the current working
50646 + directory, so that `.' can be outside the tree rooted at
50647 + `/'. In particular, the super-user can escape from a
50648 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50649 +
50650 + It is recommended that you say Y here, since it's not known to break
50651 + any software. If the sysctl option is enabled, a sysctl option with
50652 + name "chroot_enforce_chdir" is created.
50653 +
50654 +config GRKERNSEC_CHROOT_CHMOD
50655 + bool "Deny (f)chmod +s"
50656 + default y if GRKERNSEC_CONFIG_AUTO
50657 + depends on GRKERNSEC_CHROOT
50658 + help
50659 + If you say Y here, processes inside a chroot will not be able to chmod
50660 + or fchmod files to make them have suid or sgid bits. This protects
50661 + against another published method of breaking a chroot. If the sysctl
50662 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50663 + created.
50664 +
50665 +config GRKERNSEC_CHROOT_FCHDIR
50666 + bool "Deny fchdir out of chroot"
50667 + default y if GRKERNSEC_CONFIG_AUTO
50668 + depends on GRKERNSEC_CHROOT
50669 + help
50670 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50671 + to a file descriptor of the chrooting process that points to a directory
50672 + outside the filesystem will be stopped. If the sysctl option
50673 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50674 +
50675 +config GRKERNSEC_CHROOT_MKNOD
50676 + bool "Deny mknod"
50677 + default y if GRKERNSEC_CONFIG_AUTO
50678 + depends on GRKERNSEC_CHROOT
50679 + help
50680 + If you say Y here, processes inside a chroot will not be allowed to
50681 + mknod. The problem with using mknod inside a chroot is that it
50682 + would allow an attacker to create a device entry that is the same
50683 + as one on the physical root of your system, which could range from
50684 + anything from the console device to a device for your harddrive (which
50685 + they could then use to wipe the drive or steal data). It is recommended
50686 + that you say Y here, unless you run into software incompatibilities.
50687 + If the sysctl option is enabled, a sysctl option with name
50688 + "chroot_deny_mknod" is created.
50689 +
50690 +config GRKERNSEC_CHROOT_SHMAT
50691 + bool "Deny shmat() out of chroot"
50692 + default y if GRKERNSEC_CONFIG_AUTO
50693 + depends on GRKERNSEC_CHROOT
50694 + help
50695 + If you say Y here, processes inside a chroot will not be able to attach
50696 + to shared memory segments that were created outside of the chroot jail.
50697 + It is recommended that you say Y here. If the sysctl option is enabled,
50698 + a sysctl option with name "chroot_deny_shmat" is created.
50699 +
50700 +config GRKERNSEC_CHROOT_UNIX
50701 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50702 + default y if GRKERNSEC_CONFIG_AUTO
50703 + depends on GRKERNSEC_CHROOT
50704 + help
50705 + If you say Y here, processes inside a chroot will not be able to
50706 + connect to abstract (meaning not belonging to a filesystem) Unix
50707 + domain sockets that were bound outside of a chroot. It is recommended
50708 + that you say Y here. If the sysctl option is enabled, a sysctl option
50709 + with name "chroot_deny_unix" is created.
50710 +
50711 +config GRKERNSEC_CHROOT_FINDTASK
50712 + bool "Protect outside processes"
50713 + default y if GRKERNSEC_CONFIG_AUTO
50714 + depends on GRKERNSEC_CHROOT
50715 + help
50716 + If you say Y here, processes inside a chroot will not be able to
50717 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50718 + getsid, or view any process outside of the chroot. If the sysctl
50719 + option is enabled, a sysctl option with name "chroot_findtask" is
50720 + created.
50721 +
50722 +config GRKERNSEC_CHROOT_NICE
50723 + bool "Restrict priority changes"
50724 + default y if GRKERNSEC_CONFIG_AUTO
50725 + depends on GRKERNSEC_CHROOT
50726 + help
50727 + If you say Y here, processes inside a chroot will not be able to raise
50728 + the priority of processes in the chroot, or alter the priority of
50729 + processes outside the chroot. This provides more security than simply
50730 + removing CAP_SYS_NICE from the process' capability set. If the
50731 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50732 + is created.
50733 +
50734 +config GRKERNSEC_CHROOT_SYSCTL
50735 + bool "Deny sysctl writes"
50736 + default y if GRKERNSEC_CONFIG_AUTO
50737 + depends on GRKERNSEC_CHROOT
50738 + help
50739 + If you say Y here, an attacker in a chroot will not be able to
50740 + write to sysctl entries, either by sysctl(2) or through a /proc
50741 + interface. It is strongly recommended that you say Y here. If the
50742 + sysctl option is enabled, a sysctl option with name
50743 + "chroot_deny_sysctl" is created.
50744 +
50745 +config GRKERNSEC_CHROOT_CAPS
50746 + bool "Capability restrictions"
50747 + default y if GRKERNSEC_CONFIG_AUTO
50748 + depends on GRKERNSEC_CHROOT
50749 + help
50750 + If you say Y here, the capabilities on all processes within a
50751 + chroot jail will be lowered to stop module insertion, raw i/o,
50752 + system and net admin tasks, rebooting the system, modifying immutable
50753 + files, modifying IPC owned by another, and changing the system time.
50754 + This is left an option because it can break some apps. Disable this
50755 + if your chrooted apps are having problems performing those kinds of
50756 + tasks. If the sysctl option is enabled, a sysctl option with
50757 + name "chroot_caps" is created.
50758 +
50759 +endmenu
50760 +menu "Kernel Auditing"
50761 +depends on GRKERNSEC
50762 +
50763 +config GRKERNSEC_AUDIT_GROUP
50764 + bool "Single group for auditing"
50765 + help
50766 + If you say Y here, the exec, chdir, and (un)mount logging features
50767 + will only operate on a group you specify. This option is recommended
50768 + if you only want to watch certain users instead of having a large
50769 + amount of logs from the entire system. If the sysctl option is enabled,
50770 + a sysctl option with name "audit_group" is created.
50771 +
50772 +config GRKERNSEC_AUDIT_GID
50773 + int "GID for auditing"
50774 + depends on GRKERNSEC_AUDIT_GROUP
50775 + default 1007
50776 +
50777 +config GRKERNSEC_EXECLOG
50778 + bool "Exec logging"
50779 + help
50780 + If you say Y here, all execve() calls will be logged (since the
50781 + other exec*() calls are frontends to execve(), all execution
50782 + will be logged). Useful for shell-servers that like to keep track
50783 + of their users. If the sysctl option is enabled, a sysctl option with
50784 + name "exec_logging" is created.
50785 + WARNING: This option when enabled will produce a LOT of logs, especially
50786 + on an active system.
50787 +
50788 +config GRKERNSEC_RESLOG
50789 + bool "Resource logging"
50790 + default y if GRKERNSEC_CONFIG_AUTO
50791 + help
50792 + If you say Y here, all attempts to overstep resource limits will
50793 + be logged with the resource name, the requested size, and the current
50794 + limit. It is highly recommended that you say Y here. If the sysctl
50795 + option is enabled, a sysctl option with name "resource_logging" is
50796 + created. If the RBAC system is enabled, the sysctl value is ignored.
50797 +
50798 +config GRKERNSEC_CHROOT_EXECLOG
50799 + bool "Log execs within chroot"
50800 + help
50801 + If you say Y here, all executions inside a chroot jail will be logged
50802 + to syslog. This can cause a large amount of logs if certain
50803 + applications (eg. djb's daemontools) are installed on the system, and
50804 + is therefore left as an option. If the sysctl option is enabled, a
50805 + sysctl option with name "chroot_execlog" is created.
50806 +
50807 +config GRKERNSEC_AUDIT_PTRACE
50808 + bool "Ptrace logging"
50809 + help
50810 + If you say Y here, all attempts to attach to a process via ptrace
50811 + will be logged. If the sysctl option is enabled, a sysctl option
50812 + with name "audit_ptrace" is created.
50813 +
50814 +config GRKERNSEC_AUDIT_CHDIR
50815 + bool "Chdir logging"
50816 + help
50817 + If you say Y here, all chdir() calls will be logged. If the sysctl
50818 + option is enabled, a sysctl option with name "audit_chdir" is created.
50819 +
50820 +config GRKERNSEC_AUDIT_MOUNT
50821 + bool "(Un)Mount logging"
50822 + help
50823 + If you say Y here, all mounts and unmounts will be logged. If the
50824 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50825 + created.
50826 +
50827 +config GRKERNSEC_SIGNAL
50828 + bool "Signal logging"
50829 + default y if GRKERNSEC_CONFIG_AUTO
50830 + help
50831 + If you say Y here, certain important signals will be logged, such as
50832 + SIGSEGV, which will as a result inform you of when a error in a program
50833 + occurred, which in some cases could mean a possible exploit attempt.
50834 + If the sysctl option is enabled, a sysctl option with name
50835 + "signal_logging" is created.
50836 +
50837 +config GRKERNSEC_FORKFAIL
50838 + bool "Fork failure logging"
50839 + help
50840 + If you say Y here, all failed fork() attempts will be logged.
50841 + This could suggest a fork bomb, or someone attempting to overstep
50842 + their process limit. If the sysctl option is enabled, a sysctl option
50843 + with name "forkfail_logging" is created.
50844 +
50845 +config GRKERNSEC_TIME
50846 + bool "Time change logging"
50847 + default y if GRKERNSEC_CONFIG_AUTO
50848 + help
50849 + If you say Y here, any changes of the system clock will be logged.
50850 + If the sysctl option is enabled, a sysctl option with name
50851 + "timechange_logging" is created.
50852 +
50853 +config GRKERNSEC_PROC_IPADDR
50854 + bool "/proc/<pid>/ipaddr support"
50855 + default y if GRKERNSEC_CONFIG_AUTO
50856 + help
50857 + If you say Y here, a new entry will be added to each /proc/<pid>
50858 + directory that contains the IP address of the person using the task.
50859 + The IP is carried across local TCP and AF_UNIX stream sockets.
50860 + This information can be useful for IDS/IPSes to perform remote response
50861 + to a local attack. The entry is readable by only the owner of the
50862 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50863 + the RBAC system), and thus does not create privacy concerns.
50864 +
50865 +config GRKERNSEC_RWXMAP_LOG
50866 + bool 'Denied RWX mmap/mprotect logging'
50867 + default y if GRKERNSEC_CONFIG_AUTO
50868 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50869 + help
50870 + If you say Y here, calls to mmap() and mprotect() with explicit
50871 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50872 + denied by the PAX_MPROTECT feature. If the sysctl option is
50873 + enabled, a sysctl option with name "rwxmap_logging" is created.
50874 +
50875 +config GRKERNSEC_AUDIT_TEXTREL
50876 + bool 'ELF text relocations logging (READ HELP)'
50877 + depends on PAX_MPROTECT
50878 + help
50879 + If you say Y here, text relocations will be logged with the filename
50880 + of the offending library or binary. The purpose of the feature is
50881 + to help Linux distribution developers get rid of libraries and
50882 + binaries that need text relocations which hinder the future progress
50883 + of PaX. Only Linux distribution developers should say Y here, and
50884 + never on a production machine, as this option creates an information
50885 + leak that could aid an attacker in defeating the randomization of
50886 + a single memory region. If the sysctl option is enabled, a sysctl
50887 + option with name "audit_textrel" is created.
50888 +
50889 +endmenu
50890 +
50891 +menu "Executable Protections"
50892 +depends on GRKERNSEC
50893 +
50894 +config GRKERNSEC_DMESG
50895 + bool "Dmesg(8) restriction"
50896 + default y if GRKERNSEC_CONFIG_AUTO
50897 + help
50898 + If you say Y here, non-root users will not be able to use dmesg(8)
50899 + to view up to the last 4kb of messages in the kernel's log buffer.
50900 + The kernel's log buffer often contains kernel addresses and other
50901 + identifying information useful to an attacker in fingerprinting a
50902 + system for a targeted exploit.
50903 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50904 + created.
50905 +
50906 +config GRKERNSEC_HARDEN_PTRACE
50907 + bool "Deter ptrace-based process snooping"
50908 + default y if GRKERNSEC_CONFIG_AUTO
50909 + help
50910 + If you say Y here, TTY sniffers and other malicious monitoring
50911 + programs implemented through ptrace will be defeated. If you
50912 + have been using the RBAC system, this option has already been
50913 + enabled for several years for all users, with the ability to make
50914 + fine-grained exceptions.
50915 +
50916 + This option only affects the ability of non-root users to ptrace
50917 + processes that are not a descendent of the ptracing process.
50918 + This means that strace ./binary and gdb ./binary will still work,
50919 + but attaching to arbitrary processes will not. If the sysctl
50920 + option is enabled, a sysctl option with name "harden_ptrace" is
50921 + created.
50922 +
50923 +config GRKERNSEC_PTRACE_READEXEC
50924 + bool "Require read access to ptrace sensitive binaries"
50925 + default y if GRKERNSEC_CONFIG_AUTO
50926 + help
50927 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50928 + binaries. This option is useful in environments that
50929 + remove the read bits (e.g. file mode 4711) from suid binaries to
50930 + prevent infoleaking of their contents. This option adds
50931 + consistency to the use of that file mode, as the binary could normally
50932 + be read out when run without privileges while ptracing.
50933 +
50934 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50935 + is created.
50936 +
50937 +config GRKERNSEC_SETXID
50938 + bool "Enforce consistent multithreaded privileges"
50939 + default y if GRKERNSEC_CONFIG_AUTO
50940 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50941 + help
50942 + If you say Y here, a change from a root uid to a non-root uid
50943 + in a multithreaded application will cause the resulting uids,
50944 + gids, supplementary groups, and capabilities in that thread
50945 + to be propagated to the other threads of the process. In most
50946 + cases this is unnecessary, as glibc will emulate this behavior
50947 + on behalf of the application. Other libcs do not act in the
50948 + same way, allowing the other threads of the process to continue
50949 + running with root privileges. If the sysctl option is enabled,
50950 + a sysctl option with name "consistent_setxid" is created.
50951 +
50952 +config GRKERNSEC_TPE
50953 + bool "Trusted Path Execution (TPE)"
50954 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50955 + help
50956 + If you say Y here, you will be able to choose a gid to add to the
50957 + supplementary groups of users you want to mark as "untrusted."
50958 + These users will not be able to execute any files that are not in
50959 + root-owned directories writable only by root. If the sysctl option
50960 + is enabled, a sysctl option with name "tpe" is created.
50961 +
50962 +config GRKERNSEC_TPE_ALL
50963 + bool "Partially restrict all non-root users"
50964 + depends on GRKERNSEC_TPE
50965 + help
50966 + If you say Y here, all non-root users will be covered under
50967 + a weaker TPE restriction. This is separate from, and in addition to,
50968 + the main TPE options that you have selected elsewhere. Thus, if a
50969 + "trusted" GID is chosen, this restriction applies to even that GID.
50970 + Under this restriction, all non-root users will only be allowed to
50971 + execute files in directories they own that are not group or
50972 + world-writable, or in directories owned by root and writable only by
50973 + root. If the sysctl option is enabled, a sysctl option with name
50974 + "tpe_restrict_all" is created.
50975 +
50976 +config GRKERNSEC_TPE_INVERT
50977 + bool "Invert GID option"
50978 + depends on GRKERNSEC_TPE
50979 + help
50980 + If you say Y here, the group you specify in the TPE configuration will
50981 + decide what group TPE restrictions will be *disabled* for. This
50982 + option is useful if you want TPE restrictions to be applied to most
50983 + users on the system. If the sysctl option is enabled, a sysctl option
50984 + with name "tpe_invert" is created. Unlike other sysctl options, this
50985 + entry will default to on for backward-compatibility.
50986 +
50987 +config GRKERNSEC_TPE_GID
50988 + int "GID for untrusted users"
50989 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50990 + default 1005
50991 + help
50992 + Setting this GID determines what group TPE restrictions will be
50993 + *enabled* for. If the sysctl option is enabled, a sysctl option
50994 + with name "tpe_gid" is created.
50995 +
50996 +config GRKERNSEC_TPE_GID
50997 + int "GID for trusted users"
50998 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50999 + default 1005
51000 + help
51001 + Setting this GID determines what group TPE restrictions will be
51002 + *disabled* for. If the sysctl option is enabled, a sysctl option
51003 + with name "tpe_gid" is created.
51004 +
51005 +endmenu
51006 +menu "Network Protections"
51007 +depends on GRKERNSEC
51008 +
51009 +config GRKERNSEC_RANDNET
51010 + bool "Larger entropy pools"
51011 + default y if GRKERNSEC_CONFIG_AUTO
51012 + help
51013 + If you say Y here, the entropy pools used for many features of Linux
51014 + and grsecurity will be doubled in size. Since several grsecurity
51015 + features use additional randomness, it is recommended that you say Y
51016 + here. Saying Y here has a similar effect as modifying
51017 + /proc/sys/kernel/random/poolsize.
51018 +
51019 +config GRKERNSEC_BLACKHOLE
51020 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51021 + default y if GRKERNSEC_CONFIG_AUTO
51022 + depends on NET
51023 + help
51024 + If you say Y here, neither TCP resets nor ICMP
51025 + destination-unreachable packets will be sent in response to packets
51026 + sent to ports for which no associated listening process exists.
51027 + This feature supports both IPV4 and IPV6 and exempts the
51028 + loopback interface from blackholing. Enabling this feature
51029 + makes a host more resilient to DoS attacks and reduces network
51030 + visibility against scanners.
51031 +
51032 + The blackhole feature as-implemented is equivalent to the FreeBSD
51033 + blackhole feature, as it prevents RST responses to all packets, not
51034 + just SYNs. Under most application behavior this causes no
51035 + problems, but applications (like haproxy) may not close certain
51036 + connections in a way that cleanly terminates them on the remote
51037 + end, leaving the remote host in LAST_ACK state. Because of this
51038 + side-effect and to prevent intentional LAST_ACK DoSes, this
51039 + feature also adds automatic mitigation against such attacks.
51040 + The mitigation drastically reduces the amount of time a socket
51041 + can spend in LAST_ACK state. If you're using haproxy and not
51042 + all servers it connects to have this option enabled, consider
51043 + disabling this feature on the haproxy host.
51044 +
51045 + If the sysctl option is enabled, two sysctl options with names
51046 + "ip_blackhole" and "lastack_retries" will be created.
51047 + While "ip_blackhole" takes the standard zero/non-zero on/off
51048 + toggle, "lastack_retries" uses the same kinds of values as
51049 + "tcp_retries1" and "tcp_retries2". The default value of 4
51050 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51051 + state.
51052 +
51053 +config GRKERNSEC_SOCKET
51054 + bool "Socket restrictions"
51055 + depends on NET
51056 + help
51057 + If you say Y here, you will be able to choose from several options.
51058 + If you assign a GID on your system and add it to the supplementary
51059 + groups of users you want to restrict socket access to, this patch
51060 + will perform up to three things, based on the option(s) you choose.
51061 +
51062 +config GRKERNSEC_SOCKET_ALL
51063 + bool "Deny any sockets to group"
51064 + depends on GRKERNSEC_SOCKET
51065 + help
51066 + If you say Y here, you will be able to choose a GID of whose users will
51067 + be unable to connect to other hosts from your machine or run server
51068 + applications from your machine. If the sysctl option is enabled, a
51069 + sysctl option with name "socket_all" is created.
51070 +
51071 +config GRKERNSEC_SOCKET_ALL_GID
51072 + int "GID to deny all sockets for"
51073 + depends on GRKERNSEC_SOCKET_ALL
51074 + default 1004
51075 + help
51076 + Here you can choose the GID to disable socket access for. Remember to
51077 + add the users you want socket access disabled for to the GID
51078 + specified here. If the sysctl option is enabled, a sysctl option
51079 + with name "socket_all_gid" is created.
51080 +
51081 +config GRKERNSEC_SOCKET_CLIENT
51082 + bool "Deny client sockets to group"
51083 + depends on GRKERNSEC_SOCKET
51084 + help
51085 + If you say Y here, you will be able to choose a GID of whose users will
51086 + be unable to connect to other hosts from your machine, but will be
51087 + able to run servers. If this option is enabled, all users in the group
51088 + you specify will have to use passive mode when initiating ftp transfers
51089 + from the shell on your machine. If the sysctl option is enabled, a
51090 + sysctl option with name "socket_client" is created.
51091 +
51092 +config GRKERNSEC_SOCKET_CLIENT_GID
51093 + int "GID to deny client sockets for"
51094 + depends on GRKERNSEC_SOCKET_CLIENT
51095 + default 1003
51096 + help
51097 + Here you can choose the GID to disable client socket access for.
51098 + Remember to add the users you want client socket access disabled for to
51099 + the GID specified here. If the sysctl option is enabled, a sysctl
51100 + option with name "socket_client_gid" is created.
51101 +
51102 +config GRKERNSEC_SOCKET_SERVER
51103 + bool "Deny server sockets to group"
51104 + depends on GRKERNSEC_SOCKET
51105 + help
51106 + If you say Y here, you will be able to choose a GID of whose users will
51107 + be unable to run server applications from your machine. If the sysctl
51108 + option is enabled, a sysctl option with name "socket_server" is created.
51109 +
51110 +config GRKERNSEC_SOCKET_SERVER_GID
51111 + int "GID to deny server sockets for"
51112 + depends on GRKERNSEC_SOCKET_SERVER
51113 + default 1002
51114 + help
51115 + Here you can choose the GID to disable server socket access for.
51116 + Remember to add the users you want server socket access disabled for to
51117 + the GID specified here. If the sysctl option is enabled, a sysctl
51118 + option with name "socket_server_gid" is created.
51119 +
51120 +endmenu
51121 +menu "Sysctl Support"
51122 +depends on GRKERNSEC && SYSCTL
51123 +
51124 +config GRKERNSEC_SYSCTL
51125 + bool "Sysctl support"
51126 + default y if GRKERNSEC_CONFIG_AUTO
51127 + help
51128 + If you say Y here, you will be able to change the options that
51129 + grsecurity runs with at bootup, without having to recompile your
51130 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51131 + to enable (1) or disable (0) various features. All the sysctl entries
51132 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51133 + All features enabled in the kernel configuration are disabled at boot
51134 + if you do not say Y to the "Turn on features by default" option.
51135 + All options should be set at startup, and the grsec_lock entry should
51136 + be set to a non-zero value after all the options are set.
51137 + *THIS IS EXTREMELY IMPORTANT*
51138 +
51139 +config GRKERNSEC_SYSCTL_DISTRO
51140 + bool "Extra sysctl support for distro makers (READ HELP)"
51141 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51142 + help
51143 + If you say Y here, additional sysctl options will be created
51144 + for features that affect processes running as root. Therefore,
51145 + it is critical when using this option that the grsec_lock entry be
51146 + enabled after boot. Only distros with prebuilt kernel packages
51147 + with this option enabled that can ensure grsec_lock is enabled
51148 + after boot should use this option.
51149 + *Failure to set grsec_lock after boot makes all grsec features
51150 + this option covers useless*
51151 +
51152 + Currently this option creates the following sysctl entries:
51153 + "Disable Privileged I/O": "disable_priv_io"
51154 +
51155 +config GRKERNSEC_SYSCTL_ON
51156 + bool "Turn on features by default"
51157 + default y if GRKERNSEC_CONFIG_AUTO
51158 + depends on GRKERNSEC_SYSCTL
51159 + help
51160 + If you say Y here, instead of having all features enabled in the
51161 + kernel configuration disabled at boot time, the features will be
51162 + enabled at boot time. It is recommended you say Y here unless
51163 + there is some reason you would want all sysctl-tunable features to
51164 + be disabled by default. As mentioned elsewhere, it is important
51165 + to enable the grsec_lock entry once you have finished modifying
51166 + the sysctl entries.
51167 +
51168 +endmenu
51169 +menu "Logging Options"
51170 +depends on GRKERNSEC
51171 +
51172 +config GRKERNSEC_FLOODTIME
51173 + int "Seconds in between log messages (minimum)"
51174 + default 10
51175 + help
51176 + This option allows you to enforce the number of seconds between
51177 + grsecurity log messages. The default should be suitable for most
51178 + people, however, if you choose to change it, choose a value small enough
51179 + to allow informative logs to be produced, but large enough to
51180 + prevent flooding.
51181 +
51182 +config GRKERNSEC_FLOODBURST
51183 + int "Number of messages in a burst (maximum)"
51184 + default 6
51185 + help
51186 + This option allows you to choose the maximum number of messages allowed
51187 + within the flood time interval you chose in a separate option. The
51188 + default should be suitable for most people, however if you find that
51189 + many of your logs are being interpreted as flooding, you may want to
51190 + raise this value.
51191 +
51192 +endmenu
51193 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51194 new file mode 100644
51195 index 0000000..1b9afa9
51196 --- /dev/null
51197 +++ b/grsecurity/Makefile
51198 @@ -0,0 +1,38 @@
51199 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51200 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51201 +# into an RBAC system
51202 +#
51203 +# All code in this directory and various hooks inserted throughout the kernel
51204 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51205 +# under the GPL v2 or higher
51206 +
51207 +KBUILD_CFLAGS += -Werror
51208 +
51209 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51210 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51211 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51212 +
51213 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51214 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51215 + gracl_learn.o grsec_log.o
51216 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51217 +
51218 +ifdef CONFIG_NET
51219 +obj-y += grsec_sock.o
51220 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51221 +endif
51222 +
51223 +ifndef CONFIG_GRKERNSEC
51224 +obj-y += grsec_disabled.o
51225 +endif
51226 +
51227 +ifdef CONFIG_GRKERNSEC_HIDESYM
51228 +extra-y := grsec_hidesym.o
51229 +$(obj)/grsec_hidesym.o:
51230 + @-chmod -f 500 /boot
51231 + @-chmod -f 500 /lib/modules
51232 + @-chmod -f 500 /lib64/modules
51233 + @-chmod -f 500 /lib32/modules
51234 + @-chmod -f 700 .
51235 + @echo ' grsec: protected kernel image paths'
51236 +endif
51237 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51238 new file mode 100644
51239 index 0000000..1561617
51240 --- /dev/null
51241 +++ b/grsecurity/gracl.c
51242 @@ -0,0 +1,4017 @@
51243 +#include <linux/kernel.h>
51244 +#include <linux/module.h>
51245 +#include <linux/sched.h>
51246 +#include <linux/mm.h>
51247 +#include <linux/file.h>
51248 +#include <linux/fs.h>
51249 +#include <linux/namei.h>
51250 +#include <linux/mount.h>
51251 +#include <linux/tty.h>
51252 +#include <linux/proc_fs.h>
51253 +#include <linux/lglock.h>
51254 +#include <linux/slab.h>
51255 +#include <linux/vmalloc.h>
51256 +#include <linux/types.h>
51257 +#include <linux/sysctl.h>
51258 +#include <linux/netdevice.h>
51259 +#include <linux/ptrace.h>
51260 +#include <linux/gracl.h>
51261 +#include <linux/gralloc.h>
51262 +#include <linux/security.h>
51263 +#include <linux/grinternal.h>
51264 +#include <linux/pid_namespace.h>
51265 +#include <linux/stop_machine.h>
51266 +#include <linux/fdtable.h>
51267 +#include <linux/percpu.h>
51268 +#include <linux/lglock.h>
51269 +#include "../fs/mount.h"
51270 +
51271 +#include <asm/uaccess.h>
51272 +#include <asm/errno.h>
51273 +#include <asm/mman.h>
51274 +
51275 +extern struct lglock vfsmount_lock;
51276 +
51277 +static struct acl_role_db acl_role_set;
51278 +static struct name_db name_set;
51279 +static struct inodev_db inodev_set;
51280 +
51281 +/* for keeping track of userspace pointers used for subjects, so we
51282 + can share references in the kernel as well
51283 +*/
51284 +
51285 +static struct path real_root;
51286 +
51287 +static struct acl_subj_map_db subj_map_set;
51288 +
51289 +static struct acl_role_label *default_role;
51290 +
51291 +static struct acl_role_label *role_list;
51292 +
51293 +static u16 acl_sp_role_value;
51294 +
51295 +extern char *gr_shared_page[4];
51296 +static DEFINE_MUTEX(gr_dev_mutex);
51297 +DEFINE_RWLOCK(gr_inode_lock);
51298 +
51299 +struct gr_arg *gr_usermode;
51300 +
51301 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51302 +
51303 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51304 +extern void gr_clear_learn_entries(void);
51305 +
51306 +#ifdef CONFIG_GRKERNSEC_RESLOG
51307 +extern void gr_log_resource(const struct task_struct *task,
51308 + const int res, const unsigned long wanted, const int gt);
51309 +#endif
51310 +
51311 +unsigned char *gr_system_salt;
51312 +unsigned char *gr_system_sum;
51313 +
51314 +static struct sprole_pw **acl_special_roles = NULL;
51315 +static __u16 num_sprole_pws = 0;
51316 +
51317 +static struct acl_role_label *kernel_role = NULL;
51318 +
51319 +static unsigned int gr_auth_attempts = 0;
51320 +static unsigned long gr_auth_expires = 0UL;
51321 +
51322 +#ifdef CONFIG_NET
51323 +extern struct vfsmount *sock_mnt;
51324 +#endif
51325 +
51326 +extern struct vfsmount *pipe_mnt;
51327 +extern struct vfsmount *shm_mnt;
51328 +#ifdef CONFIG_HUGETLBFS
51329 +extern struct vfsmount *hugetlbfs_vfsmount;
51330 +#endif
51331 +
51332 +static struct acl_object_label *fakefs_obj_rw;
51333 +static struct acl_object_label *fakefs_obj_rwx;
51334 +
51335 +extern int gr_init_uidset(void);
51336 +extern void gr_free_uidset(void);
51337 +extern void gr_remove_uid(uid_t uid);
51338 +extern int gr_find_uid(uid_t uid);
51339 +
51340 +__inline__ int
51341 +gr_acl_is_enabled(void)
51342 +{
51343 + return (gr_status & GR_READY);
51344 +}
51345 +
51346 +#ifdef CONFIG_BTRFS_FS
51347 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51348 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51349 +#endif
51350 +
51351 +static inline dev_t __get_dev(const struct dentry *dentry)
51352 +{
51353 +#ifdef CONFIG_BTRFS_FS
51354 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51355 + return get_btrfs_dev_from_inode(dentry->d_inode);
51356 + else
51357 +#endif
51358 + return dentry->d_inode->i_sb->s_dev;
51359 +}
51360 +
51361 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51362 +{
51363 + return __get_dev(dentry);
51364 +}
51365 +
51366 +static char gr_task_roletype_to_char(struct task_struct *task)
51367 +{
51368 + switch (task->role->roletype &
51369 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51370 + GR_ROLE_SPECIAL)) {
51371 + case GR_ROLE_DEFAULT:
51372 + return 'D';
51373 + case GR_ROLE_USER:
51374 + return 'U';
51375 + case GR_ROLE_GROUP:
51376 + return 'G';
51377 + case GR_ROLE_SPECIAL:
51378 + return 'S';
51379 + }
51380 +
51381 + return 'X';
51382 +}
51383 +
51384 +char gr_roletype_to_char(void)
51385 +{
51386 + return gr_task_roletype_to_char(current);
51387 +}
51388 +
51389 +__inline__ int
51390 +gr_acl_tpe_check(void)
51391 +{
51392 + if (unlikely(!(gr_status & GR_READY)))
51393 + return 0;
51394 + if (current->role->roletype & GR_ROLE_TPE)
51395 + return 1;
51396 + else
51397 + return 0;
51398 +}
51399 +
51400 +int
51401 +gr_handle_rawio(const struct inode *inode)
51402 +{
51403 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51404 + if (inode && S_ISBLK(inode->i_mode) &&
51405 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51406 + !capable(CAP_SYS_RAWIO))
51407 + return 1;
51408 +#endif
51409 + return 0;
51410 +}
51411 +
51412 +static int
51413 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51414 +{
51415 + if (likely(lena != lenb))
51416 + return 0;
51417 +
51418 + return !memcmp(a, b, lena);
51419 +}
51420 +
51421 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51422 +{
51423 + *buflen -= namelen;
51424 + if (*buflen < 0)
51425 + return -ENAMETOOLONG;
51426 + *buffer -= namelen;
51427 + memcpy(*buffer, str, namelen);
51428 + return 0;
51429 +}
51430 +
51431 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51432 +{
51433 + return prepend(buffer, buflen, name->name, name->len);
51434 +}
51435 +
51436 +static int prepend_path(const struct path *path, struct path *root,
51437 + char **buffer, int *buflen)
51438 +{
51439 + struct dentry *dentry = path->dentry;
51440 + struct vfsmount *vfsmnt = path->mnt;
51441 + struct mount *mnt = real_mount(vfsmnt);
51442 + bool slash = false;
51443 + int error = 0;
51444 +
51445 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51446 + struct dentry * parent;
51447 +
51448 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51449 + /* Global root? */
51450 + if (!mnt_has_parent(mnt)) {
51451 + goto out;
51452 + }
51453 + dentry = mnt->mnt_mountpoint;
51454 + mnt = mnt->mnt_parent;
51455 + vfsmnt = &mnt->mnt;
51456 + continue;
51457 + }
51458 + parent = dentry->d_parent;
51459 + prefetch(parent);
51460 + spin_lock(&dentry->d_lock);
51461 + error = prepend_name(buffer, buflen, &dentry->d_name);
51462 + spin_unlock(&dentry->d_lock);
51463 + if (!error)
51464 + error = prepend(buffer, buflen, "/", 1);
51465 + if (error)
51466 + break;
51467 +
51468 + slash = true;
51469 + dentry = parent;
51470 + }
51471 +
51472 +out:
51473 + if (!error && !slash)
51474 + error = prepend(buffer, buflen, "/", 1);
51475 +
51476 + return error;
51477 +}
51478 +
51479 +/* this must be called with vfsmount_lock and rename_lock held */
51480 +
51481 +static char *__our_d_path(const struct path *path, struct path *root,
51482 + char *buf, int buflen)
51483 +{
51484 + char *res = buf + buflen;
51485 + int error;
51486 +
51487 + prepend(&res, &buflen, "\0", 1);
51488 + error = prepend_path(path, root, &res, &buflen);
51489 + if (error)
51490 + return ERR_PTR(error);
51491 +
51492 + return res;
51493 +}
51494 +
51495 +static char *
51496 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51497 +{
51498 + char *retval;
51499 +
51500 + retval = __our_d_path(path, root, buf, buflen);
51501 + if (unlikely(IS_ERR(retval)))
51502 + retval = strcpy(buf, "<path too long>");
51503 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51504 + retval[1] = '\0';
51505 +
51506 + return retval;
51507 +}
51508 +
51509 +static char *
51510 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51511 + char *buf, int buflen)
51512 +{
51513 + struct path path;
51514 + char *res;
51515 +
51516 + path.dentry = (struct dentry *)dentry;
51517 + path.mnt = (struct vfsmount *)vfsmnt;
51518 +
51519 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51520 + by the RBAC system */
51521 + res = gen_full_path(&path, &real_root, buf, buflen);
51522 +
51523 + return res;
51524 +}
51525 +
51526 +static char *
51527 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51528 + char *buf, int buflen)
51529 +{
51530 + char *res;
51531 + struct path path;
51532 + struct path root;
51533 + struct task_struct *reaper = init_pid_ns.child_reaper;
51534 +
51535 + path.dentry = (struct dentry *)dentry;
51536 + path.mnt = (struct vfsmount *)vfsmnt;
51537 +
51538 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51539 + get_fs_root(reaper->fs, &root);
51540 +
51541 + write_seqlock(&rename_lock);
51542 + br_read_lock(&vfsmount_lock);
51543 + res = gen_full_path(&path, &root, buf, buflen);
51544 + br_read_unlock(&vfsmount_lock);
51545 + write_sequnlock(&rename_lock);
51546 +
51547 + path_put(&root);
51548 + return res;
51549 +}
51550 +
51551 +static char *
51552 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51553 +{
51554 + char *ret;
51555 + write_seqlock(&rename_lock);
51556 + br_read_lock(&vfsmount_lock);
51557 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51558 + PAGE_SIZE);
51559 + br_read_unlock(&vfsmount_lock);
51560 + write_sequnlock(&rename_lock);
51561 + return ret;
51562 +}
51563 +
51564 +static char *
51565 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51566 +{
51567 + char *ret;
51568 + char *buf;
51569 + int buflen;
51570 +
51571 + write_seqlock(&rename_lock);
51572 + br_read_lock(&vfsmount_lock);
51573 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51574 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51575 + buflen = (int)(ret - buf);
51576 + if (buflen >= 5)
51577 + prepend(&ret, &buflen, "/proc", 5);
51578 + else
51579 + ret = strcpy(buf, "<path too long>");
51580 + br_read_unlock(&vfsmount_lock);
51581 + write_sequnlock(&rename_lock);
51582 + return ret;
51583 +}
51584 +
51585 +char *
51586 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51587 +{
51588 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51589 + PAGE_SIZE);
51590 +}
51591 +
51592 +char *
51593 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51594 +{
51595 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51596 + PAGE_SIZE);
51597 +}
51598 +
51599 +char *
51600 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51601 +{
51602 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51603 + PAGE_SIZE);
51604 +}
51605 +
51606 +char *
51607 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51608 +{
51609 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51610 + PAGE_SIZE);
51611 +}
51612 +
51613 +char *
51614 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51615 +{
51616 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51617 + PAGE_SIZE);
51618 +}
51619 +
51620 +__inline__ __u32
51621 +to_gr_audit(const __u32 reqmode)
51622 +{
51623 + /* masks off auditable permission flags, then shifts them to create
51624 + auditing flags, and adds the special case of append auditing if
51625 + we're requesting write */
51626 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51627 +}
51628 +
51629 +struct acl_subject_label *
51630 +lookup_subject_map(const struct acl_subject_label *userp)
51631 +{
51632 + unsigned int index = shash(userp, subj_map_set.s_size);
51633 + struct subject_map *match;
51634 +
51635 + match = subj_map_set.s_hash[index];
51636 +
51637 + while (match && match->user != userp)
51638 + match = match->next;
51639 +
51640 + if (match != NULL)
51641 + return match->kernel;
51642 + else
51643 + return NULL;
51644 +}
51645 +
51646 +static void
51647 +insert_subj_map_entry(struct subject_map *subjmap)
51648 +{
51649 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51650 + struct subject_map **curr;
51651 +
51652 + subjmap->prev = NULL;
51653 +
51654 + curr = &subj_map_set.s_hash[index];
51655 + if (*curr != NULL)
51656 + (*curr)->prev = subjmap;
51657 +
51658 + subjmap->next = *curr;
51659 + *curr = subjmap;
51660 +
51661 + return;
51662 +}
51663 +
51664 +static struct acl_role_label *
51665 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51666 + const gid_t gid)
51667 +{
51668 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51669 + struct acl_role_label *match;
51670 + struct role_allowed_ip *ipp;
51671 + unsigned int x;
51672 + u32 curr_ip = task->signal->curr_ip;
51673 +
51674 + task->signal->saved_ip = curr_ip;
51675 +
51676 + match = acl_role_set.r_hash[index];
51677 +
51678 + while (match) {
51679 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51680 + for (x = 0; x < match->domain_child_num; x++) {
51681 + if (match->domain_children[x] == uid)
51682 + goto found;
51683 + }
51684 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51685 + break;
51686 + match = match->next;
51687 + }
51688 +found:
51689 + if (match == NULL) {
51690 + try_group:
51691 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51692 + match = acl_role_set.r_hash[index];
51693 +
51694 + while (match) {
51695 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51696 + for (x = 0; x < match->domain_child_num; x++) {
51697 + if (match->domain_children[x] == gid)
51698 + goto found2;
51699 + }
51700 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51701 + break;
51702 + match = match->next;
51703 + }
51704 +found2:
51705 + if (match == NULL)
51706 + match = default_role;
51707 + if (match->allowed_ips == NULL)
51708 + return match;
51709 + else {
51710 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51711 + if (likely
51712 + ((ntohl(curr_ip) & ipp->netmask) ==
51713 + (ntohl(ipp->addr) & ipp->netmask)))
51714 + return match;
51715 + }
51716 + match = default_role;
51717 + }
51718 + } else if (match->allowed_ips == NULL) {
51719 + return match;
51720 + } else {
51721 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51722 + if (likely
51723 + ((ntohl(curr_ip) & ipp->netmask) ==
51724 + (ntohl(ipp->addr) & ipp->netmask)))
51725 + return match;
51726 + }
51727 + goto try_group;
51728 + }
51729 +
51730 + return match;
51731 +}
51732 +
51733 +struct acl_subject_label *
51734 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51735 + const struct acl_role_label *role)
51736 +{
51737 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51738 + struct acl_subject_label *match;
51739 +
51740 + match = role->subj_hash[index];
51741 +
51742 + while (match && (match->inode != ino || match->device != dev ||
51743 + (match->mode & GR_DELETED))) {
51744 + match = match->next;
51745 + }
51746 +
51747 + if (match && !(match->mode & GR_DELETED))
51748 + return match;
51749 + else
51750 + return NULL;
51751 +}
51752 +
51753 +struct acl_subject_label *
51754 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51755 + const struct acl_role_label *role)
51756 +{
51757 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51758 + struct acl_subject_label *match;
51759 +
51760 + match = role->subj_hash[index];
51761 +
51762 + while (match && (match->inode != ino || match->device != dev ||
51763 + !(match->mode & GR_DELETED))) {
51764 + match = match->next;
51765 + }
51766 +
51767 + if (match && (match->mode & GR_DELETED))
51768 + return match;
51769 + else
51770 + return NULL;
51771 +}
51772 +
51773 +static struct acl_object_label *
51774 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51775 + const struct acl_subject_label *subj)
51776 +{
51777 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51778 + struct acl_object_label *match;
51779 +
51780 + match = subj->obj_hash[index];
51781 +
51782 + while (match && (match->inode != ino || match->device != dev ||
51783 + (match->mode & GR_DELETED))) {
51784 + match = match->next;
51785 + }
51786 +
51787 + if (match && !(match->mode & GR_DELETED))
51788 + return match;
51789 + else
51790 + return NULL;
51791 +}
51792 +
51793 +static struct acl_object_label *
51794 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51795 + const struct acl_subject_label *subj)
51796 +{
51797 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51798 + struct acl_object_label *match;
51799 +
51800 + match = subj->obj_hash[index];
51801 +
51802 + while (match && (match->inode != ino || match->device != dev ||
51803 + !(match->mode & GR_DELETED))) {
51804 + match = match->next;
51805 + }
51806 +
51807 + if (match && (match->mode & GR_DELETED))
51808 + return match;
51809 +
51810 + match = subj->obj_hash[index];
51811 +
51812 + while (match && (match->inode != ino || match->device != dev ||
51813 + (match->mode & GR_DELETED))) {
51814 + match = match->next;
51815 + }
51816 +
51817 + if (match && !(match->mode & GR_DELETED))
51818 + return match;
51819 + else
51820 + return NULL;
51821 +}
51822 +
51823 +static struct name_entry *
51824 +lookup_name_entry(const char *name)
51825 +{
51826 + unsigned int len = strlen(name);
51827 + unsigned int key = full_name_hash(name, len);
51828 + unsigned int index = key % name_set.n_size;
51829 + struct name_entry *match;
51830 +
51831 + match = name_set.n_hash[index];
51832 +
51833 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51834 + match = match->next;
51835 +
51836 + return match;
51837 +}
51838 +
51839 +static struct name_entry *
51840 +lookup_name_entry_create(const char *name)
51841 +{
51842 + unsigned int len = strlen(name);
51843 + unsigned int key = full_name_hash(name, len);
51844 + unsigned int index = key % name_set.n_size;
51845 + struct name_entry *match;
51846 +
51847 + match = name_set.n_hash[index];
51848 +
51849 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51850 + !match->deleted))
51851 + match = match->next;
51852 +
51853 + if (match && match->deleted)
51854 + return match;
51855 +
51856 + match = name_set.n_hash[index];
51857 +
51858 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51859 + match->deleted))
51860 + match = match->next;
51861 +
51862 + if (match && !match->deleted)
51863 + return match;
51864 + else
51865 + return NULL;
51866 +}
51867 +
51868 +static struct inodev_entry *
51869 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51870 +{
51871 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51872 + struct inodev_entry *match;
51873 +
51874 + match = inodev_set.i_hash[index];
51875 +
51876 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51877 + match = match->next;
51878 +
51879 + return match;
51880 +}
51881 +
51882 +static void
51883 +insert_inodev_entry(struct inodev_entry *entry)
51884 +{
51885 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51886 + inodev_set.i_size);
51887 + struct inodev_entry **curr;
51888 +
51889 + entry->prev = NULL;
51890 +
51891 + curr = &inodev_set.i_hash[index];
51892 + if (*curr != NULL)
51893 + (*curr)->prev = entry;
51894 +
51895 + entry->next = *curr;
51896 + *curr = entry;
51897 +
51898 + return;
51899 +}
51900 +
51901 +static void
51902 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51903 +{
51904 + unsigned int index =
51905 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51906 + struct acl_role_label **curr;
51907 + struct acl_role_label *tmp, *tmp2;
51908 +
51909 + curr = &acl_role_set.r_hash[index];
51910 +
51911 + /* simple case, slot is empty, just set it to our role */
51912 + if (*curr == NULL) {
51913 + *curr = role;
51914 + } else {
51915 + /* example:
51916 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51917 + 2 -> 3
51918 + */
51919 + /* first check to see if we can already be reached via this slot */
51920 + tmp = *curr;
51921 + while (tmp && tmp != role)
51922 + tmp = tmp->next;
51923 + if (tmp == role) {
51924 + /* we don't need to add ourselves to this slot's chain */
51925 + return;
51926 + }
51927 + /* we need to add ourselves to this chain, two cases */
51928 + if (role->next == NULL) {
51929 + /* simple case, append the current chain to our role */
51930 + role->next = *curr;
51931 + *curr = role;
51932 + } else {
51933 + /* 1 -> 2 -> 3 -> 4
51934 + 2 -> 3 -> 4
51935 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51936 + */
51937 + /* trickier case: walk our role's chain until we find
51938 + the role for the start of the current slot's chain */
51939 + tmp = role;
51940 + tmp2 = *curr;
51941 + while (tmp->next && tmp->next != tmp2)
51942 + tmp = tmp->next;
51943 + if (tmp->next == tmp2) {
51944 + /* from example above, we found 3, so just
51945 + replace this slot's chain with ours */
51946 + *curr = role;
51947 + } else {
51948 + /* we didn't find a subset of our role's chain
51949 + in the current slot's chain, so append their
51950 + chain to ours, and set us as the first role in
51951 + the slot's chain
51952 +
51953 + we could fold this case with the case above,
51954 + but making it explicit for clarity
51955 + */
51956 + tmp->next = tmp2;
51957 + *curr = role;
51958 + }
51959 + }
51960 + }
51961 +
51962 + return;
51963 +}
51964 +
51965 +static void
51966 +insert_acl_role_label(struct acl_role_label *role)
51967 +{
51968 + int i;
51969 +
51970 + if (role_list == NULL) {
51971 + role_list = role;
51972 + role->prev = NULL;
51973 + } else {
51974 + role->prev = role_list;
51975 + role_list = role;
51976 + }
51977 +
51978 + /* used for hash chains */
51979 + role->next = NULL;
51980 +
51981 + if (role->roletype & GR_ROLE_DOMAIN) {
51982 + for (i = 0; i < role->domain_child_num; i++)
51983 + __insert_acl_role_label(role, role->domain_children[i]);
51984 + } else
51985 + __insert_acl_role_label(role, role->uidgid);
51986 +}
51987 +
51988 +static int
51989 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51990 +{
51991 + struct name_entry **curr, *nentry;
51992 + struct inodev_entry *ientry;
51993 + unsigned int len = strlen(name);
51994 + unsigned int key = full_name_hash(name, len);
51995 + unsigned int index = key % name_set.n_size;
51996 +
51997 + curr = &name_set.n_hash[index];
51998 +
51999 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52000 + curr = &((*curr)->next);
52001 +
52002 + if (*curr != NULL)
52003 + return 1;
52004 +
52005 + nentry = acl_alloc(sizeof (struct name_entry));
52006 + if (nentry == NULL)
52007 + return 0;
52008 + ientry = acl_alloc(sizeof (struct inodev_entry));
52009 + if (ientry == NULL)
52010 + return 0;
52011 + ientry->nentry = nentry;
52012 +
52013 + nentry->key = key;
52014 + nentry->name = name;
52015 + nentry->inode = inode;
52016 + nentry->device = device;
52017 + nentry->len = len;
52018 + nentry->deleted = deleted;
52019 +
52020 + nentry->prev = NULL;
52021 + curr = &name_set.n_hash[index];
52022 + if (*curr != NULL)
52023 + (*curr)->prev = nentry;
52024 + nentry->next = *curr;
52025 + *curr = nentry;
52026 +
52027 + /* insert us into the table searchable by inode/dev */
52028 + insert_inodev_entry(ientry);
52029 +
52030 + return 1;
52031 +}
52032 +
52033 +static void
52034 +insert_acl_obj_label(struct acl_object_label *obj,
52035 + struct acl_subject_label *subj)
52036 +{
52037 + unsigned int index =
52038 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52039 + struct acl_object_label **curr;
52040 +
52041 +
52042 + obj->prev = NULL;
52043 +
52044 + curr = &subj->obj_hash[index];
52045 + if (*curr != NULL)
52046 + (*curr)->prev = obj;
52047 +
52048 + obj->next = *curr;
52049 + *curr = obj;
52050 +
52051 + return;
52052 +}
52053 +
52054 +static void
52055 +insert_acl_subj_label(struct acl_subject_label *obj,
52056 + struct acl_role_label *role)
52057 +{
52058 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52059 + struct acl_subject_label **curr;
52060 +
52061 + obj->prev = NULL;
52062 +
52063 + curr = &role->subj_hash[index];
52064 + if (*curr != NULL)
52065 + (*curr)->prev = obj;
52066 +
52067 + obj->next = *curr;
52068 + *curr = obj;
52069 +
52070 + return;
52071 +}
52072 +
52073 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52074 +
52075 +static void *
52076 +create_table(__u32 * len, int elementsize)
52077 +{
52078 + unsigned int table_sizes[] = {
52079 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52080 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52081 + 4194301, 8388593, 16777213, 33554393, 67108859
52082 + };
52083 + void *newtable = NULL;
52084 + unsigned int pwr = 0;
52085 +
52086 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52087 + table_sizes[pwr] <= *len)
52088 + pwr++;
52089 +
52090 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52091 + return newtable;
52092 +
52093 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52094 + newtable =
52095 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52096 + else
52097 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52098 +
52099 + *len = table_sizes[pwr];
52100 +
52101 + return newtable;
52102 +}
52103 +
52104 +static int
52105 +init_variables(const struct gr_arg *arg)
52106 +{
52107 + struct task_struct *reaper = init_pid_ns.child_reaper;
52108 + unsigned int stacksize;
52109 +
52110 + subj_map_set.s_size = arg->role_db.num_subjects;
52111 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52112 + name_set.n_size = arg->role_db.num_objects;
52113 + inodev_set.i_size = arg->role_db.num_objects;
52114 +
52115 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52116 + !name_set.n_size || !inodev_set.i_size)
52117 + return 1;
52118 +
52119 + if (!gr_init_uidset())
52120 + return 1;
52121 +
52122 + /* set up the stack that holds allocation info */
52123 +
52124 + stacksize = arg->role_db.num_pointers + 5;
52125 +
52126 + if (!acl_alloc_stack_init(stacksize))
52127 + return 1;
52128 +
52129 + /* grab reference for the real root dentry and vfsmount */
52130 + get_fs_root(reaper->fs, &real_root);
52131 +
52132 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52133 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52134 +#endif
52135 +
52136 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52137 + if (fakefs_obj_rw == NULL)
52138 + return 1;
52139 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52140 +
52141 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52142 + if (fakefs_obj_rwx == NULL)
52143 + return 1;
52144 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52145 +
52146 + subj_map_set.s_hash =
52147 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52148 + acl_role_set.r_hash =
52149 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52150 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52151 + inodev_set.i_hash =
52152 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52153 +
52154 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52155 + !name_set.n_hash || !inodev_set.i_hash)
52156 + return 1;
52157 +
52158 + memset(subj_map_set.s_hash, 0,
52159 + sizeof(struct subject_map *) * subj_map_set.s_size);
52160 + memset(acl_role_set.r_hash, 0,
52161 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52162 + memset(name_set.n_hash, 0,
52163 + sizeof (struct name_entry *) * name_set.n_size);
52164 + memset(inodev_set.i_hash, 0,
52165 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52166 +
52167 + return 0;
52168 +}
52169 +
52170 +/* free information not needed after startup
52171 + currently contains user->kernel pointer mappings for subjects
52172 +*/
52173 +
52174 +static void
52175 +free_init_variables(void)
52176 +{
52177 + __u32 i;
52178 +
52179 + if (subj_map_set.s_hash) {
52180 + for (i = 0; i < subj_map_set.s_size; i++) {
52181 + if (subj_map_set.s_hash[i]) {
52182 + kfree(subj_map_set.s_hash[i]);
52183 + subj_map_set.s_hash[i] = NULL;
52184 + }
52185 + }
52186 +
52187 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52188 + PAGE_SIZE)
52189 + kfree(subj_map_set.s_hash);
52190 + else
52191 + vfree(subj_map_set.s_hash);
52192 + }
52193 +
52194 + return;
52195 +}
52196 +
52197 +static void
52198 +free_variables(void)
52199 +{
52200 + struct acl_subject_label *s;
52201 + struct acl_role_label *r;
52202 + struct task_struct *task, *task2;
52203 + unsigned int x;
52204 +
52205 + gr_clear_learn_entries();
52206 +
52207 + read_lock(&tasklist_lock);
52208 + do_each_thread(task2, task) {
52209 + task->acl_sp_role = 0;
52210 + task->acl_role_id = 0;
52211 + task->acl = NULL;
52212 + task->role = NULL;
52213 + } while_each_thread(task2, task);
52214 + read_unlock(&tasklist_lock);
52215 +
52216 + /* release the reference to the real root dentry and vfsmount */
52217 + path_put(&real_root);
52218 + memset(&real_root, 0, sizeof(real_root));
52219 +
52220 + /* free all object hash tables */
52221 +
52222 + FOR_EACH_ROLE_START(r)
52223 + if (r->subj_hash == NULL)
52224 + goto next_role;
52225 + FOR_EACH_SUBJECT_START(r, s, x)
52226 + if (s->obj_hash == NULL)
52227 + break;
52228 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52229 + kfree(s->obj_hash);
52230 + else
52231 + vfree(s->obj_hash);
52232 + FOR_EACH_SUBJECT_END(s, x)
52233 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52234 + if (s->obj_hash == NULL)
52235 + break;
52236 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52237 + kfree(s->obj_hash);
52238 + else
52239 + vfree(s->obj_hash);
52240 + FOR_EACH_NESTED_SUBJECT_END(s)
52241 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52242 + kfree(r->subj_hash);
52243 + else
52244 + vfree(r->subj_hash);
52245 + r->subj_hash = NULL;
52246 +next_role:
52247 + FOR_EACH_ROLE_END(r)
52248 +
52249 + acl_free_all();
52250 +
52251 + if (acl_role_set.r_hash) {
52252 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52253 + PAGE_SIZE)
52254 + kfree(acl_role_set.r_hash);
52255 + else
52256 + vfree(acl_role_set.r_hash);
52257 + }
52258 + if (name_set.n_hash) {
52259 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52260 + PAGE_SIZE)
52261 + kfree(name_set.n_hash);
52262 + else
52263 + vfree(name_set.n_hash);
52264 + }
52265 +
52266 + if (inodev_set.i_hash) {
52267 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52268 + PAGE_SIZE)
52269 + kfree(inodev_set.i_hash);
52270 + else
52271 + vfree(inodev_set.i_hash);
52272 + }
52273 +
52274 + gr_free_uidset();
52275 +
52276 + memset(&name_set, 0, sizeof (struct name_db));
52277 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52278 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52279 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52280 +
52281 + default_role = NULL;
52282 + kernel_role = NULL;
52283 + role_list = NULL;
52284 +
52285 + return;
52286 +}
52287 +
52288 +static __u32
52289 +count_user_objs(struct acl_object_label *userp)
52290 +{
52291 + struct acl_object_label o_tmp;
52292 + __u32 num = 0;
52293 +
52294 + while (userp) {
52295 + if (copy_from_user(&o_tmp, userp,
52296 + sizeof (struct acl_object_label)))
52297 + break;
52298 +
52299 + userp = o_tmp.prev;
52300 + num++;
52301 + }
52302 +
52303 + return num;
52304 +}
52305 +
52306 +static struct acl_subject_label *
52307 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52308 +
52309 +static int
52310 +copy_user_glob(struct acl_object_label *obj)
52311 +{
52312 + struct acl_object_label *g_tmp, **guser;
52313 + unsigned int len;
52314 + char *tmp;
52315 +
52316 + if (obj->globbed == NULL)
52317 + return 0;
52318 +
52319 + guser = &obj->globbed;
52320 + while (*guser) {
52321 + g_tmp = (struct acl_object_label *)
52322 + acl_alloc(sizeof (struct acl_object_label));
52323 + if (g_tmp == NULL)
52324 + return -ENOMEM;
52325 +
52326 + if (copy_from_user(g_tmp, *guser,
52327 + sizeof (struct acl_object_label)))
52328 + return -EFAULT;
52329 +
52330 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52331 +
52332 + if (!len || len >= PATH_MAX)
52333 + return -EINVAL;
52334 +
52335 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52336 + return -ENOMEM;
52337 +
52338 + if (copy_from_user(tmp, g_tmp->filename, len))
52339 + return -EFAULT;
52340 + tmp[len-1] = '\0';
52341 + g_tmp->filename = tmp;
52342 +
52343 + *guser = g_tmp;
52344 + guser = &(g_tmp->next);
52345 + }
52346 +
52347 + return 0;
52348 +}
52349 +
52350 +static int
52351 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52352 + struct acl_role_label *role)
52353 +{
52354 + struct acl_object_label *o_tmp;
52355 + unsigned int len;
52356 + int ret;
52357 + char *tmp;
52358 +
52359 + while (userp) {
52360 + if ((o_tmp = (struct acl_object_label *)
52361 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52362 + return -ENOMEM;
52363 +
52364 + if (copy_from_user(o_tmp, userp,
52365 + sizeof (struct acl_object_label)))
52366 + return -EFAULT;
52367 +
52368 + userp = o_tmp->prev;
52369 +
52370 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52371 +
52372 + if (!len || len >= PATH_MAX)
52373 + return -EINVAL;
52374 +
52375 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52376 + return -ENOMEM;
52377 +
52378 + if (copy_from_user(tmp, o_tmp->filename, len))
52379 + return -EFAULT;
52380 + tmp[len-1] = '\0';
52381 + o_tmp->filename = tmp;
52382 +
52383 + insert_acl_obj_label(o_tmp, subj);
52384 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52385 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52386 + return -ENOMEM;
52387 +
52388 + ret = copy_user_glob(o_tmp);
52389 + if (ret)
52390 + return ret;
52391 +
52392 + if (o_tmp->nested) {
52393 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52394 + if (IS_ERR(o_tmp->nested))
52395 + return PTR_ERR(o_tmp->nested);
52396 +
52397 + /* insert into nested subject list */
52398 + o_tmp->nested->next = role->hash->first;
52399 + role->hash->first = o_tmp->nested;
52400 + }
52401 + }
52402 +
52403 + return 0;
52404 +}
52405 +
52406 +static __u32
52407 +count_user_subjs(struct acl_subject_label *userp)
52408 +{
52409 + struct acl_subject_label s_tmp;
52410 + __u32 num = 0;
52411 +
52412 + while (userp) {
52413 + if (copy_from_user(&s_tmp, userp,
52414 + sizeof (struct acl_subject_label)))
52415 + break;
52416 +
52417 + userp = s_tmp.prev;
52418 + /* do not count nested subjects against this count, since
52419 + they are not included in the hash table, but are
52420 + attached to objects. We have already counted
52421 + the subjects in userspace for the allocation
52422 + stack
52423 + */
52424 + if (!(s_tmp.mode & GR_NESTED))
52425 + num++;
52426 + }
52427 +
52428 + return num;
52429 +}
52430 +
52431 +static int
52432 +copy_user_allowedips(struct acl_role_label *rolep)
52433 +{
52434 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52435 +
52436 + ruserip = rolep->allowed_ips;
52437 +
52438 + while (ruserip) {
52439 + rlast = rtmp;
52440 +
52441 + if ((rtmp = (struct role_allowed_ip *)
52442 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52443 + return -ENOMEM;
52444 +
52445 + if (copy_from_user(rtmp, ruserip,
52446 + sizeof (struct role_allowed_ip)))
52447 + return -EFAULT;
52448 +
52449 + ruserip = rtmp->prev;
52450 +
52451 + if (!rlast) {
52452 + rtmp->prev = NULL;
52453 + rolep->allowed_ips = rtmp;
52454 + } else {
52455 + rlast->next = rtmp;
52456 + rtmp->prev = rlast;
52457 + }
52458 +
52459 + if (!ruserip)
52460 + rtmp->next = NULL;
52461 + }
52462 +
52463 + return 0;
52464 +}
52465 +
52466 +static int
52467 +copy_user_transitions(struct acl_role_label *rolep)
52468 +{
52469 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52470 +
52471 + unsigned int len;
52472 + char *tmp;
52473 +
52474 + rusertp = rolep->transitions;
52475 +
52476 + while (rusertp) {
52477 + rlast = rtmp;
52478 +
52479 + if ((rtmp = (struct role_transition *)
52480 + acl_alloc(sizeof (struct role_transition))) == NULL)
52481 + return -ENOMEM;
52482 +
52483 + if (copy_from_user(rtmp, rusertp,
52484 + sizeof (struct role_transition)))
52485 + return -EFAULT;
52486 +
52487 + rusertp = rtmp->prev;
52488 +
52489 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52490 +
52491 + if (!len || len >= GR_SPROLE_LEN)
52492 + return -EINVAL;
52493 +
52494 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52495 + return -ENOMEM;
52496 +
52497 + if (copy_from_user(tmp, rtmp->rolename, len))
52498 + return -EFAULT;
52499 + tmp[len-1] = '\0';
52500 + rtmp->rolename = tmp;
52501 +
52502 + if (!rlast) {
52503 + rtmp->prev = NULL;
52504 + rolep->transitions = rtmp;
52505 + } else {
52506 + rlast->next = rtmp;
52507 + rtmp->prev = rlast;
52508 + }
52509 +
52510 + if (!rusertp)
52511 + rtmp->next = NULL;
52512 + }
52513 +
52514 + return 0;
52515 +}
52516 +
52517 +static struct acl_subject_label *
52518 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52519 +{
52520 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52521 + unsigned int len;
52522 + char *tmp;
52523 + __u32 num_objs;
52524 + struct acl_ip_label **i_tmp, *i_utmp2;
52525 + struct gr_hash_struct ghash;
52526 + struct subject_map *subjmap;
52527 + unsigned int i_num;
52528 + int err;
52529 +
52530 + s_tmp = lookup_subject_map(userp);
52531 +
52532 + /* we've already copied this subject into the kernel, just return
52533 + the reference to it, and don't copy it over again
52534 + */
52535 + if (s_tmp)
52536 + return(s_tmp);
52537 +
52538 + if ((s_tmp = (struct acl_subject_label *)
52539 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52540 + return ERR_PTR(-ENOMEM);
52541 +
52542 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52543 + if (subjmap == NULL)
52544 + return ERR_PTR(-ENOMEM);
52545 +
52546 + subjmap->user = userp;
52547 + subjmap->kernel = s_tmp;
52548 + insert_subj_map_entry(subjmap);
52549 +
52550 + if (copy_from_user(s_tmp, userp,
52551 + sizeof (struct acl_subject_label)))
52552 + return ERR_PTR(-EFAULT);
52553 +
52554 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52555 +
52556 + if (!len || len >= PATH_MAX)
52557 + return ERR_PTR(-EINVAL);
52558 +
52559 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52560 + return ERR_PTR(-ENOMEM);
52561 +
52562 + if (copy_from_user(tmp, s_tmp->filename, len))
52563 + return ERR_PTR(-EFAULT);
52564 + tmp[len-1] = '\0';
52565 + s_tmp->filename = tmp;
52566 +
52567 + if (!strcmp(s_tmp->filename, "/"))
52568 + role->root_label = s_tmp;
52569 +
52570 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52571 + return ERR_PTR(-EFAULT);
52572 +
52573 + /* copy user and group transition tables */
52574 +
52575 + if (s_tmp->user_trans_num) {
52576 + uid_t *uidlist;
52577 +
52578 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52579 + if (uidlist == NULL)
52580 + return ERR_PTR(-ENOMEM);
52581 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52582 + return ERR_PTR(-EFAULT);
52583 +
52584 + s_tmp->user_transitions = uidlist;
52585 + }
52586 +
52587 + if (s_tmp->group_trans_num) {
52588 + gid_t *gidlist;
52589 +
52590 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52591 + if (gidlist == NULL)
52592 + return ERR_PTR(-ENOMEM);
52593 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52594 + return ERR_PTR(-EFAULT);
52595 +
52596 + s_tmp->group_transitions = gidlist;
52597 + }
52598 +
52599 + /* set up object hash table */
52600 + num_objs = count_user_objs(ghash.first);
52601 +
52602 + s_tmp->obj_hash_size = num_objs;
52603 + s_tmp->obj_hash =
52604 + (struct acl_object_label **)
52605 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52606 +
52607 + if (!s_tmp->obj_hash)
52608 + return ERR_PTR(-ENOMEM);
52609 +
52610 + memset(s_tmp->obj_hash, 0,
52611 + s_tmp->obj_hash_size *
52612 + sizeof (struct acl_object_label *));
52613 +
52614 + /* add in objects */
52615 + err = copy_user_objs(ghash.first, s_tmp, role);
52616 +
52617 + if (err)
52618 + return ERR_PTR(err);
52619 +
52620 + /* set pointer for parent subject */
52621 + if (s_tmp->parent_subject) {
52622 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52623 +
52624 + if (IS_ERR(s_tmp2))
52625 + return s_tmp2;
52626 +
52627 + s_tmp->parent_subject = s_tmp2;
52628 + }
52629 +
52630 + /* add in ip acls */
52631 +
52632 + if (!s_tmp->ip_num) {
52633 + s_tmp->ips = NULL;
52634 + goto insert;
52635 + }
52636 +
52637 + i_tmp =
52638 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52639 + sizeof (struct acl_ip_label *));
52640 +
52641 + if (!i_tmp)
52642 + return ERR_PTR(-ENOMEM);
52643 +
52644 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52645 + *(i_tmp + i_num) =
52646 + (struct acl_ip_label *)
52647 + acl_alloc(sizeof (struct acl_ip_label));
52648 + if (!*(i_tmp + i_num))
52649 + return ERR_PTR(-ENOMEM);
52650 +
52651 + if (copy_from_user
52652 + (&i_utmp2, s_tmp->ips + i_num,
52653 + sizeof (struct acl_ip_label *)))
52654 + return ERR_PTR(-EFAULT);
52655 +
52656 + if (copy_from_user
52657 + (*(i_tmp + i_num), i_utmp2,
52658 + sizeof (struct acl_ip_label)))
52659 + return ERR_PTR(-EFAULT);
52660 +
52661 + if ((*(i_tmp + i_num))->iface == NULL)
52662 + continue;
52663 +
52664 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52665 + if (!len || len >= IFNAMSIZ)
52666 + return ERR_PTR(-EINVAL);
52667 + tmp = acl_alloc(len);
52668 + if (tmp == NULL)
52669 + return ERR_PTR(-ENOMEM);
52670 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52671 + return ERR_PTR(-EFAULT);
52672 + (*(i_tmp + i_num))->iface = tmp;
52673 + }
52674 +
52675 + s_tmp->ips = i_tmp;
52676 +
52677 +insert:
52678 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52679 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52680 + return ERR_PTR(-ENOMEM);
52681 +
52682 + return s_tmp;
52683 +}
52684 +
52685 +static int
52686 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52687 +{
52688 + struct acl_subject_label s_pre;
52689 + struct acl_subject_label * ret;
52690 + int err;
52691 +
52692 + while (userp) {
52693 + if (copy_from_user(&s_pre, userp,
52694 + sizeof (struct acl_subject_label)))
52695 + return -EFAULT;
52696 +
52697 + /* do not add nested subjects here, add
52698 + while parsing objects
52699 + */
52700 +
52701 + if (s_pre.mode & GR_NESTED) {
52702 + userp = s_pre.prev;
52703 + continue;
52704 + }
52705 +
52706 + ret = do_copy_user_subj(userp, role);
52707 +
52708 + err = PTR_ERR(ret);
52709 + if (IS_ERR(ret))
52710 + return err;
52711 +
52712 + insert_acl_subj_label(ret, role);
52713 +
52714 + userp = s_pre.prev;
52715 + }
52716 +
52717 + return 0;
52718 +}
52719 +
52720 +static int
52721 +copy_user_acl(struct gr_arg *arg)
52722 +{
52723 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52724 + struct sprole_pw *sptmp;
52725 + struct gr_hash_struct *ghash;
52726 + uid_t *domainlist;
52727 + unsigned int r_num;
52728 + unsigned int len;
52729 + char *tmp;
52730 + int err = 0;
52731 + __u16 i;
52732 + __u32 num_subjs;
52733 +
52734 + /* we need a default and kernel role */
52735 + if (arg->role_db.num_roles < 2)
52736 + return -EINVAL;
52737 +
52738 + /* copy special role authentication info from userspace */
52739 +
52740 + num_sprole_pws = arg->num_sprole_pws;
52741 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52742 +
52743 + if (!acl_special_roles && num_sprole_pws)
52744 + return -ENOMEM;
52745 +
52746 + for (i = 0; i < num_sprole_pws; i++) {
52747 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52748 + if (!sptmp)
52749 + return -ENOMEM;
52750 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52751 + sizeof (struct sprole_pw)))
52752 + return -EFAULT;
52753 +
52754 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52755 +
52756 + if (!len || len >= GR_SPROLE_LEN)
52757 + return -EINVAL;
52758 +
52759 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52760 + return -ENOMEM;
52761 +
52762 + if (copy_from_user(tmp, sptmp->rolename, len))
52763 + return -EFAULT;
52764 +
52765 + tmp[len-1] = '\0';
52766 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52767 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52768 +#endif
52769 + sptmp->rolename = tmp;
52770 + acl_special_roles[i] = sptmp;
52771 + }
52772 +
52773 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52774 +
52775 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52776 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52777 +
52778 + if (!r_tmp)
52779 + return -ENOMEM;
52780 +
52781 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52782 + sizeof (struct acl_role_label *)))
52783 + return -EFAULT;
52784 +
52785 + if (copy_from_user(r_tmp, r_utmp2,
52786 + sizeof (struct acl_role_label)))
52787 + return -EFAULT;
52788 +
52789 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52790 +
52791 + if (!len || len >= PATH_MAX)
52792 + return -EINVAL;
52793 +
52794 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52795 + return -ENOMEM;
52796 +
52797 + if (copy_from_user(tmp, r_tmp->rolename, len))
52798 + return -EFAULT;
52799 +
52800 + tmp[len-1] = '\0';
52801 + r_tmp->rolename = tmp;
52802 +
52803 + if (!strcmp(r_tmp->rolename, "default")
52804 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52805 + default_role = r_tmp;
52806 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52807 + kernel_role = r_tmp;
52808 + }
52809 +
52810 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52811 + return -ENOMEM;
52812 +
52813 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52814 + return -EFAULT;
52815 +
52816 + r_tmp->hash = ghash;
52817 +
52818 + num_subjs = count_user_subjs(r_tmp->hash->first);
52819 +
52820 + r_tmp->subj_hash_size = num_subjs;
52821 + r_tmp->subj_hash =
52822 + (struct acl_subject_label **)
52823 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52824 +
52825 + if (!r_tmp->subj_hash)
52826 + return -ENOMEM;
52827 +
52828 + err = copy_user_allowedips(r_tmp);
52829 + if (err)
52830 + return err;
52831 +
52832 + /* copy domain info */
52833 + if (r_tmp->domain_children != NULL) {
52834 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52835 + if (domainlist == NULL)
52836 + return -ENOMEM;
52837 +
52838 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52839 + return -EFAULT;
52840 +
52841 + r_tmp->domain_children = domainlist;
52842 + }
52843 +
52844 + err = copy_user_transitions(r_tmp);
52845 + if (err)
52846 + return err;
52847 +
52848 + memset(r_tmp->subj_hash, 0,
52849 + r_tmp->subj_hash_size *
52850 + sizeof (struct acl_subject_label *));
52851 +
52852 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52853 +
52854 + if (err)
52855 + return err;
52856 +
52857 + /* set nested subject list to null */
52858 + r_tmp->hash->first = NULL;
52859 +
52860 + insert_acl_role_label(r_tmp);
52861 + }
52862 +
52863 + if (default_role == NULL || kernel_role == NULL)
52864 + return -EINVAL;
52865 +
52866 + return err;
52867 +}
52868 +
52869 +static int
52870 +gracl_init(struct gr_arg *args)
52871 +{
52872 + int error = 0;
52873 +
52874 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52875 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52876 +
52877 + if (init_variables(args)) {
52878 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52879 + error = -ENOMEM;
52880 + free_variables();
52881 + goto out;
52882 + }
52883 +
52884 + error = copy_user_acl(args);
52885 + free_init_variables();
52886 + if (error) {
52887 + free_variables();
52888 + goto out;
52889 + }
52890 +
52891 + if ((error = gr_set_acls(0))) {
52892 + free_variables();
52893 + goto out;
52894 + }
52895 +
52896 + pax_open_kernel();
52897 + gr_status |= GR_READY;
52898 + pax_close_kernel();
52899 +
52900 + out:
52901 + return error;
52902 +}
52903 +
52904 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52905 +
52906 +static int
52907 +glob_match(const char *p, const char *n)
52908 +{
52909 + char c;
52910 +
52911 + while ((c = *p++) != '\0') {
52912 + switch (c) {
52913 + case '?':
52914 + if (*n == '\0')
52915 + return 1;
52916 + else if (*n == '/')
52917 + return 1;
52918 + break;
52919 + case '\\':
52920 + if (*n != c)
52921 + return 1;
52922 + break;
52923 + case '*':
52924 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52925 + if (*n == '/')
52926 + return 1;
52927 + else if (c == '?') {
52928 + if (*n == '\0')
52929 + return 1;
52930 + else
52931 + ++n;
52932 + }
52933 + }
52934 + if (c == '\0') {
52935 + return 0;
52936 + } else {
52937 + const char *endp;
52938 +
52939 + if ((endp = strchr(n, '/')) == NULL)
52940 + endp = n + strlen(n);
52941 +
52942 + if (c == '[') {
52943 + for (--p; n < endp; ++n)
52944 + if (!glob_match(p, n))
52945 + return 0;
52946 + } else if (c == '/') {
52947 + while (*n != '\0' && *n != '/')
52948 + ++n;
52949 + if (*n == '/' && !glob_match(p, n + 1))
52950 + return 0;
52951 + } else {
52952 + for (--p; n < endp; ++n)
52953 + if (*n == c && !glob_match(p, n))
52954 + return 0;
52955 + }
52956 +
52957 + return 1;
52958 + }
52959 + case '[':
52960 + {
52961 + int not;
52962 + char cold;
52963 +
52964 + if (*n == '\0' || *n == '/')
52965 + return 1;
52966 +
52967 + not = (*p == '!' || *p == '^');
52968 + if (not)
52969 + ++p;
52970 +
52971 + c = *p++;
52972 + for (;;) {
52973 + unsigned char fn = (unsigned char)*n;
52974 +
52975 + if (c == '\0')
52976 + return 1;
52977 + else {
52978 + if (c == fn)
52979 + goto matched;
52980 + cold = c;
52981 + c = *p++;
52982 +
52983 + if (c == '-' && *p != ']') {
52984 + unsigned char cend = *p++;
52985 +
52986 + if (cend == '\0')
52987 + return 1;
52988 +
52989 + if (cold <= fn && fn <= cend)
52990 + goto matched;
52991 +
52992 + c = *p++;
52993 + }
52994 + }
52995 +
52996 + if (c == ']')
52997 + break;
52998 + }
52999 + if (!not)
53000 + return 1;
53001 + break;
53002 + matched:
53003 + while (c != ']') {
53004 + if (c == '\0')
53005 + return 1;
53006 +
53007 + c = *p++;
53008 + }
53009 + if (not)
53010 + return 1;
53011 + }
53012 + break;
53013 + default:
53014 + if (c != *n)
53015 + return 1;
53016 + }
53017 +
53018 + ++n;
53019 + }
53020 +
53021 + if (*n == '\0')
53022 + return 0;
53023 +
53024 + if (*n == '/')
53025 + return 0;
53026 +
53027 + return 1;
53028 +}
53029 +
53030 +static struct acl_object_label *
53031 +chk_glob_label(struct acl_object_label *globbed,
53032 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53033 +{
53034 + struct acl_object_label *tmp;
53035 +
53036 + if (*path == NULL)
53037 + *path = gr_to_filename_nolock(dentry, mnt);
53038 +
53039 + tmp = globbed;
53040 +
53041 + while (tmp) {
53042 + if (!glob_match(tmp->filename, *path))
53043 + return tmp;
53044 + tmp = tmp->next;
53045 + }
53046 +
53047 + return NULL;
53048 +}
53049 +
53050 +static struct acl_object_label *
53051 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53052 + const ino_t curr_ino, const dev_t curr_dev,
53053 + const struct acl_subject_label *subj, char **path, const int checkglob)
53054 +{
53055 + struct acl_subject_label *tmpsubj;
53056 + struct acl_object_label *retval;
53057 + struct acl_object_label *retval2;
53058 +
53059 + tmpsubj = (struct acl_subject_label *) subj;
53060 + read_lock(&gr_inode_lock);
53061 + do {
53062 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53063 + if (retval) {
53064 + if (checkglob && retval->globbed) {
53065 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53066 + if (retval2)
53067 + retval = retval2;
53068 + }
53069 + break;
53070 + }
53071 + } while ((tmpsubj = tmpsubj->parent_subject));
53072 + read_unlock(&gr_inode_lock);
53073 +
53074 + return retval;
53075 +}
53076 +
53077 +static __inline__ struct acl_object_label *
53078 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53079 + struct dentry *curr_dentry,
53080 + const struct acl_subject_label *subj, char **path, const int checkglob)
53081 +{
53082 + int newglob = checkglob;
53083 + ino_t inode;
53084 + dev_t device;
53085 +
53086 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53087 + as we don't want a / * rule to match instead of the / object
53088 + don't do this for create lookups that call this function though, since they're looking up
53089 + on the parent and thus need globbing checks on all paths
53090 + */
53091 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53092 + newglob = GR_NO_GLOB;
53093 +
53094 + spin_lock(&curr_dentry->d_lock);
53095 + inode = curr_dentry->d_inode->i_ino;
53096 + device = __get_dev(curr_dentry);
53097 + spin_unlock(&curr_dentry->d_lock);
53098 +
53099 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53100 +}
53101 +
53102 +static struct acl_object_label *
53103 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53104 + const struct acl_subject_label *subj, char *path, const int checkglob)
53105 +{
53106 + struct dentry *dentry = (struct dentry *) l_dentry;
53107 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53108 + struct mount *real_mnt = real_mount(mnt);
53109 + struct acl_object_label *retval;
53110 + struct dentry *parent;
53111 +
53112 + write_seqlock(&rename_lock);
53113 + br_read_lock(&vfsmount_lock);
53114 +
53115 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53116 +#ifdef CONFIG_NET
53117 + mnt == sock_mnt ||
53118 +#endif
53119 +#ifdef CONFIG_HUGETLBFS
53120 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53121 +#endif
53122 + /* ignore Eric Biederman */
53123 + IS_PRIVATE(l_dentry->d_inode))) {
53124 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53125 + goto out;
53126 + }
53127 +
53128 + for (;;) {
53129 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53130 + break;
53131 +
53132 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53133 + if (!mnt_has_parent(real_mnt))
53134 + break;
53135 +
53136 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53137 + if (retval != NULL)
53138 + goto out;
53139 +
53140 + dentry = real_mnt->mnt_mountpoint;
53141 + real_mnt = real_mnt->mnt_parent;
53142 + mnt = &real_mnt->mnt;
53143 + continue;
53144 + }
53145 +
53146 + parent = dentry->d_parent;
53147 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53148 + if (retval != NULL)
53149 + goto out;
53150 +
53151 + dentry = parent;
53152 + }
53153 +
53154 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53155 +
53156 + /* real_root is pinned so we don't have to hold a reference */
53157 + if (retval == NULL)
53158 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53159 +out:
53160 + br_read_unlock(&vfsmount_lock);
53161 + write_sequnlock(&rename_lock);
53162 +
53163 + BUG_ON(retval == NULL);
53164 +
53165 + return retval;
53166 +}
53167 +
53168 +static __inline__ struct acl_object_label *
53169 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53170 + const struct acl_subject_label *subj)
53171 +{
53172 + char *path = NULL;
53173 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53174 +}
53175 +
53176 +static __inline__ struct acl_object_label *
53177 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53178 + const struct acl_subject_label *subj)
53179 +{
53180 + char *path = NULL;
53181 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53182 +}
53183 +
53184 +static __inline__ struct acl_object_label *
53185 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53186 + const struct acl_subject_label *subj, char *path)
53187 +{
53188 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53189 +}
53190 +
53191 +static struct acl_subject_label *
53192 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53193 + const struct acl_role_label *role)
53194 +{
53195 + struct dentry *dentry = (struct dentry *) l_dentry;
53196 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53197 + struct mount *real_mnt = real_mount(mnt);
53198 + struct acl_subject_label *retval;
53199 + struct dentry *parent;
53200 +
53201 + write_seqlock(&rename_lock);
53202 + br_read_lock(&vfsmount_lock);
53203 +
53204 + for (;;) {
53205 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53206 + break;
53207 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53208 + if (!mnt_has_parent(real_mnt))
53209 + break;
53210 +
53211 + spin_lock(&dentry->d_lock);
53212 + read_lock(&gr_inode_lock);
53213 + retval =
53214 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53215 + __get_dev(dentry), role);
53216 + read_unlock(&gr_inode_lock);
53217 + spin_unlock(&dentry->d_lock);
53218 + if (retval != NULL)
53219 + goto out;
53220 +
53221 + dentry = real_mnt->mnt_mountpoint;
53222 + real_mnt = real_mnt->mnt_parent;
53223 + mnt = &real_mnt->mnt;
53224 + continue;
53225 + }
53226 +
53227 + spin_lock(&dentry->d_lock);
53228 + read_lock(&gr_inode_lock);
53229 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53230 + __get_dev(dentry), role);
53231 + read_unlock(&gr_inode_lock);
53232 + parent = dentry->d_parent;
53233 + spin_unlock(&dentry->d_lock);
53234 +
53235 + if (retval != NULL)
53236 + goto out;
53237 +
53238 + dentry = parent;
53239 + }
53240 +
53241 + spin_lock(&dentry->d_lock);
53242 + read_lock(&gr_inode_lock);
53243 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53244 + __get_dev(dentry), role);
53245 + read_unlock(&gr_inode_lock);
53246 + spin_unlock(&dentry->d_lock);
53247 +
53248 + if (unlikely(retval == NULL)) {
53249 + /* real_root is pinned, we don't need to hold a reference */
53250 + read_lock(&gr_inode_lock);
53251 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53252 + __get_dev(real_root.dentry), role);
53253 + read_unlock(&gr_inode_lock);
53254 + }
53255 +out:
53256 + br_read_unlock(&vfsmount_lock);
53257 + write_sequnlock(&rename_lock);
53258 +
53259 + BUG_ON(retval == NULL);
53260 +
53261 + return retval;
53262 +}
53263 +
53264 +static void
53265 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53266 +{
53267 + struct task_struct *task = current;
53268 + const struct cred *cred = current_cred();
53269 +
53270 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53271 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53272 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53273 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53274 +
53275 + return;
53276 +}
53277 +
53278 +static void
53279 +gr_log_learn_id_change(const char type, const unsigned int real,
53280 + const unsigned int effective, const unsigned int fs)
53281 +{
53282 + struct task_struct *task = current;
53283 + const struct cred *cred = current_cred();
53284 +
53285 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53286 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53287 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53288 + type, real, effective, fs, &task->signal->saved_ip);
53289 +
53290 + return;
53291 +}
53292 +
53293 +__u32
53294 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53295 + const struct vfsmount * mnt)
53296 +{
53297 + __u32 retval = mode;
53298 + struct acl_subject_label *curracl;
53299 + struct acl_object_label *currobj;
53300 +
53301 + if (unlikely(!(gr_status & GR_READY)))
53302 + return (mode & ~GR_AUDITS);
53303 +
53304 + curracl = current->acl;
53305 +
53306 + currobj = chk_obj_label(dentry, mnt, curracl);
53307 + retval = currobj->mode & mode;
53308 +
53309 + /* if we're opening a specified transfer file for writing
53310 + (e.g. /dev/initctl), then transfer our role to init
53311 + */
53312 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53313 + current->role->roletype & GR_ROLE_PERSIST)) {
53314 + struct task_struct *task = init_pid_ns.child_reaper;
53315 +
53316 + if (task->role != current->role) {
53317 + task->acl_sp_role = 0;
53318 + task->acl_role_id = current->acl_role_id;
53319 + task->role = current->role;
53320 + rcu_read_lock();
53321 + read_lock(&grsec_exec_file_lock);
53322 + gr_apply_subject_to_task(task);
53323 + read_unlock(&grsec_exec_file_lock);
53324 + rcu_read_unlock();
53325 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53326 + }
53327 + }
53328 +
53329 + if (unlikely
53330 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53331 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53332 + __u32 new_mode = mode;
53333 +
53334 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53335 +
53336 + retval = new_mode;
53337 +
53338 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53339 + new_mode |= GR_INHERIT;
53340 +
53341 + if (!(mode & GR_NOLEARN))
53342 + gr_log_learn(dentry, mnt, new_mode);
53343 + }
53344 +
53345 + return retval;
53346 +}
53347 +
53348 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53349 + const struct dentry *parent,
53350 + const struct vfsmount *mnt)
53351 +{
53352 + struct name_entry *match;
53353 + struct acl_object_label *matchpo;
53354 + struct acl_subject_label *curracl;
53355 + char *path;
53356 +
53357 + if (unlikely(!(gr_status & GR_READY)))
53358 + return NULL;
53359 +
53360 + preempt_disable();
53361 + path = gr_to_filename_rbac(new_dentry, mnt);
53362 + match = lookup_name_entry_create(path);
53363 +
53364 + curracl = current->acl;
53365 +
53366 + if (match) {
53367 + read_lock(&gr_inode_lock);
53368 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53369 + read_unlock(&gr_inode_lock);
53370 +
53371 + if (matchpo) {
53372 + preempt_enable();
53373 + return matchpo;
53374 + }
53375 + }
53376 +
53377 + // lookup parent
53378 +
53379 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53380 +
53381 + preempt_enable();
53382 + return matchpo;
53383 +}
53384 +
53385 +__u32
53386 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53387 + const struct vfsmount * mnt, const __u32 mode)
53388 +{
53389 + struct acl_object_label *matchpo;
53390 + __u32 retval;
53391 +
53392 + if (unlikely(!(gr_status & GR_READY)))
53393 + return (mode & ~GR_AUDITS);
53394 +
53395 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53396 +
53397 + retval = matchpo->mode & mode;
53398 +
53399 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53400 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53401 + __u32 new_mode = mode;
53402 +
53403 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53404 +
53405 + gr_log_learn(new_dentry, mnt, new_mode);
53406 + return new_mode;
53407 + }
53408 +
53409 + return retval;
53410 +}
53411 +
53412 +__u32
53413 +gr_check_link(const struct dentry * new_dentry,
53414 + const struct dentry * parent_dentry,
53415 + const struct vfsmount * parent_mnt,
53416 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53417 +{
53418 + struct acl_object_label *obj;
53419 + __u32 oldmode, newmode;
53420 + __u32 needmode;
53421 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53422 + GR_DELETE | GR_INHERIT;
53423 +
53424 + if (unlikely(!(gr_status & GR_READY)))
53425 + return (GR_CREATE | GR_LINK);
53426 +
53427 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53428 + oldmode = obj->mode;
53429 +
53430 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53431 + newmode = obj->mode;
53432 +
53433 + needmode = newmode & checkmodes;
53434 +
53435 + // old name for hardlink must have at least the permissions of the new name
53436 + if ((oldmode & needmode) != needmode)
53437 + goto bad;
53438 +
53439 + // if old name had restrictions/auditing, make sure the new name does as well
53440 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53441 +
53442 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53443 + if (is_privileged_binary(old_dentry))
53444 + needmode |= GR_SETID;
53445 +
53446 + if ((newmode & needmode) != needmode)
53447 + goto bad;
53448 +
53449 + // enforce minimum permissions
53450 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53451 + return newmode;
53452 +bad:
53453 + needmode = oldmode;
53454 + if (is_privileged_binary(old_dentry))
53455 + needmode |= GR_SETID;
53456 +
53457 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53458 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53459 + return (GR_CREATE | GR_LINK);
53460 + } else if (newmode & GR_SUPPRESS)
53461 + return GR_SUPPRESS;
53462 + else
53463 + return 0;
53464 +}
53465 +
53466 +int
53467 +gr_check_hidden_task(const struct task_struct *task)
53468 +{
53469 + if (unlikely(!(gr_status & GR_READY)))
53470 + return 0;
53471 +
53472 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53473 + return 1;
53474 +
53475 + return 0;
53476 +}
53477 +
53478 +int
53479 +gr_check_protected_task(const struct task_struct *task)
53480 +{
53481 + if (unlikely(!(gr_status & GR_READY) || !task))
53482 + return 0;
53483 +
53484 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53485 + task->acl != current->acl)
53486 + return 1;
53487 +
53488 + return 0;
53489 +}
53490 +
53491 +int
53492 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53493 +{
53494 + struct task_struct *p;
53495 + int ret = 0;
53496 +
53497 + if (unlikely(!(gr_status & GR_READY) || !pid))
53498 + return ret;
53499 +
53500 + read_lock(&tasklist_lock);
53501 + do_each_pid_task(pid, type, p) {
53502 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53503 + p->acl != current->acl) {
53504 + ret = 1;
53505 + goto out;
53506 + }
53507 + } while_each_pid_task(pid, type, p);
53508 +out:
53509 + read_unlock(&tasklist_lock);
53510 +
53511 + return ret;
53512 +}
53513 +
53514 +void
53515 +gr_copy_label(struct task_struct *tsk)
53516 +{
53517 + tsk->signal->used_accept = 0;
53518 + tsk->acl_sp_role = 0;
53519 + tsk->acl_role_id = current->acl_role_id;
53520 + tsk->acl = current->acl;
53521 + tsk->role = current->role;
53522 + tsk->signal->curr_ip = current->signal->curr_ip;
53523 + tsk->signal->saved_ip = current->signal->saved_ip;
53524 + if (current->exec_file)
53525 + get_file(current->exec_file);
53526 + tsk->exec_file = current->exec_file;
53527 + tsk->is_writable = current->is_writable;
53528 + if (unlikely(current->signal->used_accept)) {
53529 + current->signal->curr_ip = 0;
53530 + current->signal->saved_ip = 0;
53531 + }
53532 +
53533 + return;
53534 +}
53535 +
53536 +static void
53537 +gr_set_proc_res(struct task_struct *task)
53538 +{
53539 + struct acl_subject_label *proc;
53540 + unsigned short i;
53541 +
53542 + proc = task->acl;
53543 +
53544 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53545 + return;
53546 +
53547 + for (i = 0; i < RLIM_NLIMITS; i++) {
53548 + if (!(proc->resmask & (1 << i)))
53549 + continue;
53550 +
53551 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53552 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53553 + }
53554 +
53555 + return;
53556 +}
53557 +
53558 +extern int __gr_process_user_ban(struct user_struct *user);
53559 +
53560 +int
53561 +gr_check_user_change(int real, int effective, int fs)
53562 +{
53563 + unsigned int i;
53564 + __u16 num;
53565 + uid_t *uidlist;
53566 + int curuid;
53567 + int realok = 0;
53568 + int effectiveok = 0;
53569 + int fsok = 0;
53570 +
53571 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53572 + struct user_struct *user;
53573 +
53574 + if (real == -1)
53575 + goto skipit;
53576 +
53577 + user = find_user(real);
53578 + if (user == NULL)
53579 + goto skipit;
53580 +
53581 + if (__gr_process_user_ban(user)) {
53582 + /* for find_user */
53583 + free_uid(user);
53584 + return 1;
53585 + }
53586 +
53587 + /* for find_user */
53588 + free_uid(user);
53589 +
53590 +skipit:
53591 +#endif
53592 +
53593 + if (unlikely(!(gr_status & GR_READY)))
53594 + return 0;
53595 +
53596 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53597 + gr_log_learn_id_change('u', real, effective, fs);
53598 +
53599 + num = current->acl->user_trans_num;
53600 + uidlist = current->acl->user_transitions;
53601 +
53602 + if (uidlist == NULL)
53603 + return 0;
53604 +
53605 + if (real == -1)
53606 + realok = 1;
53607 + if (effective == -1)
53608 + effectiveok = 1;
53609 + if (fs == -1)
53610 + fsok = 1;
53611 +
53612 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53613 + for (i = 0; i < num; i++) {
53614 + curuid = (int)uidlist[i];
53615 + if (real == curuid)
53616 + realok = 1;
53617 + if (effective == curuid)
53618 + effectiveok = 1;
53619 + if (fs == curuid)
53620 + fsok = 1;
53621 + }
53622 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53623 + for (i = 0; i < num; i++) {
53624 + curuid = (int)uidlist[i];
53625 + if (real == curuid)
53626 + break;
53627 + if (effective == curuid)
53628 + break;
53629 + if (fs == curuid)
53630 + break;
53631 + }
53632 + /* not in deny list */
53633 + if (i == num) {
53634 + realok = 1;
53635 + effectiveok = 1;
53636 + fsok = 1;
53637 + }
53638 + }
53639 +
53640 + if (realok && effectiveok && fsok)
53641 + return 0;
53642 + else {
53643 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53644 + return 1;
53645 + }
53646 +}
53647 +
53648 +int
53649 +gr_check_group_change(int real, int effective, int fs)
53650 +{
53651 + unsigned int i;
53652 + __u16 num;
53653 + gid_t *gidlist;
53654 + int curgid;
53655 + int realok = 0;
53656 + int effectiveok = 0;
53657 + int fsok = 0;
53658 +
53659 + if (unlikely(!(gr_status & GR_READY)))
53660 + return 0;
53661 +
53662 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53663 + gr_log_learn_id_change('g', real, effective, fs);
53664 +
53665 + num = current->acl->group_trans_num;
53666 + gidlist = current->acl->group_transitions;
53667 +
53668 + if (gidlist == NULL)
53669 + return 0;
53670 +
53671 + if (real == -1)
53672 + realok = 1;
53673 + if (effective == -1)
53674 + effectiveok = 1;
53675 + if (fs == -1)
53676 + fsok = 1;
53677 +
53678 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53679 + for (i = 0; i < num; i++) {
53680 + curgid = (int)gidlist[i];
53681 + if (real == curgid)
53682 + realok = 1;
53683 + if (effective == curgid)
53684 + effectiveok = 1;
53685 + if (fs == curgid)
53686 + fsok = 1;
53687 + }
53688 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53689 + for (i = 0; i < num; i++) {
53690 + curgid = (int)gidlist[i];
53691 + if (real == curgid)
53692 + break;
53693 + if (effective == curgid)
53694 + break;
53695 + if (fs == curgid)
53696 + break;
53697 + }
53698 + /* not in deny list */
53699 + if (i == num) {
53700 + realok = 1;
53701 + effectiveok = 1;
53702 + fsok = 1;
53703 + }
53704 + }
53705 +
53706 + if (realok && effectiveok && fsok)
53707 + return 0;
53708 + else {
53709 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53710 + return 1;
53711 + }
53712 +}
53713 +
53714 +extern int gr_acl_is_capable(const int cap);
53715 +
53716 +void
53717 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53718 +{
53719 + struct acl_role_label *role = task->role;
53720 + struct acl_subject_label *subj = NULL;
53721 + struct acl_object_label *obj;
53722 + struct file *filp;
53723 +
53724 + if (unlikely(!(gr_status & GR_READY)))
53725 + return;
53726 +
53727 + filp = task->exec_file;
53728 +
53729 + /* kernel process, we'll give them the kernel role */
53730 + if (unlikely(!filp)) {
53731 + task->role = kernel_role;
53732 + task->acl = kernel_role->root_label;
53733 + return;
53734 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53735 + role = lookup_acl_role_label(task, uid, gid);
53736 +
53737 + /* don't change the role if we're not a privileged process */
53738 + if (role && task->role != role &&
53739 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53740 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53741 + return;
53742 +
53743 + /* perform subject lookup in possibly new role
53744 + we can use this result below in the case where role == task->role
53745 + */
53746 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53747 +
53748 + /* if we changed uid/gid, but result in the same role
53749 + and are using inheritance, don't lose the inherited subject
53750 + if current subject is other than what normal lookup
53751 + would result in, we arrived via inheritance, don't
53752 + lose subject
53753 + */
53754 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53755 + (subj == task->acl)))
53756 + task->acl = subj;
53757 +
53758 + task->role = role;
53759 +
53760 + task->is_writable = 0;
53761 +
53762 + /* ignore additional mmap checks for processes that are writable
53763 + by the default ACL */
53764 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53765 + if (unlikely(obj->mode & GR_WRITE))
53766 + task->is_writable = 1;
53767 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53768 + if (unlikely(obj->mode & GR_WRITE))
53769 + task->is_writable = 1;
53770 +
53771 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53772 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53773 +#endif
53774 +
53775 + gr_set_proc_res(task);
53776 +
53777 + return;
53778 +}
53779 +
53780 +int
53781 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53782 + const int unsafe_flags)
53783 +{
53784 + struct task_struct *task = current;
53785 + struct acl_subject_label *newacl;
53786 + struct acl_object_label *obj;
53787 + __u32 retmode;
53788 +
53789 + if (unlikely(!(gr_status & GR_READY)))
53790 + return 0;
53791 +
53792 + newacl = chk_subj_label(dentry, mnt, task->role);
53793 +
53794 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53795 + did an exec
53796 + */
53797 + rcu_read_lock();
53798 + read_lock(&tasklist_lock);
53799 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53800 + (task->parent->acl->mode & GR_POVERRIDE))) {
53801 + read_unlock(&tasklist_lock);
53802 + rcu_read_unlock();
53803 + goto skip_check;
53804 + }
53805 + read_unlock(&tasklist_lock);
53806 + rcu_read_unlock();
53807 +
53808 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53809 + !(task->role->roletype & GR_ROLE_GOD) &&
53810 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53811 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53812 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53813 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53814 + else
53815 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53816 + return -EACCES;
53817 + }
53818 +
53819 +skip_check:
53820 +
53821 + obj = chk_obj_label(dentry, mnt, task->acl);
53822 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53823 +
53824 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53825 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53826 + if (obj->nested)
53827 + task->acl = obj->nested;
53828 + else
53829 + task->acl = newacl;
53830 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53831 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53832 +
53833 + task->is_writable = 0;
53834 +
53835 + /* ignore additional mmap checks for processes that are writable
53836 + by the default ACL */
53837 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53838 + if (unlikely(obj->mode & GR_WRITE))
53839 + task->is_writable = 1;
53840 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53841 + if (unlikely(obj->mode & GR_WRITE))
53842 + task->is_writable = 1;
53843 +
53844 + gr_set_proc_res(task);
53845 +
53846 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53847 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53848 +#endif
53849 + return 0;
53850 +}
53851 +
53852 +/* always called with valid inodev ptr */
53853 +static void
53854 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53855 +{
53856 + struct acl_object_label *matchpo;
53857 + struct acl_subject_label *matchps;
53858 + struct acl_subject_label *subj;
53859 + struct acl_role_label *role;
53860 + unsigned int x;
53861 +
53862 + FOR_EACH_ROLE_START(role)
53863 + FOR_EACH_SUBJECT_START(role, subj, x)
53864 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53865 + matchpo->mode |= GR_DELETED;
53866 + FOR_EACH_SUBJECT_END(subj,x)
53867 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53868 + if (subj->inode == ino && subj->device == dev)
53869 + subj->mode |= GR_DELETED;
53870 + FOR_EACH_NESTED_SUBJECT_END(subj)
53871 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53872 + matchps->mode |= GR_DELETED;
53873 + FOR_EACH_ROLE_END(role)
53874 +
53875 + inodev->nentry->deleted = 1;
53876 +
53877 + return;
53878 +}
53879 +
53880 +void
53881 +gr_handle_delete(const ino_t ino, const dev_t dev)
53882 +{
53883 + struct inodev_entry *inodev;
53884 +
53885 + if (unlikely(!(gr_status & GR_READY)))
53886 + return;
53887 +
53888 + write_lock(&gr_inode_lock);
53889 + inodev = lookup_inodev_entry(ino, dev);
53890 + if (inodev != NULL)
53891 + do_handle_delete(inodev, ino, dev);
53892 + write_unlock(&gr_inode_lock);
53893 +
53894 + return;
53895 +}
53896 +
53897 +static void
53898 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53899 + const ino_t newinode, const dev_t newdevice,
53900 + struct acl_subject_label *subj)
53901 +{
53902 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53903 + struct acl_object_label *match;
53904 +
53905 + match = subj->obj_hash[index];
53906 +
53907 + while (match && (match->inode != oldinode ||
53908 + match->device != olddevice ||
53909 + !(match->mode & GR_DELETED)))
53910 + match = match->next;
53911 +
53912 + if (match && (match->inode == oldinode)
53913 + && (match->device == olddevice)
53914 + && (match->mode & GR_DELETED)) {
53915 + if (match->prev == NULL) {
53916 + subj->obj_hash[index] = match->next;
53917 + if (match->next != NULL)
53918 + match->next->prev = NULL;
53919 + } else {
53920 + match->prev->next = match->next;
53921 + if (match->next != NULL)
53922 + match->next->prev = match->prev;
53923 + }
53924 + match->prev = NULL;
53925 + match->next = NULL;
53926 + match->inode = newinode;
53927 + match->device = newdevice;
53928 + match->mode &= ~GR_DELETED;
53929 +
53930 + insert_acl_obj_label(match, subj);
53931 + }
53932 +
53933 + return;
53934 +}
53935 +
53936 +static void
53937 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53938 + const ino_t newinode, const dev_t newdevice,
53939 + struct acl_role_label *role)
53940 +{
53941 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53942 + struct acl_subject_label *match;
53943 +
53944 + match = role->subj_hash[index];
53945 +
53946 + while (match && (match->inode != oldinode ||
53947 + match->device != olddevice ||
53948 + !(match->mode & GR_DELETED)))
53949 + match = match->next;
53950 +
53951 + if (match && (match->inode == oldinode)
53952 + && (match->device == olddevice)
53953 + && (match->mode & GR_DELETED)) {
53954 + if (match->prev == NULL) {
53955 + role->subj_hash[index] = match->next;
53956 + if (match->next != NULL)
53957 + match->next->prev = NULL;
53958 + } else {
53959 + match->prev->next = match->next;
53960 + if (match->next != NULL)
53961 + match->next->prev = match->prev;
53962 + }
53963 + match->prev = NULL;
53964 + match->next = NULL;
53965 + match->inode = newinode;
53966 + match->device = newdevice;
53967 + match->mode &= ~GR_DELETED;
53968 +
53969 + insert_acl_subj_label(match, role);
53970 + }
53971 +
53972 + return;
53973 +}
53974 +
53975 +static void
53976 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53977 + const ino_t newinode, const dev_t newdevice)
53978 +{
53979 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53980 + struct inodev_entry *match;
53981 +
53982 + match = inodev_set.i_hash[index];
53983 +
53984 + while (match && (match->nentry->inode != oldinode ||
53985 + match->nentry->device != olddevice || !match->nentry->deleted))
53986 + match = match->next;
53987 +
53988 + if (match && (match->nentry->inode == oldinode)
53989 + && (match->nentry->device == olddevice) &&
53990 + match->nentry->deleted) {
53991 + if (match->prev == NULL) {
53992 + inodev_set.i_hash[index] = match->next;
53993 + if (match->next != NULL)
53994 + match->next->prev = NULL;
53995 + } else {
53996 + match->prev->next = match->next;
53997 + if (match->next != NULL)
53998 + match->next->prev = match->prev;
53999 + }
54000 + match->prev = NULL;
54001 + match->next = NULL;
54002 + match->nentry->inode = newinode;
54003 + match->nentry->device = newdevice;
54004 + match->nentry->deleted = 0;
54005 +
54006 + insert_inodev_entry(match);
54007 + }
54008 +
54009 + return;
54010 +}
54011 +
54012 +static void
54013 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54014 +{
54015 + struct acl_subject_label *subj;
54016 + struct acl_role_label *role;
54017 + unsigned int x;
54018 +
54019 + FOR_EACH_ROLE_START(role)
54020 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54021 +
54022 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54023 + if ((subj->inode == ino) && (subj->device == dev)) {
54024 + subj->inode = ino;
54025 + subj->device = dev;
54026 + }
54027 + FOR_EACH_NESTED_SUBJECT_END(subj)
54028 + FOR_EACH_SUBJECT_START(role, subj, x)
54029 + update_acl_obj_label(matchn->inode, matchn->device,
54030 + ino, dev, subj);
54031 + FOR_EACH_SUBJECT_END(subj,x)
54032 + FOR_EACH_ROLE_END(role)
54033 +
54034 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54035 +
54036 + return;
54037 +}
54038 +
54039 +static void
54040 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54041 + const struct vfsmount *mnt)
54042 +{
54043 + ino_t ino = dentry->d_inode->i_ino;
54044 + dev_t dev = __get_dev(dentry);
54045 +
54046 + __do_handle_create(matchn, ino, dev);
54047 +
54048 + return;
54049 +}
54050 +
54051 +void
54052 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54053 +{
54054 + struct name_entry *matchn;
54055 +
54056 + if (unlikely(!(gr_status & GR_READY)))
54057 + return;
54058 +
54059 + preempt_disable();
54060 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54061 +
54062 + if (unlikely((unsigned long)matchn)) {
54063 + write_lock(&gr_inode_lock);
54064 + do_handle_create(matchn, dentry, mnt);
54065 + write_unlock(&gr_inode_lock);
54066 + }
54067 + preempt_enable();
54068 +
54069 + return;
54070 +}
54071 +
54072 +void
54073 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54074 +{
54075 + struct name_entry *matchn;
54076 +
54077 + if (unlikely(!(gr_status & GR_READY)))
54078 + return;
54079 +
54080 + preempt_disable();
54081 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54082 +
54083 + if (unlikely((unsigned long)matchn)) {
54084 + write_lock(&gr_inode_lock);
54085 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54086 + write_unlock(&gr_inode_lock);
54087 + }
54088 + preempt_enable();
54089 +
54090 + return;
54091 +}
54092 +
54093 +void
54094 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54095 + struct dentry *old_dentry,
54096 + struct dentry *new_dentry,
54097 + struct vfsmount *mnt, const __u8 replace)
54098 +{
54099 + struct name_entry *matchn;
54100 + struct inodev_entry *inodev;
54101 + struct inode *inode = new_dentry->d_inode;
54102 + ino_t old_ino = old_dentry->d_inode->i_ino;
54103 + dev_t old_dev = __get_dev(old_dentry);
54104 +
54105 + /* vfs_rename swaps the name and parent link for old_dentry and
54106 + new_dentry
54107 + at this point, old_dentry has the new name, parent link, and inode
54108 + for the renamed file
54109 + if a file is being replaced by a rename, new_dentry has the inode
54110 + and name for the replaced file
54111 + */
54112 +
54113 + if (unlikely(!(gr_status & GR_READY)))
54114 + return;
54115 +
54116 + preempt_disable();
54117 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54118 +
54119 + /* we wouldn't have to check d_inode if it weren't for
54120 + NFS silly-renaming
54121 + */
54122 +
54123 + write_lock(&gr_inode_lock);
54124 + if (unlikely(replace && inode)) {
54125 + ino_t new_ino = inode->i_ino;
54126 + dev_t new_dev = __get_dev(new_dentry);
54127 +
54128 + inodev = lookup_inodev_entry(new_ino, new_dev);
54129 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54130 + do_handle_delete(inodev, new_ino, new_dev);
54131 + }
54132 +
54133 + inodev = lookup_inodev_entry(old_ino, old_dev);
54134 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54135 + do_handle_delete(inodev, old_ino, old_dev);
54136 +
54137 + if (unlikely((unsigned long)matchn))
54138 + do_handle_create(matchn, old_dentry, mnt);
54139 +
54140 + write_unlock(&gr_inode_lock);
54141 + preempt_enable();
54142 +
54143 + return;
54144 +}
54145 +
54146 +static int
54147 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54148 + unsigned char **sum)
54149 +{
54150 + struct acl_role_label *r;
54151 + struct role_allowed_ip *ipp;
54152 + struct role_transition *trans;
54153 + unsigned int i;
54154 + int found = 0;
54155 + u32 curr_ip = current->signal->curr_ip;
54156 +
54157 + current->signal->saved_ip = curr_ip;
54158 +
54159 + /* check transition table */
54160 +
54161 + for (trans = current->role->transitions; trans; trans = trans->next) {
54162 + if (!strcmp(rolename, trans->rolename)) {
54163 + found = 1;
54164 + break;
54165 + }
54166 + }
54167 +
54168 + if (!found)
54169 + return 0;
54170 +
54171 + /* handle special roles that do not require authentication
54172 + and check ip */
54173 +
54174 + FOR_EACH_ROLE_START(r)
54175 + if (!strcmp(rolename, r->rolename) &&
54176 + (r->roletype & GR_ROLE_SPECIAL)) {
54177 + found = 0;
54178 + if (r->allowed_ips != NULL) {
54179 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54180 + if ((ntohl(curr_ip) & ipp->netmask) ==
54181 + (ntohl(ipp->addr) & ipp->netmask))
54182 + found = 1;
54183 + }
54184 + } else
54185 + found = 2;
54186 + if (!found)
54187 + return 0;
54188 +
54189 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54190 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54191 + *salt = NULL;
54192 + *sum = NULL;
54193 + return 1;
54194 + }
54195 + }
54196 + FOR_EACH_ROLE_END(r)
54197 +
54198 + for (i = 0; i < num_sprole_pws; i++) {
54199 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54200 + *salt = acl_special_roles[i]->salt;
54201 + *sum = acl_special_roles[i]->sum;
54202 + return 1;
54203 + }
54204 + }
54205 +
54206 + return 0;
54207 +}
54208 +
54209 +static void
54210 +assign_special_role(char *rolename)
54211 +{
54212 + struct acl_object_label *obj;
54213 + struct acl_role_label *r;
54214 + struct acl_role_label *assigned = NULL;
54215 + struct task_struct *tsk;
54216 + struct file *filp;
54217 +
54218 + FOR_EACH_ROLE_START(r)
54219 + if (!strcmp(rolename, r->rolename) &&
54220 + (r->roletype & GR_ROLE_SPECIAL)) {
54221 + assigned = r;
54222 + break;
54223 + }
54224 + FOR_EACH_ROLE_END(r)
54225 +
54226 + if (!assigned)
54227 + return;
54228 +
54229 + read_lock(&tasklist_lock);
54230 + read_lock(&grsec_exec_file_lock);
54231 +
54232 + tsk = current->real_parent;
54233 + if (tsk == NULL)
54234 + goto out_unlock;
54235 +
54236 + filp = tsk->exec_file;
54237 + if (filp == NULL)
54238 + goto out_unlock;
54239 +
54240 + tsk->is_writable = 0;
54241 +
54242 + tsk->acl_sp_role = 1;
54243 + tsk->acl_role_id = ++acl_sp_role_value;
54244 + tsk->role = assigned;
54245 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54246 +
54247 + /* ignore additional mmap checks for processes that are writable
54248 + by the default ACL */
54249 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54250 + if (unlikely(obj->mode & GR_WRITE))
54251 + tsk->is_writable = 1;
54252 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54253 + if (unlikely(obj->mode & GR_WRITE))
54254 + tsk->is_writable = 1;
54255 +
54256 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54257 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54258 +#endif
54259 +
54260 +out_unlock:
54261 + read_unlock(&grsec_exec_file_lock);
54262 + read_unlock(&tasklist_lock);
54263 + return;
54264 +}
54265 +
54266 +int gr_check_secure_terminal(struct task_struct *task)
54267 +{
54268 + struct task_struct *p, *p2, *p3;
54269 + struct files_struct *files;
54270 + struct fdtable *fdt;
54271 + struct file *our_file = NULL, *file;
54272 + int i;
54273 +
54274 + if (task->signal->tty == NULL)
54275 + return 1;
54276 +
54277 + files = get_files_struct(task);
54278 + if (files != NULL) {
54279 + rcu_read_lock();
54280 + fdt = files_fdtable(files);
54281 + for (i=0; i < fdt->max_fds; i++) {
54282 + file = fcheck_files(files, i);
54283 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54284 + get_file(file);
54285 + our_file = file;
54286 + }
54287 + }
54288 + rcu_read_unlock();
54289 + put_files_struct(files);
54290 + }
54291 +
54292 + if (our_file == NULL)
54293 + return 1;
54294 +
54295 + read_lock(&tasklist_lock);
54296 + do_each_thread(p2, p) {
54297 + files = get_files_struct(p);
54298 + if (files == NULL ||
54299 + (p->signal && p->signal->tty == task->signal->tty)) {
54300 + if (files != NULL)
54301 + put_files_struct(files);
54302 + continue;
54303 + }
54304 + rcu_read_lock();
54305 + fdt = files_fdtable(files);
54306 + for (i=0; i < fdt->max_fds; i++) {
54307 + file = fcheck_files(files, i);
54308 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54309 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54310 + p3 = task;
54311 + while (p3->pid > 0) {
54312 + if (p3 == p)
54313 + break;
54314 + p3 = p3->real_parent;
54315 + }
54316 + if (p3 == p)
54317 + break;
54318 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54319 + gr_handle_alertkill(p);
54320 + rcu_read_unlock();
54321 + put_files_struct(files);
54322 + read_unlock(&tasklist_lock);
54323 + fput(our_file);
54324 + return 0;
54325 + }
54326 + }
54327 + rcu_read_unlock();
54328 + put_files_struct(files);
54329 + } while_each_thread(p2, p);
54330 + read_unlock(&tasklist_lock);
54331 +
54332 + fput(our_file);
54333 + return 1;
54334 +}
54335 +
54336 +static int gr_rbac_disable(void *unused)
54337 +{
54338 + pax_open_kernel();
54339 + gr_status &= ~GR_READY;
54340 + pax_close_kernel();
54341 +
54342 + return 0;
54343 +}
54344 +
54345 +ssize_t
54346 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54347 +{
54348 + struct gr_arg_wrapper uwrap;
54349 + unsigned char *sprole_salt = NULL;
54350 + unsigned char *sprole_sum = NULL;
54351 + int error = sizeof (struct gr_arg_wrapper);
54352 + int error2 = 0;
54353 +
54354 + mutex_lock(&gr_dev_mutex);
54355 +
54356 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54357 + error = -EPERM;
54358 + goto out;
54359 + }
54360 +
54361 + if (count != sizeof (struct gr_arg_wrapper)) {
54362 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54363 + error = -EINVAL;
54364 + goto out;
54365 + }
54366 +
54367 +
54368 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54369 + gr_auth_expires = 0;
54370 + gr_auth_attempts = 0;
54371 + }
54372 +
54373 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54374 + error = -EFAULT;
54375 + goto out;
54376 + }
54377 +
54378 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54379 + error = -EINVAL;
54380 + goto out;
54381 + }
54382 +
54383 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54384 + error = -EFAULT;
54385 + goto out;
54386 + }
54387 +
54388 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54389 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54390 + time_after(gr_auth_expires, get_seconds())) {
54391 + error = -EBUSY;
54392 + goto out;
54393 + }
54394 +
54395 + /* if non-root trying to do anything other than use a special role,
54396 + do not attempt authentication, do not count towards authentication
54397 + locking
54398 + */
54399 +
54400 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54401 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54402 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54403 + error = -EPERM;
54404 + goto out;
54405 + }
54406 +
54407 + /* ensure pw and special role name are null terminated */
54408 +
54409 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54410 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54411 +
54412 + /* Okay.
54413 + * We have our enough of the argument structure..(we have yet
54414 + * to copy_from_user the tables themselves) . Copy the tables
54415 + * only if we need them, i.e. for loading operations. */
54416 +
54417 + switch (gr_usermode->mode) {
54418 + case GR_STATUS:
54419 + if (gr_status & GR_READY) {
54420 + error = 1;
54421 + if (!gr_check_secure_terminal(current))
54422 + error = 3;
54423 + } else
54424 + error = 2;
54425 + goto out;
54426 + case GR_SHUTDOWN:
54427 + if ((gr_status & GR_READY)
54428 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54429 + stop_machine(gr_rbac_disable, NULL, NULL);
54430 + free_variables();
54431 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54432 + memset(gr_system_salt, 0, GR_SALT_LEN);
54433 + memset(gr_system_sum, 0, GR_SHA_LEN);
54434 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54435 + } else if (gr_status & GR_READY) {
54436 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54437 + error = -EPERM;
54438 + } else {
54439 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54440 + error = -EAGAIN;
54441 + }
54442 + break;
54443 + case GR_ENABLE:
54444 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54445 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54446 + else {
54447 + if (gr_status & GR_READY)
54448 + error = -EAGAIN;
54449 + else
54450 + error = error2;
54451 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54452 + }
54453 + break;
54454 + case GR_RELOAD:
54455 + if (!(gr_status & GR_READY)) {
54456 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54457 + error = -EAGAIN;
54458 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54459 + stop_machine(gr_rbac_disable, NULL, NULL);
54460 + free_variables();
54461 + error2 = gracl_init(gr_usermode);
54462 + if (!error2)
54463 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54464 + else {
54465 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54466 + error = error2;
54467 + }
54468 + } else {
54469 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54470 + error = -EPERM;
54471 + }
54472 + break;
54473 + case GR_SEGVMOD:
54474 + if (unlikely(!(gr_status & GR_READY))) {
54475 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54476 + error = -EAGAIN;
54477 + break;
54478 + }
54479 +
54480 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54481 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54482 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54483 + struct acl_subject_label *segvacl;
54484 + segvacl =
54485 + lookup_acl_subj_label(gr_usermode->segv_inode,
54486 + gr_usermode->segv_device,
54487 + current->role);
54488 + if (segvacl) {
54489 + segvacl->crashes = 0;
54490 + segvacl->expires = 0;
54491 + }
54492 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54493 + gr_remove_uid(gr_usermode->segv_uid);
54494 + }
54495 + } else {
54496 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54497 + error = -EPERM;
54498 + }
54499 + break;
54500 + case GR_SPROLE:
54501 + case GR_SPROLEPAM:
54502 + if (unlikely(!(gr_status & GR_READY))) {
54503 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54504 + error = -EAGAIN;
54505 + break;
54506 + }
54507 +
54508 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54509 + current->role->expires = 0;
54510 + current->role->auth_attempts = 0;
54511 + }
54512 +
54513 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54514 + time_after(current->role->expires, get_seconds())) {
54515 + error = -EBUSY;
54516 + goto out;
54517 + }
54518 +
54519 + if (lookup_special_role_auth
54520 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54521 + && ((!sprole_salt && !sprole_sum)
54522 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54523 + char *p = "";
54524 + assign_special_role(gr_usermode->sp_role);
54525 + read_lock(&tasklist_lock);
54526 + if (current->real_parent)
54527 + p = current->real_parent->role->rolename;
54528 + read_unlock(&tasklist_lock);
54529 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54530 + p, acl_sp_role_value);
54531 + } else {
54532 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54533 + error = -EPERM;
54534 + if(!(current->role->auth_attempts++))
54535 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54536 +
54537 + goto out;
54538 + }
54539 + break;
54540 + case GR_UNSPROLE:
54541 + if (unlikely(!(gr_status & GR_READY))) {
54542 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54543 + error = -EAGAIN;
54544 + break;
54545 + }
54546 +
54547 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54548 + char *p = "";
54549 + int i = 0;
54550 +
54551 + read_lock(&tasklist_lock);
54552 + if (current->real_parent) {
54553 + p = current->real_parent->role->rolename;
54554 + i = current->real_parent->acl_role_id;
54555 + }
54556 + read_unlock(&tasklist_lock);
54557 +
54558 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54559 + gr_set_acls(1);
54560 + } else {
54561 + error = -EPERM;
54562 + goto out;
54563 + }
54564 + break;
54565 + default:
54566 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54567 + error = -EINVAL;
54568 + break;
54569 + }
54570 +
54571 + if (error != -EPERM)
54572 + goto out;
54573 +
54574 + if(!(gr_auth_attempts++))
54575 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54576 +
54577 + out:
54578 + mutex_unlock(&gr_dev_mutex);
54579 + return error;
54580 +}
54581 +
54582 +/* must be called with
54583 + rcu_read_lock();
54584 + read_lock(&tasklist_lock);
54585 + read_lock(&grsec_exec_file_lock);
54586 +*/
54587 +int gr_apply_subject_to_task(struct task_struct *task)
54588 +{
54589 + struct acl_object_label *obj;
54590 + char *tmpname;
54591 + struct acl_subject_label *tmpsubj;
54592 + struct file *filp;
54593 + struct name_entry *nmatch;
54594 +
54595 + filp = task->exec_file;
54596 + if (filp == NULL)
54597 + return 0;
54598 +
54599 + /* the following is to apply the correct subject
54600 + on binaries running when the RBAC system
54601 + is enabled, when the binaries have been
54602 + replaced or deleted since their execution
54603 + -----
54604 + when the RBAC system starts, the inode/dev
54605 + from exec_file will be one the RBAC system
54606 + is unaware of. It only knows the inode/dev
54607 + of the present file on disk, or the absence
54608 + of it.
54609 + */
54610 + preempt_disable();
54611 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54612 +
54613 + nmatch = lookup_name_entry(tmpname);
54614 + preempt_enable();
54615 + tmpsubj = NULL;
54616 + if (nmatch) {
54617 + if (nmatch->deleted)
54618 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54619 + else
54620 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54621 + if (tmpsubj != NULL)
54622 + task->acl = tmpsubj;
54623 + }
54624 + if (tmpsubj == NULL)
54625 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54626 + task->role);
54627 + if (task->acl) {
54628 + task->is_writable = 0;
54629 + /* ignore additional mmap checks for processes that are writable
54630 + by the default ACL */
54631 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54632 + if (unlikely(obj->mode & GR_WRITE))
54633 + task->is_writable = 1;
54634 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54635 + if (unlikely(obj->mode & GR_WRITE))
54636 + task->is_writable = 1;
54637 +
54638 + gr_set_proc_res(task);
54639 +
54640 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54641 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54642 +#endif
54643 + } else {
54644 + return 1;
54645 + }
54646 +
54647 + return 0;
54648 +}
54649 +
54650 +int
54651 +gr_set_acls(const int type)
54652 +{
54653 + struct task_struct *task, *task2;
54654 + struct acl_role_label *role = current->role;
54655 + __u16 acl_role_id = current->acl_role_id;
54656 + const struct cred *cred;
54657 + int ret;
54658 +
54659 + rcu_read_lock();
54660 + read_lock(&tasklist_lock);
54661 + read_lock(&grsec_exec_file_lock);
54662 + do_each_thread(task2, task) {
54663 + /* check to see if we're called from the exit handler,
54664 + if so, only replace ACLs that have inherited the admin
54665 + ACL */
54666 +
54667 + if (type && (task->role != role ||
54668 + task->acl_role_id != acl_role_id))
54669 + continue;
54670 +
54671 + task->acl_role_id = 0;
54672 + task->acl_sp_role = 0;
54673 +
54674 + if (task->exec_file) {
54675 + cred = __task_cred(task);
54676 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54677 + ret = gr_apply_subject_to_task(task);
54678 + if (ret) {
54679 + read_unlock(&grsec_exec_file_lock);
54680 + read_unlock(&tasklist_lock);
54681 + rcu_read_unlock();
54682 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54683 + return ret;
54684 + }
54685 + } else {
54686 + // it's a kernel process
54687 + task->role = kernel_role;
54688 + task->acl = kernel_role->root_label;
54689 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54690 + task->acl->mode &= ~GR_PROCFIND;
54691 +#endif
54692 + }
54693 + } while_each_thread(task2, task);
54694 + read_unlock(&grsec_exec_file_lock);
54695 + read_unlock(&tasklist_lock);
54696 + rcu_read_unlock();
54697 +
54698 + return 0;
54699 +}
54700 +
54701 +void
54702 +gr_learn_resource(const struct task_struct *task,
54703 + const int res, const unsigned long wanted, const int gt)
54704 +{
54705 + struct acl_subject_label *acl;
54706 + const struct cred *cred;
54707 +
54708 + if (unlikely((gr_status & GR_READY) &&
54709 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54710 + goto skip_reslog;
54711 +
54712 +#ifdef CONFIG_GRKERNSEC_RESLOG
54713 + gr_log_resource(task, res, wanted, gt);
54714 +#endif
54715 + skip_reslog:
54716 +
54717 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54718 + return;
54719 +
54720 + acl = task->acl;
54721 +
54722 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54723 + !(acl->resmask & (1 << (unsigned short) res))))
54724 + return;
54725 +
54726 + if (wanted >= acl->res[res].rlim_cur) {
54727 + unsigned long res_add;
54728 +
54729 + res_add = wanted;
54730 + switch (res) {
54731 + case RLIMIT_CPU:
54732 + res_add += GR_RLIM_CPU_BUMP;
54733 + break;
54734 + case RLIMIT_FSIZE:
54735 + res_add += GR_RLIM_FSIZE_BUMP;
54736 + break;
54737 + case RLIMIT_DATA:
54738 + res_add += GR_RLIM_DATA_BUMP;
54739 + break;
54740 + case RLIMIT_STACK:
54741 + res_add += GR_RLIM_STACK_BUMP;
54742 + break;
54743 + case RLIMIT_CORE:
54744 + res_add += GR_RLIM_CORE_BUMP;
54745 + break;
54746 + case RLIMIT_RSS:
54747 + res_add += GR_RLIM_RSS_BUMP;
54748 + break;
54749 + case RLIMIT_NPROC:
54750 + res_add += GR_RLIM_NPROC_BUMP;
54751 + break;
54752 + case RLIMIT_NOFILE:
54753 + res_add += GR_RLIM_NOFILE_BUMP;
54754 + break;
54755 + case RLIMIT_MEMLOCK:
54756 + res_add += GR_RLIM_MEMLOCK_BUMP;
54757 + break;
54758 + case RLIMIT_AS:
54759 + res_add += GR_RLIM_AS_BUMP;
54760 + break;
54761 + case RLIMIT_LOCKS:
54762 + res_add += GR_RLIM_LOCKS_BUMP;
54763 + break;
54764 + case RLIMIT_SIGPENDING:
54765 + res_add += GR_RLIM_SIGPENDING_BUMP;
54766 + break;
54767 + case RLIMIT_MSGQUEUE:
54768 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54769 + break;
54770 + case RLIMIT_NICE:
54771 + res_add += GR_RLIM_NICE_BUMP;
54772 + break;
54773 + case RLIMIT_RTPRIO:
54774 + res_add += GR_RLIM_RTPRIO_BUMP;
54775 + break;
54776 + case RLIMIT_RTTIME:
54777 + res_add += GR_RLIM_RTTIME_BUMP;
54778 + break;
54779 + }
54780 +
54781 + acl->res[res].rlim_cur = res_add;
54782 +
54783 + if (wanted > acl->res[res].rlim_max)
54784 + acl->res[res].rlim_max = res_add;
54785 +
54786 + /* only log the subject filename, since resource logging is supported for
54787 + single-subject learning only */
54788 + rcu_read_lock();
54789 + cred = __task_cred(task);
54790 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54791 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54792 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54793 + "", (unsigned long) res, &task->signal->saved_ip);
54794 + rcu_read_unlock();
54795 + }
54796 +
54797 + return;
54798 +}
54799 +
54800 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54801 +void
54802 +pax_set_initial_flags(struct linux_binprm *bprm)
54803 +{
54804 + struct task_struct *task = current;
54805 + struct acl_subject_label *proc;
54806 + unsigned long flags;
54807 +
54808 + if (unlikely(!(gr_status & GR_READY)))
54809 + return;
54810 +
54811 + flags = pax_get_flags(task);
54812 +
54813 + proc = task->acl;
54814 +
54815 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54816 + flags &= ~MF_PAX_PAGEEXEC;
54817 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54818 + flags &= ~MF_PAX_SEGMEXEC;
54819 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54820 + flags &= ~MF_PAX_RANDMMAP;
54821 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54822 + flags &= ~MF_PAX_EMUTRAMP;
54823 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54824 + flags &= ~MF_PAX_MPROTECT;
54825 +
54826 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54827 + flags |= MF_PAX_PAGEEXEC;
54828 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54829 + flags |= MF_PAX_SEGMEXEC;
54830 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54831 + flags |= MF_PAX_RANDMMAP;
54832 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54833 + flags |= MF_PAX_EMUTRAMP;
54834 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54835 + flags |= MF_PAX_MPROTECT;
54836 +
54837 + pax_set_flags(task, flags);
54838 +
54839 + return;
54840 +}
54841 +#endif
54842 +
54843 +int
54844 +gr_handle_proc_ptrace(struct task_struct *task)
54845 +{
54846 + struct file *filp;
54847 + struct task_struct *tmp = task;
54848 + struct task_struct *curtemp = current;
54849 + __u32 retmode;
54850 +
54851 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54852 + if (unlikely(!(gr_status & GR_READY)))
54853 + return 0;
54854 +#endif
54855 +
54856 + read_lock(&tasklist_lock);
54857 + read_lock(&grsec_exec_file_lock);
54858 + filp = task->exec_file;
54859 +
54860 + while (tmp->pid > 0) {
54861 + if (tmp == curtemp)
54862 + break;
54863 + tmp = tmp->real_parent;
54864 + }
54865 +
54866 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54867 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54868 + read_unlock(&grsec_exec_file_lock);
54869 + read_unlock(&tasklist_lock);
54870 + return 1;
54871 + }
54872 +
54873 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54874 + if (!(gr_status & GR_READY)) {
54875 + read_unlock(&grsec_exec_file_lock);
54876 + read_unlock(&tasklist_lock);
54877 + return 0;
54878 + }
54879 +#endif
54880 +
54881 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54882 + read_unlock(&grsec_exec_file_lock);
54883 + read_unlock(&tasklist_lock);
54884 +
54885 + if (retmode & GR_NOPTRACE)
54886 + return 1;
54887 +
54888 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54889 + && (current->acl != task->acl || (current->acl != current->role->root_label
54890 + && current->pid != task->pid)))
54891 + return 1;
54892 +
54893 + return 0;
54894 +}
54895 +
54896 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54897 +{
54898 + if (unlikely(!(gr_status & GR_READY)))
54899 + return;
54900 +
54901 + if (!(current->role->roletype & GR_ROLE_GOD))
54902 + return;
54903 +
54904 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54905 + p->role->rolename, gr_task_roletype_to_char(p),
54906 + p->acl->filename);
54907 +}
54908 +
54909 +int
54910 +gr_handle_ptrace(struct task_struct *task, const long request)
54911 +{
54912 + struct task_struct *tmp = task;
54913 + struct task_struct *curtemp = current;
54914 + __u32 retmode;
54915 +
54916 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54917 + if (unlikely(!(gr_status & GR_READY)))
54918 + return 0;
54919 +#endif
54920 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54921 + read_lock(&tasklist_lock);
54922 + while (tmp->pid > 0) {
54923 + if (tmp == curtemp)
54924 + break;
54925 + tmp = tmp->real_parent;
54926 + }
54927 +
54928 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54929 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54930 + read_unlock(&tasklist_lock);
54931 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54932 + return 1;
54933 + }
54934 + read_unlock(&tasklist_lock);
54935 + }
54936 +
54937 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54938 + if (!(gr_status & GR_READY))
54939 + return 0;
54940 +#endif
54941 +
54942 + read_lock(&grsec_exec_file_lock);
54943 + if (unlikely(!task->exec_file)) {
54944 + read_unlock(&grsec_exec_file_lock);
54945 + return 0;
54946 + }
54947 +
54948 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54949 + read_unlock(&grsec_exec_file_lock);
54950 +
54951 + if (retmode & GR_NOPTRACE) {
54952 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54953 + return 1;
54954 + }
54955 +
54956 + if (retmode & GR_PTRACERD) {
54957 + switch (request) {
54958 + case PTRACE_SEIZE:
54959 + case PTRACE_POKETEXT:
54960 + case PTRACE_POKEDATA:
54961 + case PTRACE_POKEUSR:
54962 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54963 + case PTRACE_SETREGS:
54964 + case PTRACE_SETFPREGS:
54965 +#endif
54966 +#ifdef CONFIG_X86
54967 + case PTRACE_SETFPXREGS:
54968 +#endif
54969 +#ifdef CONFIG_ALTIVEC
54970 + case PTRACE_SETVRREGS:
54971 +#endif
54972 + return 1;
54973 + default:
54974 + return 0;
54975 + }
54976 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54977 + !(current->role->roletype & GR_ROLE_GOD) &&
54978 + (current->acl != task->acl)) {
54979 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54980 + return 1;
54981 + }
54982 +
54983 + return 0;
54984 +}
54985 +
54986 +static int is_writable_mmap(const struct file *filp)
54987 +{
54988 + struct task_struct *task = current;
54989 + struct acl_object_label *obj, *obj2;
54990 +
54991 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54992 + !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))) {
54993 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54994 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54995 + task->role->root_label);
54996 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54997 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54998 + return 1;
54999 + }
55000 + }
55001 + return 0;
55002 +}
55003 +
55004 +int
55005 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55006 +{
55007 + __u32 mode;
55008 +
55009 + if (unlikely(!file || !(prot & PROT_EXEC)))
55010 + return 1;
55011 +
55012 + if (is_writable_mmap(file))
55013 + return 0;
55014 +
55015 + mode =
55016 + gr_search_file(file->f_path.dentry,
55017 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55018 + file->f_path.mnt);
55019 +
55020 + if (!gr_tpe_allow(file))
55021 + return 0;
55022 +
55023 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55024 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55025 + return 0;
55026 + } else if (unlikely(!(mode & GR_EXEC))) {
55027 + return 0;
55028 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55029 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55030 + return 1;
55031 + }
55032 +
55033 + return 1;
55034 +}
55035 +
55036 +int
55037 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55038 +{
55039 + __u32 mode;
55040 +
55041 + if (unlikely(!file || !(prot & PROT_EXEC)))
55042 + return 1;
55043 +
55044 + if (is_writable_mmap(file))
55045 + return 0;
55046 +
55047 + mode =
55048 + gr_search_file(file->f_path.dentry,
55049 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55050 + file->f_path.mnt);
55051 +
55052 + if (!gr_tpe_allow(file))
55053 + return 0;
55054 +
55055 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55056 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55057 + return 0;
55058 + } else if (unlikely(!(mode & GR_EXEC))) {
55059 + return 0;
55060 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55061 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55062 + return 1;
55063 + }
55064 +
55065 + return 1;
55066 +}
55067 +
55068 +void
55069 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55070 +{
55071 + unsigned long runtime;
55072 + unsigned long cputime;
55073 + unsigned int wday, cday;
55074 + __u8 whr, chr;
55075 + __u8 wmin, cmin;
55076 + __u8 wsec, csec;
55077 + struct timespec timeval;
55078 +
55079 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55080 + !(task->acl->mode & GR_PROCACCT)))
55081 + return;
55082 +
55083 + do_posix_clock_monotonic_gettime(&timeval);
55084 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55085 + wday = runtime / (3600 * 24);
55086 + runtime -= wday * (3600 * 24);
55087 + whr = runtime / 3600;
55088 + runtime -= whr * 3600;
55089 + wmin = runtime / 60;
55090 + runtime -= wmin * 60;
55091 + wsec = runtime;
55092 +
55093 + cputime = (task->utime + task->stime) / HZ;
55094 + cday = cputime / (3600 * 24);
55095 + cputime -= cday * (3600 * 24);
55096 + chr = cputime / 3600;
55097 + cputime -= chr * 3600;
55098 + cmin = cputime / 60;
55099 + cputime -= cmin * 60;
55100 + csec = cputime;
55101 +
55102 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55103 +
55104 + return;
55105 +}
55106 +
55107 +void gr_set_kernel_label(struct task_struct *task)
55108 +{
55109 + if (gr_status & GR_READY) {
55110 + task->role = kernel_role;
55111 + task->acl = kernel_role->root_label;
55112 + }
55113 + return;
55114 +}
55115 +
55116 +#ifdef CONFIG_TASKSTATS
55117 +int gr_is_taskstats_denied(int pid)
55118 +{
55119 + struct task_struct *task;
55120 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55121 + const struct cred *cred;
55122 +#endif
55123 + int ret = 0;
55124 +
55125 + /* restrict taskstats viewing to un-chrooted root users
55126 + who have the 'view' subject flag if the RBAC system is enabled
55127 + */
55128 +
55129 + rcu_read_lock();
55130 + read_lock(&tasklist_lock);
55131 + task = find_task_by_vpid(pid);
55132 + if (task) {
55133 +#ifdef CONFIG_GRKERNSEC_CHROOT
55134 + if (proc_is_chrooted(task))
55135 + ret = -EACCES;
55136 +#endif
55137 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55138 + cred = __task_cred(task);
55139 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55140 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55141 + ret = -EACCES;
55142 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55143 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55144 + ret = -EACCES;
55145 +#endif
55146 +#endif
55147 + if (gr_status & GR_READY) {
55148 + if (!(task->acl->mode & GR_VIEW))
55149 + ret = -EACCES;
55150 + }
55151 + } else
55152 + ret = -ENOENT;
55153 +
55154 + read_unlock(&tasklist_lock);
55155 + rcu_read_unlock();
55156 +
55157 + return ret;
55158 +}
55159 +#endif
55160 +
55161 +/* AUXV entries are filled via a descendant of search_binary_handler
55162 + after we've already applied the subject for the target
55163 +*/
55164 +int gr_acl_enable_at_secure(void)
55165 +{
55166 + if (unlikely(!(gr_status & GR_READY)))
55167 + return 0;
55168 +
55169 + if (current->acl->mode & GR_ATSECURE)
55170 + return 1;
55171 +
55172 + return 0;
55173 +}
55174 +
55175 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55176 +{
55177 + struct task_struct *task = current;
55178 + struct dentry *dentry = file->f_path.dentry;
55179 + struct vfsmount *mnt = file->f_path.mnt;
55180 + struct acl_object_label *obj, *tmp;
55181 + struct acl_subject_label *subj;
55182 + unsigned int bufsize;
55183 + int is_not_root;
55184 + char *path;
55185 + dev_t dev = __get_dev(dentry);
55186 +
55187 + if (unlikely(!(gr_status & GR_READY)))
55188 + return 1;
55189 +
55190 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55191 + return 1;
55192 +
55193 + /* ignore Eric Biederman */
55194 + if (IS_PRIVATE(dentry->d_inode))
55195 + return 1;
55196 +
55197 + subj = task->acl;
55198 + read_lock(&gr_inode_lock);
55199 + do {
55200 + obj = lookup_acl_obj_label(ino, dev, subj);
55201 + if (obj != NULL) {
55202 + read_unlock(&gr_inode_lock);
55203 + return (obj->mode & GR_FIND) ? 1 : 0;
55204 + }
55205 + } while ((subj = subj->parent_subject));
55206 + read_unlock(&gr_inode_lock);
55207 +
55208 + /* this is purely an optimization since we're looking for an object
55209 + for the directory we're doing a readdir on
55210 + if it's possible for any globbed object to match the entry we're
55211 + filling into the directory, then the object we find here will be
55212 + an anchor point with attached globbed objects
55213 + */
55214 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55215 + if (obj->globbed == NULL)
55216 + return (obj->mode & GR_FIND) ? 1 : 0;
55217 +
55218 + is_not_root = ((obj->filename[0] == '/') &&
55219 + (obj->filename[1] == '\0')) ? 0 : 1;
55220 + bufsize = PAGE_SIZE - namelen - is_not_root;
55221 +
55222 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55223 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55224 + return 1;
55225 +
55226 + preempt_disable();
55227 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55228 + bufsize);
55229 +
55230 + bufsize = strlen(path);
55231 +
55232 + /* if base is "/", don't append an additional slash */
55233 + if (is_not_root)
55234 + *(path + bufsize) = '/';
55235 + memcpy(path + bufsize + is_not_root, name, namelen);
55236 + *(path + bufsize + namelen + is_not_root) = '\0';
55237 +
55238 + tmp = obj->globbed;
55239 + while (tmp) {
55240 + if (!glob_match(tmp->filename, path)) {
55241 + preempt_enable();
55242 + return (tmp->mode & GR_FIND) ? 1 : 0;
55243 + }
55244 + tmp = tmp->next;
55245 + }
55246 + preempt_enable();
55247 + return (obj->mode & GR_FIND) ? 1 : 0;
55248 +}
55249 +
55250 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55251 +EXPORT_SYMBOL(gr_acl_is_enabled);
55252 +#endif
55253 +EXPORT_SYMBOL(gr_learn_resource);
55254 +EXPORT_SYMBOL(gr_set_kernel_label);
55255 +#ifdef CONFIG_SECURITY
55256 +EXPORT_SYMBOL(gr_check_user_change);
55257 +EXPORT_SYMBOL(gr_check_group_change);
55258 +#endif
55259 +
55260 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55261 new file mode 100644
55262 index 0000000..34fefda
55263 --- /dev/null
55264 +++ b/grsecurity/gracl_alloc.c
55265 @@ -0,0 +1,105 @@
55266 +#include <linux/kernel.h>
55267 +#include <linux/mm.h>
55268 +#include <linux/slab.h>
55269 +#include <linux/vmalloc.h>
55270 +#include <linux/gracl.h>
55271 +#include <linux/grsecurity.h>
55272 +
55273 +static unsigned long alloc_stack_next = 1;
55274 +static unsigned long alloc_stack_size = 1;
55275 +static void **alloc_stack;
55276 +
55277 +static __inline__ int
55278 +alloc_pop(void)
55279 +{
55280 + if (alloc_stack_next == 1)
55281 + return 0;
55282 +
55283 + kfree(alloc_stack[alloc_stack_next - 2]);
55284 +
55285 + alloc_stack_next--;
55286 +
55287 + return 1;
55288 +}
55289 +
55290 +static __inline__ int
55291 +alloc_push(void *buf)
55292 +{
55293 + if (alloc_stack_next >= alloc_stack_size)
55294 + return 1;
55295 +
55296 + alloc_stack[alloc_stack_next - 1] = buf;
55297 +
55298 + alloc_stack_next++;
55299 +
55300 + return 0;
55301 +}
55302 +
55303 +void *
55304 +acl_alloc(unsigned long len)
55305 +{
55306 + void *ret = NULL;
55307 +
55308 + if (!len || len > PAGE_SIZE)
55309 + goto out;
55310 +
55311 + ret = kmalloc(len, GFP_KERNEL);
55312 +
55313 + if (ret) {
55314 + if (alloc_push(ret)) {
55315 + kfree(ret);
55316 + ret = NULL;
55317 + }
55318 + }
55319 +
55320 +out:
55321 + return ret;
55322 +}
55323 +
55324 +void *
55325 +acl_alloc_num(unsigned long num, unsigned long len)
55326 +{
55327 + if (!len || (num > (PAGE_SIZE / len)))
55328 + return NULL;
55329 +
55330 + return acl_alloc(num * len);
55331 +}
55332 +
55333 +void
55334 +acl_free_all(void)
55335 +{
55336 + if (gr_acl_is_enabled() || !alloc_stack)
55337 + return;
55338 +
55339 + while (alloc_pop()) ;
55340 +
55341 + if (alloc_stack) {
55342 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55343 + kfree(alloc_stack);
55344 + else
55345 + vfree(alloc_stack);
55346 + }
55347 +
55348 + alloc_stack = NULL;
55349 + alloc_stack_size = 1;
55350 + alloc_stack_next = 1;
55351 +
55352 + return;
55353 +}
55354 +
55355 +int
55356 +acl_alloc_stack_init(unsigned long size)
55357 +{
55358 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55359 + alloc_stack =
55360 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55361 + else
55362 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55363 +
55364 + alloc_stack_size = size;
55365 +
55366 + if (!alloc_stack)
55367 + return 0;
55368 + else
55369 + return 1;
55370 +}
55371 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55372 new file mode 100644
55373 index 0000000..6d21049
55374 --- /dev/null
55375 +++ b/grsecurity/gracl_cap.c
55376 @@ -0,0 +1,110 @@
55377 +#include <linux/kernel.h>
55378 +#include <linux/module.h>
55379 +#include <linux/sched.h>
55380 +#include <linux/gracl.h>
55381 +#include <linux/grsecurity.h>
55382 +#include <linux/grinternal.h>
55383 +
55384 +extern const char *captab_log[];
55385 +extern int captab_log_entries;
55386 +
55387 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55388 +{
55389 + struct acl_subject_label *curracl;
55390 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55391 + kernel_cap_t cap_audit = __cap_empty_set;
55392 +
55393 + if (!gr_acl_is_enabled())
55394 + return 1;
55395 +
55396 + curracl = task->acl;
55397 +
55398 + cap_drop = curracl->cap_lower;
55399 + cap_mask = curracl->cap_mask;
55400 + cap_audit = curracl->cap_invert_audit;
55401 +
55402 + while ((curracl = curracl->parent_subject)) {
55403 + /* if the cap isn't specified in the current computed mask but is specified in the
55404 + current level subject, and is lowered in the current level subject, then add
55405 + it to the set of dropped capabilities
55406 + otherwise, add the current level subject's mask to the current computed mask
55407 + */
55408 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55409 + cap_raise(cap_mask, cap);
55410 + if (cap_raised(curracl->cap_lower, cap))
55411 + cap_raise(cap_drop, cap);
55412 + if (cap_raised(curracl->cap_invert_audit, cap))
55413 + cap_raise(cap_audit, cap);
55414 + }
55415 + }
55416 +
55417 + if (!cap_raised(cap_drop, cap)) {
55418 + if (cap_raised(cap_audit, cap))
55419 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55420 + return 1;
55421 + }
55422 +
55423 + curracl = task->acl;
55424 +
55425 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55426 + && cap_raised(cred->cap_effective, cap)) {
55427 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55428 + task->role->roletype, cred->uid,
55429 + cred->gid, task->exec_file ?
55430 + gr_to_filename(task->exec_file->f_path.dentry,
55431 + task->exec_file->f_path.mnt) : curracl->filename,
55432 + curracl->filename, 0UL,
55433 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55434 + return 1;
55435 + }
55436 +
55437 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55438 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55439 +
55440 + return 0;
55441 +}
55442 +
55443 +int
55444 +gr_acl_is_capable(const int cap)
55445 +{
55446 + return gr_task_acl_is_capable(current, current_cred(), cap);
55447 +}
55448 +
55449 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55450 +{
55451 + struct acl_subject_label *curracl;
55452 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55453 +
55454 + if (!gr_acl_is_enabled())
55455 + return 1;
55456 +
55457 + curracl = task->acl;
55458 +
55459 + cap_drop = curracl->cap_lower;
55460 + cap_mask = curracl->cap_mask;
55461 +
55462 + while ((curracl = curracl->parent_subject)) {
55463 + /* if the cap isn't specified in the current computed mask but is specified in the
55464 + current level subject, and is lowered in the current level subject, then add
55465 + it to the set of dropped capabilities
55466 + otherwise, add the current level subject's mask to the current computed mask
55467 + */
55468 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55469 + cap_raise(cap_mask, cap);
55470 + if (cap_raised(curracl->cap_lower, cap))
55471 + cap_raise(cap_drop, cap);
55472 + }
55473 + }
55474 +
55475 + if (!cap_raised(cap_drop, cap))
55476 + return 1;
55477 +
55478 + return 0;
55479 +}
55480 +
55481 +int
55482 +gr_acl_is_capable_nolog(const int cap)
55483 +{
55484 + return gr_task_acl_is_capable_nolog(current, cap);
55485 +}
55486 +
55487 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55488 new file mode 100644
55489 index 0000000..d28e241
55490 --- /dev/null
55491 +++ b/grsecurity/gracl_fs.c
55492 @@ -0,0 +1,437 @@
55493 +#include <linux/kernel.h>
55494 +#include <linux/sched.h>
55495 +#include <linux/types.h>
55496 +#include <linux/fs.h>
55497 +#include <linux/file.h>
55498 +#include <linux/stat.h>
55499 +#include <linux/grsecurity.h>
55500 +#include <linux/grinternal.h>
55501 +#include <linux/gracl.h>
55502 +
55503 +umode_t
55504 +gr_acl_umask(void)
55505 +{
55506 + if (unlikely(!gr_acl_is_enabled()))
55507 + return 0;
55508 +
55509 + return current->role->umask;
55510 +}
55511 +
55512 +__u32
55513 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55514 + const struct vfsmount * mnt)
55515 +{
55516 + __u32 mode;
55517 +
55518 + if (unlikely(!dentry->d_inode))
55519 + return GR_FIND;
55520 +
55521 + mode =
55522 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55523 +
55524 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55525 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55526 + return mode;
55527 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55528 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55529 + return 0;
55530 + } else if (unlikely(!(mode & GR_FIND)))
55531 + return 0;
55532 +
55533 + return GR_FIND;
55534 +}
55535 +
55536 +__u32
55537 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55538 + int acc_mode)
55539 +{
55540 + __u32 reqmode = GR_FIND;
55541 + __u32 mode;
55542 +
55543 + if (unlikely(!dentry->d_inode))
55544 + return reqmode;
55545 +
55546 + if (acc_mode & MAY_APPEND)
55547 + reqmode |= GR_APPEND;
55548 + else if (acc_mode & MAY_WRITE)
55549 + reqmode |= GR_WRITE;
55550 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55551 + reqmode |= GR_READ;
55552 +
55553 + mode =
55554 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55555 + mnt);
55556 +
55557 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55558 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55559 + reqmode & GR_READ ? " reading" : "",
55560 + reqmode & GR_WRITE ? " writing" : reqmode &
55561 + GR_APPEND ? " appending" : "");
55562 + return reqmode;
55563 + } else
55564 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55565 + {
55566 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55567 + reqmode & GR_READ ? " reading" : "",
55568 + reqmode & GR_WRITE ? " writing" : reqmode &
55569 + GR_APPEND ? " appending" : "");
55570 + return 0;
55571 + } else if (unlikely((mode & reqmode) != reqmode))
55572 + return 0;
55573 +
55574 + return reqmode;
55575 +}
55576 +
55577 +__u32
55578 +gr_acl_handle_creat(const struct dentry * dentry,
55579 + const struct dentry * p_dentry,
55580 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55581 + const int imode)
55582 +{
55583 + __u32 reqmode = GR_WRITE | GR_CREATE;
55584 + __u32 mode;
55585 +
55586 + if (acc_mode & MAY_APPEND)
55587 + reqmode |= GR_APPEND;
55588 + // if a directory was required or the directory already exists, then
55589 + // don't count this open as a read
55590 + if ((acc_mode & MAY_READ) &&
55591 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55592 + reqmode |= GR_READ;
55593 + if ((open_flags & O_CREAT) &&
55594 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55595 + reqmode |= GR_SETID;
55596 +
55597 + mode =
55598 + gr_check_create(dentry, p_dentry, p_mnt,
55599 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55600 +
55601 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55602 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55603 + reqmode & GR_READ ? " reading" : "",
55604 + reqmode & GR_WRITE ? " writing" : reqmode &
55605 + GR_APPEND ? " appending" : "");
55606 + return reqmode;
55607 + } else
55608 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55609 + {
55610 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55611 + reqmode & GR_READ ? " reading" : "",
55612 + reqmode & GR_WRITE ? " writing" : reqmode &
55613 + GR_APPEND ? " appending" : "");
55614 + return 0;
55615 + } else if (unlikely((mode & reqmode) != reqmode))
55616 + return 0;
55617 +
55618 + return reqmode;
55619 +}
55620 +
55621 +__u32
55622 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55623 + const int fmode)
55624 +{
55625 + __u32 mode, reqmode = GR_FIND;
55626 +
55627 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55628 + reqmode |= GR_EXEC;
55629 + if (fmode & S_IWOTH)
55630 + reqmode |= GR_WRITE;
55631 + if (fmode & S_IROTH)
55632 + reqmode |= GR_READ;
55633 +
55634 + mode =
55635 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55636 + mnt);
55637 +
55638 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55639 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55640 + reqmode & GR_READ ? " reading" : "",
55641 + reqmode & GR_WRITE ? " writing" : "",
55642 + reqmode & GR_EXEC ? " executing" : "");
55643 + return reqmode;
55644 + } else
55645 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55646 + {
55647 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55648 + reqmode & GR_READ ? " reading" : "",
55649 + reqmode & GR_WRITE ? " writing" : "",
55650 + reqmode & GR_EXEC ? " executing" : "");
55651 + return 0;
55652 + } else if (unlikely((mode & reqmode) != reqmode))
55653 + return 0;
55654 +
55655 + return reqmode;
55656 +}
55657 +
55658 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55659 +{
55660 + __u32 mode;
55661 +
55662 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55663 +
55664 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55665 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55666 + return mode;
55667 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55668 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55669 + return 0;
55670 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55671 + return 0;
55672 +
55673 + return (reqmode);
55674 +}
55675 +
55676 +__u32
55677 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55678 +{
55679 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55680 +}
55681 +
55682 +__u32
55683 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55684 +{
55685 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55686 +}
55687 +
55688 +__u32
55689 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55690 +{
55691 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55692 +}
55693 +
55694 +__u32
55695 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55696 +{
55697 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55698 +}
55699 +
55700 +__u32
55701 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55702 + umode_t *modeptr)
55703 +{
55704 + umode_t mode;
55705 +
55706 + *modeptr &= ~gr_acl_umask();
55707 + mode = *modeptr;
55708 +
55709 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55710 + return 1;
55711 +
55712 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
55713 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
55714 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55715 + GR_CHMOD_ACL_MSG);
55716 + } else {
55717 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55718 + }
55719 +}
55720 +
55721 +__u32
55722 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55723 +{
55724 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55725 +}
55726 +
55727 +__u32
55728 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55729 +{
55730 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55731 +}
55732 +
55733 +__u32
55734 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55735 +{
55736 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55737 +}
55738 +
55739 +__u32
55740 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55741 +{
55742 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55743 + GR_UNIXCONNECT_ACL_MSG);
55744 +}
55745 +
55746 +/* hardlinks require at minimum create and link permission,
55747 + any additional privilege required is based on the
55748 + privilege of the file being linked to
55749 +*/
55750 +__u32
55751 +gr_acl_handle_link(const struct dentry * new_dentry,
55752 + const struct dentry * parent_dentry,
55753 + const struct vfsmount * parent_mnt,
55754 + const struct dentry * old_dentry,
55755 + const struct vfsmount * old_mnt, const char *to)
55756 +{
55757 + __u32 mode;
55758 + __u32 needmode = GR_CREATE | GR_LINK;
55759 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55760 +
55761 + mode =
55762 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55763 + old_mnt);
55764 +
55765 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55766 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55767 + return mode;
55768 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55769 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55770 + return 0;
55771 + } else if (unlikely((mode & needmode) != needmode))
55772 + return 0;
55773 +
55774 + return 1;
55775 +}
55776 +
55777 +__u32
55778 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55779 + const struct dentry * parent_dentry,
55780 + const struct vfsmount * parent_mnt, const char *from)
55781 +{
55782 + __u32 needmode = GR_WRITE | GR_CREATE;
55783 + __u32 mode;
55784 +
55785 + mode =
55786 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55787 + GR_CREATE | GR_AUDIT_CREATE |
55788 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55789 +
55790 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55791 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55792 + return mode;
55793 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55794 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55795 + return 0;
55796 + } else if (unlikely((mode & needmode) != needmode))
55797 + return 0;
55798 +
55799 + return (GR_WRITE | GR_CREATE);
55800 +}
55801 +
55802 +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)
55803 +{
55804 + __u32 mode;
55805 +
55806 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55807 +
55808 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55809 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55810 + return mode;
55811 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55812 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55813 + return 0;
55814 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55815 + return 0;
55816 +
55817 + return (reqmode);
55818 +}
55819 +
55820 +__u32
55821 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55822 + const struct dentry * parent_dentry,
55823 + const struct vfsmount * parent_mnt,
55824 + const int mode)
55825 +{
55826 + __u32 reqmode = GR_WRITE | GR_CREATE;
55827 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55828 + reqmode |= GR_SETID;
55829 +
55830 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55831 + reqmode, GR_MKNOD_ACL_MSG);
55832 +}
55833 +
55834 +__u32
55835 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55836 + const struct dentry *parent_dentry,
55837 + const struct vfsmount *parent_mnt)
55838 +{
55839 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55840 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55841 +}
55842 +
55843 +#define RENAME_CHECK_SUCCESS(old, new) \
55844 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55845 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55846 +
55847 +int
55848 +gr_acl_handle_rename(struct dentry *new_dentry,
55849 + struct dentry *parent_dentry,
55850 + const struct vfsmount *parent_mnt,
55851 + struct dentry *old_dentry,
55852 + struct inode *old_parent_inode,
55853 + struct vfsmount *old_mnt, const char *newname)
55854 +{
55855 + __u32 comp1, comp2;
55856 + int error = 0;
55857 +
55858 + if (unlikely(!gr_acl_is_enabled()))
55859 + return 0;
55860 +
55861 + if (!new_dentry->d_inode) {
55862 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55863 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55864 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55865 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55866 + GR_DELETE | GR_AUDIT_DELETE |
55867 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55868 + GR_SUPPRESS, old_mnt);
55869 + } else {
55870 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55871 + GR_CREATE | GR_DELETE |
55872 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55873 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55874 + GR_SUPPRESS, parent_mnt);
55875 + comp2 =
55876 + gr_search_file(old_dentry,
55877 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55878 + GR_DELETE | GR_AUDIT_DELETE |
55879 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55880 + }
55881 +
55882 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55883 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55884 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55885 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55886 + && !(comp2 & GR_SUPPRESS)) {
55887 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55888 + error = -EACCES;
55889 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55890 + error = -EACCES;
55891 +
55892 + return error;
55893 +}
55894 +
55895 +void
55896 +gr_acl_handle_exit(void)
55897 +{
55898 + u16 id;
55899 + char *rolename;
55900 + struct file *exec_file;
55901 +
55902 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55903 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55904 + id = current->acl_role_id;
55905 + rolename = current->role->rolename;
55906 + gr_set_acls(1);
55907 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55908 + }
55909 +
55910 + write_lock(&grsec_exec_file_lock);
55911 + exec_file = current->exec_file;
55912 + current->exec_file = NULL;
55913 + write_unlock(&grsec_exec_file_lock);
55914 +
55915 + if (exec_file)
55916 + fput(exec_file);
55917 +}
55918 +
55919 +int
55920 +gr_acl_handle_procpidmem(const struct task_struct *task)
55921 +{
55922 + if (unlikely(!gr_acl_is_enabled()))
55923 + return 0;
55924 +
55925 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55926 + return -EACCES;
55927 +
55928 + return 0;
55929 +}
55930 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55931 new file mode 100644
55932 index 0000000..58800a7
55933 --- /dev/null
55934 +++ b/grsecurity/gracl_ip.c
55935 @@ -0,0 +1,384 @@
55936 +#include <linux/kernel.h>
55937 +#include <asm/uaccess.h>
55938 +#include <asm/errno.h>
55939 +#include <net/sock.h>
55940 +#include <linux/file.h>
55941 +#include <linux/fs.h>
55942 +#include <linux/net.h>
55943 +#include <linux/in.h>
55944 +#include <linux/skbuff.h>
55945 +#include <linux/ip.h>
55946 +#include <linux/udp.h>
55947 +#include <linux/types.h>
55948 +#include <linux/sched.h>
55949 +#include <linux/netdevice.h>
55950 +#include <linux/inetdevice.h>
55951 +#include <linux/gracl.h>
55952 +#include <linux/grsecurity.h>
55953 +#include <linux/grinternal.h>
55954 +
55955 +#define GR_BIND 0x01
55956 +#define GR_CONNECT 0x02
55957 +#define GR_INVERT 0x04
55958 +#define GR_BINDOVERRIDE 0x08
55959 +#define GR_CONNECTOVERRIDE 0x10
55960 +#define GR_SOCK_FAMILY 0x20
55961 +
55962 +static const char * gr_protocols[IPPROTO_MAX] = {
55963 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55964 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55965 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55966 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55967 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55968 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55969 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55970 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55971 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55972 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55973 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55974 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55975 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55976 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55977 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55978 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55979 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55980 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55981 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55982 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55983 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55984 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55985 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55986 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55987 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55988 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55989 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55990 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55991 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55992 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55993 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55994 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55995 + };
55996 +
55997 +static const char * gr_socktypes[SOCK_MAX] = {
55998 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55999 + "unknown:7", "unknown:8", "unknown:9", "packet"
56000 + };
56001 +
56002 +static const char * gr_sockfamilies[AF_MAX+1] = {
56003 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56004 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56005 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56006 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56007 + };
56008 +
56009 +const char *
56010 +gr_proto_to_name(unsigned char proto)
56011 +{
56012 + return gr_protocols[proto];
56013 +}
56014 +
56015 +const char *
56016 +gr_socktype_to_name(unsigned char type)
56017 +{
56018 + return gr_socktypes[type];
56019 +}
56020 +
56021 +const char *
56022 +gr_sockfamily_to_name(unsigned char family)
56023 +{
56024 + return gr_sockfamilies[family];
56025 +}
56026 +
56027 +int
56028 +gr_search_socket(const int domain, const int type, const int protocol)
56029 +{
56030 + struct acl_subject_label *curr;
56031 + const struct cred *cred = current_cred();
56032 +
56033 + if (unlikely(!gr_acl_is_enabled()))
56034 + goto exit;
56035 +
56036 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56037 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56038 + goto exit; // let the kernel handle it
56039 +
56040 + curr = current->acl;
56041 +
56042 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56043 + /* the family is allowed, if this is PF_INET allow it only if
56044 + the extra sock type/protocol checks pass */
56045 + if (domain == PF_INET)
56046 + goto inet_check;
56047 + goto exit;
56048 + } else {
56049 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56050 + __u32 fakeip = 0;
56051 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56052 + current->role->roletype, cred->uid,
56053 + cred->gid, current->exec_file ?
56054 + gr_to_filename(current->exec_file->f_path.dentry,
56055 + current->exec_file->f_path.mnt) :
56056 + curr->filename, curr->filename,
56057 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56058 + &current->signal->saved_ip);
56059 + goto exit;
56060 + }
56061 + goto exit_fail;
56062 + }
56063 +
56064 +inet_check:
56065 + /* the rest of this checking is for IPv4 only */
56066 + if (!curr->ips)
56067 + goto exit;
56068 +
56069 + if ((curr->ip_type & (1 << type)) &&
56070 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56071 + goto exit;
56072 +
56073 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56074 + /* we don't place acls on raw sockets , and sometimes
56075 + dgram/ip sockets are opened for ioctl and not
56076 + bind/connect, so we'll fake a bind learn log */
56077 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56078 + __u32 fakeip = 0;
56079 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56080 + current->role->roletype, cred->uid,
56081 + cred->gid, current->exec_file ?
56082 + gr_to_filename(current->exec_file->f_path.dentry,
56083 + current->exec_file->f_path.mnt) :
56084 + curr->filename, curr->filename,
56085 + &fakeip, 0, type,
56086 + protocol, GR_CONNECT, &current->signal->saved_ip);
56087 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56088 + __u32 fakeip = 0;
56089 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56090 + current->role->roletype, cred->uid,
56091 + cred->gid, current->exec_file ?
56092 + gr_to_filename(current->exec_file->f_path.dentry,
56093 + current->exec_file->f_path.mnt) :
56094 + curr->filename, curr->filename,
56095 + &fakeip, 0, type,
56096 + protocol, GR_BIND, &current->signal->saved_ip);
56097 + }
56098 + /* we'll log when they use connect or bind */
56099 + goto exit;
56100 + }
56101 +
56102 +exit_fail:
56103 + if (domain == PF_INET)
56104 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56105 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56106 + else
56107 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56108 + gr_socktype_to_name(type), protocol);
56109 +
56110 + return 0;
56111 +exit:
56112 + return 1;
56113 +}
56114 +
56115 +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)
56116 +{
56117 + if ((ip->mode & mode) &&
56118 + (ip_port >= ip->low) &&
56119 + (ip_port <= ip->high) &&
56120 + ((ntohl(ip_addr) & our_netmask) ==
56121 + (ntohl(our_addr) & our_netmask))
56122 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56123 + && (ip->type & (1 << type))) {
56124 + if (ip->mode & GR_INVERT)
56125 + return 2; // specifically denied
56126 + else
56127 + return 1; // allowed
56128 + }
56129 +
56130 + return 0; // not specifically allowed, may continue parsing
56131 +}
56132 +
56133 +static int
56134 +gr_search_connectbind(const int full_mode, struct sock *sk,
56135 + struct sockaddr_in *addr, const int type)
56136 +{
56137 + char iface[IFNAMSIZ] = {0};
56138 + struct acl_subject_label *curr;
56139 + struct acl_ip_label *ip;
56140 + struct inet_sock *isk;
56141 + struct net_device *dev;
56142 + struct in_device *idev;
56143 + unsigned long i;
56144 + int ret;
56145 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56146 + __u32 ip_addr = 0;
56147 + __u32 our_addr;
56148 + __u32 our_netmask;
56149 + char *p;
56150 + __u16 ip_port = 0;
56151 + const struct cred *cred = current_cred();
56152 +
56153 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56154 + return 0;
56155 +
56156 + curr = current->acl;
56157 + isk = inet_sk(sk);
56158 +
56159 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56160 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56161 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56162 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56163 + struct sockaddr_in saddr;
56164 + int err;
56165 +
56166 + saddr.sin_family = AF_INET;
56167 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56168 + saddr.sin_port = isk->inet_sport;
56169 +
56170 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56171 + if (err)
56172 + return err;
56173 +
56174 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56175 + if (err)
56176 + return err;
56177 + }
56178 +
56179 + if (!curr->ips)
56180 + return 0;
56181 +
56182 + ip_addr = addr->sin_addr.s_addr;
56183 + ip_port = ntohs(addr->sin_port);
56184 +
56185 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56186 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56187 + current->role->roletype, cred->uid,
56188 + cred->gid, current->exec_file ?
56189 + gr_to_filename(current->exec_file->f_path.dentry,
56190 + current->exec_file->f_path.mnt) :
56191 + curr->filename, curr->filename,
56192 + &ip_addr, ip_port, type,
56193 + sk->sk_protocol, mode, &current->signal->saved_ip);
56194 + return 0;
56195 + }
56196 +
56197 + for (i = 0; i < curr->ip_num; i++) {
56198 + ip = *(curr->ips + i);
56199 + if (ip->iface != NULL) {
56200 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56201 + p = strchr(iface, ':');
56202 + if (p != NULL)
56203 + *p = '\0';
56204 + dev = dev_get_by_name(sock_net(sk), iface);
56205 + if (dev == NULL)
56206 + continue;
56207 + idev = in_dev_get(dev);
56208 + if (idev == NULL) {
56209 + dev_put(dev);
56210 + continue;
56211 + }
56212 + rcu_read_lock();
56213 + for_ifa(idev) {
56214 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56215 + our_addr = ifa->ifa_address;
56216 + our_netmask = 0xffffffff;
56217 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56218 + if (ret == 1) {
56219 + rcu_read_unlock();
56220 + in_dev_put(idev);
56221 + dev_put(dev);
56222 + return 0;
56223 + } else if (ret == 2) {
56224 + rcu_read_unlock();
56225 + in_dev_put(idev);
56226 + dev_put(dev);
56227 + goto denied;
56228 + }
56229 + }
56230 + } endfor_ifa(idev);
56231 + rcu_read_unlock();
56232 + in_dev_put(idev);
56233 + dev_put(dev);
56234 + } else {
56235 + our_addr = ip->addr;
56236 + our_netmask = ip->netmask;
56237 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56238 + if (ret == 1)
56239 + return 0;
56240 + else if (ret == 2)
56241 + goto denied;
56242 + }
56243 + }
56244 +
56245 +denied:
56246 + if (mode == GR_BIND)
56247 + 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));
56248 + else if (mode == GR_CONNECT)
56249 + 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));
56250 +
56251 + return -EACCES;
56252 +}
56253 +
56254 +int
56255 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56256 +{
56257 + /* always allow disconnection of dgram sockets with connect */
56258 + if (addr->sin_family == AF_UNSPEC)
56259 + return 0;
56260 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56261 +}
56262 +
56263 +int
56264 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56265 +{
56266 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56267 +}
56268 +
56269 +int gr_search_listen(struct socket *sock)
56270 +{
56271 + struct sock *sk = sock->sk;
56272 + struct sockaddr_in addr;
56273 +
56274 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56275 + addr.sin_port = inet_sk(sk)->inet_sport;
56276 +
56277 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56278 +}
56279 +
56280 +int gr_search_accept(struct socket *sock)
56281 +{
56282 + struct sock *sk = sock->sk;
56283 + struct sockaddr_in addr;
56284 +
56285 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56286 + addr.sin_port = inet_sk(sk)->inet_sport;
56287 +
56288 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56289 +}
56290 +
56291 +int
56292 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56293 +{
56294 + if (addr)
56295 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56296 + else {
56297 + struct sockaddr_in sin;
56298 + const struct inet_sock *inet = inet_sk(sk);
56299 +
56300 + sin.sin_addr.s_addr = inet->inet_daddr;
56301 + sin.sin_port = inet->inet_dport;
56302 +
56303 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56304 + }
56305 +}
56306 +
56307 +int
56308 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56309 +{
56310 + struct sockaddr_in sin;
56311 +
56312 + if (unlikely(skb->len < sizeof (struct udphdr)))
56313 + return 0; // skip this packet
56314 +
56315 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56316 + sin.sin_port = udp_hdr(skb)->source;
56317 +
56318 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56319 +}
56320 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56321 new file mode 100644
56322 index 0000000..25f54ef
56323 --- /dev/null
56324 +++ b/grsecurity/gracl_learn.c
56325 @@ -0,0 +1,207 @@
56326 +#include <linux/kernel.h>
56327 +#include <linux/mm.h>
56328 +#include <linux/sched.h>
56329 +#include <linux/poll.h>
56330 +#include <linux/string.h>
56331 +#include <linux/file.h>
56332 +#include <linux/types.h>
56333 +#include <linux/vmalloc.h>
56334 +#include <linux/grinternal.h>
56335 +
56336 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56337 + size_t count, loff_t *ppos);
56338 +extern int gr_acl_is_enabled(void);
56339 +
56340 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56341 +static int gr_learn_attached;
56342 +
56343 +/* use a 512k buffer */
56344 +#define LEARN_BUFFER_SIZE (512 * 1024)
56345 +
56346 +static DEFINE_SPINLOCK(gr_learn_lock);
56347 +static DEFINE_MUTEX(gr_learn_user_mutex);
56348 +
56349 +/* we need to maintain two buffers, so that the kernel context of grlearn
56350 + uses a semaphore around the userspace copying, and the other kernel contexts
56351 + use a spinlock when copying into the buffer, since they cannot sleep
56352 +*/
56353 +static char *learn_buffer;
56354 +static char *learn_buffer_user;
56355 +static int learn_buffer_len;
56356 +static int learn_buffer_user_len;
56357 +
56358 +static ssize_t
56359 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56360 +{
56361 + DECLARE_WAITQUEUE(wait, current);
56362 + ssize_t retval = 0;
56363 +
56364 + add_wait_queue(&learn_wait, &wait);
56365 + set_current_state(TASK_INTERRUPTIBLE);
56366 + do {
56367 + mutex_lock(&gr_learn_user_mutex);
56368 + spin_lock(&gr_learn_lock);
56369 + if (learn_buffer_len)
56370 + break;
56371 + spin_unlock(&gr_learn_lock);
56372 + mutex_unlock(&gr_learn_user_mutex);
56373 + if (file->f_flags & O_NONBLOCK) {
56374 + retval = -EAGAIN;
56375 + goto out;
56376 + }
56377 + if (signal_pending(current)) {
56378 + retval = -ERESTARTSYS;
56379 + goto out;
56380 + }
56381 +
56382 + schedule();
56383 + } while (1);
56384 +
56385 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56386 + learn_buffer_user_len = learn_buffer_len;
56387 + retval = learn_buffer_len;
56388 + learn_buffer_len = 0;
56389 +
56390 + spin_unlock(&gr_learn_lock);
56391 +
56392 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56393 + retval = -EFAULT;
56394 +
56395 + mutex_unlock(&gr_learn_user_mutex);
56396 +out:
56397 + set_current_state(TASK_RUNNING);
56398 + remove_wait_queue(&learn_wait, &wait);
56399 + return retval;
56400 +}
56401 +
56402 +static unsigned int
56403 +poll_learn(struct file * file, poll_table * wait)
56404 +{
56405 + poll_wait(file, &learn_wait, wait);
56406 +
56407 + if (learn_buffer_len)
56408 + return (POLLIN | POLLRDNORM);
56409 +
56410 + return 0;
56411 +}
56412 +
56413 +void
56414 +gr_clear_learn_entries(void)
56415 +{
56416 + char *tmp;
56417 +
56418 + mutex_lock(&gr_learn_user_mutex);
56419 + spin_lock(&gr_learn_lock);
56420 + tmp = learn_buffer;
56421 + learn_buffer = NULL;
56422 + spin_unlock(&gr_learn_lock);
56423 + if (tmp)
56424 + vfree(tmp);
56425 + if (learn_buffer_user != NULL) {
56426 + vfree(learn_buffer_user);
56427 + learn_buffer_user = NULL;
56428 + }
56429 + learn_buffer_len = 0;
56430 + mutex_unlock(&gr_learn_user_mutex);
56431 +
56432 + return;
56433 +}
56434 +
56435 +void
56436 +gr_add_learn_entry(const char *fmt, ...)
56437 +{
56438 + va_list args;
56439 + unsigned int len;
56440 +
56441 + if (!gr_learn_attached)
56442 + return;
56443 +
56444 + spin_lock(&gr_learn_lock);
56445 +
56446 + /* leave a gap at the end so we know when it's "full" but don't have to
56447 + compute the exact length of the string we're trying to append
56448 + */
56449 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56450 + spin_unlock(&gr_learn_lock);
56451 + wake_up_interruptible(&learn_wait);
56452 + return;
56453 + }
56454 + if (learn_buffer == NULL) {
56455 + spin_unlock(&gr_learn_lock);
56456 + return;
56457 + }
56458 +
56459 + va_start(args, fmt);
56460 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56461 + va_end(args);
56462 +
56463 + learn_buffer_len += len + 1;
56464 +
56465 + spin_unlock(&gr_learn_lock);
56466 + wake_up_interruptible(&learn_wait);
56467 +
56468 + return;
56469 +}
56470 +
56471 +static int
56472 +open_learn(struct inode *inode, struct file *file)
56473 +{
56474 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56475 + return -EBUSY;
56476 + if (file->f_mode & FMODE_READ) {
56477 + int retval = 0;
56478 + mutex_lock(&gr_learn_user_mutex);
56479 + if (learn_buffer == NULL)
56480 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56481 + if (learn_buffer_user == NULL)
56482 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56483 + if (learn_buffer == NULL) {
56484 + retval = -ENOMEM;
56485 + goto out_error;
56486 + }
56487 + if (learn_buffer_user == NULL) {
56488 + retval = -ENOMEM;
56489 + goto out_error;
56490 + }
56491 + learn_buffer_len = 0;
56492 + learn_buffer_user_len = 0;
56493 + gr_learn_attached = 1;
56494 +out_error:
56495 + mutex_unlock(&gr_learn_user_mutex);
56496 + return retval;
56497 + }
56498 + return 0;
56499 +}
56500 +
56501 +static int
56502 +close_learn(struct inode *inode, struct file *file)
56503 +{
56504 + if (file->f_mode & FMODE_READ) {
56505 + char *tmp = NULL;
56506 + mutex_lock(&gr_learn_user_mutex);
56507 + spin_lock(&gr_learn_lock);
56508 + tmp = learn_buffer;
56509 + learn_buffer = NULL;
56510 + spin_unlock(&gr_learn_lock);
56511 + if (tmp)
56512 + vfree(tmp);
56513 + if (learn_buffer_user != NULL) {
56514 + vfree(learn_buffer_user);
56515 + learn_buffer_user = NULL;
56516 + }
56517 + learn_buffer_len = 0;
56518 + learn_buffer_user_len = 0;
56519 + gr_learn_attached = 0;
56520 + mutex_unlock(&gr_learn_user_mutex);
56521 + }
56522 +
56523 + return 0;
56524 +}
56525 +
56526 +const struct file_operations grsec_fops = {
56527 + .read = read_learn,
56528 + .write = write_grsec_handler,
56529 + .open = open_learn,
56530 + .release = close_learn,
56531 + .poll = poll_learn,
56532 +};
56533 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56534 new file mode 100644
56535 index 0000000..39645c9
56536 --- /dev/null
56537 +++ b/grsecurity/gracl_res.c
56538 @@ -0,0 +1,68 @@
56539 +#include <linux/kernel.h>
56540 +#include <linux/sched.h>
56541 +#include <linux/gracl.h>
56542 +#include <linux/grinternal.h>
56543 +
56544 +static const char *restab_log[] = {
56545 + [RLIMIT_CPU] = "RLIMIT_CPU",
56546 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56547 + [RLIMIT_DATA] = "RLIMIT_DATA",
56548 + [RLIMIT_STACK] = "RLIMIT_STACK",
56549 + [RLIMIT_CORE] = "RLIMIT_CORE",
56550 + [RLIMIT_RSS] = "RLIMIT_RSS",
56551 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56552 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56553 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56554 + [RLIMIT_AS] = "RLIMIT_AS",
56555 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56556 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56557 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56558 + [RLIMIT_NICE] = "RLIMIT_NICE",
56559 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56560 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56561 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56562 +};
56563 +
56564 +void
56565 +gr_log_resource(const struct task_struct *task,
56566 + const int res, const unsigned long wanted, const int gt)
56567 +{
56568 + const struct cred *cred;
56569 + unsigned long rlim;
56570 +
56571 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56572 + return;
56573 +
56574 + // not yet supported resource
56575 + if (unlikely(!restab_log[res]))
56576 + return;
56577 +
56578 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56579 + rlim = task_rlimit_max(task, res);
56580 + else
56581 + rlim = task_rlimit(task, res);
56582 +
56583 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56584 + return;
56585 +
56586 + rcu_read_lock();
56587 + cred = __task_cred(task);
56588 +
56589 + if (res == RLIMIT_NPROC &&
56590 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56591 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56592 + goto out_rcu_unlock;
56593 + else if (res == RLIMIT_MEMLOCK &&
56594 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56595 + goto out_rcu_unlock;
56596 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56597 + goto out_rcu_unlock;
56598 + rcu_read_unlock();
56599 +
56600 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56601 +
56602 + return;
56603 +out_rcu_unlock:
56604 + rcu_read_unlock();
56605 + return;
56606 +}
56607 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56608 new file mode 100644
56609 index 0000000..25197e9
56610 --- /dev/null
56611 +++ b/grsecurity/gracl_segv.c
56612 @@ -0,0 +1,299 @@
56613 +#include <linux/kernel.h>
56614 +#include <linux/mm.h>
56615 +#include <asm/uaccess.h>
56616 +#include <asm/errno.h>
56617 +#include <asm/mman.h>
56618 +#include <net/sock.h>
56619 +#include <linux/file.h>
56620 +#include <linux/fs.h>
56621 +#include <linux/net.h>
56622 +#include <linux/in.h>
56623 +#include <linux/slab.h>
56624 +#include <linux/types.h>
56625 +#include <linux/sched.h>
56626 +#include <linux/timer.h>
56627 +#include <linux/gracl.h>
56628 +#include <linux/grsecurity.h>
56629 +#include <linux/grinternal.h>
56630 +
56631 +static struct crash_uid *uid_set;
56632 +static unsigned short uid_used;
56633 +static DEFINE_SPINLOCK(gr_uid_lock);
56634 +extern rwlock_t gr_inode_lock;
56635 +extern struct acl_subject_label *
56636 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56637 + struct acl_role_label *role);
56638 +
56639 +#ifdef CONFIG_BTRFS_FS
56640 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56641 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56642 +#endif
56643 +
56644 +static inline dev_t __get_dev(const struct dentry *dentry)
56645 +{
56646 +#ifdef CONFIG_BTRFS_FS
56647 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56648 + return get_btrfs_dev_from_inode(dentry->d_inode);
56649 + else
56650 +#endif
56651 + return dentry->d_inode->i_sb->s_dev;
56652 +}
56653 +
56654 +int
56655 +gr_init_uidset(void)
56656 +{
56657 + uid_set =
56658 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56659 + uid_used = 0;
56660 +
56661 + return uid_set ? 1 : 0;
56662 +}
56663 +
56664 +void
56665 +gr_free_uidset(void)
56666 +{
56667 + if (uid_set)
56668 + kfree(uid_set);
56669 +
56670 + return;
56671 +}
56672 +
56673 +int
56674 +gr_find_uid(const uid_t uid)
56675 +{
56676 + struct crash_uid *tmp = uid_set;
56677 + uid_t buid;
56678 + int low = 0, high = uid_used - 1, mid;
56679 +
56680 + while (high >= low) {
56681 + mid = (low + high) >> 1;
56682 + buid = tmp[mid].uid;
56683 + if (buid == uid)
56684 + return mid;
56685 + if (buid > uid)
56686 + high = mid - 1;
56687 + if (buid < uid)
56688 + low = mid + 1;
56689 + }
56690 +
56691 + return -1;
56692 +}
56693 +
56694 +static __inline__ void
56695 +gr_insertsort(void)
56696 +{
56697 + unsigned short i, j;
56698 + struct crash_uid index;
56699 +
56700 + for (i = 1; i < uid_used; i++) {
56701 + index = uid_set[i];
56702 + j = i;
56703 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56704 + uid_set[j] = uid_set[j - 1];
56705 + j--;
56706 + }
56707 + uid_set[j] = index;
56708 + }
56709 +
56710 + return;
56711 +}
56712 +
56713 +static __inline__ void
56714 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56715 +{
56716 + int loc;
56717 +
56718 + if (uid_used == GR_UIDTABLE_MAX)
56719 + return;
56720 +
56721 + loc = gr_find_uid(uid);
56722 +
56723 + if (loc >= 0) {
56724 + uid_set[loc].expires = expires;
56725 + return;
56726 + }
56727 +
56728 + uid_set[uid_used].uid = uid;
56729 + uid_set[uid_used].expires = expires;
56730 + uid_used++;
56731 +
56732 + gr_insertsort();
56733 +
56734 + return;
56735 +}
56736 +
56737 +void
56738 +gr_remove_uid(const unsigned short loc)
56739 +{
56740 + unsigned short i;
56741 +
56742 + for (i = loc + 1; i < uid_used; i++)
56743 + uid_set[i - 1] = uid_set[i];
56744 +
56745 + uid_used--;
56746 +
56747 + return;
56748 +}
56749 +
56750 +int
56751 +gr_check_crash_uid(const uid_t uid)
56752 +{
56753 + int loc;
56754 + int ret = 0;
56755 +
56756 + if (unlikely(!gr_acl_is_enabled()))
56757 + return 0;
56758 +
56759 + spin_lock(&gr_uid_lock);
56760 + loc = gr_find_uid(uid);
56761 +
56762 + if (loc < 0)
56763 + goto out_unlock;
56764 +
56765 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56766 + gr_remove_uid(loc);
56767 + else
56768 + ret = 1;
56769 +
56770 +out_unlock:
56771 + spin_unlock(&gr_uid_lock);
56772 + return ret;
56773 +}
56774 +
56775 +static __inline__ int
56776 +proc_is_setxid(const struct cred *cred)
56777 +{
56778 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56779 + !uid_eq(cred->uid, cred->fsuid))
56780 + return 1;
56781 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56782 + !uid_eq(cred->gid, cred->fsgid))
56783 + return 1;
56784 +
56785 + return 0;
56786 +}
56787 +
56788 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56789 +
56790 +void
56791 +gr_handle_crash(struct task_struct *task, const int sig)
56792 +{
56793 + struct acl_subject_label *curr;
56794 + struct task_struct *tsk, *tsk2;
56795 + const struct cred *cred;
56796 + const struct cred *cred2;
56797 +
56798 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56799 + return;
56800 +
56801 + if (unlikely(!gr_acl_is_enabled()))
56802 + return;
56803 +
56804 + curr = task->acl;
56805 +
56806 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56807 + return;
56808 +
56809 + if (time_before_eq(curr->expires, get_seconds())) {
56810 + curr->expires = 0;
56811 + curr->crashes = 0;
56812 + }
56813 +
56814 + curr->crashes++;
56815 +
56816 + if (!curr->expires)
56817 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56818 +
56819 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56820 + time_after(curr->expires, get_seconds())) {
56821 + rcu_read_lock();
56822 + cred = __task_cred(task);
56823 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56824 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56825 + spin_lock(&gr_uid_lock);
56826 + gr_insert_uid(cred->uid, curr->expires);
56827 + spin_unlock(&gr_uid_lock);
56828 + curr->expires = 0;
56829 + curr->crashes = 0;
56830 + read_lock(&tasklist_lock);
56831 + do_each_thread(tsk2, tsk) {
56832 + cred2 = __task_cred(tsk);
56833 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
56834 + gr_fake_force_sig(SIGKILL, tsk);
56835 + } while_each_thread(tsk2, tsk);
56836 + read_unlock(&tasklist_lock);
56837 + } else {
56838 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56839 + read_lock(&tasklist_lock);
56840 + read_lock(&grsec_exec_file_lock);
56841 + do_each_thread(tsk2, tsk) {
56842 + if (likely(tsk != task)) {
56843 + // if this thread has the same subject as the one that triggered
56844 + // RES_CRASH and it's the same binary, kill it
56845 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56846 + gr_fake_force_sig(SIGKILL, tsk);
56847 + }
56848 + } while_each_thread(tsk2, tsk);
56849 + read_unlock(&grsec_exec_file_lock);
56850 + read_unlock(&tasklist_lock);
56851 + }
56852 + rcu_read_unlock();
56853 + }
56854 +
56855 + return;
56856 +}
56857 +
56858 +int
56859 +gr_check_crash_exec(const struct file *filp)
56860 +{
56861 + struct acl_subject_label *curr;
56862 +
56863 + if (unlikely(!gr_acl_is_enabled()))
56864 + return 0;
56865 +
56866 + read_lock(&gr_inode_lock);
56867 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56868 + __get_dev(filp->f_path.dentry),
56869 + current->role);
56870 + read_unlock(&gr_inode_lock);
56871 +
56872 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56873 + (!curr->crashes && !curr->expires))
56874 + return 0;
56875 +
56876 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56877 + time_after(curr->expires, get_seconds()))
56878 + return 1;
56879 + else if (time_before_eq(curr->expires, get_seconds())) {
56880 + curr->crashes = 0;
56881 + curr->expires = 0;
56882 + }
56883 +
56884 + return 0;
56885 +}
56886 +
56887 +void
56888 +gr_handle_alertkill(struct task_struct *task)
56889 +{
56890 + struct acl_subject_label *curracl;
56891 + __u32 curr_ip;
56892 + struct task_struct *p, *p2;
56893 +
56894 + if (unlikely(!gr_acl_is_enabled()))
56895 + return;
56896 +
56897 + curracl = task->acl;
56898 + curr_ip = task->signal->curr_ip;
56899 +
56900 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56901 + read_lock(&tasklist_lock);
56902 + do_each_thread(p2, p) {
56903 + if (p->signal->curr_ip == curr_ip)
56904 + gr_fake_force_sig(SIGKILL, p);
56905 + } while_each_thread(p2, p);
56906 + read_unlock(&tasklist_lock);
56907 + } else if (curracl->mode & GR_KILLPROC)
56908 + gr_fake_force_sig(SIGKILL, task);
56909 +
56910 + return;
56911 +}
56912 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56913 new file mode 100644
56914 index 0000000..9d83a69
56915 --- /dev/null
56916 +++ b/grsecurity/gracl_shm.c
56917 @@ -0,0 +1,40 @@
56918 +#include <linux/kernel.h>
56919 +#include <linux/mm.h>
56920 +#include <linux/sched.h>
56921 +#include <linux/file.h>
56922 +#include <linux/ipc.h>
56923 +#include <linux/gracl.h>
56924 +#include <linux/grsecurity.h>
56925 +#include <linux/grinternal.h>
56926 +
56927 +int
56928 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56929 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56930 +{
56931 + struct task_struct *task;
56932 +
56933 + if (!gr_acl_is_enabled())
56934 + return 1;
56935 +
56936 + rcu_read_lock();
56937 + read_lock(&tasklist_lock);
56938 +
56939 + task = find_task_by_vpid(shm_cprid);
56940 +
56941 + if (unlikely(!task))
56942 + task = find_task_by_vpid(shm_lapid);
56943 +
56944 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56945 + (task->pid == shm_lapid)) &&
56946 + (task->acl->mode & GR_PROTSHM) &&
56947 + (task->acl != current->acl))) {
56948 + read_unlock(&tasklist_lock);
56949 + rcu_read_unlock();
56950 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56951 + return 0;
56952 + }
56953 + read_unlock(&tasklist_lock);
56954 + rcu_read_unlock();
56955 +
56956 + return 1;
56957 +}
56958 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56959 new file mode 100644
56960 index 0000000..bc0be01
56961 --- /dev/null
56962 +++ b/grsecurity/grsec_chdir.c
56963 @@ -0,0 +1,19 @@
56964 +#include <linux/kernel.h>
56965 +#include <linux/sched.h>
56966 +#include <linux/fs.h>
56967 +#include <linux/file.h>
56968 +#include <linux/grsecurity.h>
56969 +#include <linux/grinternal.h>
56970 +
56971 +void
56972 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56973 +{
56974 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56975 + if ((grsec_enable_chdir && grsec_enable_group &&
56976 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56977 + !grsec_enable_group)) {
56978 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56979 + }
56980 +#endif
56981 + return;
56982 +}
56983 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56984 new file mode 100644
56985 index 0000000..9807ee2
56986 --- /dev/null
56987 +++ b/grsecurity/grsec_chroot.c
56988 @@ -0,0 +1,368 @@
56989 +#include <linux/kernel.h>
56990 +#include <linux/module.h>
56991 +#include <linux/sched.h>
56992 +#include <linux/file.h>
56993 +#include <linux/fs.h>
56994 +#include <linux/mount.h>
56995 +#include <linux/types.h>
56996 +#include "../fs/mount.h"
56997 +#include <linux/grsecurity.h>
56998 +#include <linux/grinternal.h>
56999 +
57000 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57001 +{
57002 +#ifdef CONFIG_GRKERNSEC
57003 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57004 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57005 + task->gr_is_chrooted = 1;
57006 + else
57007 + task->gr_is_chrooted = 0;
57008 +
57009 + task->gr_chroot_dentry = path->dentry;
57010 +#endif
57011 + return;
57012 +}
57013 +
57014 +void gr_clear_chroot_entries(struct task_struct *task)
57015 +{
57016 +#ifdef CONFIG_GRKERNSEC
57017 + task->gr_is_chrooted = 0;
57018 + task->gr_chroot_dentry = NULL;
57019 +#endif
57020 + return;
57021 +}
57022 +
57023 +int
57024 +gr_handle_chroot_unix(const pid_t pid)
57025 +{
57026 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57027 + struct task_struct *p;
57028 +
57029 + if (unlikely(!grsec_enable_chroot_unix))
57030 + return 1;
57031 +
57032 + if (likely(!proc_is_chrooted(current)))
57033 + return 1;
57034 +
57035 + rcu_read_lock();
57036 + read_lock(&tasklist_lock);
57037 + p = find_task_by_vpid_unrestricted(pid);
57038 + if (unlikely(p && !have_same_root(current, p))) {
57039 + read_unlock(&tasklist_lock);
57040 + rcu_read_unlock();
57041 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57042 + return 0;
57043 + }
57044 + read_unlock(&tasklist_lock);
57045 + rcu_read_unlock();
57046 +#endif
57047 + return 1;
57048 +}
57049 +
57050 +int
57051 +gr_handle_chroot_nice(void)
57052 +{
57053 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57054 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57055 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57056 + return -EPERM;
57057 + }
57058 +#endif
57059 + return 0;
57060 +}
57061 +
57062 +int
57063 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57064 +{
57065 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57066 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57067 + && proc_is_chrooted(current)) {
57068 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57069 + return -EACCES;
57070 + }
57071 +#endif
57072 + return 0;
57073 +}
57074 +
57075 +int
57076 +gr_handle_chroot_rawio(const struct inode *inode)
57077 +{
57078 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57079 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57080 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57081 + return 1;
57082 +#endif
57083 + return 0;
57084 +}
57085 +
57086 +int
57087 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57088 +{
57089 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57090 + struct task_struct *p;
57091 + int ret = 0;
57092 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57093 + return ret;
57094 +
57095 + read_lock(&tasklist_lock);
57096 + do_each_pid_task(pid, type, p) {
57097 + if (!have_same_root(current, p)) {
57098 + ret = 1;
57099 + goto out;
57100 + }
57101 + } while_each_pid_task(pid, type, p);
57102 +out:
57103 + read_unlock(&tasklist_lock);
57104 + return ret;
57105 +#endif
57106 + return 0;
57107 +}
57108 +
57109 +int
57110 +gr_pid_is_chrooted(struct task_struct *p)
57111 +{
57112 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57113 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57114 + return 0;
57115 +
57116 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57117 + !have_same_root(current, p)) {
57118 + return 1;
57119 + }
57120 +#endif
57121 + return 0;
57122 +}
57123 +
57124 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57125 +
57126 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57127 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57128 +{
57129 + struct path path, currentroot;
57130 + int ret = 0;
57131 +
57132 + path.dentry = (struct dentry *)u_dentry;
57133 + path.mnt = (struct vfsmount *)u_mnt;
57134 + get_fs_root(current->fs, &currentroot);
57135 + if (path_is_under(&path, &currentroot))
57136 + ret = 1;
57137 + path_put(&currentroot);
57138 +
57139 + return ret;
57140 +}
57141 +#endif
57142 +
57143 +int
57144 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57145 +{
57146 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57147 + if (!grsec_enable_chroot_fchdir)
57148 + return 1;
57149 +
57150 + if (!proc_is_chrooted(current))
57151 + return 1;
57152 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57153 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57154 + return 0;
57155 + }
57156 +#endif
57157 + return 1;
57158 +}
57159 +
57160 +int
57161 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57162 + const time_t shm_createtime)
57163 +{
57164 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57165 + struct task_struct *p;
57166 + time_t starttime;
57167 +
57168 + if (unlikely(!grsec_enable_chroot_shmat))
57169 + return 1;
57170 +
57171 + if (likely(!proc_is_chrooted(current)))
57172 + return 1;
57173 +
57174 + rcu_read_lock();
57175 + read_lock(&tasklist_lock);
57176 +
57177 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57178 + starttime = p->start_time.tv_sec;
57179 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57180 + if (have_same_root(current, p)) {
57181 + goto allow;
57182 + } else {
57183 + read_unlock(&tasklist_lock);
57184 + rcu_read_unlock();
57185 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57186 + return 0;
57187 + }
57188 + }
57189 + /* creator exited, pid reuse, fall through to next check */
57190 + }
57191 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57192 + if (unlikely(!have_same_root(current, p))) {
57193 + read_unlock(&tasklist_lock);
57194 + rcu_read_unlock();
57195 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57196 + return 0;
57197 + }
57198 + }
57199 +
57200 +allow:
57201 + read_unlock(&tasklist_lock);
57202 + rcu_read_unlock();
57203 +#endif
57204 + return 1;
57205 +}
57206 +
57207 +void
57208 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57209 +{
57210 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57211 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57212 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57213 +#endif
57214 + return;
57215 +}
57216 +
57217 +int
57218 +gr_handle_chroot_mknod(const struct dentry *dentry,
57219 + const struct vfsmount *mnt, const int mode)
57220 +{
57221 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57222 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57223 + proc_is_chrooted(current)) {
57224 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57225 + return -EPERM;
57226 + }
57227 +#endif
57228 + return 0;
57229 +}
57230 +
57231 +int
57232 +gr_handle_chroot_mount(const struct dentry *dentry,
57233 + const struct vfsmount *mnt, const char *dev_name)
57234 +{
57235 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57236 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57237 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57238 + return -EPERM;
57239 + }
57240 +#endif
57241 + return 0;
57242 +}
57243 +
57244 +int
57245 +gr_handle_chroot_pivot(void)
57246 +{
57247 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57248 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57249 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57250 + return -EPERM;
57251 + }
57252 +#endif
57253 + return 0;
57254 +}
57255 +
57256 +int
57257 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57258 +{
57259 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57260 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57261 + !gr_is_outside_chroot(dentry, mnt)) {
57262 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57263 + return -EPERM;
57264 + }
57265 +#endif
57266 + return 0;
57267 +}
57268 +
57269 +extern const char *captab_log[];
57270 +extern int captab_log_entries;
57271 +
57272 +int
57273 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57274 +{
57275 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57276 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57277 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57278 + if (cap_raised(chroot_caps, cap)) {
57279 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57280 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57281 + }
57282 + return 0;
57283 + }
57284 + }
57285 +#endif
57286 + return 1;
57287 +}
57288 +
57289 +int
57290 +gr_chroot_is_capable(const int cap)
57291 +{
57292 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57293 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57294 +#endif
57295 + return 1;
57296 +}
57297 +
57298 +int
57299 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57300 +{
57301 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57302 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57303 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57304 + if (cap_raised(chroot_caps, cap)) {
57305 + return 0;
57306 + }
57307 + }
57308 +#endif
57309 + return 1;
57310 +}
57311 +
57312 +int
57313 +gr_chroot_is_capable_nolog(const int cap)
57314 +{
57315 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57316 + return gr_task_chroot_is_capable_nolog(current, cap);
57317 +#endif
57318 + return 1;
57319 +}
57320 +
57321 +int
57322 +gr_handle_chroot_sysctl(const int op)
57323 +{
57324 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57325 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57326 + proc_is_chrooted(current))
57327 + return -EACCES;
57328 +#endif
57329 + return 0;
57330 +}
57331 +
57332 +void
57333 +gr_handle_chroot_chdir(struct path *path)
57334 +{
57335 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57336 + if (grsec_enable_chroot_chdir)
57337 + set_fs_pwd(current->fs, path);
57338 +#endif
57339 + return;
57340 +}
57341 +
57342 +int
57343 +gr_handle_chroot_chmod(const struct dentry *dentry,
57344 + const struct vfsmount *mnt, const int mode)
57345 +{
57346 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57347 + /* allow chmod +s on directories, but not files */
57348 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57349 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57350 + proc_is_chrooted(current)) {
57351 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57352 + return -EPERM;
57353 + }
57354 +#endif
57355 + return 0;
57356 +}
57357 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57358 new file mode 100644
57359 index 0000000..213ad8b
57360 --- /dev/null
57361 +++ b/grsecurity/grsec_disabled.c
57362 @@ -0,0 +1,437 @@
57363 +#include <linux/kernel.h>
57364 +#include <linux/module.h>
57365 +#include <linux/sched.h>
57366 +#include <linux/file.h>
57367 +#include <linux/fs.h>
57368 +#include <linux/kdev_t.h>
57369 +#include <linux/net.h>
57370 +#include <linux/in.h>
57371 +#include <linux/ip.h>
57372 +#include <linux/skbuff.h>
57373 +#include <linux/sysctl.h>
57374 +
57375 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57376 +void
57377 +pax_set_initial_flags(struct linux_binprm *bprm)
57378 +{
57379 + return;
57380 +}
57381 +#endif
57382 +
57383 +#ifdef CONFIG_SYSCTL
57384 +__u32
57385 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57386 +{
57387 + return 0;
57388 +}
57389 +#endif
57390 +
57391 +#ifdef CONFIG_TASKSTATS
57392 +int gr_is_taskstats_denied(int pid)
57393 +{
57394 + return 0;
57395 +}
57396 +#endif
57397 +
57398 +int
57399 +gr_acl_is_enabled(void)
57400 +{
57401 + return 0;
57402 +}
57403 +
57404 +void
57405 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57406 +{
57407 + return;
57408 +}
57409 +
57410 +int
57411 +gr_handle_rawio(const struct inode *inode)
57412 +{
57413 + return 0;
57414 +}
57415 +
57416 +void
57417 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57418 +{
57419 + return;
57420 +}
57421 +
57422 +int
57423 +gr_handle_ptrace(struct task_struct *task, const long request)
57424 +{
57425 + return 0;
57426 +}
57427 +
57428 +int
57429 +gr_handle_proc_ptrace(struct task_struct *task)
57430 +{
57431 + return 0;
57432 +}
57433 +
57434 +void
57435 +gr_learn_resource(const struct task_struct *task,
57436 + const int res, const unsigned long wanted, const int gt)
57437 +{
57438 + return;
57439 +}
57440 +
57441 +int
57442 +gr_set_acls(const int type)
57443 +{
57444 + return 0;
57445 +}
57446 +
57447 +int
57448 +gr_check_hidden_task(const struct task_struct *tsk)
57449 +{
57450 + return 0;
57451 +}
57452 +
57453 +int
57454 +gr_check_protected_task(const struct task_struct *task)
57455 +{
57456 + return 0;
57457 +}
57458 +
57459 +int
57460 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57461 +{
57462 + return 0;
57463 +}
57464 +
57465 +void
57466 +gr_copy_label(struct task_struct *tsk)
57467 +{
57468 + return;
57469 +}
57470 +
57471 +void
57472 +gr_set_pax_flags(struct task_struct *task)
57473 +{
57474 + return;
57475 +}
57476 +
57477 +int
57478 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57479 + const int unsafe_share)
57480 +{
57481 + return 0;
57482 +}
57483 +
57484 +void
57485 +gr_handle_delete(const ino_t ino, const dev_t dev)
57486 +{
57487 + return;
57488 +}
57489 +
57490 +void
57491 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57492 +{
57493 + return;
57494 +}
57495 +
57496 +void
57497 +gr_handle_crash(struct task_struct *task, const int sig)
57498 +{
57499 + return;
57500 +}
57501 +
57502 +int
57503 +gr_check_crash_exec(const struct file *filp)
57504 +{
57505 + return 0;
57506 +}
57507 +
57508 +int
57509 +gr_check_crash_uid(const uid_t uid)
57510 +{
57511 + return 0;
57512 +}
57513 +
57514 +void
57515 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57516 + struct dentry *old_dentry,
57517 + struct dentry *new_dentry,
57518 + struct vfsmount *mnt, const __u8 replace)
57519 +{
57520 + return;
57521 +}
57522 +
57523 +int
57524 +gr_search_socket(const int family, const int type, const int protocol)
57525 +{
57526 + return 1;
57527 +}
57528 +
57529 +int
57530 +gr_search_connectbind(const int mode, const struct socket *sock,
57531 + const struct sockaddr_in *addr)
57532 +{
57533 + return 0;
57534 +}
57535 +
57536 +void
57537 +gr_handle_alertkill(struct task_struct *task)
57538 +{
57539 + return;
57540 +}
57541 +
57542 +__u32
57543 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57544 +{
57545 + return 1;
57546 +}
57547 +
57548 +__u32
57549 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57550 + const struct vfsmount * mnt)
57551 +{
57552 + return 1;
57553 +}
57554 +
57555 +__u32
57556 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57557 + int acc_mode)
57558 +{
57559 + return 1;
57560 +}
57561 +
57562 +__u32
57563 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57564 +{
57565 + return 1;
57566 +}
57567 +
57568 +__u32
57569 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57570 +{
57571 + return 1;
57572 +}
57573 +
57574 +int
57575 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57576 + unsigned int *vm_flags)
57577 +{
57578 + return 1;
57579 +}
57580 +
57581 +__u32
57582 +gr_acl_handle_truncate(const struct dentry * dentry,
57583 + const struct vfsmount * mnt)
57584 +{
57585 + return 1;
57586 +}
57587 +
57588 +__u32
57589 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57590 +{
57591 + return 1;
57592 +}
57593 +
57594 +__u32
57595 +gr_acl_handle_access(const struct dentry * dentry,
57596 + const struct vfsmount * mnt, const int fmode)
57597 +{
57598 + return 1;
57599 +}
57600 +
57601 +__u32
57602 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57603 + umode_t *mode)
57604 +{
57605 + return 1;
57606 +}
57607 +
57608 +__u32
57609 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57610 +{
57611 + return 1;
57612 +}
57613 +
57614 +__u32
57615 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57616 +{
57617 + return 1;
57618 +}
57619 +
57620 +void
57621 +grsecurity_init(void)
57622 +{
57623 + return;
57624 +}
57625 +
57626 +umode_t gr_acl_umask(void)
57627 +{
57628 + return 0;
57629 +}
57630 +
57631 +__u32
57632 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57633 + const struct dentry * parent_dentry,
57634 + const struct vfsmount * parent_mnt,
57635 + const int mode)
57636 +{
57637 + return 1;
57638 +}
57639 +
57640 +__u32
57641 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57642 + const struct dentry * parent_dentry,
57643 + const struct vfsmount * parent_mnt)
57644 +{
57645 + return 1;
57646 +}
57647 +
57648 +__u32
57649 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57650 + const struct dentry * parent_dentry,
57651 + const struct vfsmount * parent_mnt, const char *from)
57652 +{
57653 + return 1;
57654 +}
57655 +
57656 +__u32
57657 +gr_acl_handle_link(const struct dentry * new_dentry,
57658 + const struct dentry * parent_dentry,
57659 + const struct vfsmount * parent_mnt,
57660 + const struct dentry * old_dentry,
57661 + const struct vfsmount * old_mnt, const char *to)
57662 +{
57663 + return 1;
57664 +}
57665 +
57666 +int
57667 +gr_acl_handle_rename(const struct dentry *new_dentry,
57668 + const struct dentry *parent_dentry,
57669 + const struct vfsmount *parent_mnt,
57670 + const struct dentry *old_dentry,
57671 + const struct inode *old_parent_inode,
57672 + const struct vfsmount *old_mnt, const char *newname)
57673 +{
57674 + return 0;
57675 +}
57676 +
57677 +int
57678 +gr_acl_handle_filldir(const struct file *file, const char *name,
57679 + const int namelen, const ino_t ino)
57680 +{
57681 + return 1;
57682 +}
57683 +
57684 +int
57685 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57686 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57687 +{
57688 + return 1;
57689 +}
57690 +
57691 +int
57692 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57693 +{
57694 + return 0;
57695 +}
57696 +
57697 +int
57698 +gr_search_accept(const struct socket *sock)
57699 +{
57700 + return 0;
57701 +}
57702 +
57703 +int
57704 +gr_search_listen(const struct socket *sock)
57705 +{
57706 + return 0;
57707 +}
57708 +
57709 +int
57710 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57711 +{
57712 + return 0;
57713 +}
57714 +
57715 +__u32
57716 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57717 +{
57718 + return 1;
57719 +}
57720 +
57721 +__u32
57722 +gr_acl_handle_creat(const struct dentry * dentry,
57723 + const struct dentry * p_dentry,
57724 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57725 + const int imode)
57726 +{
57727 + return 1;
57728 +}
57729 +
57730 +void
57731 +gr_acl_handle_exit(void)
57732 +{
57733 + return;
57734 +}
57735 +
57736 +int
57737 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57738 +{
57739 + return 1;
57740 +}
57741 +
57742 +void
57743 +gr_set_role_label(const uid_t uid, const gid_t gid)
57744 +{
57745 + return;
57746 +}
57747 +
57748 +int
57749 +gr_acl_handle_procpidmem(const struct task_struct *task)
57750 +{
57751 + return 0;
57752 +}
57753 +
57754 +int
57755 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57756 +{
57757 + return 0;
57758 +}
57759 +
57760 +int
57761 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57762 +{
57763 + return 0;
57764 +}
57765 +
57766 +void
57767 +gr_set_kernel_label(struct task_struct *task)
57768 +{
57769 + return;
57770 +}
57771 +
57772 +int
57773 +gr_check_user_change(int real, int effective, int fs)
57774 +{
57775 + return 0;
57776 +}
57777 +
57778 +int
57779 +gr_check_group_change(int real, int effective, int fs)
57780 +{
57781 + return 0;
57782 +}
57783 +
57784 +int gr_acl_enable_at_secure(void)
57785 +{
57786 + return 0;
57787 +}
57788 +
57789 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57790 +{
57791 + return dentry->d_inode->i_sb->s_dev;
57792 +}
57793 +
57794 +EXPORT_SYMBOL(gr_learn_resource);
57795 +EXPORT_SYMBOL(gr_set_kernel_label);
57796 +#ifdef CONFIG_SECURITY
57797 +EXPORT_SYMBOL(gr_check_user_change);
57798 +EXPORT_SYMBOL(gr_check_group_change);
57799 +#endif
57800 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57801 new file mode 100644
57802 index 0000000..abfa971
57803 --- /dev/null
57804 +++ b/grsecurity/grsec_exec.c
57805 @@ -0,0 +1,174 @@
57806 +#include <linux/kernel.h>
57807 +#include <linux/sched.h>
57808 +#include <linux/file.h>
57809 +#include <linux/binfmts.h>
57810 +#include <linux/fs.h>
57811 +#include <linux/types.h>
57812 +#include <linux/grdefs.h>
57813 +#include <linux/grsecurity.h>
57814 +#include <linux/grinternal.h>
57815 +#include <linux/capability.h>
57816 +#include <linux/module.h>
57817 +
57818 +#include <asm/uaccess.h>
57819 +
57820 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57821 +static char gr_exec_arg_buf[132];
57822 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57823 +#endif
57824 +
57825 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57826 +
57827 +void
57828 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57829 +{
57830 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57831 + char *grarg = gr_exec_arg_buf;
57832 + unsigned int i, x, execlen = 0;
57833 + char c;
57834 +
57835 + if (!((grsec_enable_execlog && grsec_enable_group &&
57836 + in_group_p(grsec_audit_gid))
57837 + || (grsec_enable_execlog && !grsec_enable_group)))
57838 + return;
57839 +
57840 + mutex_lock(&gr_exec_arg_mutex);
57841 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57842 +
57843 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57844 + const char __user *p;
57845 + unsigned int len;
57846 +
57847 + p = get_user_arg_ptr(argv, i);
57848 + if (IS_ERR(p))
57849 + goto log;
57850 +
57851 + len = strnlen_user(p, 128 - execlen);
57852 + if (len > 128 - execlen)
57853 + len = 128 - execlen;
57854 + else if (len > 0)
57855 + len--;
57856 + if (copy_from_user(grarg + execlen, p, len))
57857 + goto log;
57858 +
57859 + /* rewrite unprintable characters */
57860 + for (x = 0; x < len; x++) {
57861 + c = *(grarg + execlen + x);
57862 + if (c < 32 || c > 126)
57863 + *(grarg + execlen + x) = ' ';
57864 + }
57865 +
57866 + execlen += len;
57867 + *(grarg + execlen) = ' ';
57868 + *(grarg + execlen + 1) = '\0';
57869 + execlen++;
57870 + }
57871 +
57872 + log:
57873 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57874 + bprm->file->f_path.mnt, grarg);
57875 + mutex_unlock(&gr_exec_arg_mutex);
57876 +#endif
57877 + return;
57878 +}
57879 +
57880 +#ifdef CONFIG_GRKERNSEC
57881 +extern int gr_acl_is_capable(const int cap);
57882 +extern int gr_acl_is_capable_nolog(const int cap);
57883 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57884 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57885 +extern int gr_chroot_is_capable(const int cap);
57886 +extern int gr_chroot_is_capable_nolog(const int cap);
57887 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57888 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57889 +#endif
57890 +
57891 +const char *captab_log[] = {
57892 + "CAP_CHOWN",
57893 + "CAP_DAC_OVERRIDE",
57894 + "CAP_DAC_READ_SEARCH",
57895 + "CAP_FOWNER",
57896 + "CAP_FSETID",
57897 + "CAP_KILL",
57898 + "CAP_SETGID",
57899 + "CAP_SETUID",
57900 + "CAP_SETPCAP",
57901 + "CAP_LINUX_IMMUTABLE",
57902 + "CAP_NET_BIND_SERVICE",
57903 + "CAP_NET_BROADCAST",
57904 + "CAP_NET_ADMIN",
57905 + "CAP_NET_RAW",
57906 + "CAP_IPC_LOCK",
57907 + "CAP_IPC_OWNER",
57908 + "CAP_SYS_MODULE",
57909 + "CAP_SYS_RAWIO",
57910 + "CAP_SYS_CHROOT",
57911 + "CAP_SYS_PTRACE",
57912 + "CAP_SYS_PACCT",
57913 + "CAP_SYS_ADMIN",
57914 + "CAP_SYS_BOOT",
57915 + "CAP_SYS_NICE",
57916 + "CAP_SYS_RESOURCE",
57917 + "CAP_SYS_TIME",
57918 + "CAP_SYS_TTY_CONFIG",
57919 + "CAP_MKNOD",
57920 + "CAP_LEASE",
57921 + "CAP_AUDIT_WRITE",
57922 + "CAP_AUDIT_CONTROL",
57923 + "CAP_SETFCAP",
57924 + "CAP_MAC_OVERRIDE",
57925 + "CAP_MAC_ADMIN",
57926 + "CAP_SYSLOG",
57927 + "CAP_WAKE_ALARM"
57928 +};
57929 +
57930 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57931 +
57932 +int gr_is_capable(const int cap)
57933 +{
57934 +#ifdef CONFIG_GRKERNSEC
57935 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57936 + return 1;
57937 + return 0;
57938 +#else
57939 + return 1;
57940 +#endif
57941 +}
57942 +
57943 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57944 +{
57945 +#ifdef CONFIG_GRKERNSEC
57946 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57947 + return 1;
57948 + return 0;
57949 +#else
57950 + return 1;
57951 +#endif
57952 +}
57953 +
57954 +int gr_is_capable_nolog(const int cap)
57955 +{
57956 +#ifdef CONFIG_GRKERNSEC
57957 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57958 + return 1;
57959 + return 0;
57960 +#else
57961 + return 1;
57962 +#endif
57963 +}
57964 +
57965 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57966 +{
57967 +#ifdef CONFIG_GRKERNSEC
57968 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57969 + return 1;
57970 + return 0;
57971 +#else
57972 + return 1;
57973 +#endif
57974 +}
57975 +
57976 +EXPORT_SYMBOL(gr_is_capable);
57977 +EXPORT_SYMBOL(gr_is_capable_nolog);
57978 +EXPORT_SYMBOL(gr_task_is_capable);
57979 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57980 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57981 new file mode 100644
57982 index 0000000..d3ee748
57983 --- /dev/null
57984 +++ b/grsecurity/grsec_fifo.c
57985 @@ -0,0 +1,24 @@
57986 +#include <linux/kernel.h>
57987 +#include <linux/sched.h>
57988 +#include <linux/fs.h>
57989 +#include <linux/file.h>
57990 +#include <linux/grinternal.h>
57991 +
57992 +int
57993 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57994 + const struct dentry *dir, const int flag, const int acc_mode)
57995 +{
57996 +#ifdef CONFIG_GRKERNSEC_FIFO
57997 + const struct cred *cred = current_cred();
57998 +
57999 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58000 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58001 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58002 + (cred->fsuid != dentry->d_inode->i_uid)) {
58003 + if (!inode_permission(dentry->d_inode, acc_mode))
58004 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58005 + return -EACCES;
58006 + }
58007 +#endif
58008 + return 0;
58009 +}
58010 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58011 new file mode 100644
58012 index 0000000..8ca18bf
58013 --- /dev/null
58014 +++ b/grsecurity/grsec_fork.c
58015 @@ -0,0 +1,23 @@
58016 +#include <linux/kernel.h>
58017 +#include <linux/sched.h>
58018 +#include <linux/grsecurity.h>
58019 +#include <linux/grinternal.h>
58020 +#include <linux/errno.h>
58021 +
58022 +void
58023 +gr_log_forkfail(const int retval)
58024 +{
58025 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58026 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58027 + switch (retval) {
58028 + case -EAGAIN:
58029 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58030 + break;
58031 + case -ENOMEM:
58032 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58033 + break;
58034 + }
58035 + }
58036 +#endif
58037 + return;
58038 +}
58039 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58040 new file mode 100644
58041 index 0000000..05a6015
58042 --- /dev/null
58043 +++ b/grsecurity/grsec_init.c
58044 @@ -0,0 +1,283 @@
58045 +#include <linux/kernel.h>
58046 +#include <linux/sched.h>
58047 +#include <linux/mm.h>
58048 +#include <linux/gracl.h>
58049 +#include <linux/slab.h>
58050 +#include <linux/vmalloc.h>
58051 +#include <linux/percpu.h>
58052 +#include <linux/module.h>
58053 +
58054 +int grsec_enable_ptrace_readexec;
58055 +int grsec_enable_setxid;
58056 +int grsec_enable_symlinkown;
58057 +int grsec_symlinkown_gid;
58058 +int grsec_enable_brute;
58059 +int grsec_enable_link;
58060 +int grsec_enable_dmesg;
58061 +int grsec_enable_harden_ptrace;
58062 +int grsec_enable_fifo;
58063 +int grsec_enable_execlog;
58064 +int grsec_enable_signal;
58065 +int grsec_enable_forkfail;
58066 +int grsec_enable_audit_ptrace;
58067 +int grsec_enable_time;
58068 +int grsec_enable_audit_textrel;
58069 +int grsec_enable_group;
58070 +int grsec_audit_gid;
58071 +int grsec_enable_chdir;
58072 +int grsec_enable_mount;
58073 +int grsec_enable_rofs;
58074 +int grsec_enable_chroot_findtask;
58075 +int grsec_enable_chroot_mount;
58076 +int grsec_enable_chroot_shmat;
58077 +int grsec_enable_chroot_fchdir;
58078 +int grsec_enable_chroot_double;
58079 +int grsec_enable_chroot_pivot;
58080 +int grsec_enable_chroot_chdir;
58081 +int grsec_enable_chroot_chmod;
58082 +int grsec_enable_chroot_mknod;
58083 +int grsec_enable_chroot_nice;
58084 +int grsec_enable_chroot_execlog;
58085 +int grsec_enable_chroot_caps;
58086 +int grsec_enable_chroot_sysctl;
58087 +int grsec_enable_chroot_unix;
58088 +int grsec_enable_tpe;
58089 +int grsec_tpe_gid;
58090 +int grsec_enable_blackhole;
58091 +#ifdef CONFIG_IPV6_MODULE
58092 +EXPORT_SYMBOL(grsec_enable_blackhole);
58093 +#endif
58094 +int grsec_lastack_retries;
58095 +int grsec_enable_tpe_all;
58096 +int grsec_enable_tpe_invert;
58097 +int grsec_enable_socket_all;
58098 +int grsec_socket_all_gid;
58099 +int grsec_enable_socket_client;
58100 +int grsec_socket_client_gid;
58101 +int grsec_enable_socket_server;
58102 +int grsec_socket_server_gid;
58103 +int grsec_resource_logging;
58104 +int grsec_disable_privio;
58105 +int grsec_enable_log_rwxmaps;
58106 +int grsec_lock;
58107 +
58108 +DEFINE_SPINLOCK(grsec_alert_lock);
58109 +unsigned long grsec_alert_wtime = 0;
58110 +unsigned long grsec_alert_fyet = 0;
58111 +
58112 +DEFINE_SPINLOCK(grsec_audit_lock);
58113 +
58114 +DEFINE_RWLOCK(grsec_exec_file_lock);
58115 +
58116 +char *gr_shared_page[4];
58117 +
58118 +char *gr_alert_log_fmt;
58119 +char *gr_audit_log_fmt;
58120 +char *gr_alert_log_buf;
58121 +char *gr_audit_log_buf;
58122 +
58123 +extern struct gr_arg *gr_usermode;
58124 +extern unsigned char *gr_system_salt;
58125 +extern unsigned char *gr_system_sum;
58126 +
58127 +void __init
58128 +grsecurity_init(void)
58129 +{
58130 + int j;
58131 + /* create the per-cpu shared pages */
58132 +
58133 +#ifdef CONFIG_X86
58134 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58135 +#endif
58136 +
58137 + for (j = 0; j < 4; j++) {
58138 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58139 + if (gr_shared_page[j] == NULL) {
58140 + panic("Unable to allocate grsecurity shared page");
58141 + return;
58142 + }
58143 + }
58144 +
58145 + /* allocate log buffers */
58146 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58147 + if (!gr_alert_log_fmt) {
58148 + panic("Unable to allocate grsecurity alert log format buffer");
58149 + return;
58150 + }
58151 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58152 + if (!gr_audit_log_fmt) {
58153 + panic("Unable to allocate grsecurity audit log format buffer");
58154 + return;
58155 + }
58156 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58157 + if (!gr_alert_log_buf) {
58158 + panic("Unable to allocate grsecurity alert log buffer");
58159 + return;
58160 + }
58161 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58162 + if (!gr_audit_log_buf) {
58163 + panic("Unable to allocate grsecurity audit log buffer");
58164 + return;
58165 + }
58166 +
58167 + /* allocate memory for authentication structure */
58168 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58169 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58170 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58171 +
58172 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58173 + panic("Unable to allocate grsecurity authentication structure");
58174 + return;
58175 + }
58176 +
58177 +
58178 +#ifdef CONFIG_GRKERNSEC_IO
58179 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58180 + grsec_disable_privio = 1;
58181 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58182 + grsec_disable_privio = 1;
58183 +#else
58184 + grsec_disable_privio = 0;
58185 +#endif
58186 +#endif
58187 +
58188 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58189 + /* for backward compatibility, tpe_invert always defaults to on if
58190 + enabled in the kernel
58191 + */
58192 + grsec_enable_tpe_invert = 1;
58193 +#endif
58194 +
58195 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58196 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58197 + grsec_lock = 1;
58198 +#endif
58199 +
58200 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58201 + grsec_enable_audit_textrel = 1;
58202 +#endif
58203 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58204 + grsec_enable_log_rwxmaps = 1;
58205 +#endif
58206 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58207 + grsec_enable_group = 1;
58208 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58209 +#endif
58210 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58211 + grsec_enable_ptrace_readexec = 1;
58212 +#endif
58213 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58214 + grsec_enable_chdir = 1;
58215 +#endif
58216 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58217 + grsec_enable_harden_ptrace = 1;
58218 +#endif
58219 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58220 + grsec_enable_mount = 1;
58221 +#endif
58222 +#ifdef CONFIG_GRKERNSEC_LINK
58223 + grsec_enable_link = 1;
58224 +#endif
58225 +#ifdef CONFIG_GRKERNSEC_BRUTE
58226 + grsec_enable_brute = 1;
58227 +#endif
58228 +#ifdef CONFIG_GRKERNSEC_DMESG
58229 + grsec_enable_dmesg = 1;
58230 +#endif
58231 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58232 + grsec_enable_blackhole = 1;
58233 + grsec_lastack_retries = 4;
58234 +#endif
58235 +#ifdef CONFIG_GRKERNSEC_FIFO
58236 + grsec_enable_fifo = 1;
58237 +#endif
58238 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58239 + grsec_enable_execlog = 1;
58240 +#endif
58241 +#ifdef CONFIG_GRKERNSEC_SETXID
58242 + grsec_enable_setxid = 1;
58243 +#endif
58244 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58245 + grsec_enable_signal = 1;
58246 +#endif
58247 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58248 + grsec_enable_forkfail = 1;
58249 +#endif
58250 +#ifdef CONFIG_GRKERNSEC_TIME
58251 + grsec_enable_time = 1;
58252 +#endif
58253 +#ifdef CONFIG_GRKERNSEC_RESLOG
58254 + grsec_resource_logging = 1;
58255 +#endif
58256 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58257 + grsec_enable_chroot_findtask = 1;
58258 +#endif
58259 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58260 + grsec_enable_chroot_unix = 1;
58261 +#endif
58262 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58263 + grsec_enable_chroot_mount = 1;
58264 +#endif
58265 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58266 + grsec_enable_chroot_fchdir = 1;
58267 +#endif
58268 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58269 + grsec_enable_chroot_shmat = 1;
58270 +#endif
58271 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58272 + grsec_enable_audit_ptrace = 1;
58273 +#endif
58274 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58275 + grsec_enable_chroot_double = 1;
58276 +#endif
58277 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58278 + grsec_enable_chroot_pivot = 1;
58279 +#endif
58280 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58281 + grsec_enable_chroot_chdir = 1;
58282 +#endif
58283 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58284 + grsec_enable_chroot_chmod = 1;
58285 +#endif
58286 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58287 + grsec_enable_chroot_mknod = 1;
58288 +#endif
58289 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58290 + grsec_enable_chroot_nice = 1;
58291 +#endif
58292 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58293 + grsec_enable_chroot_execlog = 1;
58294 +#endif
58295 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58296 + grsec_enable_chroot_caps = 1;
58297 +#endif
58298 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58299 + grsec_enable_chroot_sysctl = 1;
58300 +#endif
58301 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58302 + grsec_enable_symlinkown = 1;
58303 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58304 +#endif
58305 +#ifdef CONFIG_GRKERNSEC_TPE
58306 + grsec_enable_tpe = 1;
58307 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58308 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58309 + grsec_enable_tpe_all = 1;
58310 +#endif
58311 +#endif
58312 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58313 + grsec_enable_socket_all = 1;
58314 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58315 +#endif
58316 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58317 + grsec_enable_socket_client = 1;
58318 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58319 +#endif
58320 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58321 + grsec_enable_socket_server = 1;
58322 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58323 +#endif
58324 +#endif
58325 +
58326 + return;
58327 +}
58328 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58329 new file mode 100644
58330 index 0000000..589481f
58331 --- /dev/null
58332 +++ b/grsecurity/grsec_link.c
58333 @@ -0,0 +1,58 @@
58334 +#include <linux/kernel.h>
58335 +#include <linux/sched.h>
58336 +#include <linux/fs.h>
58337 +#include <linux/file.h>
58338 +#include <linux/grinternal.h>
58339 +
58340 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58341 +{
58342 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58343 + const struct inode *link_inode = link->dentry->d_inode;
58344 +
58345 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58346 + /* ignore root-owned links, e.g. /proc/self */
58347 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58348 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58349 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58350 + return 1;
58351 + }
58352 +#endif
58353 + return 0;
58354 +}
58355 +
58356 +int
58357 +gr_handle_follow_link(const struct inode *parent,
58358 + const struct inode *inode,
58359 + const struct dentry *dentry, const struct vfsmount *mnt)
58360 +{
58361 +#ifdef CONFIG_GRKERNSEC_LINK
58362 + const struct cred *cred = current_cred();
58363 +
58364 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58365 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58366 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58367 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58368 + return -EACCES;
58369 + }
58370 +#endif
58371 + return 0;
58372 +}
58373 +
58374 +int
58375 +gr_handle_hardlink(const struct dentry *dentry,
58376 + const struct vfsmount *mnt,
58377 + struct inode *inode, const int mode, const char *to)
58378 +{
58379 +#ifdef CONFIG_GRKERNSEC_LINK
58380 + const struct cred *cred = current_cred();
58381 +
58382 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58383 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58384 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58385 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58386 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58387 + return -EPERM;
58388 + }
58389 +#endif
58390 + return 0;
58391 +}
58392 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58393 new file mode 100644
58394 index 0000000..a45d2e9
58395 --- /dev/null
58396 +++ b/grsecurity/grsec_log.c
58397 @@ -0,0 +1,322 @@
58398 +#include <linux/kernel.h>
58399 +#include <linux/sched.h>
58400 +#include <linux/file.h>
58401 +#include <linux/tty.h>
58402 +#include <linux/fs.h>
58403 +#include <linux/grinternal.h>
58404 +
58405 +#ifdef CONFIG_TREE_PREEMPT_RCU
58406 +#define DISABLE_PREEMPT() preempt_disable()
58407 +#define ENABLE_PREEMPT() preempt_enable()
58408 +#else
58409 +#define DISABLE_PREEMPT()
58410 +#define ENABLE_PREEMPT()
58411 +#endif
58412 +
58413 +#define BEGIN_LOCKS(x) \
58414 + DISABLE_PREEMPT(); \
58415 + rcu_read_lock(); \
58416 + read_lock(&tasklist_lock); \
58417 + read_lock(&grsec_exec_file_lock); \
58418 + if (x != GR_DO_AUDIT) \
58419 + spin_lock(&grsec_alert_lock); \
58420 + else \
58421 + spin_lock(&grsec_audit_lock)
58422 +
58423 +#define END_LOCKS(x) \
58424 + if (x != GR_DO_AUDIT) \
58425 + spin_unlock(&grsec_alert_lock); \
58426 + else \
58427 + spin_unlock(&grsec_audit_lock); \
58428 + read_unlock(&grsec_exec_file_lock); \
58429 + read_unlock(&tasklist_lock); \
58430 + rcu_read_unlock(); \
58431 + ENABLE_PREEMPT(); \
58432 + if (x == GR_DONT_AUDIT) \
58433 + gr_handle_alertkill(current)
58434 +
58435 +enum {
58436 + FLOODING,
58437 + NO_FLOODING
58438 +};
58439 +
58440 +extern char *gr_alert_log_fmt;
58441 +extern char *gr_audit_log_fmt;
58442 +extern char *gr_alert_log_buf;
58443 +extern char *gr_audit_log_buf;
58444 +
58445 +static int gr_log_start(int audit)
58446 +{
58447 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58448 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58449 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58450 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58451 + unsigned long curr_secs = get_seconds();
58452 +
58453 + if (audit == GR_DO_AUDIT)
58454 + goto set_fmt;
58455 +
58456 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58457 + grsec_alert_wtime = curr_secs;
58458 + grsec_alert_fyet = 0;
58459 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58460 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58461 + grsec_alert_fyet++;
58462 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58463 + grsec_alert_wtime = curr_secs;
58464 + grsec_alert_fyet++;
58465 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58466 + return FLOODING;
58467 + }
58468 + else return FLOODING;
58469 +
58470 +set_fmt:
58471 +#endif
58472 + memset(buf, 0, PAGE_SIZE);
58473 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58474 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58475 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58476 + } else if (current->signal->curr_ip) {
58477 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58478 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58479 + } else if (gr_acl_is_enabled()) {
58480 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58481 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58482 + } else {
58483 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58484 + strcpy(buf, fmt);
58485 + }
58486 +
58487 + return NO_FLOODING;
58488 +}
58489 +
58490 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58491 + __attribute__ ((format (printf, 2, 0)));
58492 +
58493 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58494 +{
58495 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58496 + unsigned int len = strlen(buf);
58497 +
58498 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58499 +
58500 + return;
58501 +}
58502 +
58503 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58504 + __attribute__ ((format (printf, 2, 3)));
58505 +
58506 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58507 +{
58508 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58509 + unsigned int len = strlen(buf);
58510 + va_list ap;
58511 +
58512 + va_start(ap, msg);
58513 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58514 + va_end(ap);
58515 +
58516 + return;
58517 +}
58518 +
58519 +static void gr_log_end(int audit, int append_default)
58520 +{
58521 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58522 +
58523 + if (append_default) {
58524 + unsigned int len = strlen(buf);
58525 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58526 + }
58527 +
58528 + printk("%s\n", buf);
58529 +
58530 + return;
58531 +}
58532 +
58533 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58534 +{
58535 + int logtype;
58536 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58537 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58538 + void *voidptr = NULL;
58539 + int num1 = 0, num2 = 0;
58540 + unsigned long ulong1 = 0, ulong2 = 0;
58541 + struct dentry *dentry = NULL;
58542 + struct vfsmount *mnt = NULL;
58543 + struct file *file = NULL;
58544 + struct task_struct *task = NULL;
58545 + const struct cred *cred, *pcred;
58546 + va_list ap;
58547 +
58548 + BEGIN_LOCKS(audit);
58549 + logtype = gr_log_start(audit);
58550 + if (logtype == FLOODING) {
58551 + END_LOCKS(audit);
58552 + return;
58553 + }
58554 + va_start(ap, argtypes);
58555 + switch (argtypes) {
58556 + case GR_TTYSNIFF:
58557 + task = va_arg(ap, struct task_struct *);
58558 + 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);
58559 + break;
58560 + case GR_SYSCTL_HIDDEN:
58561 + str1 = va_arg(ap, char *);
58562 + gr_log_middle_varargs(audit, msg, result, str1);
58563 + break;
58564 + case GR_RBAC:
58565 + dentry = va_arg(ap, struct dentry *);
58566 + mnt = va_arg(ap, struct vfsmount *);
58567 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58568 + break;
58569 + case GR_RBAC_STR:
58570 + dentry = va_arg(ap, struct dentry *);
58571 + mnt = va_arg(ap, struct vfsmount *);
58572 + str1 = va_arg(ap, char *);
58573 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58574 + break;
58575 + case GR_STR_RBAC:
58576 + str1 = va_arg(ap, char *);
58577 + dentry = va_arg(ap, struct dentry *);
58578 + mnt = va_arg(ap, struct vfsmount *);
58579 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58580 + break;
58581 + case GR_RBAC_MODE2:
58582 + dentry = va_arg(ap, struct dentry *);
58583 + mnt = va_arg(ap, struct vfsmount *);
58584 + str1 = va_arg(ap, char *);
58585 + str2 = va_arg(ap, char *);
58586 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58587 + break;
58588 + case GR_RBAC_MODE3:
58589 + dentry = va_arg(ap, struct dentry *);
58590 + mnt = va_arg(ap, struct vfsmount *);
58591 + str1 = va_arg(ap, char *);
58592 + str2 = va_arg(ap, char *);
58593 + str3 = va_arg(ap, char *);
58594 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58595 + break;
58596 + case GR_FILENAME:
58597 + dentry = va_arg(ap, struct dentry *);
58598 + mnt = va_arg(ap, struct vfsmount *);
58599 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58600 + break;
58601 + case GR_STR_FILENAME:
58602 + str1 = va_arg(ap, char *);
58603 + dentry = va_arg(ap, struct dentry *);
58604 + mnt = va_arg(ap, struct vfsmount *);
58605 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58606 + break;
58607 + case GR_FILENAME_STR:
58608 + dentry = va_arg(ap, struct dentry *);
58609 + mnt = va_arg(ap, struct vfsmount *);
58610 + str1 = va_arg(ap, char *);
58611 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58612 + break;
58613 + case GR_FILENAME_TWO_INT:
58614 + dentry = va_arg(ap, struct dentry *);
58615 + mnt = va_arg(ap, struct vfsmount *);
58616 + num1 = va_arg(ap, int);
58617 + num2 = va_arg(ap, int);
58618 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58619 + break;
58620 + case GR_FILENAME_TWO_INT_STR:
58621 + dentry = va_arg(ap, struct dentry *);
58622 + mnt = va_arg(ap, struct vfsmount *);
58623 + num1 = va_arg(ap, int);
58624 + num2 = va_arg(ap, int);
58625 + str1 = va_arg(ap, char *);
58626 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58627 + break;
58628 + case GR_TEXTREL:
58629 + file = va_arg(ap, struct file *);
58630 + ulong1 = va_arg(ap, unsigned long);
58631 + ulong2 = va_arg(ap, unsigned long);
58632 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58633 + break;
58634 + case GR_PTRACE:
58635 + task = va_arg(ap, struct task_struct *);
58636 + 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);
58637 + break;
58638 + case GR_RESOURCE:
58639 + task = va_arg(ap, struct task_struct *);
58640 + cred = __task_cred(task);
58641 + pcred = __task_cred(task->real_parent);
58642 + ulong1 = va_arg(ap, unsigned long);
58643 + str1 = va_arg(ap, char *);
58644 + ulong2 = va_arg(ap, unsigned long);
58645 + 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);
58646 + break;
58647 + case GR_CAP:
58648 + task = va_arg(ap, struct task_struct *);
58649 + cred = __task_cred(task);
58650 + pcred = __task_cred(task->real_parent);
58651 + str1 = va_arg(ap, char *);
58652 + 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);
58653 + break;
58654 + case GR_SIG:
58655 + str1 = va_arg(ap, char *);
58656 + voidptr = va_arg(ap, void *);
58657 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58658 + break;
58659 + case GR_SIG2:
58660 + task = va_arg(ap, struct task_struct *);
58661 + cred = __task_cred(task);
58662 + pcred = __task_cred(task->real_parent);
58663 + num1 = va_arg(ap, int);
58664 + 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);
58665 + break;
58666 + case GR_CRASH1:
58667 + task = va_arg(ap, struct task_struct *);
58668 + cred = __task_cred(task);
58669 + pcred = __task_cred(task->real_parent);
58670 + ulong1 = va_arg(ap, unsigned long);
58671 + 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);
58672 + break;
58673 + case GR_CRASH2:
58674 + task = va_arg(ap, struct task_struct *);
58675 + cred = __task_cred(task);
58676 + pcred = __task_cred(task->real_parent);
58677 + ulong1 = va_arg(ap, unsigned long);
58678 + 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);
58679 + break;
58680 + case GR_RWXMAP:
58681 + file = va_arg(ap, struct file *);
58682 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58683 + break;
58684 + case GR_PSACCT:
58685 + {
58686 + unsigned int wday, cday;
58687 + __u8 whr, chr;
58688 + __u8 wmin, cmin;
58689 + __u8 wsec, csec;
58690 + char cur_tty[64] = { 0 };
58691 + char parent_tty[64] = { 0 };
58692 +
58693 + task = va_arg(ap, struct task_struct *);
58694 + wday = va_arg(ap, unsigned int);
58695 + cday = va_arg(ap, unsigned int);
58696 + whr = va_arg(ap, int);
58697 + chr = va_arg(ap, int);
58698 + wmin = va_arg(ap, int);
58699 + cmin = va_arg(ap, int);
58700 + wsec = va_arg(ap, int);
58701 + csec = va_arg(ap, int);
58702 + ulong1 = va_arg(ap, unsigned long);
58703 + cred = __task_cred(task);
58704 + pcred = __task_cred(task->real_parent);
58705 +
58706 + 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);
58707 + }
58708 + break;
58709 + default:
58710 + gr_log_middle(audit, msg, ap);
58711 + }
58712 + va_end(ap);
58713 + // these don't need DEFAULTSECARGS printed on the end
58714 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58715 + gr_log_end(audit, 0);
58716 + else
58717 + gr_log_end(audit, 1);
58718 + END_LOCKS(audit);
58719 +}
58720 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58721 new file mode 100644
58722 index 0000000..f536303
58723 --- /dev/null
58724 +++ b/grsecurity/grsec_mem.c
58725 @@ -0,0 +1,40 @@
58726 +#include <linux/kernel.h>
58727 +#include <linux/sched.h>
58728 +#include <linux/mm.h>
58729 +#include <linux/mman.h>
58730 +#include <linux/grinternal.h>
58731 +
58732 +void
58733 +gr_handle_ioperm(void)
58734 +{
58735 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58736 + return;
58737 +}
58738 +
58739 +void
58740 +gr_handle_iopl(void)
58741 +{
58742 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58743 + return;
58744 +}
58745 +
58746 +void
58747 +gr_handle_mem_readwrite(u64 from, u64 to)
58748 +{
58749 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58750 + return;
58751 +}
58752 +
58753 +void
58754 +gr_handle_vm86(void)
58755 +{
58756 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58757 + return;
58758 +}
58759 +
58760 +void
58761 +gr_log_badprocpid(const char *entry)
58762 +{
58763 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58764 + return;
58765 +}
58766 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58767 new file mode 100644
58768 index 0000000..2131422
58769 --- /dev/null
58770 +++ b/grsecurity/grsec_mount.c
58771 @@ -0,0 +1,62 @@
58772 +#include <linux/kernel.h>
58773 +#include <linux/sched.h>
58774 +#include <linux/mount.h>
58775 +#include <linux/grsecurity.h>
58776 +#include <linux/grinternal.h>
58777 +
58778 +void
58779 +gr_log_remount(const char *devname, const int retval)
58780 +{
58781 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58782 + if (grsec_enable_mount && (retval >= 0))
58783 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58784 +#endif
58785 + return;
58786 +}
58787 +
58788 +void
58789 +gr_log_unmount(const char *devname, const int retval)
58790 +{
58791 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58792 + if (grsec_enable_mount && (retval >= 0))
58793 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58794 +#endif
58795 + return;
58796 +}
58797 +
58798 +void
58799 +gr_log_mount(const char *from, const char *to, const int retval)
58800 +{
58801 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58802 + if (grsec_enable_mount && (retval >= 0))
58803 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58804 +#endif
58805 + return;
58806 +}
58807 +
58808 +int
58809 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58810 +{
58811 +#ifdef CONFIG_GRKERNSEC_ROFS
58812 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58813 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58814 + return -EPERM;
58815 + } else
58816 + return 0;
58817 +#endif
58818 + return 0;
58819 +}
58820 +
58821 +int
58822 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58823 +{
58824 +#ifdef CONFIG_GRKERNSEC_ROFS
58825 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58826 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58827 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58828 + return -EPERM;
58829 + } else
58830 + return 0;
58831 +#endif
58832 + return 0;
58833 +}
58834 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58835 new file mode 100644
58836 index 0000000..a3b12a0
58837 --- /dev/null
58838 +++ b/grsecurity/grsec_pax.c
58839 @@ -0,0 +1,36 @@
58840 +#include <linux/kernel.h>
58841 +#include <linux/sched.h>
58842 +#include <linux/mm.h>
58843 +#include <linux/file.h>
58844 +#include <linux/grinternal.h>
58845 +#include <linux/grsecurity.h>
58846 +
58847 +void
58848 +gr_log_textrel(struct vm_area_struct * vma)
58849 +{
58850 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58851 + if (grsec_enable_audit_textrel)
58852 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58853 +#endif
58854 + return;
58855 +}
58856 +
58857 +void
58858 +gr_log_rwxmmap(struct file *file)
58859 +{
58860 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58861 + if (grsec_enable_log_rwxmaps)
58862 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58863 +#endif
58864 + return;
58865 +}
58866 +
58867 +void
58868 +gr_log_rwxmprotect(struct file *file)
58869 +{
58870 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58871 + if (grsec_enable_log_rwxmaps)
58872 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58873 +#endif
58874 + return;
58875 +}
58876 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58877 new file mode 100644
58878 index 0000000..f7f29aa
58879 --- /dev/null
58880 +++ b/grsecurity/grsec_ptrace.c
58881 @@ -0,0 +1,30 @@
58882 +#include <linux/kernel.h>
58883 +#include <linux/sched.h>
58884 +#include <linux/grinternal.h>
58885 +#include <linux/security.h>
58886 +
58887 +void
58888 +gr_audit_ptrace(struct task_struct *task)
58889 +{
58890 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58891 + if (grsec_enable_audit_ptrace)
58892 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58893 +#endif
58894 + return;
58895 +}
58896 +
58897 +int
58898 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58899 +{
58900 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58901 + const struct dentry *dentry = file->f_path.dentry;
58902 + const struct vfsmount *mnt = file->f_path.mnt;
58903 +
58904 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58905 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58906 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58907 + return -EACCES;
58908 + }
58909 +#endif
58910 + return 0;
58911 +}
58912 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58913 new file mode 100644
58914 index 0000000..b4ac94c
58915 --- /dev/null
58916 +++ b/grsecurity/grsec_sig.c
58917 @@ -0,0 +1,209 @@
58918 +#include <linux/kernel.h>
58919 +#include <linux/sched.h>
58920 +#include <linux/delay.h>
58921 +#include <linux/grsecurity.h>
58922 +#include <linux/grinternal.h>
58923 +#include <linux/hardirq.h>
58924 +
58925 +char *signames[] = {
58926 + [SIGSEGV] = "Segmentation fault",
58927 + [SIGILL] = "Illegal instruction",
58928 + [SIGABRT] = "Abort",
58929 + [SIGBUS] = "Invalid alignment/Bus error"
58930 +};
58931 +
58932 +void
58933 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58934 +{
58935 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58936 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58937 + (sig == SIGABRT) || (sig == SIGBUS))) {
58938 + if (t->pid == current->pid) {
58939 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58940 + } else {
58941 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58942 + }
58943 + }
58944 +#endif
58945 + return;
58946 +}
58947 +
58948 +int
58949 +gr_handle_signal(const struct task_struct *p, const int sig)
58950 +{
58951 +#ifdef CONFIG_GRKERNSEC
58952 + /* ignore the 0 signal for protected task checks */
58953 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58954 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58955 + return -EPERM;
58956 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58957 + return -EPERM;
58958 + }
58959 +#endif
58960 + return 0;
58961 +}
58962 +
58963 +#ifdef CONFIG_GRKERNSEC
58964 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58965 +
58966 +int gr_fake_force_sig(int sig, struct task_struct *t)
58967 +{
58968 + unsigned long int flags;
58969 + int ret, blocked, ignored;
58970 + struct k_sigaction *action;
58971 +
58972 + spin_lock_irqsave(&t->sighand->siglock, flags);
58973 + action = &t->sighand->action[sig-1];
58974 + ignored = action->sa.sa_handler == SIG_IGN;
58975 + blocked = sigismember(&t->blocked, sig);
58976 + if (blocked || ignored) {
58977 + action->sa.sa_handler = SIG_DFL;
58978 + if (blocked) {
58979 + sigdelset(&t->blocked, sig);
58980 + recalc_sigpending_and_wake(t);
58981 + }
58982 + }
58983 + if (action->sa.sa_handler == SIG_DFL)
58984 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58985 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58986 +
58987 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58988 +
58989 + return ret;
58990 +}
58991 +#endif
58992 +
58993 +#ifdef CONFIG_GRKERNSEC_BRUTE
58994 +#define GR_USER_BAN_TIME (15 * 60)
58995 +
58996 +static int __get_dumpable(unsigned long mm_flags)
58997 +{
58998 + int ret;
58999 +
59000 + ret = mm_flags & MMF_DUMPABLE_MASK;
59001 + return (ret >= 2) ? 2 : ret;
59002 +}
59003 +#endif
59004 +
59005 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59006 +{
59007 +#ifdef CONFIG_GRKERNSEC_BRUTE
59008 + kuid_t uid = GLOBAL_ROOT_UID;
59009 +
59010 + if (!grsec_enable_brute)
59011 + return;
59012 +
59013 + rcu_read_lock();
59014 + read_lock(&tasklist_lock);
59015 + read_lock(&grsec_exec_file_lock);
59016 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59017 + p->real_parent->brute = 1;
59018 + else {
59019 + const struct cred *cred = __task_cred(p), *cred2;
59020 + struct task_struct *tsk, *tsk2;
59021 +
59022 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59023 + struct user_struct *user;
59024 +
59025 + uid = cred->uid;
59026 +
59027 + /* this is put upon execution past expiration */
59028 + user = find_user(uid);
59029 + if (user == NULL)
59030 + goto unlock;
59031 + user->banned = 1;
59032 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59033 + if (user->ban_expires == ~0UL)
59034 + user->ban_expires--;
59035 +
59036 + do_each_thread(tsk2, tsk) {
59037 + cred2 = __task_cred(tsk);
59038 + if (tsk != p && uid_eq(cred2->uid, uid))
59039 + gr_fake_force_sig(SIGKILL, tsk);
59040 + } while_each_thread(tsk2, tsk);
59041 + }
59042 + }
59043 +unlock:
59044 + read_unlock(&grsec_exec_file_lock);
59045 + read_unlock(&tasklist_lock);
59046 + rcu_read_unlock();
59047 +
59048 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59049 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59050 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59051 +
59052 +#endif
59053 + return;
59054 +}
59055 +
59056 +void gr_handle_brute_check(void)
59057 +{
59058 +#ifdef CONFIG_GRKERNSEC_BRUTE
59059 + if (current->brute)
59060 + msleep(30 * 1000);
59061 +#endif
59062 + return;
59063 +}
59064 +
59065 +void gr_handle_kernel_exploit(void)
59066 +{
59067 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59068 + const struct cred *cred;
59069 + struct task_struct *tsk, *tsk2;
59070 + struct user_struct *user;
59071 + kuid_t uid;
59072 +
59073 + if (in_irq() || in_serving_softirq() || in_nmi())
59074 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59075 +
59076 + uid = current_uid();
59077 +
59078 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59079 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59080 + else {
59081 + /* kill all the processes of this user, hold a reference
59082 + to their creds struct, and prevent them from creating
59083 + another process until system reset
59084 + */
59085 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59086 + from_kuid_munged(&init_user_ns, uid));
59087 + /* we intentionally leak this ref */
59088 + user = get_uid(current->cred->user);
59089 + if (user) {
59090 + user->banned = 1;
59091 + user->ban_expires = ~0UL;
59092 + }
59093 +
59094 + read_lock(&tasklist_lock);
59095 + do_each_thread(tsk2, tsk) {
59096 + cred = __task_cred(tsk);
59097 + if (uid_eq(cred->uid, uid))
59098 + gr_fake_force_sig(SIGKILL, tsk);
59099 + } while_each_thread(tsk2, tsk);
59100 + read_unlock(&tasklist_lock);
59101 + }
59102 +#endif
59103 +}
59104 +
59105 +int __gr_process_user_ban(struct user_struct *user)
59106 +{
59107 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59108 + if (unlikely(user->banned)) {
59109 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59110 + user->banned = 0;
59111 + user->ban_expires = 0;
59112 + free_uid(user);
59113 + } else
59114 + return -EPERM;
59115 + }
59116 +#endif
59117 + return 0;
59118 +}
59119 +
59120 +int gr_process_user_ban(void)
59121 +{
59122 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59123 + return __gr_process_user_ban(current->cred->user);
59124 +#endif
59125 + return 0;
59126 +}
59127 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59128 new file mode 100644
59129 index 0000000..4030d57
59130 --- /dev/null
59131 +++ b/grsecurity/grsec_sock.c
59132 @@ -0,0 +1,244 @@
59133 +#include <linux/kernel.h>
59134 +#include <linux/module.h>
59135 +#include <linux/sched.h>
59136 +#include <linux/file.h>
59137 +#include <linux/net.h>
59138 +#include <linux/in.h>
59139 +#include <linux/ip.h>
59140 +#include <net/sock.h>
59141 +#include <net/inet_sock.h>
59142 +#include <linux/grsecurity.h>
59143 +#include <linux/grinternal.h>
59144 +#include <linux/gracl.h>
59145 +
59146 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59147 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59148 +
59149 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59150 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59151 +
59152 +#ifdef CONFIG_UNIX_MODULE
59153 +EXPORT_SYMBOL(gr_acl_handle_unix);
59154 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59155 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59156 +EXPORT_SYMBOL(gr_handle_create);
59157 +#endif
59158 +
59159 +#ifdef CONFIG_GRKERNSEC
59160 +#define gr_conn_table_size 32749
59161 +struct conn_table_entry {
59162 + struct conn_table_entry *next;
59163 + struct signal_struct *sig;
59164 +};
59165 +
59166 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59167 +DEFINE_SPINLOCK(gr_conn_table_lock);
59168 +
59169 +extern const char * gr_socktype_to_name(unsigned char type);
59170 +extern const char * gr_proto_to_name(unsigned char proto);
59171 +extern const char * gr_sockfamily_to_name(unsigned char family);
59172 +
59173 +static __inline__ int
59174 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59175 +{
59176 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59177 +}
59178 +
59179 +static __inline__ int
59180 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59181 + __u16 sport, __u16 dport)
59182 +{
59183 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59184 + sig->gr_sport == sport && sig->gr_dport == dport))
59185 + return 1;
59186 + else
59187 + return 0;
59188 +}
59189 +
59190 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59191 +{
59192 + struct conn_table_entry **match;
59193 + unsigned int index;
59194 +
59195 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59196 + sig->gr_sport, sig->gr_dport,
59197 + gr_conn_table_size);
59198 +
59199 + newent->sig = sig;
59200 +
59201 + match = &gr_conn_table[index];
59202 + newent->next = *match;
59203 + *match = newent;
59204 +
59205 + return;
59206 +}
59207 +
59208 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59209 +{
59210 + struct conn_table_entry *match, *last = NULL;
59211 + unsigned int index;
59212 +
59213 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59214 + sig->gr_sport, sig->gr_dport,
59215 + gr_conn_table_size);
59216 +
59217 + match = gr_conn_table[index];
59218 + while (match && !conn_match(match->sig,
59219 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59220 + sig->gr_dport)) {
59221 + last = match;
59222 + match = match->next;
59223 + }
59224 +
59225 + if (match) {
59226 + if (last)
59227 + last->next = match->next;
59228 + else
59229 + gr_conn_table[index] = NULL;
59230 + kfree(match);
59231 + }
59232 +
59233 + return;
59234 +}
59235 +
59236 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59237 + __u16 sport, __u16 dport)
59238 +{
59239 + struct conn_table_entry *match;
59240 + unsigned int index;
59241 +
59242 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59243 +
59244 + match = gr_conn_table[index];
59245 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59246 + match = match->next;
59247 +
59248 + if (match)
59249 + return match->sig;
59250 + else
59251 + return NULL;
59252 +}
59253 +
59254 +#endif
59255 +
59256 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59257 +{
59258 +#ifdef CONFIG_GRKERNSEC
59259 + struct signal_struct *sig = task->signal;
59260 + struct conn_table_entry *newent;
59261 +
59262 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59263 + if (newent == NULL)
59264 + return;
59265 + /* no bh lock needed since we are called with bh disabled */
59266 + spin_lock(&gr_conn_table_lock);
59267 + gr_del_task_from_ip_table_nolock(sig);
59268 + sig->gr_saddr = inet->inet_rcv_saddr;
59269 + sig->gr_daddr = inet->inet_daddr;
59270 + sig->gr_sport = inet->inet_sport;
59271 + sig->gr_dport = inet->inet_dport;
59272 + gr_add_to_task_ip_table_nolock(sig, newent);
59273 + spin_unlock(&gr_conn_table_lock);
59274 +#endif
59275 + return;
59276 +}
59277 +
59278 +void gr_del_task_from_ip_table(struct task_struct *task)
59279 +{
59280 +#ifdef CONFIG_GRKERNSEC
59281 + spin_lock_bh(&gr_conn_table_lock);
59282 + gr_del_task_from_ip_table_nolock(task->signal);
59283 + spin_unlock_bh(&gr_conn_table_lock);
59284 +#endif
59285 + return;
59286 +}
59287 +
59288 +void
59289 +gr_attach_curr_ip(const struct sock *sk)
59290 +{
59291 +#ifdef CONFIG_GRKERNSEC
59292 + struct signal_struct *p, *set;
59293 + const struct inet_sock *inet = inet_sk(sk);
59294 +
59295 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59296 + return;
59297 +
59298 + set = current->signal;
59299 +
59300 + spin_lock_bh(&gr_conn_table_lock);
59301 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59302 + inet->inet_dport, inet->inet_sport);
59303 + if (unlikely(p != NULL)) {
59304 + set->curr_ip = p->curr_ip;
59305 + set->used_accept = 1;
59306 + gr_del_task_from_ip_table_nolock(p);
59307 + spin_unlock_bh(&gr_conn_table_lock);
59308 + return;
59309 + }
59310 + spin_unlock_bh(&gr_conn_table_lock);
59311 +
59312 + set->curr_ip = inet->inet_daddr;
59313 + set->used_accept = 1;
59314 +#endif
59315 + return;
59316 +}
59317 +
59318 +int
59319 +gr_handle_sock_all(const int family, const int type, const int protocol)
59320 +{
59321 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59322 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59323 + (family != AF_UNIX)) {
59324 + if (family == AF_INET)
59325 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59326 + else
59327 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59328 + return -EACCES;
59329 + }
59330 +#endif
59331 + return 0;
59332 +}
59333 +
59334 +int
59335 +gr_handle_sock_server(const struct sockaddr *sck)
59336 +{
59337 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59338 + if (grsec_enable_socket_server &&
59339 + in_group_p(grsec_socket_server_gid) &&
59340 + sck && (sck->sa_family != AF_UNIX) &&
59341 + (sck->sa_family != AF_LOCAL)) {
59342 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59343 + return -EACCES;
59344 + }
59345 +#endif
59346 + return 0;
59347 +}
59348 +
59349 +int
59350 +gr_handle_sock_server_other(const struct sock *sck)
59351 +{
59352 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59353 + if (grsec_enable_socket_server &&
59354 + in_group_p(grsec_socket_server_gid) &&
59355 + sck && (sck->sk_family != AF_UNIX) &&
59356 + (sck->sk_family != AF_LOCAL)) {
59357 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59358 + return -EACCES;
59359 + }
59360 +#endif
59361 + return 0;
59362 +}
59363 +
59364 +int
59365 +gr_handle_sock_client(const struct sockaddr *sck)
59366 +{
59367 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59368 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59369 + sck && (sck->sa_family != AF_UNIX) &&
59370 + (sck->sa_family != AF_LOCAL)) {
59371 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59372 + return -EACCES;
59373 + }
59374 +#endif
59375 + return 0;
59376 +}
59377 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59378 new file mode 100644
59379 index 0000000..f55ef0f
59380 --- /dev/null
59381 +++ b/grsecurity/grsec_sysctl.c
59382 @@ -0,0 +1,469 @@
59383 +#include <linux/kernel.h>
59384 +#include <linux/sched.h>
59385 +#include <linux/sysctl.h>
59386 +#include <linux/grsecurity.h>
59387 +#include <linux/grinternal.h>
59388 +
59389 +int
59390 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59391 +{
59392 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59393 + if (dirname == NULL || name == NULL)
59394 + return 0;
59395 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59396 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59397 + return -EACCES;
59398 + }
59399 +#endif
59400 + return 0;
59401 +}
59402 +
59403 +#ifdef CONFIG_GRKERNSEC_ROFS
59404 +static int __maybe_unused one = 1;
59405 +#endif
59406 +
59407 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59408 +struct ctl_table grsecurity_table[] = {
59409 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59410 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59411 +#ifdef CONFIG_GRKERNSEC_IO
59412 + {
59413 + .procname = "disable_priv_io",
59414 + .data = &grsec_disable_privio,
59415 + .maxlen = sizeof(int),
59416 + .mode = 0600,
59417 + .proc_handler = &proc_dointvec,
59418 + },
59419 +#endif
59420 +#endif
59421 +#ifdef CONFIG_GRKERNSEC_LINK
59422 + {
59423 + .procname = "linking_restrictions",
59424 + .data = &grsec_enable_link,
59425 + .maxlen = sizeof(int),
59426 + .mode = 0600,
59427 + .proc_handler = &proc_dointvec,
59428 + },
59429 +#endif
59430 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59431 + {
59432 + .procname = "enforce_symlinksifowner",
59433 + .data = &grsec_enable_symlinkown,
59434 + .maxlen = sizeof(int),
59435 + .mode = 0600,
59436 + .proc_handler = &proc_dointvec,
59437 + },
59438 + {
59439 + .procname = "symlinkown_gid",
59440 + .data = &grsec_symlinkown_gid,
59441 + .maxlen = sizeof(int),
59442 + .mode = 0600,
59443 + .proc_handler = &proc_dointvec,
59444 + },
59445 +#endif
59446 +#ifdef CONFIG_GRKERNSEC_BRUTE
59447 + {
59448 + .procname = "deter_bruteforce",
59449 + .data = &grsec_enable_brute,
59450 + .maxlen = sizeof(int),
59451 + .mode = 0600,
59452 + .proc_handler = &proc_dointvec,
59453 + },
59454 +#endif
59455 +#ifdef CONFIG_GRKERNSEC_FIFO
59456 + {
59457 + .procname = "fifo_restrictions",
59458 + .data = &grsec_enable_fifo,
59459 + .maxlen = sizeof(int),
59460 + .mode = 0600,
59461 + .proc_handler = &proc_dointvec,
59462 + },
59463 +#endif
59464 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59465 + {
59466 + .procname = "ptrace_readexec",
59467 + .data = &grsec_enable_ptrace_readexec,
59468 + .maxlen = sizeof(int),
59469 + .mode = 0600,
59470 + .proc_handler = &proc_dointvec,
59471 + },
59472 +#endif
59473 +#ifdef CONFIG_GRKERNSEC_SETXID
59474 + {
59475 + .procname = "consistent_setxid",
59476 + .data = &grsec_enable_setxid,
59477 + .maxlen = sizeof(int),
59478 + .mode = 0600,
59479 + .proc_handler = &proc_dointvec,
59480 + },
59481 +#endif
59482 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59483 + {
59484 + .procname = "ip_blackhole",
59485 + .data = &grsec_enable_blackhole,
59486 + .maxlen = sizeof(int),
59487 + .mode = 0600,
59488 + .proc_handler = &proc_dointvec,
59489 + },
59490 + {
59491 + .procname = "lastack_retries",
59492 + .data = &grsec_lastack_retries,
59493 + .maxlen = sizeof(int),
59494 + .mode = 0600,
59495 + .proc_handler = &proc_dointvec,
59496 + },
59497 +#endif
59498 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59499 + {
59500 + .procname = "exec_logging",
59501 + .data = &grsec_enable_execlog,
59502 + .maxlen = sizeof(int),
59503 + .mode = 0600,
59504 + .proc_handler = &proc_dointvec,
59505 + },
59506 +#endif
59507 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59508 + {
59509 + .procname = "rwxmap_logging",
59510 + .data = &grsec_enable_log_rwxmaps,
59511 + .maxlen = sizeof(int),
59512 + .mode = 0600,
59513 + .proc_handler = &proc_dointvec,
59514 + },
59515 +#endif
59516 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59517 + {
59518 + .procname = "signal_logging",
59519 + .data = &grsec_enable_signal,
59520 + .maxlen = sizeof(int),
59521 + .mode = 0600,
59522 + .proc_handler = &proc_dointvec,
59523 + },
59524 +#endif
59525 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59526 + {
59527 + .procname = "forkfail_logging",
59528 + .data = &grsec_enable_forkfail,
59529 + .maxlen = sizeof(int),
59530 + .mode = 0600,
59531 + .proc_handler = &proc_dointvec,
59532 + },
59533 +#endif
59534 +#ifdef CONFIG_GRKERNSEC_TIME
59535 + {
59536 + .procname = "timechange_logging",
59537 + .data = &grsec_enable_time,
59538 + .maxlen = sizeof(int),
59539 + .mode = 0600,
59540 + .proc_handler = &proc_dointvec,
59541 + },
59542 +#endif
59543 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59544 + {
59545 + .procname = "chroot_deny_shmat",
59546 + .data = &grsec_enable_chroot_shmat,
59547 + .maxlen = sizeof(int),
59548 + .mode = 0600,
59549 + .proc_handler = &proc_dointvec,
59550 + },
59551 +#endif
59552 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59553 + {
59554 + .procname = "chroot_deny_unix",
59555 + .data = &grsec_enable_chroot_unix,
59556 + .maxlen = sizeof(int),
59557 + .mode = 0600,
59558 + .proc_handler = &proc_dointvec,
59559 + },
59560 +#endif
59561 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59562 + {
59563 + .procname = "chroot_deny_mount",
59564 + .data = &grsec_enable_chroot_mount,
59565 + .maxlen = sizeof(int),
59566 + .mode = 0600,
59567 + .proc_handler = &proc_dointvec,
59568 + },
59569 +#endif
59570 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59571 + {
59572 + .procname = "chroot_deny_fchdir",
59573 + .data = &grsec_enable_chroot_fchdir,
59574 + .maxlen = sizeof(int),
59575 + .mode = 0600,
59576 + .proc_handler = &proc_dointvec,
59577 + },
59578 +#endif
59579 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59580 + {
59581 + .procname = "chroot_deny_chroot",
59582 + .data = &grsec_enable_chroot_double,
59583 + .maxlen = sizeof(int),
59584 + .mode = 0600,
59585 + .proc_handler = &proc_dointvec,
59586 + },
59587 +#endif
59588 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59589 + {
59590 + .procname = "chroot_deny_pivot",
59591 + .data = &grsec_enable_chroot_pivot,
59592 + .maxlen = sizeof(int),
59593 + .mode = 0600,
59594 + .proc_handler = &proc_dointvec,
59595 + },
59596 +#endif
59597 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59598 + {
59599 + .procname = "chroot_enforce_chdir",
59600 + .data = &grsec_enable_chroot_chdir,
59601 + .maxlen = sizeof(int),
59602 + .mode = 0600,
59603 + .proc_handler = &proc_dointvec,
59604 + },
59605 +#endif
59606 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59607 + {
59608 + .procname = "chroot_deny_chmod",
59609 + .data = &grsec_enable_chroot_chmod,
59610 + .maxlen = sizeof(int),
59611 + .mode = 0600,
59612 + .proc_handler = &proc_dointvec,
59613 + },
59614 +#endif
59615 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59616 + {
59617 + .procname = "chroot_deny_mknod",
59618 + .data = &grsec_enable_chroot_mknod,
59619 + .maxlen = sizeof(int),
59620 + .mode = 0600,
59621 + .proc_handler = &proc_dointvec,
59622 + },
59623 +#endif
59624 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59625 + {
59626 + .procname = "chroot_restrict_nice",
59627 + .data = &grsec_enable_chroot_nice,
59628 + .maxlen = sizeof(int),
59629 + .mode = 0600,
59630 + .proc_handler = &proc_dointvec,
59631 + },
59632 +#endif
59633 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59634 + {
59635 + .procname = "chroot_execlog",
59636 + .data = &grsec_enable_chroot_execlog,
59637 + .maxlen = sizeof(int),
59638 + .mode = 0600,
59639 + .proc_handler = &proc_dointvec,
59640 + },
59641 +#endif
59642 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59643 + {
59644 + .procname = "chroot_caps",
59645 + .data = &grsec_enable_chroot_caps,
59646 + .maxlen = sizeof(int),
59647 + .mode = 0600,
59648 + .proc_handler = &proc_dointvec,
59649 + },
59650 +#endif
59651 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59652 + {
59653 + .procname = "chroot_deny_sysctl",
59654 + .data = &grsec_enable_chroot_sysctl,
59655 + .maxlen = sizeof(int),
59656 + .mode = 0600,
59657 + .proc_handler = &proc_dointvec,
59658 + },
59659 +#endif
59660 +#ifdef CONFIG_GRKERNSEC_TPE
59661 + {
59662 + .procname = "tpe",
59663 + .data = &grsec_enable_tpe,
59664 + .maxlen = sizeof(int),
59665 + .mode = 0600,
59666 + .proc_handler = &proc_dointvec,
59667 + },
59668 + {
59669 + .procname = "tpe_gid",
59670 + .data = &grsec_tpe_gid,
59671 + .maxlen = sizeof(int),
59672 + .mode = 0600,
59673 + .proc_handler = &proc_dointvec,
59674 + },
59675 +#endif
59676 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59677 + {
59678 + .procname = "tpe_invert",
59679 + .data = &grsec_enable_tpe_invert,
59680 + .maxlen = sizeof(int),
59681 + .mode = 0600,
59682 + .proc_handler = &proc_dointvec,
59683 + },
59684 +#endif
59685 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59686 + {
59687 + .procname = "tpe_restrict_all",
59688 + .data = &grsec_enable_tpe_all,
59689 + .maxlen = sizeof(int),
59690 + .mode = 0600,
59691 + .proc_handler = &proc_dointvec,
59692 + },
59693 +#endif
59694 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59695 + {
59696 + .procname = "socket_all",
59697 + .data = &grsec_enable_socket_all,
59698 + .maxlen = sizeof(int),
59699 + .mode = 0600,
59700 + .proc_handler = &proc_dointvec,
59701 + },
59702 + {
59703 + .procname = "socket_all_gid",
59704 + .data = &grsec_socket_all_gid,
59705 + .maxlen = sizeof(int),
59706 + .mode = 0600,
59707 + .proc_handler = &proc_dointvec,
59708 + },
59709 +#endif
59710 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59711 + {
59712 + .procname = "socket_client",
59713 + .data = &grsec_enable_socket_client,
59714 + .maxlen = sizeof(int),
59715 + .mode = 0600,
59716 + .proc_handler = &proc_dointvec,
59717 + },
59718 + {
59719 + .procname = "socket_client_gid",
59720 + .data = &grsec_socket_client_gid,
59721 + .maxlen = sizeof(int),
59722 + .mode = 0600,
59723 + .proc_handler = &proc_dointvec,
59724 + },
59725 +#endif
59726 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59727 + {
59728 + .procname = "socket_server",
59729 + .data = &grsec_enable_socket_server,
59730 + .maxlen = sizeof(int),
59731 + .mode = 0600,
59732 + .proc_handler = &proc_dointvec,
59733 + },
59734 + {
59735 + .procname = "socket_server_gid",
59736 + .data = &grsec_socket_server_gid,
59737 + .maxlen = sizeof(int),
59738 + .mode = 0600,
59739 + .proc_handler = &proc_dointvec,
59740 + },
59741 +#endif
59742 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59743 + {
59744 + .procname = "audit_group",
59745 + .data = &grsec_enable_group,
59746 + .maxlen = sizeof(int),
59747 + .mode = 0600,
59748 + .proc_handler = &proc_dointvec,
59749 + },
59750 + {
59751 + .procname = "audit_gid",
59752 + .data = &grsec_audit_gid,
59753 + .maxlen = sizeof(int),
59754 + .mode = 0600,
59755 + .proc_handler = &proc_dointvec,
59756 + },
59757 +#endif
59758 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59759 + {
59760 + .procname = "audit_chdir",
59761 + .data = &grsec_enable_chdir,
59762 + .maxlen = sizeof(int),
59763 + .mode = 0600,
59764 + .proc_handler = &proc_dointvec,
59765 + },
59766 +#endif
59767 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59768 + {
59769 + .procname = "audit_mount",
59770 + .data = &grsec_enable_mount,
59771 + .maxlen = sizeof(int),
59772 + .mode = 0600,
59773 + .proc_handler = &proc_dointvec,
59774 + },
59775 +#endif
59776 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59777 + {
59778 + .procname = "audit_textrel",
59779 + .data = &grsec_enable_audit_textrel,
59780 + .maxlen = sizeof(int),
59781 + .mode = 0600,
59782 + .proc_handler = &proc_dointvec,
59783 + },
59784 +#endif
59785 +#ifdef CONFIG_GRKERNSEC_DMESG
59786 + {
59787 + .procname = "dmesg",
59788 + .data = &grsec_enable_dmesg,
59789 + .maxlen = sizeof(int),
59790 + .mode = 0600,
59791 + .proc_handler = &proc_dointvec,
59792 + },
59793 +#endif
59794 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59795 + {
59796 + .procname = "chroot_findtask",
59797 + .data = &grsec_enable_chroot_findtask,
59798 + .maxlen = sizeof(int),
59799 + .mode = 0600,
59800 + .proc_handler = &proc_dointvec,
59801 + },
59802 +#endif
59803 +#ifdef CONFIG_GRKERNSEC_RESLOG
59804 + {
59805 + .procname = "resource_logging",
59806 + .data = &grsec_resource_logging,
59807 + .maxlen = sizeof(int),
59808 + .mode = 0600,
59809 + .proc_handler = &proc_dointvec,
59810 + },
59811 +#endif
59812 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59813 + {
59814 + .procname = "audit_ptrace",
59815 + .data = &grsec_enable_audit_ptrace,
59816 + .maxlen = sizeof(int),
59817 + .mode = 0600,
59818 + .proc_handler = &proc_dointvec,
59819 + },
59820 +#endif
59821 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59822 + {
59823 + .procname = "harden_ptrace",
59824 + .data = &grsec_enable_harden_ptrace,
59825 + .maxlen = sizeof(int),
59826 + .mode = 0600,
59827 + .proc_handler = &proc_dointvec,
59828 + },
59829 +#endif
59830 + {
59831 + .procname = "grsec_lock",
59832 + .data = &grsec_lock,
59833 + .maxlen = sizeof(int),
59834 + .mode = 0600,
59835 + .proc_handler = &proc_dointvec,
59836 + },
59837 +#endif
59838 +#ifdef CONFIG_GRKERNSEC_ROFS
59839 + {
59840 + .procname = "romount_protect",
59841 + .data = &grsec_enable_rofs,
59842 + .maxlen = sizeof(int),
59843 + .mode = 0600,
59844 + .proc_handler = &proc_dointvec_minmax,
59845 + .extra1 = &one,
59846 + .extra2 = &one,
59847 + },
59848 +#endif
59849 + { }
59850 +};
59851 +#endif
59852 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59853 new file mode 100644
59854 index 0000000..0dc13c3
59855 --- /dev/null
59856 +++ b/grsecurity/grsec_time.c
59857 @@ -0,0 +1,16 @@
59858 +#include <linux/kernel.h>
59859 +#include <linux/sched.h>
59860 +#include <linux/grinternal.h>
59861 +#include <linux/module.h>
59862 +
59863 +void
59864 +gr_log_timechange(void)
59865 +{
59866 +#ifdef CONFIG_GRKERNSEC_TIME
59867 + if (grsec_enable_time)
59868 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59869 +#endif
59870 + return;
59871 +}
59872 +
59873 +EXPORT_SYMBOL(gr_log_timechange);
59874 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59875 new file mode 100644
59876 index 0000000..07e0dc0
59877 --- /dev/null
59878 +++ b/grsecurity/grsec_tpe.c
59879 @@ -0,0 +1,73 @@
59880 +#include <linux/kernel.h>
59881 +#include <linux/sched.h>
59882 +#include <linux/file.h>
59883 +#include <linux/fs.h>
59884 +#include <linux/grinternal.h>
59885 +
59886 +extern int gr_acl_tpe_check(void);
59887 +
59888 +int
59889 +gr_tpe_allow(const struct file *file)
59890 +{
59891 +#ifdef CONFIG_GRKERNSEC
59892 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59893 + const struct cred *cred = current_cred();
59894 + char *msg = NULL;
59895 + char *msg2 = NULL;
59896 +
59897 + // never restrict root
59898 + if (!cred->uid)
59899 + return 1;
59900 +
59901 + if (grsec_enable_tpe) {
59902 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59903 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59904 + msg = "not being in trusted group";
59905 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59906 + msg = "being in untrusted group";
59907 +#else
59908 + if (in_group_p(grsec_tpe_gid))
59909 + msg = "being in untrusted group";
59910 +#endif
59911 + }
59912 + if (!msg && gr_acl_tpe_check())
59913 + msg = "being in untrusted role";
59914 +
59915 + // not in any affected group/role
59916 + if (!msg)
59917 + goto next_check;
59918 +
59919 + if (inode->i_uid)
59920 + msg2 = "file in non-root-owned directory";
59921 + else if (inode->i_mode & S_IWOTH)
59922 + msg2 = "file in world-writable directory";
59923 + else if (inode->i_mode & S_IWGRP)
59924 + msg2 = "file in group-writable directory";
59925 +
59926 + if (msg && msg2) {
59927 + char fullmsg[70] = {0};
59928 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59929 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59930 + return 0;
59931 + }
59932 + msg = NULL;
59933 +next_check:
59934 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59935 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59936 + return 1;
59937 +
59938 + if (inode->i_uid && (inode->i_uid != cred->uid))
59939 + msg = "directory not owned by user";
59940 + else if (inode->i_mode & S_IWOTH)
59941 + msg = "file in world-writable directory";
59942 + else if (inode->i_mode & S_IWGRP)
59943 + msg = "file in group-writable directory";
59944 +
59945 + if (msg) {
59946 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59947 + return 0;
59948 + }
59949 +#endif
59950 +#endif
59951 + return 1;
59952 +}
59953 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59954 new file mode 100644
59955 index 0000000..9f7b1ac
59956 --- /dev/null
59957 +++ b/grsecurity/grsum.c
59958 @@ -0,0 +1,61 @@
59959 +#include <linux/err.h>
59960 +#include <linux/kernel.h>
59961 +#include <linux/sched.h>
59962 +#include <linux/mm.h>
59963 +#include <linux/scatterlist.h>
59964 +#include <linux/crypto.h>
59965 +#include <linux/gracl.h>
59966 +
59967 +
59968 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59969 +#error "crypto and sha256 must be built into the kernel"
59970 +#endif
59971 +
59972 +int
59973 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59974 +{
59975 + char *p;
59976 + struct crypto_hash *tfm;
59977 + struct hash_desc desc;
59978 + struct scatterlist sg;
59979 + unsigned char temp_sum[GR_SHA_LEN];
59980 + volatile int retval = 0;
59981 + volatile int dummy = 0;
59982 + unsigned int i;
59983 +
59984 + sg_init_table(&sg, 1);
59985 +
59986 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59987 + if (IS_ERR(tfm)) {
59988 + /* should never happen, since sha256 should be built in */
59989 + return 1;
59990 + }
59991 +
59992 + desc.tfm = tfm;
59993 + desc.flags = 0;
59994 +
59995 + crypto_hash_init(&desc);
59996 +
59997 + p = salt;
59998 + sg_set_buf(&sg, p, GR_SALT_LEN);
59999 + crypto_hash_update(&desc, &sg, sg.length);
60000 +
60001 + p = entry->pw;
60002 + sg_set_buf(&sg, p, strlen(p));
60003 +
60004 + crypto_hash_update(&desc, &sg, sg.length);
60005 +
60006 + crypto_hash_final(&desc, temp_sum);
60007 +
60008 + memset(entry->pw, 0, GR_PW_LEN);
60009 +
60010 + for (i = 0; i < GR_SHA_LEN; i++)
60011 + if (sum[i] != temp_sum[i])
60012 + retval = 1;
60013 + else
60014 + dummy = 1; // waste a cycle
60015 +
60016 + crypto_free_hash(tfm);
60017 +
60018 + return retval;
60019 +}
60020 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60021 index 9e6e1c6..d47b906 100644
60022 --- a/include/acpi/acpi_bus.h
60023 +++ b/include/acpi/acpi_bus.h
60024 @@ -138,7 +138,7 @@ struct acpi_device_ops {
60025 acpi_op_bind bind;
60026 acpi_op_unbind unbind;
60027 acpi_op_notify notify;
60028 -};
60029 +} __no_const;
60030
60031 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60032
60033 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60034 index 77ff547..181834f 100644
60035 --- a/include/asm-generic/4level-fixup.h
60036 +++ b/include/asm-generic/4level-fixup.h
60037 @@ -13,8 +13,10 @@
60038 #define pmd_alloc(mm, pud, address) \
60039 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60040 NULL: pmd_offset(pud, address))
60041 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60042
60043 #define pud_alloc(mm, pgd, address) (pgd)
60044 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60045 #define pud_offset(pgd, start) (pgd)
60046 #define pud_none(pud) 0
60047 #define pud_bad(pud) 0
60048 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60049 index b7babf0..3ba8aee 100644
60050 --- a/include/asm-generic/atomic-long.h
60051 +++ b/include/asm-generic/atomic-long.h
60052 @@ -22,6 +22,12 @@
60053
60054 typedef atomic64_t atomic_long_t;
60055
60056 +#ifdef CONFIG_PAX_REFCOUNT
60057 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60058 +#else
60059 +typedef atomic64_t atomic_long_unchecked_t;
60060 +#endif
60061 +
60062 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60063
60064 static inline long atomic_long_read(atomic_long_t *l)
60065 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60066 return (long)atomic64_read(v);
60067 }
60068
60069 +#ifdef CONFIG_PAX_REFCOUNT
60070 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60071 +{
60072 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60073 +
60074 + return (long)atomic64_read_unchecked(v);
60075 +}
60076 +#endif
60077 +
60078 static inline void atomic_long_set(atomic_long_t *l, long i)
60079 {
60080 atomic64_t *v = (atomic64_t *)l;
60081 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60082 atomic64_set(v, i);
60083 }
60084
60085 +#ifdef CONFIG_PAX_REFCOUNT
60086 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60087 +{
60088 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60089 +
60090 + atomic64_set_unchecked(v, i);
60091 +}
60092 +#endif
60093 +
60094 static inline void atomic_long_inc(atomic_long_t *l)
60095 {
60096 atomic64_t *v = (atomic64_t *)l;
60097 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60098 atomic64_inc(v);
60099 }
60100
60101 +#ifdef CONFIG_PAX_REFCOUNT
60102 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60103 +{
60104 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60105 +
60106 + atomic64_inc_unchecked(v);
60107 +}
60108 +#endif
60109 +
60110 static inline void atomic_long_dec(atomic_long_t *l)
60111 {
60112 atomic64_t *v = (atomic64_t *)l;
60113 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60114 atomic64_dec(v);
60115 }
60116
60117 +#ifdef CONFIG_PAX_REFCOUNT
60118 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60119 +{
60120 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60121 +
60122 + atomic64_dec_unchecked(v);
60123 +}
60124 +#endif
60125 +
60126 static inline void atomic_long_add(long i, atomic_long_t *l)
60127 {
60128 atomic64_t *v = (atomic64_t *)l;
60129 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60130 atomic64_add(i, v);
60131 }
60132
60133 +#ifdef CONFIG_PAX_REFCOUNT
60134 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60135 +{
60136 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60137 +
60138 + atomic64_add_unchecked(i, v);
60139 +}
60140 +#endif
60141 +
60142 static inline void atomic_long_sub(long i, atomic_long_t *l)
60143 {
60144 atomic64_t *v = (atomic64_t *)l;
60145 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60146 atomic64_sub(i, v);
60147 }
60148
60149 +#ifdef CONFIG_PAX_REFCOUNT
60150 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60151 +{
60152 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60153 +
60154 + atomic64_sub_unchecked(i, v);
60155 +}
60156 +#endif
60157 +
60158 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60159 {
60160 atomic64_t *v = (atomic64_t *)l;
60161 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60162 return (long)atomic64_inc_return(v);
60163 }
60164
60165 +#ifdef CONFIG_PAX_REFCOUNT
60166 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60167 +{
60168 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60169 +
60170 + return (long)atomic64_inc_return_unchecked(v);
60171 +}
60172 +#endif
60173 +
60174 static inline long atomic_long_dec_return(atomic_long_t *l)
60175 {
60176 atomic64_t *v = (atomic64_t *)l;
60177 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60178
60179 typedef atomic_t atomic_long_t;
60180
60181 +#ifdef CONFIG_PAX_REFCOUNT
60182 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60183 +#else
60184 +typedef atomic_t atomic_long_unchecked_t;
60185 +#endif
60186 +
60187 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60188 static inline long atomic_long_read(atomic_long_t *l)
60189 {
60190 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60191 return (long)atomic_read(v);
60192 }
60193
60194 +#ifdef CONFIG_PAX_REFCOUNT
60195 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60196 +{
60197 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60198 +
60199 + return (long)atomic_read_unchecked(v);
60200 +}
60201 +#endif
60202 +
60203 static inline void atomic_long_set(atomic_long_t *l, long i)
60204 {
60205 atomic_t *v = (atomic_t *)l;
60206 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60207 atomic_set(v, i);
60208 }
60209
60210 +#ifdef CONFIG_PAX_REFCOUNT
60211 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60212 +{
60213 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60214 +
60215 + atomic_set_unchecked(v, i);
60216 +}
60217 +#endif
60218 +
60219 static inline void atomic_long_inc(atomic_long_t *l)
60220 {
60221 atomic_t *v = (atomic_t *)l;
60222 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60223 atomic_inc(v);
60224 }
60225
60226 +#ifdef CONFIG_PAX_REFCOUNT
60227 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60228 +{
60229 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60230 +
60231 + atomic_inc_unchecked(v);
60232 +}
60233 +#endif
60234 +
60235 static inline void atomic_long_dec(atomic_long_t *l)
60236 {
60237 atomic_t *v = (atomic_t *)l;
60238 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60239 atomic_dec(v);
60240 }
60241
60242 +#ifdef CONFIG_PAX_REFCOUNT
60243 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60244 +{
60245 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60246 +
60247 + atomic_dec_unchecked(v);
60248 +}
60249 +#endif
60250 +
60251 static inline void atomic_long_add(long i, atomic_long_t *l)
60252 {
60253 atomic_t *v = (atomic_t *)l;
60254 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60255 atomic_add(i, v);
60256 }
60257
60258 +#ifdef CONFIG_PAX_REFCOUNT
60259 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60260 +{
60261 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60262 +
60263 + atomic_add_unchecked(i, v);
60264 +}
60265 +#endif
60266 +
60267 static inline void atomic_long_sub(long i, atomic_long_t *l)
60268 {
60269 atomic_t *v = (atomic_t *)l;
60270 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60271 atomic_sub(i, v);
60272 }
60273
60274 +#ifdef CONFIG_PAX_REFCOUNT
60275 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60276 +{
60277 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60278 +
60279 + atomic_sub_unchecked(i, v);
60280 +}
60281 +#endif
60282 +
60283 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60284 {
60285 atomic_t *v = (atomic_t *)l;
60286 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60287 return (long)atomic_inc_return(v);
60288 }
60289
60290 +#ifdef CONFIG_PAX_REFCOUNT
60291 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60292 +{
60293 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60294 +
60295 + return (long)atomic_inc_return_unchecked(v);
60296 +}
60297 +#endif
60298 +
60299 static inline long atomic_long_dec_return(atomic_long_t *l)
60300 {
60301 atomic_t *v = (atomic_t *)l;
60302 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60303
60304 #endif /* BITS_PER_LONG == 64 */
60305
60306 +#ifdef CONFIG_PAX_REFCOUNT
60307 +static inline void pax_refcount_needs_these_functions(void)
60308 +{
60309 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60310 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60311 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60312 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60313 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60314 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60315 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60316 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60317 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60318 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60319 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60320 +#ifdef CONFIG_X86
60321 + atomic_clear_mask_unchecked(0, NULL);
60322 + atomic_set_mask_unchecked(0, NULL);
60323 +#endif
60324 +
60325 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60326 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60327 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60328 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60329 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60330 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60331 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60332 +}
60333 +#else
60334 +#define atomic_read_unchecked(v) atomic_read(v)
60335 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60336 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60337 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60338 +#define atomic_inc_unchecked(v) atomic_inc(v)
60339 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60340 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60341 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60342 +#define atomic_dec_unchecked(v) atomic_dec(v)
60343 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60344 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60345 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60346 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60347 +
60348 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60349 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60350 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60351 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60352 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60353 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60354 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60355 +#endif
60356 +
60357 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60358 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60359 index 1ced641..c896ee8 100644
60360 --- a/include/asm-generic/atomic.h
60361 +++ b/include/asm-generic/atomic.h
60362 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60363 * Atomically clears the bits set in @mask from @v
60364 */
60365 #ifndef atomic_clear_mask
60366 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60367 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60368 {
60369 unsigned long flags;
60370
60371 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60372 index b18ce4f..2ee2843 100644
60373 --- a/include/asm-generic/atomic64.h
60374 +++ b/include/asm-generic/atomic64.h
60375 @@ -16,6 +16,8 @@ typedef struct {
60376 long long counter;
60377 } atomic64_t;
60378
60379 +typedef atomic64_t atomic64_unchecked_t;
60380 +
60381 #define ATOMIC64_INIT(i) { (i) }
60382
60383 extern long long atomic64_read(const atomic64_t *v);
60384 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60385 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60386 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60387
60388 +#define atomic64_read_unchecked(v) atomic64_read(v)
60389 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60390 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60391 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60392 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60393 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60394 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60395 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60396 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60397 +
60398 #endif /* _ASM_GENERIC_ATOMIC64_H */
60399 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60400 index 1bfcfe5..e04c5c9 100644
60401 --- a/include/asm-generic/cache.h
60402 +++ b/include/asm-generic/cache.h
60403 @@ -6,7 +6,7 @@
60404 * cache lines need to provide their own cache.h.
60405 */
60406
60407 -#define L1_CACHE_SHIFT 5
60408 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60409 +#define L1_CACHE_SHIFT 5UL
60410 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60411
60412 #endif /* __ASM_GENERIC_CACHE_H */
60413 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60414 index 0d68a1e..b74a761 100644
60415 --- a/include/asm-generic/emergency-restart.h
60416 +++ b/include/asm-generic/emergency-restart.h
60417 @@ -1,7 +1,7 @@
60418 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60419 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60420
60421 -static inline void machine_emergency_restart(void)
60422 +static inline __noreturn void machine_emergency_restart(void)
60423 {
60424 machine_restart(NULL);
60425 }
60426 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60427 index 0232ccb..13d9165 100644
60428 --- a/include/asm-generic/kmap_types.h
60429 +++ b/include/asm-generic/kmap_types.h
60430 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60431 KMAP_D(17) KM_NMI,
60432 KMAP_D(18) KM_NMI_PTE,
60433 KMAP_D(19) KM_KDB,
60434 +KMAP_D(20) KM_CLEARPAGE,
60435 /*
60436 * Remember to update debug_kmap_atomic() when adding new kmap types!
60437 */
60438 -KMAP_D(20) KM_TYPE_NR
60439 +KMAP_D(21) KM_TYPE_NR
60440 };
60441
60442 #undef KMAP_D
60443 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60444 index 9ceb03b..2efbcbd 100644
60445 --- a/include/asm-generic/local.h
60446 +++ b/include/asm-generic/local.h
60447 @@ -39,6 +39,7 @@ typedef struct
60448 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60449 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60450 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60451 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60452
60453 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60454 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60455 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60456 index 725612b..9cc513a 100644
60457 --- a/include/asm-generic/pgtable-nopmd.h
60458 +++ b/include/asm-generic/pgtable-nopmd.h
60459 @@ -1,14 +1,19 @@
60460 #ifndef _PGTABLE_NOPMD_H
60461 #define _PGTABLE_NOPMD_H
60462
60463 -#ifndef __ASSEMBLY__
60464 -
60465 #include <asm-generic/pgtable-nopud.h>
60466
60467 -struct mm_struct;
60468 -
60469 #define __PAGETABLE_PMD_FOLDED
60470
60471 +#define PMD_SHIFT PUD_SHIFT
60472 +#define PTRS_PER_PMD 1
60473 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60474 +#define PMD_MASK (~(PMD_SIZE-1))
60475 +
60476 +#ifndef __ASSEMBLY__
60477 +
60478 +struct mm_struct;
60479 +
60480 /*
60481 * Having the pmd type consist of a pud gets the size right, and allows
60482 * us to conceptually access the pud entry that this pmd is folded into
60483 @@ -16,11 +21,6 @@ struct mm_struct;
60484 */
60485 typedef struct { pud_t pud; } pmd_t;
60486
60487 -#define PMD_SHIFT PUD_SHIFT
60488 -#define PTRS_PER_PMD 1
60489 -#define PMD_SIZE (1UL << PMD_SHIFT)
60490 -#define PMD_MASK (~(PMD_SIZE-1))
60491 -
60492 /*
60493 * The "pud_xxx()" functions here are trivial for a folded two-level
60494 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60495 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60496 index 810431d..0ec4804f 100644
60497 --- a/include/asm-generic/pgtable-nopud.h
60498 +++ b/include/asm-generic/pgtable-nopud.h
60499 @@ -1,10 +1,15 @@
60500 #ifndef _PGTABLE_NOPUD_H
60501 #define _PGTABLE_NOPUD_H
60502
60503 -#ifndef __ASSEMBLY__
60504 -
60505 #define __PAGETABLE_PUD_FOLDED
60506
60507 +#define PUD_SHIFT PGDIR_SHIFT
60508 +#define PTRS_PER_PUD 1
60509 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60510 +#define PUD_MASK (~(PUD_SIZE-1))
60511 +
60512 +#ifndef __ASSEMBLY__
60513 +
60514 /*
60515 * Having the pud type consist of a pgd gets the size right, and allows
60516 * us to conceptually access the pgd entry that this pud is folded into
60517 @@ -12,11 +17,6 @@
60518 */
60519 typedef struct { pgd_t pgd; } pud_t;
60520
60521 -#define PUD_SHIFT PGDIR_SHIFT
60522 -#define PTRS_PER_PUD 1
60523 -#define PUD_SIZE (1UL << PUD_SHIFT)
60524 -#define PUD_MASK (~(PUD_SIZE-1))
60525 -
60526 /*
60527 * The "pgd_xxx()" functions here are trivial for a folded two-level
60528 * setup: the pud is never bad, and a pud always exists (as it's folded
60529 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60530 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60531
60532 #define pgd_populate(mm, pgd, pud) do { } while (0)
60533 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60534 /*
60535 * (puds are folded into pgds so this doesn't get actually called,
60536 * but the define is needed for a generic inline function.)
60537 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60538 index ff4947b..f48183f 100644
60539 --- a/include/asm-generic/pgtable.h
60540 +++ b/include/asm-generic/pgtable.h
60541 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60542 #endif
60543 }
60544
60545 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60546 +static inline unsigned long pax_open_kernel(void) { return 0; }
60547 +#endif
60548 +
60549 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60550 +static inline unsigned long pax_close_kernel(void) { return 0; }
60551 +#endif
60552 +
60553 #endif /* CONFIG_MMU */
60554
60555 #endif /* !__ASSEMBLY__ */
60556 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60557 index 4e2e1cc..12c266b 100644
60558 --- a/include/asm-generic/vmlinux.lds.h
60559 +++ b/include/asm-generic/vmlinux.lds.h
60560 @@ -218,6 +218,7 @@
60561 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60562 VMLINUX_SYMBOL(__start_rodata) = .; \
60563 *(.rodata) *(.rodata.*) \
60564 + *(.data..read_only) \
60565 *(__vermagic) /* Kernel version magic */ \
60566 . = ALIGN(8); \
60567 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60568 @@ -716,17 +717,18 @@
60569 * section in the linker script will go there too. @phdr should have
60570 * a leading colon.
60571 *
60572 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60573 + * Note that this macros defines per_cpu_load as an absolute symbol.
60574 * If there is no need to put the percpu section at a predetermined
60575 * address, use PERCPU_SECTION.
60576 */
60577 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60578 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60579 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60580 + per_cpu_load = .; \
60581 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60582 - LOAD_OFFSET) { \
60583 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60584 PERCPU_INPUT(cacheline) \
60585 } phdr \
60586 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60587 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60588
60589 /**
60590 * PERCPU_SECTION - define output section for percpu area, simple version
60591 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60592 index 31ad880..4e79884 100644
60593 --- a/include/drm/drmP.h
60594 +++ b/include/drm/drmP.h
60595 @@ -72,6 +72,7 @@
60596 #include <linux/workqueue.h>
60597 #include <linux/poll.h>
60598 #include <asm/pgalloc.h>
60599 +#include <asm/local.h>
60600 #include "drm.h"
60601
60602 #include <linux/idr.h>
60603 @@ -1074,7 +1075,7 @@ struct drm_device {
60604
60605 /** \name Usage Counters */
60606 /*@{ */
60607 - int open_count; /**< Outstanding files open */
60608 + local_t open_count; /**< Outstanding files open */
60609 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60610 atomic_t vma_count; /**< Outstanding vma areas open */
60611 int buf_use; /**< Buffers in use -- cannot alloc */
60612 @@ -1085,7 +1086,7 @@ struct drm_device {
60613 /*@{ */
60614 unsigned long counters;
60615 enum drm_stat_type types[15];
60616 - atomic_t counts[15];
60617 + atomic_unchecked_t counts[15];
60618 /*@} */
60619
60620 struct list_head filelist;
60621 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60622 index 7988e55..ec974c9 100644
60623 --- a/include/drm/drm_crtc_helper.h
60624 +++ b/include/drm/drm_crtc_helper.h
60625 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60626
60627 /* disable crtc when not in use - more explicit than dpms off */
60628 void (*disable)(struct drm_crtc *crtc);
60629 -};
60630 +} __no_const;
60631
60632 /**
60633 * drm_encoder_helper_funcs - helper operations for encoders
60634 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60635 struct drm_connector *connector);
60636 /* disable encoder when not in use - more explicit than dpms off */
60637 void (*disable)(struct drm_encoder *encoder);
60638 -};
60639 +} __no_const;
60640
60641 /**
60642 * drm_connector_helper_funcs - helper operations for connectors
60643 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60644 index d6d1da4..fdd1ac5 100644
60645 --- a/include/drm/ttm/ttm_memory.h
60646 +++ b/include/drm/ttm/ttm_memory.h
60647 @@ -48,7 +48,7 @@
60648
60649 struct ttm_mem_shrink {
60650 int (*do_shrink) (struct ttm_mem_shrink *);
60651 -};
60652 +} __no_const;
60653
60654 /**
60655 * struct ttm_mem_global - Global memory accounting structure.
60656 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60657 index e86dfca..40cc55f 100644
60658 --- a/include/linux/a.out.h
60659 +++ b/include/linux/a.out.h
60660 @@ -39,6 +39,14 @@ enum machine_type {
60661 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60662 };
60663
60664 +/* Constants for the N_FLAGS field */
60665 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60666 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60667 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60668 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60669 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60670 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60671 +
60672 #if !defined (N_MAGIC)
60673 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60674 #endif
60675 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60676 index 06fd4bb..1caec0d 100644
60677 --- a/include/linux/atmdev.h
60678 +++ b/include/linux/atmdev.h
60679 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60680 #endif
60681
60682 struct k_atm_aal_stats {
60683 -#define __HANDLE_ITEM(i) atomic_t i
60684 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60685 __AAL_STAT_ITEMS
60686 #undef __HANDLE_ITEM
60687 };
60688 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60689 index 366422b..1fa7f84 100644
60690 --- a/include/linux/binfmts.h
60691 +++ b/include/linux/binfmts.h
60692 @@ -89,6 +89,7 @@ struct linux_binfmt {
60693 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60694 int (*load_shlib)(struct file *);
60695 int (*core_dump)(struct coredump_params *cprm);
60696 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60697 unsigned long min_coredump; /* minimal dump size */
60698 };
60699
60700 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60701 index 07954b0..cb2ae71 100644
60702 --- a/include/linux/blkdev.h
60703 +++ b/include/linux/blkdev.h
60704 @@ -1393,7 +1393,7 @@ struct block_device_operations {
60705 /* this callback is with swap_lock and sometimes page table lock held */
60706 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60707 struct module *owner;
60708 -};
60709 +} __do_const;
60710
60711 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60712 unsigned long);
60713 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60714 index 4d1a074..88f929a 100644
60715 --- a/include/linux/blktrace_api.h
60716 +++ b/include/linux/blktrace_api.h
60717 @@ -162,7 +162,7 @@ struct blk_trace {
60718 struct dentry *dir;
60719 struct dentry *dropped_file;
60720 struct dentry *msg_file;
60721 - atomic_t dropped;
60722 + atomic_unchecked_t dropped;
60723 };
60724
60725 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60726 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60727 index 83195fb..0b0f77d 100644
60728 --- a/include/linux/byteorder/little_endian.h
60729 +++ b/include/linux/byteorder/little_endian.h
60730 @@ -42,51 +42,51 @@
60731
60732 static inline __le64 __cpu_to_le64p(const __u64 *p)
60733 {
60734 - return (__force __le64)*p;
60735 + return (__force const __le64)*p;
60736 }
60737 static inline __u64 __le64_to_cpup(const __le64 *p)
60738 {
60739 - return (__force __u64)*p;
60740 + return (__force const __u64)*p;
60741 }
60742 static inline __le32 __cpu_to_le32p(const __u32 *p)
60743 {
60744 - return (__force __le32)*p;
60745 + return (__force const __le32)*p;
60746 }
60747 static inline __u32 __le32_to_cpup(const __le32 *p)
60748 {
60749 - return (__force __u32)*p;
60750 + return (__force const __u32)*p;
60751 }
60752 static inline __le16 __cpu_to_le16p(const __u16 *p)
60753 {
60754 - return (__force __le16)*p;
60755 + return (__force const __le16)*p;
60756 }
60757 static inline __u16 __le16_to_cpup(const __le16 *p)
60758 {
60759 - return (__force __u16)*p;
60760 + return (__force const __u16)*p;
60761 }
60762 static inline __be64 __cpu_to_be64p(const __u64 *p)
60763 {
60764 - return (__force __be64)__swab64p(p);
60765 + return (__force const __be64)__swab64p(p);
60766 }
60767 static inline __u64 __be64_to_cpup(const __be64 *p)
60768 {
60769 - return __swab64p((__u64 *)p);
60770 + return __swab64p((const __u64 *)p);
60771 }
60772 static inline __be32 __cpu_to_be32p(const __u32 *p)
60773 {
60774 - return (__force __be32)__swab32p(p);
60775 + return (__force const __be32)__swab32p(p);
60776 }
60777 static inline __u32 __be32_to_cpup(const __be32 *p)
60778 {
60779 - return __swab32p((__u32 *)p);
60780 + return __swab32p((const __u32 *)p);
60781 }
60782 static inline __be16 __cpu_to_be16p(const __u16 *p)
60783 {
60784 - return (__force __be16)__swab16p(p);
60785 + return (__force const __be16)__swab16p(p);
60786 }
60787 static inline __u16 __be16_to_cpup(const __be16 *p)
60788 {
60789 - return __swab16p((__u16 *)p);
60790 + return __swab16p((const __u16 *)p);
60791 }
60792 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60793 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60794 diff --git a/include/linux/cache.h b/include/linux/cache.h
60795 index 4c57065..4307975 100644
60796 --- a/include/linux/cache.h
60797 +++ b/include/linux/cache.h
60798 @@ -16,6 +16,10 @@
60799 #define __read_mostly
60800 #endif
60801
60802 +#ifndef __read_only
60803 +#define __read_only __read_mostly
60804 +#endif
60805 +
60806 #ifndef ____cacheline_aligned
60807 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60808 #endif
60809 diff --git a/include/linux/capability.h b/include/linux/capability.h
60810 index d10b7ed..0288b79 100644
60811 --- a/include/linux/capability.h
60812 +++ b/include/linux/capability.h
60813 @@ -553,10 +553,15 @@ extern bool capable(int cap);
60814 extern bool ns_capable(struct user_namespace *ns, int cap);
60815 extern bool nsown_capable(int cap);
60816 extern bool inode_capable(const struct inode *inode, int cap);
60817 +extern bool capable_nolog(int cap);
60818 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60819 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
60820
60821 /* audit system wants to get cap info from files as well */
60822 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60823
60824 +extern int is_privileged_binary(const struct dentry *dentry);
60825 +
60826 #endif /* __KERNEL__ */
60827
60828 #endif /* !_LINUX_CAPABILITY_H */
60829 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60830 index 42e55de..1cd0e66 100644
60831 --- a/include/linux/cleancache.h
60832 +++ b/include/linux/cleancache.h
60833 @@ -31,7 +31,7 @@ struct cleancache_ops {
60834 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60835 void (*invalidate_inode)(int, struct cleancache_filekey);
60836 void (*invalidate_fs)(int);
60837 -};
60838 +} __no_const;
60839
60840 extern struct cleancache_ops
60841 cleancache_register_ops(struct cleancache_ops *ops);
60842 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
60843 index 4a0b483..f1f70ba 100644
60844 --- a/include/linux/clk-provider.h
60845 +++ b/include/linux/clk-provider.h
60846 @@ -110,6 +110,7 @@ struct clk_ops {
60847 unsigned long);
60848 void (*init)(struct clk_hw *hw);
60849 };
60850 +typedef struct clk_ops __no_const clk_ops_no_const;
60851
60852 /**
60853 * struct clk_init_data - holds init data that's common to all clocks and is
60854 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60855 index 2f40791..9c9e13c 100644
60856 --- a/include/linux/compiler-gcc4.h
60857 +++ b/include/linux/compiler-gcc4.h
60858 @@ -32,6 +32,20 @@
60859 #define __linktime_error(message) __attribute__((__error__(message)))
60860
60861 #if __GNUC_MINOR__ >= 5
60862 +
60863 +#ifdef CONSTIFY_PLUGIN
60864 +#define __no_const __attribute__((no_const))
60865 +#define __do_const __attribute__((do_const))
60866 +#endif
60867 +
60868 +#ifdef SIZE_OVERFLOW_PLUGIN
60869 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60870 +#endif
60871 +
60872 +#ifdef LATENT_ENTROPY_PLUGIN
60873 +#define __latent_entropy __attribute__((latent_entropy))
60874 +#endif
60875 +
60876 /*
60877 * Mark a position in code as unreachable. This can be used to
60878 * suppress control flow warnings after asm blocks that transfer
60879 @@ -47,6 +61,11 @@
60880 #define __noclone __attribute__((__noclone__))
60881
60882 #endif
60883 +
60884 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60885 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60886 +#define __bos0(ptr) __bos((ptr), 0)
60887 +#define __bos1(ptr) __bos((ptr), 1)
60888 #endif
60889
60890 #if __GNUC_MINOR__ > 0
60891 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60892 index 923d093..1fef491 100644
60893 --- a/include/linux/compiler.h
60894 +++ b/include/linux/compiler.h
60895 @@ -5,31 +5,62 @@
60896
60897 #ifdef __CHECKER__
60898 # define __user __attribute__((noderef, address_space(1)))
60899 +# define __force_user __force __user
60900 # define __kernel __attribute__((address_space(0)))
60901 +# define __force_kernel __force __kernel
60902 # define __safe __attribute__((safe))
60903 # define __force __attribute__((force))
60904 # define __nocast __attribute__((nocast))
60905 # define __iomem __attribute__((noderef, address_space(2)))
60906 +# define __force_iomem __force __iomem
60907 # define __acquires(x) __attribute__((context(x,0,1)))
60908 # define __releases(x) __attribute__((context(x,1,0)))
60909 # define __acquire(x) __context__(x,1)
60910 # define __release(x) __context__(x,-1)
60911 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60912 # define __percpu __attribute__((noderef, address_space(3)))
60913 +# define __force_percpu __force __percpu
60914 #ifdef CONFIG_SPARSE_RCU_POINTER
60915 # define __rcu __attribute__((noderef, address_space(4)))
60916 +# define __force_rcu __force __rcu
60917 #else
60918 # define __rcu
60919 +# define __force_rcu
60920 #endif
60921 extern void __chk_user_ptr(const volatile void __user *);
60922 extern void __chk_io_ptr(const volatile void __iomem *);
60923 +#elif defined(CHECKER_PLUGIN)
60924 +//# define __user
60925 +//# define __force_user
60926 +//# define __kernel
60927 +//# define __force_kernel
60928 +# define __safe
60929 +# define __force
60930 +# define __nocast
60931 +# define __iomem
60932 +# define __force_iomem
60933 +# define __chk_user_ptr(x) (void)0
60934 +# define __chk_io_ptr(x) (void)0
60935 +# define __builtin_warning(x, y...) (1)
60936 +# define __acquires(x)
60937 +# define __releases(x)
60938 +# define __acquire(x) (void)0
60939 +# define __release(x) (void)0
60940 +# define __cond_lock(x,c) (c)
60941 +# define __percpu
60942 +# define __force_percpu
60943 +# define __rcu
60944 +# define __force_rcu
60945 #else
60946 # define __user
60947 +# define __force_user
60948 # define __kernel
60949 +# define __force_kernel
60950 # define __safe
60951 # define __force
60952 # define __nocast
60953 # define __iomem
60954 +# define __force_iomem
60955 # define __chk_user_ptr(x) (void)0
60956 # define __chk_io_ptr(x) (void)0
60957 # define __builtin_warning(x, y...) (1)
60958 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60959 # define __release(x) (void)0
60960 # define __cond_lock(x,c) (c)
60961 # define __percpu
60962 +# define __force_percpu
60963 # define __rcu
60964 +# define __force_rcu
60965 #endif
60966
60967 #ifdef __KERNEL__
60968 @@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60969 # define __attribute_const__ /* unimplemented */
60970 #endif
60971
60972 +#ifndef __no_const
60973 +# define __no_const
60974 +#endif
60975 +
60976 +#ifndef __do_const
60977 +# define __do_const
60978 +#endif
60979 +
60980 +#ifndef __size_overflow
60981 +# define __size_overflow(...)
60982 +#endif
60983 +
60984 +#ifndef __latent_entropy
60985 +# define __latent_entropy
60986 +#endif
60987 +
60988 /*
60989 * Tell gcc if a function is cold. The compiler will assume any path
60990 * directly leading to the call is unlikely.
60991 @@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60992 #define __cold
60993 #endif
60994
60995 +#ifndef __alloc_size
60996 +#define __alloc_size(...)
60997 +#endif
60998 +
60999 +#ifndef __bos
61000 +#define __bos(ptr, arg)
61001 +#endif
61002 +
61003 +#ifndef __bos0
61004 +#define __bos0(ptr)
61005 +#endif
61006 +
61007 +#ifndef __bos1
61008 +#define __bos1(ptr)
61009 +#endif
61010 +
61011 /* Simple shorthand for a section definition */
61012 #ifndef __section
61013 # define __section(S) __attribute__ ((__section__(#S)))
61014 @@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61015 * use is to mediate communication between process-level code and irq/NMI
61016 * handlers, all running on the same CPU.
61017 */
61018 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61019 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61020 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61021
61022 #endif /* __LINUX_COMPILER_H */
61023 diff --git a/include/linux/cred.h b/include/linux/cred.h
61024 index ebbed2c..908cc2c 100644
61025 --- a/include/linux/cred.h
61026 +++ b/include/linux/cred.h
61027 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61028 static inline void validate_process_creds(void)
61029 {
61030 }
61031 +static inline void validate_task_creds(struct task_struct *task)
61032 +{
61033 +}
61034 #endif
61035
61036 /**
61037 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61038 index b92eadf..b4ecdc1 100644
61039 --- a/include/linux/crypto.h
61040 +++ b/include/linux/crypto.h
61041 @@ -373,7 +373,7 @@ struct cipher_tfm {
61042 const u8 *key, unsigned int keylen);
61043 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61044 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61045 -};
61046 +} __no_const;
61047
61048 struct hash_tfm {
61049 int (*init)(struct hash_desc *desc);
61050 @@ -394,13 +394,13 @@ struct compress_tfm {
61051 int (*cot_decompress)(struct crypto_tfm *tfm,
61052 const u8 *src, unsigned int slen,
61053 u8 *dst, unsigned int *dlen);
61054 -};
61055 +} __no_const;
61056
61057 struct rng_tfm {
61058 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61059 unsigned int dlen);
61060 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61061 -};
61062 +} __no_const;
61063
61064 #define crt_ablkcipher crt_u.ablkcipher
61065 #define crt_aead crt_u.aead
61066 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61067 index 7925bf0..d5143d2 100644
61068 --- a/include/linux/decompress/mm.h
61069 +++ b/include/linux/decompress/mm.h
61070 @@ -77,7 +77,7 @@ static void free(void *where)
61071 * warnings when not needed (indeed large_malloc / large_free are not
61072 * needed by inflate */
61073
61074 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61075 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61076 #define free(a) kfree(a)
61077
61078 #define large_malloc(a) vmalloc(a)
61079 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61080 index dfc099e..e583e66 100644
61081 --- a/include/linux/dma-mapping.h
61082 +++ b/include/linux/dma-mapping.h
61083 @@ -51,7 +51,7 @@ struct dma_map_ops {
61084 u64 (*get_required_mask)(struct device *dev);
61085 #endif
61086 int is_phys;
61087 -};
61088 +} __do_const;
61089
61090 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61091
61092 diff --git a/include/linux/efi.h b/include/linux/efi.h
61093 index ec45ccd..9923c32 100644
61094 --- a/include/linux/efi.h
61095 +++ b/include/linux/efi.h
61096 @@ -635,7 +635,7 @@ struct efivar_operations {
61097 efi_get_variable_t *get_variable;
61098 efi_get_next_variable_t *get_next_variable;
61099 efi_set_variable_t *set_variable;
61100 -};
61101 +} __no_const;
61102
61103 struct efivars {
61104 /*
61105 diff --git a/include/linux/elf.h b/include/linux/elf.h
61106 index 999b4f5..57753b4 100644
61107 --- a/include/linux/elf.h
61108 +++ b/include/linux/elf.h
61109 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61110 #define PT_GNU_EH_FRAME 0x6474e550
61111
61112 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61113 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61114 +
61115 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61116 +
61117 +/* Constants for the e_flags field */
61118 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61119 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61120 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61121 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61122 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61123 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61124
61125 /*
61126 * Extended Numbering
61127 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61128 #define DT_DEBUG 21
61129 #define DT_TEXTREL 22
61130 #define DT_JMPREL 23
61131 +#define DT_FLAGS 30
61132 + #define DF_TEXTREL 0x00000004
61133 #define DT_ENCODING 32
61134 #define OLD_DT_LOOS 0x60000000
61135 #define DT_LOOS 0x6000000d
61136 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61137 #define PF_W 0x2
61138 #define PF_X 0x1
61139
61140 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61141 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61142 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61143 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61144 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61145 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61146 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61147 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61148 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61149 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61150 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61151 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61152 +
61153 typedef struct elf32_phdr{
61154 Elf32_Word p_type;
61155 Elf32_Off p_offset;
61156 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61157 #define EI_OSABI 7
61158 #define EI_PAD 8
61159
61160 +#define EI_PAX 14
61161 +
61162 #define ELFMAG0 0x7f /* EI_MAG */
61163 #define ELFMAG1 'E'
61164 #define ELFMAG2 'L'
61165 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61166 #define elf_note elf32_note
61167 #define elf_addr_t Elf32_Off
61168 #define Elf_Half Elf32_Half
61169 +#define elf_dyn Elf32_Dyn
61170
61171 #else
61172
61173 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61174 #define elf_note elf64_note
61175 #define elf_addr_t Elf64_Off
61176 #define Elf_Half Elf64_Half
61177 +#define elf_dyn Elf64_Dyn
61178
61179 #endif
61180
61181 diff --git a/include/linux/filter.h b/include/linux/filter.h
61182 index 82b0135..917914d 100644
61183 --- a/include/linux/filter.h
61184 +++ b/include/linux/filter.h
61185 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61186
61187 struct sk_buff;
61188 struct sock;
61189 +struct bpf_jit_work;
61190
61191 struct sk_filter
61192 {
61193 @@ -153,6 +154,9 @@ struct sk_filter
61194 unsigned int len; /* Number of filter blocks */
61195 unsigned int (*bpf_func)(const struct sk_buff *skb,
61196 const struct sock_filter *filter);
61197 +#ifdef CONFIG_BPF_JIT
61198 + struct bpf_jit_work *work;
61199 +#endif
61200 struct rcu_head rcu;
61201 struct sock_filter insns[0];
61202 };
61203 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61204 index 7edcf10..714d5e8 100644
61205 --- a/include/linux/firewire.h
61206 +++ b/include/linux/firewire.h
61207 @@ -430,7 +430,7 @@ struct fw_iso_context {
61208 union {
61209 fw_iso_callback_t sc;
61210 fw_iso_mc_callback_t mc;
61211 - } callback;
61212 + } __no_const callback;
61213 void *callback_data;
61214 };
61215
61216 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61217 index 0e4e2ee..4ff4312 100644
61218 --- a/include/linux/frontswap.h
61219 +++ b/include/linux/frontswap.h
61220 @@ -11,7 +11,7 @@ struct frontswap_ops {
61221 int (*load)(unsigned, pgoff_t, struct page *);
61222 void (*invalidate_page)(unsigned, pgoff_t);
61223 void (*invalidate_area)(unsigned);
61224 -};
61225 +} __no_const;
61226
61227 extern bool frontswap_enabled;
61228 extern struct frontswap_ops
61229 diff --git a/include/linux/fs.h b/include/linux/fs.h
61230 index 17fd887..8eebca0 100644
61231 --- a/include/linux/fs.h
61232 +++ b/include/linux/fs.h
61233 @@ -1663,7 +1663,8 @@ struct file_operations {
61234 int (*setlease)(struct file *, long, struct file_lock **);
61235 long (*fallocate)(struct file *file, int mode, loff_t offset,
61236 loff_t len);
61237 -};
61238 +} __do_const;
61239 +typedef struct file_operations __no_const file_operations_no_const;
61240
61241 struct inode_operations {
61242 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61243 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61244 index 003dc0f..3c4ea97 100644
61245 --- a/include/linux/fs_struct.h
61246 +++ b/include/linux/fs_struct.h
61247 @@ -6,7 +6,7 @@
61248 #include <linux/seqlock.h>
61249
61250 struct fs_struct {
61251 - int users;
61252 + atomic_t users;
61253 spinlock_t lock;
61254 seqcount_t seq;
61255 int umask;
61256 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61257 index ce31408..b1ad003 100644
61258 --- a/include/linux/fscache-cache.h
61259 +++ b/include/linux/fscache-cache.h
61260 @@ -102,7 +102,7 @@ struct fscache_operation {
61261 fscache_operation_release_t release;
61262 };
61263
61264 -extern atomic_t fscache_op_debug_id;
61265 +extern atomic_unchecked_t fscache_op_debug_id;
61266 extern void fscache_op_work_func(struct work_struct *work);
61267
61268 extern void fscache_enqueue_operation(struct fscache_operation *);
61269 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61270 {
61271 INIT_WORK(&op->work, fscache_op_work_func);
61272 atomic_set(&op->usage, 1);
61273 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61274 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61275 op->processor = processor;
61276 op->release = release;
61277 INIT_LIST_HEAD(&op->pend_link);
61278 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61279 index a6dfe69..569586df 100644
61280 --- a/include/linux/fsnotify.h
61281 +++ b/include/linux/fsnotify.h
61282 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61283 */
61284 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61285 {
61286 - return kstrdup(name, GFP_KERNEL);
61287 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61288 }
61289
61290 /*
61291 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61292 index 63d966d..cdcb717 100644
61293 --- a/include/linux/fsnotify_backend.h
61294 +++ b/include/linux/fsnotify_backend.h
61295 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61296 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61297 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61298 };
61299 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61300
61301 /*
61302 * A group is a "thing" that wants to receive notification about filesystem
61303 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61304 index 176a939..1462211 100644
61305 --- a/include/linux/ftrace_event.h
61306 +++ b/include/linux/ftrace_event.h
61307 @@ -97,7 +97,7 @@ struct trace_event_functions {
61308 trace_print_func raw;
61309 trace_print_func hex;
61310 trace_print_func binary;
61311 -};
61312 +} __no_const;
61313
61314 struct trace_event {
61315 struct hlist_node node;
61316 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61317 extern int trace_add_event_call(struct ftrace_event_call *call);
61318 extern void trace_remove_event_call(struct ftrace_event_call *call);
61319
61320 -#define is_signed_type(type) (((type)(-1)) < 0)
61321 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61322
61323 int trace_set_clr_event(const char *system, const char *event, int set);
61324
61325 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61326 index 017a7fb..33a8507 100644
61327 --- a/include/linux/genhd.h
61328 +++ b/include/linux/genhd.h
61329 @@ -185,7 +185,7 @@ struct gendisk {
61330 struct kobject *slave_dir;
61331
61332 struct timer_rand_state *random;
61333 - atomic_t sync_io; /* RAID */
61334 + atomic_unchecked_t sync_io; /* RAID */
61335 struct disk_events *ev;
61336 #ifdef CONFIG_BLK_DEV_INTEGRITY
61337 struct blk_integrity *integrity;
61338 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61339 index 1e49be4..b8a9305 100644
61340 --- a/include/linux/gfp.h
61341 +++ b/include/linux/gfp.h
61342 @@ -38,6 +38,12 @@ struct vm_area_struct;
61343 #define ___GFP_OTHER_NODE 0x800000u
61344 #define ___GFP_WRITE 0x1000000u
61345
61346 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61347 +#define ___GFP_USERCOPY 0x2000000u
61348 +#else
61349 +#define ___GFP_USERCOPY 0
61350 +#endif
61351 +
61352 /*
61353 * GFP bitmasks..
61354 *
61355 @@ -87,6 +93,7 @@ struct vm_area_struct;
61356 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61357 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61358 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61359 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61360
61361 /*
61362 * This may seem redundant, but it's a way of annotating false positives vs.
61363 @@ -94,7 +101,7 @@ struct vm_area_struct;
61364 */
61365 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61366
61367 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61368 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61369 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61370
61371 /* This equals 0, but use constants in case they ever change */
61372 @@ -148,6 +155,8 @@ struct vm_area_struct;
61373 /* 4GB DMA on some platforms */
61374 #define GFP_DMA32 __GFP_DMA32
61375
61376 +#define GFP_USERCOPY __GFP_USERCOPY
61377 +
61378 /* Convert GFP flags to their corresponding migrate type */
61379 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61380 {
61381 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61382 new file mode 100644
61383 index 0000000..c938b1f
61384 --- /dev/null
61385 +++ b/include/linux/gracl.h
61386 @@ -0,0 +1,319 @@
61387 +#ifndef GR_ACL_H
61388 +#define GR_ACL_H
61389 +
61390 +#include <linux/grdefs.h>
61391 +#include <linux/resource.h>
61392 +#include <linux/capability.h>
61393 +#include <linux/dcache.h>
61394 +#include <asm/resource.h>
61395 +
61396 +/* Major status information */
61397 +
61398 +#define GR_VERSION "grsecurity 2.9.1"
61399 +#define GRSECURITY_VERSION 0x2901
61400 +
61401 +enum {
61402 + GR_SHUTDOWN = 0,
61403 + GR_ENABLE = 1,
61404 + GR_SPROLE = 2,
61405 + GR_RELOAD = 3,
61406 + GR_SEGVMOD = 4,
61407 + GR_STATUS = 5,
61408 + GR_UNSPROLE = 6,
61409 + GR_PASSSET = 7,
61410 + GR_SPROLEPAM = 8,
61411 +};
61412 +
61413 +/* Password setup definitions
61414 + * kernel/grhash.c */
61415 +enum {
61416 + GR_PW_LEN = 128,
61417 + GR_SALT_LEN = 16,
61418 + GR_SHA_LEN = 32,
61419 +};
61420 +
61421 +enum {
61422 + GR_SPROLE_LEN = 64,
61423 +};
61424 +
61425 +enum {
61426 + GR_NO_GLOB = 0,
61427 + GR_REG_GLOB,
61428 + GR_CREATE_GLOB
61429 +};
61430 +
61431 +#define GR_NLIMITS 32
61432 +
61433 +/* Begin Data Structures */
61434 +
61435 +struct sprole_pw {
61436 + unsigned char *rolename;
61437 + unsigned char salt[GR_SALT_LEN];
61438 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61439 +};
61440 +
61441 +struct name_entry {
61442 + __u32 key;
61443 + ino_t inode;
61444 + dev_t device;
61445 + char *name;
61446 + __u16 len;
61447 + __u8 deleted;
61448 + struct name_entry *prev;
61449 + struct name_entry *next;
61450 +};
61451 +
61452 +struct inodev_entry {
61453 + struct name_entry *nentry;
61454 + struct inodev_entry *prev;
61455 + struct inodev_entry *next;
61456 +};
61457 +
61458 +struct acl_role_db {
61459 + struct acl_role_label **r_hash;
61460 + __u32 r_size;
61461 +};
61462 +
61463 +struct inodev_db {
61464 + struct inodev_entry **i_hash;
61465 + __u32 i_size;
61466 +};
61467 +
61468 +struct name_db {
61469 + struct name_entry **n_hash;
61470 + __u32 n_size;
61471 +};
61472 +
61473 +struct crash_uid {
61474 + uid_t uid;
61475 + unsigned long expires;
61476 +};
61477 +
61478 +struct gr_hash_struct {
61479 + void **table;
61480 + void **nametable;
61481 + void *first;
61482 + __u32 table_size;
61483 + __u32 used_size;
61484 + int type;
61485 +};
61486 +
61487 +/* Userspace Grsecurity ACL data structures */
61488 +
61489 +struct acl_subject_label {
61490 + char *filename;
61491 + ino_t inode;
61492 + dev_t device;
61493 + __u32 mode;
61494 + kernel_cap_t cap_mask;
61495 + kernel_cap_t cap_lower;
61496 + kernel_cap_t cap_invert_audit;
61497 +
61498 + struct rlimit res[GR_NLIMITS];
61499 + __u32 resmask;
61500 +
61501 + __u8 user_trans_type;
61502 + __u8 group_trans_type;
61503 + uid_t *user_transitions;
61504 + gid_t *group_transitions;
61505 + __u16 user_trans_num;
61506 + __u16 group_trans_num;
61507 +
61508 + __u32 sock_families[2];
61509 + __u32 ip_proto[8];
61510 + __u32 ip_type;
61511 + struct acl_ip_label **ips;
61512 + __u32 ip_num;
61513 + __u32 inaddr_any_override;
61514 +
61515 + __u32 crashes;
61516 + unsigned long expires;
61517 +
61518 + struct acl_subject_label *parent_subject;
61519 + struct gr_hash_struct *hash;
61520 + struct acl_subject_label *prev;
61521 + struct acl_subject_label *next;
61522 +
61523 + struct acl_object_label **obj_hash;
61524 + __u32 obj_hash_size;
61525 + __u16 pax_flags;
61526 +};
61527 +
61528 +struct role_allowed_ip {
61529 + __u32 addr;
61530 + __u32 netmask;
61531 +
61532 + struct role_allowed_ip *prev;
61533 + struct role_allowed_ip *next;
61534 +};
61535 +
61536 +struct role_transition {
61537 + char *rolename;
61538 +
61539 + struct role_transition *prev;
61540 + struct role_transition *next;
61541 +};
61542 +
61543 +struct acl_role_label {
61544 + char *rolename;
61545 + uid_t uidgid;
61546 + __u16 roletype;
61547 +
61548 + __u16 auth_attempts;
61549 + unsigned long expires;
61550 +
61551 + struct acl_subject_label *root_label;
61552 + struct gr_hash_struct *hash;
61553 +
61554 + struct acl_role_label *prev;
61555 + struct acl_role_label *next;
61556 +
61557 + struct role_transition *transitions;
61558 + struct role_allowed_ip *allowed_ips;
61559 + uid_t *domain_children;
61560 + __u16 domain_child_num;
61561 +
61562 + umode_t umask;
61563 +
61564 + struct acl_subject_label **subj_hash;
61565 + __u32 subj_hash_size;
61566 +};
61567 +
61568 +struct user_acl_role_db {
61569 + struct acl_role_label **r_table;
61570 + __u32 num_pointers; /* Number of allocations to track */
61571 + __u32 num_roles; /* Number of roles */
61572 + __u32 num_domain_children; /* Number of domain children */
61573 + __u32 num_subjects; /* Number of subjects */
61574 + __u32 num_objects; /* Number of objects */
61575 +};
61576 +
61577 +struct acl_object_label {
61578 + char *filename;
61579 + ino_t inode;
61580 + dev_t device;
61581 + __u32 mode;
61582 +
61583 + struct acl_subject_label *nested;
61584 + struct acl_object_label *globbed;
61585 +
61586 + /* next two structures not used */
61587 +
61588 + struct acl_object_label *prev;
61589 + struct acl_object_label *next;
61590 +};
61591 +
61592 +struct acl_ip_label {
61593 + char *iface;
61594 + __u32 addr;
61595 + __u32 netmask;
61596 + __u16 low, high;
61597 + __u8 mode;
61598 + __u32 type;
61599 + __u32 proto[8];
61600 +
61601 + /* next two structures not used */
61602 +
61603 + struct acl_ip_label *prev;
61604 + struct acl_ip_label *next;
61605 +};
61606 +
61607 +struct gr_arg {
61608 + struct user_acl_role_db role_db;
61609 + unsigned char pw[GR_PW_LEN];
61610 + unsigned char salt[GR_SALT_LEN];
61611 + unsigned char sum[GR_SHA_LEN];
61612 + unsigned char sp_role[GR_SPROLE_LEN];
61613 + struct sprole_pw *sprole_pws;
61614 + dev_t segv_device;
61615 + ino_t segv_inode;
61616 + uid_t segv_uid;
61617 + __u16 num_sprole_pws;
61618 + __u16 mode;
61619 +};
61620 +
61621 +struct gr_arg_wrapper {
61622 + struct gr_arg *arg;
61623 + __u32 version;
61624 + __u32 size;
61625 +};
61626 +
61627 +struct subject_map {
61628 + struct acl_subject_label *user;
61629 + struct acl_subject_label *kernel;
61630 + struct subject_map *prev;
61631 + struct subject_map *next;
61632 +};
61633 +
61634 +struct acl_subj_map_db {
61635 + struct subject_map **s_hash;
61636 + __u32 s_size;
61637 +};
61638 +
61639 +/* End Data Structures Section */
61640 +
61641 +/* Hash functions generated by empirical testing by Brad Spengler
61642 + Makes good use of the low bits of the inode. Generally 0-1 times
61643 + in loop for successful match. 0-3 for unsuccessful match.
61644 + Shift/add algorithm with modulus of table size and an XOR*/
61645 +
61646 +static __inline__ unsigned int
61647 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61648 +{
61649 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61650 +}
61651 +
61652 + static __inline__ unsigned int
61653 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61654 +{
61655 + return ((const unsigned long)userp % sz);
61656 +}
61657 +
61658 +static __inline__ unsigned int
61659 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61660 +{
61661 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61662 +}
61663 +
61664 +static __inline__ unsigned int
61665 +nhash(const char *name, const __u16 len, const unsigned int sz)
61666 +{
61667 + return full_name_hash((const unsigned char *)name, len) % sz;
61668 +}
61669 +
61670 +#define FOR_EACH_ROLE_START(role) \
61671 + role = role_list; \
61672 + while (role) {
61673 +
61674 +#define FOR_EACH_ROLE_END(role) \
61675 + role = role->prev; \
61676 + }
61677 +
61678 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61679 + subj = NULL; \
61680 + iter = 0; \
61681 + while (iter < role->subj_hash_size) { \
61682 + if (subj == NULL) \
61683 + subj = role->subj_hash[iter]; \
61684 + if (subj == NULL) { \
61685 + iter++; \
61686 + continue; \
61687 + }
61688 +
61689 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61690 + subj = subj->next; \
61691 + if (subj == NULL) \
61692 + iter++; \
61693 + }
61694 +
61695 +
61696 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61697 + subj = role->hash->first; \
61698 + while (subj != NULL) {
61699 +
61700 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61701 + subj = subj->next; \
61702 + }
61703 +
61704 +#endif
61705 +
61706 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61707 new file mode 100644
61708 index 0000000..323ecf2
61709 --- /dev/null
61710 +++ b/include/linux/gralloc.h
61711 @@ -0,0 +1,9 @@
61712 +#ifndef __GRALLOC_H
61713 +#define __GRALLOC_H
61714 +
61715 +void acl_free_all(void);
61716 +int acl_alloc_stack_init(unsigned long size);
61717 +void *acl_alloc(unsigned long len);
61718 +void *acl_alloc_num(unsigned long num, unsigned long len);
61719 +
61720 +#endif
61721 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61722 new file mode 100644
61723 index 0000000..b30e9bc
61724 --- /dev/null
61725 +++ b/include/linux/grdefs.h
61726 @@ -0,0 +1,140 @@
61727 +#ifndef GRDEFS_H
61728 +#define GRDEFS_H
61729 +
61730 +/* Begin grsecurity status declarations */
61731 +
61732 +enum {
61733 + GR_READY = 0x01,
61734 + GR_STATUS_INIT = 0x00 // disabled state
61735 +};
61736 +
61737 +/* Begin ACL declarations */
61738 +
61739 +/* Role flags */
61740 +
61741 +enum {
61742 + GR_ROLE_USER = 0x0001,
61743 + GR_ROLE_GROUP = 0x0002,
61744 + GR_ROLE_DEFAULT = 0x0004,
61745 + GR_ROLE_SPECIAL = 0x0008,
61746 + GR_ROLE_AUTH = 0x0010,
61747 + GR_ROLE_NOPW = 0x0020,
61748 + GR_ROLE_GOD = 0x0040,
61749 + GR_ROLE_LEARN = 0x0080,
61750 + GR_ROLE_TPE = 0x0100,
61751 + GR_ROLE_DOMAIN = 0x0200,
61752 + GR_ROLE_PAM = 0x0400,
61753 + GR_ROLE_PERSIST = 0x0800
61754 +};
61755 +
61756 +/* ACL Subject and Object mode flags */
61757 +enum {
61758 + GR_DELETED = 0x80000000
61759 +};
61760 +
61761 +/* ACL Object-only mode flags */
61762 +enum {
61763 + GR_READ = 0x00000001,
61764 + GR_APPEND = 0x00000002,
61765 + GR_WRITE = 0x00000004,
61766 + GR_EXEC = 0x00000008,
61767 + GR_FIND = 0x00000010,
61768 + GR_INHERIT = 0x00000020,
61769 + GR_SETID = 0x00000040,
61770 + GR_CREATE = 0x00000080,
61771 + GR_DELETE = 0x00000100,
61772 + GR_LINK = 0x00000200,
61773 + GR_AUDIT_READ = 0x00000400,
61774 + GR_AUDIT_APPEND = 0x00000800,
61775 + GR_AUDIT_WRITE = 0x00001000,
61776 + GR_AUDIT_EXEC = 0x00002000,
61777 + GR_AUDIT_FIND = 0x00004000,
61778 + GR_AUDIT_INHERIT= 0x00008000,
61779 + GR_AUDIT_SETID = 0x00010000,
61780 + GR_AUDIT_CREATE = 0x00020000,
61781 + GR_AUDIT_DELETE = 0x00040000,
61782 + GR_AUDIT_LINK = 0x00080000,
61783 + GR_PTRACERD = 0x00100000,
61784 + GR_NOPTRACE = 0x00200000,
61785 + GR_SUPPRESS = 0x00400000,
61786 + GR_NOLEARN = 0x00800000,
61787 + GR_INIT_TRANSFER= 0x01000000
61788 +};
61789 +
61790 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61791 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61792 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61793 +
61794 +/* ACL subject-only mode flags */
61795 +enum {
61796 + GR_KILL = 0x00000001,
61797 + GR_VIEW = 0x00000002,
61798 + GR_PROTECTED = 0x00000004,
61799 + GR_LEARN = 0x00000008,
61800 + GR_OVERRIDE = 0x00000010,
61801 + /* just a placeholder, this mode is only used in userspace */
61802 + GR_DUMMY = 0x00000020,
61803 + GR_PROTSHM = 0x00000040,
61804 + GR_KILLPROC = 0x00000080,
61805 + GR_KILLIPPROC = 0x00000100,
61806 + /* just a placeholder, this mode is only used in userspace */
61807 + GR_NOTROJAN = 0x00000200,
61808 + GR_PROTPROCFD = 0x00000400,
61809 + GR_PROCACCT = 0x00000800,
61810 + GR_RELAXPTRACE = 0x00001000,
61811 + GR_NESTED = 0x00002000,
61812 + GR_INHERITLEARN = 0x00004000,
61813 + GR_PROCFIND = 0x00008000,
61814 + GR_POVERRIDE = 0x00010000,
61815 + GR_KERNELAUTH = 0x00020000,
61816 + GR_ATSECURE = 0x00040000,
61817 + GR_SHMEXEC = 0x00080000
61818 +};
61819 +
61820 +enum {
61821 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61822 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61823 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61824 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61825 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61826 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61827 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61828 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61829 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61830 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61831 +};
61832 +
61833 +enum {
61834 + GR_ID_USER = 0x01,
61835 + GR_ID_GROUP = 0x02,
61836 +};
61837 +
61838 +enum {
61839 + GR_ID_ALLOW = 0x01,
61840 + GR_ID_DENY = 0x02,
61841 +};
61842 +
61843 +#define GR_CRASH_RES 31
61844 +#define GR_UIDTABLE_MAX 500
61845 +
61846 +/* begin resource learning section */
61847 +enum {
61848 + GR_RLIM_CPU_BUMP = 60,
61849 + GR_RLIM_FSIZE_BUMP = 50000,
61850 + GR_RLIM_DATA_BUMP = 10000,
61851 + GR_RLIM_STACK_BUMP = 1000,
61852 + GR_RLIM_CORE_BUMP = 10000,
61853 + GR_RLIM_RSS_BUMP = 500000,
61854 + GR_RLIM_NPROC_BUMP = 1,
61855 + GR_RLIM_NOFILE_BUMP = 5,
61856 + GR_RLIM_MEMLOCK_BUMP = 50000,
61857 + GR_RLIM_AS_BUMP = 500000,
61858 + GR_RLIM_LOCKS_BUMP = 2,
61859 + GR_RLIM_SIGPENDING_BUMP = 5,
61860 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61861 + GR_RLIM_NICE_BUMP = 1,
61862 + GR_RLIM_RTPRIO_BUMP = 1,
61863 + GR_RLIM_RTTIME_BUMP = 1000000
61864 +};
61865 +
61866 +#endif
61867 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61868 new file mode 100644
61869 index 0000000..c9292f7
61870 --- /dev/null
61871 +++ b/include/linux/grinternal.h
61872 @@ -0,0 +1,223 @@
61873 +#ifndef __GRINTERNAL_H
61874 +#define __GRINTERNAL_H
61875 +
61876 +#ifdef CONFIG_GRKERNSEC
61877 +
61878 +#include <linux/fs.h>
61879 +#include <linux/mnt_namespace.h>
61880 +#include <linux/nsproxy.h>
61881 +#include <linux/gracl.h>
61882 +#include <linux/grdefs.h>
61883 +#include <linux/grmsg.h>
61884 +
61885 +void gr_add_learn_entry(const char *fmt, ...)
61886 + __attribute__ ((format (printf, 1, 2)));
61887 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61888 + const struct vfsmount *mnt);
61889 +__u32 gr_check_create(const struct dentry *new_dentry,
61890 + const struct dentry *parent,
61891 + const struct vfsmount *mnt, const __u32 mode);
61892 +int gr_check_protected_task(const struct task_struct *task);
61893 +__u32 to_gr_audit(const __u32 reqmode);
61894 +int gr_set_acls(const int type);
61895 +int gr_apply_subject_to_task(struct task_struct *task);
61896 +int gr_acl_is_enabled(void);
61897 +char gr_roletype_to_char(void);
61898 +
61899 +void gr_handle_alertkill(struct task_struct *task);
61900 +char *gr_to_filename(const struct dentry *dentry,
61901 + const struct vfsmount *mnt);
61902 +char *gr_to_filename1(const struct dentry *dentry,
61903 + const struct vfsmount *mnt);
61904 +char *gr_to_filename2(const struct dentry *dentry,
61905 + const struct vfsmount *mnt);
61906 +char *gr_to_filename3(const struct dentry *dentry,
61907 + const struct vfsmount *mnt);
61908 +
61909 +extern int grsec_enable_ptrace_readexec;
61910 +extern int grsec_enable_harden_ptrace;
61911 +extern int grsec_enable_link;
61912 +extern int grsec_enable_fifo;
61913 +extern int grsec_enable_execve;
61914 +extern int grsec_enable_shm;
61915 +extern int grsec_enable_execlog;
61916 +extern int grsec_enable_signal;
61917 +extern int grsec_enable_audit_ptrace;
61918 +extern int grsec_enable_forkfail;
61919 +extern int grsec_enable_time;
61920 +extern int grsec_enable_rofs;
61921 +extern int grsec_enable_chroot_shmat;
61922 +extern int grsec_enable_chroot_mount;
61923 +extern int grsec_enable_chroot_double;
61924 +extern int grsec_enable_chroot_pivot;
61925 +extern int grsec_enable_chroot_chdir;
61926 +extern int grsec_enable_chroot_chmod;
61927 +extern int grsec_enable_chroot_mknod;
61928 +extern int grsec_enable_chroot_fchdir;
61929 +extern int grsec_enable_chroot_nice;
61930 +extern int grsec_enable_chroot_execlog;
61931 +extern int grsec_enable_chroot_caps;
61932 +extern int grsec_enable_chroot_sysctl;
61933 +extern int grsec_enable_chroot_unix;
61934 +extern int grsec_enable_symlinkown;
61935 +extern int grsec_symlinkown_gid;
61936 +extern int grsec_enable_tpe;
61937 +extern int grsec_tpe_gid;
61938 +extern int grsec_enable_tpe_all;
61939 +extern int grsec_enable_tpe_invert;
61940 +extern int grsec_enable_socket_all;
61941 +extern int grsec_socket_all_gid;
61942 +extern int grsec_enable_socket_client;
61943 +extern int grsec_socket_client_gid;
61944 +extern int grsec_enable_socket_server;
61945 +extern int grsec_socket_server_gid;
61946 +extern int grsec_audit_gid;
61947 +extern int grsec_enable_group;
61948 +extern int grsec_enable_audit_textrel;
61949 +extern int grsec_enable_log_rwxmaps;
61950 +extern int grsec_enable_mount;
61951 +extern int grsec_enable_chdir;
61952 +extern int grsec_resource_logging;
61953 +extern int grsec_enable_blackhole;
61954 +extern int grsec_lastack_retries;
61955 +extern int grsec_enable_brute;
61956 +extern int grsec_lock;
61957 +
61958 +extern spinlock_t grsec_alert_lock;
61959 +extern unsigned long grsec_alert_wtime;
61960 +extern unsigned long grsec_alert_fyet;
61961 +
61962 +extern spinlock_t grsec_audit_lock;
61963 +
61964 +extern rwlock_t grsec_exec_file_lock;
61965 +
61966 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61967 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61968 + (tsk)->exec_file->f_vfsmnt) : "/")
61969 +
61970 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61971 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61972 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61973 +
61974 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61975 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61976 + (tsk)->exec_file->f_vfsmnt) : "/")
61977 +
61978 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61979 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61980 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61981 +
61982 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61983 +
61984 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61985 +
61986 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61987 + (task)->pid, (cred)->uid, \
61988 + (cred)->euid, (cred)->gid, (cred)->egid, \
61989 + gr_parent_task_fullpath(task), \
61990 + (task)->real_parent->comm, (task)->real_parent->pid, \
61991 + (pcred)->uid, (pcred)->euid, \
61992 + (pcred)->gid, (pcred)->egid
61993 +
61994 +#define GR_CHROOT_CAPS {{ \
61995 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61996 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61997 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61998 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61999 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62000 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62001 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62002 +
62003 +#define security_learn(normal_msg,args...) \
62004 +({ \
62005 + read_lock(&grsec_exec_file_lock); \
62006 + gr_add_learn_entry(normal_msg "\n", ## args); \
62007 + read_unlock(&grsec_exec_file_lock); \
62008 +})
62009 +
62010 +enum {
62011 + GR_DO_AUDIT,
62012 + GR_DONT_AUDIT,
62013 + /* used for non-audit messages that we shouldn't kill the task on */
62014 + GR_DONT_AUDIT_GOOD
62015 +};
62016 +
62017 +enum {
62018 + GR_TTYSNIFF,
62019 + GR_RBAC,
62020 + GR_RBAC_STR,
62021 + GR_STR_RBAC,
62022 + GR_RBAC_MODE2,
62023 + GR_RBAC_MODE3,
62024 + GR_FILENAME,
62025 + GR_SYSCTL_HIDDEN,
62026 + GR_NOARGS,
62027 + GR_ONE_INT,
62028 + GR_ONE_INT_TWO_STR,
62029 + GR_ONE_STR,
62030 + GR_STR_INT,
62031 + GR_TWO_STR_INT,
62032 + GR_TWO_INT,
62033 + GR_TWO_U64,
62034 + GR_THREE_INT,
62035 + GR_FIVE_INT_TWO_STR,
62036 + GR_TWO_STR,
62037 + GR_THREE_STR,
62038 + GR_FOUR_STR,
62039 + GR_STR_FILENAME,
62040 + GR_FILENAME_STR,
62041 + GR_FILENAME_TWO_INT,
62042 + GR_FILENAME_TWO_INT_STR,
62043 + GR_TEXTREL,
62044 + GR_PTRACE,
62045 + GR_RESOURCE,
62046 + GR_CAP,
62047 + GR_SIG,
62048 + GR_SIG2,
62049 + GR_CRASH1,
62050 + GR_CRASH2,
62051 + GR_PSACCT,
62052 + GR_RWXMAP
62053 +};
62054 +
62055 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62056 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62057 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62058 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62059 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62060 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62061 +#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)
62062 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62063 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62064 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62065 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62066 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62067 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62068 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62069 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62070 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62071 +#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)
62072 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62073 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62074 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62075 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62076 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62077 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62078 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62079 +#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)
62080 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62081 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62082 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62083 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62084 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62085 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62086 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62087 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62088 +#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)
62089 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62090 +
62091 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62092 +
62093 +#endif
62094 +
62095 +#endif
62096 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62097 new file mode 100644
62098 index 0000000..54f4e85
62099 --- /dev/null
62100 +++ b/include/linux/grmsg.h
62101 @@ -0,0 +1,110 @@
62102 +#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"
62103 +#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"
62104 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62105 +#define GR_STOPMOD_MSG "denied modification of module state by "
62106 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62107 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62108 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62109 +#define GR_IOPL_MSG "denied use of iopl() by "
62110 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62111 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62112 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62113 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62114 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62115 +#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"
62116 +#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"
62117 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62118 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62119 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62120 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62121 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62122 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62123 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62124 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62125 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62126 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62127 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62128 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62129 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62130 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62131 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62132 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62133 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62134 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62135 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62136 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62137 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62138 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62139 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62140 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62141 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62142 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62143 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62144 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62145 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62146 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62147 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62148 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62149 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62150 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62151 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62152 +#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"
62153 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62154 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62155 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62156 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62157 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62158 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62159 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62160 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62161 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62162 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62163 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62164 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62165 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62166 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62167 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62168 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62169 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62170 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62171 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62172 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62173 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62174 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62175 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62176 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62177 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62178 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62179 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62180 +#define GR_TIME_MSG "time set by "
62181 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62182 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62183 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62184 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62185 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62186 +#define GR_BIND_MSG "denied bind() by "
62187 +#define GR_CONNECT_MSG "denied connect() by "
62188 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62189 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62190 +#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"
62191 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62192 +#define GR_CAP_ACL_MSG "use of %s denied for "
62193 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62194 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62195 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62196 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62197 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62198 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62199 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62200 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62201 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62202 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62203 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62204 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62205 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62206 +#define GR_VM86_MSG "denied use of vm86 by "
62207 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62208 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62209 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62210 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62211 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62212 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62213 new file mode 100644
62214 index 0000000..38bfb04
62215 --- /dev/null
62216 +++ b/include/linux/grsecurity.h
62217 @@ -0,0 +1,233 @@
62218 +#ifndef GR_SECURITY_H
62219 +#define GR_SECURITY_H
62220 +#include <linux/fs.h>
62221 +#include <linux/fs_struct.h>
62222 +#include <linux/binfmts.h>
62223 +#include <linux/gracl.h>
62224 +
62225 +/* notify of brain-dead configs */
62226 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62227 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62228 +#endif
62229 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62230 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62231 +#endif
62232 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62233 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62234 +#endif
62235 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62236 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62237 +#endif
62238 +
62239 +#include <linux/compat.h>
62240 +
62241 +struct user_arg_ptr {
62242 +#ifdef CONFIG_COMPAT
62243 + bool is_compat;
62244 +#endif
62245 + union {
62246 + const char __user *const __user *native;
62247 +#ifdef CONFIG_COMPAT
62248 + compat_uptr_t __user *compat;
62249 +#endif
62250 + } ptr;
62251 +};
62252 +
62253 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62254 +void gr_handle_brute_check(void);
62255 +void gr_handle_kernel_exploit(void);
62256 +int gr_process_user_ban(void);
62257 +
62258 +char gr_roletype_to_char(void);
62259 +
62260 +int gr_acl_enable_at_secure(void);
62261 +
62262 +int gr_check_user_change(int real, int effective, int fs);
62263 +int gr_check_group_change(int real, int effective, int fs);
62264 +
62265 +void gr_del_task_from_ip_table(struct task_struct *p);
62266 +
62267 +int gr_pid_is_chrooted(struct task_struct *p);
62268 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62269 +int gr_handle_chroot_nice(void);
62270 +int gr_handle_chroot_sysctl(const int op);
62271 +int gr_handle_chroot_setpriority(struct task_struct *p,
62272 + const int niceval);
62273 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62274 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62275 + const struct vfsmount *mnt);
62276 +void gr_handle_chroot_chdir(struct path *path);
62277 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62278 + const struct vfsmount *mnt, const int mode);
62279 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62280 + const struct vfsmount *mnt, const int mode);
62281 +int gr_handle_chroot_mount(const struct dentry *dentry,
62282 + const struct vfsmount *mnt,
62283 + const char *dev_name);
62284 +int gr_handle_chroot_pivot(void);
62285 +int gr_handle_chroot_unix(const pid_t pid);
62286 +
62287 +int gr_handle_rawio(const struct inode *inode);
62288 +
62289 +void gr_handle_ioperm(void);
62290 +void gr_handle_iopl(void);
62291 +
62292 +umode_t gr_acl_umask(void);
62293 +
62294 +int gr_tpe_allow(const struct file *file);
62295 +
62296 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62297 +void gr_clear_chroot_entries(struct task_struct *task);
62298 +
62299 +void gr_log_forkfail(const int retval);
62300 +void gr_log_timechange(void);
62301 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62302 +void gr_log_chdir(const struct dentry *dentry,
62303 + const struct vfsmount *mnt);
62304 +void gr_log_chroot_exec(const struct dentry *dentry,
62305 + const struct vfsmount *mnt);
62306 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62307 +void gr_log_remount(const char *devname, const int retval);
62308 +void gr_log_unmount(const char *devname, const int retval);
62309 +void gr_log_mount(const char *from, const char *to, const int retval);
62310 +void gr_log_textrel(struct vm_area_struct *vma);
62311 +void gr_log_rwxmmap(struct file *file);
62312 +void gr_log_rwxmprotect(struct file *file);
62313 +
62314 +int gr_handle_follow_link(const struct inode *parent,
62315 + const struct inode *inode,
62316 + const struct dentry *dentry,
62317 + const struct vfsmount *mnt);
62318 +int gr_handle_fifo(const struct dentry *dentry,
62319 + const struct vfsmount *mnt,
62320 + const struct dentry *dir, const int flag,
62321 + const int acc_mode);
62322 +int gr_handle_hardlink(const struct dentry *dentry,
62323 + const struct vfsmount *mnt,
62324 + struct inode *inode,
62325 + const int mode, const char *to);
62326 +
62327 +int gr_is_capable(const int cap);
62328 +int gr_is_capable_nolog(const int cap);
62329 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62330 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62331 +
62332 +void gr_learn_resource(const struct task_struct *task, const int limit,
62333 + const unsigned long wanted, const int gt);
62334 +void gr_copy_label(struct task_struct *tsk);
62335 +void gr_handle_crash(struct task_struct *task, const int sig);
62336 +int gr_handle_signal(const struct task_struct *p, const int sig);
62337 +int gr_check_crash_uid(const uid_t uid);
62338 +int gr_check_protected_task(const struct task_struct *task);
62339 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62340 +int gr_acl_handle_mmap(const struct file *file,
62341 + const unsigned long prot);
62342 +int gr_acl_handle_mprotect(const struct file *file,
62343 + const unsigned long prot);
62344 +int gr_check_hidden_task(const struct task_struct *tsk);
62345 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62346 + const struct vfsmount *mnt);
62347 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62348 + const struct vfsmount *mnt);
62349 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62350 + const struct vfsmount *mnt, const int fmode);
62351 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62352 + const struct vfsmount *mnt, umode_t *mode);
62353 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62354 + const struct vfsmount *mnt);
62355 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62356 + const struct vfsmount *mnt);
62357 +int gr_handle_ptrace(struct task_struct *task, const long request);
62358 +int gr_handle_proc_ptrace(struct task_struct *task);
62359 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62360 + const struct vfsmount *mnt);
62361 +int gr_check_crash_exec(const struct file *filp);
62362 +int gr_acl_is_enabled(void);
62363 +void gr_set_kernel_label(struct task_struct *task);
62364 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62365 + const gid_t gid);
62366 +int gr_set_proc_label(const struct dentry *dentry,
62367 + const struct vfsmount *mnt,
62368 + const int unsafe_flags);
62369 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62370 + const struct vfsmount *mnt);
62371 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62372 + const struct vfsmount *mnt, int acc_mode);
62373 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62374 + const struct dentry *p_dentry,
62375 + const struct vfsmount *p_mnt,
62376 + int open_flags, int acc_mode, const int imode);
62377 +void gr_handle_create(const struct dentry *dentry,
62378 + const struct vfsmount *mnt);
62379 +void gr_handle_proc_create(const struct dentry *dentry,
62380 + const struct inode *inode);
62381 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62382 + const struct dentry *parent_dentry,
62383 + const struct vfsmount *parent_mnt,
62384 + const int mode);
62385 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62386 + const struct dentry *parent_dentry,
62387 + const struct vfsmount *parent_mnt);
62388 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62389 + const struct vfsmount *mnt);
62390 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62391 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62392 + const struct vfsmount *mnt);
62393 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62394 + const struct dentry *parent_dentry,
62395 + const struct vfsmount *parent_mnt,
62396 + const char *from);
62397 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62398 + const struct dentry *parent_dentry,
62399 + const struct vfsmount *parent_mnt,
62400 + const struct dentry *old_dentry,
62401 + const struct vfsmount *old_mnt, const char *to);
62402 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62403 +int gr_acl_handle_rename(struct dentry *new_dentry,
62404 + struct dentry *parent_dentry,
62405 + const struct vfsmount *parent_mnt,
62406 + struct dentry *old_dentry,
62407 + struct inode *old_parent_inode,
62408 + struct vfsmount *old_mnt, const char *newname);
62409 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62410 + struct dentry *old_dentry,
62411 + struct dentry *new_dentry,
62412 + struct vfsmount *mnt, const __u8 replace);
62413 +__u32 gr_check_link(const struct dentry *new_dentry,
62414 + const struct dentry *parent_dentry,
62415 + const struct vfsmount *parent_mnt,
62416 + const struct dentry *old_dentry,
62417 + const struct vfsmount *old_mnt);
62418 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62419 + const unsigned int namelen, const ino_t ino);
62420 +
62421 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62422 + const struct vfsmount *mnt);
62423 +void gr_acl_handle_exit(void);
62424 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62425 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62426 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62427 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62428 +void gr_audit_ptrace(struct task_struct *task);
62429 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62430 +
62431 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62432 +
62433 +#ifdef CONFIG_GRKERNSEC
62434 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62435 +void gr_handle_vm86(void);
62436 +void gr_handle_mem_readwrite(u64 from, u64 to);
62437 +
62438 +void gr_log_badprocpid(const char *entry);
62439 +
62440 +extern int grsec_enable_dmesg;
62441 +extern int grsec_disable_privio;
62442 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62443 +extern int grsec_enable_chroot_findtask;
62444 +#endif
62445 +#ifdef CONFIG_GRKERNSEC_SETXID
62446 +extern int grsec_enable_setxid;
62447 +#endif
62448 +#endif
62449 +
62450 +#endif
62451 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62452 new file mode 100644
62453 index 0000000..e7ffaaf
62454 --- /dev/null
62455 +++ b/include/linux/grsock.h
62456 @@ -0,0 +1,19 @@
62457 +#ifndef __GRSOCK_H
62458 +#define __GRSOCK_H
62459 +
62460 +extern void gr_attach_curr_ip(const struct sock *sk);
62461 +extern int gr_handle_sock_all(const int family, const int type,
62462 + const int protocol);
62463 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62464 +extern int gr_handle_sock_server_other(const struct sock *sck);
62465 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62466 +extern int gr_search_connect(struct socket * sock,
62467 + struct sockaddr_in * addr);
62468 +extern int gr_search_bind(struct socket * sock,
62469 + struct sockaddr_in * addr);
62470 +extern int gr_search_listen(struct socket * sock);
62471 +extern int gr_search_accept(struct socket * sock);
62472 +extern int gr_search_socket(const int domain, const int type,
62473 + const int protocol);
62474 +
62475 +#endif
62476 diff --git a/include/linux/hid.h b/include/linux/hid.h
62477 index 449fa38..b37c8cc 100644
62478 --- a/include/linux/hid.h
62479 +++ b/include/linux/hid.h
62480 @@ -704,7 +704,7 @@ struct hid_ll_driver {
62481 unsigned int code, int value);
62482
62483 int (*parse)(struct hid_device *hdev);
62484 -};
62485 +} __no_const;
62486
62487 #define PM_HINT_FULLON 1<<5
62488 #define PM_HINT_NORMAL 1<<1
62489 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62490 index d3999b4..1304cb4 100644
62491 --- a/include/linux/highmem.h
62492 +++ b/include/linux/highmem.h
62493 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62494 kunmap_atomic(kaddr);
62495 }
62496
62497 +static inline void sanitize_highpage(struct page *page)
62498 +{
62499 + void *kaddr;
62500 + unsigned long flags;
62501 +
62502 + local_irq_save(flags);
62503 + kaddr = kmap_atomic(page);
62504 + clear_page(kaddr);
62505 + kunmap_atomic(kaddr);
62506 + local_irq_restore(flags);
62507 +}
62508 +
62509 static inline void zero_user_segments(struct page *page,
62510 unsigned start1, unsigned end1,
62511 unsigned start2, unsigned end2)
62512 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62513 index ddfa041..a44cfff 100644
62514 --- a/include/linux/i2c.h
62515 +++ b/include/linux/i2c.h
62516 @@ -366,6 +366,7 @@ struct i2c_algorithm {
62517 /* To determine what the adapter supports */
62518 u32 (*functionality) (struct i2c_adapter *);
62519 };
62520 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62521
62522 /*
62523 * i2c_adapter is the structure used to identify a physical i2c bus along
62524 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62525 index d23c3c2..eb63c81 100644
62526 --- a/include/linux/i2o.h
62527 +++ b/include/linux/i2o.h
62528 @@ -565,7 +565,7 @@ struct i2o_controller {
62529 struct i2o_device *exec; /* Executive */
62530 #if BITS_PER_LONG == 64
62531 spinlock_t context_list_lock; /* lock for context_list */
62532 - atomic_t context_list_counter; /* needed for unique contexts */
62533 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62534 struct list_head context_list; /* list of context id's
62535 and pointers */
62536 #endif
62537 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62538 index 8185f57..7b2d222 100644
62539 --- a/include/linux/if_team.h
62540 +++ b/include/linux/if_team.h
62541 @@ -74,6 +74,7 @@ struct team_mode_ops {
62542 void (*port_leave)(struct team *team, struct team_port *port);
62543 void (*port_change_mac)(struct team *team, struct team_port *port);
62544 };
62545 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62546
62547 enum team_option_type {
62548 TEAM_OPTION_TYPE_U32,
62549 @@ -136,7 +137,7 @@ struct team {
62550 struct list_head option_inst_list; /* list of option instances */
62551
62552 const struct team_mode *mode;
62553 - struct team_mode_ops ops;
62554 + team_mode_ops_no_const ops;
62555 long mode_priv[TEAM_MODE_PRIV_LONGS];
62556 };
62557
62558 diff --git a/include/linux/init.h b/include/linux/init.h
62559 index 6b95109..7616d09 100644
62560 --- a/include/linux/init.h
62561 +++ b/include/linux/init.h
62562 @@ -39,9 +39,15 @@
62563 * Also note, that this data cannot be "const".
62564 */
62565
62566 +#ifdef MODULE
62567 +#define add_latent_entropy
62568 +#else
62569 +#define add_latent_entropy __latent_entropy
62570 +#endif
62571 +
62572 /* These are for everybody (although not all archs will actually
62573 discard it in modules) */
62574 -#define __init __section(.init.text) __cold notrace
62575 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62576 #define __initdata __section(.init.data)
62577 #define __initconst __section(.init.rodata)
62578 #define __exitdata __section(.exit.data)
62579 @@ -83,7 +89,7 @@
62580 #define __exit __section(.exit.text) __exitused __cold notrace
62581
62582 /* Used for HOTPLUG */
62583 -#define __devinit __section(.devinit.text) __cold notrace
62584 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62585 #define __devinitdata __section(.devinit.data)
62586 #define __devinitconst __section(.devinit.rodata)
62587 #define __devexit __section(.devexit.text) __exitused __cold notrace
62588 @@ -91,7 +97,7 @@
62589 #define __devexitconst __section(.devexit.rodata)
62590
62591 /* Used for HOTPLUG_CPU */
62592 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62593 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62594 #define __cpuinitdata __section(.cpuinit.data)
62595 #define __cpuinitconst __section(.cpuinit.rodata)
62596 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62597 @@ -99,7 +105,7 @@
62598 #define __cpuexitconst __section(.cpuexit.rodata)
62599
62600 /* Used for MEMORY_HOTPLUG */
62601 -#define __meminit __section(.meminit.text) __cold notrace
62602 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62603 #define __meminitdata __section(.meminit.data)
62604 #define __meminitconst __section(.meminit.rodata)
62605 #define __memexit __section(.memexit.text) __exitused __cold notrace
62606 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62607 index 9e65eff..b131e8b 100644
62608 --- a/include/linux/init_task.h
62609 +++ b/include/linux/init_task.h
62610 @@ -134,6 +134,12 @@ extern struct cred init_cred;
62611
62612 #define INIT_TASK_COMM "swapper"
62613
62614 +#ifdef CONFIG_X86
62615 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62616 +#else
62617 +#define INIT_TASK_THREAD_INFO
62618 +#endif
62619 +
62620 /*
62621 * INIT_TASK is used to set up the first task table, touch at
62622 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62623 @@ -172,6 +178,7 @@ extern struct cred init_cred;
62624 RCU_INIT_POINTER(.cred, &init_cred), \
62625 .comm = INIT_TASK_COMM, \
62626 .thread = INIT_THREAD, \
62627 + INIT_TASK_THREAD_INFO \
62628 .fs = &init_fs, \
62629 .files = &init_files, \
62630 .signal = &init_signals, \
62631 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62632 index e6ca56d..8583707 100644
62633 --- a/include/linux/intel-iommu.h
62634 +++ b/include/linux/intel-iommu.h
62635 @@ -296,7 +296,7 @@ struct iommu_flush {
62636 u8 fm, u64 type);
62637 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62638 unsigned int size_order, u64 type);
62639 -};
62640 +} __no_const;
62641
62642 enum {
62643 SR_DMAR_FECTL_REG,
62644 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62645 index e68a8e5..811b9af 100644
62646 --- a/include/linux/interrupt.h
62647 +++ b/include/linux/interrupt.h
62648 @@ -435,7 +435,7 @@ enum
62649 /* map softirq index to softirq name. update 'softirq_to_name' in
62650 * kernel/softirq.c when adding a new softirq.
62651 */
62652 -extern char *softirq_to_name[NR_SOFTIRQS];
62653 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62654
62655 /* softirq mask and active fields moved to irq_cpustat_t in
62656 * asm/hardirq.h to get better cache usage. KAO
62657 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62658
62659 struct softirq_action
62660 {
62661 - void (*action)(struct softirq_action *);
62662 + void (*action)(void);
62663 };
62664
62665 asmlinkage void do_softirq(void);
62666 asmlinkage void __do_softirq(void);
62667 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62668 +extern void open_softirq(int nr, void (*action)(void));
62669 extern void softirq_init(void);
62670 extern void __raise_softirq_irqoff(unsigned int nr);
62671
62672 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62673 index 6883e19..06992b1 100644
62674 --- a/include/linux/kallsyms.h
62675 +++ b/include/linux/kallsyms.h
62676 @@ -15,7 +15,8 @@
62677
62678 struct module;
62679
62680 -#ifdef CONFIG_KALLSYMS
62681 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62682 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62683 /* Lookup the address for a symbol. Returns 0 if not found. */
62684 unsigned long kallsyms_lookup_name(const char *name);
62685
62686 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62687 /* Stupid that this does nothing, but I didn't create this mess. */
62688 #define __print_symbol(fmt, addr)
62689 #endif /*CONFIG_KALLSYMS*/
62690 +#else /* when included by kallsyms.c, vsnprintf.c, or
62691 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62692 +extern void __print_symbol(const char *fmt, unsigned long address);
62693 +extern int sprint_backtrace(char *buffer, unsigned long address);
62694 +extern int sprint_symbol(char *buffer, unsigned long address);
62695 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62696 +const char *kallsyms_lookup(unsigned long addr,
62697 + unsigned long *symbolsize,
62698 + unsigned long *offset,
62699 + char **modname, char *namebuf);
62700 +#endif
62701
62702 /* This macro allows us to keep printk typechecking */
62703 static __printf(1, 2)
62704 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62705 index c4d2fc1..5df9c19 100644
62706 --- a/include/linux/kgdb.h
62707 +++ b/include/linux/kgdb.h
62708 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62709 extern int kgdb_io_module_registered;
62710
62711 extern atomic_t kgdb_setting_breakpoint;
62712 -extern atomic_t kgdb_cpu_doing_single_step;
62713 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62714
62715 extern struct task_struct *kgdb_usethread;
62716 extern struct task_struct *kgdb_contthread;
62717 @@ -252,7 +252,7 @@ struct kgdb_arch {
62718 void (*disable_hw_break)(struct pt_regs *regs);
62719 void (*remove_all_hw_break)(void);
62720 void (*correct_hw_break)(void);
62721 -};
62722 +} __do_const;
62723
62724 /**
62725 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62726 @@ -277,7 +277,7 @@ struct kgdb_io {
62727 void (*pre_exception) (void);
62728 void (*post_exception) (void);
62729 int is_console;
62730 -};
62731 +} __do_const;
62732
62733 extern struct kgdb_arch arch_kgdb_ops;
62734
62735 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62736 index 5398d58..5883a34 100644
62737 --- a/include/linux/kmod.h
62738 +++ b/include/linux/kmod.h
62739 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62740 * usually useless though. */
62741 extern __printf(2, 3)
62742 int __request_module(bool wait, const char *name, ...);
62743 +extern __printf(3, 4)
62744 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62745 #define request_module(mod...) __request_module(true, mod)
62746 #define request_module_nowait(mod...) __request_module(false, mod)
62747 #define try_then_request_module(x, mod...) \
62748 diff --git a/include/linux/kref.h b/include/linux/kref.h
62749 index 9c07dce..a92fa71 100644
62750 --- a/include/linux/kref.h
62751 +++ b/include/linux/kref.h
62752 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62753 static inline int kref_sub(struct kref *kref, unsigned int count,
62754 void (*release)(struct kref *kref))
62755 {
62756 - WARN_ON(release == NULL);
62757 + BUG_ON(release == NULL);
62758
62759 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62760 release(kref);
62761 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62762 index 96c158a..1864db5 100644
62763 --- a/include/linux/kvm_host.h
62764 +++ b/include/linux/kvm_host.h
62765 @@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62766 void vcpu_load(struct kvm_vcpu *vcpu);
62767 void vcpu_put(struct kvm_vcpu *vcpu);
62768
62769 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62770 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62771 struct module *module);
62772 void kvm_exit(void);
62773
62774 @@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62775 struct kvm_guest_debug *dbg);
62776 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62777
62778 -int kvm_arch_init(void *opaque);
62779 +int kvm_arch_init(const void *opaque);
62780 void kvm_arch_exit(void);
62781
62782 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62783 diff --git a/include/linux/libata.h b/include/linux/libata.h
62784 index 6e887c7..4539601 100644
62785 --- a/include/linux/libata.h
62786 +++ b/include/linux/libata.h
62787 @@ -910,7 +910,7 @@ struct ata_port_operations {
62788 * fields must be pointers.
62789 */
62790 const struct ata_port_operations *inherits;
62791 -};
62792 +} __do_const;
62793
62794 struct ata_port_info {
62795 unsigned long flags;
62796 diff --git a/include/linux/memory.h b/include/linux/memory.h
62797 index 1ac7f6e..a5794d0 100644
62798 --- a/include/linux/memory.h
62799 +++ b/include/linux/memory.h
62800 @@ -143,7 +143,7 @@ struct memory_accessor {
62801 size_t count);
62802 ssize_t (*write)(struct memory_accessor *, const char *buf,
62803 off_t offset, size_t count);
62804 -};
62805 +} __no_const;
62806
62807 /*
62808 * Kernel text modification mutex, used for code patching. Users of this lock
62809 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62810 index 1318ca6..7521340 100644
62811 --- a/include/linux/mfd/abx500.h
62812 +++ b/include/linux/mfd/abx500.h
62813 @@ -452,6 +452,7 @@ struct abx500_ops {
62814 int (*event_registers_startup_state_get) (struct device *, u8 *);
62815 int (*startup_irq_enabled) (struct device *, unsigned int);
62816 };
62817 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62818
62819 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62820 void abx500_remove_ops(struct device *dev);
62821 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62822 index 9b07725..3d55001 100644
62823 --- a/include/linux/mfd/abx500/ux500_chargalg.h
62824 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
62825 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
62826 int (*enable) (struct ux500_charger *, int, int, int);
62827 int (*kick_wd) (struct ux500_charger *);
62828 int (*update_curr) (struct ux500_charger *, int);
62829 -};
62830 +} __no_const;
62831
62832 /**
62833 * struct ux500_charger - power supply ux500 charger sub class
62834 diff --git a/include/linux/mm.h b/include/linux/mm.h
62835 index f9f279c..198da78 100644
62836 --- a/include/linux/mm.h
62837 +++ b/include/linux/mm.h
62838 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62839
62840 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62841 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62842 +
62843 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62844 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62845 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62846 +#else
62847 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62848 +#endif
62849 +
62850 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62851 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62852
62853 @@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62854 int set_page_dirty_lock(struct page *page);
62855 int clear_page_dirty_for_io(struct page *page);
62856
62857 -/* Is the vma a continuation of the stack vma above it? */
62858 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62859 -{
62860 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62861 -}
62862 -
62863 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62864 - unsigned long addr)
62865 -{
62866 - return (vma->vm_flags & VM_GROWSDOWN) &&
62867 - (vma->vm_start == addr) &&
62868 - !vma_growsdown(vma->vm_prev, addr);
62869 -}
62870 -
62871 -/* Is the vma a continuation of the stack vma below it? */
62872 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62873 -{
62874 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62875 -}
62876 -
62877 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62878 - unsigned long addr)
62879 -{
62880 - return (vma->vm_flags & VM_GROWSUP) &&
62881 - (vma->vm_end == addr) &&
62882 - !vma_growsup(vma->vm_next, addr);
62883 -}
62884 -
62885 extern pid_t
62886 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62887
62888 @@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62889 }
62890 #endif
62891
62892 +#ifdef CONFIG_MMU
62893 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62894 +#else
62895 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62896 +{
62897 + return __pgprot(0);
62898 +}
62899 +#endif
62900 +
62901 int vma_wants_writenotify(struct vm_area_struct *vma);
62902
62903 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62904 @@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62905 {
62906 return 0;
62907 }
62908 +
62909 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62910 + unsigned long address)
62911 +{
62912 + return 0;
62913 +}
62914 #else
62915 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62916 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62917 #endif
62918
62919 #ifdef __PAGETABLE_PMD_FOLDED
62920 @@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62921 {
62922 return 0;
62923 }
62924 +
62925 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62926 + unsigned long address)
62927 +{
62928 + return 0;
62929 +}
62930 #else
62931 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62932 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62933 #endif
62934
62935 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62936 @@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62937 NULL: pud_offset(pgd, address);
62938 }
62939
62940 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62941 +{
62942 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62943 + NULL: pud_offset(pgd, address);
62944 +}
62945 +
62946 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62947 {
62948 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62949 NULL: pmd_offset(pud, address);
62950 }
62951 +
62952 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62953 +{
62954 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62955 + NULL: pmd_offset(pud, address);
62956 +}
62957 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62958
62959 #if USE_SPLIT_PTLOCKS
62960 @@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62961 unsigned long, unsigned long,
62962 unsigned long, unsigned long);
62963 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62964 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62965
62966 /* These take the mm semaphore themselves */
62967 extern unsigned long vm_brk(unsigned long, unsigned long);
62968 @@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62969 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62970 struct vm_area_struct **pprev);
62971
62972 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62973 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62974 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62975 +
62976 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62977 NULL if none. Assume start_addr < end_addr. */
62978 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62979 @@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62980 return vma;
62981 }
62982
62983 -#ifdef CONFIG_MMU
62984 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62985 -#else
62986 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62987 -{
62988 - return __pgprot(0);
62989 -}
62990 -#endif
62991 -
62992 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62993 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62994 unsigned long pfn, unsigned long size, pgprot_t);
62995 @@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
62996 extern int sysctl_memory_failure_early_kill;
62997 extern int sysctl_memory_failure_recovery;
62998 extern void shake_page(struct page *p, int access);
62999 -extern atomic_long_t mce_bad_pages;
63000 +extern atomic_long_unchecked_t mce_bad_pages;
63001 extern int soft_offline_page(struct page *page, int flags);
63002
63003 extern void dump_page(struct page *page);
63004 @@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63005 static inline bool page_is_guard(struct page *page) { return false; }
63006 #endif /* CONFIG_DEBUG_PAGEALLOC */
63007
63008 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63009 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63010 +#else
63011 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63012 +#endif
63013 +
63014 #endif /* __KERNEL__ */
63015 #endif /* _LINUX_MM_H */
63016 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63017 index 704a626..bb0705a 100644
63018 --- a/include/linux/mm_types.h
63019 +++ b/include/linux/mm_types.h
63020 @@ -263,6 +263,8 @@ struct vm_area_struct {
63021 #ifdef CONFIG_NUMA
63022 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63023 #endif
63024 +
63025 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63026 };
63027
63028 struct core_thread {
63029 @@ -337,7 +339,7 @@ struct mm_struct {
63030 unsigned long def_flags;
63031 unsigned long nr_ptes; /* Page table pages */
63032 unsigned long start_code, end_code, start_data, end_data;
63033 - unsigned long start_brk, brk, start_stack;
63034 + unsigned long brk_gap, start_brk, brk, start_stack;
63035 unsigned long arg_start, arg_end, env_start, env_end;
63036
63037 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63038 @@ -389,6 +391,24 @@ struct mm_struct {
63039 struct cpumask cpumask_allocation;
63040 #endif
63041 struct uprobes_state uprobes_state;
63042 +
63043 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63044 + unsigned long pax_flags;
63045 +#endif
63046 +
63047 +#ifdef CONFIG_PAX_DLRESOLVE
63048 + unsigned long call_dl_resolve;
63049 +#endif
63050 +
63051 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63052 + unsigned long call_syscall;
63053 +#endif
63054 +
63055 +#ifdef CONFIG_PAX_ASLR
63056 + unsigned long delta_mmap; /* randomized offset */
63057 + unsigned long delta_stack; /* randomized offset */
63058 +#endif
63059 +
63060 };
63061
63062 static inline void mm_init_cpumask(struct mm_struct *mm)
63063 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63064 index 1d1b1e1..2a13c78 100644
63065 --- a/include/linux/mmu_notifier.h
63066 +++ b/include/linux/mmu_notifier.h
63067 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63068 */
63069 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63070 ({ \
63071 - pte_t __pte; \
63072 + pte_t ___pte; \
63073 struct vm_area_struct *___vma = __vma; \
63074 unsigned long ___address = __address; \
63075 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63076 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63077 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63078 - __pte; \
63079 + ___pte; \
63080 })
63081
63082 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63083 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63084 index 68c569f..5f43753 100644
63085 --- a/include/linux/mmzone.h
63086 +++ b/include/linux/mmzone.h
63087 @@ -411,7 +411,7 @@ struct zone {
63088 unsigned long flags; /* zone flags, see below */
63089
63090 /* Zone statistics */
63091 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63092 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63093
63094 /*
63095 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63096 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63097 index 5db9382..50e801d 100644
63098 --- a/include/linux/mod_devicetable.h
63099 +++ b/include/linux/mod_devicetable.h
63100 @@ -12,7 +12,7 @@
63101 typedef unsigned long kernel_ulong_t;
63102 #endif
63103
63104 -#define PCI_ANY_ID (~0)
63105 +#define PCI_ANY_ID ((__u16)~0)
63106
63107 struct pci_device_id {
63108 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63109 @@ -131,7 +131,7 @@ struct usb_device_id {
63110 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63111 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63112
63113 -#define HID_ANY_ID (~0)
63114 +#define HID_ANY_ID (~0U)
63115 #define HID_BUS_ANY 0xffff
63116 #define HID_GROUP_ANY 0x0000
63117
63118 diff --git a/include/linux/module.h b/include/linux/module.h
63119 index fbcafe2..e5d9587 100644
63120 --- a/include/linux/module.h
63121 +++ b/include/linux/module.h
63122 @@ -17,6 +17,7 @@
63123 #include <linux/moduleparam.h>
63124 #include <linux/tracepoint.h>
63125 #include <linux/export.h>
63126 +#include <linux/fs.h>
63127
63128 #include <linux/percpu.h>
63129 #include <asm/module.h>
63130 @@ -273,19 +274,16 @@ struct module
63131 int (*init)(void);
63132
63133 /* If this is non-NULL, vfree after init() returns */
63134 - void *module_init;
63135 + void *module_init_rx, *module_init_rw;
63136
63137 /* Here is the actual code + data, vfree'd on unload. */
63138 - void *module_core;
63139 + void *module_core_rx, *module_core_rw;
63140
63141 /* Here are the sizes of the init and core sections */
63142 - unsigned int init_size, core_size;
63143 + unsigned int init_size_rw, core_size_rw;
63144
63145 /* The size of the executable code in each section. */
63146 - unsigned int init_text_size, core_text_size;
63147 -
63148 - /* Size of RO sections of the module (text+rodata) */
63149 - unsigned int init_ro_size, core_ro_size;
63150 + unsigned int init_size_rx, core_size_rx;
63151
63152 /* Arch-specific module values */
63153 struct mod_arch_specific arch;
63154 @@ -341,6 +339,10 @@ struct module
63155 #ifdef CONFIG_EVENT_TRACING
63156 struct ftrace_event_call **trace_events;
63157 unsigned int num_trace_events;
63158 + struct file_operations trace_id;
63159 + struct file_operations trace_enable;
63160 + struct file_operations trace_format;
63161 + struct file_operations trace_filter;
63162 #endif
63163 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63164 unsigned int num_ftrace_callsites;
63165 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63166 bool is_module_percpu_address(unsigned long addr);
63167 bool is_module_text_address(unsigned long addr);
63168
63169 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63170 +{
63171 +
63172 +#ifdef CONFIG_PAX_KERNEXEC
63173 + if (ktla_ktva(addr) >= (unsigned long)start &&
63174 + ktla_ktva(addr) < (unsigned long)start + size)
63175 + return 1;
63176 +#endif
63177 +
63178 + return ((void *)addr >= start && (void *)addr < start + size);
63179 +}
63180 +
63181 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63182 +{
63183 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63184 +}
63185 +
63186 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63187 +{
63188 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63189 +}
63190 +
63191 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63192 +{
63193 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63194 +}
63195 +
63196 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63197 +{
63198 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63199 +}
63200 +
63201 static inline int within_module_core(unsigned long addr, struct module *mod)
63202 {
63203 - return (unsigned long)mod->module_core <= addr &&
63204 - addr < (unsigned long)mod->module_core + mod->core_size;
63205 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63206 }
63207
63208 static inline int within_module_init(unsigned long addr, struct module *mod)
63209 {
63210 - return (unsigned long)mod->module_init <= addr &&
63211 - addr < (unsigned long)mod->module_init + mod->init_size;
63212 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63213 }
63214
63215 /* Search for module by name: must hold module_mutex. */
63216 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63217 index b2be02e..72d2f78 100644
63218 --- a/include/linux/moduleloader.h
63219 +++ b/include/linux/moduleloader.h
63220 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63221
63222 /* Allocator used for allocating struct module, core sections and init
63223 sections. Returns NULL on failure. */
63224 -void *module_alloc(unsigned long size);
63225 +void *module_alloc(unsigned long size) __size_overflow(1);
63226 +
63227 +#ifdef CONFIG_PAX_KERNEXEC
63228 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63229 +#else
63230 +#define module_alloc_exec(x) module_alloc(x)
63231 +#endif
63232
63233 /* Free memory returned from module_alloc. */
63234 void module_free(struct module *mod, void *module_region);
63235
63236 +#ifdef CONFIG_PAX_KERNEXEC
63237 +void module_free_exec(struct module *mod, void *module_region);
63238 +#else
63239 +#define module_free_exec(x, y) module_free((x), (y))
63240 +#endif
63241 +
63242 /* Apply the given relocation to the (simplified) ELF. Return -error
63243 or 0. */
63244 int apply_relocate(Elf_Shdr *sechdrs,
63245 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63246 index d6a5806..7c13347 100644
63247 --- a/include/linux/moduleparam.h
63248 +++ b/include/linux/moduleparam.h
63249 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63250 * @len is usually just sizeof(string).
63251 */
63252 #define module_param_string(name, string, len, perm) \
63253 - static const struct kparam_string __param_string_##name \
63254 + static const struct kparam_string __param_string_##name __used \
63255 = { len, string }; \
63256 __module_param_call(MODULE_PARAM_PREFIX, name, \
63257 &param_ops_string, \
63258 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63259 */
63260 #define module_param_array_named(name, array, type, nump, perm) \
63261 param_check_##type(name, &(array)[0]); \
63262 - static const struct kparam_array __param_arr_##name \
63263 + static const struct kparam_array __param_arr_##name __used \
63264 = { .max = ARRAY_SIZE(array), .num = nump, \
63265 .ops = &param_ops_##type, \
63266 .elemsize = sizeof(array[0]), .elem = array }; \
63267 diff --git a/include/linux/namei.h b/include/linux/namei.h
63268 index ffc0213..2c1f2cb 100644
63269 --- a/include/linux/namei.h
63270 +++ b/include/linux/namei.h
63271 @@ -24,7 +24,7 @@ struct nameidata {
63272 unsigned seq;
63273 int last_type;
63274 unsigned depth;
63275 - char *saved_names[MAX_NESTED_LINKS + 1];
63276 + const char *saved_names[MAX_NESTED_LINKS + 1];
63277
63278 /* Intent data */
63279 union {
63280 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63281 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63282 extern void unlock_rename(struct dentry *, struct dentry *);
63283
63284 -static inline void nd_set_link(struct nameidata *nd, char *path)
63285 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63286 {
63287 nd->saved_names[nd->depth] = path;
63288 }
63289
63290 -static inline char *nd_get_link(struct nameidata *nd)
63291 +static inline const char *nd_get_link(const struct nameidata *nd)
63292 {
63293 return nd->saved_names[nd->depth];
63294 }
63295 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63296 index d94cb14..e64c951 100644
63297 --- a/include/linux/netdevice.h
63298 +++ b/include/linux/netdevice.h
63299 @@ -1026,6 +1026,7 @@ struct net_device_ops {
63300 struct net_device *dev,
63301 int idx);
63302 };
63303 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63304
63305 /*
63306 * The DEVICE structure.
63307 @@ -1087,7 +1088,7 @@ struct net_device {
63308 int iflink;
63309
63310 struct net_device_stats stats;
63311 - atomic_long_t rx_dropped; /* dropped packets by core network
63312 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63313 * Do not use this in drivers.
63314 */
63315
63316 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63317 new file mode 100644
63318 index 0000000..33f4af8
63319 --- /dev/null
63320 +++ b/include/linux/netfilter/xt_gradm.h
63321 @@ -0,0 +1,9 @@
63322 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63323 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63324 +
63325 +struct xt_gradm_mtinfo {
63326 + __u16 flags;
63327 + __u16 invflags;
63328 +};
63329 +
63330 +#endif
63331 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63332 index c65a18a..0c05f3a 100644
63333 --- a/include/linux/of_pdt.h
63334 +++ b/include/linux/of_pdt.h
63335 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63336
63337 /* return 0 on success; fill in 'len' with number of bytes in path */
63338 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63339 -};
63340 +} __no_const;
63341
63342 extern void *prom_early_alloc(unsigned long size);
63343
63344 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63345 index a4c5624..79d6d88 100644
63346 --- a/include/linux/oprofile.h
63347 +++ b/include/linux/oprofile.h
63348 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63349 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63350 char const * name, ulong * val);
63351
63352 -/** Create a file for read-only access to an atomic_t. */
63353 +/** Create a file for read-only access to an atomic_unchecked_t. */
63354 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63355 - char const * name, atomic_t * val);
63356 + char const * name, atomic_unchecked_t * val);
63357
63358 /** create a directory */
63359 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63360 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63361 index 45db49f..386788e 100644
63362 --- a/include/linux/perf_event.h
63363 +++ b/include/linux/perf_event.h
63364 @@ -879,8 +879,8 @@ struct perf_event {
63365
63366 enum perf_event_active_state state;
63367 unsigned int attach_state;
63368 - local64_t count;
63369 - atomic64_t child_count;
63370 + local64_t count; /* PaX: fix it one day */
63371 + atomic64_unchecked_t child_count;
63372
63373 /*
63374 * These are the total time in nanoseconds that the event
63375 @@ -931,8 +931,8 @@ struct perf_event {
63376 * These accumulate total time (in nanoseconds) that children
63377 * events have been enabled and running, respectively.
63378 */
63379 - atomic64_t child_total_time_enabled;
63380 - atomic64_t child_total_time_running;
63381 + atomic64_unchecked_t child_total_time_enabled;
63382 + atomic64_unchecked_t child_total_time_running;
63383
63384 /*
63385 * Protect attach/detach and child_list:
63386 diff --git a/include/linux/personality.h b/include/linux/personality.h
63387 index 8fc7dd1a..c19d89e 100644
63388 --- a/include/linux/personality.h
63389 +++ b/include/linux/personality.h
63390 @@ -44,6 +44,7 @@ enum {
63391 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63392 ADDR_NO_RANDOMIZE | \
63393 ADDR_COMPAT_LAYOUT | \
63394 + ADDR_LIMIT_3GB | \
63395 MMAP_PAGE_ZERO)
63396
63397 /*
63398 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63399 index e1ac1ce..0675fed 100644
63400 --- a/include/linux/pipe_fs_i.h
63401 +++ b/include/linux/pipe_fs_i.h
63402 @@ -45,9 +45,9 @@ struct pipe_buffer {
63403 struct pipe_inode_info {
63404 wait_queue_head_t wait;
63405 unsigned int nrbufs, curbuf, buffers;
63406 - unsigned int readers;
63407 - unsigned int writers;
63408 - unsigned int waiting_writers;
63409 + atomic_t readers;
63410 + atomic_t writers;
63411 + atomic_t waiting_writers;
63412 unsigned int r_counter;
63413 unsigned int w_counter;
63414 struct page *tmp_page;
63415 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63416 index f271860..6b3bec5 100644
63417 --- a/include/linux/pm_runtime.h
63418 +++ b/include/linux/pm_runtime.h
63419 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63420
63421 static inline void pm_runtime_mark_last_busy(struct device *dev)
63422 {
63423 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63424 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63425 }
63426
63427 #else /* !CONFIG_PM_RUNTIME */
63428 diff --git a/include/linux/poison.h b/include/linux/poison.h
63429 index 2110a81..13a11bb 100644
63430 --- a/include/linux/poison.h
63431 +++ b/include/linux/poison.h
63432 @@ -19,8 +19,8 @@
63433 * under normal circumstances, used to verify that nobody uses
63434 * non-initialized list entries.
63435 */
63436 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63437 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63438 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63439 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63440
63441 /********** include/linux/timer.h **********/
63442 /*
63443 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63444 index 5a710b9..0b0dab9 100644
63445 --- a/include/linux/preempt.h
63446 +++ b/include/linux/preempt.h
63447 @@ -126,7 +126,7 @@ struct preempt_ops {
63448 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63449 void (*sched_out)(struct preempt_notifier *notifier,
63450 struct task_struct *next);
63451 -};
63452 +} __no_const;
63453
63454 /**
63455 * preempt_notifier - key for installing preemption notifiers
63456 diff --git a/include/linux/printk.h b/include/linux/printk.h
63457 index 1bec2f7..b66e833 100644
63458 --- a/include/linux/printk.h
63459 +++ b/include/linux/printk.h
63460 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63461 extern int printk_needs_cpu(int cpu);
63462 extern void printk_tick(void);
63463
63464 +extern int kptr_restrict;
63465 +
63466 #ifdef CONFIG_PRINTK
63467 asmlinkage __printf(5, 0)
63468 int vprintk_emit(int facility, int level,
63469 @@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63470
63471 extern int printk_delay_msec;
63472 extern int dmesg_restrict;
63473 -extern int kptr_restrict;
63474
63475 void log_buf_kexec_setup(void);
63476 void __init setup_log_buf(int early);
63477 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63478 index 3fd2e87..d93a721 100644
63479 --- a/include/linux/proc_fs.h
63480 +++ b/include/linux/proc_fs.h
63481 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63482 return proc_create_data(name, mode, parent, proc_fops, NULL);
63483 }
63484
63485 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63486 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63487 +{
63488 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63489 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63490 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63491 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63492 +#else
63493 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63494 +#endif
63495 +}
63496 +
63497 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63498 umode_t mode, struct proc_dir_entry *base,
63499 read_proc_t *read_proc, void * data)
63500 @@ -258,7 +270,7 @@ union proc_op {
63501 int (*proc_show)(struct seq_file *m,
63502 struct pid_namespace *ns, struct pid *pid,
63503 struct task_struct *task);
63504 -};
63505 +} __no_const;
63506
63507 struct ctl_table_header;
63508 struct ctl_table;
63509 diff --git a/include/linux/random.h b/include/linux/random.h
63510 index ac621ce..c1215f3 100644
63511 --- a/include/linux/random.h
63512 +++ b/include/linux/random.h
63513 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63514 unsigned int value);
63515 extern void add_interrupt_randomness(int irq, int irq_flags);
63516
63517 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63518 +extern void transfer_latent_entropy(void);
63519 +#endif
63520 +
63521 extern void get_random_bytes(void *buf, int nbytes);
63522 extern void get_random_bytes_arch(void *buf, int nbytes);
63523 void generate_random_uuid(unsigned char uuid_out[16]);
63524 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63525
63526 u32 prandom32(struct rnd_state *);
63527
63528 +static inline unsigned long pax_get_random_long(void)
63529 +{
63530 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63531 +}
63532 +
63533 /*
63534 * Handle minimum values for seeds
63535 */
63536 static inline u32 __seed(u32 x, u32 m)
63537 {
63538 - return (x < m) ? x + m : x;
63539 + return (x <= m) ? x + m + 1 : x;
63540 }
63541
63542 /**
63543 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63544 index e0879a7..a12f962 100644
63545 --- a/include/linux/reboot.h
63546 +++ b/include/linux/reboot.h
63547 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63548 * Architecture-specific implementations of sys_reboot commands.
63549 */
63550
63551 -extern void machine_restart(char *cmd);
63552 -extern void machine_halt(void);
63553 -extern void machine_power_off(void);
63554 +extern void machine_restart(char *cmd) __noreturn;
63555 +extern void machine_halt(void) __noreturn;
63556 +extern void machine_power_off(void) __noreturn;
63557
63558 extern void machine_shutdown(void);
63559 struct pt_regs;
63560 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63561 */
63562
63563 extern void kernel_restart_prepare(char *cmd);
63564 -extern void kernel_restart(char *cmd);
63565 -extern void kernel_halt(void);
63566 -extern void kernel_power_off(void);
63567 +extern void kernel_restart(char *cmd) __noreturn;
63568 +extern void kernel_halt(void) __noreturn;
63569 +extern void kernel_power_off(void) __noreturn;
63570
63571 extern int C_A_D; /* for sysctl */
63572 void ctrl_alt_del(void);
63573 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63574 * Emergency restart, callable from an interrupt handler.
63575 */
63576
63577 -extern void emergency_restart(void);
63578 +extern void emergency_restart(void) __noreturn;
63579 #include <asm/emergency-restart.h>
63580
63581 #endif
63582 diff --git a/include/linux/relay.h b/include/linux/relay.h
63583 index 91cacc3..b55ff74 100644
63584 --- a/include/linux/relay.h
63585 +++ b/include/linux/relay.h
63586 @@ -160,7 +160,7 @@ struct rchan_callbacks
63587 * The callback should return 0 if successful, negative if not.
63588 */
63589 int (*remove_buf_file)(struct dentry *dentry);
63590 -};
63591 +} __no_const;
63592
63593 /*
63594 * CONFIG_RELAY kernel API, kernel/relay.c
63595 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63596 index 6fdf027..ff72610 100644
63597 --- a/include/linux/rfkill.h
63598 +++ b/include/linux/rfkill.h
63599 @@ -147,6 +147,7 @@ struct rfkill_ops {
63600 void (*query)(struct rfkill *rfkill, void *data);
63601 int (*set_block)(void *data, bool blocked);
63602 };
63603 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63604
63605 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63606 /**
63607 diff --git a/include/linux/rio.h b/include/linux/rio.h
63608 index a90ebad..fd87b5d 100644
63609 --- a/include/linux/rio.h
63610 +++ b/include/linux/rio.h
63611 @@ -321,7 +321,7 @@ struct rio_ops {
63612 int mbox, void *buffer, size_t len);
63613 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63614 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63615 -};
63616 +} __no_const;
63617
63618 #define RIO_RESOURCE_MEM 0x00000100
63619 #define RIO_RESOURCE_DOORBELL 0x00000200
63620 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63621 index 3fce545..b4fed6e 100644
63622 --- a/include/linux/rmap.h
63623 +++ b/include/linux/rmap.h
63624 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63625 void anon_vma_init(void); /* create anon_vma_cachep */
63626 int anon_vma_prepare(struct vm_area_struct *);
63627 void unlink_anon_vmas(struct vm_area_struct *);
63628 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63629 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63630 void anon_vma_moveto_tail(struct vm_area_struct *);
63631 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63632 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63633
63634 static inline void anon_vma_merge(struct vm_area_struct *vma,
63635 struct vm_area_struct *next)
63636 diff --git a/include/linux/sched.h b/include/linux/sched.h
63637 index 4a1f493..5812aeb 100644
63638 --- a/include/linux/sched.h
63639 +++ b/include/linux/sched.h
63640 @@ -101,6 +101,7 @@ struct bio_list;
63641 struct fs_struct;
63642 struct perf_event_context;
63643 struct blk_plug;
63644 +struct linux_binprm;
63645
63646 /*
63647 * List of flags we want to share for kernel threads,
63648 @@ -384,10 +385,13 @@ struct user_namespace;
63649 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63650
63651 extern int sysctl_max_map_count;
63652 +extern unsigned long sysctl_heap_stack_gap;
63653
63654 #include <linux/aio.h>
63655
63656 #ifdef CONFIG_MMU
63657 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63658 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63659 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63660 extern unsigned long
63661 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63662 @@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63663 extern void set_dumpable(struct mm_struct *mm, int value);
63664 extern int get_dumpable(struct mm_struct *mm);
63665
63666 +/* get/set_dumpable() values */
63667 +#define SUID_DUMPABLE_DISABLED 0
63668 +#define SUID_DUMPABLE_ENABLED 1
63669 +#define SUID_DUMPABLE_SAFE 2
63670 +
63671 /* mm flags */
63672 /* dumpable bits */
63673 #define MMF_DUMPABLE 0 /* core dump is permitted */
63674 @@ -646,6 +655,17 @@ struct signal_struct {
63675 #ifdef CONFIG_TASKSTATS
63676 struct taskstats *stats;
63677 #endif
63678 +
63679 +#ifdef CONFIG_GRKERNSEC
63680 + u32 curr_ip;
63681 + u32 saved_ip;
63682 + u32 gr_saddr;
63683 + u32 gr_daddr;
63684 + u16 gr_sport;
63685 + u16 gr_dport;
63686 + u8 used_accept:1;
63687 +#endif
63688 +
63689 #ifdef CONFIG_AUDIT
63690 unsigned audit_tty;
63691 struct tty_audit_buf *tty_audit_buf;
63692 @@ -729,6 +749,11 @@ struct user_struct {
63693 struct key *session_keyring; /* UID's default session keyring */
63694 #endif
63695
63696 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63697 + unsigned int banned;
63698 + unsigned long ban_expires;
63699 +#endif
63700 +
63701 /* Hash table maintenance information */
63702 struct hlist_node uidhash_node;
63703 kuid_t uid;
63704 @@ -1348,8 +1373,8 @@ struct task_struct {
63705 struct list_head thread_group;
63706
63707 struct completion *vfork_done; /* for vfork() */
63708 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63709 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63710 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63711 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63712
63713 cputime_t utime, stime, utimescaled, stimescaled;
63714 cputime_t gtime;
63715 @@ -1365,11 +1390,6 @@ struct task_struct {
63716 struct task_cputime cputime_expires;
63717 struct list_head cpu_timers[3];
63718
63719 -/* process credentials */
63720 - const struct cred __rcu *real_cred; /* objective and real subjective task
63721 - * credentials (COW) */
63722 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63723 - * credentials (COW) */
63724 char comm[TASK_COMM_LEN]; /* executable name excluding path
63725 - access with [gs]et_task_comm (which lock
63726 it with task_lock())
63727 @@ -1386,8 +1406,16 @@ struct task_struct {
63728 #endif
63729 /* CPU-specific state of this task */
63730 struct thread_struct thread;
63731 +/* thread_info moved to task_struct */
63732 +#ifdef CONFIG_X86
63733 + struct thread_info tinfo;
63734 +#endif
63735 /* filesystem information */
63736 struct fs_struct *fs;
63737 +
63738 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63739 + * credentials (COW) */
63740 +
63741 /* open file information */
63742 struct files_struct *files;
63743 /* namespaces */
63744 @@ -1431,6 +1459,11 @@ struct task_struct {
63745 struct rt_mutex_waiter *pi_blocked_on;
63746 #endif
63747
63748 +/* process credentials */
63749 + const struct cred __rcu *real_cred; /* objective and real subjective task
63750 + * credentials (COW) */
63751 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63752 +
63753 #ifdef CONFIG_DEBUG_MUTEXES
63754 /* mutex deadlock detection */
63755 struct mutex_waiter *blocked_on;
63756 @@ -1547,6 +1580,27 @@ struct task_struct {
63757 unsigned long default_timer_slack_ns;
63758
63759 struct list_head *scm_work_list;
63760 +
63761 +#ifdef CONFIG_GRKERNSEC
63762 + /* grsecurity */
63763 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63764 + u64 exec_id;
63765 +#endif
63766 +#ifdef CONFIG_GRKERNSEC_SETXID
63767 + const struct cred *delayed_cred;
63768 +#endif
63769 + struct dentry *gr_chroot_dentry;
63770 + struct acl_subject_label *acl;
63771 + struct acl_role_label *role;
63772 + struct file *exec_file;
63773 + u16 acl_role_id;
63774 + /* is this the task that authenticated to the special role */
63775 + u8 acl_sp_role;
63776 + u8 is_writable;
63777 + u8 brute;
63778 + u8 gr_is_chrooted;
63779 +#endif
63780 +
63781 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63782 /* Index of current stored address in ret_stack */
63783 int curr_ret_stack;
63784 @@ -1585,6 +1639,51 @@ struct task_struct {
63785 #endif
63786 };
63787
63788 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63789 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63790 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63791 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63792 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63793 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63794 +
63795 +#ifdef CONFIG_PAX_SOFTMODE
63796 +extern int pax_softmode;
63797 +#endif
63798 +
63799 +extern int pax_check_flags(unsigned long *);
63800 +
63801 +/* if tsk != current then task_lock must be held on it */
63802 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63803 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63804 +{
63805 + if (likely(tsk->mm))
63806 + return tsk->mm->pax_flags;
63807 + else
63808 + return 0UL;
63809 +}
63810 +
63811 +/* if tsk != current then task_lock must be held on it */
63812 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63813 +{
63814 + if (likely(tsk->mm)) {
63815 + tsk->mm->pax_flags = flags;
63816 + return 0;
63817 + }
63818 + return -EINVAL;
63819 +}
63820 +#endif
63821 +
63822 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63823 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63824 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63825 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63826 +#endif
63827 +
63828 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63829 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63830 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63831 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
63832 +
63833 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63834 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63835
63836 @@ -2112,7 +2211,9 @@ void yield(void);
63837 extern struct exec_domain default_exec_domain;
63838
63839 union thread_union {
63840 +#ifndef CONFIG_X86
63841 struct thread_info thread_info;
63842 +#endif
63843 unsigned long stack[THREAD_SIZE/sizeof(long)];
63844 };
63845
63846 @@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63847 */
63848
63849 extern struct task_struct *find_task_by_vpid(pid_t nr);
63850 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63851 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63852 struct pid_namespace *ns);
63853
63854 @@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63855 extern void exit_itimers(struct signal_struct *);
63856 extern void flush_itimer_signals(void);
63857
63858 -extern void do_group_exit(int);
63859 +extern __noreturn void do_group_exit(int);
63860
63861 extern void daemonize(const char *, ...);
63862 extern int allow_signal(int);
63863 @@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63864
63865 #endif
63866
63867 -static inline int object_is_on_stack(void *obj)
63868 +static inline int object_starts_on_stack(void *obj)
63869 {
63870 - void *stack = task_stack_page(current);
63871 + const void *stack = task_stack_page(current);
63872
63873 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63874 }
63875 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63876 index 899fbb4..1cb4138 100644
63877 --- a/include/linux/screen_info.h
63878 +++ b/include/linux/screen_info.h
63879 @@ -43,7 +43,8 @@ struct screen_info {
63880 __u16 pages; /* 0x32 */
63881 __u16 vesa_attributes; /* 0x34 */
63882 __u32 capabilities; /* 0x36 */
63883 - __u8 _reserved[6]; /* 0x3a */
63884 + __u16 vesapm_size; /* 0x3a */
63885 + __u8 _reserved[4]; /* 0x3c */
63886 } __attribute__((packed));
63887
63888 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63889 diff --git a/include/linux/security.h b/include/linux/security.h
63890 index 3dea6a9..81fd81f 100644
63891 --- a/include/linux/security.h
63892 +++ b/include/linux/security.h
63893 @@ -26,6 +26,7 @@
63894 #include <linux/capability.h>
63895 #include <linux/slab.h>
63896 #include <linux/err.h>
63897 +#include <linux/grsecurity.h>
63898
63899 struct linux_binprm;
63900 struct cred;
63901 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63902 index fc61854..d7c490b 100644
63903 --- a/include/linux/seq_file.h
63904 +++ b/include/linux/seq_file.h
63905 @@ -25,6 +25,9 @@ struct seq_file {
63906 struct mutex lock;
63907 const struct seq_operations *op;
63908 int poll_event;
63909 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63910 + u64 exec_id;
63911 +#endif
63912 void *private;
63913 };
63914
63915 @@ -34,6 +37,7 @@ struct seq_operations {
63916 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63917 int (*show) (struct seq_file *m, void *v);
63918 };
63919 +typedef struct seq_operations __no_const seq_operations_no_const;
63920
63921 #define SEQ_SKIP 1
63922
63923 diff --git a/include/linux/shm.h b/include/linux/shm.h
63924 index 92808b8..c28cac4 100644
63925 --- a/include/linux/shm.h
63926 +++ b/include/linux/shm.h
63927 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63928
63929 /* The task created the shm object. NULL if the task is dead. */
63930 struct task_struct *shm_creator;
63931 +#ifdef CONFIG_GRKERNSEC
63932 + time_t shm_createtime;
63933 + pid_t shm_lapid;
63934 +#endif
63935 };
63936
63937 /* shm_mode upper byte flags */
63938 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63939 index 642cb73..7ff7f9f 100644
63940 --- a/include/linux/skbuff.h
63941 +++ b/include/linux/skbuff.h
63942 @@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63943 */
63944 static inline int skb_queue_empty(const struct sk_buff_head *list)
63945 {
63946 - return list->next == (struct sk_buff *)list;
63947 + return list->next == (const struct sk_buff *)list;
63948 }
63949
63950 /**
63951 @@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63952 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63953 const struct sk_buff *skb)
63954 {
63955 - return skb->next == (struct sk_buff *)list;
63956 + return skb->next == (const struct sk_buff *)list;
63957 }
63958
63959 /**
63960 @@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63961 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63962 const struct sk_buff *skb)
63963 {
63964 - return skb->prev == (struct sk_buff *)list;
63965 + return skb->prev == (const struct sk_buff *)list;
63966 }
63967
63968 /**
63969 @@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63970 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63971 */
63972 #ifndef NET_SKB_PAD
63973 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63974 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63975 #endif
63976
63977 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63978 diff --git a/include/linux/slab.h b/include/linux/slab.h
63979 index 67d5d94..bbd740b 100644
63980 --- a/include/linux/slab.h
63981 +++ b/include/linux/slab.h
63982 @@ -11,12 +11,20 @@
63983
63984 #include <linux/gfp.h>
63985 #include <linux/types.h>
63986 +#include <linux/err.h>
63987
63988 /*
63989 * Flags to pass to kmem_cache_create().
63990 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63991 */
63992 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63993 +
63994 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63995 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63996 +#else
63997 +#define SLAB_USERCOPY 0x00000000UL
63998 +#endif
63999 +
64000 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64001 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64002 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64003 @@ -87,10 +95,13 @@
64004 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64005 * Both make kfree a no-op.
64006 */
64007 -#define ZERO_SIZE_PTR ((void *)16)
64008 +#define ZERO_SIZE_PTR \
64009 +({ \
64010 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64011 + (void *)(-MAX_ERRNO-1L); \
64012 +})
64013
64014 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64015 - (unsigned long)ZERO_SIZE_PTR)
64016 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64017
64018 /*
64019 * struct kmem_cache related prototypes
64020 @@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64021 void kfree(const void *);
64022 void kzfree(const void *);
64023 size_t ksize(const void *);
64024 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64025 +bool is_usercopy_object(const void *ptr);
64026
64027 /*
64028 * Allocator specific definitions. These are mainly used to establish optimized
64029 @@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64030 */
64031 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64032 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64033 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64034 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64035 #define kmalloc_track_caller(size, flags) \
64036 __kmalloc_track_caller(size, flags, _RET_IP_)
64037 #else
64038 @@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64039 */
64040 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64041 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64042 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64043 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64044 #define kmalloc_node_track_caller(size, flags, node) \
64045 __kmalloc_node_track_caller(size, flags, node, \
64046 _RET_IP_)
64047 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64048 index fbd1117..0a3d314 100644
64049 --- a/include/linux/slab_def.h
64050 +++ b/include/linux/slab_def.h
64051 @@ -66,10 +66,10 @@ struct kmem_cache {
64052 unsigned long node_allocs;
64053 unsigned long node_frees;
64054 unsigned long node_overflow;
64055 - atomic_t allochit;
64056 - atomic_t allocmiss;
64057 - atomic_t freehit;
64058 - atomic_t freemiss;
64059 + atomic_unchecked_t allochit;
64060 + atomic_unchecked_t allocmiss;
64061 + atomic_unchecked_t freehit;
64062 + atomic_unchecked_t freemiss;
64063
64064 /*
64065 * If debugging is enabled, then the allocator can add additional
64066 @@ -103,11 +103,16 @@ struct cache_sizes {
64067 #ifdef CONFIG_ZONE_DMA
64068 struct kmem_cache *cs_dmacachep;
64069 #endif
64070 +
64071 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64072 + struct kmem_cache *cs_usercopycachep;
64073 +#endif
64074 +
64075 };
64076 extern struct cache_sizes malloc_sizes[];
64077
64078 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64079 -void *__kmalloc(size_t size, gfp_t flags);
64080 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64081
64082 #ifdef CONFIG_TRACING
64083 extern void *kmem_cache_alloc_trace(size_t size,
64084 @@ -150,6 +155,13 @@ found:
64085 cachep = malloc_sizes[i].cs_dmacachep;
64086 else
64087 #endif
64088 +
64089 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64090 + if (flags & GFP_USERCOPY)
64091 + cachep = malloc_sizes[i].cs_usercopycachep;
64092 + else
64093 +#endif
64094 +
64095 cachep = malloc_sizes[i].cs_cachep;
64096
64097 ret = kmem_cache_alloc_trace(size, cachep, flags);
64098 @@ -160,7 +172,7 @@ found:
64099 }
64100
64101 #ifdef CONFIG_NUMA
64102 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64103 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64104 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64105
64106 #ifdef CONFIG_TRACING
64107 @@ -203,6 +215,13 @@ found:
64108 cachep = malloc_sizes[i].cs_dmacachep;
64109 else
64110 #endif
64111 +
64112 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64113 + if (flags & GFP_USERCOPY)
64114 + cachep = malloc_sizes[i].cs_usercopycachep;
64115 + else
64116 +#endif
64117 +
64118 cachep = malloc_sizes[i].cs_cachep;
64119
64120 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64121 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64122 index 0ec00b3..22b4715 100644
64123 --- a/include/linux/slob_def.h
64124 +++ b/include/linux/slob_def.h
64125 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64126 return kmem_cache_alloc_node(cachep, flags, -1);
64127 }
64128
64129 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64130 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64131
64132 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64133 {
64134 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64135 return __kmalloc_node(size, flags, -1);
64136 }
64137
64138 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64139 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64140 {
64141 return kmalloc(size, flags);
64142 }
64143 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64144 index c2f8c8b..d992a41 100644
64145 --- a/include/linux/slub_def.h
64146 +++ b/include/linux/slub_def.h
64147 @@ -92,7 +92,7 @@ struct kmem_cache {
64148 struct kmem_cache_order_objects max;
64149 struct kmem_cache_order_objects min;
64150 gfp_t allocflags; /* gfp flags to use on each alloc */
64151 - int refcount; /* Refcount for slab cache destroy */
64152 + atomic_t refcount; /* Refcount for slab cache destroy */
64153 void (*ctor)(void *);
64154 int inuse; /* Offset to metadata */
64155 int align; /* Alignment */
64156 @@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64157 * Sorry that the following has to be that ugly but some versions of GCC
64158 * have trouble with constant propagation and loops.
64159 */
64160 -static __always_inline int kmalloc_index(size_t size)
64161 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64162 {
64163 if (!size)
64164 return 0;
64165 @@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64166 }
64167
64168 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64169 -void *__kmalloc(size_t size, gfp_t flags);
64170 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64171
64172 static __always_inline void *
64173 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64174 @@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64175 }
64176 #endif
64177
64178 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64179 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64180 {
64181 unsigned int order = get_order(size);
64182 return kmalloc_order_trace(size, flags, order);
64183 @@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64184 }
64185
64186 #ifdef CONFIG_NUMA
64187 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64188 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64189 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64190
64191 #ifdef CONFIG_TRACING
64192 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64193 index de8832d..0147b46 100644
64194 --- a/include/linux/sonet.h
64195 +++ b/include/linux/sonet.h
64196 @@ -61,7 +61,7 @@ struct sonet_stats {
64197 #include <linux/atomic.h>
64198
64199 struct k_sonet_stats {
64200 -#define __HANDLE_ITEM(i) atomic_t i
64201 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64202 __SONET_ITEMS
64203 #undef __HANDLE_ITEM
64204 };
64205 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64206 index 523547e..2cb7140 100644
64207 --- a/include/linux/sunrpc/clnt.h
64208 +++ b/include/linux/sunrpc/clnt.h
64209 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64210 {
64211 switch (sap->sa_family) {
64212 case AF_INET:
64213 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64214 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64215 case AF_INET6:
64216 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64217 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64218 }
64219 return 0;
64220 }
64221 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64222 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64223 const struct sockaddr *src)
64224 {
64225 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64226 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64227 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64228
64229 dsin->sin_family = ssin->sin_family;
64230 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64231 if (sa->sa_family != AF_INET6)
64232 return 0;
64233
64234 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64235 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64236 }
64237
64238 #endif /* __KERNEL__ */
64239 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64240 index dc0c3cc..8503fb6 100644
64241 --- a/include/linux/sunrpc/sched.h
64242 +++ b/include/linux/sunrpc/sched.h
64243 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64244 void (*rpc_count_stats)(struct rpc_task *, void *);
64245 void (*rpc_release)(void *);
64246 };
64247 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64248
64249 struct rpc_task_setup {
64250 struct rpc_task *task;
64251 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64252 index 0b8e3e6..33e0a01 100644
64253 --- a/include/linux/sunrpc/svc_rdma.h
64254 +++ b/include/linux/sunrpc/svc_rdma.h
64255 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64256 extern unsigned int svcrdma_max_requests;
64257 extern unsigned int svcrdma_max_req_size;
64258
64259 -extern atomic_t rdma_stat_recv;
64260 -extern atomic_t rdma_stat_read;
64261 -extern atomic_t rdma_stat_write;
64262 -extern atomic_t rdma_stat_sq_starve;
64263 -extern atomic_t rdma_stat_rq_starve;
64264 -extern atomic_t rdma_stat_rq_poll;
64265 -extern atomic_t rdma_stat_rq_prod;
64266 -extern atomic_t rdma_stat_sq_poll;
64267 -extern atomic_t rdma_stat_sq_prod;
64268 +extern atomic_unchecked_t rdma_stat_recv;
64269 +extern atomic_unchecked_t rdma_stat_read;
64270 +extern atomic_unchecked_t rdma_stat_write;
64271 +extern atomic_unchecked_t rdma_stat_sq_starve;
64272 +extern atomic_unchecked_t rdma_stat_rq_starve;
64273 +extern atomic_unchecked_t rdma_stat_rq_poll;
64274 +extern atomic_unchecked_t rdma_stat_rq_prod;
64275 +extern atomic_unchecked_t rdma_stat_sq_poll;
64276 +extern atomic_unchecked_t rdma_stat_sq_prod;
64277
64278 #define RPCRDMA_VERSION 1
64279
64280 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64281 index c34b4c8..a65b67d 100644
64282 --- a/include/linux/sysctl.h
64283 +++ b/include/linux/sysctl.h
64284 @@ -155,7 +155,11 @@ enum
64285 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64286 };
64287
64288 -
64289 +#ifdef CONFIG_PAX_SOFTMODE
64290 +enum {
64291 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64292 +};
64293 +#endif
64294
64295 /* CTL_VM names: */
64296 enum
64297 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64298
64299 extern int proc_dostring(struct ctl_table *, int,
64300 void __user *, size_t *, loff_t *);
64301 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64302 + void __user *, size_t *, loff_t *);
64303 extern int proc_dointvec(struct ctl_table *, int,
64304 void __user *, size_t *, loff_t *);
64305 extern int proc_dointvec_minmax(struct ctl_table *, int,
64306 diff --git a/include/linux/tty.h b/include/linux/tty.h
64307 index 9f47ab5..73da944 100644
64308 --- a/include/linux/tty.h
64309 +++ b/include/linux/tty.h
64310 @@ -225,7 +225,7 @@ struct tty_port {
64311 const struct tty_port_operations *ops; /* Port operations */
64312 spinlock_t lock; /* Lock protecting tty field */
64313 int blocked_open; /* Waiting to open */
64314 - int count; /* Usage count */
64315 + atomic_t count; /* Usage count */
64316 wait_queue_head_t open_wait; /* Open waiters */
64317 wait_queue_head_t close_wait; /* Close waiters */
64318 wait_queue_head_t delta_msr_wait; /* Modem status change */
64319 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64320 struct tty_struct *tty, struct file *filp);
64321 static inline int tty_port_users(struct tty_port *port)
64322 {
64323 - return port->count + port->blocked_open;
64324 + return atomic_read(&port->count) + port->blocked_open;
64325 }
64326
64327 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64328 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64329 index fb79dd8d..07d4773 100644
64330 --- a/include/linux/tty_ldisc.h
64331 +++ b/include/linux/tty_ldisc.h
64332 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64333
64334 struct module *owner;
64335
64336 - int refcount;
64337 + atomic_t refcount;
64338 };
64339
64340 struct tty_ldisc {
64341 diff --git a/include/linux/types.h b/include/linux/types.h
64342 index 9c1bd53..c2370f6 100644
64343 --- a/include/linux/types.h
64344 +++ b/include/linux/types.h
64345 @@ -220,10 +220,26 @@ typedef struct {
64346 int counter;
64347 } atomic_t;
64348
64349 +#ifdef CONFIG_PAX_REFCOUNT
64350 +typedef struct {
64351 + int counter;
64352 +} atomic_unchecked_t;
64353 +#else
64354 +typedef atomic_t atomic_unchecked_t;
64355 +#endif
64356 +
64357 #ifdef CONFIG_64BIT
64358 typedef struct {
64359 long counter;
64360 } atomic64_t;
64361 +
64362 +#ifdef CONFIG_PAX_REFCOUNT
64363 +typedef struct {
64364 + long counter;
64365 +} atomic64_unchecked_t;
64366 +#else
64367 +typedef atomic64_t atomic64_unchecked_t;
64368 +#endif
64369 #endif
64370
64371 struct list_head {
64372 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64373 index 5ca0951..ab496a5 100644
64374 --- a/include/linux/uaccess.h
64375 +++ b/include/linux/uaccess.h
64376 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64377 long ret; \
64378 mm_segment_t old_fs = get_fs(); \
64379 \
64380 - set_fs(KERNEL_DS); \
64381 pagefault_disable(); \
64382 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64383 - pagefault_enable(); \
64384 + set_fs(KERNEL_DS); \
64385 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64386 set_fs(old_fs); \
64387 + pagefault_enable(); \
64388 ret; \
64389 })
64390
64391 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64392 index 99c1b4d..bb94261 100644
64393 --- a/include/linux/unaligned/access_ok.h
64394 +++ b/include/linux/unaligned/access_ok.h
64395 @@ -6,32 +6,32 @@
64396
64397 static inline u16 get_unaligned_le16(const void *p)
64398 {
64399 - return le16_to_cpup((__le16 *)p);
64400 + return le16_to_cpup((const __le16 *)p);
64401 }
64402
64403 static inline u32 get_unaligned_le32(const void *p)
64404 {
64405 - return le32_to_cpup((__le32 *)p);
64406 + return le32_to_cpup((const __le32 *)p);
64407 }
64408
64409 static inline u64 get_unaligned_le64(const void *p)
64410 {
64411 - return le64_to_cpup((__le64 *)p);
64412 + return le64_to_cpup((const __le64 *)p);
64413 }
64414
64415 static inline u16 get_unaligned_be16(const void *p)
64416 {
64417 - return be16_to_cpup((__be16 *)p);
64418 + return be16_to_cpup((const __be16 *)p);
64419 }
64420
64421 static inline u32 get_unaligned_be32(const void *p)
64422 {
64423 - return be32_to_cpup((__be32 *)p);
64424 + return be32_to_cpup((const __be32 *)p);
64425 }
64426
64427 static inline u64 get_unaligned_be64(const void *p)
64428 {
64429 - return be64_to_cpup((__be64 *)p);
64430 + return be64_to_cpup((const __be64 *)p);
64431 }
64432
64433 static inline void put_unaligned_le16(u16 val, void *p)
64434 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64435 index 547e59c..db6ad19 100644
64436 --- a/include/linux/usb/renesas_usbhs.h
64437 +++ b/include/linux/usb/renesas_usbhs.h
64438 @@ -39,7 +39,7 @@ enum {
64439 */
64440 struct renesas_usbhs_driver_callback {
64441 int (*notify_hotplug)(struct platform_device *pdev);
64442 -};
64443 +} __no_const;
64444
64445 /*
64446 * callback functions for platform
64447 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64448 * VBUS control is needed for Host
64449 */
64450 int (*set_vbus)(struct platform_device *pdev, int enable);
64451 -};
64452 +} __no_const;
64453
64454 /*
64455 * parameters for renesas usbhs
64456 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64457 index 6f8fbcf..8259001 100644
64458 --- a/include/linux/vermagic.h
64459 +++ b/include/linux/vermagic.h
64460 @@ -25,9 +25,35 @@
64461 #define MODULE_ARCH_VERMAGIC ""
64462 #endif
64463
64464 +#ifdef CONFIG_PAX_REFCOUNT
64465 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64466 +#else
64467 +#define MODULE_PAX_REFCOUNT ""
64468 +#endif
64469 +
64470 +#ifdef CONSTIFY_PLUGIN
64471 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64472 +#else
64473 +#define MODULE_CONSTIFY_PLUGIN ""
64474 +#endif
64475 +
64476 +#ifdef STACKLEAK_PLUGIN
64477 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64478 +#else
64479 +#define MODULE_STACKLEAK_PLUGIN ""
64480 +#endif
64481 +
64482 +#ifdef CONFIG_GRKERNSEC
64483 +#define MODULE_GRSEC "GRSEC "
64484 +#else
64485 +#define MODULE_GRSEC ""
64486 +#endif
64487 +
64488 #define VERMAGIC_STRING \
64489 UTS_RELEASE " " \
64490 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64491 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64492 - MODULE_ARCH_VERMAGIC
64493 + MODULE_ARCH_VERMAGIC \
64494 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64495 + MODULE_GRSEC
64496
64497 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64498 index dcdfc2b..ec79ab5 100644
64499 --- a/include/linux/vmalloc.h
64500 +++ b/include/linux/vmalloc.h
64501 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64502 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64503 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64504 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64505 +
64506 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64507 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64508 +#endif
64509 +
64510 /* bits [20..32] reserved for arch specific ioremap internals */
64511
64512 /*
64513 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64514 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64515 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64516 unsigned long start, unsigned long end, gfp_t gfp_mask,
64517 - pgprot_t prot, int node, void *caller);
64518 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64519 extern void vfree(const void *addr);
64520
64521 extern void *vmap(struct page **pages, unsigned int count,
64522 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64523 extern void free_vm_area(struct vm_struct *area);
64524
64525 /* for /dev/kmem */
64526 -extern long vread(char *buf, char *addr, unsigned long count);
64527 -extern long vwrite(char *buf, char *addr, unsigned long count);
64528 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64529 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64530
64531 /*
64532 * Internals. Dont't use..
64533 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64534 index 65efb92..137adbb 100644
64535 --- a/include/linux/vmstat.h
64536 +++ b/include/linux/vmstat.h
64537 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64538 /*
64539 * Zone based page accounting with per cpu differentials.
64540 */
64541 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64542 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64543
64544 static inline void zone_page_state_add(long x, struct zone *zone,
64545 enum zone_stat_item item)
64546 {
64547 - atomic_long_add(x, &zone->vm_stat[item]);
64548 - atomic_long_add(x, &vm_stat[item]);
64549 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64550 + atomic_long_add_unchecked(x, &vm_stat[item]);
64551 }
64552
64553 static inline unsigned long global_page_state(enum zone_stat_item item)
64554 {
64555 - long x = atomic_long_read(&vm_stat[item]);
64556 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64557 #ifdef CONFIG_SMP
64558 if (x < 0)
64559 x = 0;
64560 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64561 static inline unsigned long zone_page_state(struct zone *zone,
64562 enum zone_stat_item item)
64563 {
64564 - long x = atomic_long_read(&zone->vm_stat[item]);
64565 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64566 #ifdef CONFIG_SMP
64567 if (x < 0)
64568 x = 0;
64569 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64570 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64571 enum zone_stat_item item)
64572 {
64573 - long x = atomic_long_read(&zone->vm_stat[item]);
64574 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64575
64576 #ifdef CONFIG_SMP
64577 int cpu;
64578 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64579
64580 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64581 {
64582 - atomic_long_inc(&zone->vm_stat[item]);
64583 - atomic_long_inc(&vm_stat[item]);
64584 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64585 + atomic_long_inc_unchecked(&vm_stat[item]);
64586 }
64587
64588 static inline void __inc_zone_page_state(struct page *page,
64589 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64590
64591 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64592 {
64593 - atomic_long_dec(&zone->vm_stat[item]);
64594 - atomic_long_dec(&vm_stat[item]);
64595 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64596 + atomic_long_dec_unchecked(&vm_stat[item]);
64597 }
64598
64599 static inline void __dec_zone_page_state(struct page *page,
64600 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64601 index e5d1220..ef6e406 100644
64602 --- a/include/linux/xattr.h
64603 +++ b/include/linux/xattr.h
64604 @@ -57,6 +57,11 @@
64605 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64606 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64607
64608 +/* User namespace */
64609 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64610 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64611 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64612 +
64613 #ifdef __KERNEL__
64614
64615 #include <linux/types.h>
64616 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64617 index 944ecdf..a3994fc 100644
64618 --- a/include/media/saa7146_vv.h
64619 +++ b/include/media/saa7146_vv.h
64620 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64621 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64622
64623 /* the extension can override this */
64624 - struct v4l2_ioctl_ops vid_ops;
64625 - struct v4l2_ioctl_ops vbi_ops;
64626 + v4l2_ioctl_ops_no_const vid_ops;
64627 + v4l2_ioctl_ops_no_const vbi_ops;
64628 /* pointer to the saa7146 core ops */
64629 const struct v4l2_ioctl_ops *core_ops;
64630
64631 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64632 index a056e6e..31023a5 100644
64633 --- a/include/media/v4l2-dev.h
64634 +++ b/include/media/v4l2-dev.h
64635 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64636 int (*mmap) (struct file *, struct vm_area_struct *);
64637 int (*open) (struct file *);
64638 int (*release) (struct file *);
64639 -};
64640 +} __do_const;
64641 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64642
64643 /*
64644 * Newer version of video_device, handled by videodev2.c
64645 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64646 index d8b76f7..7d5aa18 100644
64647 --- a/include/media/v4l2-ioctl.h
64648 +++ b/include/media/v4l2-ioctl.h
64649 @@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64650 long (*vidioc_default) (struct file *file, void *fh,
64651 bool valid_prio, int cmd, void *arg);
64652 };
64653 -
64654 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64655
64656 /* v4l debugging and diagnostics */
64657
64658 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64659 index 439dadc..1c67e3f 100644
64660 --- a/include/net/caif/caif_hsi.h
64661 +++ b/include/net/caif/caif_hsi.h
64662 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64663 void (*rx_done_cb) (struct cfhsi_drv *drv);
64664 void (*wake_up_cb) (struct cfhsi_drv *drv);
64665 void (*wake_down_cb) (struct cfhsi_drv *drv);
64666 -};
64667 +} __no_const;
64668
64669 /* Structure implemented by HSI device. */
64670 struct cfhsi_dev {
64671 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64672 index 9e5425b..8136ffc 100644
64673 --- a/include/net/caif/cfctrl.h
64674 +++ b/include/net/caif/cfctrl.h
64675 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64676 void (*radioset_rsp)(void);
64677 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64678 struct cflayer *client_layer);
64679 -};
64680 +} __no_const;
64681
64682 /* Link Setup Parameters for CAIF-Links. */
64683 struct cfctrl_link_param {
64684 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64685 struct cfctrl {
64686 struct cfsrvl serv;
64687 struct cfctrl_rsp res;
64688 - atomic_t req_seq_no;
64689 - atomic_t rsp_seq_no;
64690 + atomic_unchecked_t req_seq_no;
64691 + atomic_unchecked_t rsp_seq_no;
64692 struct list_head list;
64693 /* Protects from simultaneous access to first_req list */
64694 spinlock_t info_list_lock;
64695 diff --git a/include/net/flow.h b/include/net/flow.h
64696 index 6c469db..7743b8e 100644
64697 --- a/include/net/flow.h
64698 +++ b/include/net/flow.h
64699 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64700
64701 extern void flow_cache_flush(void);
64702 extern void flow_cache_flush_deferred(void);
64703 -extern atomic_t flow_cache_genid;
64704 +extern atomic_unchecked_t flow_cache_genid;
64705
64706 #endif
64707 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64708 index 2040bff..f4c0733 100644
64709 --- a/include/net/inetpeer.h
64710 +++ b/include/net/inetpeer.h
64711 @@ -51,8 +51,8 @@ struct inet_peer {
64712 */
64713 union {
64714 struct {
64715 - atomic_t rid; /* Frag reception counter */
64716 - atomic_t ip_id_count; /* IP ID for the next packet */
64717 + atomic_unchecked_t rid; /* Frag reception counter */
64718 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64719 __u32 tcp_ts;
64720 __u32 tcp_ts_stamp;
64721 };
64722 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64723 more++;
64724 inet_peer_refcheck(p);
64725 do {
64726 - old = atomic_read(&p->ip_id_count);
64727 + old = atomic_read_unchecked(&p->ip_id_count);
64728 new = old + more;
64729 if (!new)
64730 new = 1;
64731 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64732 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64733 return new;
64734 }
64735
64736 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64737 index 78df0866..00e5c9b 100644
64738 --- a/include/net/ip_fib.h
64739 +++ b/include/net/ip_fib.h
64740 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64741
64742 #define FIB_RES_SADDR(net, res) \
64743 ((FIB_RES_NH(res).nh_saddr_genid == \
64744 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64745 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64746 FIB_RES_NH(res).nh_saddr : \
64747 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64748 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64749 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64750 index 95374d1..2300e36 100644
64751 --- a/include/net/ip_vs.h
64752 +++ b/include/net/ip_vs.h
64753 @@ -510,7 +510,7 @@ struct ip_vs_conn {
64754 struct ip_vs_conn *control; /* Master control connection */
64755 atomic_t n_control; /* Number of controlled ones */
64756 struct ip_vs_dest *dest; /* real server */
64757 - atomic_t in_pkts; /* incoming packet counter */
64758 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64759
64760 /* packet transmitter for different forwarding methods. If it
64761 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64762 @@ -648,7 +648,7 @@ struct ip_vs_dest {
64763 __be16 port; /* port number of the server */
64764 union nf_inet_addr addr; /* IP address of the server */
64765 volatile unsigned int flags; /* dest status flags */
64766 - atomic_t conn_flags; /* flags to copy to conn */
64767 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64768 atomic_t weight; /* server weight */
64769
64770 atomic_t refcnt; /* reference counter */
64771 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64772 index 69b610a..fe3962c 100644
64773 --- a/include/net/irda/ircomm_core.h
64774 +++ b/include/net/irda/ircomm_core.h
64775 @@ -51,7 +51,7 @@ typedef struct {
64776 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64777 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64778 struct ircomm_info *);
64779 -} call_t;
64780 +} __no_const call_t;
64781
64782 struct ircomm_cb {
64783 irda_queue_t queue;
64784 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64785 index 59ba38bc..d515662 100644
64786 --- a/include/net/irda/ircomm_tty.h
64787 +++ b/include/net/irda/ircomm_tty.h
64788 @@ -35,6 +35,7 @@
64789 #include <linux/termios.h>
64790 #include <linux/timer.h>
64791 #include <linux/tty.h> /* struct tty_struct */
64792 +#include <asm/local.h>
64793
64794 #include <net/irda/irias_object.h>
64795 #include <net/irda/ircomm_core.h>
64796 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64797 unsigned short close_delay;
64798 unsigned short closing_wait; /* time to wait before closing */
64799
64800 - int open_count;
64801 - int blocked_open; /* # of blocked opens */
64802 + local_t open_count;
64803 + local_t blocked_open; /* # of blocked opens */
64804
64805 /* Protect concurent access to :
64806 * o self->open_count
64807 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64808 index cc7c197..9f2da2a 100644
64809 --- a/include/net/iucv/af_iucv.h
64810 +++ b/include/net/iucv/af_iucv.h
64811 @@ -141,7 +141,7 @@ struct iucv_sock {
64812 struct iucv_sock_list {
64813 struct hlist_head head;
64814 rwlock_t lock;
64815 - atomic_t autobind_name;
64816 + atomic_unchecked_t autobind_name;
64817 };
64818
64819 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64820 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64821 index 6cdfeed..55a0256 100644
64822 --- a/include/net/neighbour.h
64823 +++ b/include/net/neighbour.h
64824 @@ -123,7 +123,7 @@ struct neigh_ops {
64825 void (*error_report)(struct neighbour *, struct sk_buff *);
64826 int (*output)(struct neighbour *, struct sk_buff *);
64827 int (*connected_output)(struct neighbour *, struct sk_buff *);
64828 -};
64829 +} __do_const;
64830
64831 struct pneigh_entry {
64832 struct pneigh_entry *next;
64833 diff --git a/include/net/netlink.h b/include/net/netlink.h
64834 index 785f37a..c81dc0c 100644
64835 --- a/include/net/netlink.h
64836 +++ b/include/net/netlink.h
64837 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64838 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64839 {
64840 if (mark)
64841 - skb_trim(skb, (unsigned char *) mark - skb->data);
64842 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64843 }
64844
64845 /**
64846 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64847 index bbd023a..97c6d0d 100644
64848 --- a/include/net/netns/ipv4.h
64849 +++ b/include/net/netns/ipv4.h
64850 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64851 unsigned int sysctl_ping_group_range[2];
64852 long sysctl_tcp_mem[3];
64853
64854 - atomic_t rt_genid;
64855 - atomic_t dev_addr_genid;
64856 + atomic_unchecked_t rt_genid;
64857 + atomic_unchecked_t dev_addr_genid;
64858
64859 #ifdef CONFIG_IP_MROUTE
64860 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64861 diff --git a/include/net/scm.h b/include/net/scm.h
64862 index d456f4c..0c0017c 100644
64863 --- a/include/net/scm.h
64864 +++ b/include/net/scm.h
64865 @@ -71,9 +71,11 @@ static __inline__ void scm_destroy(struct scm_cookie *scm)
64866 }
64867
64868 static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
64869 - struct scm_cookie *scm)
64870 + struct scm_cookie *scm, bool forcecreds)
64871 {
64872 memset(scm, 0, sizeof(*scm));
64873 + if (forcecreds)
64874 + scm_set_cred(scm, task_tgid(current), current_cred());
64875 unix_get_peersec_dgram(sock, scm);
64876 if (msg->msg_controllen <= 0)
64877 return 0;
64878 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64879 index a2ef814..31a8e3f 100644
64880 --- a/include/net/sctp/sctp.h
64881 +++ b/include/net/sctp/sctp.h
64882 @@ -318,9 +318,9 @@ do { \
64883
64884 #else /* SCTP_DEBUG */
64885
64886 -#define SCTP_DEBUG_PRINTK(whatever...)
64887 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64888 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64889 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64890 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64891 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64892 #define SCTP_ENABLE_DEBUG
64893 #define SCTP_DISABLE_DEBUG
64894 #define SCTP_ASSERT(expr, str, func)
64895 diff --git a/include/net/sock.h b/include/net/sock.h
64896 index 4a45216..7af2578 100644
64897 --- a/include/net/sock.h
64898 +++ b/include/net/sock.h
64899 @@ -303,7 +303,7 @@ struct sock {
64900 #ifdef CONFIG_RPS
64901 __u32 sk_rxhash;
64902 #endif
64903 - atomic_t sk_drops;
64904 + atomic_unchecked_t sk_drops;
64905 int sk_rcvbuf;
64906
64907 struct sk_filter __rcu *sk_filter;
64908 @@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64909 }
64910
64911 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64912 - char __user *from, char *to,
64913 + char __user *from, unsigned char *to,
64914 int copy, int offset)
64915 {
64916 if (skb->ip_summed == CHECKSUM_NONE) {
64917 diff --git a/include/net/tcp.h b/include/net/tcp.h
64918 index e79aa48..9929421 100644
64919 --- a/include/net/tcp.h
64920 +++ b/include/net/tcp.h
64921 @@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64922 char *name;
64923 sa_family_t family;
64924 const struct file_operations *seq_fops;
64925 - struct seq_operations seq_ops;
64926 + seq_operations_no_const seq_ops;
64927 };
64928
64929 struct tcp_iter_state {
64930 diff --git a/include/net/udp.h b/include/net/udp.h
64931 index 065f379..b661b40 100644
64932 --- a/include/net/udp.h
64933 +++ b/include/net/udp.h
64934 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64935 sa_family_t family;
64936 struct udp_table *udp_table;
64937 const struct file_operations *seq_fops;
64938 - struct seq_operations seq_ops;
64939 + seq_operations_no_const seq_ops;
64940 };
64941
64942 struct udp_iter_state {
64943 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64944 index e0a55df..5890bca07 100644
64945 --- a/include/net/xfrm.h
64946 +++ b/include/net/xfrm.h
64947 @@ -505,7 +505,7 @@ struct xfrm_policy {
64948 struct timer_list timer;
64949
64950 struct flow_cache_object flo;
64951 - atomic_t genid;
64952 + atomic_unchecked_t genid;
64953 u32 priority;
64954 u32 index;
64955 struct xfrm_mark mark;
64956 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64957 index 1a046b1..ee0bef0 100644
64958 --- a/include/rdma/iw_cm.h
64959 +++ b/include/rdma/iw_cm.h
64960 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64961 int backlog);
64962
64963 int (*destroy_listen)(struct iw_cm_id *cm_id);
64964 -};
64965 +} __no_const;
64966
64967 /**
64968 * iw_create_cm_id - Create an IW CM identifier.
64969 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64970 index 8f9dfba..610ab6c 100644
64971 --- a/include/scsi/libfc.h
64972 +++ b/include/scsi/libfc.h
64973 @@ -756,6 +756,7 @@ struct libfc_function_template {
64974 */
64975 void (*disc_stop_final) (struct fc_lport *);
64976 };
64977 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64978
64979 /**
64980 * struct fc_disc - Discovery context
64981 @@ -861,7 +862,7 @@ struct fc_lport {
64982 struct fc_vport *vport;
64983
64984 /* Operational Information */
64985 - struct libfc_function_template tt;
64986 + libfc_function_template_no_const tt;
64987 u8 link_up;
64988 u8 qfull;
64989 enum fc_lport_state state;
64990 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64991 index ba96988..ecf2eb9 100644
64992 --- a/include/scsi/scsi_device.h
64993 +++ b/include/scsi/scsi_device.h
64994 @@ -163,9 +163,9 @@ struct scsi_device {
64995 unsigned int max_device_blocked; /* what device_blocked counts down from */
64996 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64997
64998 - atomic_t iorequest_cnt;
64999 - atomic_t iodone_cnt;
65000 - atomic_t ioerr_cnt;
65001 + atomic_unchecked_t iorequest_cnt;
65002 + atomic_unchecked_t iodone_cnt;
65003 + atomic_unchecked_t ioerr_cnt;
65004
65005 struct device sdev_gendev,
65006 sdev_dev;
65007 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65008 index 719faf1..07b6728 100644
65009 --- a/include/scsi/scsi_transport_fc.h
65010 +++ b/include/scsi/scsi_transport_fc.h
65011 @@ -739,7 +739,8 @@ struct fc_function_template {
65012 unsigned long show_host_system_hostname:1;
65013
65014 unsigned long disable_target_scan:1;
65015 -};
65016 +} __do_const;
65017 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65018
65019
65020 /**
65021 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65022 index 030b87c..98a6954 100644
65023 --- a/include/sound/ak4xxx-adda.h
65024 +++ b/include/sound/ak4xxx-adda.h
65025 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65026 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65027 unsigned char val);
65028 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65029 -};
65030 +} __no_const;
65031
65032 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65033
65034 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65035 index 8c05e47..2b5df97 100644
65036 --- a/include/sound/hwdep.h
65037 +++ b/include/sound/hwdep.h
65038 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65039 struct snd_hwdep_dsp_status *status);
65040 int (*dsp_load)(struct snd_hwdep *hw,
65041 struct snd_hwdep_dsp_image *image);
65042 -};
65043 +} __no_const;
65044
65045 struct snd_hwdep {
65046 struct snd_card *card;
65047 diff --git a/include/sound/info.h b/include/sound/info.h
65048 index 9ca1a49..aba1728 100644
65049 --- a/include/sound/info.h
65050 +++ b/include/sound/info.h
65051 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65052 struct snd_info_buffer *buffer);
65053 void (*write)(struct snd_info_entry *entry,
65054 struct snd_info_buffer *buffer);
65055 -};
65056 +} __no_const;
65057
65058 struct snd_info_entry_ops {
65059 int (*open)(struct snd_info_entry *entry,
65060 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65061 index 0d11128..814178e 100644
65062 --- a/include/sound/pcm.h
65063 +++ b/include/sound/pcm.h
65064 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65065 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65066 int (*ack)(struct snd_pcm_substream *substream);
65067 };
65068 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65069
65070 /*
65071 *
65072 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65073 index af1b49e..a5d55a5 100644
65074 --- a/include/sound/sb16_csp.h
65075 +++ b/include/sound/sb16_csp.h
65076 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65077 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65078 int (*csp_stop) (struct snd_sb_csp * p);
65079 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65080 -};
65081 +} __no_const;
65082
65083 /*
65084 * CSP private data
65085 diff --git a/include/sound/soc.h b/include/sound/soc.h
65086 index c703871..f7fbbbd 100644
65087 --- a/include/sound/soc.h
65088 +++ b/include/sound/soc.h
65089 @@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
65090 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65091 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65092 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65093 -};
65094 +} __do_const;
65095
65096 struct snd_soc_platform {
65097 const char *name;
65098 @@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
65099 struct snd_soc_dai_link *dai_link;
65100 struct mutex pcm_mutex;
65101 enum snd_soc_pcm_subclass pcm_subclass;
65102 - struct snd_pcm_ops ops;
65103 + snd_pcm_ops_no_const ops;
65104
65105 unsigned int dev_registered:1;
65106
65107 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65108 index 0c3c2fb..d9d9990 100644
65109 --- a/include/sound/tea575x-tuner.h
65110 +++ b/include/sound/tea575x-tuner.h
65111 @@ -44,7 +44,7 @@ struct snd_tea575x_ops {
65112
65113 struct snd_tea575x {
65114 struct v4l2_device *v4l2_dev;
65115 - struct v4l2_file_operations fops;
65116 + v4l2_file_operations_no_const fops;
65117 struct video_device vd; /* video device */
65118 int radio_nr; /* radio_nr */
65119 bool tea5759; /* 5759 chip is present */
65120 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65121 index 4119966..1a4671c 100644
65122 --- a/include/sound/ymfpci.h
65123 +++ b/include/sound/ymfpci.h
65124 @@ -358,7 +358,7 @@ struct snd_ymfpci {
65125 spinlock_t reg_lock;
65126 spinlock_t voice_lock;
65127 wait_queue_head_t interrupt_sleep;
65128 - atomic_t interrupt_sleep_count;
65129 + atomic_unchecked_t interrupt_sleep_count;
65130 struct snd_info_entry *proc_entry;
65131 const struct firmware *dsp_microcode;
65132 const struct firmware *controller_microcode;
65133 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65134 index 362e0d9..36b9a83 100644
65135 --- a/include/target/target_core_base.h
65136 +++ b/include/target/target_core_base.h
65137 @@ -441,7 +441,7 @@ struct t10_reservation_ops {
65138 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65139 int (*t10_pr_register)(struct se_cmd *);
65140 int (*t10_pr_clear)(struct se_cmd *);
65141 -};
65142 +} __no_const;
65143
65144 struct t10_reservation {
65145 /* Reservation effects all target ports */
65146 @@ -780,7 +780,7 @@ struct se_device {
65147 spinlock_t stats_lock;
65148 /* Active commands on this virtual SE device */
65149 atomic_t simple_cmds;
65150 - atomic_t dev_ordered_id;
65151 + atomic_unchecked_t dev_ordered_id;
65152 atomic_t execute_tasks;
65153 atomic_t dev_ordered_sync;
65154 atomic_t dev_qf_count;
65155 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65156 new file mode 100644
65157 index 0000000..2efe49d
65158 --- /dev/null
65159 +++ b/include/trace/events/fs.h
65160 @@ -0,0 +1,53 @@
65161 +#undef TRACE_SYSTEM
65162 +#define TRACE_SYSTEM fs
65163 +
65164 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65165 +#define _TRACE_FS_H
65166 +
65167 +#include <linux/fs.h>
65168 +#include <linux/tracepoint.h>
65169 +
65170 +TRACE_EVENT(do_sys_open,
65171 +
65172 + TP_PROTO(char *filename, int flags, int mode),
65173 +
65174 + TP_ARGS(filename, flags, mode),
65175 +
65176 + TP_STRUCT__entry(
65177 + __string( filename, filename )
65178 + __field( int, flags )
65179 + __field( int, mode )
65180 + ),
65181 +
65182 + TP_fast_assign(
65183 + __assign_str(filename, filename);
65184 + __entry->flags = flags;
65185 + __entry->mode = mode;
65186 + ),
65187 +
65188 + TP_printk("\"%s\" %x %o",
65189 + __get_str(filename), __entry->flags, __entry->mode)
65190 +);
65191 +
65192 +TRACE_EVENT(open_exec,
65193 +
65194 + TP_PROTO(const char *filename),
65195 +
65196 + TP_ARGS(filename),
65197 +
65198 + TP_STRUCT__entry(
65199 + __string( filename, filename )
65200 + ),
65201 +
65202 + TP_fast_assign(
65203 + __assign_str(filename, filename);
65204 + ),
65205 +
65206 + TP_printk("\"%s\"",
65207 + __get_str(filename))
65208 +);
65209 +
65210 +#endif /* _TRACE_FS_H */
65211 +
65212 +/* This part must be outside protection */
65213 +#include <trace/define_trace.h>
65214 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65215 index 1c09820..7f5ec79 100644
65216 --- a/include/trace/events/irq.h
65217 +++ b/include/trace/events/irq.h
65218 @@ -36,7 +36,7 @@ struct softirq_action;
65219 */
65220 TRACE_EVENT(irq_handler_entry,
65221
65222 - TP_PROTO(int irq, struct irqaction *action),
65223 + TP_PROTO(int irq, const struct irqaction *action),
65224
65225 TP_ARGS(irq, action),
65226
65227 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65228 */
65229 TRACE_EVENT(irq_handler_exit,
65230
65231 - TP_PROTO(int irq, struct irqaction *action, int ret),
65232 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65233
65234 TP_ARGS(irq, action, ret),
65235
65236 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65237 index f9466fa..f4e2b81 100644
65238 --- a/include/video/udlfb.h
65239 +++ b/include/video/udlfb.h
65240 @@ -53,10 +53,10 @@ struct dlfb_data {
65241 u32 pseudo_palette[256];
65242 int blank_mode; /*one of FB_BLANK_ */
65243 /* blit-only rendering path metrics, exposed through sysfs */
65244 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65245 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65246 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65247 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65248 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65249 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65250 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65251 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65252 };
65253
65254 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65255 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65256 index 0993a22..32ba2fe 100644
65257 --- a/include/video/uvesafb.h
65258 +++ b/include/video/uvesafb.h
65259 @@ -177,6 +177,7 @@ struct uvesafb_par {
65260 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65261 u8 pmi_setpal; /* PMI for palette changes */
65262 u16 *pmi_base; /* protected mode interface location */
65263 + u8 *pmi_code; /* protected mode code location */
65264 void *pmi_start;
65265 void *pmi_pal;
65266 u8 *vbe_state_orig; /*
65267 diff --git a/init/Kconfig b/init/Kconfig
65268 index d07dcf9..fa47d0e 100644
65269 --- a/init/Kconfig
65270 +++ b/init/Kconfig
65271 @@ -835,6 +835,7 @@ endif # CGROUPS
65272
65273 config CHECKPOINT_RESTORE
65274 bool "Checkpoint/restore support" if EXPERT
65275 + depends on !GRKERNSEC
65276 default n
65277 help
65278 Enables additional kernel features in a sake of checkpoint/restore.
65279 @@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65280 # Security modules
65281 depends on SECURITY_TOMOYO = n
65282 depends on SECURITY_APPARMOR = n
65283 + depends on GRKERNSEC = n
65284
65285 config UIDGID_STRICT_TYPE_CHECKS
65286 bool "Require conversions between uid/gids and their internal representation"
65287 @@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65288
65289 config COMPAT_BRK
65290 bool "Disable heap randomization"
65291 - default y
65292 + default n
65293 help
65294 Randomizing heap placement makes heap exploits harder, but it
65295 also breaks ancient binaries (including anything libc5 based).
65296 @@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65297 config STOP_MACHINE
65298 bool
65299 default y
65300 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65301 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65302 help
65303 Need stop_machine() primitive.
65304
65305 diff --git a/init/Makefile b/init/Makefile
65306 index 7bc47ee..6da2dc7 100644
65307 --- a/init/Makefile
65308 +++ b/init/Makefile
65309 @@ -2,6 +2,9 @@
65310 # Makefile for the linux kernel.
65311 #
65312
65313 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65314 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65315 +
65316 obj-y := main.o version.o mounts.o
65317 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65318 obj-y += noinitramfs.o
65319 diff --git a/init/do_mounts.c b/init/do_mounts.c
65320 index d3f0aee..c9322f5 100644
65321 --- a/init/do_mounts.c
65322 +++ b/init/do_mounts.c
65323 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65324 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65325 {
65326 struct super_block *s;
65327 - int err = sys_mount(name, "/root", fs, flags, data);
65328 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65329 if (err)
65330 return err;
65331
65332 - sys_chdir("/root");
65333 + sys_chdir((const char __force_user *)"/root");
65334 s = current->fs->pwd.dentry->d_sb;
65335 ROOT_DEV = s->s_dev;
65336 printk(KERN_INFO
65337 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65338 va_start(args, fmt);
65339 vsprintf(buf, fmt, args);
65340 va_end(args);
65341 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65342 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65343 if (fd >= 0) {
65344 sys_ioctl(fd, FDEJECT, 0);
65345 sys_close(fd);
65346 }
65347 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65348 - fd = sys_open("/dev/console", O_RDWR, 0);
65349 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65350 if (fd >= 0) {
65351 sys_ioctl(fd, TCGETS, (long)&termios);
65352 termios.c_lflag &= ~ICANON;
65353 sys_ioctl(fd, TCSETSF, (long)&termios);
65354 - sys_read(fd, &c, 1);
65355 + sys_read(fd, (char __user *)&c, 1);
65356 termios.c_lflag |= ICANON;
65357 sys_ioctl(fd, TCSETSF, (long)&termios);
65358 sys_close(fd);
65359 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65360 mount_root();
65361 out:
65362 devtmpfs_mount("dev");
65363 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65364 - sys_chroot(".");
65365 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65366 + sys_chroot((const char __force_user *)".");
65367 }
65368 diff --git a/init/do_mounts.h b/init/do_mounts.h
65369 index f5b978a..69dbfe8 100644
65370 --- a/init/do_mounts.h
65371 +++ b/init/do_mounts.h
65372 @@ -15,15 +15,15 @@ extern int root_mountflags;
65373
65374 static inline int create_dev(char *name, dev_t dev)
65375 {
65376 - sys_unlink(name);
65377 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65378 + sys_unlink((char __force_user *)name);
65379 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65380 }
65381
65382 #if BITS_PER_LONG == 32
65383 static inline u32 bstat(char *name)
65384 {
65385 struct stat64 stat;
65386 - if (sys_stat64(name, &stat) != 0)
65387 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65388 return 0;
65389 if (!S_ISBLK(stat.st_mode))
65390 return 0;
65391 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65392 static inline u32 bstat(char *name)
65393 {
65394 struct stat stat;
65395 - if (sys_newstat(name, &stat) != 0)
65396 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65397 return 0;
65398 if (!S_ISBLK(stat.st_mode))
65399 return 0;
65400 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65401 index 135959a2..28a3f43 100644
65402 --- a/init/do_mounts_initrd.c
65403 +++ b/init/do_mounts_initrd.c
65404 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65405 create_dev("/dev/root.old", Root_RAM0);
65406 /* mount initrd on rootfs' /root */
65407 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65408 - sys_mkdir("/old", 0700);
65409 - root_fd = sys_open("/", 0, 0);
65410 - old_fd = sys_open("/old", 0, 0);
65411 + sys_mkdir((const char __force_user *)"/old", 0700);
65412 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65413 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65414 /* move initrd over / and chdir/chroot in initrd root */
65415 - sys_chdir("/root");
65416 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65417 - sys_chroot(".");
65418 + sys_chdir((const char __force_user *)"/root");
65419 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65420 + sys_chroot((const char __force_user *)".");
65421
65422 /*
65423 * In case that a resume from disk is carried out by linuxrc or one of
65424 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65425
65426 /* move initrd to rootfs' /old */
65427 sys_fchdir(old_fd);
65428 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65429 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65430 /* switch root and cwd back to / of rootfs */
65431 sys_fchdir(root_fd);
65432 - sys_chroot(".");
65433 + sys_chroot((const char __force_user *)".");
65434 sys_close(old_fd);
65435 sys_close(root_fd);
65436
65437 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65438 - sys_chdir("/old");
65439 + sys_chdir((const char __force_user *)"/old");
65440 return;
65441 }
65442
65443 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65444 mount_root();
65445
65446 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65447 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65448 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65449 if (!error)
65450 printk("okay\n");
65451 else {
65452 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65453 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65454 if (error == -ENOENT)
65455 printk("/initrd does not exist. Ignored.\n");
65456 else
65457 printk("failed\n");
65458 printk(KERN_NOTICE "Unmounting old root\n");
65459 - sys_umount("/old", MNT_DETACH);
65460 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65461 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65462 if (fd < 0) {
65463 error = fd;
65464 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65465 * mounted in the normal path.
65466 */
65467 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65468 - sys_unlink("/initrd.image");
65469 + sys_unlink((const char __force_user *)"/initrd.image");
65470 handle_initrd();
65471 return 1;
65472 }
65473 }
65474 - sys_unlink("/initrd.image");
65475 + sys_unlink((const char __force_user *)"/initrd.image");
65476 return 0;
65477 }
65478 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65479 index 8cb6db5..d729f50 100644
65480 --- a/init/do_mounts_md.c
65481 +++ b/init/do_mounts_md.c
65482 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65483 partitioned ? "_d" : "", minor,
65484 md_setup_args[ent].device_names);
65485
65486 - fd = sys_open(name, 0, 0);
65487 + fd = sys_open((char __force_user *)name, 0, 0);
65488 if (fd < 0) {
65489 printk(KERN_ERR "md: open failed - cannot start "
65490 "array %s\n", name);
65491 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65492 * array without it
65493 */
65494 sys_close(fd);
65495 - fd = sys_open(name, 0, 0);
65496 + fd = sys_open((char __force_user *)name, 0, 0);
65497 sys_ioctl(fd, BLKRRPART, 0);
65498 }
65499 sys_close(fd);
65500 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65501
65502 wait_for_device_probe();
65503
65504 - fd = sys_open("/dev/md0", 0, 0);
65505 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65506 if (fd >= 0) {
65507 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65508 sys_close(fd);
65509 diff --git a/init/init_task.c b/init/init_task.c
65510 index 8b2f399..f0797c9 100644
65511 --- a/init/init_task.c
65512 +++ b/init/init_task.c
65513 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65514 * Initial thread structure. Alignment of this is handled by a special
65515 * linker map entry.
65516 */
65517 +#ifdef CONFIG_X86
65518 +union thread_union init_thread_union __init_task_data;
65519 +#else
65520 union thread_union init_thread_union __init_task_data =
65521 { INIT_THREAD_INFO(init_task) };
65522 +#endif
65523 diff --git a/init/initramfs.c b/init/initramfs.c
65524 index 84c6bf1..8899338 100644
65525 --- a/init/initramfs.c
65526 +++ b/init/initramfs.c
65527 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65528 }
65529 }
65530
65531 -static long __init do_utime(char *filename, time_t mtime)
65532 +static long __init do_utime(char __force_user *filename, time_t mtime)
65533 {
65534 struct timespec t[2];
65535
65536 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65537 struct dir_entry *de, *tmp;
65538 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65539 list_del(&de->list);
65540 - do_utime(de->name, de->mtime);
65541 + do_utime((char __force_user *)de->name, de->mtime);
65542 kfree(de->name);
65543 kfree(de);
65544 }
65545 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65546 if (nlink >= 2) {
65547 char *old = find_link(major, minor, ino, mode, collected);
65548 if (old)
65549 - return (sys_link(old, collected) < 0) ? -1 : 1;
65550 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65551 }
65552 return 0;
65553 }
65554 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65555 {
65556 struct stat st;
65557
65558 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65559 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65560 if (S_ISDIR(st.st_mode))
65561 - sys_rmdir(path);
65562 + sys_rmdir((char __force_user *)path);
65563 else
65564 - sys_unlink(path);
65565 + sys_unlink((char __force_user *)path);
65566 }
65567 }
65568
65569 @@ -315,7 +315,7 @@ static int __init do_name(void)
65570 int openflags = O_WRONLY|O_CREAT;
65571 if (ml != 1)
65572 openflags |= O_TRUNC;
65573 - wfd = sys_open(collected, openflags, mode);
65574 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65575
65576 if (wfd >= 0) {
65577 sys_fchown(wfd, uid, gid);
65578 @@ -327,17 +327,17 @@ static int __init do_name(void)
65579 }
65580 }
65581 } else if (S_ISDIR(mode)) {
65582 - sys_mkdir(collected, mode);
65583 - sys_chown(collected, uid, gid);
65584 - sys_chmod(collected, mode);
65585 + sys_mkdir((char __force_user *)collected, mode);
65586 + sys_chown((char __force_user *)collected, uid, gid);
65587 + sys_chmod((char __force_user *)collected, mode);
65588 dir_add(collected, mtime);
65589 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65590 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65591 if (maybe_link() == 0) {
65592 - sys_mknod(collected, mode, rdev);
65593 - sys_chown(collected, uid, gid);
65594 - sys_chmod(collected, mode);
65595 - do_utime(collected, mtime);
65596 + sys_mknod((char __force_user *)collected, mode, rdev);
65597 + sys_chown((char __force_user *)collected, uid, gid);
65598 + sys_chmod((char __force_user *)collected, mode);
65599 + do_utime((char __force_user *)collected, mtime);
65600 }
65601 }
65602 return 0;
65603 @@ -346,15 +346,15 @@ static int __init do_name(void)
65604 static int __init do_copy(void)
65605 {
65606 if (count >= body_len) {
65607 - sys_write(wfd, victim, body_len);
65608 + sys_write(wfd, (char __force_user *)victim, body_len);
65609 sys_close(wfd);
65610 - do_utime(vcollected, mtime);
65611 + do_utime((char __force_user *)vcollected, mtime);
65612 kfree(vcollected);
65613 eat(body_len);
65614 state = SkipIt;
65615 return 0;
65616 } else {
65617 - sys_write(wfd, victim, count);
65618 + sys_write(wfd, (char __force_user *)victim, count);
65619 body_len -= count;
65620 eat(count);
65621 return 1;
65622 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
65623 {
65624 collected[N_ALIGN(name_len) + body_len] = '\0';
65625 clean_path(collected, 0);
65626 - sys_symlink(collected + N_ALIGN(name_len), collected);
65627 - sys_lchown(collected, uid, gid);
65628 - do_utime(collected, mtime);
65629 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65630 + sys_lchown((char __force_user *)collected, uid, gid);
65631 + do_utime((char __force_user *)collected, mtime);
65632 state = SkipIt;
65633 next_state = Reset;
65634 return 0;
65635 diff --git a/init/main.c b/init/main.c
65636 index b5cc0a7..5605c91 100644
65637 --- a/init/main.c
65638 +++ b/init/main.c
65639 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65640 extern void tc_init(void);
65641 #endif
65642
65643 +extern void grsecurity_init(void);
65644 +
65645 /*
65646 * Debug helper: via this flag we know that we are in 'early bootup code'
65647 * where only the boot processor is running with IRQ disabled. This means
65648 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65649
65650 __setup("reset_devices", set_reset_devices);
65651
65652 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65653 +extern char pax_enter_kernel_user[];
65654 +extern char pax_exit_kernel_user[];
65655 +extern pgdval_t clone_pgd_mask;
65656 +#endif
65657 +
65658 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65659 +static int __init setup_pax_nouderef(char *str)
65660 +{
65661 +#ifdef CONFIG_X86_32
65662 + unsigned int cpu;
65663 + struct desc_struct *gdt;
65664 +
65665 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65666 + gdt = get_cpu_gdt_table(cpu);
65667 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65668 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65669 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65670 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65671 + }
65672 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65673 +#else
65674 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65675 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65676 + clone_pgd_mask = ~(pgdval_t)0UL;
65677 +#endif
65678 +
65679 + return 0;
65680 +}
65681 +early_param("pax_nouderef", setup_pax_nouderef);
65682 +#endif
65683 +
65684 +#ifdef CONFIG_PAX_SOFTMODE
65685 +int pax_softmode;
65686 +
65687 +static int __init setup_pax_softmode(char *str)
65688 +{
65689 + get_option(&str, &pax_softmode);
65690 + return 1;
65691 +}
65692 +__setup("pax_softmode=", setup_pax_softmode);
65693 +#endif
65694 +
65695 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65696 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65697 static const char *panic_later, *panic_param;
65698 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65699 {
65700 int count = preempt_count();
65701 int ret;
65702 + const char *msg1 = "", *msg2 = "";
65703
65704 if (initcall_debug)
65705 ret = do_one_initcall_debug(fn);
65706 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65707 sprintf(msgbuf, "error code %d ", ret);
65708
65709 if (preempt_count() != count) {
65710 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65711 + msg1 = " preemption imbalance";
65712 preempt_count() = count;
65713 }
65714 if (irqs_disabled()) {
65715 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65716 + msg2 = " disabled interrupts";
65717 local_irq_enable();
65718 }
65719 - if (msgbuf[0]) {
65720 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65721 + if (msgbuf[0] || *msg1 || *msg2) {
65722 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65723 }
65724
65725 return ret;
65726 @@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65727 level, level,
65728 &repair_env_string);
65729
65730 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65731 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65732 do_one_initcall(*fn);
65733 +
65734 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65735 + transfer_latent_entropy();
65736 +#endif
65737 +
65738 + }
65739 }
65740
65741 static void __init do_initcalls(void)
65742 @@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65743 {
65744 initcall_t *fn;
65745
65746 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
65747 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65748 do_one_initcall(*fn);
65749 +
65750 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65751 + transfer_latent_entropy();
65752 +#endif
65753 +
65754 + }
65755 }
65756
65757 static void run_init_process(const char *init_filename)
65758 @@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65759 do_basic_setup();
65760
65761 /* Open the /dev/console on the rootfs, this should never fail */
65762 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65763 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65764 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65765
65766 (void) sys_dup(0);
65767 @@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65768 if (!ramdisk_execute_command)
65769 ramdisk_execute_command = "/init";
65770
65771 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65772 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65773 ramdisk_execute_command = NULL;
65774 prepare_namespace();
65775 }
65776
65777 + grsecurity_init();
65778 +
65779 /*
65780 * Ok, we have completed the initial bootup, and
65781 * we're essentially up and running. Get rid of the
65782 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65783 index 8ce5769..4666884 100644
65784 --- a/ipc/mqueue.c
65785 +++ b/ipc/mqueue.c
65786 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65787 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65788 info->attr.mq_msgsize);
65789
65790 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65791 spin_lock(&mq_lock);
65792 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65793 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65794 diff --git a/ipc/msg.c b/ipc/msg.c
65795 index 7385de2..a8180e08 100644
65796 --- a/ipc/msg.c
65797 +++ b/ipc/msg.c
65798 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65799 return security_msg_queue_associate(msq, msgflg);
65800 }
65801
65802 +static struct ipc_ops msg_ops = {
65803 + .getnew = newque,
65804 + .associate = msg_security,
65805 + .more_checks = NULL
65806 +};
65807 +
65808 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65809 {
65810 struct ipc_namespace *ns;
65811 - struct ipc_ops msg_ops;
65812 struct ipc_params msg_params;
65813
65814 ns = current->nsproxy->ipc_ns;
65815
65816 - msg_ops.getnew = newque;
65817 - msg_ops.associate = msg_security;
65818 - msg_ops.more_checks = NULL;
65819 -
65820 msg_params.key = key;
65821 msg_params.flg = msgflg;
65822
65823 diff --git a/ipc/sem.c b/ipc/sem.c
65824 index 5215a81..cfc0cac 100644
65825 --- a/ipc/sem.c
65826 +++ b/ipc/sem.c
65827 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65828 return 0;
65829 }
65830
65831 +static struct ipc_ops sem_ops = {
65832 + .getnew = newary,
65833 + .associate = sem_security,
65834 + .more_checks = sem_more_checks
65835 +};
65836 +
65837 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65838 {
65839 struct ipc_namespace *ns;
65840 - struct ipc_ops sem_ops;
65841 struct ipc_params sem_params;
65842
65843 ns = current->nsproxy->ipc_ns;
65844 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65845 if (nsems < 0 || nsems > ns->sc_semmsl)
65846 return -EINVAL;
65847
65848 - sem_ops.getnew = newary;
65849 - sem_ops.associate = sem_security;
65850 - sem_ops.more_checks = sem_more_checks;
65851 -
65852 sem_params.key = key;
65853 sem_params.flg = semflg;
65854 sem_params.u.nsems = nsems;
65855 diff --git a/ipc/shm.c b/ipc/shm.c
65856 index 41c1285..cf6404c 100644
65857 --- a/ipc/shm.c
65858 +++ b/ipc/shm.c
65859 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65860 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65861 #endif
65862
65863 +#ifdef CONFIG_GRKERNSEC
65864 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65865 + const time_t shm_createtime, const uid_t cuid,
65866 + const int shmid);
65867 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65868 + const time_t shm_createtime);
65869 +#endif
65870 +
65871 void shm_init_ns(struct ipc_namespace *ns)
65872 {
65873 ns->shm_ctlmax = SHMMAX;
65874 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65875 shp->shm_lprid = 0;
65876 shp->shm_atim = shp->shm_dtim = 0;
65877 shp->shm_ctim = get_seconds();
65878 +#ifdef CONFIG_GRKERNSEC
65879 + {
65880 + struct timespec timeval;
65881 + do_posix_clock_monotonic_gettime(&timeval);
65882 +
65883 + shp->shm_createtime = timeval.tv_sec;
65884 + }
65885 +#endif
65886 shp->shm_segsz = size;
65887 shp->shm_nattch = 0;
65888 shp->shm_file = file;
65889 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65890 return 0;
65891 }
65892
65893 +static struct ipc_ops shm_ops = {
65894 + .getnew = newseg,
65895 + .associate = shm_security,
65896 + .more_checks = shm_more_checks
65897 +};
65898 +
65899 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65900 {
65901 struct ipc_namespace *ns;
65902 - struct ipc_ops shm_ops;
65903 struct ipc_params shm_params;
65904
65905 ns = current->nsproxy->ipc_ns;
65906
65907 - shm_ops.getnew = newseg;
65908 - shm_ops.associate = shm_security;
65909 - shm_ops.more_checks = shm_more_checks;
65910 -
65911 shm_params.key = key;
65912 shm_params.flg = shmflg;
65913 shm_params.u.size = size;
65914 @@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65915 f_mode = FMODE_READ | FMODE_WRITE;
65916 }
65917 if (shmflg & SHM_EXEC) {
65918 +
65919 +#ifdef CONFIG_PAX_MPROTECT
65920 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65921 + goto out;
65922 +#endif
65923 +
65924 prot |= PROT_EXEC;
65925 acc_mode |= S_IXUGO;
65926 }
65927 @@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65928 if (err)
65929 goto out_unlock;
65930
65931 +#ifdef CONFIG_GRKERNSEC
65932 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65933 + shp->shm_perm.cuid, shmid) ||
65934 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65935 + err = -EACCES;
65936 + goto out_unlock;
65937 + }
65938 +#endif
65939 +
65940 path = shp->shm_file->f_path;
65941 path_get(&path);
65942 shp->shm_nattch++;
65943 +#ifdef CONFIG_GRKERNSEC
65944 + shp->shm_lapid = current->pid;
65945 +#endif
65946 size = i_size_read(path.dentry->d_inode);
65947 shm_unlock(shp);
65948
65949 diff --git a/kernel/acct.c b/kernel/acct.c
65950 index 02e6167..54824f7 100644
65951 --- a/kernel/acct.c
65952 +++ b/kernel/acct.c
65953 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65954 */
65955 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65956 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65957 - file->f_op->write(file, (char *)&ac,
65958 + file->f_op->write(file, (char __force_user *)&ac,
65959 sizeof(acct_t), &file->f_pos);
65960 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65961 set_fs(fs);
65962 diff --git a/kernel/audit.c b/kernel/audit.c
65963 index 1c7f2c6..9ba5359 100644
65964 --- a/kernel/audit.c
65965 +++ b/kernel/audit.c
65966 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65967 3) suppressed due to audit_rate_limit
65968 4) suppressed due to audit_backlog_limit
65969 */
65970 -static atomic_t audit_lost = ATOMIC_INIT(0);
65971 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65972
65973 /* The netlink socket. */
65974 static struct sock *audit_sock;
65975 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65976 unsigned long now;
65977 int print;
65978
65979 - atomic_inc(&audit_lost);
65980 + atomic_inc_unchecked(&audit_lost);
65981
65982 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65983
65984 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65985 printk(KERN_WARNING
65986 "audit: audit_lost=%d audit_rate_limit=%d "
65987 "audit_backlog_limit=%d\n",
65988 - atomic_read(&audit_lost),
65989 + atomic_read_unchecked(&audit_lost),
65990 audit_rate_limit,
65991 audit_backlog_limit);
65992 audit_panic(message);
65993 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65994 status_set.pid = audit_pid;
65995 status_set.rate_limit = audit_rate_limit;
65996 status_set.backlog_limit = audit_backlog_limit;
65997 - status_set.lost = atomic_read(&audit_lost);
65998 + status_set.lost = atomic_read_unchecked(&audit_lost);
65999 status_set.backlog = skb_queue_len(&audit_skb_queue);
66000 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66001 &status_set, sizeof(status_set));
66002 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66003 index 4b96415..d8c16ee 100644
66004 --- a/kernel/auditsc.c
66005 +++ b/kernel/auditsc.c
66006 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66007 }
66008
66009 /* global counter which is incremented every time something logs in */
66010 -static atomic_t session_id = ATOMIC_INIT(0);
66011 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66012
66013 /**
66014 * audit_set_loginuid - set current task's audit_context loginuid
66015 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66016 return -EPERM;
66017 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66018
66019 - sessionid = atomic_inc_return(&session_id);
66020 + sessionid = atomic_inc_return_unchecked(&session_id);
66021 if (context && context->in_syscall) {
66022 struct audit_buffer *ab;
66023
66024 diff --git a/kernel/capability.c b/kernel/capability.c
66025 index 493d972..ea17248 100644
66026 --- a/kernel/capability.c
66027 +++ b/kernel/capability.c
66028 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66029 * before modification is attempted and the application
66030 * fails.
66031 */
66032 + if (tocopy > ARRAY_SIZE(kdata))
66033 + return -EFAULT;
66034 +
66035 if (copy_to_user(dataptr, kdata, tocopy
66036 * sizeof(struct __user_cap_data_struct))) {
66037 return -EFAULT;
66038 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66039 int ret;
66040
66041 rcu_read_lock();
66042 - ret = security_capable(__task_cred(t), ns, cap);
66043 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66044 + gr_task_is_capable(t, __task_cred(t), cap);
66045 rcu_read_unlock();
66046
66047 - return (ret == 0);
66048 + return ret;
66049 }
66050
66051 /**
66052 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66053 int ret;
66054
66055 rcu_read_lock();
66056 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66057 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66058 rcu_read_unlock();
66059
66060 - return (ret == 0);
66061 + return ret;
66062 }
66063
66064 /**
66065 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66066 BUG();
66067 }
66068
66069 - if (security_capable(current_cred(), ns, cap) == 0) {
66070 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66071 current->flags |= PF_SUPERPRIV;
66072 return true;
66073 }
66074 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66075 }
66076 EXPORT_SYMBOL(ns_capable);
66077
66078 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66079 +{
66080 + if (unlikely(!cap_valid(cap))) {
66081 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66082 + BUG();
66083 + }
66084 +
66085 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66086 + current->flags |= PF_SUPERPRIV;
66087 + return true;
66088 + }
66089 + return false;
66090 +}
66091 +EXPORT_SYMBOL(ns_capable_nolog);
66092 +
66093 /**
66094 * capable - Determine if the current task has a superior capability in effect
66095 * @cap: The capability to be tested for
66096 @@ -408,6 +427,12 @@ bool capable(int cap)
66097 }
66098 EXPORT_SYMBOL(capable);
66099
66100 +bool capable_nolog(int cap)
66101 +{
66102 + return ns_capable_nolog(&init_user_ns, cap);
66103 +}
66104 +EXPORT_SYMBOL(capable_nolog);
66105 +
66106 /**
66107 * nsown_capable - Check superior capability to one's own user_ns
66108 * @cap: The capability in question
66109 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66110
66111 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66112 }
66113 +
66114 +bool inode_capable_nolog(const struct inode *inode, int cap)
66115 +{
66116 + struct user_namespace *ns = current_user_ns();
66117 +
66118 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66119 +}
66120 diff --git a/kernel/compat.c b/kernel/compat.c
66121 index c28a306..b4d0cf3 100644
66122 --- a/kernel/compat.c
66123 +++ b/kernel/compat.c
66124 @@ -13,6 +13,7 @@
66125
66126 #include <linux/linkage.h>
66127 #include <linux/compat.h>
66128 +#include <linux/module.h>
66129 #include <linux/errno.h>
66130 #include <linux/time.h>
66131 #include <linux/signal.h>
66132 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66133 mm_segment_t oldfs;
66134 long ret;
66135
66136 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66137 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66138 oldfs = get_fs();
66139 set_fs(KERNEL_DS);
66140 ret = hrtimer_nanosleep_restart(restart);
66141 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66142 oldfs = get_fs();
66143 set_fs(KERNEL_DS);
66144 ret = hrtimer_nanosleep(&tu,
66145 - rmtp ? (struct timespec __user *)&rmt : NULL,
66146 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66147 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66148 set_fs(oldfs);
66149
66150 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66151 mm_segment_t old_fs = get_fs();
66152
66153 set_fs(KERNEL_DS);
66154 - ret = sys_sigpending((old_sigset_t __user *) &s);
66155 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66156 set_fs(old_fs);
66157 if (ret == 0)
66158 ret = put_user(s, set);
66159 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66160 mm_segment_t old_fs = get_fs();
66161
66162 set_fs(KERNEL_DS);
66163 - ret = sys_old_getrlimit(resource, &r);
66164 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66165 set_fs(old_fs);
66166
66167 if (!ret) {
66168 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66169 mm_segment_t old_fs = get_fs();
66170
66171 set_fs(KERNEL_DS);
66172 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66173 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66174 set_fs(old_fs);
66175
66176 if (ret)
66177 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66178 set_fs (KERNEL_DS);
66179 ret = sys_wait4(pid,
66180 (stat_addr ?
66181 - (unsigned int __user *) &status : NULL),
66182 - options, (struct rusage __user *) &r);
66183 + (unsigned int __force_user *) &status : NULL),
66184 + options, (struct rusage __force_user *) &r);
66185 set_fs (old_fs);
66186
66187 if (ret > 0) {
66188 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66189 memset(&info, 0, sizeof(info));
66190
66191 set_fs(KERNEL_DS);
66192 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66193 - uru ? (struct rusage __user *)&ru : NULL);
66194 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66195 + uru ? (struct rusage __force_user *)&ru : NULL);
66196 set_fs(old_fs);
66197
66198 if ((ret < 0) || (info.si_signo == 0))
66199 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66200 oldfs = get_fs();
66201 set_fs(KERNEL_DS);
66202 err = sys_timer_settime(timer_id, flags,
66203 - (struct itimerspec __user *) &newts,
66204 - (struct itimerspec __user *) &oldts);
66205 + (struct itimerspec __force_user *) &newts,
66206 + (struct itimerspec __force_user *) &oldts);
66207 set_fs(oldfs);
66208 if (!err && old && put_compat_itimerspec(old, &oldts))
66209 return -EFAULT;
66210 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66211 oldfs = get_fs();
66212 set_fs(KERNEL_DS);
66213 err = sys_timer_gettime(timer_id,
66214 - (struct itimerspec __user *) &ts);
66215 + (struct itimerspec __force_user *) &ts);
66216 set_fs(oldfs);
66217 if (!err && put_compat_itimerspec(setting, &ts))
66218 return -EFAULT;
66219 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66220 oldfs = get_fs();
66221 set_fs(KERNEL_DS);
66222 err = sys_clock_settime(which_clock,
66223 - (struct timespec __user *) &ts);
66224 + (struct timespec __force_user *) &ts);
66225 set_fs(oldfs);
66226 return err;
66227 }
66228 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66229 oldfs = get_fs();
66230 set_fs(KERNEL_DS);
66231 err = sys_clock_gettime(which_clock,
66232 - (struct timespec __user *) &ts);
66233 + (struct timespec __force_user *) &ts);
66234 set_fs(oldfs);
66235 if (!err && put_compat_timespec(&ts, tp))
66236 return -EFAULT;
66237 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66238
66239 oldfs = get_fs();
66240 set_fs(KERNEL_DS);
66241 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66242 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66243 set_fs(oldfs);
66244
66245 err = compat_put_timex(utp, &txc);
66246 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66247 oldfs = get_fs();
66248 set_fs(KERNEL_DS);
66249 err = sys_clock_getres(which_clock,
66250 - (struct timespec __user *) &ts);
66251 + (struct timespec __force_user *) &ts);
66252 set_fs(oldfs);
66253 if (!err && tp && put_compat_timespec(&ts, tp))
66254 return -EFAULT;
66255 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66256 long err;
66257 mm_segment_t oldfs;
66258 struct timespec tu;
66259 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66260 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66261
66262 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66263 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66264 oldfs = get_fs();
66265 set_fs(KERNEL_DS);
66266 err = clock_nanosleep_restart(restart);
66267 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66268 oldfs = get_fs();
66269 set_fs(KERNEL_DS);
66270 err = sys_clock_nanosleep(which_clock, flags,
66271 - (struct timespec __user *) &in,
66272 - (struct timespec __user *) &out);
66273 + (struct timespec __force_user *) &in,
66274 + (struct timespec __force_user *) &out);
66275 set_fs(oldfs);
66276
66277 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66278 diff --git a/kernel/configs.c b/kernel/configs.c
66279 index 42e8fa0..9e7406b 100644
66280 --- a/kernel/configs.c
66281 +++ b/kernel/configs.c
66282 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66283 struct proc_dir_entry *entry;
66284
66285 /* create the current config file */
66286 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66287 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66288 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66289 + &ikconfig_file_ops);
66290 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66291 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66292 + &ikconfig_file_ops);
66293 +#endif
66294 +#else
66295 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66296 &ikconfig_file_ops);
66297 +#endif
66298 +
66299 if (!entry)
66300 return -ENOMEM;
66301
66302 diff --git a/kernel/cred.c b/kernel/cred.c
66303 index de728ac..e3c267c 100644
66304 --- a/kernel/cred.c
66305 +++ b/kernel/cred.c
66306 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66307 validate_creds(cred);
66308 alter_cred_subscribers(cred, -1);
66309 put_cred(cred);
66310 +
66311 +#ifdef CONFIG_GRKERNSEC_SETXID
66312 + cred = (struct cred *) tsk->delayed_cred;
66313 + if (cred != NULL) {
66314 + tsk->delayed_cred = NULL;
66315 + validate_creds(cred);
66316 + alter_cred_subscribers(cred, -1);
66317 + put_cred(cred);
66318 + }
66319 +#endif
66320 }
66321
66322 /**
66323 @@ -469,7 +479,7 @@ error_put:
66324 * Always returns 0 thus allowing this function to be tail-called at the end
66325 * of, say, sys_setgid().
66326 */
66327 -int commit_creds(struct cred *new)
66328 +static int __commit_creds(struct cred *new)
66329 {
66330 struct task_struct *task = current;
66331 const struct cred *old = task->real_cred;
66332 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66333
66334 get_cred(new); /* we will require a ref for the subj creds too */
66335
66336 + gr_set_role_label(task, new->uid, new->gid);
66337 +
66338 /* dumpability changes */
66339 if (!uid_eq(old->euid, new->euid) ||
66340 !gid_eq(old->egid, new->egid) ||
66341 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66342 put_cred(old);
66343 return 0;
66344 }
66345 +#ifdef CONFIG_GRKERNSEC_SETXID
66346 +extern int set_user(struct cred *new);
66347 +
66348 +void gr_delayed_cred_worker(void)
66349 +{
66350 + const struct cred *new = current->delayed_cred;
66351 + struct cred *ncred;
66352 +
66353 + current->delayed_cred = NULL;
66354 +
66355 + if (current_uid() && new != NULL) {
66356 + // from doing get_cred on it when queueing this
66357 + put_cred(new);
66358 + return;
66359 + } else if (new == NULL)
66360 + return;
66361 +
66362 + ncred = prepare_creds();
66363 + if (!ncred)
66364 + goto die;
66365 + // uids
66366 + ncred->uid = new->uid;
66367 + ncred->euid = new->euid;
66368 + ncred->suid = new->suid;
66369 + ncred->fsuid = new->fsuid;
66370 + // gids
66371 + ncred->gid = new->gid;
66372 + ncred->egid = new->egid;
66373 + ncred->sgid = new->sgid;
66374 + ncred->fsgid = new->fsgid;
66375 + // groups
66376 + if (set_groups(ncred, new->group_info) < 0) {
66377 + abort_creds(ncred);
66378 + goto die;
66379 + }
66380 + // caps
66381 + ncred->securebits = new->securebits;
66382 + ncred->cap_inheritable = new->cap_inheritable;
66383 + ncred->cap_permitted = new->cap_permitted;
66384 + ncred->cap_effective = new->cap_effective;
66385 + ncred->cap_bset = new->cap_bset;
66386 +
66387 + if (set_user(ncred)) {
66388 + abort_creds(ncred);
66389 + goto die;
66390 + }
66391 +
66392 + // from doing get_cred on it when queueing this
66393 + put_cred(new);
66394 +
66395 + __commit_creds(ncred);
66396 + return;
66397 +die:
66398 + // from doing get_cred on it when queueing this
66399 + put_cred(new);
66400 + do_group_exit(SIGKILL);
66401 +}
66402 +#endif
66403 +
66404 +int commit_creds(struct cred *new)
66405 +{
66406 +#ifdef CONFIG_GRKERNSEC_SETXID
66407 + int ret;
66408 + int schedule_it = 0;
66409 + struct task_struct *t;
66410 +
66411 + /* we won't get called with tasklist_lock held for writing
66412 + and interrupts disabled as the cred struct in that case is
66413 + init_cred
66414 + */
66415 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66416 + !current_uid() && new->uid) {
66417 + schedule_it = 1;
66418 + }
66419 + ret = __commit_creds(new);
66420 + if (schedule_it) {
66421 + rcu_read_lock();
66422 + read_lock(&tasklist_lock);
66423 + for (t = next_thread(current); t != current;
66424 + t = next_thread(t)) {
66425 + if (t->delayed_cred == NULL) {
66426 + t->delayed_cred = get_cred(new);
66427 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66428 + set_tsk_need_resched(t);
66429 + }
66430 + }
66431 + read_unlock(&tasklist_lock);
66432 + rcu_read_unlock();
66433 + }
66434 + return ret;
66435 +#else
66436 + return __commit_creds(new);
66437 +#endif
66438 +}
66439 +
66440 EXPORT_SYMBOL(commit_creds);
66441
66442 /**
66443 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66444 index 0557f24..1a00d9a 100644
66445 --- a/kernel/debug/debug_core.c
66446 +++ b/kernel/debug/debug_core.c
66447 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66448 */
66449 static atomic_t masters_in_kgdb;
66450 static atomic_t slaves_in_kgdb;
66451 -static atomic_t kgdb_break_tasklet_var;
66452 +static atomic_unchecked_t kgdb_break_tasklet_var;
66453 atomic_t kgdb_setting_breakpoint;
66454
66455 struct task_struct *kgdb_usethread;
66456 @@ -132,7 +132,7 @@ int kgdb_single_step;
66457 static pid_t kgdb_sstep_pid;
66458
66459 /* to keep track of the CPU which is doing the single stepping*/
66460 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66461 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66462
66463 /*
66464 * If you are debugging a problem where roundup (the collection of
66465 @@ -540,7 +540,7 @@ return_normal:
66466 * kernel will only try for the value of sstep_tries before
66467 * giving up and continuing on.
66468 */
66469 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66470 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66471 (kgdb_info[cpu].task &&
66472 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66473 atomic_set(&kgdb_active, -1);
66474 @@ -634,8 +634,8 @@ cpu_master_loop:
66475 }
66476
66477 kgdb_restore:
66478 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66479 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66480 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66481 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66482 if (kgdb_info[sstep_cpu].task)
66483 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66484 else
66485 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66486 static void kgdb_tasklet_bpt(unsigned long ing)
66487 {
66488 kgdb_breakpoint();
66489 - atomic_set(&kgdb_break_tasklet_var, 0);
66490 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66491 }
66492
66493 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66494
66495 void kgdb_schedule_breakpoint(void)
66496 {
66497 - if (atomic_read(&kgdb_break_tasklet_var) ||
66498 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66499 atomic_read(&kgdb_active) != -1 ||
66500 atomic_read(&kgdb_setting_breakpoint))
66501 return;
66502 - atomic_inc(&kgdb_break_tasklet_var);
66503 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66504 tasklet_schedule(&kgdb_tasklet_breakpoint);
66505 }
66506 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66507 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66508 index 1f91413..362a0a1 100644
66509 --- a/kernel/debug/kdb/kdb_main.c
66510 +++ b/kernel/debug/kdb/kdb_main.c
66511 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66512 list_for_each_entry(mod, kdb_modules, list) {
66513
66514 kdb_printf("%-20s%8u 0x%p ", mod->name,
66515 - mod->core_size, (void *)mod);
66516 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66517 #ifdef CONFIG_MODULE_UNLOAD
66518 kdb_printf("%4ld ", module_refcount(mod));
66519 #endif
66520 @@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66521 kdb_printf(" (Loading)");
66522 else
66523 kdb_printf(" (Live)");
66524 - kdb_printf(" 0x%p", mod->module_core);
66525 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66526
66527 #ifdef CONFIG_MODULE_UNLOAD
66528 {
66529 diff --git a/kernel/events/core.c b/kernel/events/core.c
66530 index d7d71d6..f54b76f 100644
66531 --- a/kernel/events/core.c
66532 +++ b/kernel/events/core.c
66533 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66534 return 0;
66535 }
66536
66537 -static atomic64_t perf_event_id;
66538 +static atomic64_unchecked_t perf_event_id;
66539
66540 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66541 enum event_type_t event_type);
66542 @@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66543
66544 static inline u64 perf_event_count(struct perf_event *event)
66545 {
66546 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66547 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66548 }
66549
66550 static u64 perf_event_read(struct perf_event *event)
66551 @@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66552 mutex_lock(&event->child_mutex);
66553 total += perf_event_read(event);
66554 *enabled += event->total_time_enabled +
66555 - atomic64_read(&event->child_total_time_enabled);
66556 + atomic64_read_unchecked(&event->child_total_time_enabled);
66557 *running += event->total_time_running +
66558 - atomic64_read(&event->child_total_time_running);
66559 + atomic64_read_unchecked(&event->child_total_time_running);
66560
66561 list_for_each_entry(child, &event->child_list, child_list) {
66562 total += perf_event_read(child);
66563 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66564 userpg->offset -= local64_read(&event->hw.prev_count);
66565
66566 userpg->time_enabled = enabled +
66567 - atomic64_read(&event->child_total_time_enabled);
66568 + atomic64_read_unchecked(&event->child_total_time_enabled);
66569
66570 userpg->time_running = running +
66571 - atomic64_read(&event->child_total_time_running);
66572 + atomic64_read_unchecked(&event->child_total_time_running);
66573
66574 arch_perf_update_userpage(userpg, now);
66575
66576 @@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66577 values[n++] = perf_event_count(event);
66578 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66579 values[n++] = enabled +
66580 - atomic64_read(&event->child_total_time_enabled);
66581 + atomic64_read_unchecked(&event->child_total_time_enabled);
66582 }
66583 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66584 values[n++] = running +
66585 - atomic64_read(&event->child_total_time_running);
66586 + atomic64_read_unchecked(&event->child_total_time_running);
66587 }
66588 if (read_format & PERF_FORMAT_ID)
66589 values[n++] = primary_event_id(event);
66590 @@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66591 * need to add enough zero bytes after the string to handle
66592 * the 64bit alignment we do later.
66593 */
66594 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66595 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66596 if (!buf) {
66597 name = strncpy(tmp, "//enomem", sizeof(tmp));
66598 goto got_name;
66599 }
66600 - name = d_path(&file->f_path, buf, PATH_MAX);
66601 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66602 if (IS_ERR(name)) {
66603 name = strncpy(tmp, "//toolong", sizeof(tmp));
66604 goto got_name;
66605 @@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66606 event->parent = parent_event;
66607
66608 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66609 - event->id = atomic64_inc_return(&perf_event_id);
66610 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66611
66612 event->state = PERF_EVENT_STATE_INACTIVE;
66613
66614 @@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66615 /*
66616 * Add back the child's count to the parent's count:
66617 */
66618 - atomic64_add(child_val, &parent_event->child_count);
66619 - atomic64_add(child_event->total_time_enabled,
66620 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66621 + atomic64_add_unchecked(child_event->total_time_enabled,
66622 &parent_event->child_total_time_enabled);
66623 - atomic64_add(child_event->total_time_running,
66624 + atomic64_add_unchecked(child_event->total_time_running,
66625 &parent_event->child_total_time_running);
66626
66627 /*
66628 diff --git a/kernel/exit.c b/kernel/exit.c
66629 index 46ce8da..c648f3a 100644
66630 --- a/kernel/exit.c
66631 +++ b/kernel/exit.c
66632 @@ -59,6 +59,10 @@
66633 #include <asm/pgtable.h>
66634 #include <asm/mmu_context.h>
66635
66636 +#ifdef CONFIG_GRKERNSEC
66637 +extern rwlock_t grsec_exec_file_lock;
66638 +#endif
66639 +
66640 static void exit_mm(struct task_struct * tsk);
66641
66642 static void __unhash_process(struct task_struct *p, bool group_dead)
66643 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66644 struct task_struct *leader;
66645 int zap_leader;
66646 repeat:
66647 +#ifdef CONFIG_NET
66648 + gr_del_task_from_ip_table(p);
66649 +#endif
66650 +
66651 /* don't need to get the RCU readlock here - the process is dead and
66652 * can't be modifying its own credentials. But shut RCU-lockdep up */
66653 rcu_read_lock();
66654 @@ -394,7 +402,7 @@ int allow_signal(int sig)
66655 * know it'll be handled, so that they don't get converted to
66656 * SIGKILL or just silently dropped.
66657 */
66658 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66659 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66660 recalc_sigpending();
66661 spin_unlock_irq(&current->sighand->siglock);
66662 return 0;
66663 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66664 vsnprintf(current->comm, sizeof(current->comm), name, args);
66665 va_end(args);
66666
66667 +#ifdef CONFIG_GRKERNSEC
66668 + write_lock(&grsec_exec_file_lock);
66669 + if (current->exec_file) {
66670 + fput(current->exec_file);
66671 + current->exec_file = NULL;
66672 + }
66673 + write_unlock(&grsec_exec_file_lock);
66674 +#endif
66675 +
66676 + gr_set_kernel_label(current);
66677 +
66678 /*
66679 * If we were started as result of loading a module, close all of the
66680 * user space pages. We don't need them, and if we didn't close them
66681 @@ -907,6 +926,8 @@ void do_exit(long code)
66682 struct task_struct *tsk = current;
66683 int group_dead;
66684
66685 + set_fs(USER_DS);
66686 +
66687 profile_task_exit(tsk);
66688
66689 WARN_ON(blk_needs_flush_plug(tsk));
66690 @@ -923,7 +944,6 @@ void do_exit(long code)
66691 * mm_release()->clear_child_tid() from writing to a user-controlled
66692 * kernel address.
66693 */
66694 - set_fs(USER_DS);
66695
66696 ptrace_event(PTRACE_EVENT_EXIT, code);
66697
66698 @@ -985,6 +1005,9 @@ void do_exit(long code)
66699 tsk->exit_code = code;
66700 taskstats_exit(tsk, group_dead);
66701
66702 + gr_acl_handle_psacct(tsk, code);
66703 + gr_acl_handle_exit();
66704 +
66705 exit_mm(tsk);
66706
66707 if (group_dead)
66708 @@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66709 * Take down every thread in the group. This is called by fatal signals
66710 * as well as by sys_exit_group (below).
66711 */
66712 -void
66713 +__noreturn void
66714 do_group_exit(int exit_code)
66715 {
66716 struct signal_struct *sig = current->signal;
66717 diff --git a/kernel/fork.c b/kernel/fork.c
66718 index f00e319..c212fbc 100644
66719 --- a/kernel/fork.c
66720 +++ b/kernel/fork.c
66721 @@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66722 *stackend = STACK_END_MAGIC; /* for overflow detection */
66723
66724 #ifdef CONFIG_CC_STACKPROTECTOR
66725 - tsk->stack_canary = get_random_int();
66726 + tsk->stack_canary = pax_get_random_long();
66727 #endif
66728
66729 /*
66730 @@ -345,13 +345,78 @@ out:
66731 }
66732
66733 #ifdef CONFIG_MMU
66734 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66735 +{
66736 + struct vm_area_struct *tmp;
66737 + unsigned long charge;
66738 + struct mempolicy *pol;
66739 + struct file *file;
66740 +
66741 + charge = 0;
66742 + if (mpnt->vm_flags & VM_ACCOUNT) {
66743 + unsigned long len;
66744 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66745 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66746 + goto fail_nomem;
66747 + charge = len;
66748 + }
66749 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66750 + if (!tmp)
66751 + goto fail_nomem;
66752 + *tmp = *mpnt;
66753 + tmp->vm_mm = mm;
66754 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66755 + pol = mpol_dup(vma_policy(mpnt));
66756 + if (IS_ERR(pol))
66757 + goto fail_nomem_policy;
66758 + vma_set_policy(tmp, pol);
66759 + if (anon_vma_fork(tmp, mpnt))
66760 + goto fail_nomem_anon_vma_fork;
66761 + tmp->vm_flags &= ~VM_LOCKED;
66762 + tmp->vm_next = tmp->vm_prev = NULL;
66763 + tmp->vm_mirror = NULL;
66764 + file = tmp->vm_file;
66765 + if (file) {
66766 + struct inode *inode = file->f_path.dentry->d_inode;
66767 + struct address_space *mapping = file->f_mapping;
66768 +
66769 + get_file(file);
66770 + if (tmp->vm_flags & VM_DENYWRITE)
66771 + atomic_dec(&inode->i_writecount);
66772 + mutex_lock(&mapping->i_mmap_mutex);
66773 + if (tmp->vm_flags & VM_SHARED)
66774 + mapping->i_mmap_writable++;
66775 + flush_dcache_mmap_lock(mapping);
66776 + /* insert tmp into the share list, just after mpnt */
66777 + vma_prio_tree_add(tmp, mpnt);
66778 + flush_dcache_mmap_unlock(mapping);
66779 + mutex_unlock(&mapping->i_mmap_mutex);
66780 + }
66781 +
66782 + /*
66783 + * Clear hugetlb-related page reserves for children. This only
66784 + * affects MAP_PRIVATE mappings. Faults generated by the child
66785 + * are not guaranteed to succeed, even if read-only
66786 + */
66787 + if (is_vm_hugetlb_page(tmp))
66788 + reset_vma_resv_huge_pages(tmp);
66789 +
66790 + return tmp;
66791 +
66792 +fail_nomem_anon_vma_fork:
66793 + mpol_put(pol);
66794 +fail_nomem_policy:
66795 + kmem_cache_free(vm_area_cachep, tmp);
66796 +fail_nomem:
66797 + vm_unacct_memory(charge);
66798 + return NULL;
66799 +}
66800 +
66801 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66802 {
66803 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66804 struct rb_node **rb_link, *rb_parent;
66805 int retval;
66806 - unsigned long charge;
66807 - struct mempolicy *pol;
66808
66809 down_write(&oldmm->mmap_sem);
66810 flush_cache_dup_mm(oldmm);
66811 @@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66812 mm->locked_vm = 0;
66813 mm->mmap = NULL;
66814 mm->mmap_cache = NULL;
66815 - mm->free_area_cache = oldmm->mmap_base;
66816 - mm->cached_hole_size = ~0UL;
66817 + mm->free_area_cache = oldmm->free_area_cache;
66818 + mm->cached_hole_size = oldmm->cached_hole_size;
66819 mm->map_count = 0;
66820 cpumask_clear(mm_cpumask(mm));
66821 mm->mm_rb = RB_ROOT;
66822 @@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66823
66824 prev = NULL;
66825 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66826 - struct file *file;
66827 -
66828 if (mpnt->vm_flags & VM_DONTCOPY) {
66829 long pages = vma_pages(mpnt);
66830 mm->total_vm -= pages;
66831 @@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66832 -pages);
66833 continue;
66834 }
66835 - charge = 0;
66836 - if (mpnt->vm_flags & VM_ACCOUNT) {
66837 - unsigned long len;
66838 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66839 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66840 - goto fail_nomem;
66841 - charge = len;
66842 + tmp = dup_vma(mm, oldmm, mpnt);
66843 + if (!tmp) {
66844 + retval = -ENOMEM;
66845 + goto out;
66846 }
66847 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66848 - if (!tmp)
66849 - goto fail_nomem;
66850 - *tmp = *mpnt;
66851 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66852 - pol = mpol_dup(vma_policy(mpnt));
66853 - retval = PTR_ERR(pol);
66854 - if (IS_ERR(pol))
66855 - goto fail_nomem_policy;
66856 - vma_set_policy(tmp, pol);
66857 - tmp->vm_mm = mm;
66858 - if (anon_vma_fork(tmp, mpnt))
66859 - goto fail_nomem_anon_vma_fork;
66860 - tmp->vm_flags &= ~VM_LOCKED;
66861 - tmp->vm_next = tmp->vm_prev = NULL;
66862 - file = tmp->vm_file;
66863 - if (file) {
66864 - struct inode *inode = file->f_path.dentry->d_inode;
66865 - struct address_space *mapping = file->f_mapping;
66866 -
66867 - get_file(file);
66868 - if (tmp->vm_flags & VM_DENYWRITE)
66869 - atomic_dec(&inode->i_writecount);
66870 - mutex_lock(&mapping->i_mmap_mutex);
66871 - if (tmp->vm_flags & VM_SHARED)
66872 - mapping->i_mmap_writable++;
66873 - flush_dcache_mmap_lock(mapping);
66874 - /* insert tmp into the share list, just after mpnt */
66875 - vma_prio_tree_add(tmp, mpnt);
66876 - flush_dcache_mmap_unlock(mapping);
66877 - mutex_unlock(&mapping->i_mmap_mutex);
66878 - }
66879 -
66880 - /*
66881 - * Clear hugetlb-related page reserves for children. This only
66882 - * affects MAP_PRIVATE mappings. Faults generated by the child
66883 - * are not guaranteed to succeed, even if read-only
66884 - */
66885 - if (is_vm_hugetlb_page(tmp))
66886 - reset_vma_resv_huge_pages(tmp);
66887
66888 /*
66889 * Link in the new vma and copy the page table entries.
66890 @@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66891 if (retval)
66892 goto out;
66893
66894 - if (file && uprobe_mmap(tmp))
66895 + if (tmp->vm_file && uprobe_mmap(tmp))
66896 goto out;
66897 }
66898 +
66899 +#ifdef CONFIG_PAX_SEGMEXEC
66900 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66901 + struct vm_area_struct *mpnt_m;
66902 +
66903 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66904 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66905 +
66906 + if (!mpnt->vm_mirror)
66907 + continue;
66908 +
66909 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66910 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66911 + mpnt->vm_mirror = mpnt_m;
66912 + } else {
66913 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66914 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66915 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66916 + mpnt->vm_mirror->vm_mirror = mpnt;
66917 + }
66918 + }
66919 + BUG_ON(mpnt_m);
66920 + }
66921 +#endif
66922 +
66923 /* a new mm has just been created */
66924 arch_dup_mmap(oldmm, mm);
66925 retval = 0;
66926 @@ -470,14 +515,6 @@ out:
66927 flush_tlb_mm(oldmm);
66928 up_write(&oldmm->mmap_sem);
66929 return retval;
66930 -fail_nomem_anon_vma_fork:
66931 - mpol_put(pol);
66932 -fail_nomem_policy:
66933 - kmem_cache_free(vm_area_cachep, tmp);
66934 -fail_nomem:
66935 - retval = -ENOMEM;
66936 - vm_unacct_memory(charge);
66937 - goto out;
66938 }
66939
66940 static inline int mm_alloc_pgd(struct mm_struct *mm)
66941 @@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66942 return ERR_PTR(err);
66943
66944 mm = get_task_mm(task);
66945 - if (mm && mm != current->mm &&
66946 - !ptrace_may_access(task, mode)) {
66947 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66948 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66949 mmput(mm);
66950 mm = ERR_PTR(-EACCES);
66951 }
66952 @@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66953 spin_unlock(&fs->lock);
66954 return -EAGAIN;
66955 }
66956 - fs->users++;
66957 + atomic_inc(&fs->users);
66958 spin_unlock(&fs->lock);
66959 return 0;
66960 }
66961 tsk->fs = copy_fs_struct(fs);
66962 if (!tsk->fs)
66963 return -ENOMEM;
66964 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66965 return 0;
66966 }
66967
66968 @@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66969 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66970 #endif
66971 retval = -EAGAIN;
66972 +
66973 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66974 +
66975 if (atomic_read(&p->real_cred->user->processes) >=
66976 task_rlimit(p, RLIMIT_NPROC)) {
66977 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66978 @@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66979 /* Need tasklist lock for parent etc handling! */
66980 write_lock_irq(&tasklist_lock);
66981
66982 + /* synchronizes with gr_set_acls() */
66983 + gr_copy_label(p);
66984 +
66985 /* CLONE_PARENT re-uses the old parent */
66986 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66987 p->real_parent = current->real_parent;
66988 @@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66989 bad_fork_free:
66990 free_task(p);
66991 fork_out:
66992 + gr_log_forkfail(retval);
66993 +
66994 return ERR_PTR(retval);
66995 }
66996
66997 @@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66998 if (clone_flags & CLONE_PARENT_SETTID)
66999 put_user(nr, parent_tidptr);
67000
67001 + gr_handle_brute_check();
67002 +
67003 if (clone_flags & CLONE_VFORK) {
67004 p->vfork_done = &vfork;
67005 init_completion(&vfork);
67006 @@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67007 return 0;
67008
67009 /* don't need lock here; in the worst case we'll do useless copy */
67010 - if (fs->users == 1)
67011 + if (atomic_read(&fs->users) == 1)
67012 return 0;
67013
67014 *new_fsp = copy_fs_struct(fs);
67015 @@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67016 fs = current->fs;
67017 spin_lock(&fs->lock);
67018 current->fs = new_fs;
67019 - if (--fs->users)
67020 + gr_set_chroot_entries(current, &current->fs->root);
67021 + if (atomic_dec_return(&fs->users))
67022 new_fs = NULL;
67023 else
67024 new_fs = fs;
67025 diff --git a/kernel/futex.c b/kernel/futex.c
67026 index 3717e7b..473c750 100644
67027 --- a/kernel/futex.c
67028 +++ b/kernel/futex.c
67029 @@ -54,6 +54,7 @@
67030 #include <linux/mount.h>
67031 #include <linux/pagemap.h>
67032 #include <linux/syscalls.h>
67033 +#include <linux/ptrace.h>
67034 #include <linux/signal.h>
67035 #include <linux/export.h>
67036 #include <linux/magic.h>
67037 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67038 struct page *page, *page_head;
67039 int err, ro = 0;
67040
67041 +#ifdef CONFIG_PAX_SEGMEXEC
67042 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67043 + return -EFAULT;
67044 +#endif
67045 +
67046 /*
67047 * The futex address must be "naturally" aligned.
67048 */
67049 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67050 {
67051 u32 curval;
67052 int i;
67053 + mm_segment_t oldfs;
67054
67055 /*
67056 * This will fail and we want it. Some arch implementations do
67057 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67058 * implementation, the non-functional ones will return
67059 * -ENOSYS.
67060 */
67061 + oldfs = get_fs();
67062 + set_fs(USER_DS);
67063 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67064 futex_cmpxchg_enabled = 1;
67065 + set_fs(oldfs);
67066
67067 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67068 plist_head_init(&futex_queues[i].chain);
67069 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67070 index 9b22d03..6295b62 100644
67071 --- a/kernel/gcov/base.c
67072 +++ b/kernel/gcov/base.c
67073 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67074 }
67075
67076 #ifdef CONFIG_MODULES
67077 -static inline int within(void *addr, void *start, unsigned long size)
67078 -{
67079 - return ((addr >= start) && (addr < start + size));
67080 -}
67081 -
67082 /* Update list and generate events when modules are unloaded. */
67083 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67084 void *data)
67085 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67086 prev = NULL;
67087 /* Remove entries located in module from linked list. */
67088 for (info = gcov_info_head; info; info = info->next) {
67089 - if (within(info, mod->module_core, mod->core_size)) {
67090 + if (within_module_core_rw((unsigned long)info, mod)) {
67091 if (prev)
67092 prev->next = info->next;
67093 else
67094 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67095 index 6db7a5e..25b6648 100644
67096 --- a/kernel/hrtimer.c
67097 +++ b/kernel/hrtimer.c
67098 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67099 local_irq_restore(flags);
67100 }
67101
67102 -static void run_hrtimer_softirq(struct softirq_action *h)
67103 +static void run_hrtimer_softirq(void)
67104 {
67105 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67106
67107 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67108 index 4304919..408c4c0 100644
67109 --- a/kernel/jump_label.c
67110 +++ b/kernel/jump_label.c
67111 @@ -13,6 +13,7 @@
67112 #include <linux/sort.h>
67113 #include <linux/err.h>
67114 #include <linux/static_key.h>
67115 +#include <linux/mm.h>
67116
67117 #ifdef HAVE_JUMP_LABEL
67118
67119 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67120
67121 size = (((unsigned long)stop - (unsigned long)start)
67122 / sizeof(struct jump_entry));
67123 + pax_open_kernel();
67124 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67125 + pax_close_kernel();
67126 }
67127
67128 static void jump_label_update(struct static_key *key, int enable);
67129 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67130 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67131 struct jump_entry *iter;
67132
67133 + pax_open_kernel();
67134 for (iter = iter_start; iter < iter_stop; iter++) {
67135 if (within_module_init(iter->code, mod))
67136 iter->code = 0;
67137 }
67138 + pax_close_kernel();
67139 }
67140
67141 static int
67142 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67143 index 2169fee..45c017a 100644
67144 --- a/kernel/kallsyms.c
67145 +++ b/kernel/kallsyms.c
67146 @@ -11,6 +11,9 @@
67147 * Changed the compression method from stem compression to "table lookup"
67148 * compression (see scripts/kallsyms.c for a more complete description)
67149 */
67150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67151 +#define __INCLUDED_BY_HIDESYM 1
67152 +#endif
67153 #include <linux/kallsyms.h>
67154 #include <linux/module.h>
67155 #include <linux/init.h>
67156 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67157
67158 static inline int is_kernel_inittext(unsigned long addr)
67159 {
67160 + if (system_state != SYSTEM_BOOTING)
67161 + return 0;
67162 +
67163 if (addr >= (unsigned long)_sinittext
67164 && addr <= (unsigned long)_einittext)
67165 return 1;
67166 return 0;
67167 }
67168
67169 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67170 +#ifdef CONFIG_MODULES
67171 +static inline int is_module_text(unsigned long addr)
67172 +{
67173 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67174 + return 1;
67175 +
67176 + addr = ktla_ktva(addr);
67177 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67178 +}
67179 +#else
67180 +static inline int is_module_text(unsigned long addr)
67181 +{
67182 + return 0;
67183 +}
67184 +#endif
67185 +#endif
67186 +
67187 static inline int is_kernel_text(unsigned long addr)
67188 {
67189 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67190 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67191
67192 static inline int is_kernel(unsigned long addr)
67193 {
67194 +
67195 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67196 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67197 + return 1;
67198 +
67199 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67200 +#else
67201 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67202 +#endif
67203 +
67204 return 1;
67205 return in_gate_area_no_mm(addr);
67206 }
67207
67208 static int is_ksym_addr(unsigned long addr)
67209 {
67210 +
67211 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67212 + if (is_module_text(addr))
67213 + return 0;
67214 +#endif
67215 +
67216 if (all_var)
67217 return is_kernel(addr);
67218
67219 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67220
67221 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67222 {
67223 - iter->name[0] = '\0';
67224 iter->nameoff = get_symbol_offset(new_pos);
67225 iter->pos = new_pos;
67226 }
67227 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67228 {
67229 struct kallsym_iter *iter = m->private;
67230
67231 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67232 + if (current_uid())
67233 + return 0;
67234 +#endif
67235 +
67236 /* Some debugging symbols have no name. Ignore them. */
67237 if (!iter->name[0])
67238 return 0;
67239 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67240 */
67241 type = iter->exported ? toupper(iter->type) :
67242 tolower(iter->type);
67243 +
67244 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67245 type, iter->name, iter->module_name);
67246 } else
67247 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67248 struct kallsym_iter *iter;
67249 int ret;
67250
67251 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67252 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67253 if (!iter)
67254 return -ENOMEM;
67255 reset_iter(iter, 0);
67256 diff --git a/kernel/kexec.c b/kernel/kexec.c
67257 index 4e2e472..cd0c7ae 100644
67258 --- a/kernel/kexec.c
67259 +++ b/kernel/kexec.c
67260 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67261 unsigned long flags)
67262 {
67263 struct compat_kexec_segment in;
67264 - struct kexec_segment out, __user *ksegments;
67265 + struct kexec_segment out;
67266 + struct kexec_segment __user *ksegments;
67267 unsigned long i, result;
67268
67269 /* Don't allow clients that don't understand the native
67270 diff --git a/kernel/kmod.c b/kernel/kmod.c
67271 index ff2c7cb..085d7af 100644
67272 --- a/kernel/kmod.c
67273 +++ b/kernel/kmod.c
67274 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67275 kfree(info->argv);
67276 }
67277
67278 -static int call_modprobe(char *module_name, int wait)
67279 +static int call_modprobe(char *module_name, char *module_param, int wait)
67280 {
67281 static char *envp[] = {
67282 "HOME=/",
67283 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67284 NULL
67285 };
67286
67287 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67288 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67289 if (!argv)
67290 goto out;
67291
67292 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67293 argv[1] = "-q";
67294 argv[2] = "--";
67295 argv[3] = module_name; /* check free_modprobe_argv() */
67296 - argv[4] = NULL;
67297 + argv[4] = module_param;
67298 + argv[5] = NULL;
67299
67300 return call_usermodehelper_fns(modprobe_path, argv, envp,
67301 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67302 @@ -112,9 +113,8 @@ out:
67303 * If module auto-loading support is disabled then this function
67304 * becomes a no-operation.
67305 */
67306 -int __request_module(bool wait, const char *fmt, ...)
67307 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67308 {
67309 - va_list args;
67310 char module_name[MODULE_NAME_LEN];
67311 unsigned int max_modprobes;
67312 int ret;
67313 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67314 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67315 static int kmod_loop_msg;
67316
67317 - va_start(args, fmt);
67318 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67319 - va_end(args);
67320 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67321 if (ret >= MODULE_NAME_LEN)
67322 return -ENAMETOOLONG;
67323
67324 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67325 if (ret)
67326 return ret;
67327
67328 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67329 + if (!current_uid()) {
67330 + /* hack to workaround consolekit/udisks stupidity */
67331 + read_lock(&tasklist_lock);
67332 + if (!strcmp(current->comm, "mount") &&
67333 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67334 + read_unlock(&tasklist_lock);
67335 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67336 + return -EPERM;
67337 + }
67338 + read_unlock(&tasklist_lock);
67339 + }
67340 +#endif
67341 +
67342 /* If modprobe needs a service that is in a module, we get a recursive
67343 * loop. Limit the number of running kmod threads to max_threads/2 or
67344 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67345 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67346
67347 trace_module_request(module_name, wait, _RET_IP_);
67348
67349 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67350 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67351
67352 atomic_dec(&kmod_concurrent);
67353 return ret;
67354 }
67355 +
67356 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67357 +{
67358 + va_list args;
67359 + int ret;
67360 +
67361 + va_start(args, fmt);
67362 + ret = ____request_module(wait, module_param, fmt, args);
67363 + va_end(args);
67364 +
67365 + return ret;
67366 +}
67367 +
67368 +int __request_module(bool wait, const char *fmt, ...)
67369 +{
67370 + va_list args;
67371 + int ret;
67372 +
67373 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67374 + if (current_uid()) {
67375 + char module_param[MODULE_NAME_LEN];
67376 +
67377 + memset(module_param, 0, sizeof(module_param));
67378 +
67379 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67380 +
67381 + va_start(args, fmt);
67382 + ret = ____request_module(wait, module_param, fmt, args);
67383 + va_end(args);
67384 +
67385 + return ret;
67386 + }
67387 +#endif
67388 +
67389 + va_start(args, fmt);
67390 + ret = ____request_module(wait, NULL, fmt, args);
67391 + va_end(args);
67392 +
67393 + return ret;
67394 +}
67395 +
67396 EXPORT_SYMBOL(__request_module);
67397 #endif /* CONFIG_MODULES */
67398
67399 @@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67400 *
67401 * Thus the __user pointer cast is valid here.
67402 */
67403 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67404 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67405
67406 /*
67407 * If ret is 0, either ____call_usermodehelper failed and the
67408 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67409 index c62b854..cb67968 100644
67410 --- a/kernel/kprobes.c
67411 +++ b/kernel/kprobes.c
67412 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67413 * kernel image and loaded module images reside. This is required
67414 * so x86_64 can correctly handle the %rip-relative fixups.
67415 */
67416 - kip->insns = module_alloc(PAGE_SIZE);
67417 + kip->insns = module_alloc_exec(PAGE_SIZE);
67418 if (!kip->insns) {
67419 kfree(kip);
67420 return NULL;
67421 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67422 */
67423 if (!list_is_singular(&kip->list)) {
67424 list_del(&kip->list);
67425 - module_free(NULL, kip->insns);
67426 + module_free_exec(NULL, kip->insns);
67427 kfree(kip);
67428 }
67429 return 1;
67430 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67431 {
67432 int i, err = 0;
67433 unsigned long offset = 0, size = 0;
67434 - char *modname, namebuf[128];
67435 + char *modname, namebuf[KSYM_NAME_LEN];
67436 const char *symbol_name;
67437 void *addr;
67438 struct kprobe_blackpoint *kb;
67439 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67440 const char *sym = NULL;
67441 unsigned int i = *(loff_t *) v;
67442 unsigned long offset = 0;
67443 - char *modname, namebuf[128];
67444 + char *modname, namebuf[KSYM_NAME_LEN];
67445
67446 head = &kprobe_table[i];
67447 preempt_disable();
67448 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67449 index 4e316e1..5501eef 100644
67450 --- a/kernel/ksysfs.c
67451 +++ b/kernel/ksysfs.c
67452 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67453 {
67454 if (count+1 > UEVENT_HELPER_PATH_LEN)
67455 return -ENOENT;
67456 + if (!capable(CAP_SYS_ADMIN))
67457 + return -EPERM;
67458 memcpy(uevent_helper, buf, count);
67459 uevent_helper[count] = '\0';
67460 if (count && uevent_helper[count-1] == '\n')
67461 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67462 index ea9ee45..67ebc8f 100644
67463 --- a/kernel/lockdep.c
67464 +++ b/kernel/lockdep.c
67465 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67466 end = (unsigned long) &_end,
67467 addr = (unsigned long) obj;
67468
67469 +#ifdef CONFIG_PAX_KERNEXEC
67470 + start = ktla_ktva(start);
67471 +#endif
67472 +
67473 /*
67474 * static variable?
67475 */
67476 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67477 if (!static_obj(lock->key)) {
67478 debug_locks_off();
67479 printk("INFO: trying to register non-static key.\n");
67480 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67481 printk("the code is fine but needs lockdep annotation.\n");
67482 printk("turning off the locking correctness validator.\n");
67483 dump_stack();
67484 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67485 if (!class)
67486 return 0;
67487 }
67488 - atomic_inc((atomic_t *)&class->ops);
67489 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67490 if (very_verbose(class)) {
67491 printk("\nacquire class [%p] %s", class->key, class->name);
67492 if (class->name_version > 1)
67493 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67494 index 91c32a0..b2c71c5 100644
67495 --- a/kernel/lockdep_proc.c
67496 +++ b/kernel/lockdep_proc.c
67497 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67498
67499 static void print_name(struct seq_file *m, struct lock_class *class)
67500 {
67501 - char str[128];
67502 + char str[KSYM_NAME_LEN];
67503 const char *name = class->name;
67504
67505 if (!name) {
67506 diff --git a/kernel/module.c b/kernel/module.c
67507 index 4edbd9c..165e780 100644
67508 --- a/kernel/module.c
67509 +++ b/kernel/module.c
67510 @@ -58,6 +58,7 @@
67511 #include <linux/jump_label.h>
67512 #include <linux/pfn.h>
67513 #include <linux/bsearch.h>
67514 +#include <linux/grsecurity.h>
67515
67516 #define CREATE_TRACE_POINTS
67517 #include <trace/events/module.h>
67518 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67519
67520 /* Bounds of module allocation, for speeding __module_address.
67521 * Protected by module_mutex. */
67522 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67523 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67524 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67525
67526 int register_module_notifier(struct notifier_block * nb)
67527 {
67528 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67529 return true;
67530
67531 list_for_each_entry_rcu(mod, &modules, list) {
67532 - struct symsearch arr[] = {
67533 + struct symsearch modarr[] = {
67534 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67535 NOT_GPL_ONLY, false },
67536 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67537 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67538 #endif
67539 };
67540
67541 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67542 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67543 return true;
67544 }
67545 return false;
67546 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67547 static int percpu_modalloc(struct module *mod,
67548 unsigned long size, unsigned long align)
67549 {
67550 - if (align > PAGE_SIZE) {
67551 + if (align-1 >= PAGE_SIZE) {
67552 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67553 mod->name, align, PAGE_SIZE);
67554 align = PAGE_SIZE;
67555 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67556 static ssize_t show_coresize(struct module_attribute *mattr,
67557 struct module_kobject *mk, char *buffer)
67558 {
67559 - return sprintf(buffer, "%u\n", mk->mod->core_size);
67560 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67561 }
67562
67563 static struct module_attribute modinfo_coresize =
67564 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67565 static ssize_t show_initsize(struct module_attribute *mattr,
67566 struct module_kobject *mk, char *buffer)
67567 {
67568 - return sprintf(buffer, "%u\n", mk->mod->init_size);
67569 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67570 }
67571
67572 static struct module_attribute modinfo_initsize =
67573 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67574 */
67575 #ifdef CONFIG_SYSFS
67576
67577 -#ifdef CONFIG_KALLSYMS
67578 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67579 static inline bool sect_empty(const Elf_Shdr *sect)
67580 {
67581 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67582 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67583
67584 static void unset_module_core_ro_nx(struct module *mod)
67585 {
67586 - set_page_attributes(mod->module_core + mod->core_text_size,
67587 - mod->module_core + mod->core_size,
67588 + set_page_attributes(mod->module_core_rw,
67589 + mod->module_core_rw + mod->core_size_rw,
67590 set_memory_x);
67591 - set_page_attributes(mod->module_core,
67592 - mod->module_core + mod->core_ro_size,
67593 + set_page_attributes(mod->module_core_rx,
67594 + mod->module_core_rx + mod->core_size_rx,
67595 set_memory_rw);
67596 }
67597
67598 static void unset_module_init_ro_nx(struct module *mod)
67599 {
67600 - set_page_attributes(mod->module_init + mod->init_text_size,
67601 - mod->module_init + mod->init_size,
67602 + set_page_attributes(mod->module_init_rw,
67603 + mod->module_init_rw + mod->init_size_rw,
67604 set_memory_x);
67605 - set_page_attributes(mod->module_init,
67606 - mod->module_init + mod->init_ro_size,
67607 + set_page_attributes(mod->module_init_rx,
67608 + mod->module_init_rx + mod->init_size_rx,
67609 set_memory_rw);
67610 }
67611
67612 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67613
67614 mutex_lock(&module_mutex);
67615 list_for_each_entry_rcu(mod, &modules, list) {
67616 - if ((mod->module_core) && (mod->core_text_size)) {
67617 - set_page_attributes(mod->module_core,
67618 - mod->module_core + mod->core_text_size,
67619 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67620 + set_page_attributes(mod->module_core_rx,
67621 + mod->module_core_rx + mod->core_size_rx,
67622 set_memory_rw);
67623 }
67624 - if ((mod->module_init) && (mod->init_text_size)) {
67625 - set_page_attributes(mod->module_init,
67626 - mod->module_init + mod->init_text_size,
67627 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67628 + set_page_attributes(mod->module_init_rx,
67629 + mod->module_init_rx + mod->init_size_rx,
67630 set_memory_rw);
67631 }
67632 }
67633 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67634
67635 mutex_lock(&module_mutex);
67636 list_for_each_entry_rcu(mod, &modules, list) {
67637 - if ((mod->module_core) && (mod->core_text_size)) {
67638 - set_page_attributes(mod->module_core,
67639 - mod->module_core + mod->core_text_size,
67640 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67641 + set_page_attributes(mod->module_core_rx,
67642 + mod->module_core_rx + mod->core_size_rx,
67643 set_memory_ro);
67644 }
67645 - if ((mod->module_init) && (mod->init_text_size)) {
67646 - set_page_attributes(mod->module_init,
67647 - mod->module_init + mod->init_text_size,
67648 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67649 + set_page_attributes(mod->module_init_rx,
67650 + mod->module_init_rx + mod->init_size_rx,
67651 set_memory_ro);
67652 }
67653 }
67654 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67655
67656 /* This may be NULL, but that's OK */
67657 unset_module_init_ro_nx(mod);
67658 - module_free(mod, mod->module_init);
67659 + module_free(mod, mod->module_init_rw);
67660 + module_free_exec(mod, mod->module_init_rx);
67661 kfree(mod->args);
67662 percpu_modfree(mod);
67663
67664 /* Free lock-classes: */
67665 - lockdep_free_key_range(mod->module_core, mod->core_size);
67666 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67667 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67668
67669 /* Finally, free the core (containing the module structure) */
67670 unset_module_core_ro_nx(mod);
67671 - module_free(mod, mod->module_core);
67672 + module_free_exec(mod, mod->module_core_rx);
67673 + module_free(mod, mod->module_core_rw);
67674
67675 #ifdef CONFIG_MPU
67676 update_protections(current->mm);
67677 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67678 int ret = 0;
67679 const struct kernel_symbol *ksym;
67680
67681 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67682 + int is_fs_load = 0;
67683 + int register_filesystem_found = 0;
67684 + char *p;
67685 +
67686 + p = strstr(mod->args, "grsec_modharden_fs");
67687 + if (p) {
67688 + char *endptr = p + strlen("grsec_modharden_fs");
67689 + /* copy \0 as well */
67690 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67691 + is_fs_load = 1;
67692 + }
67693 +#endif
67694 +
67695 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67696 const char *name = info->strtab + sym[i].st_name;
67697
67698 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67699 + /* it's a real shame this will never get ripped and copied
67700 + upstream! ;(
67701 + */
67702 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67703 + register_filesystem_found = 1;
67704 +#endif
67705 +
67706 switch (sym[i].st_shndx) {
67707 case SHN_COMMON:
67708 /* We compiled with -fno-common. These are not
67709 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67710 ksym = resolve_symbol_wait(mod, info, name);
67711 /* Ok if resolved. */
67712 if (ksym && !IS_ERR(ksym)) {
67713 + pax_open_kernel();
67714 sym[i].st_value = ksym->value;
67715 + pax_close_kernel();
67716 break;
67717 }
67718
67719 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67720 secbase = (unsigned long)mod_percpu(mod);
67721 else
67722 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67723 + pax_open_kernel();
67724 sym[i].st_value += secbase;
67725 + pax_close_kernel();
67726 break;
67727 }
67728 }
67729
67730 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67731 + if (is_fs_load && !register_filesystem_found) {
67732 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67733 + ret = -EPERM;
67734 + }
67735 +#endif
67736 +
67737 return ret;
67738 }
67739
67740 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67741 || s->sh_entsize != ~0UL
67742 || strstarts(sname, ".init"))
67743 continue;
67744 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67745 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67746 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67747 + else
67748 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67749 pr_debug("\t%s\n", sname);
67750 }
67751 - switch (m) {
67752 - case 0: /* executable */
67753 - mod->core_size = debug_align(mod->core_size);
67754 - mod->core_text_size = mod->core_size;
67755 - break;
67756 - case 1: /* RO: text and ro-data */
67757 - mod->core_size = debug_align(mod->core_size);
67758 - mod->core_ro_size = mod->core_size;
67759 - break;
67760 - case 3: /* whole core */
67761 - mod->core_size = debug_align(mod->core_size);
67762 - break;
67763 - }
67764 }
67765
67766 pr_debug("Init section allocation order:\n");
67767 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67768 || s->sh_entsize != ~0UL
67769 || !strstarts(sname, ".init"))
67770 continue;
67771 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67772 - | INIT_OFFSET_MASK);
67773 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67774 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67775 + else
67776 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67777 + s->sh_entsize |= INIT_OFFSET_MASK;
67778 pr_debug("\t%s\n", sname);
67779 }
67780 - switch (m) {
67781 - case 0: /* executable */
67782 - mod->init_size = debug_align(mod->init_size);
67783 - mod->init_text_size = mod->init_size;
67784 - break;
67785 - case 1: /* RO: text and ro-data */
67786 - mod->init_size = debug_align(mod->init_size);
67787 - mod->init_ro_size = mod->init_size;
67788 - break;
67789 - case 3: /* whole init */
67790 - mod->init_size = debug_align(mod->init_size);
67791 - break;
67792 - }
67793 }
67794 }
67795
67796 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67797
67798 /* Put symbol section at end of init part of module. */
67799 symsect->sh_flags |= SHF_ALLOC;
67800 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67801 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67802 info->index.sym) | INIT_OFFSET_MASK;
67803 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67804
67805 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67806 }
67807
67808 /* Append room for core symbols at end of core part. */
67809 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67810 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67811 - mod->core_size += strtab_size;
67812 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67813 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67814 + mod->core_size_rx += strtab_size;
67815
67816 /* Put string table section at end of init part of module. */
67817 strsect->sh_flags |= SHF_ALLOC;
67818 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67819 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67820 info->index.str) | INIT_OFFSET_MASK;
67821 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67822 }
67823 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67824 /* Make sure we get permanent strtab: don't use info->strtab. */
67825 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67826
67827 + pax_open_kernel();
67828 +
67829 /* Set types up while we still have access to sections. */
67830 for (i = 0; i < mod->num_symtab; i++)
67831 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67832
67833 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67834 - mod->core_strtab = s = mod->module_core + info->stroffs;
67835 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67836 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67837 src = mod->symtab;
67838 *dst = *src;
67839 *s++ = 0;
67840 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67841 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67842 }
67843 mod->core_num_syms = ndst;
67844 +
67845 + pax_close_kernel();
67846 }
67847 #else
67848 static inline void layout_symtab(struct module *mod, struct load_info *info)
67849 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67850 return size == 0 ? NULL : vmalloc_exec(size);
67851 }
67852
67853 -static void *module_alloc_update_bounds(unsigned long size)
67854 +static void *module_alloc_update_bounds_rw(unsigned long size)
67855 {
67856 void *ret = module_alloc(size);
67857
67858 if (ret) {
67859 mutex_lock(&module_mutex);
67860 /* Update module bounds. */
67861 - if ((unsigned long)ret < module_addr_min)
67862 - module_addr_min = (unsigned long)ret;
67863 - if ((unsigned long)ret + size > module_addr_max)
67864 - module_addr_max = (unsigned long)ret + size;
67865 + if ((unsigned long)ret < module_addr_min_rw)
67866 + module_addr_min_rw = (unsigned long)ret;
67867 + if ((unsigned long)ret + size > module_addr_max_rw)
67868 + module_addr_max_rw = (unsigned long)ret + size;
67869 + mutex_unlock(&module_mutex);
67870 + }
67871 + return ret;
67872 +}
67873 +
67874 +static void *module_alloc_update_bounds_rx(unsigned long size)
67875 +{
67876 + void *ret = module_alloc_exec(size);
67877 +
67878 + if (ret) {
67879 + mutex_lock(&module_mutex);
67880 + /* Update module bounds. */
67881 + if ((unsigned long)ret < module_addr_min_rx)
67882 + module_addr_min_rx = (unsigned long)ret;
67883 + if ((unsigned long)ret + size > module_addr_max_rx)
67884 + module_addr_max_rx = (unsigned long)ret + size;
67885 mutex_unlock(&module_mutex);
67886 }
67887 return ret;
67888 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67889 static int check_modinfo(struct module *mod, struct load_info *info)
67890 {
67891 const char *modmagic = get_modinfo(info, "vermagic");
67892 + const char *license = get_modinfo(info, "license");
67893 int err;
67894
67895 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67896 + if (!license || !license_is_gpl_compatible(license))
67897 + return -ENOEXEC;
67898 +#endif
67899 +
67900 /* This is allowed: modprobe --force will invalidate it. */
67901 if (!modmagic) {
67902 err = try_to_force_load(mod, "bad vermagic");
67903 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67904 }
67905
67906 /* Set up license info based on the info section */
67907 - set_license(mod, get_modinfo(info, "license"));
67908 + set_license(mod, license);
67909
67910 return 0;
67911 }
67912 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67913 void *ptr;
67914
67915 /* Do the allocs. */
67916 - ptr = module_alloc_update_bounds(mod->core_size);
67917 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67918 /*
67919 * The pointer to this block is stored in the module structure
67920 * which is inside the block. Just mark it as not being a
67921 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67922 if (!ptr)
67923 return -ENOMEM;
67924
67925 - memset(ptr, 0, mod->core_size);
67926 - mod->module_core = ptr;
67927 + memset(ptr, 0, mod->core_size_rw);
67928 + mod->module_core_rw = ptr;
67929
67930 - ptr = module_alloc_update_bounds(mod->init_size);
67931 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67932 /*
67933 * The pointer to this block is stored in the module structure
67934 * which is inside the block. This block doesn't need to be
67935 * scanned as it contains data and code that will be freed
67936 * after the module is initialized.
67937 */
67938 - kmemleak_ignore(ptr);
67939 - if (!ptr && mod->init_size) {
67940 - module_free(mod, mod->module_core);
67941 + kmemleak_not_leak(ptr);
67942 + if (!ptr && mod->init_size_rw) {
67943 + module_free(mod, mod->module_core_rw);
67944 return -ENOMEM;
67945 }
67946 - memset(ptr, 0, mod->init_size);
67947 - mod->module_init = ptr;
67948 + memset(ptr, 0, mod->init_size_rw);
67949 + mod->module_init_rw = ptr;
67950 +
67951 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67952 + kmemleak_not_leak(ptr);
67953 + if (!ptr) {
67954 + module_free(mod, mod->module_init_rw);
67955 + module_free(mod, mod->module_core_rw);
67956 + return -ENOMEM;
67957 + }
67958 +
67959 + pax_open_kernel();
67960 + memset(ptr, 0, mod->core_size_rx);
67961 + pax_close_kernel();
67962 + mod->module_core_rx = ptr;
67963 +
67964 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67965 + kmemleak_not_leak(ptr);
67966 + if (!ptr && mod->init_size_rx) {
67967 + module_free_exec(mod, mod->module_core_rx);
67968 + module_free(mod, mod->module_init_rw);
67969 + module_free(mod, mod->module_core_rw);
67970 + return -ENOMEM;
67971 + }
67972 +
67973 + pax_open_kernel();
67974 + memset(ptr, 0, mod->init_size_rx);
67975 + pax_close_kernel();
67976 + mod->module_init_rx = ptr;
67977
67978 /* Transfer each section which specifies SHF_ALLOC */
67979 pr_debug("final section addresses:\n");
67980 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67981 if (!(shdr->sh_flags & SHF_ALLOC))
67982 continue;
67983
67984 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67985 - dest = mod->module_init
67986 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67987 - else
67988 - dest = mod->module_core + shdr->sh_entsize;
67989 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67990 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67991 + dest = mod->module_init_rw
67992 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67993 + else
67994 + dest = mod->module_init_rx
67995 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67996 + } else {
67997 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67998 + dest = mod->module_core_rw + shdr->sh_entsize;
67999 + else
68000 + dest = mod->module_core_rx + shdr->sh_entsize;
68001 + }
68002 +
68003 + if (shdr->sh_type != SHT_NOBITS) {
68004 +
68005 +#ifdef CONFIG_PAX_KERNEXEC
68006 +#ifdef CONFIG_X86_64
68007 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68008 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68009 +#endif
68010 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68011 + pax_open_kernel();
68012 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68013 + pax_close_kernel();
68014 + } else
68015 +#endif
68016
68017 - if (shdr->sh_type != SHT_NOBITS)
68018 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68019 + }
68020 /* Update sh_addr to point to copy in image. */
68021 - shdr->sh_addr = (unsigned long)dest;
68022 +
68023 +#ifdef CONFIG_PAX_KERNEXEC
68024 + if (shdr->sh_flags & SHF_EXECINSTR)
68025 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68026 + else
68027 +#endif
68028 +
68029 + shdr->sh_addr = (unsigned long)dest;
68030 pr_debug("\t0x%lx %s\n",
68031 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68032 }
68033 @@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
68034 * Do it before processing of module parameters, so the module
68035 * can provide parameter accessor functions of its own.
68036 */
68037 - if (mod->module_init)
68038 - flush_icache_range((unsigned long)mod->module_init,
68039 - (unsigned long)mod->module_init
68040 - + mod->init_size);
68041 - flush_icache_range((unsigned long)mod->module_core,
68042 - (unsigned long)mod->module_core + mod->core_size);
68043 + if (mod->module_init_rx)
68044 + flush_icache_range((unsigned long)mod->module_init_rx,
68045 + (unsigned long)mod->module_init_rx
68046 + + mod->init_size_rx);
68047 + flush_icache_range((unsigned long)mod->module_core_rx,
68048 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68049
68050 set_fs(old_fs);
68051 }
68052 @@ -2834,8 +2934,10 @@ out:
68053 static void module_deallocate(struct module *mod, struct load_info *info)
68054 {
68055 percpu_modfree(mod);
68056 - module_free(mod, mod->module_init);
68057 - module_free(mod, mod->module_core);
68058 + module_free_exec(mod, mod->module_init_rx);
68059 + module_free_exec(mod, mod->module_core_rx);
68060 + module_free(mod, mod->module_init_rw);
68061 + module_free(mod, mod->module_core_rw);
68062 }
68063
68064 int __weak module_finalize(const Elf_Ehdr *hdr,
68065 @@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68066 static int post_relocation(struct module *mod, const struct load_info *info)
68067 {
68068 /* Sort exception table now relocations are done. */
68069 + pax_open_kernel();
68070 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68071 + pax_close_kernel();
68072
68073 /* Copy relocated percpu area over. */
68074 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68075 @@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
68076 if (err)
68077 goto free_unload;
68078
68079 + /* Now copy in args */
68080 + mod->args = strndup_user(uargs, ~0UL >> 1);
68081 + if (IS_ERR(mod->args)) {
68082 + err = PTR_ERR(mod->args);
68083 + goto free_unload;
68084 + }
68085 +
68086 /* Set up MODINFO_ATTR fields */
68087 setup_modinfo(mod, &info);
68088
68089 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68090 + {
68091 + char *p, *p2;
68092 +
68093 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68094 + 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);
68095 + err = -EPERM;
68096 + goto free_modinfo;
68097 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68098 + p += strlen("grsec_modharden_normal");
68099 + p2 = strstr(p, "_");
68100 + if (p2) {
68101 + *p2 = '\0';
68102 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68103 + *p2 = '_';
68104 + }
68105 + err = -EPERM;
68106 + goto free_modinfo;
68107 + }
68108 + }
68109 +#endif
68110 +
68111 /* Fix up syms, so that st_value is a pointer to location. */
68112 err = simplify_symbols(mod, &info);
68113 if (err < 0)
68114 @@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68115
68116 flush_module_icache(mod);
68117
68118 - /* Now copy in args */
68119 - mod->args = strndup_user(uargs, ~0UL >> 1);
68120 - if (IS_ERR(mod->args)) {
68121 - err = PTR_ERR(mod->args);
68122 - goto free_arch_cleanup;
68123 - }
68124 -
68125 /* Mark state as coming so strong_try_module_get() ignores us. */
68126 mod->state = MODULE_STATE_COMING;
68127
68128 @@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68129 unlock:
68130 mutex_unlock(&module_mutex);
68131 synchronize_sched();
68132 - kfree(mod->args);
68133 - free_arch_cleanup:
68134 module_arch_cleanup(mod);
68135 free_modinfo:
68136 free_modinfo(mod);
68137 + kfree(mod->args);
68138 free_unload:
68139 module_unload_free(mod);
68140 free_module:
68141 @@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68142 MODULE_STATE_COMING, mod);
68143
68144 /* Set RO and NX regions for core */
68145 - set_section_ro_nx(mod->module_core,
68146 - mod->core_text_size,
68147 - mod->core_ro_size,
68148 - mod->core_size);
68149 + set_section_ro_nx(mod->module_core_rx,
68150 + mod->core_size_rx,
68151 + mod->core_size_rx,
68152 + mod->core_size_rx);
68153
68154 /* Set RO and NX regions for init */
68155 - set_section_ro_nx(mod->module_init,
68156 - mod->init_text_size,
68157 - mod->init_ro_size,
68158 - mod->init_size);
68159 + set_section_ro_nx(mod->module_init_rx,
68160 + mod->init_size_rx,
68161 + mod->init_size_rx,
68162 + mod->init_size_rx);
68163
68164 do_mod_ctors(mod);
68165 /* Start the module */
68166 @@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68167 mod->strtab = mod->core_strtab;
68168 #endif
68169 unset_module_init_ro_nx(mod);
68170 - module_free(mod, mod->module_init);
68171 - mod->module_init = NULL;
68172 - mod->init_size = 0;
68173 - mod->init_ro_size = 0;
68174 - mod->init_text_size = 0;
68175 + module_free(mod, mod->module_init_rw);
68176 + module_free_exec(mod, mod->module_init_rx);
68177 + mod->module_init_rw = NULL;
68178 + mod->module_init_rx = NULL;
68179 + mod->init_size_rw = 0;
68180 + mod->init_size_rx = 0;
68181 mutex_unlock(&module_mutex);
68182
68183 return 0;
68184 @@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68185 unsigned long nextval;
68186
68187 /* At worse, next value is at end of module */
68188 - if (within_module_init(addr, mod))
68189 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68190 + if (within_module_init_rx(addr, mod))
68191 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68192 + else if (within_module_init_rw(addr, mod))
68193 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68194 + else if (within_module_core_rx(addr, mod))
68195 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68196 + else if (within_module_core_rw(addr, mod))
68197 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68198 else
68199 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68200 + return NULL;
68201
68202 /* Scan for closest preceding symbol, and next symbol. (ELF
68203 starts real symbols at 1). */
68204 @@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68205 char buf[8];
68206
68207 seq_printf(m, "%s %u",
68208 - mod->name, mod->init_size + mod->core_size);
68209 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68210 print_unload_info(m, mod);
68211
68212 /* Informative for users. */
68213 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68214 mod->state == MODULE_STATE_COMING ? "Loading":
68215 "Live");
68216 /* Used by oprofile and other similar tools. */
68217 - seq_printf(m, " 0x%pK", mod->module_core);
68218 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68219
68220 /* Taints info */
68221 if (mod->taints)
68222 @@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68223
68224 static int __init proc_modules_init(void)
68225 {
68226 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68227 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68228 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68229 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68230 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68231 +#else
68232 proc_create("modules", 0, NULL, &proc_modules_operations);
68233 +#endif
68234 +#else
68235 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68236 +#endif
68237 return 0;
68238 }
68239 module_init(proc_modules_init);
68240 @@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68241 {
68242 struct module *mod;
68243
68244 - if (addr < module_addr_min || addr > module_addr_max)
68245 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68246 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68247 return NULL;
68248
68249 list_for_each_entry_rcu(mod, &modules, list)
68250 - if (within_module_core(addr, mod)
68251 - || within_module_init(addr, mod))
68252 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68253 return mod;
68254 return NULL;
68255 }
68256 @@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68257 */
68258 struct module *__module_text_address(unsigned long addr)
68259 {
68260 - struct module *mod = __module_address(addr);
68261 + struct module *mod;
68262 +
68263 +#ifdef CONFIG_X86_32
68264 + addr = ktla_ktva(addr);
68265 +#endif
68266 +
68267 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68268 + return NULL;
68269 +
68270 + mod = __module_address(addr);
68271 +
68272 if (mod) {
68273 /* Make sure it's within the text section. */
68274 - if (!within(addr, mod->module_init, mod->init_text_size)
68275 - && !within(addr, mod->module_core, mod->core_text_size))
68276 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68277 mod = NULL;
68278 }
68279 return mod;
68280 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68281 index 7e3443f..b2a1e6b 100644
68282 --- a/kernel/mutex-debug.c
68283 +++ b/kernel/mutex-debug.c
68284 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68285 }
68286
68287 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68288 - struct thread_info *ti)
68289 + struct task_struct *task)
68290 {
68291 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68292
68293 /* Mark the current thread as blocked on the lock: */
68294 - ti->task->blocked_on = waiter;
68295 + task->blocked_on = waiter;
68296 }
68297
68298 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68299 - struct thread_info *ti)
68300 + struct task_struct *task)
68301 {
68302 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68303 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68304 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68305 - ti->task->blocked_on = NULL;
68306 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68307 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68308 + task->blocked_on = NULL;
68309
68310 list_del_init(&waiter->list);
68311 waiter->task = NULL;
68312 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68313 index 0799fd3..d06ae3b 100644
68314 --- a/kernel/mutex-debug.h
68315 +++ b/kernel/mutex-debug.h
68316 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68317 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68318 extern void debug_mutex_add_waiter(struct mutex *lock,
68319 struct mutex_waiter *waiter,
68320 - struct thread_info *ti);
68321 + struct task_struct *task);
68322 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68323 - struct thread_info *ti);
68324 + struct task_struct *task);
68325 extern void debug_mutex_unlock(struct mutex *lock);
68326 extern void debug_mutex_init(struct mutex *lock, const char *name,
68327 struct lock_class_key *key);
68328 diff --git a/kernel/mutex.c b/kernel/mutex.c
68329 index a307cc9..27fd2e9 100644
68330 --- a/kernel/mutex.c
68331 +++ b/kernel/mutex.c
68332 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68333 spin_lock_mutex(&lock->wait_lock, flags);
68334
68335 debug_mutex_lock_common(lock, &waiter);
68336 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68337 + debug_mutex_add_waiter(lock, &waiter, task);
68338
68339 /* add waiting tasks to the end of the waitqueue (FIFO): */
68340 list_add_tail(&waiter.list, &lock->wait_list);
68341 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68342 * TASK_UNINTERRUPTIBLE case.)
68343 */
68344 if (unlikely(signal_pending_state(state, task))) {
68345 - mutex_remove_waiter(lock, &waiter,
68346 - task_thread_info(task));
68347 + mutex_remove_waiter(lock, &waiter, task);
68348 mutex_release(&lock->dep_map, 1, ip);
68349 spin_unlock_mutex(&lock->wait_lock, flags);
68350
68351 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68352 done:
68353 lock_acquired(&lock->dep_map, ip);
68354 /* got the lock - rejoice! */
68355 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68356 + mutex_remove_waiter(lock, &waiter, task);
68357 mutex_set_owner(lock);
68358
68359 /* set it to 0 if there are no waiters left: */
68360 diff --git a/kernel/panic.c b/kernel/panic.c
68361 index d2a5f4e..5edc1d9 100644
68362 --- a/kernel/panic.c
68363 +++ b/kernel/panic.c
68364 @@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68365 int state = 0;
68366
68367 /*
68368 + * Disable local interrupts. This will prevent panic_smp_self_stop
68369 + * from deadlocking the first cpu that invokes the panic, since
68370 + * there is nothing to prevent an interrupt handler (that runs
68371 + * after the panic_lock is acquired) from invoking panic again.
68372 + */
68373 + local_irq_disable();
68374 +
68375 + /*
68376 * It's possible to come here directly from a panic-assertion and
68377 * not have preempt disabled. Some functions called from here want
68378 * preempt to be disabled. No point enabling it later though...
68379 @@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68380 const char *board;
68381
68382 printk(KERN_WARNING "------------[ cut here ]------------\n");
68383 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68384 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68385 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68386 if (board)
68387 printk(KERN_WARNING "Hardware name: %s\n", board);
68388 @@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68389 */
68390 void __stack_chk_fail(void)
68391 {
68392 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68393 + dump_stack();
68394 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68395 __builtin_return_address(0));
68396 }
68397 EXPORT_SYMBOL(__stack_chk_fail);
68398 diff --git a/kernel/pid.c b/kernel/pid.c
68399 index e86b291a..e8b0fb5 100644
68400 --- a/kernel/pid.c
68401 +++ b/kernel/pid.c
68402 @@ -33,6 +33,7 @@
68403 #include <linux/rculist.h>
68404 #include <linux/bootmem.h>
68405 #include <linux/hash.h>
68406 +#include <linux/security.h>
68407 #include <linux/pid_namespace.h>
68408 #include <linux/init_task.h>
68409 #include <linux/syscalls.h>
68410 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68411
68412 int pid_max = PID_MAX_DEFAULT;
68413
68414 -#define RESERVED_PIDS 300
68415 +#define RESERVED_PIDS 500
68416
68417 int pid_max_min = RESERVED_PIDS + 1;
68418 int pid_max_max = PID_MAX_LIMIT;
68419 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68420 */
68421 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68422 {
68423 + struct task_struct *task;
68424 +
68425 rcu_lockdep_assert(rcu_read_lock_held(),
68426 "find_task_by_pid_ns() needs rcu_read_lock()"
68427 " protection");
68428 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68429 +
68430 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68431 +
68432 + if (gr_pid_is_chrooted(task))
68433 + return NULL;
68434 +
68435 + return task;
68436 }
68437
68438 struct task_struct *find_task_by_vpid(pid_t vnr)
68439 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68440 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68441 }
68442
68443 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68444 +{
68445 + rcu_lockdep_assert(rcu_read_lock_held(),
68446 + "find_task_by_pid_ns() needs rcu_read_lock()"
68447 + " protection");
68448 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68449 +}
68450 +
68451 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68452 {
68453 struct pid *pid;
68454 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68455 index 125cb67..a4d1c30 100644
68456 --- a/kernel/posix-cpu-timers.c
68457 +++ b/kernel/posix-cpu-timers.c
68458 @@ -6,6 +6,7 @@
68459 #include <linux/posix-timers.h>
68460 #include <linux/errno.h>
68461 #include <linux/math64.h>
68462 +#include <linux/security.h>
68463 #include <asm/uaccess.h>
68464 #include <linux/kernel_stat.h>
68465 #include <trace/events/timer.h>
68466 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68467
68468 static __init int init_posix_cpu_timers(void)
68469 {
68470 - struct k_clock process = {
68471 + static struct k_clock process = {
68472 .clock_getres = process_cpu_clock_getres,
68473 .clock_get = process_cpu_clock_get,
68474 .timer_create = process_cpu_timer_create,
68475 .nsleep = process_cpu_nsleep,
68476 .nsleep_restart = process_cpu_nsleep_restart,
68477 };
68478 - struct k_clock thread = {
68479 + static struct k_clock thread = {
68480 .clock_getres = thread_cpu_clock_getres,
68481 .clock_get = thread_cpu_clock_get,
68482 .timer_create = thread_cpu_timer_create,
68483 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68484 index 69185ae..cc2847a 100644
68485 --- a/kernel/posix-timers.c
68486 +++ b/kernel/posix-timers.c
68487 @@ -43,6 +43,7 @@
68488 #include <linux/idr.h>
68489 #include <linux/posix-clock.h>
68490 #include <linux/posix-timers.h>
68491 +#include <linux/grsecurity.h>
68492 #include <linux/syscalls.h>
68493 #include <linux/wait.h>
68494 #include <linux/workqueue.h>
68495 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68496 * which we beg off on and pass to do_sys_settimeofday().
68497 */
68498
68499 -static struct k_clock posix_clocks[MAX_CLOCKS];
68500 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68501
68502 /*
68503 * These ones are defined below.
68504 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68505 */
68506 static __init int init_posix_timers(void)
68507 {
68508 - struct k_clock clock_realtime = {
68509 + static struct k_clock clock_realtime = {
68510 .clock_getres = hrtimer_get_res,
68511 .clock_get = posix_clock_realtime_get,
68512 .clock_set = posix_clock_realtime_set,
68513 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68514 .timer_get = common_timer_get,
68515 .timer_del = common_timer_del,
68516 };
68517 - struct k_clock clock_monotonic = {
68518 + static struct k_clock clock_monotonic = {
68519 .clock_getres = hrtimer_get_res,
68520 .clock_get = posix_ktime_get_ts,
68521 .nsleep = common_nsleep,
68522 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68523 .timer_get = common_timer_get,
68524 .timer_del = common_timer_del,
68525 };
68526 - struct k_clock clock_monotonic_raw = {
68527 + static struct k_clock clock_monotonic_raw = {
68528 .clock_getres = hrtimer_get_res,
68529 .clock_get = posix_get_monotonic_raw,
68530 };
68531 - struct k_clock clock_realtime_coarse = {
68532 + static struct k_clock clock_realtime_coarse = {
68533 .clock_getres = posix_get_coarse_res,
68534 .clock_get = posix_get_realtime_coarse,
68535 };
68536 - struct k_clock clock_monotonic_coarse = {
68537 + static struct k_clock clock_monotonic_coarse = {
68538 .clock_getres = posix_get_coarse_res,
68539 .clock_get = posix_get_monotonic_coarse,
68540 };
68541 - struct k_clock clock_boottime = {
68542 + static struct k_clock clock_boottime = {
68543 .clock_getres = hrtimer_get_res,
68544 .clock_get = posix_get_boottime,
68545 .nsleep = common_nsleep,
68546 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68547 return;
68548 }
68549
68550 - posix_clocks[clock_id] = *new_clock;
68551 + posix_clocks[clock_id] = new_clock;
68552 }
68553 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68554
68555 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68556 return (id & CLOCKFD_MASK) == CLOCKFD ?
68557 &clock_posix_dynamic : &clock_posix_cpu;
68558
68559 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68560 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68561 return NULL;
68562 - return &posix_clocks[id];
68563 + return posix_clocks[id];
68564 }
68565
68566 static int common_timer_create(struct k_itimer *new_timer)
68567 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68568 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68569 return -EFAULT;
68570
68571 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68572 + have their clock_set fptr set to a nosettime dummy function
68573 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68574 + call common_clock_set, which calls do_sys_settimeofday, which
68575 + we hook
68576 + */
68577 +
68578 return kc->clock_set(which_clock, &new_tp);
68579 }
68580
68581 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68582 index d523593..68197a4 100644
68583 --- a/kernel/power/poweroff.c
68584 +++ b/kernel/power/poweroff.c
68585 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68586 .enable_mask = SYSRQ_ENABLE_BOOT,
68587 };
68588
68589 -static int pm_sysrq_init(void)
68590 +static int __init pm_sysrq_init(void)
68591 {
68592 register_sysrq_key('o', &sysrq_poweroff_op);
68593 return 0;
68594 diff --git a/kernel/power/process.c b/kernel/power/process.c
68595 index 19db29f..33b52b6 100644
68596 --- a/kernel/power/process.c
68597 +++ b/kernel/power/process.c
68598 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68599 u64 elapsed_csecs64;
68600 unsigned int elapsed_csecs;
68601 bool wakeup = false;
68602 + bool timedout = false;
68603
68604 do_gettimeofday(&start);
68605
68606 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68607
68608 while (true) {
68609 todo = 0;
68610 + if (time_after(jiffies, end_time))
68611 + timedout = true;
68612 read_lock(&tasklist_lock);
68613 do_each_thread(g, p) {
68614 if (p == current || !freeze_task(p))
68615 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68616 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68617 * transition can't race with task state testing here.
68618 */
68619 - if (!task_is_stopped_or_traced(p) &&
68620 - !freezer_should_skip(p))
68621 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68622 todo++;
68623 + if (timedout) {
68624 + printk(KERN_ERR "Task refusing to freeze:\n");
68625 + sched_show_task(p);
68626 + }
68627 + }
68628 } while_each_thread(g, p);
68629 read_unlock(&tasklist_lock);
68630
68631 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68632 todo += wq_busy;
68633 }
68634
68635 - if (!todo || time_after(jiffies, end_time))
68636 + if (!todo || timedout)
68637 break;
68638
68639 if (pm_wakeup_pending()) {
68640 diff --git a/kernel/printk.c b/kernel/printk.c
68641 index 146827f..a501fec 100644
68642 --- a/kernel/printk.c
68643 +++ b/kernel/printk.c
68644 @@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
68645 if (from_file && type != SYSLOG_ACTION_OPEN)
68646 return 0;
68647
68648 +#ifdef CONFIG_GRKERNSEC_DMESG
68649 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68650 + return -EPERM;
68651 +#endif
68652 +
68653 if (syslog_action_restricted(type)) {
68654 if (capable(CAP_SYSLOG))
68655 return 0;
68656 diff --git a/kernel/profile.c b/kernel/profile.c
68657 index 76b8e77..a2930e8 100644
68658 --- a/kernel/profile.c
68659 +++ b/kernel/profile.c
68660 @@ -39,7 +39,7 @@ struct profile_hit {
68661 /* Oprofile timer tick hook */
68662 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68663
68664 -static atomic_t *prof_buffer;
68665 +static atomic_unchecked_t *prof_buffer;
68666 static unsigned long prof_len, prof_shift;
68667
68668 int prof_on __read_mostly;
68669 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68670 hits[i].pc = 0;
68671 continue;
68672 }
68673 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68674 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68675 hits[i].hits = hits[i].pc = 0;
68676 }
68677 }
68678 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68679 * Add the current hit(s) and flush the write-queue out
68680 * to the global buffer:
68681 */
68682 - atomic_add(nr_hits, &prof_buffer[pc]);
68683 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68684 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68685 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68686 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68687 hits[i].pc = hits[i].hits = 0;
68688 }
68689 out:
68690 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68691 {
68692 unsigned long pc;
68693 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68694 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68695 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68696 }
68697 #endif /* !CONFIG_SMP */
68698
68699 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68700 return -EFAULT;
68701 buf++; p++; count--; read++;
68702 }
68703 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68704 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68705 if (copy_to_user(buf, (void *)pnt, count))
68706 return -EFAULT;
68707 read += count;
68708 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68709 }
68710 #endif
68711 profile_discard_flip_buffers();
68712 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68713 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68714 return count;
68715 }
68716
68717 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68718 index a232bb5..2a65ef9 100644
68719 --- a/kernel/ptrace.c
68720 +++ b/kernel/ptrace.c
68721 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68722
68723 if (seize)
68724 flags |= PT_SEIZED;
68725 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68726 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68727 flags |= PT_PTRACE_CAP;
68728 task->ptrace = flags;
68729
68730 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68731 break;
68732 return -EIO;
68733 }
68734 - if (copy_to_user(dst, buf, retval))
68735 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68736 return -EFAULT;
68737 copied += retval;
68738 src += retval;
68739 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68740 bool seized = child->ptrace & PT_SEIZED;
68741 int ret = -EIO;
68742 siginfo_t siginfo, *si;
68743 - void __user *datavp = (void __user *) data;
68744 + void __user *datavp = (__force void __user *) data;
68745 unsigned long __user *datalp = datavp;
68746 unsigned long flags;
68747
68748 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68749 goto out;
68750 }
68751
68752 + if (gr_handle_ptrace(child, request)) {
68753 + ret = -EPERM;
68754 + goto out_put_task_struct;
68755 + }
68756 +
68757 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68758 ret = ptrace_attach(child, request, addr, data);
68759 /*
68760 * Some architectures need to do book-keeping after
68761 * a ptrace attach.
68762 */
68763 - if (!ret)
68764 + if (!ret) {
68765 arch_ptrace_attach(child);
68766 + gr_audit_ptrace(child);
68767 + }
68768 goto out_put_task_struct;
68769 }
68770
68771 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68772 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68773 if (copied != sizeof(tmp))
68774 return -EIO;
68775 - return put_user(tmp, (unsigned long __user *)data);
68776 + return put_user(tmp, (__force unsigned long __user *)data);
68777 }
68778
68779 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68780 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68781 goto out;
68782 }
68783
68784 + if (gr_handle_ptrace(child, request)) {
68785 + ret = -EPERM;
68786 + goto out_put_task_struct;
68787 + }
68788 +
68789 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68790 ret = ptrace_attach(child, request, addr, data);
68791 /*
68792 * Some architectures need to do book-keeping after
68793 * a ptrace attach.
68794 */
68795 - if (!ret)
68796 + if (!ret) {
68797 arch_ptrace_attach(child);
68798 + gr_audit_ptrace(child);
68799 + }
68800 goto out_put_task_struct;
68801 }
68802
68803 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68804 index 37a5444..eec170a 100644
68805 --- a/kernel/rcutiny.c
68806 +++ b/kernel/rcutiny.c
68807 @@ -46,7 +46,7 @@
68808 struct rcu_ctrlblk;
68809 static void invoke_rcu_callbacks(void);
68810 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68811 -static void rcu_process_callbacks(struct softirq_action *unused);
68812 +static void rcu_process_callbacks(void);
68813 static void __call_rcu(struct rcu_head *head,
68814 void (*func)(struct rcu_head *rcu),
68815 struct rcu_ctrlblk *rcp);
68816 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68817 rcu_is_callbacks_kthread()));
68818 }
68819
68820 -static void rcu_process_callbacks(struct softirq_action *unused)
68821 +static void rcu_process_callbacks(void)
68822 {
68823 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68824 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68825 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68826 index fc31a2d..be2ec04 100644
68827 --- a/kernel/rcutiny_plugin.h
68828 +++ b/kernel/rcutiny_plugin.h
68829 @@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68830 have_rcu_kthread_work = morework;
68831 local_irq_restore(flags);
68832 if (work)
68833 - rcu_process_callbacks(NULL);
68834 + rcu_process_callbacks();
68835 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68836 }
68837
68838 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68839 index e66b34a..4b8b626 100644
68840 --- a/kernel/rcutorture.c
68841 +++ b/kernel/rcutorture.c
68842 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68843 { 0 };
68844 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68845 { 0 };
68846 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68847 -static atomic_t n_rcu_torture_alloc;
68848 -static atomic_t n_rcu_torture_alloc_fail;
68849 -static atomic_t n_rcu_torture_free;
68850 -static atomic_t n_rcu_torture_mberror;
68851 -static atomic_t n_rcu_torture_error;
68852 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68853 +static atomic_unchecked_t n_rcu_torture_alloc;
68854 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68855 +static atomic_unchecked_t n_rcu_torture_free;
68856 +static atomic_unchecked_t n_rcu_torture_mberror;
68857 +static atomic_unchecked_t n_rcu_torture_error;
68858 static long n_rcu_torture_barrier_error;
68859 static long n_rcu_torture_boost_ktrerror;
68860 static long n_rcu_torture_boost_rterror;
68861 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68862
68863 spin_lock_bh(&rcu_torture_lock);
68864 if (list_empty(&rcu_torture_freelist)) {
68865 - atomic_inc(&n_rcu_torture_alloc_fail);
68866 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68867 spin_unlock_bh(&rcu_torture_lock);
68868 return NULL;
68869 }
68870 - atomic_inc(&n_rcu_torture_alloc);
68871 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68872 p = rcu_torture_freelist.next;
68873 list_del_init(p);
68874 spin_unlock_bh(&rcu_torture_lock);
68875 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68876 static void
68877 rcu_torture_free(struct rcu_torture *p)
68878 {
68879 - atomic_inc(&n_rcu_torture_free);
68880 + atomic_inc_unchecked(&n_rcu_torture_free);
68881 spin_lock_bh(&rcu_torture_lock);
68882 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68883 spin_unlock_bh(&rcu_torture_lock);
68884 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68885 i = rp->rtort_pipe_count;
68886 if (i > RCU_TORTURE_PIPE_LEN)
68887 i = RCU_TORTURE_PIPE_LEN;
68888 - atomic_inc(&rcu_torture_wcount[i]);
68889 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68890 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68891 rp->rtort_mbtest = 0;
68892 rcu_torture_free(rp);
68893 @@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68894 i = rp->rtort_pipe_count;
68895 if (i > RCU_TORTURE_PIPE_LEN)
68896 i = RCU_TORTURE_PIPE_LEN;
68897 - atomic_inc(&rcu_torture_wcount[i]);
68898 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68899 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68900 rp->rtort_mbtest = 0;
68901 list_del(&rp->rtort_free);
68902 @@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68903 i = old_rp->rtort_pipe_count;
68904 if (i > RCU_TORTURE_PIPE_LEN)
68905 i = RCU_TORTURE_PIPE_LEN;
68906 - atomic_inc(&rcu_torture_wcount[i]);
68907 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68908 old_rp->rtort_pipe_count++;
68909 cur_ops->deferred_free(old_rp);
68910 }
68911 @@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68912 }
68913 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68914 if (p->rtort_mbtest == 0)
68915 - atomic_inc(&n_rcu_torture_mberror);
68916 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68917 spin_lock(&rand_lock);
68918 cur_ops->read_delay(&rand);
68919 n_rcu_torture_timers++;
68920 @@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68921 }
68922 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68923 if (p->rtort_mbtest == 0)
68924 - atomic_inc(&n_rcu_torture_mberror);
68925 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68926 cur_ops->read_delay(&rand);
68927 preempt_disable();
68928 pipe_count = p->rtort_pipe_count;
68929 @@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68930 rcu_torture_current,
68931 rcu_torture_current_version,
68932 list_empty(&rcu_torture_freelist),
68933 - atomic_read(&n_rcu_torture_alloc),
68934 - atomic_read(&n_rcu_torture_alloc_fail),
68935 - atomic_read(&n_rcu_torture_free),
68936 - atomic_read(&n_rcu_torture_mberror),
68937 + atomic_read_unchecked(&n_rcu_torture_alloc),
68938 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68939 + atomic_read_unchecked(&n_rcu_torture_free),
68940 + atomic_read_unchecked(&n_rcu_torture_mberror),
68941 n_rcu_torture_boost_ktrerror,
68942 n_rcu_torture_boost_rterror,
68943 n_rcu_torture_boost_failure,
68944 @@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68945 n_barrier_attempts,
68946 n_rcu_torture_barrier_error);
68947 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68948 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68949 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68950 n_rcu_torture_barrier_error != 0 ||
68951 n_rcu_torture_boost_ktrerror != 0 ||
68952 n_rcu_torture_boost_rterror != 0 ||
68953 n_rcu_torture_boost_failure != 0 ||
68954 i > 1) {
68955 cnt += sprintf(&page[cnt], "!!! ");
68956 - atomic_inc(&n_rcu_torture_error);
68957 + atomic_inc_unchecked(&n_rcu_torture_error);
68958 WARN_ON_ONCE(1);
68959 }
68960 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68961 @@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68962 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68963 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68964 cnt += sprintf(&page[cnt], " %d",
68965 - atomic_read(&rcu_torture_wcount[i]));
68966 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68967 }
68968 cnt += sprintf(&page[cnt], "\n");
68969 if (cur_ops->stats)
68970 @@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68971
68972 if (cur_ops->cleanup)
68973 cur_ops->cleanup();
68974 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68975 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68976 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68977 else if (n_online_successes != n_online_attempts ||
68978 n_offline_successes != n_offline_attempts)
68979 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68980
68981 rcu_torture_current = NULL;
68982 rcu_torture_current_version = 0;
68983 - atomic_set(&n_rcu_torture_alloc, 0);
68984 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68985 - atomic_set(&n_rcu_torture_free, 0);
68986 - atomic_set(&n_rcu_torture_mberror, 0);
68987 - atomic_set(&n_rcu_torture_error, 0);
68988 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68989 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68990 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68991 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68992 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68993 n_rcu_torture_barrier_error = 0;
68994 n_rcu_torture_boost_ktrerror = 0;
68995 n_rcu_torture_boost_rterror = 0;
68996 n_rcu_torture_boost_failure = 0;
68997 n_rcu_torture_boosts = 0;
68998 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68999 - atomic_set(&rcu_torture_wcount[i], 0);
69000 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69001 for_each_possible_cpu(cpu) {
69002 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69003 per_cpu(rcu_torture_count, cpu)[i] = 0;
69004 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69005 index 4b97bba..b92c9d2 100644
69006 --- a/kernel/rcutree.c
69007 +++ b/kernel/rcutree.c
69008 @@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69009 rcu_prepare_for_idle(smp_processor_id());
69010 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69011 smp_mb__before_atomic_inc(); /* See above. */
69012 - atomic_inc(&rdtp->dynticks);
69013 + atomic_inc_unchecked(&rdtp->dynticks);
69014 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69015 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69016 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69017
69018 /*
69019 * The idle task is not permitted to enter the idle loop while
69020 @@ -457,10 +457,10 @@ void rcu_irq_exit(void)
69021 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69022 {
69023 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69024 - atomic_inc(&rdtp->dynticks);
69025 + atomic_inc_unchecked(&rdtp->dynticks);
69026 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69027 smp_mb__after_atomic_inc(); /* See above. */
69028 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69029 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69030 rcu_cleanup_after_idle(smp_processor_id());
69031 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69032 if (!is_idle_task(current)) {
69033 @@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
69034 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69035
69036 if (rdtp->dynticks_nmi_nesting == 0 &&
69037 - (atomic_read(&rdtp->dynticks) & 0x1))
69038 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69039 return;
69040 rdtp->dynticks_nmi_nesting++;
69041 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69042 - atomic_inc(&rdtp->dynticks);
69043 + atomic_inc_unchecked(&rdtp->dynticks);
69044 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69045 smp_mb__after_atomic_inc(); /* See above. */
69046 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69047 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69048 }
69049
69050 /**
69051 @@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
69052 return;
69053 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69054 smp_mb__before_atomic_inc(); /* See above. */
69055 - atomic_inc(&rdtp->dynticks);
69056 + atomic_inc_unchecked(&rdtp->dynticks);
69057 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69058 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69059 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69060 }
69061
69062 #ifdef CONFIG_PROVE_RCU
69063 @@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
69064 int ret;
69065
69066 preempt_disable();
69067 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69068 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69069 preempt_enable();
69070 return ret;
69071 }
69072 @@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69073 */
69074 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69075 {
69076 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69077 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69078 return (rdp->dynticks_snap & 0x1) == 0;
69079 }
69080
69081 @@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69082 unsigned int curr;
69083 unsigned int snap;
69084
69085 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69086 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69087 snap = (unsigned int)rdp->dynticks_snap;
69088
69089 /*
69090 @@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
69091 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69092 */
69093 if (till_stall_check < 3) {
69094 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69095 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69096 till_stall_check = 3;
69097 } else if (till_stall_check > 300) {
69098 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69099 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69100 till_stall_check = 300;
69101 }
69102 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69103 @@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
69104 /*
69105 * Do RCU core processing for the current CPU.
69106 */
69107 -static void rcu_process_callbacks(struct softirq_action *unused)
69108 +static void rcu_process_callbacks(void)
69109 {
69110 trace_rcu_utilization("Start RCU core");
69111 __rcu_process_callbacks(&rcu_sched_state,
69112 @@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
69113 }
69114 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69115
69116 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69117 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69118 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69119 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69120
69121 static int synchronize_sched_expedited_cpu_stop(void *data)
69122 {
69123 @@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
69124 int firstsnap, s, snap, trycount = 0;
69125
69126 /* Note that atomic_inc_return() implies full memory barrier. */
69127 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69128 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69129 get_online_cpus();
69130 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69131
69132 @@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
69133 }
69134
69135 /* Check to see if someone else did our work for us. */
69136 - s = atomic_read(&sync_sched_expedited_done);
69137 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69138 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69139 smp_mb(); /* ensure test happens before caller kfree */
69140 return;
69141 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69142 * grace period works for us.
69143 */
69144 get_online_cpus();
69145 - snap = atomic_read(&sync_sched_expedited_started);
69146 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69147 smp_mb(); /* ensure read is before try_stop_cpus(). */
69148 }
69149
69150 @@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
69151 * than we did beat us to the punch.
69152 */
69153 do {
69154 - s = atomic_read(&sync_sched_expedited_done);
69155 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69156 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69157 smp_mb(); /* ensure test happens before caller kfree */
69158 break;
69159 }
69160 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69161 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69162
69163 put_online_cpus();
69164 }
69165 @@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69166 rdp->qlen = 0;
69167 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69168 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69169 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69170 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69171 rdp->cpu = cpu;
69172 rdp->rsp = rsp;
69173 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69174 @@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69175 rdp->n_force_qs_snap = rsp->n_force_qs;
69176 rdp->blimit = blimit;
69177 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69178 - atomic_set(&rdp->dynticks->dynticks,
69179 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69180 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69181 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69182 rcu_prepare_for_idle_init(cpu);
69183 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69184
69185 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69186 index 19b61ac..5c60a94 100644
69187 --- a/kernel/rcutree.h
69188 +++ b/kernel/rcutree.h
69189 @@ -83,7 +83,7 @@ struct rcu_dynticks {
69190 long long dynticks_nesting; /* Track irq/process nesting level. */
69191 /* Process level is worth LLONG_MAX/2. */
69192 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69193 - atomic_t dynticks; /* Even value for idle, else odd. */
69194 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69195 #ifdef CONFIG_RCU_FAST_NO_HZ
69196 int dyntick_drain; /* Prepare-for-idle state variable. */
69197 unsigned long dyntick_holdoff;
69198 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69199 index 3e48994..d94f03a 100644
69200 --- a/kernel/rcutree_plugin.h
69201 +++ b/kernel/rcutree_plugin.h
69202 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
69203
69204 /* Clean up and exit. */
69205 smp_mb(); /* ensure expedited GP seen before counter increment. */
69206 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69207 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69208 unlock_mb_ret:
69209 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69210 mb_ret:
69211 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69212 index d4bc16d..c234a5c 100644
69213 --- a/kernel/rcutree_trace.c
69214 +++ b/kernel/rcutree_trace.c
69215 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69216 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69217 rdp->qs_pending);
69218 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69219 - atomic_read(&rdp->dynticks->dynticks),
69220 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69221 rdp->dynticks->dynticks_nesting,
69222 rdp->dynticks->dynticks_nmi_nesting,
69223 rdp->dynticks_fqs);
69224 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69225 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69226 rdp->qs_pending);
69227 seq_printf(m, ",%d,%llx,%d,%lu",
69228 - atomic_read(&rdp->dynticks->dynticks),
69229 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69230 rdp->dynticks->dynticks_nesting,
69231 rdp->dynticks->dynticks_nmi_nesting,
69232 rdp->dynticks_fqs);
69233 diff --git a/kernel/resource.c b/kernel/resource.c
69234 index e1d2b8e..24820bb 100644
69235 --- a/kernel/resource.c
69236 +++ b/kernel/resource.c
69237 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69238
69239 static int __init ioresources_init(void)
69240 {
69241 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69242 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69243 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69244 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69245 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69246 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69247 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69248 +#endif
69249 +#else
69250 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69251 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69252 +#endif
69253 return 0;
69254 }
69255 __initcall(ioresources_init);
69256 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69257 index 98ec494..4241d6d 100644
69258 --- a/kernel/rtmutex-tester.c
69259 +++ b/kernel/rtmutex-tester.c
69260 @@ -20,7 +20,7 @@
69261 #define MAX_RT_TEST_MUTEXES 8
69262
69263 static spinlock_t rttest_lock;
69264 -static atomic_t rttest_event;
69265 +static atomic_unchecked_t rttest_event;
69266
69267 struct test_thread_data {
69268 int opcode;
69269 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69270
69271 case RTTEST_LOCKCONT:
69272 td->mutexes[td->opdata] = 1;
69273 - td->event = atomic_add_return(1, &rttest_event);
69274 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69275 return 0;
69276
69277 case RTTEST_RESET:
69278 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69279 return 0;
69280
69281 case RTTEST_RESETEVENT:
69282 - atomic_set(&rttest_event, 0);
69283 + atomic_set_unchecked(&rttest_event, 0);
69284 return 0;
69285
69286 default:
69287 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69288 return ret;
69289
69290 td->mutexes[id] = 1;
69291 - td->event = atomic_add_return(1, &rttest_event);
69292 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69293 rt_mutex_lock(&mutexes[id]);
69294 - td->event = atomic_add_return(1, &rttest_event);
69295 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69296 td->mutexes[id] = 4;
69297 return 0;
69298
69299 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69300 return ret;
69301
69302 td->mutexes[id] = 1;
69303 - td->event = atomic_add_return(1, &rttest_event);
69304 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69305 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69306 - td->event = atomic_add_return(1, &rttest_event);
69307 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69308 td->mutexes[id] = ret ? 0 : 4;
69309 return ret ? -EINTR : 0;
69310
69311 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69312 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69313 return ret;
69314
69315 - td->event = atomic_add_return(1, &rttest_event);
69316 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69317 rt_mutex_unlock(&mutexes[id]);
69318 - td->event = atomic_add_return(1, &rttest_event);
69319 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69320 td->mutexes[id] = 0;
69321 return 0;
69322
69323 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69324 break;
69325
69326 td->mutexes[dat] = 2;
69327 - td->event = atomic_add_return(1, &rttest_event);
69328 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69329 break;
69330
69331 default:
69332 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69333 return;
69334
69335 td->mutexes[dat] = 3;
69336 - td->event = atomic_add_return(1, &rttest_event);
69337 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69338 break;
69339
69340 case RTTEST_LOCKNOWAIT:
69341 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69342 return;
69343
69344 td->mutexes[dat] = 1;
69345 - td->event = atomic_add_return(1, &rttest_event);
69346 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69347 return;
69348
69349 default:
69350 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69351 index 0984a21..939f183 100644
69352 --- a/kernel/sched/auto_group.c
69353 +++ b/kernel/sched/auto_group.c
69354 @@ -11,7 +11,7 @@
69355
69356 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69357 static struct autogroup autogroup_default;
69358 -static atomic_t autogroup_seq_nr;
69359 +static atomic_unchecked_t autogroup_seq_nr;
69360
69361 void __init autogroup_init(struct task_struct *init_task)
69362 {
69363 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69364
69365 kref_init(&ag->kref);
69366 init_rwsem(&ag->lock);
69367 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69368 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69369 ag->tg = tg;
69370 #ifdef CONFIG_RT_GROUP_SCHED
69371 /*
69372 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69373 index 468bdd4..b941572 100644
69374 --- a/kernel/sched/core.c
69375 +++ b/kernel/sched/core.c
69376 @@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69377 /* convert nice value [19,-20] to rlimit style value [1,40] */
69378 int nice_rlim = 20 - nice;
69379
69380 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69381 +
69382 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69383 capable(CAP_SYS_NICE));
69384 }
69385 @@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69386 if (nice > 19)
69387 nice = 19;
69388
69389 - if (increment < 0 && !can_nice(current, nice))
69390 + if (increment < 0 && (!can_nice(current, nice) ||
69391 + gr_handle_chroot_nice()))
69392 return -EPERM;
69393
69394 retval = security_task_setnice(current, nice);
69395 @@ -4284,6 +4287,7 @@ recheck:
69396 unsigned long rlim_rtprio =
69397 task_rlimit(p, RLIMIT_RTPRIO);
69398
69399 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69400 /* can't set/change the rt policy */
69401 if (policy != p->policy && !rlim_rtprio)
69402 return -EPERM;
69403 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69404 index c099cc6..06aec4f 100644
69405 --- a/kernel/sched/fair.c
69406 +++ b/kernel/sched/fair.c
69407 @@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69408 * run_rebalance_domains is triggered when needed from the scheduler tick.
69409 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69410 */
69411 -static void run_rebalance_domains(struct softirq_action *h)
69412 +static void run_rebalance_domains(void)
69413 {
69414 int this_cpu = smp_processor_id();
69415 struct rq *this_rq = cpu_rq(this_cpu);
69416 diff --git a/kernel/signal.c b/kernel/signal.c
69417 index 6771027..763e51e 100644
69418 --- a/kernel/signal.c
69419 +++ b/kernel/signal.c
69420 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69421
69422 int print_fatal_signals __read_mostly;
69423
69424 -static void __user *sig_handler(struct task_struct *t, int sig)
69425 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69426 {
69427 return t->sighand->action[sig - 1].sa.sa_handler;
69428 }
69429
69430 -static int sig_handler_ignored(void __user *handler, int sig)
69431 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69432 {
69433 /* Is it explicitly or implicitly ignored? */
69434 return handler == SIG_IGN ||
69435 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69436
69437 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69438 {
69439 - void __user *handler;
69440 + __sighandler_t handler;
69441
69442 handler = sig_handler(t, sig);
69443
69444 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69445 atomic_inc(&user->sigpending);
69446 rcu_read_unlock();
69447
69448 + if (!override_rlimit)
69449 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69450 +
69451 if (override_rlimit ||
69452 atomic_read(&user->sigpending) <=
69453 task_rlimit(t, RLIMIT_SIGPENDING)) {
69454 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69455
69456 int unhandled_signal(struct task_struct *tsk, int sig)
69457 {
69458 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69459 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69460 if (is_global_init(tsk))
69461 return 1;
69462 if (handler != SIG_IGN && handler != SIG_DFL)
69463 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69464 }
69465 }
69466
69467 + /* allow glibc communication via tgkill to other threads in our
69468 + thread group */
69469 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69470 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69471 + && gr_handle_signal(t, sig))
69472 + return -EPERM;
69473 +
69474 return security_task_kill(t, info, sig, 0);
69475 }
69476
69477 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69478 return send_signal(sig, info, p, 1);
69479 }
69480
69481 -static int
69482 +int
69483 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69484 {
69485 return send_signal(sig, info, t, 0);
69486 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69487 unsigned long int flags;
69488 int ret, blocked, ignored;
69489 struct k_sigaction *action;
69490 + int is_unhandled = 0;
69491
69492 spin_lock_irqsave(&t->sighand->siglock, flags);
69493 action = &t->sighand->action[sig-1];
69494 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69495 }
69496 if (action->sa.sa_handler == SIG_DFL)
69497 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69498 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69499 + is_unhandled = 1;
69500 ret = specific_send_sig_info(sig, info, t);
69501 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69502
69503 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69504 + normal operation */
69505 + if (is_unhandled) {
69506 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69507 + gr_handle_crash(t, sig);
69508 + }
69509 +
69510 return ret;
69511 }
69512
69513 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69514 ret = check_kill_permission(sig, info, p);
69515 rcu_read_unlock();
69516
69517 - if (!ret && sig)
69518 + if (!ret && sig) {
69519 ret = do_send_sig_info(sig, info, p, true);
69520 + if (!ret)
69521 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69522 + }
69523
69524 return ret;
69525 }
69526 @@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69527 int error = -ESRCH;
69528
69529 rcu_read_lock();
69530 - p = find_task_by_vpid(pid);
69531 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69532 + /* allow glibc communication via tgkill to other threads in our
69533 + thread group */
69534 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69535 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69536 + p = find_task_by_vpid_unrestricted(pid);
69537 + else
69538 +#endif
69539 + p = find_task_by_vpid(pid);
69540 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69541 error = check_kill_permission(sig, info, p);
69542 /*
69543 diff --git a/kernel/smp.c b/kernel/smp.c
69544 index d0ae5b2..b87c5a8 100644
69545 --- a/kernel/smp.c
69546 +++ b/kernel/smp.c
69547 @@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69548 }
69549 EXPORT_SYMBOL(smp_call_function);
69550
69551 -void ipi_call_lock(void)
69552 +void ipi_call_lock(void) __acquires(call_function.lock)
69553 {
69554 raw_spin_lock(&call_function.lock);
69555 }
69556
69557 -void ipi_call_unlock(void)
69558 +void ipi_call_unlock(void) __releases(call_function.lock)
69559 {
69560 raw_spin_unlock(&call_function.lock);
69561 }
69562
69563 -void ipi_call_lock_irq(void)
69564 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69565 {
69566 raw_spin_lock_irq(&call_function.lock);
69567 }
69568
69569 -void ipi_call_unlock_irq(void)
69570 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69571 {
69572 raw_spin_unlock_irq(&call_function.lock);
69573 }
69574 diff --git a/kernel/softirq.c b/kernel/softirq.c
69575 index 671f959..91c51cb 100644
69576 --- a/kernel/softirq.c
69577 +++ b/kernel/softirq.c
69578 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69579
69580 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69581
69582 -char *softirq_to_name[NR_SOFTIRQS] = {
69583 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69584 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69585 "TASKLET", "SCHED", "HRTIMER", "RCU"
69586 };
69587 @@ -235,7 +235,7 @@ restart:
69588 kstat_incr_softirqs_this_cpu(vec_nr);
69589
69590 trace_softirq_entry(vec_nr);
69591 - h->action(h);
69592 + h->action();
69593 trace_softirq_exit(vec_nr);
69594 if (unlikely(prev_count != preempt_count())) {
69595 printk(KERN_ERR "huh, entered softirq %u %s %p"
69596 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69597 or_softirq_pending(1UL << nr);
69598 }
69599
69600 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69601 +void open_softirq(int nr, void (*action)(void))
69602 {
69603 - softirq_vec[nr].action = action;
69604 + pax_open_kernel();
69605 + *(void **)&softirq_vec[nr].action = action;
69606 + pax_close_kernel();
69607 }
69608
69609 /*
69610 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69611
69612 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69613
69614 -static void tasklet_action(struct softirq_action *a)
69615 +static void tasklet_action(void)
69616 {
69617 struct tasklet_struct *list;
69618
69619 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69620 }
69621 }
69622
69623 -static void tasklet_hi_action(struct softirq_action *a)
69624 +static void tasklet_hi_action(void)
69625 {
69626 struct tasklet_struct *list;
69627
69628 diff --git a/kernel/srcu.c b/kernel/srcu.c
69629 index 2095be3..9a5b89d 100644
69630 --- a/kernel/srcu.c
69631 +++ b/kernel/srcu.c
69632 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69633 preempt_disable();
69634 idx = rcu_dereference_index_check(sp->completed,
69635 rcu_read_lock_sched_held()) & 0x1;
69636 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69637 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69638 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69639 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69640 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69641 preempt_enable();
69642 return idx;
69643 }
69644 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69645 {
69646 preempt_disable();
69647 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69648 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69649 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69650 preempt_enable();
69651 }
69652 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69653 diff --git a/kernel/sys.c b/kernel/sys.c
69654 index 2d39a84..f778b49 100644
69655 --- a/kernel/sys.c
69656 +++ b/kernel/sys.c
69657 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69658 error = -EACCES;
69659 goto out;
69660 }
69661 +
69662 + if (gr_handle_chroot_setpriority(p, niceval)) {
69663 + error = -EACCES;
69664 + goto out;
69665 + }
69666 +
69667 no_nice = security_task_setnice(p, niceval);
69668 if (no_nice) {
69669 error = no_nice;
69670 @@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69671 goto error;
69672 }
69673
69674 + if (gr_check_group_change(new->gid, new->egid, -1))
69675 + goto error;
69676 +
69677 if (rgid != (gid_t) -1 ||
69678 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69679 new->sgid = new->egid;
69680 @@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69681 old = current_cred();
69682
69683 retval = -EPERM;
69684 +
69685 + if (gr_check_group_change(kgid, kgid, kgid))
69686 + goto error;
69687 +
69688 if (nsown_capable(CAP_SETGID))
69689 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69690 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69691 @@ -646,7 +659,7 @@ error:
69692 /*
69693 * change the user struct in a credentials set to match the new UID
69694 */
69695 -static int set_user(struct cred *new)
69696 +int set_user(struct cred *new)
69697 {
69698 struct user_struct *new_user;
69699
69700 @@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69701 goto error;
69702 }
69703
69704 + if (gr_check_user_change(new->uid, new->euid, -1))
69705 + goto error;
69706 +
69707 if (!uid_eq(new->uid, old->uid)) {
69708 retval = set_user(new);
69709 if (retval < 0)
69710 @@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69711 old = current_cred();
69712
69713 retval = -EPERM;
69714 +
69715 + if (gr_check_crash_uid(kuid))
69716 + goto error;
69717 + if (gr_check_user_change(kuid, kuid, kuid))
69718 + goto error;
69719 +
69720 if (nsown_capable(CAP_SETUID)) {
69721 new->suid = new->uid = kuid;
69722 if (!uid_eq(kuid, old->uid)) {
69723 @@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69724 goto error;
69725 }
69726
69727 + if (gr_check_user_change(kruid, keuid, -1))
69728 + goto error;
69729 +
69730 if (ruid != (uid_t) -1) {
69731 new->uid = kruid;
69732 if (!uid_eq(kruid, old->uid)) {
69733 @@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69734 goto error;
69735 }
69736
69737 + if (gr_check_group_change(krgid, kegid, -1))
69738 + goto error;
69739 +
69740 if (rgid != (gid_t) -1)
69741 new->gid = krgid;
69742 if (egid != (gid_t) -1)
69743 @@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69744 if (!uid_valid(kuid))
69745 return old_fsuid;
69746
69747 + if (gr_check_user_change(-1, -1, kuid))
69748 + goto error;
69749 +
69750 new = prepare_creds();
69751 if (!new)
69752 return old_fsuid;
69753 @@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69754 }
69755 }
69756
69757 +error:
69758 abort_creds(new);
69759 return old_fsuid;
69760
69761 @@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69762 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69763 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69764 nsown_capable(CAP_SETGID)) {
69765 + if (gr_check_group_change(-1, -1, kgid))
69766 + goto error;
69767 +
69768 if (!gid_eq(kgid, old->fsgid)) {
69769 new->fsgid = kgid;
69770 goto change_okay;
69771 }
69772 }
69773
69774 +error:
69775 abort_creds(new);
69776 return old_fsgid;
69777
69778 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69779 }
69780 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69781 snprintf(buf, len, "2.6.%u%s", v, rest);
69782 - ret = copy_to_user(release, buf, len);
69783 + if (len > sizeof(buf))
69784 + ret = -EFAULT;
69785 + else
69786 + ret = copy_to_user(release, buf, len);
69787 }
69788 return ret;
69789 }
69790 @@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69791 return -EFAULT;
69792
69793 down_read(&uts_sem);
69794 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69795 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69796 __OLD_UTS_LEN);
69797 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69798 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69799 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69800 __OLD_UTS_LEN);
69801 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69802 - error |= __copy_to_user(&name->release, &utsname()->release,
69803 + error |= __copy_to_user(name->release, &utsname()->release,
69804 __OLD_UTS_LEN);
69805 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69806 - error |= __copy_to_user(&name->version, &utsname()->version,
69807 + error |= __copy_to_user(name->version, &utsname()->version,
69808 __OLD_UTS_LEN);
69809 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69810 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69811 + error |= __copy_to_user(name->machine, &utsname()->machine,
69812 __OLD_UTS_LEN);
69813 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69814 up_read(&uts_sem);
69815 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69816 error = get_dumpable(me->mm);
69817 break;
69818 case PR_SET_DUMPABLE:
69819 - if (arg2 < 0 || arg2 > 1) {
69820 + if (arg2 > 1) {
69821 error = -EINVAL;
69822 break;
69823 }
69824 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69825 index 4ab1187..33f4f2b 100644
69826 --- a/kernel/sysctl.c
69827 +++ b/kernel/sysctl.c
69828 @@ -91,7 +91,6 @@
69829
69830
69831 #if defined(CONFIG_SYSCTL)
69832 -
69833 /* External variables not in a header file. */
69834 extern int sysctl_overcommit_memory;
69835 extern int sysctl_overcommit_ratio;
69836 @@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69837 void __user *buffer, size_t *lenp, loff_t *ppos);
69838 #endif
69839
69840 -#ifdef CONFIG_PRINTK
69841 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69842 void __user *buffer, size_t *lenp, loff_t *ppos);
69843 -#endif
69844 +
69845 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69846 + void __user *buffer, size_t *lenp, loff_t *ppos);
69847 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69848 + void __user *buffer, size_t *lenp, loff_t *ppos);
69849
69850 #ifdef CONFIG_MAGIC_SYSRQ
69851 /* Note: sysrq code uses it's own private copy */
69852 @@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69853
69854 #endif
69855
69856 +extern struct ctl_table grsecurity_table[];
69857 +
69858 static struct ctl_table kern_table[];
69859 static struct ctl_table vm_table[];
69860 static struct ctl_table fs_table[];
69861 @@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69862 int sysctl_legacy_va_layout;
69863 #endif
69864
69865 +#ifdef CONFIG_PAX_SOFTMODE
69866 +static ctl_table pax_table[] = {
69867 + {
69868 + .procname = "softmode",
69869 + .data = &pax_softmode,
69870 + .maxlen = sizeof(unsigned int),
69871 + .mode = 0600,
69872 + .proc_handler = &proc_dointvec,
69873 + },
69874 +
69875 + { }
69876 +};
69877 +#endif
69878 +
69879 /* The default sysctl tables: */
69880
69881 static struct ctl_table sysctl_base_table[] = {
69882 @@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69883 #endif
69884
69885 static struct ctl_table kern_table[] = {
69886 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69887 + {
69888 + .procname = "grsecurity",
69889 + .mode = 0500,
69890 + .child = grsecurity_table,
69891 + },
69892 +#endif
69893 +
69894 +#ifdef CONFIG_PAX_SOFTMODE
69895 + {
69896 + .procname = "pax",
69897 + .mode = 0500,
69898 + .child = pax_table,
69899 + },
69900 +#endif
69901 +
69902 {
69903 .procname = "sched_child_runs_first",
69904 .data = &sysctl_sched_child_runs_first,
69905 @@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69906 .data = core_pattern,
69907 .maxlen = CORENAME_MAX_SIZE,
69908 .mode = 0644,
69909 - .proc_handler = proc_dostring,
69910 + .proc_handler = proc_dostring_coredump,
69911 },
69912 {
69913 .procname = "core_pipe_limit",
69914 @@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69915 .data = &modprobe_path,
69916 .maxlen = KMOD_PATH_LEN,
69917 .mode = 0644,
69918 - .proc_handler = proc_dostring,
69919 + .proc_handler = proc_dostring_modpriv,
69920 },
69921 {
69922 .procname = "modules_disabled",
69923 @@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69924 .extra1 = &zero,
69925 .extra2 = &one,
69926 },
69927 +#endif
69928 {
69929 .procname = "kptr_restrict",
69930 .data = &kptr_restrict,
69931 .maxlen = sizeof(int),
69932 .mode = 0644,
69933 .proc_handler = proc_dointvec_minmax_sysadmin,
69934 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69935 + .extra1 = &two,
69936 +#else
69937 .extra1 = &zero,
69938 +#endif
69939 .extra2 = &two,
69940 },
69941 -#endif
69942 {
69943 .procname = "ngroups_max",
69944 .data = &ngroups_max,
69945 @@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69946 .proc_handler = proc_dointvec_minmax,
69947 .extra1 = &zero,
69948 },
69949 + {
69950 + .procname = "heap_stack_gap",
69951 + .data = &sysctl_heap_stack_gap,
69952 + .maxlen = sizeof(sysctl_heap_stack_gap),
69953 + .mode = 0644,
69954 + .proc_handler = proc_doulongvec_minmax,
69955 + },
69956 #else
69957 {
69958 .procname = "nr_trim_pages",
69959 @@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69960 .data = &suid_dumpable,
69961 .maxlen = sizeof(int),
69962 .mode = 0644,
69963 - .proc_handler = proc_dointvec_minmax,
69964 + .proc_handler = proc_dointvec_minmax_coredump,
69965 .extra1 = &zero,
69966 .extra2 = &two,
69967 },
69968 @@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69969 buffer, lenp, ppos);
69970 }
69971
69972 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69973 + void __user *buffer, size_t *lenp, loff_t *ppos)
69974 +{
69975 + if (write && !capable(CAP_SYS_MODULE))
69976 + return -EPERM;
69977 +
69978 + return _proc_do_string(table->data, table->maxlen, write,
69979 + buffer, lenp, ppos);
69980 +}
69981 +
69982 static size_t proc_skip_spaces(char **buf)
69983 {
69984 size_t ret;
69985 @@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69986 len = strlen(tmp);
69987 if (len > *size)
69988 len = *size;
69989 + if (len > sizeof(tmp))
69990 + len = sizeof(tmp);
69991 if (copy_to_user(*buf, tmp, len))
69992 return -EFAULT;
69993 *size -= len;
69994 @@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69995 return err;
69996 }
69997
69998 -#ifdef CONFIG_PRINTK
69999 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70000 void __user *buffer, size_t *lenp, loff_t *ppos)
70001 {
70002 @@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70003
70004 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70005 }
70006 -#endif
70007
70008 struct do_proc_dointvec_minmax_conv_param {
70009 int *min;
70010 @@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
70011 do_proc_dointvec_minmax_conv, &param);
70012 }
70013
70014 +static void validate_coredump_safety(void)
70015 +{
70016 + if (suid_dumpable == SUID_DUMPABLE_SAFE &&
70017 + core_pattern[0] != '/' && core_pattern[0] != '|') {
70018 + printk(KERN_WARNING "Unsafe core_pattern used with "\
70019 + "suid_dumpable=2. Pipe handler or fully qualified "\
70020 + "core dump path required.\n");
70021 + }
70022 +}
70023 +
70024 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70025 + void __user *buffer, size_t *lenp, loff_t *ppos)
70026 +{
70027 + int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70028 + if (!error)
70029 + validate_coredump_safety();
70030 + return error;
70031 +}
70032 +
70033 +static int proc_dostring_coredump(struct ctl_table *table, int write,
70034 + void __user *buffer, size_t *lenp, loff_t *ppos)
70035 +{
70036 + int error = proc_dostring(table, write, buffer, lenp, ppos);
70037 + if (!error)
70038 + validate_coredump_safety();
70039 + return error;
70040 +}
70041 +
70042 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
70043 void __user *buffer,
70044 size_t *lenp, loff_t *ppos,
70045 @@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70046 *i = val;
70047 } else {
70048 val = convdiv * (*i) / convmul;
70049 - if (!first)
70050 + if (!first) {
70051 err = proc_put_char(&buffer, &left, '\t');
70052 + if (err)
70053 + break;
70054 + }
70055 err = proc_put_long(&buffer, &left, val, false);
70056 if (err)
70057 break;
70058 @@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
70059 return -ENOSYS;
70060 }
70061
70062 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70063 + void __user *buffer, size_t *lenp, loff_t *ppos)
70064 +{
70065 + return -ENOSYS;
70066 +}
70067 +
70068 int proc_dointvec(struct ctl_table *table, int write,
70069 void __user *buffer, size_t *lenp, loff_t *ppos)
70070 {
70071 @@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70072 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70073 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70074 EXPORT_SYMBOL(proc_dostring);
70075 +EXPORT_SYMBOL(proc_dostring_modpriv);
70076 EXPORT_SYMBOL(proc_doulongvec_minmax);
70077 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70078 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70079 index a650694..aaeeb20 100644
70080 --- a/kernel/sysctl_binary.c
70081 +++ b/kernel/sysctl_binary.c
70082 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70083 int i;
70084
70085 set_fs(KERNEL_DS);
70086 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70087 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70088 set_fs(old_fs);
70089 if (result < 0)
70090 goto out_kfree;
70091 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70092 }
70093
70094 set_fs(KERNEL_DS);
70095 - result = vfs_write(file, buffer, str - buffer, &pos);
70096 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70097 set_fs(old_fs);
70098 if (result < 0)
70099 goto out_kfree;
70100 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70101 int i;
70102
70103 set_fs(KERNEL_DS);
70104 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70105 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70106 set_fs(old_fs);
70107 if (result < 0)
70108 goto out_kfree;
70109 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70110 }
70111
70112 set_fs(KERNEL_DS);
70113 - result = vfs_write(file, buffer, str - buffer, &pos);
70114 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70115 set_fs(old_fs);
70116 if (result < 0)
70117 goto out_kfree;
70118 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70119 int i;
70120
70121 set_fs(KERNEL_DS);
70122 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70123 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70124 set_fs(old_fs);
70125 if (result < 0)
70126 goto out;
70127 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70128 __le16 dnaddr;
70129
70130 set_fs(KERNEL_DS);
70131 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70132 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70133 set_fs(old_fs);
70134 if (result < 0)
70135 goto out;
70136 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70137 le16_to_cpu(dnaddr) & 0x3ff);
70138
70139 set_fs(KERNEL_DS);
70140 - result = vfs_write(file, buf, len, &pos);
70141 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70142 set_fs(old_fs);
70143 if (result < 0)
70144 goto out;
70145 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70146 index e660464..c8b9e67 100644
70147 --- a/kernel/taskstats.c
70148 +++ b/kernel/taskstats.c
70149 @@ -27,9 +27,12 @@
70150 #include <linux/cgroup.h>
70151 #include <linux/fs.h>
70152 #include <linux/file.h>
70153 +#include <linux/grsecurity.h>
70154 #include <net/genetlink.h>
70155 #include <linux/atomic.h>
70156
70157 +extern int gr_is_taskstats_denied(int pid);
70158 +
70159 /*
70160 * Maximum length of a cpumask that can be specified in
70161 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70162 @@ -556,6 +559,9 @@ err:
70163
70164 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70165 {
70166 + if (gr_is_taskstats_denied(current->pid))
70167 + return -EACCES;
70168 +
70169 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70170 return cmd_attr_register_cpumask(info);
70171 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70172 diff --git a/kernel/time.c b/kernel/time.c
70173 index ba744cf..267b7c5 100644
70174 --- a/kernel/time.c
70175 +++ b/kernel/time.c
70176 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70177 return error;
70178
70179 if (tz) {
70180 + /* we log in do_settimeofday called below, so don't log twice
70181 + */
70182 + if (!tv)
70183 + gr_log_timechange();
70184 +
70185 sys_tz = *tz;
70186 update_vsyscall_tz();
70187 if (firsttime) {
70188 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70189 index aa27d39..34d221c 100644
70190 --- a/kernel/time/alarmtimer.c
70191 +++ b/kernel/time/alarmtimer.c
70192 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70193 struct platform_device *pdev;
70194 int error = 0;
70195 int i;
70196 - struct k_clock alarm_clock = {
70197 + static struct k_clock alarm_clock = {
70198 .clock_getres = alarm_clock_getres,
70199 .clock_get = alarm_clock_get,
70200 .timer_create = alarm_timer_create,
70201 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70202 index f113755..ec24223 100644
70203 --- a/kernel/time/tick-broadcast.c
70204 +++ b/kernel/time/tick-broadcast.c
70205 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70206 * then clear the broadcast bit.
70207 */
70208 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70209 - int cpu = smp_processor_id();
70210 + cpu = smp_processor_id();
70211
70212 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70213 tick_broadcast_clear_oneshot(cpu);
70214 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70215 index 3447cfa..291806b 100644
70216 --- a/kernel/time/timekeeping.c
70217 +++ b/kernel/time/timekeeping.c
70218 @@ -14,6 +14,7 @@
70219 #include <linux/init.h>
70220 #include <linux/mm.h>
70221 #include <linux/sched.h>
70222 +#include <linux/grsecurity.h>
70223 #include <linux/syscore_ops.h>
70224 #include <linux/clocksource.h>
70225 #include <linux/jiffies.h>
70226 @@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
70227 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70228 return -EINVAL;
70229
70230 + gr_log_timechange();
70231 +
70232 write_seqlock_irqsave(&timekeeper.lock, flags);
70233
70234 timekeeping_forward_now();
70235 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70236 index 3258455..f35227d 100644
70237 --- a/kernel/time/timer_list.c
70238 +++ b/kernel/time/timer_list.c
70239 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70240
70241 static void print_name_offset(struct seq_file *m, void *sym)
70242 {
70243 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70244 + SEQ_printf(m, "<%p>", NULL);
70245 +#else
70246 char symname[KSYM_NAME_LEN];
70247
70248 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70249 SEQ_printf(m, "<%pK>", sym);
70250 else
70251 SEQ_printf(m, "%s", symname);
70252 +#endif
70253 }
70254
70255 static void
70256 @@ -112,7 +116,11 @@ next_one:
70257 static void
70258 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70259 {
70260 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70261 + SEQ_printf(m, " .base: %p\n", NULL);
70262 +#else
70263 SEQ_printf(m, " .base: %pK\n", base);
70264 +#endif
70265 SEQ_printf(m, " .index: %d\n",
70266 base->index);
70267 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70268 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70269 {
70270 struct proc_dir_entry *pe;
70271
70272 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70273 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70274 +#else
70275 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70276 +#endif
70277 if (!pe)
70278 return -ENOMEM;
70279 return 0;
70280 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70281 index 0b537f2..9e71eca 100644
70282 --- a/kernel/time/timer_stats.c
70283 +++ b/kernel/time/timer_stats.c
70284 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70285 static unsigned long nr_entries;
70286 static struct entry entries[MAX_ENTRIES];
70287
70288 -static atomic_t overflow_count;
70289 +static atomic_unchecked_t overflow_count;
70290
70291 /*
70292 * The entries are in a hash-table, for fast lookup:
70293 @@ -140,7 +140,7 @@ static void reset_entries(void)
70294 nr_entries = 0;
70295 memset(entries, 0, sizeof(entries));
70296 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70297 - atomic_set(&overflow_count, 0);
70298 + atomic_set_unchecked(&overflow_count, 0);
70299 }
70300
70301 static struct entry *alloc_entry(void)
70302 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70303 if (likely(entry))
70304 entry->count++;
70305 else
70306 - atomic_inc(&overflow_count);
70307 + atomic_inc_unchecked(&overflow_count);
70308
70309 out_unlock:
70310 raw_spin_unlock_irqrestore(lock, flags);
70311 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70312
70313 static void print_name_offset(struct seq_file *m, unsigned long addr)
70314 {
70315 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70316 + seq_printf(m, "<%p>", NULL);
70317 +#else
70318 char symname[KSYM_NAME_LEN];
70319
70320 if (lookup_symbol_name(addr, symname) < 0)
70321 seq_printf(m, "<%p>", (void *)addr);
70322 else
70323 seq_printf(m, "%s", symname);
70324 +#endif
70325 }
70326
70327 static int tstats_show(struct seq_file *m, void *v)
70328 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70329
70330 seq_puts(m, "Timer Stats Version: v0.2\n");
70331 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70332 - if (atomic_read(&overflow_count))
70333 + if (atomic_read_unchecked(&overflow_count))
70334 seq_printf(m, "Overflow: %d entries\n",
70335 - atomic_read(&overflow_count));
70336 + atomic_read_unchecked(&overflow_count));
70337
70338 for (i = 0; i < nr_entries; i++) {
70339 entry = entries + i;
70340 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70341 {
70342 struct proc_dir_entry *pe;
70343
70344 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70345 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70346 +#else
70347 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70348 +#endif
70349 if (!pe)
70350 return -ENOMEM;
70351 return 0;
70352 diff --git a/kernel/timer.c b/kernel/timer.c
70353 index 6ec7e7e..cbc448b 100644
70354 --- a/kernel/timer.c
70355 +++ b/kernel/timer.c
70356 @@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70357 /*
70358 * This function runs timers and the timer-tq in bottom half context.
70359 */
70360 -static void run_timer_softirq(struct softirq_action *h)
70361 +static void run_timer_softirq(void)
70362 {
70363 struct tvec_base *base = __this_cpu_read(tvec_bases);
70364
70365 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70366 index c0bd030..62a1927 100644
70367 --- a/kernel/trace/blktrace.c
70368 +++ b/kernel/trace/blktrace.c
70369 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70370 struct blk_trace *bt = filp->private_data;
70371 char buf[16];
70372
70373 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70374 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70375
70376 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70377 }
70378 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70379 return 1;
70380
70381 bt = buf->chan->private_data;
70382 - atomic_inc(&bt->dropped);
70383 + atomic_inc_unchecked(&bt->dropped);
70384 return 0;
70385 }
70386
70387 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70388
70389 bt->dir = dir;
70390 bt->dev = dev;
70391 - atomic_set(&bt->dropped, 0);
70392 + atomic_set_unchecked(&bt->dropped, 0);
70393
70394 ret = -EIO;
70395 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70396 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70397 index a008663..30d7429 100644
70398 --- a/kernel/trace/ftrace.c
70399 +++ b/kernel/trace/ftrace.c
70400 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70401 if (unlikely(ftrace_disabled))
70402 return 0;
70403
70404 + ret = ftrace_arch_code_modify_prepare();
70405 + FTRACE_WARN_ON(ret);
70406 + if (ret)
70407 + return 0;
70408 +
70409 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70410 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70411 if (ret) {
70412 ftrace_bug(ret, ip);
70413 - return 0;
70414 }
70415 - return 1;
70416 + return ret ? 0 : 1;
70417 }
70418
70419 /*
70420 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70421
70422 int
70423 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70424 - void *data)
70425 + void *data)
70426 {
70427 struct ftrace_func_probe *entry;
70428 struct ftrace_page *pg;
70429 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70430 if (!count)
70431 return 0;
70432
70433 + pax_open_kernel();
70434 sort(start, count, sizeof(*start),
70435 ftrace_cmp_ips, ftrace_swap_ips);
70436 + pax_close_kernel();
70437
70438 start_pg = ftrace_allocate_pages(count);
70439 if (!start_pg)
70440 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70441 index a7fa070..403bc8d 100644
70442 --- a/kernel/trace/trace.c
70443 +++ b/kernel/trace/trace.c
70444 @@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70445 };
70446 #endif
70447
70448 -static struct dentry *d_tracer;
70449 -
70450 struct dentry *tracing_init_dentry(void)
70451 {
70452 + static struct dentry *d_tracer;
70453 static int once;
70454
70455 if (d_tracer)
70456 @@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70457 return d_tracer;
70458 }
70459
70460 -static struct dentry *d_percpu;
70461 -
70462 struct dentry *tracing_dentry_percpu(void)
70463 {
70464 + static struct dentry *d_percpu;
70465 static int once;
70466 struct dentry *d_tracer;
70467
70468 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70469 index 29111da..d190fe2 100644
70470 --- a/kernel/trace/trace_events.c
70471 +++ b/kernel/trace/trace_events.c
70472 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70473 struct ftrace_module_file_ops {
70474 struct list_head list;
70475 struct module *mod;
70476 - struct file_operations id;
70477 - struct file_operations enable;
70478 - struct file_operations format;
70479 - struct file_operations filter;
70480 };
70481
70482 static struct ftrace_module_file_ops *
70483 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70484
70485 file_ops->mod = mod;
70486
70487 - file_ops->id = ftrace_event_id_fops;
70488 - file_ops->id.owner = mod;
70489 -
70490 - file_ops->enable = ftrace_enable_fops;
70491 - file_ops->enable.owner = mod;
70492 -
70493 - file_ops->filter = ftrace_event_filter_fops;
70494 - file_ops->filter.owner = mod;
70495 -
70496 - file_ops->format = ftrace_event_format_fops;
70497 - file_ops->format.owner = mod;
70498 + pax_open_kernel();
70499 + *(void **)&mod->trace_id.owner = mod;
70500 + *(void **)&mod->trace_enable.owner = mod;
70501 + *(void **)&mod->trace_filter.owner = mod;
70502 + *(void **)&mod->trace_format.owner = mod;
70503 + pax_close_kernel();
70504
70505 list_add(&file_ops->list, &ftrace_module_file_list);
70506
70507 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70508
70509 for_each_event(call, start, end) {
70510 __trace_add_event_call(*call, mod,
70511 - &file_ops->id, &file_ops->enable,
70512 - &file_ops->filter, &file_ops->format);
70513 + &mod->trace_id, &mod->trace_enable,
70514 + &mod->trace_filter, &mod->trace_format);
70515 }
70516 }
70517
70518 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70519 index fd3c8aa..5f324a6 100644
70520 --- a/kernel/trace/trace_mmiotrace.c
70521 +++ b/kernel/trace/trace_mmiotrace.c
70522 @@ -24,7 +24,7 @@ struct header_iter {
70523 static struct trace_array *mmio_trace_array;
70524 static bool overrun_detected;
70525 static unsigned long prev_overruns;
70526 -static atomic_t dropped_count;
70527 +static atomic_unchecked_t dropped_count;
70528
70529 static void mmio_reset_data(struct trace_array *tr)
70530 {
70531 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70532
70533 static unsigned long count_overruns(struct trace_iterator *iter)
70534 {
70535 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70536 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70537 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70538
70539 if (over > prev_overruns)
70540 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70541 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70542 sizeof(*entry), 0, pc);
70543 if (!event) {
70544 - atomic_inc(&dropped_count);
70545 + atomic_inc_unchecked(&dropped_count);
70546 return;
70547 }
70548 entry = ring_buffer_event_data(event);
70549 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70550 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70551 sizeof(*entry), 0, pc);
70552 if (!event) {
70553 - atomic_inc(&dropped_count);
70554 + atomic_inc_unchecked(&dropped_count);
70555 return;
70556 }
70557 entry = ring_buffer_event_data(event);
70558 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70559 index df611a0..10d8b32 100644
70560 --- a/kernel/trace/trace_output.c
70561 +++ b/kernel/trace/trace_output.c
70562 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70563
70564 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70565 if (!IS_ERR(p)) {
70566 - p = mangle_path(s->buffer + s->len, p, "\n");
70567 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70568 if (p) {
70569 s->len = p - s->buffer;
70570 return 1;
70571 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70572 index d4545f4..a9010a1 100644
70573 --- a/kernel/trace/trace_stack.c
70574 +++ b/kernel/trace/trace_stack.c
70575 @@ -53,7 +53,7 @@ static inline void check_stack(void)
70576 return;
70577
70578 /* we do not handle interrupt stacks yet */
70579 - if (!object_is_on_stack(&this_size))
70580 + if (!object_starts_on_stack(&this_size))
70581 return;
70582
70583 local_irq_save(flags);
70584 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70585 index ff5bdee..3eaeba6 100644
70586 --- a/lib/Kconfig.debug
70587 +++ b/lib/Kconfig.debug
70588 @@ -1165,6 +1165,7 @@ config LATENCYTOP
70589 depends on DEBUG_KERNEL
70590 depends on STACKTRACE_SUPPORT
70591 depends on PROC_FS
70592 + depends on !GRKERNSEC_HIDESYM
70593 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70594 select KALLSYMS
70595 select KALLSYMS_ALL
70596 diff --git a/lib/bitmap.c b/lib/bitmap.c
70597 index 06fdfa1..97c5c7d 100644
70598 --- a/lib/bitmap.c
70599 +++ b/lib/bitmap.c
70600 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70601 {
70602 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70603 u32 chunk;
70604 - const char __user __force *ubuf = (const char __user __force *)buf;
70605 + const char __user *ubuf = (const char __force_user *)buf;
70606
70607 bitmap_zero(maskp, nmaskbits);
70608
70609 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70610 {
70611 if (!access_ok(VERIFY_READ, ubuf, ulen))
70612 return -EFAULT;
70613 - return __bitmap_parse((const char __force *)ubuf,
70614 + return __bitmap_parse((const char __force_kernel *)ubuf,
70615 ulen, 1, maskp, nmaskbits);
70616
70617 }
70618 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70619 {
70620 unsigned a, b;
70621 int c, old_c, totaldigits;
70622 - const char __user __force *ubuf = (const char __user __force *)buf;
70623 + const char __user *ubuf = (const char __force_user *)buf;
70624 int exp_digit, in_range;
70625
70626 totaldigits = c = 0;
70627 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70628 {
70629 if (!access_ok(VERIFY_READ, ubuf, ulen))
70630 return -EFAULT;
70631 - return __bitmap_parselist((const char __force *)ubuf,
70632 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70633 ulen, 1, maskp, nmaskbits);
70634 }
70635 EXPORT_SYMBOL(bitmap_parselist_user);
70636 diff --git a/lib/bug.c b/lib/bug.c
70637 index a28c141..2bd3d95 100644
70638 --- a/lib/bug.c
70639 +++ b/lib/bug.c
70640 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70641 return BUG_TRAP_TYPE_NONE;
70642
70643 bug = find_bug(bugaddr);
70644 + if (!bug)
70645 + return BUG_TRAP_TYPE_NONE;
70646
70647 file = NULL;
70648 line = 0;
70649 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70650 index d11808c..dc2d6f8 100644
70651 --- a/lib/debugobjects.c
70652 +++ b/lib/debugobjects.c
70653 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70654 if (limit > 4)
70655 return;
70656
70657 - is_on_stack = object_is_on_stack(addr);
70658 + is_on_stack = object_starts_on_stack(addr);
70659 if (is_on_stack == onstack)
70660 return;
70661
70662 diff --git a/lib/devres.c b/lib/devres.c
70663 index 80b9c76..9e32279 100644
70664 --- a/lib/devres.c
70665 +++ b/lib/devres.c
70666 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70667 void devm_iounmap(struct device *dev, void __iomem *addr)
70668 {
70669 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70670 - (void *)addr));
70671 + (void __force *)addr));
70672 iounmap(addr);
70673 }
70674 EXPORT_SYMBOL(devm_iounmap);
70675 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70676 {
70677 ioport_unmap(addr);
70678 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70679 - devm_ioport_map_match, (void *)addr));
70680 + devm_ioport_map_match, (void __force *)addr));
70681 }
70682 EXPORT_SYMBOL(devm_ioport_unmap);
70683
70684 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70685 index 66ce414..6f0a0dd 100644
70686 --- a/lib/dma-debug.c
70687 +++ b/lib/dma-debug.c
70688 @@ -924,7 +924,7 @@ out:
70689
70690 static void check_for_stack(struct device *dev, void *addr)
70691 {
70692 - if (object_is_on_stack(addr))
70693 + if (object_starts_on_stack(addr))
70694 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70695 "stack [addr=%p]\n", addr);
70696 }
70697 diff --git a/lib/inflate.c b/lib/inflate.c
70698 index 013a761..c28f3fc 100644
70699 --- a/lib/inflate.c
70700 +++ b/lib/inflate.c
70701 @@ -269,7 +269,7 @@ static void free(void *where)
70702 malloc_ptr = free_mem_ptr;
70703 }
70704 #else
70705 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70706 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70707 #define free(a) kfree(a)
70708 #endif
70709
70710 diff --git a/lib/ioremap.c b/lib/ioremap.c
70711 index 0c9216c..863bd89 100644
70712 --- a/lib/ioremap.c
70713 +++ b/lib/ioremap.c
70714 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70715 unsigned long next;
70716
70717 phys_addr -= addr;
70718 - pmd = pmd_alloc(&init_mm, pud, addr);
70719 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70720 if (!pmd)
70721 return -ENOMEM;
70722 do {
70723 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70724 unsigned long next;
70725
70726 phys_addr -= addr;
70727 - pud = pud_alloc(&init_mm, pgd, addr);
70728 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
70729 if (!pud)
70730 return -ENOMEM;
70731 do {
70732 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70733 index bd2bea9..6b3c95e 100644
70734 --- a/lib/is_single_threaded.c
70735 +++ b/lib/is_single_threaded.c
70736 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70737 struct task_struct *p, *t;
70738 bool ret;
70739
70740 + if (!mm)
70741 + return true;
70742 +
70743 if (atomic_read(&task->signal->live) != 1)
70744 return false;
70745
70746 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70747 index e796429..6e38f9f 100644
70748 --- a/lib/radix-tree.c
70749 +++ b/lib/radix-tree.c
70750 @@ -92,7 +92,7 @@ struct radix_tree_preload {
70751 int nr;
70752 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70753 };
70754 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70755 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70756
70757 static inline void *ptr_to_indirect(void *ptr)
70758 {
70759 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70760 index 598a73e..5c5aeb5 100644
70761 --- a/lib/vsprintf.c
70762 +++ b/lib/vsprintf.c
70763 @@ -16,6 +16,9 @@
70764 * - scnprintf and vscnprintf
70765 */
70766
70767 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70768 +#define __INCLUDED_BY_HIDESYM 1
70769 +#endif
70770 #include <stdarg.h>
70771 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70772 #include <linux/types.h>
70773 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70774 char sym[KSYM_SYMBOL_LEN];
70775 if (ext == 'B')
70776 sprint_backtrace(sym, value);
70777 - else if (ext != 'f' && ext != 's')
70778 + else if (ext != 'f' && ext != 's' && ext != 'a')
70779 sprint_symbol(sym, value);
70780 else
70781 sprint_symbol_no_offset(sym, value);
70782 @@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70783 return number(buf, end, *(const netdev_features_t *)addr, spec);
70784 }
70785
70786 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70787 +int kptr_restrict __read_mostly = 2;
70788 +#else
70789 int kptr_restrict __read_mostly;
70790 +#endif
70791
70792 /*
70793 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70794 @@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70795 * - 'S' For symbolic direct pointers with offset
70796 * - 's' For symbolic direct pointers without offset
70797 * - 'B' For backtraced symbolic direct pointers with offset
70798 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70799 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70800 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70801 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70802 * - 'M' For a 6-byte MAC address, it prints the address in the
70803 @@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70804
70805 if (!ptr && *fmt != 'K') {
70806 /*
70807 - * Print (null) with the same width as a pointer so it makes
70808 + * Print (nil) with the same width as a pointer so it makes
70809 * tabular output look nice.
70810 */
70811 if (spec.field_width == -1)
70812 spec.field_width = default_width;
70813 - return string(buf, end, "(null)", spec);
70814 + return string(buf, end, "(nil)", spec);
70815 }
70816
70817 switch (*fmt) {
70818 @@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70819 /* Fallthrough */
70820 case 'S':
70821 case 's':
70822 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70823 + break;
70824 +#else
70825 + return symbol_string(buf, end, ptr, spec, *fmt);
70826 +#endif
70827 + case 'A':
70828 + case 'a':
70829 case 'B':
70830 return symbol_string(buf, end, ptr, spec, *fmt);
70831 case 'R':
70832 @@ -1025,6 +1041,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70833 va_end(va);
70834 return buf;
70835 }
70836 + case 'P':
70837 + break;
70838 case 'K':
70839 /*
70840 * %pK cannot be used in IRQ context because its test
70841 @@ -1048,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70842 }
70843 break;
70844 }
70845 +
70846 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70847 + /* 'P' = approved pointers to copy to userland,
70848 + as in the /proc/kallsyms case, as we make it display nothing
70849 + for non-root users, and the real contents for root users
70850 + Also ignore 'K' pointers, since we force their NULLing for non-root users
70851 + above
70852 + */
70853 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70854 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70855 + dump_stack();
70856 + ptr = NULL;
70857 + }
70858 +#endif
70859 +
70860 spec.flags |= SMALL;
70861 if (spec.field_width == -1) {
70862 spec.field_width = default_width;
70863 @@ -1759,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70864 typeof(type) value; \
70865 if (sizeof(type) == 8) { \
70866 args = PTR_ALIGN(args, sizeof(u32)); \
70867 - *(u32 *)&value = *(u32 *)args; \
70868 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70869 + *(u32 *)&value = *(const u32 *)args; \
70870 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70871 } else { \
70872 args = PTR_ALIGN(args, sizeof(type)); \
70873 - value = *(typeof(type) *)args; \
70874 + value = *(const typeof(type) *)args; \
70875 } \
70876 args += sizeof(type); \
70877 value; \
70878 @@ -1826,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70879 case FORMAT_TYPE_STR: {
70880 const char *str_arg = args;
70881 args += strlen(str_arg) + 1;
70882 - str = string(str, end, (char *)str_arg, spec);
70883 + str = string(str, end, str_arg, spec);
70884 break;
70885 }
70886
70887 diff --git a/localversion-grsec b/localversion-grsec
70888 new file mode 100644
70889 index 0000000..7cd6065
70890 --- /dev/null
70891 +++ b/localversion-grsec
70892 @@ -0,0 +1 @@
70893 +-grsec
70894 diff --git a/mm/Kconfig b/mm/Kconfig
70895 index 82fed4e..979e814 100644
70896 --- a/mm/Kconfig
70897 +++ b/mm/Kconfig
70898 @@ -247,10 +247,10 @@ config KSM
70899 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70900
70901 config DEFAULT_MMAP_MIN_ADDR
70902 - int "Low address space to protect from user allocation"
70903 + int "Low address space to protect from user allocation"
70904 depends on MMU
70905 - default 4096
70906 - help
70907 + default 65536
70908 + help
70909 This is the portion of low virtual memory which should be protected
70910 from userspace allocation. Keeping a user from writing to low pages
70911 can help reduce the impact of kernel NULL pointer bugs.
70912 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
70913
70914 config HWPOISON_INJECT
70915 tristate "HWPoison pages injector"
70916 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70917 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70918 select PROC_PAGE_MONITOR
70919
70920 config NOMMU_INITIAL_TRIM_EXCESS
70921 diff --git a/mm/filemap.c b/mm/filemap.c
70922 index a4a5260..6151dc5 100644
70923 --- a/mm/filemap.c
70924 +++ b/mm/filemap.c
70925 @@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70926 struct address_space *mapping = file->f_mapping;
70927
70928 if (!mapping->a_ops->readpage)
70929 - return -ENOEXEC;
70930 + return -ENODEV;
70931 file_accessed(file);
70932 vma->vm_ops = &generic_file_vm_ops;
70933 vma->vm_flags |= VM_CAN_NONLINEAR;
70934 @@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70935 *pos = i_size_read(inode);
70936
70937 if (limit != RLIM_INFINITY) {
70938 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70939 if (*pos >= limit) {
70940 send_sig(SIGXFSZ, current, 0);
70941 return -EFBIG;
70942 diff --git a/mm/fremap.c b/mm/fremap.c
70943 index 9ed4fd4..c42648d 100644
70944 --- a/mm/fremap.c
70945 +++ b/mm/fremap.c
70946 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70947 retry:
70948 vma = find_vma(mm, start);
70949
70950 +#ifdef CONFIG_PAX_SEGMEXEC
70951 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70952 + goto out;
70953 +#endif
70954 +
70955 /*
70956 * Make sure the vma is shared, that it supports prefaulting,
70957 * and that the remapped range is valid and fully within
70958 diff --git a/mm/highmem.c b/mm/highmem.c
70959 index 57d82c6..e9e0552 100644
70960 --- a/mm/highmem.c
70961 +++ b/mm/highmem.c
70962 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70963 * So no dangers, even with speculative execution.
70964 */
70965 page = pte_page(pkmap_page_table[i]);
70966 + pax_open_kernel();
70967 pte_clear(&init_mm, (unsigned long)page_address(page),
70968 &pkmap_page_table[i]);
70969 -
70970 + pax_close_kernel();
70971 set_page_address(page, NULL);
70972 need_flush = 1;
70973 }
70974 @@ -186,9 +187,11 @@ start:
70975 }
70976 }
70977 vaddr = PKMAP_ADDR(last_pkmap_nr);
70978 +
70979 + pax_open_kernel();
70980 set_pte_at(&init_mm, vaddr,
70981 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70982 -
70983 + pax_close_kernel();
70984 pkmap_count[last_pkmap_nr] = 1;
70985 set_page_address(page, (void *)vaddr);
70986
70987 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70988 index 57c4b93..24b8f59 100644
70989 --- a/mm/huge_memory.c
70990 +++ b/mm/huge_memory.c
70991 @@ -735,7 +735,7 @@ out:
70992 * run pte_offset_map on the pmd, if an huge pmd could
70993 * materialize from under us from a different thread.
70994 */
70995 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70996 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70997 return VM_FAULT_OOM;
70998 /* if an huge pmd materialized from under us just retry later */
70999 if (unlikely(pmd_trans_huge(*pmd)))
71000 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71001 index 19558df..f7743b3 100644
71002 --- a/mm/hugetlb.c
71003 +++ b/mm/hugetlb.c
71004 @@ -2463,6 +2463,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71005 return 1;
71006 }
71007
71008 +#ifdef CONFIG_PAX_SEGMEXEC
71009 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71010 +{
71011 + struct mm_struct *mm = vma->vm_mm;
71012 + struct vm_area_struct *vma_m;
71013 + unsigned long address_m;
71014 + pte_t *ptep_m;
71015 +
71016 + vma_m = pax_find_mirror_vma(vma);
71017 + if (!vma_m)
71018 + return;
71019 +
71020 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71021 + address_m = address + SEGMEXEC_TASK_SIZE;
71022 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71023 + get_page(page_m);
71024 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71025 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71026 +}
71027 +#endif
71028 +
71029 /*
71030 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71031 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71032 @@ -2575,6 +2596,11 @@ retry_avoidcopy:
71033 make_huge_pte(vma, new_page, 1));
71034 page_remove_rmap(old_page);
71035 hugepage_add_new_anon_rmap(new_page, vma, address);
71036 +
71037 +#ifdef CONFIG_PAX_SEGMEXEC
71038 + pax_mirror_huge_pte(vma, address, new_page);
71039 +#endif
71040 +
71041 /* Make the old page be freed below */
71042 new_page = old_page;
71043 mmu_notifier_invalidate_range_end(mm,
71044 @@ -2729,6 +2755,10 @@ retry:
71045 && (vma->vm_flags & VM_SHARED)));
71046 set_huge_pte_at(mm, address, ptep, new_pte);
71047
71048 +#ifdef CONFIG_PAX_SEGMEXEC
71049 + pax_mirror_huge_pte(vma, address, page);
71050 +#endif
71051 +
71052 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71053 /* Optimization, do the COW without a second fault */
71054 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71055 @@ -2758,6 +2788,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71056 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71057 struct hstate *h = hstate_vma(vma);
71058
71059 +#ifdef CONFIG_PAX_SEGMEXEC
71060 + struct vm_area_struct *vma_m;
71061 +#endif
71062 +
71063 address &= huge_page_mask(h);
71064
71065 ptep = huge_pte_offset(mm, address);
71066 @@ -2771,6 +2805,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71067 VM_FAULT_SET_HINDEX(h - hstates);
71068 }
71069
71070 +#ifdef CONFIG_PAX_SEGMEXEC
71071 + vma_m = pax_find_mirror_vma(vma);
71072 + if (vma_m) {
71073 + unsigned long address_m;
71074 +
71075 + if (vma->vm_start > vma_m->vm_start) {
71076 + address_m = address;
71077 + address -= SEGMEXEC_TASK_SIZE;
71078 + vma = vma_m;
71079 + h = hstate_vma(vma);
71080 + } else
71081 + address_m = address + SEGMEXEC_TASK_SIZE;
71082 +
71083 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71084 + return VM_FAULT_OOM;
71085 + address_m &= HPAGE_MASK;
71086 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71087 + }
71088 +#endif
71089 +
71090 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71091 if (!ptep)
71092 return VM_FAULT_OOM;
71093 diff --git a/mm/internal.h b/mm/internal.h
71094 index 8052379..47029d1 100644
71095 --- a/mm/internal.h
71096 +++ b/mm/internal.h
71097 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71098 * in mm/page_alloc.c
71099 */
71100 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71101 +extern void free_compound_page(struct page *page);
71102 extern void prep_compound_page(struct page *page, unsigned long order);
71103 #ifdef CONFIG_MEMORY_FAILURE
71104 extern bool is_free_buddy_page(struct page *page);
71105 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71106 index 45eb621..6ccd8ea 100644
71107 --- a/mm/kmemleak.c
71108 +++ b/mm/kmemleak.c
71109 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71110
71111 for (i = 0; i < object->trace_len; i++) {
71112 void *ptr = (void *)object->trace[i];
71113 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71114 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71115 }
71116 }
71117
71118 diff --git a/mm/maccess.c b/mm/maccess.c
71119 index d53adf9..03a24bf 100644
71120 --- a/mm/maccess.c
71121 +++ b/mm/maccess.c
71122 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71123 set_fs(KERNEL_DS);
71124 pagefault_disable();
71125 ret = __copy_from_user_inatomic(dst,
71126 - (__force const void __user *)src, size);
71127 + (const void __force_user *)src, size);
71128 pagefault_enable();
71129 set_fs(old_fs);
71130
71131 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71132
71133 set_fs(KERNEL_DS);
71134 pagefault_disable();
71135 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71136 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71137 pagefault_enable();
71138 set_fs(old_fs);
71139
71140 diff --git a/mm/madvise.c b/mm/madvise.c
71141 index 14d260f..b2a80fd 100644
71142 --- a/mm/madvise.c
71143 +++ b/mm/madvise.c
71144 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71145 pgoff_t pgoff;
71146 unsigned long new_flags = vma->vm_flags;
71147
71148 +#ifdef CONFIG_PAX_SEGMEXEC
71149 + struct vm_area_struct *vma_m;
71150 +#endif
71151 +
71152 switch (behavior) {
71153 case MADV_NORMAL:
71154 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71155 @@ -119,6 +123,13 @@ success:
71156 /*
71157 * vm_flags is protected by the mmap_sem held in write mode.
71158 */
71159 +
71160 +#ifdef CONFIG_PAX_SEGMEXEC
71161 + vma_m = pax_find_mirror_vma(vma);
71162 + if (vma_m)
71163 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71164 +#endif
71165 +
71166 vma->vm_flags = new_flags;
71167
71168 out:
71169 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71170 struct vm_area_struct ** prev,
71171 unsigned long start, unsigned long end)
71172 {
71173 +
71174 +#ifdef CONFIG_PAX_SEGMEXEC
71175 + struct vm_area_struct *vma_m;
71176 +#endif
71177 +
71178 *prev = vma;
71179 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71180 return -EINVAL;
71181 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71182 zap_page_range(vma, start, end - start, &details);
71183 } else
71184 zap_page_range(vma, start, end - start, NULL);
71185 +
71186 +#ifdef CONFIG_PAX_SEGMEXEC
71187 + vma_m = pax_find_mirror_vma(vma);
71188 + if (vma_m) {
71189 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71190 + struct zap_details details = {
71191 + .nonlinear_vma = vma_m,
71192 + .last_index = ULONG_MAX,
71193 + };
71194 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71195 + } else
71196 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71197 + }
71198 +#endif
71199 +
71200 return 0;
71201 }
71202
71203 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71204 if (end < start)
71205 goto out;
71206
71207 +#ifdef CONFIG_PAX_SEGMEXEC
71208 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71209 + if (end > SEGMEXEC_TASK_SIZE)
71210 + goto out;
71211 + } else
71212 +#endif
71213 +
71214 + if (end > TASK_SIZE)
71215 + goto out;
71216 +
71217 error = 0;
71218 if (end == start)
71219 goto out;
71220 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71221 index 6de0d61..da836cf 100644
71222 --- a/mm/memory-failure.c
71223 +++ b/mm/memory-failure.c
71224 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71225
71226 int sysctl_memory_failure_recovery __read_mostly = 1;
71227
71228 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71229 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71230
71231 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71232
71233 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71234 pfn, t->comm, t->pid);
71235 si.si_signo = SIGBUS;
71236 si.si_errno = 0;
71237 - si.si_addr = (void *)addr;
71238 + si.si_addr = (void __user *)addr;
71239 #ifdef __ARCH_SI_TRAPNO
71240 si.si_trapno = trapno;
71241 #endif
71242 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71243 }
71244
71245 nr_pages = 1 << compound_trans_order(hpage);
71246 - atomic_long_add(nr_pages, &mce_bad_pages);
71247 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71248
71249 /*
71250 * We need/can do nothing about count=0 pages.
71251 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71252 if (!PageHWPoison(hpage)
71253 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71254 || (p != hpage && TestSetPageHWPoison(hpage))) {
71255 - atomic_long_sub(nr_pages, &mce_bad_pages);
71256 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71257 return 0;
71258 }
71259 set_page_hwpoison_huge_page(hpage);
71260 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71261 }
71262 if (hwpoison_filter(p)) {
71263 if (TestClearPageHWPoison(p))
71264 - atomic_long_sub(nr_pages, &mce_bad_pages);
71265 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71266 unlock_page(hpage);
71267 put_page(hpage);
71268 return 0;
71269 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71270 return 0;
71271 }
71272 if (TestClearPageHWPoison(p))
71273 - atomic_long_sub(nr_pages, &mce_bad_pages);
71274 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71275 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71276 return 0;
71277 }
71278 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71279 */
71280 if (TestClearPageHWPoison(page)) {
71281 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71282 - atomic_long_sub(nr_pages, &mce_bad_pages);
71283 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71284 freeit = 1;
71285 if (PageHuge(page))
71286 clear_page_hwpoison_huge_page(page);
71287 @@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71288 }
71289 done:
71290 if (!PageHWPoison(hpage))
71291 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71292 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71293 set_page_hwpoison_huge_page(hpage);
71294 dequeue_hwpoisoned_huge_page(hpage);
71295 /* keep elevated page count for bad page */
71296 @@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71297 return ret;
71298
71299 done:
71300 - atomic_long_add(1, &mce_bad_pages);
71301 + atomic_long_add_unchecked(1, &mce_bad_pages);
71302 SetPageHWPoison(page);
71303 /* keep elevated page count for bad page */
71304 return ret;
71305 diff --git a/mm/memory.c b/mm/memory.c
71306 index 2466d12..08be4f6 100644
71307 --- a/mm/memory.c
71308 +++ b/mm/memory.c
71309 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71310 return;
71311
71312 pmd = pmd_offset(pud, start);
71313 +
71314 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71315 pud_clear(pud);
71316 pmd_free_tlb(tlb, pmd, start);
71317 +#endif
71318 +
71319 }
71320
71321 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71322 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71323 if (end - 1 > ceiling - 1)
71324 return;
71325
71326 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71327 pud = pud_offset(pgd, start);
71328 pgd_clear(pgd);
71329 pud_free_tlb(tlb, pud, start);
71330 +#endif
71331 +
71332 }
71333
71334 /*
71335 @@ -1602,12 +1609,6 @@ no_page_table:
71336 return page;
71337 }
71338
71339 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71340 -{
71341 - return stack_guard_page_start(vma, addr) ||
71342 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71343 -}
71344 -
71345 /**
71346 * __get_user_pages() - pin user pages in memory
71347 * @tsk: task_struct of target task
71348 @@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71349 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71350 i = 0;
71351
71352 - do {
71353 + while (nr_pages) {
71354 struct vm_area_struct *vma;
71355
71356 - vma = find_extend_vma(mm, start);
71357 + vma = find_vma(mm, start);
71358 if (!vma && in_gate_area(mm, start)) {
71359 unsigned long pg = start & PAGE_MASK;
71360 pgd_t *pgd;
71361 @@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71362 goto next_page;
71363 }
71364
71365 - if (!vma ||
71366 + if (!vma || start < vma->vm_start ||
71367 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71368 !(vm_flags & vma->vm_flags))
71369 return i ? : -EFAULT;
71370 @@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71371 int ret;
71372 unsigned int fault_flags = 0;
71373
71374 - /* For mlock, just skip the stack guard page. */
71375 - if (foll_flags & FOLL_MLOCK) {
71376 - if (stack_guard_page(vma, start))
71377 - goto next_page;
71378 - }
71379 if (foll_flags & FOLL_WRITE)
71380 fault_flags |= FAULT_FLAG_WRITE;
71381 if (nonblocking)
71382 @@ -1836,7 +1832,7 @@ next_page:
71383 start += PAGE_SIZE;
71384 nr_pages--;
71385 } while (nr_pages && start < vma->vm_end);
71386 - } while (nr_pages);
71387 + }
71388 return i;
71389 }
71390 EXPORT_SYMBOL(__get_user_pages);
71391 @@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71392 page_add_file_rmap(page);
71393 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71394
71395 +#ifdef CONFIG_PAX_SEGMEXEC
71396 + pax_mirror_file_pte(vma, addr, page, ptl);
71397 +#endif
71398 +
71399 retval = 0;
71400 pte_unmap_unlock(pte, ptl);
71401 return retval;
71402 @@ -2077,10 +2077,22 @@ out:
71403 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71404 struct page *page)
71405 {
71406 +
71407 +#ifdef CONFIG_PAX_SEGMEXEC
71408 + struct vm_area_struct *vma_m;
71409 +#endif
71410 +
71411 if (addr < vma->vm_start || addr >= vma->vm_end)
71412 return -EFAULT;
71413 if (!page_count(page))
71414 return -EINVAL;
71415 +
71416 +#ifdef CONFIG_PAX_SEGMEXEC
71417 + vma_m = pax_find_mirror_vma(vma);
71418 + if (vma_m)
71419 + vma_m->vm_flags |= VM_INSERTPAGE;
71420 +#endif
71421 +
71422 vma->vm_flags |= VM_INSERTPAGE;
71423 return insert_page(vma, addr, page, vma->vm_page_prot);
71424 }
71425 @@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71426 unsigned long pfn)
71427 {
71428 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71429 + BUG_ON(vma->vm_mirror);
71430
71431 if (addr < vma->vm_start || addr >= vma->vm_end)
71432 return -EFAULT;
71433 @@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71434
71435 BUG_ON(pud_huge(*pud));
71436
71437 - pmd = pmd_alloc(mm, pud, addr);
71438 + pmd = (mm == &init_mm) ?
71439 + pmd_alloc_kernel(mm, pud, addr) :
71440 + pmd_alloc(mm, pud, addr);
71441 if (!pmd)
71442 return -ENOMEM;
71443 do {
71444 @@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71445 unsigned long next;
71446 int err;
71447
71448 - pud = pud_alloc(mm, pgd, addr);
71449 + pud = (mm == &init_mm) ?
71450 + pud_alloc_kernel(mm, pgd, addr) :
71451 + pud_alloc(mm, pgd, addr);
71452 if (!pud)
71453 return -ENOMEM;
71454 do {
71455 @@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71456 copy_user_highpage(dst, src, va, vma);
71457 }
71458
71459 +#ifdef CONFIG_PAX_SEGMEXEC
71460 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71461 +{
71462 + struct mm_struct *mm = vma->vm_mm;
71463 + spinlock_t *ptl;
71464 + pte_t *pte, entry;
71465 +
71466 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71467 + entry = *pte;
71468 + if (!pte_present(entry)) {
71469 + if (!pte_none(entry)) {
71470 + BUG_ON(pte_file(entry));
71471 + free_swap_and_cache(pte_to_swp_entry(entry));
71472 + pte_clear_not_present_full(mm, address, pte, 0);
71473 + }
71474 + } else {
71475 + struct page *page;
71476 +
71477 + flush_cache_page(vma, address, pte_pfn(entry));
71478 + entry = ptep_clear_flush(vma, address, pte);
71479 + BUG_ON(pte_dirty(entry));
71480 + page = vm_normal_page(vma, address, entry);
71481 + if (page) {
71482 + update_hiwater_rss(mm);
71483 + if (PageAnon(page))
71484 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71485 + else
71486 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71487 + page_remove_rmap(page);
71488 + page_cache_release(page);
71489 + }
71490 + }
71491 + pte_unmap_unlock(pte, ptl);
71492 +}
71493 +
71494 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71495 + *
71496 + * the ptl of the lower mapped page is held on entry and is not released on exit
71497 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71498 + */
71499 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71500 +{
71501 + struct mm_struct *mm = vma->vm_mm;
71502 + unsigned long address_m;
71503 + spinlock_t *ptl_m;
71504 + struct vm_area_struct *vma_m;
71505 + pmd_t *pmd_m;
71506 + pte_t *pte_m, entry_m;
71507 +
71508 + BUG_ON(!page_m || !PageAnon(page_m));
71509 +
71510 + vma_m = pax_find_mirror_vma(vma);
71511 + if (!vma_m)
71512 + return;
71513 +
71514 + BUG_ON(!PageLocked(page_m));
71515 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71516 + address_m = address + SEGMEXEC_TASK_SIZE;
71517 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71518 + pte_m = pte_offset_map(pmd_m, address_m);
71519 + ptl_m = pte_lockptr(mm, pmd_m);
71520 + if (ptl != ptl_m) {
71521 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71522 + if (!pte_none(*pte_m))
71523 + goto out;
71524 + }
71525 +
71526 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71527 + page_cache_get(page_m);
71528 + page_add_anon_rmap(page_m, vma_m, address_m);
71529 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71530 + set_pte_at(mm, address_m, pte_m, entry_m);
71531 + update_mmu_cache(vma_m, address_m, entry_m);
71532 +out:
71533 + if (ptl != ptl_m)
71534 + spin_unlock(ptl_m);
71535 + pte_unmap(pte_m);
71536 + unlock_page(page_m);
71537 +}
71538 +
71539 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71540 +{
71541 + struct mm_struct *mm = vma->vm_mm;
71542 + unsigned long address_m;
71543 + spinlock_t *ptl_m;
71544 + struct vm_area_struct *vma_m;
71545 + pmd_t *pmd_m;
71546 + pte_t *pte_m, entry_m;
71547 +
71548 + BUG_ON(!page_m || PageAnon(page_m));
71549 +
71550 + vma_m = pax_find_mirror_vma(vma);
71551 + if (!vma_m)
71552 + return;
71553 +
71554 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71555 + address_m = address + SEGMEXEC_TASK_SIZE;
71556 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71557 + pte_m = pte_offset_map(pmd_m, address_m);
71558 + ptl_m = pte_lockptr(mm, pmd_m);
71559 + if (ptl != ptl_m) {
71560 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71561 + if (!pte_none(*pte_m))
71562 + goto out;
71563 + }
71564 +
71565 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71566 + page_cache_get(page_m);
71567 + page_add_file_rmap(page_m);
71568 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71569 + set_pte_at(mm, address_m, pte_m, entry_m);
71570 + update_mmu_cache(vma_m, address_m, entry_m);
71571 +out:
71572 + if (ptl != ptl_m)
71573 + spin_unlock(ptl_m);
71574 + pte_unmap(pte_m);
71575 +}
71576 +
71577 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71578 +{
71579 + struct mm_struct *mm = vma->vm_mm;
71580 + unsigned long address_m;
71581 + spinlock_t *ptl_m;
71582 + struct vm_area_struct *vma_m;
71583 + pmd_t *pmd_m;
71584 + pte_t *pte_m, entry_m;
71585 +
71586 + vma_m = pax_find_mirror_vma(vma);
71587 + if (!vma_m)
71588 + return;
71589 +
71590 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71591 + address_m = address + SEGMEXEC_TASK_SIZE;
71592 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71593 + pte_m = pte_offset_map(pmd_m, address_m);
71594 + ptl_m = pte_lockptr(mm, pmd_m);
71595 + if (ptl != ptl_m) {
71596 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71597 + if (!pte_none(*pte_m))
71598 + goto out;
71599 + }
71600 +
71601 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71602 + set_pte_at(mm, address_m, pte_m, entry_m);
71603 +out:
71604 + if (ptl != ptl_m)
71605 + spin_unlock(ptl_m);
71606 + pte_unmap(pte_m);
71607 +}
71608 +
71609 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71610 +{
71611 + struct page *page_m;
71612 + pte_t entry;
71613 +
71614 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71615 + goto out;
71616 +
71617 + entry = *pte;
71618 + page_m = vm_normal_page(vma, address, entry);
71619 + if (!page_m)
71620 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71621 + else if (PageAnon(page_m)) {
71622 + if (pax_find_mirror_vma(vma)) {
71623 + pte_unmap_unlock(pte, ptl);
71624 + lock_page(page_m);
71625 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71626 + if (pte_same(entry, *pte))
71627 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71628 + else
71629 + unlock_page(page_m);
71630 + }
71631 + } else
71632 + pax_mirror_file_pte(vma, address, page_m, ptl);
71633 +
71634 +out:
71635 + pte_unmap_unlock(pte, ptl);
71636 +}
71637 +#endif
71638 +
71639 /*
71640 * This routine handles present pages, when users try to write
71641 * to a shared page. It is done by copying the page to a new address
71642 @@ -2692,6 +2889,12 @@ gotten:
71643 */
71644 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71645 if (likely(pte_same(*page_table, orig_pte))) {
71646 +
71647 +#ifdef CONFIG_PAX_SEGMEXEC
71648 + if (pax_find_mirror_vma(vma))
71649 + BUG_ON(!trylock_page(new_page));
71650 +#endif
71651 +
71652 if (old_page) {
71653 if (!PageAnon(old_page)) {
71654 dec_mm_counter_fast(mm, MM_FILEPAGES);
71655 @@ -2743,6 +2946,10 @@ gotten:
71656 page_remove_rmap(old_page);
71657 }
71658
71659 +#ifdef CONFIG_PAX_SEGMEXEC
71660 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71661 +#endif
71662 +
71663 /* Free the old page.. */
71664 new_page = old_page;
71665 ret |= VM_FAULT_WRITE;
71666 @@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71667 swap_free(entry);
71668 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71669 try_to_free_swap(page);
71670 +
71671 +#ifdef CONFIG_PAX_SEGMEXEC
71672 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71673 +#endif
71674 +
71675 unlock_page(page);
71676 if (swapcache) {
71677 /*
71678 @@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71679
71680 /* No need to invalidate - it was non-present before */
71681 update_mmu_cache(vma, address, page_table);
71682 +
71683 +#ifdef CONFIG_PAX_SEGMEXEC
71684 + pax_mirror_anon_pte(vma, address, page, ptl);
71685 +#endif
71686 +
71687 unlock:
71688 pte_unmap_unlock(page_table, ptl);
71689 out:
71690 @@ -3064,40 +3281,6 @@ out_release:
71691 }
71692
71693 /*
71694 - * This is like a special single-page "expand_{down|up}wards()",
71695 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71696 - * doesn't hit another vma.
71697 - */
71698 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71699 -{
71700 - address &= PAGE_MASK;
71701 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71702 - struct vm_area_struct *prev = vma->vm_prev;
71703 -
71704 - /*
71705 - * Is there a mapping abutting this one below?
71706 - *
71707 - * That's only ok if it's the same stack mapping
71708 - * that has gotten split..
71709 - */
71710 - if (prev && prev->vm_end == address)
71711 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71712 -
71713 - expand_downwards(vma, address - PAGE_SIZE);
71714 - }
71715 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71716 - struct vm_area_struct *next = vma->vm_next;
71717 -
71718 - /* As VM_GROWSDOWN but s/below/above/ */
71719 - if (next && next->vm_start == address + PAGE_SIZE)
71720 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71721 -
71722 - expand_upwards(vma, address + PAGE_SIZE);
71723 - }
71724 - return 0;
71725 -}
71726 -
71727 -/*
71728 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71729 * but allow concurrent faults), and pte mapped but not yet locked.
71730 * We return with mmap_sem still held, but pte unmapped and unlocked.
71731 @@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71732 unsigned long address, pte_t *page_table, pmd_t *pmd,
71733 unsigned int flags)
71734 {
71735 - struct page *page;
71736 + struct page *page = NULL;
71737 spinlock_t *ptl;
71738 pte_t entry;
71739
71740 - pte_unmap(page_table);
71741 -
71742 - /* Check if we need to add a guard page to the stack */
71743 - if (check_stack_guard_page(vma, address) < 0)
71744 - return VM_FAULT_SIGBUS;
71745 -
71746 - /* Use the zero-page for reads */
71747 if (!(flags & FAULT_FLAG_WRITE)) {
71748 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71749 vma->vm_page_prot));
71750 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71751 + ptl = pte_lockptr(mm, pmd);
71752 + spin_lock(ptl);
71753 if (!pte_none(*page_table))
71754 goto unlock;
71755 goto setpte;
71756 }
71757
71758 /* Allocate our own private page. */
71759 + pte_unmap(page_table);
71760 +
71761 if (unlikely(anon_vma_prepare(vma)))
71762 goto oom;
71763 page = alloc_zeroed_user_highpage_movable(vma, address);
71764 @@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71765 if (!pte_none(*page_table))
71766 goto release;
71767
71768 +#ifdef CONFIG_PAX_SEGMEXEC
71769 + if (pax_find_mirror_vma(vma))
71770 + BUG_ON(!trylock_page(page));
71771 +#endif
71772 +
71773 inc_mm_counter_fast(mm, MM_ANONPAGES);
71774 page_add_new_anon_rmap(page, vma, address);
71775 setpte:
71776 @@ -3152,6 +3336,12 @@ setpte:
71777
71778 /* No need to invalidate - it was non-present before */
71779 update_mmu_cache(vma, address, page_table);
71780 +
71781 +#ifdef CONFIG_PAX_SEGMEXEC
71782 + if (page)
71783 + pax_mirror_anon_pte(vma, address, page, ptl);
71784 +#endif
71785 +
71786 unlock:
71787 pte_unmap_unlock(page_table, ptl);
71788 return 0;
71789 @@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71790 */
71791 /* Only go through if we didn't race with anybody else... */
71792 if (likely(pte_same(*page_table, orig_pte))) {
71793 +
71794 +#ifdef CONFIG_PAX_SEGMEXEC
71795 + if (anon && pax_find_mirror_vma(vma))
71796 + BUG_ON(!trylock_page(page));
71797 +#endif
71798 +
71799 flush_icache_page(vma, page);
71800 entry = mk_pte(page, vma->vm_page_prot);
71801 if (flags & FAULT_FLAG_WRITE)
71802 @@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71803
71804 /* no need to invalidate: a not-present page won't be cached */
71805 update_mmu_cache(vma, address, page_table);
71806 +
71807 +#ifdef CONFIG_PAX_SEGMEXEC
71808 + if (anon)
71809 + pax_mirror_anon_pte(vma, address, page, ptl);
71810 + else
71811 + pax_mirror_file_pte(vma, address, page, ptl);
71812 +#endif
71813 +
71814 } else {
71815 if (cow_page)
71816 mem_cgroup_uncharge_page(cow_page);
71817 @@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71818 if (flags & FAULT_FLAG_WRITE)
71819 flush_tlb_fix_spurious_fault(vma, address);
71820 }
71821 +
71822 +#ifdef CONFIG_PAX_SEGMEXEC
71823 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71824 + return 0;
71825 +#endif
71826 +
71827 unlock:
71828 pte_unmap_unlock(pte, ptl);
71829 return 0;
71830 @@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71831 pmd_t *pmd;
71832 pte_t *pte;
71833
71834 +#ifdef CONFIG_PAX_SEGMEXEC
71835 + struct vm_area_struct *vma_m;
71836 +#endif
71837 +
71838 __set_current_state(TASK_RUNNING);
71839
71840 count_vm_event(PGFAULT);
71841 @@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71842 if (unlikely(is_vm_hugetlb_page(vma)))
71843 return hugetlb_fault(mm, vma, address, flags);
71844
71845 +#ifdef CONFIG_PAX_SEGMEXEC
71846 + vma_m = pax_find_mirror_vma(vma);
71847 + if (vma_m) {
71848 + unsigned long address_m;
71849 + pgd_t *pgd_m;
71850 + pud_t *pud_m;
71851 + pmd_t *pmd_m;
71852 +
71853 + if (vma->vm_start > vma_m->vm_start) {
71854 + address_m = address;
71855 + address -= SEGMEXEC_TASK_SIZE;
71856 + vma = vma_m;
71857 + } else
71858 + address_m = address + SEGMEXEC_TASK_SIZE;
71859 +
71860 + pgd_m = pgd_offset(mm, address_m);
71861 + pud_m = pud_alloc(mm, pgd_m, address_m);
71862 + if (!pud_m)
71863 + return VM_FAULT_OOM;
71864 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71865 + if (!pmd_m)
71866 + return VM_FAULT_OOM;
71867 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71868 + return VM_FAULT_OOM;
71869 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71870 + }
71871 +#endif
71872 +
71873 retry:
71874 pgd = pgd_offset(mm, address);
71875 pud = pud_alloc(mm, pgd, address);
71876 @@ -3535,7 +3777,7 @@ retry:
71877 * run pte_offset_map on the pmd, if an huge pmd could
71878 * materialize from under us from a different thread.
71879 */
71880 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71881 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71882 return VM_FAULT_OOM;
71883 /* if an huge pmd materialized from under us just retry later */
71884 if (unlikely(pmd_trans_huge(*pmd)))
71885 @@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71886 spin_unlock(&mm->page_table_lock);
71887 return 0;
71888 }
71889 +
71890 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71891 +{
71892 + pud_t *new = pud_alloc_one(mm, address);
71893 + if (!new)
71894 + return -ENOMEM;
71895 +
71896 + smp_wmb(); /* See comment in __pte_alloc */
71897 +
71898 + spin_lock(&mm->page_table_lock);
71899 + if (pgd_present(*pgd)) /* Another has populated it */
71900 + pud_free(mm, new);
71901 + else
71902 + pgd_populate_kernel(mm, pgd, new);
71903 + spin_unlock(&mm->page_table_lock);
71904 + return 0;
71905 +}
71906 #endif /* __PAGETABLE_PUD_FOLDED */
71907
71908 #ifndef __PAGETABLE_PMD_FOLDED
71909 @@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71910 spin_unlock(&mm->page_table_lock);
71911 return 0;
71912 }
71913 +
71914 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71915 +{
71916 + pmd_t *new = pmd_alloc_one(mm, address);
71917 + if (!new)
71918 + return -ENOMEM;
71919 +
71920 + smp_wmb(); /* See comment in __pte_alloc */
71921 +
71922 + spin_lock(&mm->page_table_lock);
71923 +#ifndef __ARCH_HAS_4LEVEL_HACK
71924 + if (pud_present(*pud)) /* Another has populated it */
71925 + pmd_free(mm, new);
71926 + else
71927 + pud_populate_kernel(mm, pud, new);
71928 +#else
71929 + if (pgd_present(*pud)) /* Another has populated it */
71930 + pmd_free(mm, new);
71931 + else
71932 + pgd_populate_kernel(mm, pud, new);
71933 +#endif /* __ARCH_HAS_4LEVEL_HACK */
71934 + spin_unlock(&mm->page_table_lock);
71935 + return 0;
71936 +}
71937 #endif /* __PAGETABLE_PMD_FOLDED */
71938
71939 int make_pages_present(unsigned long addr, unsigned long end)
71940 @@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71941 gate_vma.vm_start = FIXADDR_USER_START;
71942 gate_vma.vm_end = FIXADDR_USER_END;
71943 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71944 - gate_vma.vm_page_prot = __P101;
71945 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71946
71947 return 0;
71948 }
71949 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71950 index 1d771e4..64b57d0 100644
71951 --- a/mm/mempolicy.c
71952 +++ b/mm/mempolicy.c
71953 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71954 unsigned long vmstart;
71955 unsigned long vmend;
71956
71957 +#ifdef CONFIG_PAX_SEGMEXEC
71958 + struct vm_area_struct *vma_m;
71959 +#endif
71960 +
71961 vma = find_vma(mm, start);
71962 if (!vma || vma->vm_start > start)
71963 return -EFAULT;
71964 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71965 if (err)
71966 goto out;
71967 }
71968 +
71969 +#ifdef CONFIG_PAX_SEGMEXEC
71970 + vma_m = pax_find_mirror_vma(vma);
71971 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71972 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71973 + if (err)
71974 + goto out;
71975 + }
71976 +#endif
71977 +
71978 }
71979
71980 out:
71981 @@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71982
71983 if (end < start)
71984 return -EINVAL;
71985 +
71986 +#ifdef CONFIG_PAX_SEGMEXEC
71987 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71988 + if (end > SEGMEXEC_TASK_SIZE)
71989 + return -EINVAL;
71990 + } else
71991 +#endif
71992 +
71993 + if (end > TASK_SIZE)
71994 + return -EINVAL;
71995 +
71996 if (end == start)
71997 return 0;
71998
71999 @@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72000 */
72001 tcred = __task_cred(task);
72002 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72003 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72004 - !capable(CAP_SYS_NICE)) {
72005 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72006 rcu_read_unlock();
72007 err = -EPERM;
72008 goto out_put;
72009 @@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72010 goto out;
72011 }
72012
72013 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72014 + if (mm != current->mm &&
72015 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72016 + mmput(mm);
72017 + err = -EPERM;
72018 + goto out;
72019 + }
72020 +#endif
72021 +
72022 err = do_migrate_pages(mm, old, new,
72023 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72024
72025 @@ -2556,7 +2589,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
72026 break;
72027
72028 default:
72029 - BUG();
72030 + return -EINVAL;
72031 }
72032
72033 l = strlen(policy_modes[mode]);
72034 diff --git a/mm/mlock.c b/mm/mlock.c
72035 index ef726e8..cd7f1ec 100644
72036 --- a/mm/mlock.c
72037 +++ b/mm/mlock.c
72038 @@ -13,6 +13,7 @@
72039 #include <linux/pagemap.h>
72040 #include <linux/mempolicy.h>
72041 #include <linux/syscalls.h>
72042 +#include <linux/security.h>
72043 #include <linux/sched.h>
72044 #include <linux/export.h>
72045 #include <linux/rmap.h>
72046 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72047 {
72048 unsigned long nstart, end, tmp;
72049 struct vm_area_struct * vma, * prev;
72050 - int error;
72051 + int error = 0;
72052
72053 VM_BUG_ON(start & ~PAGE_MASK);
72054 VM_BUG_ON(len != PAGE_ALIGN(len));
72055 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72056 return -EINVAL;
72057 if (end == start)
72058 return 0;
72059 + if (end > TASK_SIZE)
72060 + return -EINVAL;
72061 +
72062 vma = find_vma(current->mm, start);
72063 if (!vma || vma->vm_start > start)
72064 return -ENOMEM;
72065 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72066 for (nstart = start ; ; ) {
72067 vm_flags_t newflags;
72068
72069 +#ifdef CONFIG_PAX_SEGMEXEC
72070 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72071 + break;
72072 +#endif
72073 +
72074 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72075
72076 newflags = vma->vm_flags | VM_LOCKED;
72077 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72078 lock_limit >>= PAGE_SHIFT;
72079
72080 /* check against resource limits */
72081 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72082 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72083 error = do_mlock(start, len, 1);
72084 up_write(&current->mm->mmap_sem);
72085 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72086 static int do_mlockall(int flags)
72087 {
72088 struct vm_area_struct * vma, * prev = NULL;
72089 - unsigned int def_flags = 0;
72090
72091 if (flags & MCL_FUTURE)
72092 - def_flags = VM_LOCKED;
72093 - current->mm->def_flags = def_flags;
72094 + current->mm->def_flags |= VM_LOCKED;
72095 + else
72096 + current->mm->def_flags &= ~VM_LOCKED;
72097 if (flags == MCL_FUTURE)
72098 goto out;
72099
72100 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72101 vm_flags_t newflags;
72102
72103 +#ifdef CONFIG_PAX_SEGMEXEC
72104 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72105 + break;
72106 +#endif
72107 +
72108 + BUG_ON(vma->vm_end > TASK_SIZE);
72109 newflags = vma->vm_flags | VM_LOCKED;
72110 if (!(flags & MCL_CURRENT))
72111 newflags &= ~VM_LOCKED;
72112 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72113 lock_limit >>= PAGE_SHIFT;
72114
72115 ret = -ENOMEM;
72116 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72117 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72118 capable(CAP_IPC_LOCK))
72119 ret = do_mlockall(flags);
72120 diff --git a/mm/mmap.c b/mm/mmap.c
72121 index 3edfcdf..4a27ae9 100644
72122 --- a/mm/mmap.c
72123 +++ b/mm/mmap.c
72124 @@ -47,6 +47,16 @@
72125 #define arch_rebalance_pgtables(addr, len) (addr)
72126 #endif
72127
72128 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72129 +{
72130 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72131 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72132 + up_read(&mm->mmap_sem);
72133 + BUG();
72134 + }
72135 +#endif
72136 +}
72137 +
72138 static void unmap_region(struct mm_struct *mm,
72139 struct vm_area_struct *vma, struct vm_area_struct *prev,
72140 unsigned long start, unsigned long end);
72141 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72142 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72143 *
72144 */
72145 -pgprot_t protection_map[16] = {
72146 +pgprot_t protection_map[16] __read_only = {
72147 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72148 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72149 };
72150
72151 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72152 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72153 {
72154 - return __pgprot(pgprot_val(protection_map[vm_flags &
72155 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72156 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72157 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72158 +
72159 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72160 + if (!(__supported_pte_mask & _PAGE_NX) &&
72161 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72162 + (vm_flags & (VM_READ | VM_WRITE)))
72163 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72164 +#endif
72165 +
72166 + return prot;
72167 }
72168 EXPORT_SYMBOL(vm_get_page_prot);
72169
72170 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72171 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72172 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72173 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72174 /*
72175 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72176 * other variables. It can be updated by several CPUs frequently.
72177 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72178 struct vm_area_struct *next = vma->vm_next;
72179
72180 might_sleep();
72181 + BUG_ON(vma->vm_mirror);
72182 if (vma->vm_ops && vma->vm_ops->close)
72183 vma->vm_ops->close(vma);
72184 if (vma->vm_file) {
72185 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72186 * not page aligned -Ram Gupta
72187 */
72188 rlim = rlimit(RLIMIT_DATA);
72189 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72190 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72191 (mm->end_data - mm->start_data) > rlim)
72192 goto out;
72193 @@ -708,6 +730,12 @@ static int
72194 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72195 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72196 {
72197 +
72198 +#ifdef CONFIG_PAX_SEGMEXEC
72199 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72200 + return 0;
72201 +#endif
72202 +
72203 if (is_mergeable_vma(vma, file, vm_flags) &&
72204 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72205 if (vma->vm_pgoff == vm_pgoff)
72206 @@ -727,6 +755,12 @@ static int
72207 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72208 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72209 {
72210 +
72211 +#ifdef CONFIG_PAX_SEGMEXEC
72212 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72213 + return 0;
72214 +#endif
72215 +
72216 if (is_mergeable_vma(vma, file, vm_flags) &&
72217 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72218 pgoff_t vm_pglen;
72219 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72220 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72221 struct vm_area_struct *prev, unsigned long addr,
72222 unsigned long end, unsigned long vm_flags,
72223 - struct anon_vma *anon_vma, struct file *file,
72224 + struct anon_vma *anon_vma, struct file *file,
72225 pgoff_t pgoff, struct mempolicy *policy)
72226 {
72227 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72228 struct vm_area_struct *area, *next;
72229 int err;
72230
72231 +#ifdef CONFIG_PAX_SEGMEXEC
72232 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72233 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72234 +
72235 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72236 +#endif
72237 +
72238 /*
72239 * We later require that vma->vm_flags == vm_flags,
72240 * so this tests vma->vm_flags & VM_SPECIAL, too.
72241 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72242 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72243 next = next->vm_next;
72244
72245 +#ifdef CONFIG_PAX_SEGMEXEC
72246 + if (prev)
72247 + prev_m = pax_find_mirror_vma(prev);
72248 + if (area)
72249 + area_m = pax_find_mirror_vma(area);
72250 + if (next)
72251 + next_m = pax_find_mirror_vma(next);
72252 +#endif
72253 +
72254 /*
72255 * Can it merge with the predecessor?
72256 */
72257 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72258 /* cases 1, 6 */
72259 err = vma_adjust(prev, prev->vm_start,
72260 next->vm_end, prev->vm_pgoff, NULL);
72261 - } else /* cases 2, 5, 7 */
72262 +
72263 +#ifdef CONFIG_PAX_SEGMEXEC
72264 + if (!err && prev_m)
72265 + err = vma_adjust(prev_m, prev_m->vm_start,
72266 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72267 +#endif
72268 +
72269 + } else { /* cases 2, 5, 7 */
72270 err = vma_adjust(prev, prev->vm_start,
72271 end, prev->vm_pgoff, NULL);
72272 +
72273 +#ifdef CONFIG_PAX_SEGMEXEC
72274 + if (!err && prev_m)
72275 + err = vma_adjust(prev_m, prev_m->vm_start,
72276 + end_m, prev_m->vm_pgoff, NULL);
72277 +#endif
72278 +
72279 + }
72280 if (err)
72281 return NULL;
72282 khugepaged_enter_vma_merge(prev);
72283 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72284 mpol_equal(policy, vma_policy(next)) &&
72285 can_vma_merge_before(next, vm_flags,
72286 anon_vma, file, pgoff+pglen)) {
72287 - if (prev && addr < prev->vm_end) /* case 4 */
72288 + if (prev && addr < prev->vm_end) { /* case 4 */
72289 err = vma_adjust(prev, prev->vm_start,
72290 addr, prev->vm_pgoff, NULL);
72291 - else /* cases 3, 8 */
72292 +
72293 +#ifdef CONFIG_PAX_SEGMEXEC
72294 + if (!err && prev_m)
72295 + err = vma_adjust(prev_m, prev_m->vm_start,
72296 + addr_m, prev_m->vm_pgoff, NULL);
72297 +#endif
72298 +
72299 + } else { /* cases 3, 8 */
72300 err = vma_adjust(area, addr, next->vm_end,
72301 next->vm_pgoff - pglen, NULL);
72302 +
72303 +#ifdef CONFIG_PAX_SEGMEXEC
72304 + if (!err && area_m)
72305 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72306 + next_m->vm_pgoff - pglen, NULL);
72307 +#endif
72308 +
72309 + }
72310 if (err)
72311 return NULL;
72312 khugepaged_enter_vma_merge(area);
72313 @@ -940,14 +1020,11 @@ none:
72314 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72315 struct file *file, long pages)
72316 {
72317 - const unsigned long stack_flags
72318 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72319 -
72320 if (file) {
72321 mm->shared_vm += pages;
72322 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72323 mm->exec_vm += pages;
72324 - } else if (flags & stack_flags)
72325 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72326 mm->stack_vm += pages;
72327 if (flags & (VM_RESERVED|VM_IO))
72328 mm->reserved_vm += pages;
72329 @@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72330 * (the exception is when the underlying filesystem is noexec
72331 * mounted, in which case we dont add PROT_EXEC.)
72332 */
72333 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72334 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72335 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72336 prot |= PROT_EXEC;
72337
72338 @@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72339 /* Obtain the address to map to. we verify (or select) it and ensure
72340 * that it represents a valid section of the address space.
72341 */
72342 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72343 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72344 if (addr & ~PAGE_MASK)
72345 return addr;
72346
72347 @@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72348 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72349 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72350
72351 +#ifdef CONFIG_PAX_MPROTECT
72352 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72353 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72354 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72355 + gr_log_rwxmmap(file);
72356 +
72357 +#ifdef CONFIG_PAX_EMUPLT
72358 + vm_flags &= ~VM_EXEC;
72359 +#else
72360 + return -EPERM;
72361 +#endif
72362 +
72363 + }
72364 +
72365 + if (!(vm_flags & VM_EXEC))
72366 + vm_flags &= ~VM_MAYEXEC;
72367 +#else
72368 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72369 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72370 +#endif
72371 + else
72372 + vm_flags &= ~VM_MAYWRITE;
72373 + }
72374 +#endif
72375 +
72376 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72377 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72378 + vm_flags &= ~VM_PAGEEXEC;
72379 +#endif
72380 +
72381 if (flags & MAP_LOCKED)
72382 if (!can_do_mlock())
72383 return -EPERM;
72384 @@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72385 locked += mm->locked_vm;
72386 lock_limit = rlimit(RLIMIT_MEMLOCK);
72387 lock_limit >>= PAGE_SHIFT;
72388 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72389 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72390 return -EAGAIN;
72391 }
72392 @@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72393 }
72394 }
72395
72396 + if (!gr_acl_handle_mmap(file, prot))
72397 + return -EACCES;
72398 +
72399 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72400 }
72401
72402 @@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72403 vm_flags_t vm_flags = vma->vm_flags;
72404
72405 /* If it was private or non-writable, the write bit is already clear */
72406 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72407 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72408 return 0;
72409
72410 /* The backer wishes to know when pages are first written to? */
72411 @@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72412 unsigned long charged = 0;
72413 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72414
72415 +#ifdef CONFIG_PAX_SEGMEXEC
72416 + struct vm_area_struct *vma_m = NULL;
72417 +#endif
72418 +
72419 + /*
72420 + * mm->mmap_sem is required to protect against another thread
72421 + * changing the mappings in case we sleep.
72422 + */
72423 + verify_mm_writelocked(mm);
72424 +
72425 /* Clear old maps */
72426 error = -ENOMEM;
72427 -munmap_back:
72428 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72429 if (vma && vma->vm_start < addr + len) {
72430 if (do_munmap(mm, addr, len))
72431 return -ENOMEM;
72432 - goto munmap_back;
72433 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72434 + BUG_ON(vma && vma->vm_start < addr + len);
72435 }
72436
72437 /* Check against address space limit. */
72438 @@ -1280,6 +1401,16 @@ munmap_back:
72439 goto unacct_error;
72440 }
72441
72442 +#ifdef CONFIG_PAX_SEGMEXEC
72443 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72444 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72445 + if (!vma_m) {
72446 + error = -ENOMEM;
72447 + goto free_vma;
72448 + }
72449 + }
72450 +#endif
72451 +
72452 vma->vm_mm = mm;
72453 vma->vm_start = addr;
72454 vma->vm_end = addr + len;
72455 @@ -1304,6 +1435,19 @@ munmap_back:
72456 error = file->f_op->mmap(file, vma);
72457 if (error)
72458 goto unmap_and_free_vma;
72459 +
72460 +#ifdef CONFIG_PAX_SEGMEXEC
72461 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72462 + added_exe_file_vma(mm);
72463 +#endif
72464 +
72465 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72466 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72467 + vma->vm_flags |= VM_PAGEEXEC;
72468 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72469 + }
72470 +#endif
72471 +
72472 if (vm_flags & VM_EXECUTABLE)
72473 added_exe_file_vma(mm);
72474
72475 @@ -1341,6 +1485,11 @@ munmap_back:
72476 vma_link(mm, vma, prev, rb_link, rb_parent);
72477 file = vma->vm_file;
72478
72479 +#ifdef CONFIG_PAX_SEGMEXEC
72480 + if (vma_m)
72481 + BUG_ON(pax_mirror_vma(vma_m, vma));
72482 +#endif
72483 +
72484 /* Once vma denies write, undo our temporary denial count */
72485 if (correct_wcount)
72486 atomic_inc(&inode->i_writecount);
72487 @@ -1349,6 +1498,7 @@ out:
72488
72489 mm->total_vm += len >> PAGE_SHIFT;
72490 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72491 + track_exec_limit(mm, addr, addr + len, vm_flags);
72492 if (vm_flags & VM_LOCKED) {
72493 if (!mlock_vma_pages_range(vma, addr, addr + len))
72494 mm->locked_vm += (len >> PAGE_SHIFT);
72495 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72496 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72497 charged = 0;
72498 free_vma:
72499 +
72500 +#ifdef CONFIG_PAX_SEGMEXEC
72501 + if (vma_m)
72502 + kmem_cache_free(vm_area_cachep, vma_m);
72503 +#endif
72504 +
72505 kmem_cache_free(vm_area_cachep, vma);
72506 unacct_error:
72507 if (charged)
72508 @@ -1378,6 +1534,44 @@ unacct_error:
72509 return error;
72510 }
72511
72512 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72513 +{
72514 + if (!vma) {
72515 +#ifdef CONFIG_STACK_GROWSUP
72516 + if (addr > sysctl_heap_stack_gap)
72517 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72518 + else
72519 + vma = find_vma(current->mm, 0);
72520 + if (vma && (vma->vm_flags & VM_GROWSUP))
72521 + return false;
72522 +#endif
72523 + return true;
72524 + }
72525 +
72526 + if (addr + len > vma->vm_start)
72527 + return false;
72528 +
72529 + if (vma->vm_flags & VM_GROWSDOWN)
72530 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72531 +#ifdef CONFIG_STACK_GROWSUP
72532 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72533 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72534 +#endif
72535 +
72536 + return true;
72537 +}
72538 +
72539 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72540 +{
72541 + if (vma->vm_start < len)
72542 + return -ENOMEM;
72543 + if (!(vma->vm_flags & VM_GROWSDOWN))
72544 + return vma->vm_start - len;
72545 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72546 + return vma->vm_start - len - sysctl_heap_stack_gap;
72547 + return -ENOMEM;
72548 +}
72549 +
72550 /* Get an address range which is currently unmapped.
72551 * For shmat() with addr=0.
72552 *
72553 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72554 if (flags & MAP_FIXED)
72555 return addr;
72556
72557 +#ifdef CONFIG_PAX_RANDMMAP
72558 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72559 +#endif
72560 +
72561 if (addr) {
72562 addr = PAGE_ALIGN(addr);
72563 - vma = find_vma(mm, addr);
72564 - if (TASK_SIZE - len >= addr &&
72565 - (!vma || addr + len <= vma->vm_start))
72566 - return addr;
72567 + if (TASK_SIZE - len >= addr) {
72568 + vma = find_vma(mm, addr);
72569 + if (check_heap_stack_gap(vma, addr, len))
72570 + return addr;
72571 + }
72572 }
72573 if (len > mm->cached_hole_size) {
72574 - start_addr = addr = mm->free_area_cache;
72575 + start_addr = addr = mm->free_area_cache;
72576 } else {
72577 - start_addr = addr = TASK_UNMAPPED_BASE;
72578 - mm->cached_hole_size = 0;
72579 + start_addr = addr = mm->mmap_base;
72580 + mm->cached_hole_size = 0;
72581 }
72582
72583 full_search:
72584 @@ -1426,34 +1625,40 @@ full_search:
72585 * Start a new search - just in case we missed
72586 * some holes.
72587 */
72588 - if (start_addr != TASK_UNMAPPED_BASE) {
72589 - addr = TASK_UNMAPPED_BASE;
72590 - start_addr = addr;
72591 + if (start_addr != mm->mmap_base) {
72592 + start_addr = addr = mm->mmap_base;
72593 mm->cached_hole_size = 0;
72594 goto full_search;
72595 }
72596 return -ENOMEM;
72597 }
72598 - if (!vma || addr + len <= vma->vm_start) {
72599 - /*
72600 - * Remember the place where we stopped the search:
72601 - */
72602 - mm->free_area_cache = addr + len;
72603 - return addr;
72604 - }
72605 + if (check_heap_stack_gap(vma, addr, len))
72606 + break;
72607 if (addr + mm->cached_hole_size < vma->vm_start)
72608 mm->cached_hole_size = vma->vm_start - addr;
72609 addr = vma->vm_end;
72610 }
72611 +
72612 + /*
72613 + * Remember the place where we stopped the search:
72614 + */
72615 + mm->free_area_cache = addr + len;
72616 + return addr;
72617 }
72618 #endif
72619
72620 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72621 {
72622 +
72623 +#ifdef CONFIG_PAX_SEGMEXEC
72624 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72625 + return;
72626 +#endif
72627 +
72628 /*
72629 * Is this a new hole at the lowest possible address?
72630 */
72631 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72632 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72633 mm->free_area_cache = addr;
72634 }
72635
72636 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72637 {
72638 struct vm_area_struct *vma;
72639 struct mm_struct *mm = current->mm;
72640 - unsigned long addr = addr0, start_addr;
72641 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72642
72643 /* requested length too big for entire address space */
72644 if (len > TASK_SIZE)
72645 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72646 if (flags & MAP_FIXED)
72647 return addr;
72648
72649 +#ifdef CONFIG_PAX_RANDMMAP
72650 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72651 +#endif
72652 +
72653 /* requesting a specific address */
72654 if (addr) {
72655 addr = PAGE_ALIGN(addr);
72656 - vma = find_vma(mm, addr);
72657 - if (TASK_SIZE - len >= addr &&
72658 - (!vma || addr + len <= vma->vm_start))
72659 - return addr;
72660 + if (TASK_SIZE - len >= addr) {
72661 + vma = find_vma(mm, addr);
72662 + if (check_heap_stack_gap(vma, addr, len))
72663 + return addr;
72664 + }
72665 }
72666
72667 /* check if free_area_cache is useful for us */
72668 @@ -1508,7 +1718,7 @@ try_again:
72669 * return with success:
72670 */
72671 vma = find_vma(mm, addr);
72672 - if (!vma || addr+len <= vma->vm_start)
72673 + if (check_heap_stack_gap(vma, addr, len))
72674 /* remember the address as a hint for next time */
72675 return (mm->free_area_cache = addr);
72676
72677 @@ -1517,8 +1727,8 @@ try_again:
72678 mm->cached_hole_size = vma->vm_start - addr;
72679
72680 /* try just below the current vma->vm_start */
72681 - addr = vma->vm_start-len;
72682 - } while (len < vma->vm_start);
72683 + addr = skip_heap_stack_gap(vma, len);
72684 + } while (!IS_ERR_VALUE(addr));
72685
72686 fail:
72687 /*
72688 @@ -1541,13 +1751,21 @@ fail:
72689 * can happen with large stack limits and large mmap()
72690 * allocations.
72691 */
72692 + mm->mmap_base = TASK_UNMAPPED_BASE;
72693 +
72694 +#ifdef CONFIG_PAX_RANDMMAP
72695 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72696 + mm->mmap_base += mm->delta_mmap;
72697 +#endif
72698 +
72699 + mm->free_area_cache = mm->mmap_base;
72700 mm->cached_hole_size = ~0UL;
72701 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72702 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72703 /*
72704 * Restore the topdown base:
72705 */
72706 - mm->free_area_cache = mm->mmap_base;
72707 + mm->mmap_base = base;
72708 + mm->free_area_cache = base;
72709 mm->cached_hole_size = ~0UL;
72710
72711 return addr;
72712 @@ -1556,6 +1774,12 @@ fail:
72713
72714 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72715 {
72716 +
72717 +#ifdef CONFIG_PAX_SEGMEXEC
72718 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72719 + return;
72720 +#endif
72721 +
72722 /*
72723 * Is this a new hole at the highest possible address?
72724 */
72725 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72726 mm->free_area_cache = addr;
72727
72728 /* dont allow allocations above current base */
72729 - if (mm->free_area_cache > mm->mmap_base)
72730 + if (mm->free_area_cache > mm->mmap_base) {
72731 mm->free_area_cache = mm->mmap_base;
72732 + mm->cached_hole_size = ~0UL;
72733 + }
72734 }
72735
72736 unsigned long
72737 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72738 return vma;
72739 }
72740
72741 +#ifdef CONFIG_PAX_SEGMEXEC
72742 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72743 +{
72744 + struct vm_area_struct *vma_m;
72745 +
72746 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72747 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72748 + BUG_ON(vma->vm_mirror);
72749 + return NULL;
72750 + }
72751 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72752 + vma_m = vma->vm_mirror;
72753 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72754 + BUG_ON(vma->vm_file != vma_m->vm_file);
72755 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72756 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72757 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72758 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72759 + return vma_m;
72760 +}
72761 +#endif
72762 +
72763 /*
72764 * Verify that the stack growth is acceptable and
72765 * update accounting. This is shared with both the
72766 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72767 return -ENOMEM;
72768
72769 /* Stack limit test */
72770 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72771 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72772 return -ENOMEM;
72773
72774 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72775 locked = mm->locked_vm + grow;
72776 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72777 limit >>= PAGE_SHIFT;
72778 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72779 if (locked > limit && !capable(CAP_IPC_LOCK))
72780 return -ENOMEM;
72781 }
72782 @@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72783 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72784 * vma is the last one with address > vma->vm_end. Have to extend vma.
72785 */
72786 +#ifndef CONFIG_IA64
72787 +static
72788 +#endif
72789 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72790 {
72791 int error;
72792 + bool locknext;
72793
72794 if (!(vma->vm_flags & VM_GROWSUP))
72795 return -EFAULT;
72796
72797 + /* Also guard against wrapping around to address 0. */
72798 + if (address < PAGE_ALIGN(address+1))
72799 + address = PAGE_ALIGN(address+1);
72800 + else
72801 + return -ENOMEM;
72802 +
72803 /*
72804 * We must make sure the anon_vma is allocated
72805 * so that the anon_vma locking is not a noop.
72806 */
72807 if (unlikely(anon_vma_prepare(vma)))
72808 return -ENOMEM;
72809 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72810 + if (locknext && anon_vma_prepare(vma->vm_next))
72811 + return -ENOMEM;
72812 vma_lock_anon_vma(vma);
72813 + if (locknext)
72814 + vma_lock_anon_vma(vma->vm_next);
72815
72816 /*
72817 * vma->vm_start/vm_end cannot change under us because the caller
72818 * is required to hold the mmap_sem in read mode. We need the
72819 - * anon_vma lock to serialize against concurrent expand_stacks.
72820 - * Also guard against wrapping around to address 0.
72821 + * anon_vma locks to serialize against concurrent expand_stacks
72822 + * and expand_upwards.
72823 */
72824 - if (address < PAGE_ALIGN(address+4))
72825 - address = PAGE_ALIGN(address+4);
72826 - else {
72827 - vma_unlock_anon_vma(vma);
72828 - return -ENOMEM;
72829 - }
72830 error = 0;
72831
72832 /* Somebody else might have raced and expanded it already */
72833 - if (address > vma->vm_end) {
72834 + 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)
72835 + error = -ENOMEM;
72836 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72837 unsigned long size, grow;
72838
72839 size = address - vma->vm_start;
72840 @@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72841 }
72842 }
72843 }
72844 + if (locknext)
72845 + vma_unlock_anon_vma(vma->vm_next);
72846 vma_unlock_anon_vma(vma);
72847 khugepaged_enter_vma_merge(vma);
72848 return error;
72849 @@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72850 unsigned long address)
72851 {
72852 int error;
72853 + bool lockprev = false;
72854 + struct vm_area_struct *prev;
72855
72856 /*
72857 * We must make sure the anon_vma is allocated
72858 @@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72859 if (error)
72860 return error;
72861
72862 + prev = vma->vm_prev;
72863 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72864 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72865 +#endif
72866 + if (lockprev && anon_vma_prepare(prev))
72867 + return -ENOMEM;
72868 + if (lockprev)
72869 + vma_lock_anon_vma(prev);
72870 +
72871 vma_lock_anon_vma(vma);
72872
72873 /*
72874 @@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72875 */
72876
72877 /* Somebody else might have raced and expanded it already */
72878 - if (address < vma->vm_start) {
72879 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72880 + error = -ENOMEM;
72881 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72882 unsigned long size, grow;
72883
72884 +#ifdef CONFIG_PAX_SEGMEXEC
72885 + struct vm_area_struct *vma_m;
72886 +
72887 + vma_m = pax_find_mirror_vma(vma);
72888 +#endif
72889 +
72890 size = vma->vm_end - address;
72891 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72892
72893 @@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72894 if (!error) {
72895 vma->vm_start = address;
72896 vma->vm_pgoff -= grow;
72897 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72898 +
72899 +#ifdef CONFIG_PAX_SEGMEXEC
72900 + if (vma_m) {
72901 + vma_m->vm_start -= grow << PAGE_SHIFT;
72902 + vma_m->vm_pgoff -= grow;
72903 + }
72904 +#endif
72905 +
72906 perf_event_mmap(vma);
72907 }
72908 }
72909 }
72910 vma_unlock_anon_vma(vma);
72911 + if (lockprev)
72912 + vma_unlock_anon_vma(prev);
72913 khugepaged_enter_vma_merge(vma);
72914 return error;
72915 }
72916 @@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72917 do {
72918 long nrpages = vma_pages(vma);
72919
72920 +#ifdef CONFIG_PAX_SEGMEXEC
72921 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72922 + vma = remove_vma(vma);
72923 + continue;
72924 + }
72925 +#endif
72926 +
72927 if (vma->vm_flags & VM_ACCOUNT)
72928 nr_accounted += nrpages;
72929 mm->total_vm -= nrpages;
72930 @@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72931 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72932 vma->vm_prev = NULL;
72933 do {
72934 +
72935 +#ifdef CONFIG_PAX_SEGMEXEC
72936 + if (vma->vm_mirror) {
72937 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72938 + vma->vm_mirror->vm_mirror = NULL;
72939 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72940 + vma->vm_mirror = NULL;
72941 + }
72942 +#endif
72943 +
72944 rb_erase(&vma->vm_rb, &mm->mm_rb);
72945 mm->map_count--;
72946 tail_vma = vma;
72947 @@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72948 struct vm_area_struct *new;
72949 int err = -ENOMEM;
72950
72951 +#ifdef CONFIG_PAX_SEGMEXEC
72952 + struct vm_area_struct *vma_m, *new_m = NULL;
72953 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72954 +#endif
72955 +
72956 if (is_vm_hugetlb_page(vma) && (addr &
72957 ~(huge_page_mask(hstate_vma(vma)))))
72958 return -EINVAL;
72959
72960 +#ifdef CONFIG_PAX_SEGMEXEC
72961 + vma_m = pax_find_mirror_vma(vma);
72962 +#endif
72963 +
72964 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72965 if (!new)
72966 goto out_err;
72967
72968 +#ifdef CONFIG_PAX_SEGMEXEC
72969 + if (vma_m) {
72970 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72971 + if (!new_m) {
72972 + kmem_cache_free(vm_area_cachep, new);
72973 + goto out_err;
72974 + }
72975 + }
72976 +#endif
72977 +
72978 /* most fields are the same, copy all, and then fixup */
72979 *new = *vma;
72980
72981 @@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72982 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72983 }
72984
72985 +#ifdef CONFIG_PAX_SEGMEXEC
72986 + if (vma_m) {
72987 + *new_m = *vma_m;
72988 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72989 + new_m->vm_mirror = new;
72990 + new->vm_mirror = new_m;
72991 +
72992 + if (new_below)
72993 + new_m->vm_end = addr_m;
72994 + else {
72995 + new_m->vm_start = addr_m;
72996 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72997 + }
72998 + }
72999 +#endif
73000 +
73001 pol = mpol_dup(vma_policy(vma));
73002 if (IS_ERR(pol)) {
73003 err = PTR_ERR(pol);
73004 @@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73005 else
73006 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73007
73008 +#ifdef CONFIG_PAX_SEGMEXEC
73009 + if (!err && vma_m) {
73010 + if (anon_vma_clone(new_m, vma_m))
73011 + goto out_free_mpol;
73012 +
73013 + mpol_get(pol);
73014 + vma_set_policy(new_m, pol);
73015 +
73016 + if (new_m->vm_file) {
73017 + get_file(new_m->vm_file);
73018 + if (vma_m->vm_flags & VM_EXECUTABLE)
73019 + added_exe_file_vma(mm);
73020 + }
73021 +
73022 + if (new_m->vm_ops && new_m->vm_ops->open)
73023 + new_m->vm_ops->open(new_m);
73024 +
73025 + if (new_below)
73026 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73027 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73028 + else
73029 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73030 +
73031 + if (err) {
73032 + if (new_m->vm_ops && new_m->vm_ops->close)
73033 + new_m->vm_ops->close(new_m);
73034 + if (new_m->vm_file) {
73035 + if (vma_m->vm_flags & VM_EXECUTABLE)
73036 + removed_exe_file_vma(mm);
73037 + fput(new_m->vm_file);
73038 + }
73039 + mpol_put(pol);
73040 + }
73041 + }
73042 +#endif
73043 +
73044 /* Success. */
73045 if (!err)
73046 return 0;
73047 @@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73048 removed_exe_file_vma(mm);
73049 fput(new->vm_file);
73050 }
73051 - unlink_anon_vmas(new);
73052 out_free_mpol:
73053 mpol_put(pol);
73054 out_free_vma:
73055 +
73056 +#ifdef CONFIG_PAX_SEGMEXEC
73057 + if (new_m) {
73058 + unlink_anon_vmas(new_m);
73059 + kmem_cache_free(vm_area_cachep, new_m);
73060 + }
73061 +#endif
73062 +
73063 + unlink_anon_vmas(new);
73064 kmem_cache_free(vm_area_cachep, new);
73065 out_err:
73066 return err;
73067 @@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73068 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73069 unsigned long addr, int new_below)
73070 {
73071 +
73072 +#ifdef CONFIG_PAX_SEGMEXEC
73073 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73074 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73075 + if (mm->map_count >= sysctl_max_map_count-1)
73076 + return -ENOMEM;
73077 + } else
73078 +#endif
73079 +
73080 if (mm->map_count >= sysctl_max_map_count)
73081 return -ENOMEM;
73082
73083 @@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73084 * work. This now handles partial unmappings.
73085 * Jeremy Fitzhardinge <jeremy@goop.org>
73086 */
73087 +#ifdef CONFIG_PAX_SEGMEXEC
73088 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73089 {
73090 + int ret = __do_munmap(mm, start, len);
73091 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73092 + return ret;
73093 +
73094 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73095 +}
73096 +
73097 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73098 +#else
73099 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73100 +#endif
73101 +{
73102 unsigned long end;
73103 struct vm_area_struct *vma, *prev, *last;
73104
73105 + /*
73106 + * mm->mmap_sem is required to protect against another thread
73107 + * changing the mappings in case we sleep.
73108 + */
73109 + verify_mm_writelocked(mm);
73110 +
73111 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73112 return -EINVAL;
73113
73114 @@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73115 /* Fix up all other VM information */
73116 remove_vma_list(mm, vma);
73117
73118 + track_exec_limit(mm, start, end, 0UL);
73119 +
73120 return 0;
73121 }
73122
73123 @@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
73124 int ret;
73125 struct mm_struct *mm = current->mm;
73126
73127 +
73128 +#ifdef CONFIG_PAX_SEGMEXEC
73129 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73130 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73131 + return -EINVAL;
73132 +#endif
73133 +
73134 down_write(&mm->mmap_sem);
73135 ret = do_munmap(mm, start, len);
73136 up_write(&mm->mmap_sem);
73137 @@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73138 return vm_munmap(addr, len);
73139 }
73140
73141 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73142 -{
73143 -#ifdef CONFIG_DEBUG_VM
73144 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73145 - WARN_ON(1);
73146 - up_read(&mm->mmap_sem);
73147 - }
73148 -#endif
73149 -}
73150 -
73151 /*
73152 * this is really a simplified "do_mmap". it only handles
73153 * anonymous maps. eventually we may be able to do some
73154 @@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73155 struct rb_node ** rb_link, * rb_parent;
73156 pgoff_t pgoff = addr >> PAGE_SHIFT;
73157 int error;
73158 + unsigned long charged;
73159
73160 len = PAGE_ALIGN(len);
73161 if (!len)
73162 @@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73163
73164 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73165
73166 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73167 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73168 + flags &= ~VM_EXEC;
73169 +
73170 +#ifdef CONFIG_PAX_MPROTECT
73171 + if (mm->pax_flags & MF_PAX_MPROTECT)
73172 + flags &= ~VM_MAYEXEC;
73173 +#endif
73174 +
73175 + }
73176 +#endif
73177 +
73178 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73179 if (error & ~PAGE_MASK)
73180 return error;
73181
73182 + charged = len >> PAGE_SHIFT;
73183 +
73184 /*
73185 * mlock MCL_FUTURE?
73186 */
73187 if (mm->def_flags & VM_LOCKED) {
73188 unsigned long locked, lock_limit;
73189 - locked = len >> PAGE_SHIFT;
73190 + locked = charged;
73191 locked += mm->locked_vm;
73192 lock_limit = rlimit(RLIMIT_MEMLOCK);
73193 lock_limit >>= PAGE_SHIFT;
73194 @@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73195 /*
73196 * Clear old maps. this also does some error checking for us
73197 */
73198 - munmap_back:
73199 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73200 if (vma && vma->vm_start < addr + len) {
73201 if (do_munmap(mm, addr, len))
73202 return -ENOMEM;
73203 - goto munmap_back;
73204 - }
73205 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73206 + BUG_ON(vma && vma->vm_start < addr + len);
73207 + }
73208
73209 /* Check against address space limits *after* clearing old maps... */
73210 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73211 + if (!may_expand_vm(mm, charged))
73212 return -ENOMEM;
73213
73214 if (mm->map_count > sysctl_max_map_count)
73215 return -ENOMEM;
73216
73217 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73218 + if (security_vm_enough_memory_mm(mm, charged))
73219 return -ENOMEM;
73220
73221 /* Can we just expand an old private anonymous mapping? */
73222 @@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73223 */
73224 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73225 if (!vma) {
73226 - vm_unacct_memory(len >> PAGE_SHIFT);
73227 + vm_unacct_memory(charged);
73228 return -ENOMEM;
73229 }
73230
73231 @@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73232 vma_link(mm, vma, prev, rb_link, rb_parent);
73233 out:
73234 perf_event_mmap(vma);
73235 - mm->total_vm += len >> PAGE_SHIFT;
73236 + mm->total_vm += charged;
73237 if (flags & VM_LOCKED) {
73238 if (!mlock_vma_pages_range(vma, addr, addr + len))
73239 - mm->locked_vm += (len >> PAGE_SHIFT);
73240 + mm->locked_vm += charged;
73241 }
73242 + track_exec_limit(mm, addr, addr + len, flags);
73243 return addr;
73244 }
73245
73246 @@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
73247 while (vma) {
73248 if (vma->vm_flags & VM_ACCOUNT)
73249 nr_accounted += vma_pages(vma);
73250 + vma->vm_mirror = NULL;
73251 vma = remove_vma(vma);
73252 }
73253 vm_unacct_memory(nr_accounted);
73254 @@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73255 struct vm_area_struct * __vma, * prev;
73256 struct rb_node ** rb_link, * rb_parent;
73257
73258 +#ifdef CONFIG_PAX_SEGMEXEC
73259 + struct vm_area_struct *vma_m = NULL;
73260 +#endif
73261 +
73262 + if (security_mmap_addr(vma->vm_start))
73263 + return -EPERM;
73264 +
73265 /*
73266 * The vm_pgoff of a purely anonymous vma should be irrelevant
73267 * until its first write fault, when page's anon_vma and index
73268 @@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73269 if (vma->vm_file && uprobe_mmap(vma))
73270 return -EINVAL;
73271
73272 +#ifdef CONFIG_PAX_SEGMEXEC
73273 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73274 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73275 + if (!vma_m)
73276 + return -ENOMEM;
73277 + }
73278 +#endif
73279 +
73280 vma_link(mm, vma, prev, rb_link, rb_parent);
73281 +
73282 +#ifdef CONFIG_PAX_SEGMEXEC
73283 + if (vma_m)
73284 + BUG_ON(pax_mirror_vma(vma_m, vma));
73285 +#endif
73286 +
73287 return 0;
73288 }
73289
73290 @@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73291 struct mempolicy *pol;
73292 bool faulted_in_anon_vma = true;
73293
73294 + BUG_ON(vma->vm_mirror);
73295 +
73296 /*
73297 * If anonymous vma has not yet been faulted, update new pgoff
73298 * to match new location, to increase its chance of merging.
73299 @@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73300 return NULL;
73301 }
73302
73303 +#ifdef CONFIG_PAX_SEGMEXEC
73304 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73305 +{
73306 + struct vm_area_struct *prev_m;
73307 + struct rb_node **rb_link_m, *rb_parent_m;
73308 + struct mempolicy *pol_m;
73309 +
73310 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73311 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73312 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73313 + *vma_m = *vma;
73314 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73315 + if (anon_vma_clone(vma_m, vma))
73316 + return -ENOMEM;
73317 + pol_m = vma_policy(vma_m);
73318 + mpol_get(pol_m);
73319 + vma_set_policy(vma_m, pol_m);
73320 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73321 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73322 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73323 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73324 + if (vma_m->vm_file)
73325 + get_file(vma_m->vm_file);
73326 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73327 + vma_m->vm_ops->open(vma_m);
73328 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73329 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73330 + vma_m->vm_mirror = vma;
73331 + vma->vm_mirror = vma_m;
73332 + return 0;
73333 +}
73334 +#endif
73335 +
73336 /*
73337 * Return true if the calling process may expand its vm space by the passed
73338 * number of pages
73339 @@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73340
73341 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73342
73343 +#ifdef CONFIG_PAX_RANDMMAP
73344 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73345 + cur -= mm->brk_gap;
73346 +#endif
73347 +
73348 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73349 if (cur + npages > lim)
73350 return 0;
73351 return 1;
73352 @@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73353 vma->vm_start = addr;
73354 vma->vm_end = addr + len;
73355
73356 +#ifdef CONFIG_PAX_MPROTECT
73357 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73358 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73359 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73360 + return -EPERM;
73361 + if (!(vm_flags & VM_EXEC))
73362 + vm_flags &= ~VM_MAYEXEC;
73363 +#else
73364 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73365 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73366 +#endif
73367 + else
73368 + vm_flags &= ~VM_MAYWRITE;
73369 + }
73370 +#endif
73371 +
73372 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73373 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73374
73375 diff --git a/mm/mprotect.c b/mm/mprotect.c
73376 index a409926..8b32e6d 100644
73377 --- a/mm/mprotect.c
73378 +++ b/mm/mprotect.c
73379 @@ -23,10 +23,17 @@
73380 #include <linux/mmu_notifier.h>
73381 #include <linux/migrate.h>
73382 #include <linux/perf_event.h>
73383 +
73384 +#ifdef CONFIG_PAX_MPROTECT
73385 +#include <linux/elf.h>
73386 +#include <linux/binfmts.h>
73387 +#endif
73388 +
73389 #include <asm/uaccess.h>
73390 #include <asm/pgtable.h>
73391 #include <asm/cacheflush.h>
73392 #include <asm/tlbflush.h>
73393 +#include <asm/mmu_context.h>
73394
73395 #ifndef pgprot_modify
73396 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73397 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73398 flush_tlb_range(vma, start, end);
73399 }
73400
73401 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73402 +/* called while holding the mmap semaphor for writing except stack expansion */
73403 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73404 +{
73405 + unsigned long oldlimit, newlimit = 0UL;
73406 +
73407 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73408 + return;
73409 +
73410 + spin_lock(&mm->page_table_lock);
73411 + oldlimit = mm->context.user_cs_limit;
73412 + if ((prot & VM_EXEC) && oldlimit < end)
73413 + /* USER_CS limit moved up */
73414 + newlimit = end;
73415 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73416 + /* USER_CS limit moved down */
73417 + newlimit = start;
73418 +
73419 + if (newlimit) {
73420 + mm->context.user_cs_limit = newlimit;
73421 +
73422 +#ifdef CONFIG_SMP
73423 + wmb();
73424 + cpus_clear(mm->context.cpu_user_cs_mask);
73425 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73426 +#endif
73427 +
73428 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73429 + }
73430 + spin_unlock(&mm->page_table_lock);
73431 + if (newlimit == end) {
73432 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73433 +
73434 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73435 + if (is_vm_hugetlb_page(vma))
73436 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73437 + else
73438 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73439 + }
73440 +}
73441 +#endif
73442 +
73443 int
73444 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73445 unsigned long start, unsigned long end, unsigned long newflags)
73446 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73447 int error;
73448 int dirty_accountable = 0;
73449
73450 +#ifdef CONFIG_PAX_SEGMEXEC
73451 + struct vm_area_struct *vma_m = NULL;
73452 + unsigned long start_m, end_m;
73453 +
73454 + start_m = start + SEGMEXEC_TASK_SIZE;
73455 + end_m = end + SEGMEXEC_TASK_SIZE;
73456 +#endif
73457 +
73458 if (newflags == oldflags) {
73459 *pprev = vma;
73460 return 0;
73461 }
73462
73463 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73464 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73465 +
73466 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73467 + return -ENOMEM;
73468 +
73469 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73470 + return -ENOMEM;
73471 + }
73472 +
73473 /*
73474 * If we make a private mapping writable we increase our commit;
73475 * but (without finer accounting) cannot reduce our commit if we
73476 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73477 }
73478 }
73479
73480 +#ifdef CONFIG_PAX_SEGMEXEC
73481 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73482 + if (start != vma->vm_start) {
73483 + error = split_vma(mm, vma, start, 1);
73484 + if (error)
73485 + goto fail;
73486 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73487 + *pprev = (*pprev)->vm_next;
73488 + }
73489 +
73490 + if (end != vma->vm_end) {
73491 + error = split_vma(mm, vma, end, 0);
73492 + if (error)
73493 + goto fail;
73494 + }
73495 +
73496 + if (pax_find_mirror_vma(vma)) {
73497 + error = __do_munmap(mm, start_m, end_m - start_m);
73498 + if (error)
73499 + goto fail;
73500 + } else {
73501 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73502 + if (!vma_m) {
73503 + error = -ENOMEM;
73504 + goto fail;
73505 + }
73506 + vma->vm_flags = newflags;
73507 + error = pax_mirror_vma(vma_m, vma);
73508 + if (error) {
73509 + vma->vm_flags = oldflags;
73510 + goto fail;
73511 + }
73512 + }
73513 + }
73514 +#endif
73515 +
73516 /*
73517 * First try to merge with previous and/or next vma.
73518 */
73519 @@ -204,9 +307,21 @@ success:
73520 * vm_flags and vm_page_prot are protected by the mmap_sem
73521 * held in write mode.
73522 */
73523 +
73524 +#ifdef CONFIG_PAX_SEGMEXEC
73525 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73526 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73527 +#endif
73528 +
73529 vma->vm_flags = newflags;
73530 +
73531 +#ifdef CONFIG_PAX_MPROTECT
73532 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73533 + mm->binfmt->handle_mprotect(vma, newflags);
73534 +#endif
73535 +
73536 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73537 - vm_get_page_prot(newflags));
73538 + vm_get_page_prot(vma->vm_flags));
73539
73540 if (vma_wants_writenotify(vma)) {
73541 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73542 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73543 end = start + len;
73544 if (end <= start)
73545 return -ENOMEM;
73546 +
73547 +#ifdef CONFIG_PAX_SEGMEXEC
73548 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73549 + if (end > SEGMEXEC_TASK_SIZE)
73550 + return -EINVAL;
73551 + } else
73552 +#endif
73553 +
73554 + if (end > TASK_SIZE)
73555 + return -EINVAL;
73556 +
73557 if (!arch_validate_prot(prot))
73558 return -EINVAL;
73559
73560 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73561 /*
73562 * Does the application expect PROT_READ to imply PROT_EXEC:
73563 */
73564 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73565 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73566 prot |= PROT_EXEC;
73567
73568 vm_flags = calc_vm_prot_bits(prot);
73569 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73570 if (start > vma->vm_start)
73571 prev = vma;
73572
73573 +#ifdef CONFIG_PAX_MPROTECT
73574 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73575 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73576 +#endif
73577 +
73578 for (nstart = start ; ; ) {
73579 unsigned long newflags;
73580
73581 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73582
73583 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73584 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73585 + if (prot & (PROT_WRITE | PROT_EXEC))
73586 + gr_log_rwxmprotect(vma->vm_file);
73587 +
73588 + error = -EACCES;
73589 + goto out;
73590 + }
73591 +
73592 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73593 error = -EACCES;
73594 goto out;
73595 }
73596 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73597 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73598 if (error)
73599 goto out;
73600 +
73601 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73602 +
73603 nstart = tmp;
73604
73605 if (nstart < prev->vm_end)
73606 diff --git a/mm/mremap.c b/mm/mremap.c
73607 index 21fed20..6822658 100644
73608 --- a/mm/mremap.c
73609 +++ b/mm/mremap.c
73610 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73611 continue;
73612 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73613 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73614 +
73615 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73616 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73617 + pte = pte_exprotect(pte);
73618 +#endif
73619 +
73620 set_pte_at(mm, new_addr, new_pte, pte);
73621 }
73622
73623 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73624 if (is_vm_hugetlb_page(vma))
73625 goto Einval;
73626
73627 +#ifdef CONFIG_PAX_SEGMEXEC
73628 + if (pax_find_mirror_vma(vma))
73629 + goto Einval;
73630 +#endif
73631 +
73632 /* We can't remap across vm area boundaries */
73633 if (old_len > vma->vm_end - addr)
73634 goto Efault;
73635 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73636 unsigned long ret = -EINVAL;
73637 unsigned long charged = 0;
73638 unsigned long map_flags;
73639 + unsigned long pax_task_size = TASK_SIZE;
73640
73641 if (new_addr & ~PAGE_MASK)
73642 goto out;
73643
73644 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73645 +#ifdef CONFIG_PAX_SEGMEXEC
73646 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73647 + pax_task_size = SEGMEXEC_TASK_SIZE;
73648 +#endif
73649 +
73650 + pax_task_size -= PAGE_SIZE;
73651 +
73652 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73653 goto out;
73654
73655 /* Check if the location we're moving into overlaps the
73656 * old location at all, and fail if it does.
73657 */
73658 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73659 - goto out;
73660 -
73661 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73662 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73663 goto out;
73664
73665 ret = do_munmap(mm, new_addr, new_len);
73666 @@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73667 struct vm_area_struct *vma;
73668 unsigned long ret = -EINVAL;
73669 unsigned long charged = 0;
73670 + unsigned long pax_task_size = TASK_SIZE;
73671
73672 down_write(&current->mm->mmap_sem);
73673
73674 @@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73675 if (!new_len)
73676 goto out;
73677
73678 +#ifdef CONFIG_PAX_SEGMEXEC
73679 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73680 + pax_task_size = SEGMEXEC_TASK_SIZE;
73681 +#endif
73682 +
73683 + pax_task_size -= PAGE_SIZE;
73684 +
73685 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73686 + old_len > pax_task_size || addr > pax_task_size-old_len)
73687 + goto out;
73688 +
73689 if (flags & MREMAP_FIXED) {
73690 if (flags & MREMAP_MAYMOVE)
73691 ret = mremap_to(addr, old_len, new_addr, new_len);
73692 @@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73693 addr + new_len);
73694 }
73695 ret = addr;
73696 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73697 goto out;
73698 }
73699 }
73700 @@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73701 goto out;
73702 }
73703
73704 + map_flags = vma->vm_flags;
73705 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73706 + if (!(ret & ~PAGE_MASK)) {
73707 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73708 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73709 + }
73710 }
73711 out:
73712 if (ret & ~PAGE_MASK)
73713 diff --git a/mm/nommu.c b/mm/nommu.c
73714 index d4b0c10..ed421b5 100644
73715 --- a/mm/nommu.c
73716 +++ b/mm/nommu.c
73717 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73718 int sysctl_overcommit_ratio = 50; /* default is 50% */
73719 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73720 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73721 -int heap_stack_gap = 0;
73722
73723 atomic_long_t mmap_pages_allocated;
73724
73725 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73726 EXPORT_SYMBOL(find_vma);
73727
73728 /*
73729 - * find a VMA
73730 - * - we don't extend stack VMAs under NOMMU conditions
73731 - */
73732 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73733 -{
73734 - return find_vma(mm, addr);
73735 -}
73736 -
73737 -/*
73738 * expand a stack to a given address
73739 * - not supported under NOMMU conditions
73740 */
73741 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73742
73743 /* most fields are the same, copy all, and then fixup */
73744 *new = *vma;
73745 + INIT_LIST_HEAD(&new->anon_vma_chain);
73746 *region = *vma->vm_region;
73747 new->vm_region = region;
73748
73749 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73750 index 201b508..1fb51ca 100644
73751 --- a/mm/page_alloc.c
73752 +++ b/mm/page_alloc.c
73753 @@ -336,7 +336,7 @@ out:
73754 * This usage means that zero-order pages may not be compound.
73755 */
73756
73757 -static void free_compound_page(struct page *page)
73758 +void free_compound_page(struct page *page)
73759 {
73760 __free_pages_ok(page, compound_order(page));
73761 }
73762 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73763 int i;
73764 int bad = 0;
73765
73766 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73767 + unsigned long index = 1UL << order;
73768 +#endif
73769 +
73770 trace_mm_page_free(page, order);
73771 kmemcheck_free_shadow(page, order);
73772
73773 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73774 debug_check_no_obj_freed(page_address(page),
73775 PAGE_SIZE << order);
73776 }
73777 +
73778 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73779 + for (; index; --index)
73780 + sanitize_highpage(page + index - 1);
73781 +#endif
73782 +
73783 arch_free_page(page, order);
73784 kernel_map_pages(page, 1 << order, 0);
73785
73786 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73787 arch_alloc_page(page, order);
73788 kernel_map_pages(page, 1 << order, 1);
73789
73790 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73791 if (gfp_flags & __GFP_ZERO)
73792 prep_zero_page(page, order, gfp_flags);
73793 +#endif
73794
73795 if (order && (gfp_flags & __GFP_COMP))
73796 prep_compound_page(page, order);
73797 @@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73798 unsigned long pfn;
73799
73800 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73801 +#ifdef CONFIG_X86_32
73802 + /* boot failures in VMware 8 on 32bit vanilla since
73803 + this change */
73804 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73805 +#else
73806 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73807 +#endif
73808 return 1;
73809 }
73810 return 0;
73811 diff --git a/mm/percpu.c b/mm/percpu.c
73812 index bb4be74..a43ea85 100644
73813 --- a/mm/percpu.c
73814 +++ b/mm/percpu.c
73815 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73816 static unsigned int pcpu_high_unit_cpu __read_mostly;
73817
73818 /* the address of the first chunk which starts with the kernel static area */
73819 -void *pcpu_base_addr __read_mostly;
73820 +void *pcpu_base_addr __read_only;
73821 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73822
73823 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73824 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73825 index 926b466..b23df53 100644
73826 --- a/mm/process_vm_access.c
73827 +++ b/mm/process_vm_access.c
73828 @@ -13,6 +13,7 @@
73829 #include <linux/uio.h>
73830 #include <linux/sched.h>
73831 #include <linux/highmem.h>
73832 +#include <linux/security.h>
73833 #include <linux/ptrace.h>
73834 #include <linux/slab.h>
73835 #include <linux/syscalls.h>
73836 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73837 size_t iov_l_curr_offset = 0;
73838 ssize_t iov_len;
73839
73840 + return -ENOSYS; // PaX: until properly audited
73841 +
73842 /*
73843 * Work out how many pages of struct pages we're going to need
73844 * when eventually calling get_user_pages
73845 */
73846 for (i = 0; i < riovcnt; i++) {
73847 iov_len = rvec[i].iov_len;
73848 - if (iov_len > 0) {
73849 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73850 - + iov_len)
73851 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73852 - / PAGE_SIZE + 1;
73853 - nr_pages = max(nr_pages, nr_pages_iov);
73854 - }
73855 + if (iov_len <= 0)
73856 + continue;
73857 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73858 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73859 + nr_pages = max(nr_pages, nr_pages_iov);
73860 }
73861
73862 if (nr_pages == 0)
73863 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73864 goto free_proc_pages;
73865 }
73866
73867 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73868 + rc = -EPERM;
73869 + goto put_task_struct;
73870 + }
73871 +
73872 mm = mm_access(task, PTRACE_MODE_ATTACH);
73873 if (!mm || IS_ERR(mm)) {
73874 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73875 diff --git a/mm/rmap.c b/mm/rmap.c
73876 index 0f3b7cd..c5652b6 100644
73877 --- a/mm/rmap.c
73878 +++ b/mm/rmap.c
73879 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73880 struct anon_vma *anon_vma = vma->anon_vma;
73881 struct anon_vma_chain *avc;
73882
73883 +#ifdef CONFIG_PAX_SEGMEXEC
73884 + struct anon_vma_chain *avc_m = NULL;
73885 +#endif
73886 +
73887 might_sleep();
73888 if (unlikely(!anon_vma)) {
73889 struct mm_struct *mm = vma->vm_mm;
73890 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73891 if (!avc)
73892 goto out_enomem;
73893
73894 +#ifdef CONFIG_PAX_SEGMEXEC
73895 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73896 + if (!avc_m)
73897 + goto out_enomem_free_avc;
73898 +#endif
73899 +
73900 anon_vma = find_mergeable_anon_vma(vma);
73901 allocated = NULL;
73902 if (!anon_vma) {
73903 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73904 /* page_table_lock to protect against threads */
73905 spin_lock(&mm->page_table_lock);
73906 if (likely(!vma->anon_vma)) {
73907 +
73908 +#ifdef CONFIG_PAX_SEGMEXEC
73909 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73910 +
73911 + if (vma_m) {
73912 + BUG_ON(vma_m->anon_vma);
73913 + vma_m->anon_vma = anon_vma;
73914 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
73915 + avc_m = NULL;
73916 + }
73917 +#endif
73918 +
73919 vma->anon_vma = anon_vma;
73920 anon_vma_chain_link(vma, avc, anon_vma);
73921 allocated = NULL;
73922 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73923
73924 if (unlikely(allocated))
73925 put_anon_vma(allocated);
73926 +
73927 +#ifdef CONFIG_PAX_SEGMEXEC
73928 + if (unlikely(avc_m))
73929 + anon_vma_chain_free(avc_m);
73930 +#endif
73931 +
73932 if (unlikely(avc))
73933 anon_vma_chain_free(avc);
73934 }
73935 return 0;
73936
73937 out_enomem_free_avc:
73938 +
73939 +#ifdef CONFIG_PAX_SEGMEXEC
73940 + if (avc_m)
73941 + anon_vma_chain_free(avc_m);
73942 +#endif
73943 +
73944 anon_vma_chain_free(avc);
73945 out_enomem:
73946 return -ENOMEM;
73947 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73948 * Attach the anon_vmas from src to dst.
73949 * Returns 0 on success, -ENOMEM on failure.
73950 */
73951 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73952 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73953 {
73954 struct anon_vma_chain *avc, *pavc;
73955 struct anon_vma *root = NULL;
73956 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73957 * the corresponding VMA in the parent process is attached to.
73958 * Returns 0 on success, non-zero on failure.
73959 */
73960 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73961 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73962 {
73963 struct anon_vma_chain *avc;
73964 struct anon_vma *anon_vma;
73965 diff --git a/mm/shmem.c b/mm/shmem.c
73966 index bd10636..5c16d49 100644
73967 --- a/mm/shmem.c
73968 +++ b/mm/shmem.c
73969 @@ -31,7 +31,7 @@
73970 #include <linux/export.h>
73971 #include <linux/swap.h>
73972
73973 -static struct vfsmount *shm_mnt;
73974 +struct vfsmount *shm_mnt;
73975
73976 #ifdef CONFIG_SHMEM
73977 /*
73978 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73979 #define BOGO_DIRENT_SIZE 20
73980
73981 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73982 -#define SHORT_SYMLINK_LEN 128
73983 +#define SHORT_SYMLINK_LEN 64
73984
73985 struct shmem_xattr {
73986 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73987 @@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73988 int err = -ENOMEM;
73989
73990 /* Round up to L1_CACHE_BYTES to resist false sharing */
73991 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73992 - L1_CACHE_BYTES), GFP_KERNEL);
73993 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73994 if (!sbinfo)
73995 return -ENOMEM;
73996
73997 diff --git a/mm/slab.c b/mm/slab.c
73998 index e901a36..9ff3f90 100644
73999 --- a/mm/slab.c
74000 +++ b/mm/slab.c
74001 @@ -153,7 +153,7 @@
74002
74003 /* Legal flag mask for kmem_cache_create(). */
74004 #if DEBUG
74005 -# define CREATE_MASK (SLAB_RED_ZONE | \
74006 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74007 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74008 SLAB_CACHE_DMA | \
74009 SLAB_STORE_USER | \
74010 @@ -161,7 +161,7 @@
74011 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74012 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74013 #else
74014 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74015 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74016 SLAB_CACHE_DMA | \
74017 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74018 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74019 @@ -290,7 +290,7 @@ struct kmem_list3 {
74020 * Need this for bootstrapping a per node allocator.
74021 */
74022 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74023 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74024 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74025 #define CACHE_CACHE 0
74026 #define SIZE_AC MAX_NUMNODES
74027 #define SIZE_L3 (2 * MAX_NUMNODES)
74028 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74029 if ((x)->max_freeable < i) \
74030 (x)->max_freeable = i; \
74031 } while (0)
74032 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74033 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74034 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74035 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74036 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74037 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74038 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74039 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74040 #else
74041 #define STATS_INC_ACTIVE(x) do { } while (0)
74042 #define STATS_DEC_ACTIVE(x) do { } while (0)
74043 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74044 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74045 */
74046 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74047 - const struct slab *slab, void *obj)
74048 + const struct slab *slab, const void *obj)
74049 {
74050 u32 offset = (obj - slab->s_mem);
74051 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74052 @@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
74053 struct cache_names {
74054 char *name;
74055 char *name_dma;
74056 + char *name_usercopy;
74057 };
74058
74059 static struct cache_names __initdata cache_names[] = {
74060 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74061 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74062 #include <linux/kmalloc_sizes.h>
74063 - {NULL,}
74064 + {NULL}
74065 #undef CACHE
74066 };
74067
74068 @@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74069 if (unlikely(gfpflags & GFP_DMA))
74070 return csizep->cs_dmacachep;
74071 #endif
74072 +
74073 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74074 + if (unlikely(gfpflags & GFP_USERCOPY))
74075 + return csizep->cs_usercopycachep;
74076 +#endif
74077 +
74078 return csizep->cs_cachep;
74079 }
74080
74081 @@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
74082 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74083 sizes[INDEX_AC].cs_size,
74084 ARCH_KMALLOC_MINALIGN,
74085 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74086 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74087 NULL);
74088
74089 if (INDEX_AC != INDEX_L3) {
74090 @@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
74091 kmem_cache_create(names[INDEX_L3].name,
74092 sizes[INDEX_L3].cs_size,
74093 ARCH_KMALLOC_MINALIGN,
74094 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74095 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74096 NULL);
74097 }
74098
74099 @@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
74100 sizes->cs_cachep = kmem_cache_create(names->name,
74101 sizes->cs_size,
74102 ARCH_KMALLOC_MINALIGN,
74103 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74104 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74105 NULL);
74106 }
74107 #ifdef CONFIG_ZONE_DMA
74108 @@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
74109 SLAB_PANIC,
74110 NULL);
74111 #endif
74112 +
74113 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74114 + sizes->cs_usercopycachep = kmem_cache_create(
74115 + names->name_usercopy,
74116 + sizes->cs_size,
74117 + ARCH_KMALLOC_MINALIGN,
74118 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74119 + NULL);
74120 +#endif
74121 +
74122 sizes++;
74123 names++;
74124 }
74125 @@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
74126 }
74127 /* cpu stats */
74128 {
74129 - unsigned long allochit = atomic_read(&cachep->allochit);
74130 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74131 - unsigned long freehit = atomic_read(&cachep->freehit);
74132 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74133 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74134 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74135 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74136 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74137
74138 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74139 allochit, allocmiss, freehit, freemiss);
74140 @@ -4652,13 +4669,71 @@ static int __init slab_proc_init(void)
74141 {
74142 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74143 #ifdef CONFIG_DEBUG_SLAB_LEAK
74144 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74145 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74146 #endif
74147 return 0;
74148 }
74149 module_init(slab_proc_init);
74150 #endif
74151
74152 +bool is_usercopy_object(const void *ptr)
74153 +{
74154 + struct page *page;
74155 + struct kmem_cache *cachep;
74156 +
74157 + if (ZERO_OR_NULL_PTR(ptr))
74158 + return false;
74159 +
74160 + if (!slab_is_available())
74161 + return false;
74162 +
74163 + if (!virt_addr_valid(ptr))
74164 + return false;
74165 +
74166 + page = virt_to_head_page(ptr);
74167 +
74168 + if (!PageSlab(page))
74169 + return false;
74170 +
74171 + cachep = page_get_cache(page);
74172 + return cachep->flags & SLAB_USERCOPY;
74173 +}
74174 +
74175 +#ifdef CONFIG_PAX_USERCOPY
74176 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74177 +{
74178 + struct page *page;
74179 + struct kmem_cache *cachep;
74180 + struct slab *slabp;
74181 + unsigned int objnr;
74182 + unsigned long offset;
74183 +
74184 + if (ZERO_OR_NULL_PTR(ptr))
74185 + return "<null>";
74186 +
74187 + if (!virt_addr_valid(ptr))
74188 + return NULL;
74189 +
74190 + page = virt_to_head_page(ptr);
74191 +
74192 + if (!PageSlab(page))
74193 + return NULL;
74194 +
74195 + cachep = page_get_cache(page);
74196 + if (!(cachep->flags & SLAB_USERCOPY))
74197 + return cachep->name;
74198 +
74199 + slabp = page_get_slab(page);
74200 + objnr = obj_to_index(cachep, slabp, ptr);
74201 + BUG_ON(objnr >= cachep->num);
74202 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74203 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74204 + return NULL;
74205 +
74206 + return cachep->name;
74207 +}
74208 +#endif
74209 +
74210 /**
74211 * ksize - get the actual amount of memory allocated for a given object
74212 * @objp: Pointer to the object
74213 diff --git a/mm/slob.c b/mm/slob.c
74214 index 8105be4..3e3e9cd 100644
74215 --- a/mm/slob.c
74216 +++ b/mm/slob.c
74217 @@ -29,7 +29,7 @@
74218 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74219 * alloc_pages() directly, allocating compound pages so the page order
74220 * does not have to be separately tracked, and also stores the exact
74221 - * allocation size in page->private so that it can be used to accurately
74222 + * allocation size in slob_page->size so that it can be used to accurately
74223 * provide ksize(). These objects are detected in kfree() because slob_page()
74224 * is false for them.
74225 *
74226 @@ -58,6 +58,7 @@
74227 */
74228
74229 #include <linux/kernel.h>
74230 +#include <linux/sched.h>
74231 #include <linux/slab.h>
74232 #include <linux/mm.h>
74233 #include <linux/swap.h> /* struct reclaim_state */
74234 @@ -102,7 +103,8 @@ struct slob_page {
74235 unsigned long flags; /* mandatory */
74236 atomic_t _count; /* mandatory */
74237 slobidx_t units; /* free units left in page */
74238 - unsigned long pad[2];
74239 + unsigned long pad[1];
74240 + unsigned long size; /* size when >=PAGE_SIZE */
74241 slob_t *free; /* first free slob_t in page */
74242 struct list_head list; /* linked list of free pages */
74243 };
74244 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74245 */
74246 static inline int is_slob_page(struct slob_page *sp)
74247 {
74248 - return PageSlab((struct page *)sp);
74249 + return PageSlab((struct page *)sp) && !sp->size;
74250 }
74251
74252 static inline void set_slob_page(struct slob_page *sp)
74253 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74254
74255 static inline struct slob_page *slob_page(const void *addr)
74256 {
74257 - return (struct slob_page *)virt_to_page(addr);
74258 + return (struct slob_page *)virt_to_head_page(addr);
74259 }
74260
74261 /*
74262 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74263 /*
74264 * Return the size of a slob block.
74265 */
74266 -static slobidx_t slob_units(slob_t *s)
74267 +static slobidx_t slob_units(const slob_t *s)
74268 {
74269 if (s->units > 0)
74270 return s->units;
74271 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74272 /*
74273 * Return the next free slob block pointer after this one.
74274 */
74275 -static slob_t *slob_next(slob_t *s)
74276 +static slob_t *slob_next(const slob_t *s)
74277 {
74278 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74279 slobidx_t next;
74280 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74281 /*
74282 * Returns true if s is the last free block in its page.
74283 */
74284 -static int slob_last(slob_t *s)
74285 +static int slob_last(const slob_t *s)
74286 {
74287 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74288 }
74289 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74290 if (!page)
74291 return NULL;
74292
74293 + set_slob_page(page);
74294 return page_address(page);
74295 }
74296
74297 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74298 if (!b)
74299 return NULL;
74300 sp = slob_page(b);
74301 - set_slob_page(sp);
74302
74303 spin_lock_irqsave(&slob_lock, flags);
74304 sp->units = SLOB_UNITS(PAGE_SIZE);
74305 sp->free = b;
74306 + sp->size = 0;
74307 INIT_LIST_HEAD(&sp->list);
74308 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74309 set_slob_page_free(sp, slob_list);
74310 @@ -476,10 +479,9 @@ out:
74311 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74312 */
74313
74314 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74315 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74316 {
74317 - unsigned int *m;
74318 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74319 + slob_t *m;
74320 void *ret;
74321
74322 gfp &= gfp_allowed_mask;
74323 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74324
74325 if (!m)
74326 return NULL;
74327 - *m = size;
74328 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74329 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74330 + m[0].units = size;
74331 + m[1].units = align;
74332 ret = (void *)m + align;
74333
74334 trace_kmalloc_node(_RET_IP_, ret,
74335 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74336 gfp |= __GFP_COMP;
74337 ret = slob_new_pages(gfp, order, node);
74338 if (ret) {
74339 - struct page *page;
74340 - page = virt_to_page(ret);
74341 - page->private = size;
74342 + struct slob_page *sp;
74343 + sp = slob_page(ret);
74344 + sp->size = size;
74345 }
74346
74347 trace_kmalloc_node(_RET_IP_, ret,
74348 size, PAGE_SIZE << order, gfp, node);
74349 }
74350
74351 - kmemleak_alloc(ret, size, 1, gfp);
74352 + return ret;
74353 +}
74354 +
74355 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74356 +{
74357 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74358 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74359 +
74360 + if (!ZERO_OR_NULL_PTR(ret))
74361 + kmemleak_alloc(ret, size, 1, gfp);
74362 return ret;
74363 }
74364 EXPORT_SYMBOL(__kmalloc_node);
74365 @@ -533,13 +547,88 @@ void kfree(const void *block)
74366 sp = slob_page(block);
74367 if (is_slob_page(sp)) {
74368 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74369 - unsigned int *m = (unsigned int *)(block - align);
74370 - slob_free(m, *m + align);
74371 - } else
74372 + slob_t *m = (slob_t *)(block - align);
74373 + slob_free(m, m[0].units + align);
74374 + } else {
74375 + clear_slob_page(sp);
74376 + free_slob_page(sp);
74377 + sp->size = 0;
74378 put_page(&sp->page);
74379 + }
74380 }
74381 EXPORT_SYMBOL(kfree);
74382
74383 +bool is_usercopy_object(const void *ptr)
74384 +{
74385 + if (!slab_is_available())
74386 + return false;
74387 +
74388 + // PAX: TODO
74389 +
74390 + return false;
74391 +}
74392 +
74393 +#ifdef CONFIG_PAX_USERCOPY
74394 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74395 +{
74396 + struct slob_page *sp;
74397 + const slob_t *free;
74398 + const void *base;
74399 + unsigned long flags;
74400 +
74401 + if (ZERO_OR_NULL_PTR(ptr))
74402 + return "<null>";
74403 +
74404 + if (!virt_addr_valid(ptr))
74405 + return NULL;
74406 +
74407 + sp = slob_page(ptr);
74408 + if (!PageSlab((struct page *)sp))
74409 + return NULL;
74410 +
74411 + if (sp->size) {
74412 + base = page_address(&sp->page);
74413 + if (base <= ptr && n <= sp->size - (ptr - base))
74414 + return NULL;
74415 + return "<slob>";
74416 + }
74417 +
74418 + /* some tricky double walking to find the chunk */
74419 + spin_lock_irqsave(&slob_lock, flags);
74420 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74421 + free = sp->free;
74422 +
74423 + while (!slob_last(free) && (void *)free <= ptr) {
74424 + base = free + slob_units(free);
74425 + free = slob_next(free);
74426 + }
74427 +
74428 + while (base < (void *)free) {
74429 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74430 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74431 + int offset;
74432 +
74433 + if (ptr < base + align)
74434 + break;
74435 +
74436 + offset = ptr - base - align;
74437 + if (offset >= m) {
74438 + base += size;
74439 + continue;
74440 + }
74441 +
74442 + if (n > m - offset)
74443 + break;
74444 +
74445 + spin_unlock_irqrestore(&slob_lock, flags);
74446 + return NULL;
74447 + }
74448 +
74449 + spin_unlock_irqrestore(&slob_lock, flags);
74450 + return "<slob>";
74451 +}
74452 +#endif
74453 +
74454 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74455 size_t ksize(const void *block)
74456 {
74457 @@ -552,10 +641,10 @@ size_t ksize(const void *block)
74458 sp = slob_page(block);
74459 if (is_slob_page(sp)) {
74460 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74461 - unsigned int *m = (unsigned int *)(block - align);
74462 - return SLOB_UNITS(*m) * SLOB_UNIT;
74463 + slob_t *m = (slob_t *)(block - align);
74464 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74465 } else
74466 - return sp->page.private;
74467 + return sp->size;
74468 }
74469 EXPORT_SYMBOL(ksize);
74470
74471 @@ -571,8 +660,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74472 {
74473 struct kmem_cache *c;
74474
74475 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74476 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74477 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74478 +#else
74479 c = slob_alloc(sizeof(struct kmem_cache),
74480 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74481 +#endif
74482
74483 if (c) {
74484 c->name = name;
74485 @@ -614,17 +708,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74486
74487 lockdep_trace_alloc(flags);
74488
74489 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74490 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74491 +#else
74492 if (c->size < PAGE_SIZE) {
74493 b = slob_alloc(c->size, flags, c->align, node);
74494 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74495 SLOB_UNITS(c->size) * SLOB_UNIT,
74496 flags, node);
74497 } else {
74498 + struct slob_page *sp;
74499 +
74500 b = slob_new_pages(flags, get_order(c->size), node);
74501 + sp = slob_page(b);
74502 + sp->size = c->size;
74503 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74504 PAGE_SIZE << get_order(c->size),
74505 flags, node);
74506 }
74507 +#endif
74508
74509 if (c->ctor)
74510 c->ctor(b);
74511 @@ -636,10 +738,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74512
74513 static void __kmem_cache_free(void *b, int size)
74514 {
74515 - if (size < PAGE_SIZE)
74516 + struct slob_page *sp = slob_page(b);
74517 +
74518 + if (is_slob_page(sp))
74519 slob_free(b, size);
74520 - else
74521 + else {
74522 + clear_slob_page(sp);
74523 + free_slob_page(sp);
74524 + sp->size = 0;
74525 slob_free_pages(b, get_order(size));
74526 + }
74527 }
74528
74529 static void kmem_rcu_free(struct rcu_head *head)
74530 @@ -652,17 +760,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74531
74532 void kmem_cache_free(struct kmem_cache *c, void *b)
74533 {
74534 + int size = c->size;
74535 +
74536 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74537 + if (size + c->align < PAGE_SIZE) {
74538 + size += c->align;
74539 + b -= c->align;
74540 + }
74541 +#endif
74542 +
74543 kmemleak_free_recursive(b, c->flags);
74544 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74545 struct slob_rcu *slob_rcu;
74546 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74547 - slob_rcu->size = c->size;
74548 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74549 + slob_rcu->size = size;
74550 call_rcu(&slob_rcu->head, kmem_rcu_free);
74551 } else {
74552 - __kmem_cache_free(b, c->size);
74553 + __kmem_cache_free(b, size);
74554 }
74555
74556 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74557 + trace_kfree(_RET_IP_, b);
74558 +#else
74559 trace_kmem_cache_free(_RET_IP_, b);
74560 +#endif
74561 +
74562 }
74563 EXPORT_SYMBOL(kmem_cache_free);
74564
74565 diff --git a/mm/slub.c b/mm/slub.c
74566 index 8c691fa..2993c2b 100644
74567 --- a/mm/slub.c
74568 +++ b/mm/slub.c
74569 @@ -209,7 +209,7 @@ struct track {
74570
74571 enum track_item { TRACK_ALLOC, TRACK_FREE };
74572
74573 -#ifdef CONFIG_SYSFS
74574 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74575 static int sysfs_slab_add(struct kmem_cache *);
74576 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74577 static void sysfs_slab_remove(struct kmem_cache *);
74578 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74579 if (!t->addr)
74580 return;
74581
74582 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74583 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74584 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74585 #ifdef CONFIG_STACKTRACE
74586 {
74587 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74588
74589 page = virt_to_head_page(x);
74590
74591 + BUG_ON(!PageSlab(page));
74592 +
74593 slab_free(s, page, x, _RET_IP_);
74594
74595 trace_kmem_cache_free(_RET_IP_, x);
74596 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
74597 * Merge control. If this is set then no merging of slab caches will occur.
74598 * (Could be removed. This was introduced to pacify the merge skeptics.)
74599 */
74600 -static int slub_nomerge;
74601 +static int slub_nomerge = 1;
74602
74603 /*
74604 * Calculate the order of allocation given an slab object size.
74605 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74606 else
74607 s->cpu_partial = 30;
74608
74609 - s->refcount = 1;
74610 + atomic_set(&s->refcount, 1);
74611 #ifdef CONFIG_NUMA
74612 s->remote_node_defrag_ratio = 1000;
74613 #endif
74614 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74615 void kmem_cache_destroy(struct kmem_cache *s)
74616 {
74617 down_write(&slub_lock);
74618 - s->refcount--;
74619 - if (!s->refcount) {
74620 + if (atomic_dec_and_test(&s->refcount)) {
74621 list_del(&s->list);
74622 up_write(&slub_lock);
74623 if (kmem_cache_close(s)) {
74624 @@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74625 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74626 #endif
74627
74628 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74629 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74630 +#endif
74631 +
74632 static int __init setup_slub_min_order(char *str)
74633 {
74634 get_option(&str, &slub_min_order);
74635 @@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74636 return kmalloc_dma_caches[index];
74637
74638 #endif
74639 +
74640 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74641 + if (flags & SLAB_USERCOPY)
74642 + return kmalloc_usercopy_caches[index];
74643 +
74644 +#endif
74645 +
74646 return kmalloc_caches[index];
74647 }
74648
74649 @@ -3405,6 +3417,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74650 EXPORT_SYMBOL(__kmalloc_node);
74651 #endif
74652
74653 +bool is_usercopy_object(const void *ptr)
74654 +{
74655 + struct page *page;
74656 + struct kmem_cache *s;
74657 +
74658 + if (ZERO_OR_NULL_PTR(ptr))
74659 + return false;
74660 +
74661 + if (!slab_is_available())
74662 + return false;
74663 +
74664 + if (!virt_addr_valid(ptr))
74665 + return false;
74666 +
74667 + page = virt_to_head_page(ptr);
74668 +
74669 + if (!PageSlab(page))
74670 + return false;
74671 +
74672 + s = page->slab;
74673 + return s->flags & SLAB_USERCOPY;
74674 +}
74675 +
74676 +#ifdef CONFIG_PAX_USERCOPY
74677 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74678 +{
74679 + struct page *page;
74680 + struct kmem_cache *s;
74681 + unsigned long offset;
74682 +
74683 + if (ZERO_OR_NULL_PTR(ptr))
74684 + return "<null>";
74685 +
74686 + if (!virt_addr_valid(ptr))
74687 + return NULL;
74688 +
74689 + page = virt_to_head_page(ptr);
74690 +
74691 + if (!PageSlab(page))
74692 + return NULL;
74693 +
74694 + s = page->slab;
74695 + if (!(s->flags & SLAB_USERCOPY))
74696 + return s->name;
74697 +
74698 + offset = (ptr - page_address(page)) % s->size;
74699 + if (offset <= s->objsize && n <= s->objsize - offset)
74700 + return NULL;
74701 +
74702 + return s->name;
74703 +}
74704 +#endif
74705 +
74706 size_t ksize(const void *object)
74707 {
74708 struct page *page;
74709 @@ -3679,7 +3744,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74710 int node;
74711
74712 list_add(&s->list, &slab_caches);
74713 - s->refcount = -1;
74714 + atomic_set(&s->refcount, -1);
74715
74716 for_each_node_state(node, N_NORMAL_MEMORY) {
74717 struct kmem_cache_node *n = get_node(s, node);
74718 @@ -3799,17 +3864,17 @@ void __init kmem_cache_init(void)
74719
74720 /* Caches that are not of the two-to-the-power-of size */
74721 if (KMALLOC_MIN_SIZE <= 32) {
74722 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74723 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74724 caches++;
74725 }
74726
74727 if (KMALLOC_MIN_SIZE <= 64) {
74728 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74729 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74730 caches++;
74731 }
74732
74733 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74734 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74735 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74736 caches++;
74737 }
74738
74739 @@ -3851,6 +3916,22 @@ void __init kmem_cache_init(void)
74740 }
74741 }
74742 #endif
74743 +
74744 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74745 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74746 + struct kmem_cache *s = kmalloc_caches[i];
74747 +
74748 + if (s && s->size) {
74749 + char *name = kasprintf(GFP_NOWAIT,
74750 + "usercopy-kmalloc-%d", s->objsize);
74751 +
74752 + BUG_ON(!name);
74753 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74754 + s->objsize, SLAB_USERCOPY);
74755 + }
74756 + }
74757 +#endif
74758 +
74759 printk(KERN_INFO
74760 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74761 " CPUs=%d, Nodes=%d\n",
74762 @@ -3877,7 +3958,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74763 /*
74764 * We may have set a slab to be unmergeable during bootstrap.
74765 */
74766 - if (s->refcount < 0)
74767 + if (atomic_read(&s->refcount) < 0)
74768 return 1;
74769
74770 return 0;
74771 @@ -3936,7 +4017,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74772 down_write(&slub_lock);
74773 s = find_mergeable(size, align, flags, name, ctor);
74774 if (s) {
74775 - s->refcount++;
74776 + atomic_inc(&s->refcount);
74777 /*
74778 * Adjust the object sizes so that we clear
74779 * the complete object on kzalloc.
74780 @@ -3945,7 +4026,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74781 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74782
74783 if (sysfs_slab_alias(s, name)) {
74784 - s->refcount--;
74785 + atomic_dec(&s->refcount);
74786 goto err;
74787 }
74788 up_write(&slub_lock);
74789 @@ -4074,7 +4155,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74790 }
74791 #endif
74792
74793 -#ifdef CONFIG_SYSFS
74794 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74795 static int count_inuse(struct page *page)
74796 {
74797 return page->inuse;
74798 @@ -4461,12 +4542,12 @@ static void resiliency_test(void)
74799 validate_slab_cache(kmalloc_caches[9]);
74800 }
74801 #else
74802 -#ifdef CONFIG_SYSFS
74803 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74804 static void resiliency_test(void) {};
74805 #endif
74806 #endif
74807
74808 -#ifdef CONFIG_SYSFS
74809 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74810 enum slab_stat_type {
74811 SL_ALL, /* All slabs */
74812 SL_PARTIAL, /* Only partially allocated slabs */
74813 @@ -4709,7 +4790,7 @@ SLAB_ATTR_RO(ctor);
74814
74815 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74816 {
74817 - return sprintf(buf, "%d\n", s->refcount - 1);
74818 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74819 }
74820 SLAB_ATTR_RO(aliases);
74821
74822 @@ -5280,6 +5361,7 @@ static char *create_unique_id(struct kmem_cache *s)
74823 return name;
74824 }
74825
74826 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74827 static int sysfs_slab_add(struct kmem_cache *s)
74828 {
74829 int err;
74830 @@ -5342,6 +5424,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74831 kobject_del(&s->kobj);
74832 kobject_put(&s->kobj);
74833 }
74834 +#endif
74835
74836 /*
74837 * Need to buffer aliases during bootup until sysfs becomes
74838 @@ -5355,6 +5438,7 @@ struct saved_alias {
74839
74840 static struct saved_alias *alias_list;
74841
74842 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74843 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74844 {
74845 struct saved_alias *al;
74846 @@ -5377,6 +5461,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74847 alias_list = al;
74848 return 0;
74849 }
74850 +#endif
74851
74852 static int __init slab_sysfs_init(void)
74853 {
74854 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74855 index 1b7e22a..3fcd4f3 100644
74856 --- a/mm/sparse-vmemmap.c
74857 +++ b/mm/sparse-vmemmap.c
74858 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74859 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74860 if (!p)
74861 return NULL;
74862 - pud_populate(&init_mm, pud, p);
74863 + pud_populate_kernel(&init_mm, pud, p);
74864 }
74865 return pud;
74866 }
74867 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74868 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74869 if (!p)
74870 return NULL;
74871 - pgd_populate(&init_mm, pgd, p);
74872 + pgd_populate_kernel(&init_mm, pgd, p);
74873 }
74874 return pgd;
74875 }
74876 diff --git a/mm/swap.c b/mm/swap.c
74877 index 4e7e2ec..0c57830 100644
74878 --- a/mm/swap.c
74879 +++ b/mm/swap.c
74880 @@ -30,6 +30,7 @@
74881 #include <linux/backing-dev.h>
74882 #include <linux/memcontrol.h>
74883 #include <linux/gfp.h>
74884 +#include <linux/hugetlb.h>
74885
74886 #include "internal.h"
74887
74888 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74889
74890 __page_cache_release(page);
74891 dtor = get_compound_page_dtor(page);
74892 + if (!PageHuge(page))
74893 + BUG_ON(dtor != free_compound_page);
74894 (*dtor)(page);
74895 }
74896
74897 diff --git a/mm/swapfile.c b/mm/swapfile.c
74898 index 71373d0..11fa7d9 100644
74899 --- a/mm/swapfile.c
74900 +++ b/mm/swapfile.c
74901 @@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74902
74903 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74904 /* Activity counter to indicate that a swapon or swapoff has occurred */
74905 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74906 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74907
74908 static inline unsigned char swap_count(unsigned char ent)
74909 {
74910 @@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74911 }
74912 filp_close(swap_file, NULL);
74913 err = 0;
74914 - atomic_inc(&proc_poll_event);
74915 + atomic_inc_unchecked(&proc_poll_event);
74916 wake_up_interruptible(&proc_poll_wait);
74917
74918 out_dput:
74919 @@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74920
74921 poll_wait(file, &proc_poll_wait, wait);
74922
74923 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74924 - seq->poll_event = atomic_read(&proc_poll_event);
74925 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74926 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74927 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74928 }
74929
74930 @@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74931 return ret;
74932
74933 seq = file->private_data;
74934 - seq->poll_event = atomic_read(&proc_poll_event);
74935 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74936 return 0;
74937 }
74938
74939 @@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74940 (frontswap_map) ? "FS" : "");
74941
74942 mutex_unlock(&swapon_mutex);
74943 - atomic_inc(&proc_poll_event);
74944 + atomic_inc_unchecked(&proc_poll_event);
74945 wake_up_interruptible(&proc_poll_wait);
74946
74947 if (S_ISREG(inode->i_mode))
74948 diff --git a/mm/util.c b/mm/util.c
74949 index 8c7265a..c96d884 100644
74950 --- a/mm/util.c
74951 +++ b/mm/util.c
74952 @@ -285,6 +285,12 @@ done:
74953 void arch_pick_mmap_layout(struct mm_struct *mm)
74954 {
74955 mm->mmap_base = TASK_UNMAPPED_BASE;
74956 +
74957 +#ifdef CONFIG_PAX_RANDMMAP
74958 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74959 + mm->mmap_base += mm->delta_mmap;
74960 +#endif
74961 +
74962 mm->get_unmapped_area = arch_get_unmapped_area;
74963 mm->unmap_area = arch_unmap_area;
74964 }
74965 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74966 index 2aad499..4006a74 100644
74967 --- a/mm/vmalloc.c
74968 +++ b/mm/vmalloc.c
74969 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74970
74971 pte = pte_offset_kernel(pmd, addr);
74972 do {
74973 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74974 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74975 +
74976 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74977 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74978 + BUG_ON(!pte_exec(*pte));
74979 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74980 + continue;
74981 + }
74982 +#endif
74983 +
74984 + {
74985 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74986 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74987 + }
74988 } while (pte++, addr += PAGE_SIZE, addr != end);
74989 }
74990
74991 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74992 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74993 {
74994 pte_t *pte;
74995 + int ret = -ENOMEM;
74996
74997 /*
74998 * nr is a running index into the array which helps higher level
74999 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75000 pte = pte_alloc_kernel(pmd, addr);
75001 if (!pte)
75002 return -ENOMEM;
75003 +
75004 + pax_open_kernel();
75005 do {
75006 struct page *page = pages[*nr];
75007
75008 - if (WARN_ON(!pte_none(*pte)))
75009 - return -EBUSY;
75010 - if (WARN_ON(!page))
75011 - return -ENOMEM;
75012 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75013 + if (pgprot_val(prot) & _PAGE_NX)
75014 +#endif
75015 +
75016 + if (WARN_ON(!pte_none(*pte))) {
75017 + ret = -EBUSY;
75018 + goto out;
75019 + }
75020 + if (WARN_ON(!page)) {
75021 + ret = -ENOMEM;
75022 + goto out;
75023 + }
75024 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75025 (*nr)++;
75026 } while (pte++, addr += PAGE_SIZE, addr != end);
75027 - return 0;
75028 + ret = 0;
75029 +out:
75030 + pax_close_kernel();
75031 + return ret;
75032 }
75033
75034 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75035 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75036 pmd_t *pmd;
75037 unsigned long next;
75038
75039 - pmd = pmd_alloc(&init_mm, pud, addr);
75040 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75041 if (!pmd)
75042 return -ENOMEM;
75043 do {
75044 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75045 pud_t *pud;
75046 unsigned long next;
75047
75048 - pud = pud_alloc(&init_mm, pgd, addr);
75049 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75050 if (!pud)
75051 return -ENOMEM;
75052 do {
75053 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75054 * and fall back on vmalloc() if that fails. Others
75055 * just put it in the vmalloc space.
75056 */
75057 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75058 +#ifdef CONFIG_MODULES
75059 +#ifdef MODULES_VADDR
75060 unsigned long addr = (unsigned long)x;
75061 if (addr >= MODULES_VADDR && addr < MODULES_END)
75062 return 1;
75063 #endif
75064 +
75065 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75066 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75067 + return 1;
75068 +#endif
75069 +
75070 +#endif
75071 +
75072 return is_vmalloc_addr(x);
75073 }
75074
75075 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75076
75077 if (!pgd_none(*pgd)) {
75078 pud_t *pud = pud_offset(pgd, addr);
75079 +#ifdef CONFIG_X86
75080 + if (!pud_large(*pud))
75081 +#endif
75082 if (!pud_none(*pud)) {
75083 pmd_t *pmd = pmd_offset(pud, addr);
75084 +#ifdef CONFIG_X86
75085 + if (!pmd_large(*pmd))
75086 +#endif
75087 if (!pmd_none(*pmd)) {
75088 pte_t *ptep, pte;
75089
75090 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75091 * Allocate a region of KVA of the specified size and alignment, within the
75092 * vstart and vend.
75093 */
75094 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75095 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75096 unsigned long align,
75097 unsigned long vstart, unsigned long vend,
75098 int node, gfp_t gfp_mask)
75099 @@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75100 struct vm_struct *area;
75101
75102 BUG_ON(in_interrupt());
75103 +
75104 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75105 + if (flags & VM_KERNEXEC) {
75106 + if (start != VMALLOC_START || end != VMALLOC_END)
75107 + return NULL;
75108 + start = (unsigned long)MODULES_EXEC_VADDR;
75109 + end = (unsigned long)MODULES_EXEC_END;
75110 + }
75111 +#endif
75112 +
75113 if (flags & VM_IOREMAP) {
75114 int bit = fls(size);
75115
75116 @@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
75117 if (count > totalram_pages)
75118 return NULL;
75119
75120 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75121 + if (!(pgprot_val(prot) & _PAGE_NX))
75122 + flags |= VM_KERNEXEC;
75123 +#endif
75124 +
75125 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75126 __builtin_return_address(0));
75127 if (!area)
75128 @@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75129 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75130 goto fail;
75131
75132 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75133 + if (!(pgprot_val(prot) & _PAGE_NX))
75134 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75135 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75136 + else
75137 +#endif
75138 +
75139 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75140 start, end, node, gfp_mask, caller);
75141 if (!area)
75142 @@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
75143 * For tight control over page level allocator and protection flags
75144 * use __vmalloc() instead.
75145 */
75146 -
75147 void *vmalloc_exec(unsigned long size)
75148 {
75149 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75150 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75151 -1, __builtin_return_address(0));
75152 }
75153
75154 @@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75155 unsigned long uaddr = vma->vm_start;
75156 unsigned long usize = vma->vm_end - vma->vm_start;
75157
75158 + BUG_ON(vma->vm_mirror);
75159 +
75160 if ((PAGE_SIZE-1) & (unsigned long)addr)
75161 return -EINVAL;
75162
75163 diff --git a/mm/vmstat.c b/mm/vmstat.c
75164 index 1bbbbd9..ff35669 100644
75165 --- a/mm/vmstat.c
75166 +++ b/mm/vmstat.c
75167 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75168 *
75169 * vm_stat contains the global counters
75170 */
75171 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75172 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75173 EXPORT_SYMBOL(vm_stat);
75174
75175 #ifdef CONFIG_SMP
75176 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75177 v = p->vm_stat_diff[i];
75178 p->vm_stat_diff[i] = 0;
75179 local_irq_restore(flags);
75180 - atomic_long_add(v, &zone->vm_stat[i]);
75181 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75182 global_diff[i] += v;
75183 #ifdef CONFIG_NUMA
75184 /* 3 seconds idle till flush */
75185 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75186
75187 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75188 if (global_diff[i])
75189 - atomic_long_add(global_diff[i], &vm_stat[i]);
75190 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75191 }
75192
75193 #endif
75194 @@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
75195 start_cpu_timer(cpu);
75196 #endif
75197 #ifdef CONFIG_PROC_FS
75198 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75199 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75200 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75201 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75202 + {
75203 + mode_t gr_mode = S_IRUGO;
75204 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75205 + gr_mode = S_IRUSR;
75206 +#endif
75207 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75208 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75209 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75210 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75211 +#else
75212 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75213 +#endif
75214 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75215 + }
75216 #endif
75217 return 0;
75218 }
75219 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75220 index 9096bcb..43ed7bb 100644
75221 --- a/net/8021q/vlan.c
75222 +++ b/net/8021q/vlan.c
75223 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75224 err = -EPERM;
75225 if (!capable(CAP_NET_ADMIN))
75226 break;
75227 - if ((args.u.name_type >= 0) &&
75228 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75229 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75230 struct vlan_net *vn;
75231
75232 vn = net_generic(net, vlan_net_id);
75233 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75234 index 6449bae..8c1f454 100644
75235 --- a/net/9p/trans_fd.c
75236 +++ b/net/9p/trans_fd.c
75237 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75238 oldfs = get_fs();
75239 set_fs(get_ds());
75240 /* The cast to a user pointer is valid due to the set_fs() */
75241 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75242 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75243 set_fs(oldfs);
75244
75245 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75246 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75247 index 876fbe8..8bbea9f 100644
75248 --- a/net/atm/atm_misc.c
75249 +++ b/net/atm/atm_misc.c
75250 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75251 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75252 return 1;
75253 atm_return(vcc, truesize);
75254 - atomic_inc(&vcc->stats->rx_drop);
75255 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75256 return 0;
75257 }
75258 EXPORT_SYMBOL(atm_charge);
75259 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75260 }
75261 }
75262 atm_return(vcc, guess);
75263 - atomic_inc(&vcc->stats->rx_drop);
75264 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75265 return NULL;
75266 }
75267 EXPORT_SYMBOL(atm_alloc_charge);
75268 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75269
75270 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75271 {
75272 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75273 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75274 __SONET_ITEMS
75275 #undef __HANDLE_ITEM
75276 }
75277 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75278
75279 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75280 {
75281 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75282 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75283 __SONET_ITEMS
75284 #undef __HANDLE_ITEM
75285 }
75286 diff --git a/net/atm/common.c b/net/atm/common.c
75287 index b4b44db..0c0ad93 100644
75288 --- a/net/atm/common.c
75289 +++ b/net/atm/common.c
75290 @@ -812,6 +812,7 @@ int vcc_getsockopt(struct socket *sock, int level, int optname,
75291
75292 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
75293 return -ENOTCONN;
75294 + memset(&pvc, 0, sizeof(pvc));
75295 pvc.sap_family = AF_ATMPVC;
75296 pvc.sap_addr.itf = vcc->dev->number;
75297 pvc.sap_addr.vpi = vcc->vpi;
75298 diff --git a/net/atm/lec.h b/net/atm/lec.h
75299 index a86aff9..3a0d6f6 100644
75300 --- a/net/atm/lec.h
75301 +++ b/net/atm/lec.h
75302 @@ -48,7 +48,7 @@ struct lane2_ops {
75303 const u8 *tlvs, u32 sizeoftlvs);
75304 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75305 const u8 *tlvs, u32 sizeoftlvs);
75306 -};
75307 +} __no_const;
75308
75309 /*
75310 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75311 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75312 index 0919a88..a23d54e 100644
75313 --- a/net/atm/mpc.h
75314 +++ b/net/atm/mpc.h
75315 @@ -33,7 +33,7 @@ struct mpoa_client {
75316 struct mpc_parameters parameters; /* parameters for this client */
75317
75318 const struct net_device_ops *old_ops;
75319 - struct net_device_ops new_ops;
75320 + net_device_ops_no_const new_ops;
75321 };
75322
75323
75324 diff --git a/net/atm/proc.c b/net/atm/proc.c
75325 index 0d020de..011c7bb 100644
75326 --- a/net/atm/proc.c
75327 +++ b/net/atm/proc.c
75328 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75329 const struct k_atm_aal_stats *stats)
75330 {
75331 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75332 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75333 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75334 - atomic_read(&stats->rx_drop));
75335 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75336 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75337 + atomic_read_unchecked(&stats->rx_drop));
75338 }
75339
75340 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75341 diff --git a/net/atm/pvc.c b/net/atm/pvc.c
75342 index 3a73491..ae03240 100644
75343 --- a/net/atm/pvc.c
75344 +++ b/net/atm/pvc.c
75345 @@ -95,6 +95,7 @@ static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
75346 return -ENOTCONN;
75347 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
75348 addr = (struct sockaddr_atmpvc *)sockaddr;
75349 + memset(addr, 0, sizeof(*addr));
75350 addr->sap_family = AF_ATMPVC;
75351 addr->sap_addr.itf = vcc->dev->number;
75352 addr->sap_addr.vpi = vcc->vpi;
75353 diff --git a/net/atm/resources.c b/net/atm/resources.c
75354 index 23f45ce..c748f1a 100644
75355 --- a/net/atm/resources.c
75356 +++ b/net/atm/resources.c
75357 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75358 static void copy_aal_stats(struct k_atm_aal_stats *from,
75359 struct atm_aal_stats *to)
75360 {
75361 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75362 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75363 __AAL_STAT_ITEMS
75364 #undef __HANDLE_ITEM
75365 }
75366 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75367 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75368 struct atm_aal_stats *to)
75369 {
75370 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75371 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75372 __AAL_STAT_ITEMS
75373 #undef __HANDLE_ITEM
75374 }
75375 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75376 index dc53798..dc66333 100644
75377 --- a/net/batman-adv/bat_iv_ogm.c
75378 +++ b/net/batman-adv/bat_iv_ogm.c
75379 @@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75380
75381 /* randomize initial seqno to avoid collision */
75382 get_random_bytes(&random_seqno, sizeof(random_seqno));
75383 - atomic_set(&hard_iface->seqno, random_seqno);
75384 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75385
75386 hard_iface->packet_len = BATMAN_OGM_HLEN;
75387 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75388 @@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75389
75390 /* change sequence number to network order */
75391 batman_ogm_packet->seqno =
75392 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75393 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75394
75395 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75396 batman_ogm_packet->tt_crc = htons((uint16_t)
75397 @@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75398 else
75399 batman_ogm_packet->gw_flags = NO_FLAGS;
75400
75401 - atomic_inc(&hard_iface->seqno);
75402 + atomic_inc_unchecked(&hard_iface->seqno);
75403
75404 slide_own_bcast_window(hard_iface);
75405 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75406 @@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75407 return;
75408
75409 /* could be changed by schedule_own_packet() */
75410 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75411 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75412
75413 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75414
75415 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75416 index dc334fa..766a01a 100644
75417 --- a/net/batman-adv/hard-interface.c
75418 +++ b/net/batman-adv/hard-interface.c
75419 @@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75420 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75421 dev_add_pack(&hard_iface->batman_adv_ptype);
75422
75423 - atomic_set(&hard_iface->frag_seqno, 1);
75424 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75425 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75426 hard_iface->net_dev->name);
75427
75428 @@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75429 * This can't be called via a bat_priv callback because
75430 * we have no bat_priv yet.
75431 */
75432 - atomic_set(&hard_iface->seqno, 1);
75433 + atomic_set_unchecked(&hard_iface->seqno, 1);
75434 hard_iface->packet_buff = NULL;
75435
75436 return hard_iface;
75437 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75438 index a0ec0e4..7beb587 100644
75439 --- a/net/batman-adv/soft-interface.c
75440 +++ b/net/batman-adv/soft-interface.c
75441 @@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75442
75443 /* set broadcast sequence number */
75444 bcast_packet->seqno =
75445 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75446 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75447
75448 add_bcast_packet_to_list(bat_priv, skb, 1);
75449
75450 @@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75451 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75452
75453 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75454 - atomic_set(&bat_priv->bcast_seqno, 1);
75455 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75456 atomic_set(&bat_priv->ttvn, 0);
75457 atomic_set(&bat_priv->tt_local_changes, 0);
75458 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75459 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75460 index 61308e8..2e142b2 100644
75461 --- a/net/batman-adv/types.h
75462 +++ b/net/batman-adv/types.h
75463 @@ -38,8 +38,8 @@ struct hard_iface {
75464 int16_t if_num;
75465 char if_status;
75466 struct net_device *net_dev;
75467 - atomic_t seqno;
75468 - atomic_t frag_seqno;
75469 + atomic_unchecked_t seqno;
75470 + atomic_unchecked_t frag_seqno;
75471 unsigned char *packet_buff;
75472 int packet_len;
75473 struct kobject *hardif_obj;
75474 @@ -163,7 +163,7 @@ struct bat_priv {
75475 atomic_t orig_interval; /* uint */
75476 atomic_t hop_penalty; /* uint */
75477 atomic_t log_level; /* uint */
75478 - atomic_t bcast_seqno;
75479 + atomic_unchecked_t bcast_seqno;
75480 atomic_t bcast_queue_left;
75481 atomic_t batman_queue_left;
75482 atomic_t ttvn; /* translation table version number */
75483 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75484 index 74175c2..32f8901 100644
75485 --- a/net/batman-adv/unicast.c
75486 +++ b/net/batman-adv/unicast.c
75487 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75488 frag1->flags = UNI_FRAG_HEAD | large_tail;
75489 frag2->flags = large_tail;
75490
75491 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75492 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75493 frag1->seqno = htons(seqno - 1);
75494 frag2->seqno = htons(seqno);
75495
75496 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75497 index 5914623..bedc768 100644
75498 --- a/net/bluetooth/hci_sock.c
75499 +++ b/net/bluetooth/hci_sock.c
75500 @@ -706,6 +706,7 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *add
75501 *addr_len = sizeof(*haddr);
75502 haddr->hci_family = AF_BLUETOOTH;
75503 haddr->hci_dev = hdev->id;
75504 + haddr->hci_channel= 0;
75505
75506 release_sock(sk);
75507 return 0;
75508 @@ -1016,6 +1017,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char
75509 {
75510 struct hci_filter *f = &hci_pi(sk)->filter;
75511
75512 + memset(&uf, 0, sizeof(uf));
75513 uf.type_mask = f->type_mask;
75514 uf.opcode = f->opcode;
75515 uf.event_mask[0] = *((u32 *) f->event_mask + 0);
75516 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75517 index 4554e80..b778671 100644
75518 --- a/net/bluetooth/l2cap_core.c
75519 +++ b/net/bluetooth/l2cap_core.c
75520 @@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75521 break;
75522
75523 case L2CAP_CONF_RFC:
75524 - if (olen == sizeof(rfc))
75525 - memcpy(&rfc, (void *)val, olen);
75526 + if (olen != sizeof(rfc))
75527 + break;
75528 +
75529 + memcpy(&rfc, (void *)val, olen);
75530
75531 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75532 rfc.mode != chan->mode)
75533 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
75534 index 3bb1611..fcf656b 100644
75535 --- a/net/bluetooth/l2cap_sock.c
75536 +++ b/net/bluetooth/l2cap_sock.c
75537 @@ -246,6 +246,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l
75538
75539 BT_DBG("sock %p, sk %p", sock, sk);
75540
75541 + memset(la, 0, sizeof(struct sockaddr_l2));
75542 addr->sa_family = AF_BLUETOOTH;
75543 *len = sizeof(struct sockaddr_l2);
75544
75545 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
75546 index e8707de..2df6956 100644
75547 --- a/net/bluetooth/rfcomm/sock.c
75548 +++ b/net/bluetooth/rfcomm/sock.c
75549 @@ -547,6 +547,7 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
75550
75551 BT_DBG("sock %p, sk %p", sock, sk);
75552
75553 + memset(sa, 0, sizeof(*sa));
75554 sa->rc_family = AF_BLUETOOTH;
75555 sa->rc_channel = rfcomm_pi(sk)->channel;
75556 if (peer)
75557 @@ -841,6 +842,7 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c
75558 }
75559
75560 sec.level = rfcomm_pi(sk)->sec_level;
75561 + sec.key_size = 0;
75562
75563 len = min_t(unsigned int, len, sizeof(sec));
75564 if (copy_to_user(optval, (char *) &sec, len))
75565 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75566 index d1820ff..4f8c8f6 100644
75567 --- a/net/bluetooth/rfcomm/tty.c
75568 +++ b/net/bluetooth/rfcomm/tty.c
75569 @@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75570 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75571
75572 spin_lock_irqsave(&dev->port.lock, flags);
75573 - if (dev->port.count > 0) {
75574 + if (atomic_read(&dev->port.count) > 0) {
75575 spin_unlock_irqrestore(&dev->port.lock, flags);
75576 return;
75577 }
75578 @@ -461,7 +461,7 @@ static int rfcomm_get_dev_list(void __user *arg)
75579
75580 size = sizeof(*dl) + dev_num * sizeof(*di);
75581
75582 - dl = kmalloc(size, GFP_KERNEL);
75583 + dl = kzalloc(size, GFP_KERNEL);
75584 if (!dl)
75585 return -ENOMEM;
75586
75587 @@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75588 return -ENODEV;
75589
75590 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75591 - dev->channel, dev->port.count);
75592 + dev->channel, atomic_read(&dev->port.count));
75593
75594 spin_lock_irqsave(&dev->port.lock, flags);
75595 - if (++dev->port.count > 1) {
75596 + if (atomic_inc_return(&dev->port.count) > 1) {
75597 spin_unlock_irqrestore(&dev->port.lock, flags);
75598 return 0;
75599 }
75600 @@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75601 return;
75602
75603 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75604 - dev->port.count);
75605 + atomic_read(&dev->port.count));
75606
75607 spin_lock_irqsave(&dev->port.lock, flags);
75608 - if (!--dev->port.count) {
75609 + if (!atomic_dec_return(&dev->port.count)) {
75610 spin_unlock_irqrestore(&dev->port.lock, flags);
75611 if (dev->tty_dev->parent)
75612 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75613 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75614 index 5fe2ff3..10968b5 100644
75615 --- a/net/bridge/netfilter/ebtables.c
75616 +++ b/net/bridge/netfilter/ebtables.c
75617 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75618 tmp.valid_hooks = t->table->valid_hooks;
75619 }
75620 mutex_unlock(&ebt_mutex);
75621 - if (copy_to_user(user, &tmp, *len) != 0){
75622 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75623 BUGPRINT("c2u Didn't work\n");
75624 ret = -EFAULT;
75625 break;
75626 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75627 index 047cd0e..461fd28 100644
75628 --- a/net/caif/cfctrl.c
75629 +++ b/net/caif/cfctrl.c
75630 @@ -10,6 +10,7 @@
75631 #include <linux/spinlock.h>
75632 #include <linux/slab.h>
75633 #include <linux/pkt_sched.h>
75634 +#include <linux/sched.h>
75635 #include <net/caif/caif_layer.h>
75636 #include <net/caif/cfpkt.h>
75637 #include <net/caif/cfctrl.h>
75638 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75639 memset(&dev_info, 0, sizeof(dev_info));
75640 dev_info.id = 0xff;
75641 cfsrvl_init(&this->serv, 0, &dev_info, false);
75642 - atomic_set(&this->req_seq_no, 1);
75643 - atomic_set(&this->rsp_seq_no, 1);
75644 + atomic_set_unchecked(&this->req_seq_no, 1);
75645 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75646 this->serv.layer.receive = cfctrl_recv;
75647 sprintf(this->serv.layer.name, "ctrl");
75648 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75649 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75650 struct cfctrl_request_info *req)
75651 {
75652 spin_lock_bh(&ctrl->info_list_lock);
75653 - atomic_inc(&ctrl->req_seq_no);
75654 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75655 + atomic_inc_unchecked(&ctrl->req_seq_no);
75656 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75657 list_add_tail(&req->list, &ctrl->list);
75658 spin_unlock_bh(&ctrl->info_list_lock);
75659 }
75660 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75661 if (p != first)
75662 pr_warn("Requests are not received in order\n");
75663
75664 - atomic_set(&ctrl->rsp_seq_no,
75665 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75666 p->sequence_no);
75667 list_del(&p->list);
75668 goto out;
75669 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
75670 index 69771c0..e597733 100644
75671 --- a/net/caif/chnl_net.c
75672 +++ b/net/caif/chnl_net.c
75673 @@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
75674
75675 /* check the version of IP */
75676 ip_version = skb_header_pointer(skb, 0, 1, &buf);
75677 + if (!ip_version) {
75678 + kfree_skb(skb);
75679 + return -EINVAL;
75680 + }
75681
75682 switch (*ip_version >> 4) {
75683 case 4:
75684 diff --git a/net/can/gw.c b/net/can/gw.c
75685 index b41acf2..3affb3a 100644
75686 --- a/net/can/gw.c
75687 +++ b/net/can/gw.c
75688 @@ -96,7 +96,7 @@ struct cf_mod {
75689 struct {
75690 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75691 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75692 - } csumfunc;
75693 + } __no_const csumfunc;
75694 };
75695
75696
75697 diff --git a/net/compat.c b/net/compat.c
75698 index 74ed1d7..62f7ea6 100644
75699 --- a/net/compat.c
75700 +++ b/net/compat.c
75701 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75702 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75703 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75704 return -EFAULT;
75705 - kmsg->msg_name = compat_ptr(tmp1);
75706 - kmsg->msg_iov = compat_ptr(tmp2);
75707 - kmsg->msg_control = compat_ptr(tmp3);
75708 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75709 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75710 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75711 return 0;
75712 }
75713
75714 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75715
75716 if (kern_msg->msg_namelen) {
75717 if (mode == VERIFY_READ) {
75718 - int err = move_addr_to_kernel(kern_msg->msg_name,
75719 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75720 kern_msg->msg_namelen,
75721 kern_address);
75722 if (err < 0)
75723 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75724 kern_msg->msg_name = NULL;
75725
75726 tot_len = iov_from_user_compat_to_kern(kern_iov,
75727 - (struct compat_iovec __user *)kern_msg->msg_iov,
75728 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75729 kern_msg->msg_iovlen);
75730 if (tot_len >= 0)
75731 kern_msg->msg_iov = kern_iov;
75732 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75733
75734 #define CMSG_COMPAT_FIRSTHDR(msg) \
75735 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75736 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75737 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75738 (struct compat_cmsghdr __user *)NULL)
75739
75740 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75741 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75742 (ucmlen) <= (unsigned long) \
75743 ((mhdr)->msg_controllen - \
75744 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75745 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75746
75747 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75748 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75749 {
75750 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75751 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75752 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75753 msg->msg_controllen)
75754 return NULL;
75755 return (struct compat_cmsghdr __user *)ptr;
75756 @@ -219,7 +219,7 @@ Efault:
75757
75758 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75759 {
75760 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75761 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75762 struct compat_cmsghdr cmhdr;
75763 struct compat_timeval ctv;
75764 struct compat_timespec cts[3];
75765 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75766
75767 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75768 {
75769 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75770 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75771 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75772 int fdnum = scm->fp->count;
75773 struct file **fp = scm->fp->fp;
75774 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75775 return -EFAULT;
75776 old_fs = get_fs();
75777 set_fs(KERNEL_DS);
75778 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75779 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75780 set_fs(old_fs);
75781
75782 return err;
75783 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75784 len = sizeof(ktime);
75785 old_fs = get_fs();
75786 set_fs(KERNEL_DS);
75787 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75788 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75789 set_fs(old_fs);
75790
75791 if (!err) {
75792 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75793 case MCAST_JOIN_GROUP:
75794 case MCAST_LEAVE_GROUP:
75795 {
75796 - struct compat_group_req __user *gr32 = (void *)optval;
75797 + struct compat_group_req __user *gr32 = (void __user *)optval;
75798 struct group_req __user *kgr =
75799 compat_alloc_user_space(sizeof(struct group_req));
75800 u32 interface;
75801 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75802 case MCAST_BLOCK_SOURCE:
75803 case MCAST_UNBLOCK_SOURCE:
75804 {
75805 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75806 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75807 struct group_source_req __user *kgsr = compat_alloc_user_space(
75808 sizeof(struct group_source_req));
75809 u32 interface;
75810 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75811 }
75812 case MCAST_MSFILTER:
75813 {
75814 - struct compat_group_filter __user *gf32 = (void *)optval;
75815 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75816 struct group_filter __user *kgf;
75817 u32 interface, fmode, numsrc;
75818
75819 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75820 char __user *optval, int __user *optlen,
75821 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75822 {
75823 - struct compat_group_filter __user *gf32 = (void *)optval;
75824 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75825 struct group_filter __user *kgf;
75826 int __user *koptlen;
75827 u32 interface, fmode, numsrc;
75828 diff --git a/net/core/datagram.c b/net/core/datagram.c
75829 index ae6acf6..d5c8f66 100644
75830 --- a/net/core/datagram.c
75831 +++ b/net/core/datagram.c
75832 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75833 }
75834
75835 kfree_skb(skb);
75836 - atomic_inc(&sk->sk_drops);
75837 + atomic_inc_unchecked(&sk->sk_drops);
75838 sk_mem_reclaim_partial(sk);
75839
75840 return err;
75841 diff --git a/net/core/dev.c b/net/core/dev.c
75842 index a000840..566cee1 100644
75843 --- a/net/core/dev.c
75844 +++ b/net/core/dev.c
75845 @@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75846 if (no_module && capable(CAP_NET_ADMIN))
75847 no_module = request_module("netdev-%s", name);
75848 if (no_module && capable(CAP_SYS_MODULE)) {
75849 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75850 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75851 +#else
75852 if (!request_module("%s", name))
75853 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75854 name);
75855 +#endif
75856 }
75857 }
75858 EXPORT_SYMBOL(dev_load);
75859 @@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75860 {
75861 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75862 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75863 - atomic_long_inc(&dev->rx_dropped);
75864 + atomic_long_inc_unchecked(&dev->rx_dropped);
75865 kfree_skb(skb);
75866 return NET_RX_DROP;
75867 }
75868 @@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75869 nf_reset(skb);
75870
75871 if (unlikely(!is_skb_forwardable(dev, skb))) {
75872 - atomic_long_inc(&dev->rx_dropped);
75873 + atomic_long_inc_unchecked(&dev->rx_dropped);
75874 kfree_skb(skb);
75875 return NET_RX_DROP;
75876 }
75877 @@ -2041,7 +2045,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75878
75879 struct dev_gso_cb {
75880 void (*destructor)(struct sk_buff *skb);
75881 -};
75882 +} __no_const;
75883
75884 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75885
75886 @@ -2876,7 +2880,7 @@ enqueue:
75887
75888 local_irq_restore(flags);
75889
75890 - atomic_long_inc(&skb->dev->rx_dropped);
75891 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75892 kfree_skb(skb);
75893 return NET_RX_DROP;
75894 }
75895 @@ -2948,7 +2952,7 @@ int netif_rx_ni(struct sk_buff *skb)
75896 }
75897 EXPORT_SYMBOL(netif_rx_ni);
75898
75899 -static void net_tx_action(struct softirq_action *h)
75900 +static void net_tx_action(void)
75901 {
75902 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75903
75904 @@ -3235,7 +3239,7 @@ ncls:
75905 if (pt_prev) {
75906 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75907 } else {
75908 - atomic_long_inc(&skb->dev->rx_dropped);
75909 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75910 kfree_skb(skb);
75911 /* Jamal, now you will not able to escape explaining
75912 * me how you were going to use this. :-)
75913 @@ -3800,7 +3804,7 @@ void netif_napi_del(struct napi_struct *napi)
75914 }
75915 EXPORT_SYMBOL(netif_napi_del);
75916
75917 -static void net_rx_action(struct softirq_action *h)
75918 +static void net_rx_action(void)
75919 {
75920 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75921 unsigned long time_limit = jiffies + 2;
75922 @@ -4270,8 +4274,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75923 else
75924 seq_printf(seq, "%04x", ntohs(pt->type));
75925
75926 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75927 + seq_printf(seq, " %-8s %p\n",
75928 + pt->dev ? pt->dev->name : "", NULL);
75929 +#else
75930 seq_printf(seq, " %-8s %pF\n",
75931 pt->dev ? pt->dev->name : "", pt->func);
75932 +#endif
75933 }
75934
75935 return 0;
75936 @@ -5823,7 +5832,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75937 } else {
75938 netdev_stats_to_stats64(storage, &dev->stats);
75939 }
75940 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75941 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75942 return storage;
75943 }
75944 EXPORT_SYMBOL(dev_get_stats);
75945 diff --git a/net/core/flow.c b/net/core/flow.c
75946 index e318c7e..168b1d0 100644
75947 --- a/net/core/flow.c
75948 +++ b/net/core/flow.c
75949 @@ -61,7 +61,7 @@ struct flow_cache {
75950 struct timer_list rnd_timer;
75951 };
75952
75953 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75954 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75955 EXPORT_SYMBOL(flow_cache_genid);
75956 static struct flow_cache flow_cache_global;
75957 static struct kmem_cache *flow_cachep __read_mostly;
75958 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75959
75960 static int flow_entry_valid(struct flow_cache_entry *fle)
75961 {
75962 - if (atomic_read(&flow_cache_genid) != fle->genid)
75963 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75964 return 0;
75965 if (fle->object && !fle->object->ops->check(fle->object))
75966 return 0;
75967 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75968 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75969 fcp->hash_count++;
75970 }
75971 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75972 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75973 flo = fle->object;
75974 if (!flo)
75975 goto ret_object;
75976 @@ -280,7 +280,7 @@ nocache:
75977 }
75978 flo = resolver(net, key, family, dir, flo, ctx);
75979 if (fle) {
75980 - fle->genid = atomic_read(&flow_cache_genid);
75981 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75982 if (!IS_ERR(flo))
75983 fle->object = flo;
75984 else
75985 diff --git a/net/core/iovec.c b/net/core/iovec.c
75986 index 7e7aeb0..2a998cb 100644
75987 --- a/net/core/iovec.c
75988 +++ b/net/core/iovec.c
75989 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75990 if (m->msg_namelen) {
75991 if (mode == VERIFY_READ) {
75992 void __user *namep;
75993 - namep = (void __user __force *) m->msg_name;
75994 + namep = (void __force_user *) m->msg_name;
75995 err = move_addr_to_kernel(namep, m->msg_namelen,
75996 address);
75997 if (err < 0)
75998 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75999 }
76000
76001 size = m->msg_iovlen * sizeof(struct iovec);
76002 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76003 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76004 return -EFAULT;
76005
76006 m->msg_iov = iov;
76007 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76008 index 6c50ac0..6b4c038 100644
76009 --- a/net/core/rtnetlink.c
76010 +++ b/net/core/rtnetlink.c
76011 @@ -58,7 +58,7 @@ struct rtnl_link {
76012 rtnl_doit_func doit;
76013 rtnl_dumpit_func dumpit;
76014 rtnl_calcit_func calcit;
76015 -};
76016 +} __no_const;
76017
76018 static DEFINE_MUTEX(rtnl_mutex);
76019
76020 diff --git a/net/core/scm.c b/net/core/scm.c
76021 index 611c5ef..88f6d6d 100644
76022 --- a/net/core/scm.c
76023 +++ b/net/core/scm.c
76024 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
76025 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76026 {
76027 struct cmsghdr __user *cm
76028 - = (__force struct cmsghdr __user *)msg->msg_control;
76029 + = (struct cmsghdr __force_user *)msg->msg_control;
76030 struct cmsghdr cmhdr;
76031 int cmlen = CMSG_LEN(len);
76032 int err;
76033 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76034 err = -EFAULT;
76035 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76036 goto out;
76037 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76038 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76039 goto out;
76040 cmlen = CMSG_SPACE(len);
76041 if (msg->msg_controllen < cmlen)
76042 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
76043 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76044 {
76045 struct cmsghdr __user *cm
76046 - = (__force struct cmsghdr __user*)msg->msg_control;
76047 + = (struct cmsghdr __force_user *)msg->msg_control;
76048
76049 int fdmax = 0;
76050 int fdnum = scm->fp->count;
76051 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76052 if (fdnum < fdmax)
76053 fdmax = fdnum;
76054
76055 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76056 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76057 i++, cmfptr++)
76058 {
76059 int new_fd;
76060 diff --git a/net/core/sock.c b/net/core/sock.c
76061 index 9e5b71f..66dec30 100644
76062 --- a/net/core/sock.c
76063 +++ b/net/core/sock.c
76064 @@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76065 struct sk_buff_head *list = &sk->sk_receive_queue;
76066
76067 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76068 - atomic_inc(&sk->sk_drops);
76069 + atomic_inc_unchecked(&sk->sk_drops);
76070 trace_sock_rcvqueue_full(sk, skb);
76071 return -ENOMEM;
76072 }
76073 @@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76074 return err;
76075
76076 if (!sk_rmem_schedule(sk, skb->truesize)) {
76077 - atomic_inc(&sk->sk_drops);
76078 + atomic_inc_unchecked(&sk->sk_drops);
76079 return -ENOBUFS;
76080 }
76081
76082 @@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76083 skb_dst_force(skb);
76084
76085 spin_lock_irqsave(&list->lock, flags);
76086 - skb->dropcount = atomic_read(&sk->sk_drops);
76087 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76088 __skb_queue_tail(list, skb);
76089 spin_unlock_irqrestore(&list->lock, flags);
76090
76091 @@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76092 skb->dev = NULL;
76093
76094 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76095 - atomic_inc(&sk->sk_drops);
76096 + atomic_inc_unchecked(&sk->sk_drops);
76097 goto discard_and_relse;
76098 }
76099 if (nested)
76100 @@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76101 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76102 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76103 bh_unlock_sock(sk);
76104 - atomic_inc(&sk->sk_drops);
76105 + atomic_inc_unchecked(&sk->sk_drops);
76106 goto discard_and_relse;
76107 }
76108
76109 @@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76110 if (len > sizeof(peercred))
76111 len = sizeof(peercred);
76112 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
76113 - if (copy_to_user(optval, &peercred, len))
76114 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
76115 return -EFAULT;
76116 goto lenout;
76117 }
76118 @@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76119 return -ENOTCONN;
76120 if (lv < len)
76121 return -EINVAL;
76122 - if (copy_to_user(optval, address, len))
76123 + if (len > sizeof(address) || copy_to_user(optval, address, len))
76124 return -EFAULT;
76125 goto lenout;
76126 }
76127 @@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76128
76129 if (len > lv)
76130 len = lv;
76131 - if (copy_to_user(optval, &v, len))
76132 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76133 return -EFAULT;
76134 lenout:
76135 if (put_user(len, optlen))
76136 @@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76137 */
76138 smp_wmb();
76139 atomic_set(&sk->sk_refcnt, 1);
76140 - atomic_set(&sk->sk_drops, 0);
76141 + atomic_set_unchecked(&sk->sk_drops, 0);
76142 }
76143 EXPORT_SYMBOL(sock_init_data);
76144
76145 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76146 index 5fd1467..8b70900 100644
76147 --- a/net/core/sock_diag.c
76148 +++ b/net/core/sock_diag.c
76149 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76150
76151 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76152 {
76153 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76154 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76155 cookie[1] != INET_DIAG_NOCOOKIE) &&
76156 ((u32)(unsigned long)sk != cookie[0] ||
76157 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76158 return -ESTALE;
76159 else
76160 +#endif
76161 return 0;
76162 }
76163 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76164
76165 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76166 {
76167 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76168 + cookie[0] = 0;
76169 + cookie[1] = 0;
76170 +#else
76171 cookie[0] = (u32)(unsigned long)sk;
76172 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76173 +#endif
76174 }
76175 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76176
76177 diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
76178 index 75c3582..fb85d37 100644
76179 --- a/net/dccp/ccid.h
76180 +++ b/net/dccp/ccid.h
76181 @@ -246,7 +246,7 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
76182 u32 __user *optval, int __user *optlen)
76183 {
76184 int rc = -ENOPROTOOPT;
76185 - if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76186 + if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76187 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
76188 optval, optlen);
76189 return rc;
76190 @@ -257,7 +257,7 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
76191 u32 __user *optval, int __user *optlen)
76192 {
76193 int rc = -ENOPROTOOPT;
76194 - if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76195 + if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76196 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
76197 optval, optlen);
76198 return rc;
76199 diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
76200 index 8c67bed..ce0d140 100644
76201 --- a/net/dccp/ccids/ccid3.c
76202 +++ b/net/dccp/ccids/ccid3.c
76203 @@ -531,6 +531,7 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
76204 case DCCP_SOCKOPT_CCID_TX_INFO:
76205 if (len < sizeof(tfrc))
76206 return -EINVAL;
76207 + memset(&tfrc, 0, sizeof(tfrc));
76208 tfrc.tfrctx_x = hc->tx_x;
76209 tfrc.tfrctx_x_recv = hc->tx_x_recv;
76210 tfrc.tfrctx_x_calc = hc->tx_x_calc;
76211 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76212 index a55eecc..dd8428c 100644
76213 --- a/net/decnet/sysctl_net_decnet.c
76214 +++ b/net/decnet/sysctl_net_decnet.c
76215 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76216
76217 if (len > *lenp) len = *lenp;
76218
76219 - if (copy_to_user(buffer, addr, len))
76220 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76221 return -EFAULT;
76222
76223 *lenp = len;
76224 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76225
76226 if (len > *lenp) len = *lenp;
76227
76228 - if (copy_to_user(buffer, devname, len))
76229 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76230 return -EFAULT;
76231
76232 *lenp = len;
76233 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76234 index 3854411..2201a94 100644
76235 --- a/net/ipv4/fib_frontend.c
76236 +++ b/net/ipv4/fib_frontend.c
76237 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76238 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76239 fib_sync_up(dev);
76240 #endif
76241 - atomic_inc(&net->ipv4.dev_addr_genid);
76242 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76243 rt_cache_flush(dev_net(dev), -1);
76244 break;
76245 case NETDEV_DOWN:
76246 fib_del_ifaddr(ifa, NULL);
76247 - atomic_inc(&net->ipv4.dev_addr_genid);
76248 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76249 if (ifa->ifa_dev->ifa_list == NULL) {
76250 /* Last address was deleted from this interface.
76251 * Disable IP.
76252 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76253 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76254 fib_sync_up(dev);
76255 #endif
76256 - atomic_inc(&net->ipv4.dev_addr_genid);
76257 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76258 rt_cache_flush(dev_net(dev), -1);
76259 break;
76260 case NETDEV_DOWN:
76261 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76262 index e5b7182..570a90e 100644
76263 --- a/net/ipv4/fib_semantics.c
76264 +++ b/net/ipv4/fib_semantics.c
76265 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76266 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76267 nh->nh_gw,
76268 nh->nh_parent->fib_scope);
76269 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76270 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76271
76272 return nh->nh_saddr;
76273 }
76274 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76275 index 7880af9..70f92a3 100644
76276 --- a/net/ipv4/inet_hashtables.c
76277 +++ b/net/ipv4/inet_hashtables.c
76278 @@ -18,12 +18,15 @@
76279 #include <linux/sched.h>
76280 #include <linux/slab.h>
76281 #include <linux/wait.h>
76282 +#include <linux/security.h>
76283
76284 #include <net/inet_connection_sock.h>
76285 #include <net/inet_hashtables.h>
76286 #include <net/secure_seq.h>
76287 #include <net/ip.h>
76288
76289 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76290 +
76291 /*
76292 * Allocate and initialize a new local port bind bucket.
76293 * The bindhash mutex for snum's hash chain must be held here.
76294 @@ -530,6 +533,8 @@ ok:
76295 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76296 spin_unlock(&head->lock);
76297
76298 + gr_update_task_in_ip_table(current, inet_sk(sk));
76299 +
76300 if (tw) {
76301 inet_twsk_deschedule(tw, death_row);
76302 while (twrefcnt) {
76303 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76304 index dfba343..c827d50 100644
76305 --- a/net/ipv4/inetpeer.c
76306 +++ b/net/ipv4/inetpeer.c
76307 @@ -487,8 +487,8 @@ relookup:
76308 if (p) {
76309 p->daddr = *daddr;
76310 atomic_set(&p->refcnt, 1);
76311 - atomic_set(&p->rid, 0);
76312 - atomic_set(&p->ip_id_count,
76313 + atomic_set_unchecked(&p->rid, 0);
76314 + atomic_set_unchecked(&p->ip_id_count,
76315 (daddr->family == AF_INET) ?
76316 secure_ip_id(daddr->addr.a4) :
76317 secure_ipv6_id(daddr->addr.a6));
76318 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76319 index 9dbd3dd..0c59fb2 100644
76320 --- a/net/ipv4/ip_fragment.c
76321 +++ b/net/ipv4/ip_fragment.c
76322 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76323 return 0;
76324
76325 start = qp->rid;
76326 - end = atomic_inc_return(&peer->rid);
76327 + end = atomic_inc_return_unchecked(&peer->rid);
76328 qp->rid = end;
76329
76330 rc = qp->q.fragments && (end - start) > max;
76331 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76332 index 0d11f23..2bb3f64 100644
76333 --- a/net/ipv4/ip_sockglue.c
76334 +++ b/net/ipv4/ip_sockglue.c
76335 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76336 len = min_t(unsigned int, len, opt->optlen);
76337 if (put_user(len, optlen))
76338 return -EFAULT;
76339 - if (copy_to_user(optval, opt->__data, len))
76340 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76341 + copy_to_user(optval, opt->__data, len))
76342 return -EFAULT;
76343 return 0;
76344 }
76345 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76346 if (sk->sk_type != SOCK_STREAM)
76347 return -ENOPROTOOPT;
76348
76349 - msg.msg_control = optval;
76350 + msg.msg_control = (void __force_kernel *)optval;
76351 msg.msg_controllen = len;
76352 msg.msg_flags = flags;
76353
76354 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76355 index 67e8a6b..386764d 100644
76356 --- a/net/ipv4/ipconfig.c
76357 +++ b/net/ipv4/ipconfig.c
76358 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76359
76360 mm_segment_t oldfs = get_fs();
76361 set_fs(get_ds());
76362 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76363 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76364 set_fs(oldfs);
76365 return res;
76366 }
76367 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76368
76369 mm_segment_t oldfs = get_fs();
76370 set_fs(get_ds());
76371 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76372 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76373 set_fs(oldfs);
76374 return res;
76375 }
76376 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76377
76378 mm_segment_t oldfs = get_fs();
76379 set_fs(get_ds());
76380 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76381 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76382 set_fs(oldfs);
76383 return res;
76384 }
76385 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76386 index 2c00e8b..45b3bdd 100644
76387 --- a/net/ipv4/ping.c
76388 +++ b/net/ipv4/ping.c
76389 @@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76390 sk_rmem_alloc_get(sp),
76391 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76392 atomic_read(&sp->sk_refcnt), sp,
76393 - atomic_read(&sp->sk_drops), len);
76394 + atomic_read_unchecked(&sp->sk_drops), len);
76395 }
76396
76397 static int ping_seq_show(struct seq_file *seq, void *v)
76398 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76399 index 4032b81..625143c 100644
76400 --- a/net/ipv4/raw.c
76401 +++ b/net/ipv4/raw.c
76402 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76403 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76404 {
76405 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76406 - atomic_inc(&sk->sk_drops);
76407 + atomic_inc_unchecked(&sk->sk_drops);
76408 kfree_skb(skb);
76409 return NET_RX_DROP;
76410 }
76411 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
76412
76413 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76414 {
76415 + struct icmp_filter filter;
76416 +
76417 if (optlen > sizeof(struct icmp_filter))
76418 optlen = sizeof(struct icmp_filter);
76419 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76420 + if (copy_from_user(&filter, optval, optlen))
76421 return -EFAULT;
76422 + raw_sk(sk)->filter = filter;
76423 return 0;
76424 }
76425
76426 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76427 {
76428 int len, ret = -EFAULT;
76429 + struct icmp_filter filter;
76430
76431 if (get_user(len, optlen))
76432 goto out;
76433 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76434 if (len > sizeof(struct icmp_filter))
76435 len = sizeof(struct icmp_filter);
76436 ret = -EFAULT;
76437 - if (put_user(len, optlen) ||
76438 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76439 + filter = raw_sk(sk)->filter;
76440 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76441 goto out;
76442 ret = 0;
76443 out: return ret;
76444 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76445 sk_wmem_alloc_get(sp),
76446 sk_rmem_alloc_get(sp),
76447 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76448 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76449 + atomic_read(&sp->sk_refcnt),
76450 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76451 + NULL,
76452 +#else
76453 + sp,
76454 +#endif
76455 + atomic_read_unchecked(&sp->sk_drops));
76456 }
76457
76458 static int raw_seq_show(struct seq_file *seq, void *v)
76459 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76460 index 98b30d0..cfa3cf7 100644
76461 --- a/net/ipv4/route.c
76462 +++ b/net/ipv4/route.c
76463 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76464
76465 static inline int rt_genid(struct net *net)
76466 {
76467 - return atomic_read(&net->ipv4.rt_genid);
76468 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76469 }
76470
76471 #ifdef CONFIG_PROC_FS
76472 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76473 unsigned char shuffle;
76474
76475 get_random_bytes(&shuffle, sizeof(shuffle));
76476 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76477 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76478 inetpeer_invalidate_tree(AF_INET);
76479 }
76480
76481 @@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76482 error = rt->dst.error;
76483 if (peer) {
76484 inet_peer_refcheck(rt->peer);
76485 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76486 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76487 if (peer->tcp_ts_stamp) {
76488 ts = peer->tcp_ts;
76489 tsage = get_seconds() - peer->tcp_ts_stamp;
76490 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76491 index c8d28c4..e40f75a 100644
76492 --- a/net/ipv4/tcp_ipv4.c
76493 +++ b/net/ipv4/tcp_ipv4.c
76494 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76495 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76496
76497
76498 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76499 +extern int grsec_enable_blackhole;
76500 +#endif
76501 +
76502 #ifdef CONFIG_TCP_MD5SIG
76503 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76504 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76505 @@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76506 return 0;
76507
76508 reset:
76509 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76510 + if (!grsec_enable_blackhole)
76511 +#endif
76512 tcp_v4_send_reset(rsk, skb);
76513 discard:
76514 kfree_skb(skb);
76515 @@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76516 TCP_SKB_CB(skb)->sacked = 0;
76517
76518 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76519 - if (!sk)
76520 + if (!sk) {
76521 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76522 + ret = 1;
76523 +#endif
76524 goto no_tcp_socket;
76525 -
76526 + }
76527 process:
76528 - if (sk->sk_state == TCP_TIME_WAIT)
76529 + if (sk->sk_state == TCP_TIME_WAIT) {
76530 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76531 + ret = 2;
76532 +#endif
76533 goto do_time_wait;
76534 + }
76535
76536 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76537 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76538 @@ -1774,6 +1788,10 @@ no_tcp_socket:
76539 bad_packet:
76540 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76541 } else {
76542 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76543 + if (!grsec_enable_blackhole || (ret == 1 &&
76544 + (skb->dev->flags & IFF_LOOPBACK)))
76545 +#endif
76546 tcp_v4_send_reset(NULL, skb);
76547 }
76548
76549 @@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76550 0, /* non standard timer */
76551 0, /* open_requests have no inode */
76552 atomic_read(&sk->sk_refcnt),
76553 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76554 + NULL,
76555 +#else
76556 req,
76557 +#endif
76558 len);
76559 }
76560
76561 @@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76562 sock_i_uid(sk),
76563 icsk->icsk_probes_out,
76564 sock_i_ino(sk),
76565 - atomic_read(&sk->sk_refcnt), sk,
76566 + atomic_read(&sk->sk_refcnt),
76567 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76568 + NULL,
76569 +#else
76570 + sk,
76571 +#endif
76572 jiffies_to_clock_t(icsk->icsk_rto),
76573 jiffies_to_clock_t(icsk->icsk_ack.ato),
76574 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76575 @@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76576 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76577 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76578 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76579 - atomic_read(&tw->tw_refcnt), tw, len);
76580 + atomic_read(&tw->tw_refcnt),
76581 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76582 + NULL,
76583 +#else
76584 + tw,
76585 +#endif
76586 + len);
76587 }
76588
76589 #define TMPSZ 150
76590 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76591 index b85d9fe..4b0eed9 100644
76592 --- a/net/ipv4/tcp_minisocks.c
76593 +++ b/net/ipv4/tcp_minisocks.c
76594 @@ -27,6 +27,10 @@
76595 #include <net/inet_common.h>
76596 #include <net/xfrm.h>
76597
76598 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76599 +extern int grsec_enable_blackhole;
76600 +#endif
76601 +
76602 int sysctl_tcp_syncookies __read_mostly = 1;
76603 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76604
76605 @@ -754,6 +758,10 @@ listen_overflow:
76606
76607 embryonic_reset:
76608 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76609 +
76610 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76611 + if (!grsec_enable_blackhole)
76612 +#endif
76613 if (!(flg & TCP_FLAG_RST))
76614 req->rsk_ops->send_reset(sk, skb);
76615
76616 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76617 index 4526fe6..1a34e43 100644
76618 --- a/net/ipv4/tcp_probe.c
76619 +++ b/net/ipv4/tcp_probe.c
76620 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76621 if (cnt + width >= len)
76622 break;
76623
76624 - if (copy_to_user(buf + cnt, tbuf, width))
76625 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76626 return -EFAULT;
76627 cnt += width;
76628 }
76629 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76630 index e911e6c..d0a9356 100644
76631 --- a/net/ipv4/tcp_timer.c
76632 +++ b/net/ipv4/tcp_timer.c
76633 @@ -22,6 +22,10 @@
76634 #include <linux/gfp.h>
76635 #include <net/tcp.h>
76636
76637 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76638 +extern int grsec_lastack_retries;
76639 +#endif
76640 +
76641 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76642 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76643 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76644 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76645 }
76646 }
76647
76648 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76649 + if ((sk->sk_state == TCP_LAST_ACK) &&
76650 + (grsec_lastack_retries > 0) &&
76651 + (grsec_lastack_retries < retry_until))
76652 + retry_until = grsec_lastack_retries;
76653 +#endif
76654 +
76655 if (retransmits_timed_out(sk, retry_until,
76656 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76657 /* Has it gone just too far? */
76658 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76659 index eaca736..60488ae 100644
76660 --- a/net/ipv4/udp.c
76661 +++ b/net/ipv4/udp.c
76662 @@ -87,6 +87,7 @@
76663 #include <linux/types.h>
76664 #include <linux/fcntl.h>
76665 #include <linux/module.h>
76666 +#include <linux/security.h>
76667 #include <linux/socket.h>
76668 #include <linux/sockios.h>
76669 #include <linux/igmp.h>
76670 @@ -110,6 +111,10 @@
76671 #include <linux/static_key.h>
76672 #include "udp_impl.h"
76673
76674 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76675 +extern int grsec_enable_blackhole;
76676 +#endif
76677 +
76678 struct udp_table udp_table __read_mostly;
76679 EXPORT_SYMBOL(udp_table);
76680
76681 @@ -568,6 +573,9 @@ found:
76682 return s;
76683 }
76684
76685 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76686 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76687 +
76688 /*
76689 * This routine is called by the ICMP module when it gets some
76690 * sort of error condition. If err < 0 then the socket should
76691 @@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76692 dport = usin->sin_port;
76693 if (dport == 0)
76694 return -EINVAL;
76695 +
76696 + err = gr_search_udp_sendmsg(sk, usin);
76697 + if (err)
76698 + return err;
76699 } else {
76700 if (sk->sk_state != TCP_ESTABLISHED)
76701 return -EDESTADDRREQ;
76702 +
76703 + err = gr_search_udp_sendmsg(sk, NULL);
76704 + if (err)
76705 + return err;
76706 +
76707 daddr = inet->inet_daddr;
76708 dport = inet->inet_dport;
76709 /* Open fast path for connected socket.
76710 @@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76711 udp_lib_checksum_complete(skb)) {
76712 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76713 IS_UDPLITE(sk));
76714 - atomic_inc(&sk->sk_drops);
76715 + atomic_inc_unchecked(&sk->sk_drops);
76716 __skb_unlink(skb, rcvq);
76717 __skb_queue_tail(&list_kill, skb);
76718 }
76719 @@ -1189,6 +1206,10 @@ try_again:
76720 if (!skb)
76721 goto out;
76722
76723 + err = gr_search_udp_recvmsg(sk, skb);
76724 + if (err)
76725 + goto out_free;
76726 +
76727 ulen = skb->len - sizeof(struct udphdr);
76728 copied = len;
76729 if (copied > ulen)
76730 @@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76731
76732 drop:
76733 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76734 - atomic_inc(&sk->sk_drops);
76735 + atomic_inc_unchecked(&sk->sk_drops);
76736 kfree_skb(skb);
76737 return -1;
76738 }
76739 @@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76740 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76741
76742 if (!skb1) {
76743 - atomic_inc(&sk->sk_drops);
76744 + atomic_inc_unchecked(&sk->sk_drops);
76745 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76746 IS_UDPLITE(sk));
76747 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76748 @@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76749 goto csum_error;
76750
76751 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76752 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76753 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76754 +#endif
76755 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76756
76757 /*
76758 @@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76759 sk_wmem_alloc_get(sp),
76760 sk_rmem_alloc_get(sp),
76761 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76762 - atomic_read(&sp->sk_refcnt), sp,
76763 - atomic_read(&sp->sk_drops), len);
76764 + atomic_read(&sp->sk_refcnt),
76765 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76766 + NULL,
76767 +#else
76768 + sp,
76769 +#endif
76770 + atomic_read_unchecked(&sp->sk_drops), len);
76771 }
76772
76773 int udp4_seq_show(struct seq_file *seq, void *v)
76774 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76775 index 8f6411c..5767579 100644
76776 --- a/net/ipv6/addrconf.c
76777 +++ b/net/ipv6/addrconf.c
76778 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76779 p.iph.ihl = 5;
76780 p.iph.protocol = IPPROTO_IPV6;
76781 p.iph.ttl = 64;
76782 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76783 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76784
76785 if (ops->ndo_do_ioctl) {
76786 mm_segment_t oldfs = get_fs();
76787 diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
76788 index db1521f..ebb3314 100644
76789 --- a/net/ipv6/esp6.c
76790 +++ b/net/ipv6/esp6.c
76791 @@ -166,8 +166,6 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
76792 struct esp_data *esp = x->data;
76793
76794 /* skb is pure payload to encrypt */
76795 - err = -ENOMEM;
76796 -
76797 aead = esp->aead;
76798 alen = crypto_aead_authsize(aead);
76799
76800 @@ -202,8 +200,10 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
76801 }
76802
76803 tmp = esp_alloc_tmp(aead, nfrags + sglists, seqhilen);
76804 - if (!tmp)
76805 + if (!tmp) {
76806 + err = -ENOMEM;
76807 goto error;
76808 + }
76809
76810 seqhi = esp_tmp_seqhi(tmp);
76811 iv = esp_tmp_iv(aead, tmp, seqhilen);
76812 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76813 index e6cee52..cf47476 100644
76814 --- a/net/ipv6/inet6_connection_sock.c
76815 +++ b/net/ipv6/inet6_connection_sock.c
76816 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76817 #ifdef CONFIG_XFRM
76818 {
76819 struct rt6_info *rt = (struct rt6_info *)dst;
76820 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76821 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76822 }
76823 #endif
76824 }
76825 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76826 #ifdef CONFIG_XFRM
76827 if (dst) {
76828 struct rt6_info *rt = (struct rt6_info *)dst;
76829 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76830 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76831 __sk_dst_reset(sk);
76832 dst = NULL;
76833 }
76834 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76835 index ba6d13d..6899122 100644
76836 --- a/net/ipv6/ipv6_sockglue.c
76837 +++ b/net/ipv6/ipv6_sockglue.c
76838 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76839 if (sk->sk_type != SOCK_STREAM)
76840 return -ENOPROTOOPT;
76841
76842 - msg.msg_control = optval;
76843 + msg.msg_control = (void __force_kernel *)optval;
76844 msg.msg_controllen = len;
76845 msg.msg_flags = flags;
76846
76847 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76848 index 93d6983..8e54c4d 100644
76849 --- a/net/ipv6/raw.c
76850 +++ b/net/ipv6/raw.c
76851 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76852 {
76853 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76854 skb_checksum_complete(skb)) {
76855 - atomic_inc(&sk->sk_drops);
76856 + atomic_inc_unchecked(&sk->sk_drops);
76857 kfree_skb(skb);
76858 return NET_RX_DROP;
76859 }
76860 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76861 struct raw6_sock *rp = raw6_sk(sk);
76862
76863 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76864 - atomic_inc(&sk->sk_drops);
76865 + atomic_inc_unchecked(&sk->sk_drops);
76866 kfree_skb(skb);
76867 return NET_RX_DROP;
76868 }
76869 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76870
76871 if (inet->hdrincl) {
76872 if (skb_checksum_complete(skb)) {
76873 - atomic_inc(&sk->sk_drops);
76874 + atomic_inc_unchecked(&sk->sk_drops);
76875 kfree_skb(skb);
76876 return NET_RX_DROP;
76877 }
76878 @@ -602,7 +602,7 @@ out:
76879 return err;
76880 }
76881
76882 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76883 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76884 struct flowi6 *fl6, struct dst_entry **dstp,
76885 unsigned int flags)
76886 {
76887 @@ -914,12 +914,15 @@ do_confirm:
76888 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76889 char __user *optval, int optlen)
76890 {
76891 + struct icmp6_filter filter;
76892 +
76893 switch (optname) {
76894 case ICMPV6_FILTER:
76895 if (optlen > sizeof(struct icmp6_filter))
76896 optlen = sizeof(struct icmp6_filter);
76897 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76898 + if (copy_from_user(&filter, optval, optlen))
76899 return -EFAULT;
76900 + raw6_sk(sk)->filter = filter;
76901 return 0;
76902 default:
76903 return -ENOPROTOOPT;
76904 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76905 char __user *optval, int __user *optlen)
76906 {
76907 int len;
76908 + struct icmp6_filter filter;
76909
76910 switch (optname) {
76911 case ICMPV6_FILTER:
76912 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76913 len = sizeof(struct icmp6_filter);
76914 if (put_user(len, optlen))
76915 return -EFAULT;
76916 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76917 + filter = raw6_sk(sk)->filter;
76918 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76919 return -EFAULT;
76920 return 0;
76921 default:
76922 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76923 0, 0L, 0,
76924 sock_i_uid(sp), 0,
76925 sock_i_ino(sp),
76926 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76927 + atomic_read(&sp->sk_refcnt),
76928 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76929 + NULL,
76930 +#else
76931 + sp,
76932 +#endif
76933 + atomic_read_unchecked(&sp->sk_drops));
76934 }
76935
76936 static int raw6_seq_show(struct seq_file *seq, void *v)
76937 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76938 index 9df64a5..39875da 100644
76939 --- a/net/ipv6/tcp_ipv6.c
76940 +++ b/net/ipv6/tcp_ipv6.c
76941 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76942 }
76943 #endif
76944
76945 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76946 +extern int grsec_enable_blackhole;
76947 +#endif
76948 +
76949 static void tcp_v6_hash(struct sock *sk)
76950 {
76951 if (sk->sk_state != TCP_CLOSE) {
76952 @@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76953 return 0;
76954
76955 reset:
76956 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76957 + if (!grsec_enable_blackhole)
76958 +#endif
76959 tcp_v6_send_reset(sk, skb);
76960 discard:
76961 if (opt_skb)
76962 @@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76963 TCP_SKB_CB(skb)->sacked = 0;
76964
76965 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76966 - if (!sk)
76967 + if (!sk) {
76968 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76969 + ret = 1;
76970 +#endif
76971 goto no_tcp_socket;
76972 + }
76973
76974 process:
76975 - if (sk->sk_state == TCP_TIME_WAIT)
76976 + if (sk->sk_state == TCP_TIME_WAIT) {
76977 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76978 + ret = 2;
76979 +#endif
76980 goto do_time_wait;
76981 + }
76982
76983 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76984 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76985 @@ -1679,6 +1694,10 @@ no_tcp_socket:
76986 bad_packet:
76987 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76988 } else {
76989 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76990 + if (!grsec_enable_blackhole || (ret == 1 &&
76991 + (skb->dev->flags & IFF_LOOPBACK)))
76992 +#endif
76993 tcp_v6_send_reset(NULL, skb);
76994 }
76995
76996 @@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76997 uid,
76998 0, /* non standard timer */
76999 0, /* open_requests have no inode */
77000 - 0, req);
77001 + 0,
77002 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77003 + NULL
77004 +#else
77005 + req
77006 +#endif
77007 + );
77008 }
77009
77010 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77011 @@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77012 sock_i_uid(sp),
77013 icsk->icsk_probes_out,
77014 sock_i_ino(sp),
77015 - atomic_read(&sp->sk_refcnt), sp,
77016 + atomic_read(&sp->sk_refcnt),
77017 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77018 + NULL,
77019 +#else
77020 + sp,
77021 +#endif
77022 jiffies_to_clock_t(icsk->icsk_rto),
77023 jiffies_to_clock_t(icsk->icsk_ack.ato),
77024 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77025 @@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77026 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77027 tw->tw_substate, 0, 0,
77028 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77029 - atomic_read(&tw->tw_refcnt), tw);
77030 + atomic_read(&tw->tw_refcnt),
77031 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77032 + NULL
77033 +#else
77034 + tw
77035 +#endif
77036 + );
77037 }
77038
77039 static int tcp6_seq_show(struct seq_file *seq, void *v)
77040 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77041 index f05099f..ea613f0 100644
77042 --- a/net/ipv6/udp.c
77043 +++ b/net/ipv6/udp.c
77044 @@ -50,6 +50,10 @@
77045 #include <linux/seq_file.h>
77046 #include "udp_impl.h"
77047
77048 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77049 +extern int grsec_enable_blackhole;
77050 +#endif
77051 +
77052 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77053 {
77054 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77055 @@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77056 return rc;
77057 drop:
77058 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77059 - atomic_inc(&sk->sk_drops);
77060 + atomic_inc_unchecked(&sk->sk_drops);
77061 kfree_skb(skb);
77062 return -1;
77063 }
77064 @@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77065 if (likely(skb1 == NULL))
77066 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77067 if (!skb1) {
77068 - atomic_inc(&sk->sk_drops);
77069 + atomic_inc_unchecked(&sk->sk_drops);
77070 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77071 IS_UDPLITE(sk));
77072 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77073 @@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77074 goto discard;
77075
77076 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77077 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77078 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77079 +#endif
77080 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77081
77082 kfree_skb(skb);
77083 @@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77084 0, 0L, 0,
77085 sock_i_uid(sp), 0,
77086 sock_i_ino(sp),
77087 - atomic_read(&sp->sk_refcnt), sp,
77088 - atomic_read(&sp->sk_drops));
77089 + atomic_read(&sp->sk_refcnt),
77090 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77091 + NULL,
77092 +#else
77093 + sp,
77094 +#endif
77095 + atomic_read_unchecked(&sp->sk_drops));
77096 }
77097
77098 int udp6_seq_show(struct seq_file *seq, void *v)
77099 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77100 index 6b9d5a0..4dffaf1 100644
77101 --- a/net/irda/ircomm/ircomm_tty.c
77102 +++ b/net/irda/ircomm/ircomm_tty.c
77103 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77104 add_wait_queue(&self->open_wait, &wait);
77105
77106 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77107 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77108 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77109
77110 /* As far as I can see, we protect open_count - Jean II */
77111 spin_lock_irqsave(&self->spinlock, flags);
77112 if (!tty_hung_up_p(filp)) {
77113 extra_count = 1;
77114 - self->open_count--;
77115 + local_dec(&self->open_count);
77116 }
77117 spin_unlock_irqrestore(&self->spinlock, flags);
77118 - self->blocked_open++;
77119 + local_inc(&self->blocked_open);
77120
77121 while (1) {
77122 if (tty->termios->c_cflag & CBAUD) {
77123 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77124 }
77125
77126 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77127 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77128 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77129
77130 schedule();
77131 }
77132 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77133 if (extra_count) {
77134 /* ++ is not atomic, so this should be protected - Jean II */
77135 spin_lock_irqsave(&self->spinlock, flags);
77136 - self->open_count++;
77137 + local_inc(&self->open_count);
77138 spin_unlock_irqrestore(&self->spinlock, flags);
77139 }
77140 - self->blocked_open--;
77141 + local_dec(&self->blocked_open);
77142
77143 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77144 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77145 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77146
77147 if (!retval)
77148 self->flags |= ASYNC_NORMAL_ACTIVE;
77149 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77150 }
77151 /* ++ is not atomic, so this should be protected - Jean II */
77152 spin_lock_irqsave(&self->spinlock, flags);
77153 - self->open_count++;
77154 + local_inc(&self->open_count);
77155
77156 tty->driver_data = self;
77157 self->tty = tty;
77158 spin_unlock_irqrestore(&self->spinlock, flags);
77159
77160 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77161 - self->line, self->open_count);
77162 + self->line, local_read(&self->open_count));
77163
77164 /* Not really used by us, but lets do it anyway */
77165 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77166 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77167 return;
77168 }
77169
77170 - if ((tty->count == 1) && (self->open_count != 1)) {
77171 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77172 /*
77173 * Uh, oh. tty->count is 1, which means that the tty
77174 * structure will be freed. state->count should always
77175 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77176 */
77177 IRDA_DEBUG(0, "%s(), bad serial port count; "
77178 "tty->count is 1, state->count is %d\n", __func__ ,
77179 - self->open_count);
77180 - self->open_count = 1;
77181 + local_read(&self->open_count));
77182 + local_set(&self->open_count, 1);
77183 }
77184
77185 - if (--self->open_count < 0) {
77186 + if (local_dec_return(&self->open_count) < 0) {
77187 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77188 - __func__, self->line, self->open_count);
77189 - self->open_count = 0;
77190 + __func__, self->line, local_read(&self->open_count));
77191 + local_set(&self->open_count, 0);
77192 }
77193 - if (self->open_count) {
77194 + if (local_read(&self->open_count)) {
77195 spin_unlock_irqrestore(&self->spinlock, flags);
77196
77197 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77198 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77199 tty->closing = 0;
77200 self->tty = NULL;
77201
77202 - if (self->blocked_open) {
77203 + if (local_read(&self->blocked_open)) {
77204 if (self->close_delay)
77205 schedule_timeout_interruptible(self->close_delay);
77206 wake_up_interruptible(&self->open_wait);
77207 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77208 spin_lock_irqsave(&self->spinlock, flags);
77209 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77210 self->tty = NULL;
77211 - self->open_count = 0;
77212 + local_set(&self->open_count, 0);
77213 spin_unlock_irqrestore(&self->spinlock, flags);
77214
77215 wake_up_interruptible(&self->open_wait);
77216 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77217 seq_putc(m, '\n');
77218
77219 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77220 - seq_printf(m, "Open count: %d\n", self->open_count);
77221 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77222 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77223 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77224
77225 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77226 index cd6f7a9..e63fe89 100644
77227 --- a/net/iucv/af_iucv.c
77228 +++ b/net/iucv/af_iucv.c
77229 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77230
77231 write_lock_bh(&iucv_sk_list.lock);
77232
77233 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77234 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77235 while (__iucv_get_sock_by_name(name)) {
77236 sprintf(name, "%08x",
77237 - atomic_inc_return(&iucv_sk_list.autobind_name));
77238 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77239 }
77240
77241 write_unlock_bh(&iucv_sk_list.lock);
77242 diff --git a/net/key/af_key.c b/net/key/af_key.c
77243 index 34e4185..8823368 100644
77244 --- a/net/key/af_key.c
77245 +++ b/net/key/af_key.c
77246 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77247 static u32 get_acqseq(void)
77248 {
77249 u32 res;
77250 - static atomic_t acqseq;
77251 + static atomic_unchecked_t acqseq;
77252
77253 do {
77254 - res = atomic_inc_return(&acqseq);
77255 + res = atomic_inc_return_unchecked(&acqseq);
77256 } while (!res);
77257 return res;
77258 }
77259 diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
77260 index 35e1e4b..9275471 100644
77261 --- a/net/l2tp/l2tp_ip6.c
77262 +++ b/net/l2tp/l2tp_ip6.c
77263 @@ -410,6 +410,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr,
77264 lsa->l2tp_family = AF_INET6;
77265 lsa->l2tp_flowinfo = 0;
77266 lsa->l2tp_scope_id = 0;
77267 + lsa->l2tp_unused = 0;
77268 if (peer) {
77269 if (!lsk->peer_conn_id)
77270 return -ENOTCONN;
77271 diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
77272 index fe5453c..a13c3e23 100644
77273 --- a/net/llc/af_llc.c
77274 +++ b/net/llc/af_llc.c
77275 @@ -969,14 +969,13 @@ static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
77276 struct sockaddr_llc sllc;
77277 struct sock *sk = sock->sk;
77278 struct llc_sock *llc = llc_sk(sk);
77279 - int rc = 0;
77280 + int rc = -EBADF;
77281
77282 memset(&sllc, 0, sizeof(sllc));
77283 lock_sock(sk);
77284 if (sock_flag(sk, SOCK_ZAPPED))
77285 goto out;
77286 *uaddrlen = sizeof(sllc);
77287 - memset(uaddr, 0, *uaddrlen);
77288 if (peer) {
77289 rc = -ENOTCONN;
77290 if (sk->sk_state != TCP_ESTABLISHED)
77291 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77292 index 3f3cd50..d2cf249 100644
77293 --- a/net/mac80211/ieee80211_i.h
77294 +++ b/net/mac80211/ieee80211_i.h
77295 @@ -28,6 +28,7 @@
77296 #include <net/ieee80211_radiotap.h>
77297 #include <net/cfg80211.h>
77298 #include <net/mac80211.h>
77299 +#include <asm/local.h>
77300 #include "key.h"
77301 #include "sta_info.h"
77302
77303 @@ -863,7 +864,7 @@ struct ieee80211_local {
77304 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77305 spinlock_t queue_stop_reason_lock;
77306
77307 - int open_count;
77308 + local_t open_count;
77309 int monitors, cooked_mntrs;
77310 /* number of interfaces with corresponding FIF_ flags */
77311 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77312 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77313 index 8664111..1d6a065 100644
77314 --- a/net/mac80211/iface.c
77315 +++ b/net/mac80211/iface.c
77316 @@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77317 break;
77318 }
77319
77320 - if (local->open_count == 0) {
77321 + if (local_read(&local->open_count) == 0) {
77322 res = drv_start(local);
77323 if (res)
77324 goto err_del_bss;
77325 @@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77326 break;
77327 }
77328
77329 - if (local->monitors == 0 && local->open_count == 0) {
77330 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77331 res = ieee80211_add_virtual_monitor(local);
77332 if (res)
77333 goto err_stop;
77334 @@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77335 mutex_unlock(&local->mtx);
77336
77337 if (coming_up)
77338 - local->open_count++;
77339 + local_inc(&local->open_count);
77340
77341 if (hw_reconf_flags)
77342 ieee80211_hw_config(local, hw_reconf_flags);
77343 @@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77344 err_del_interface:
77345 drv_remove_interface(local, sdata);
77346 err_stop:
77347 - if (!local->open_count)
77348 + if (!local_read(&local->open_count))
77349 drv_stop(local);
77350 err_del_bss:
77351 sdata->bss = NULL;
77352 @@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77353 }
77354
77355 if (going_down)
77356 - local->open_count--;
77357 + local_dec(&local->open_count);
77358
77359 switch (sdata->vif.type) {
77360 case NL80211_IFTYPE_AP_VLAN:
77361 @@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77362
77363 ieee80211_recalc_ps(local, -1);
77364
77365 - if (local->open_count == 0) {
77366 + if (local_read(&local->open_count) == 0) {
77367 if (local->ops->napi_poll)
77368 napi_disable(&local->napi);
77369 ieee80211_clear_tx_pending(local);
77370 @@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77371 }
77372 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77373
77374 - if (local->monitors == local->open_count && local->monitors > 0)
77375 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77376 ieee80211_add_virtual_monitor(local);
77377 }
77378
77379 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77380 index f5548e9..474a15f 100644
77381 --- a/net/mac80211/main.c
77382 +++ b/net/mac80211/main.c
77383 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77384 local->hw.conf.power_level = power;
77385 }
77386
77387 - if (changed && local->open_count) {
77388 + if (changed && local_read(&local->open_count)) {
77389 ret = drv_config(local, changed);
77390 /*
77391 * Goal:
77392 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77393 index af1c4e2..24dbbe3 100644
77394 --- a/net/mac80211/pm.c
77395 +++ b/net/mac80211/pm.c
77396 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77397 struct ieee80211_sub_if_data *sdata;
77398 struct sta_info *sta;
77399
77400 - if (!local->open_count)
77401 + if (!local_read(&local->open_count))
77402 goto suspend;
77403
77404 ieee80211_scan_cancel(local);
77405 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77406 cancel_work_sync(&local->dynamic_ps_enable_work);
77407 del_timer_sync(&local->dynamic_ps_timer);
77408
77409 - local->wowlan = wowlan && local->open_count;
77410 + local->wowlan = wowlan && local_read(&local->open_count);
77411 if (local->wowlan) {
77412 int err = drv_suspend(local, wowlan);
77413 if (err < 0) {
77414 @@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77415 drv_remove_interface(local, sdata);
77416
77417 /* stop hardware - this must stop RX */
77418 - if (local->open_count)
77419 + if (local_read(&local->open_count))
77420 ieee80211_stop_device(local);
77421
77422 suspend:
77423 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77424 index 3313c11..bec9f17 100644
77425 --- a/net/mac80211/rate.c
77426 +++ b/net/mac80211/rate.c
77427 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77428
77429 ASSERT_RTNL();
77430
77431 - if (local->open_count)
77432 + if (local_read(&local->open_count))
77433 return -EBUSY;
77434
77435 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77436 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77437 index c97a065..ff61928 100644
77438 --- a/net/mac80211/rc80211_pid_debugfs.c
77439 +++ b/net/mac80211/rc80211_pid_debugfs.c
77440 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77441
77442 spin_unlock_irqrestore(&events->lock, status);
77443
77444 - if (copy_to_user(buf, pb, p))
77445 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77446 return -EFAULT;
77447
77448 return p;
77449 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77450 index f564b5e..22fee47 100644
77451 --- a/net/mac80211/util.c
77452 +++ b/net/mac80211/util.c
77453 @@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77454 }
77455 #endif
77456 /* everything else happens only if HW was up & running */
77457 - if (!local->open_count)
77458 + if (!local_read(&local->open_count))
77459 goto wake_up;
77460
77461 /*
77462 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77463 index 209c1ed..39484dc 100644
77464 --- a/net/netfilter/Kconfig
77465 +++ b/net/netfilter/Kconfig
77466 @@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
77467
77468 To compile it as a module, choose M here. If unsure, say N.
77469
77470 +config NETFILTER_XT_MATCH_GRADM
77471 + tristate '"gradm" match support'
77472 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77473 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77474 + ---help---
77475 + The gradm match allows to match on grsecurity RBAC being enabled.
77476 + It is useful when iptables rules are applied early on bootup to
77477 + prevent connections to the machine (except from a trusted host)
77478 + while the RBAC system is disabled.
77479 +
77480 config NETFILTER_XT_MATCH_HASHLIMIT
77481 tristate '"hashlimit" match support'
77482 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77483 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77484 index 4e7960c..89e48d4 100644
77485 --- a/net/netfilter/Makefile
77486 +++ b/net/netfilter/Makefile
77487 @@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77488 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77489 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77490 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77491 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77492 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77493 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77494 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77495 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77496 index 1548df9..98ad9b4 100644
77497 --- a/net/netfilter/ipvs/ip_vs_conn.c
77498 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77499 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77500 /* Increase the refcnt counter of the dest */
77501 atomic_inc(&dest->refcnt);
77502
77503 - conn_flags = atomic_read(&dest->conn_flags);
77504 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77505 if (cp->protocol != IPPROTO_UDP)
77506 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77507 flags = cp->flags;
77508 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77509 atomic_set(&cp->refcnt, 1);
77510
77511 atomic_set(&cp->n_control, 0);
77512 - atomic_set(&cp->in_pkts, 0);
77513 + atomic_set_unchecked(&cp->in_pkts, 0);
77514
77515 atomic_inc(&ipvs->conn_count);
77516 if (flags & IP_VS_CONN_F_NO_CPORT)
77517 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77518
77519 /* Don't drop the entry if its number of incoming packets is not
77520 located in [0, 8] */
77521 - i = atomic_read(&cp->in_pkts);
77522 + i = atomic_read_unchecked(&cp->in_pkts);
77523 if (i > 8 || i < 0) return 0;
77524
77525 if (!todrop_rate[i]) return 0;
77526 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77527 index a54b018c..07e0120 100644
77528 --- a/net/netfilter/ipvs/ip_vs_core.c
77529 +++ b/net/netfilter/ipvs/ip_vs_core.c
77530 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77531 ret = cp->packet_xmit(skb, cp, pd->pp);
77532 /* do not touch skb anymore */
77533
77534 - atomic_inc(&cp->in_pkts);
77535 + atomic_inc_unchecked(&cp->in_pkts);
77536 ip_vs_conn_put(cp);
77537 return ret;
77538 }
77539 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77540 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77541 pkts = sysctl_sync_threshold(ipvs);
77542 else
77543 - pkts = atomic_add_return(1, &cp->in_pkts);
77544 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77545
77546 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77547 ip_vs_sync_conn(net, cp, pkts);
77548 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77549 index 84444dd..f91c066 100644
77550 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77551 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77552 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77553 ip_vs_rs_hash(ipvs, dest);
77554 write_unlock_bh(&ipvs->rs_lock);
77555 }
77556 - atomic_set(&dest->conn_flags, conn_flags);
77557 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77558
77559 /* bind the service */
77560 if (!dest->svc) {
77561 @@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77562 " %-7s %-6d %-10d %-10d\n",
77563 &dest->addr.in6,
77564 ntohs(dest->port),
77565 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77566 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77567 atomic_read(&dest->weight),
77568 atomic_read(&dest->activeconns),
77569 atomic_read(&dest->inactconns));
77570 @@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77571 "%-7s %-6d %-10d %-10d\n",
77572 ntohl(dest->addr.ip),
77573 ntohs(dest->port),
77574 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77575 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77576 atomic_read(&dest->weight),
77577 atomic_read(&dest->activeconns),
77578 atomic_read(&dest->inactconns));
77579 @@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77580
77581 entry.addr = dest->addr.ip;
77582 entry.port = dest->port;
77583 - entry.conn_flags = atomic_read(&dest->conn_flags);
77584 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77585 entry.weight = atomic_read(&dest->weight);
77586 entry.u_threshold = dest->u_threshold;
77587 entry.l_threshold = dest->l_threshold;
77588 @@ -2759,6 +2759,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77589 {
77590 struct ip_vs_timeout_user t;
77591
77592 + memset(&t, 0, sizeof(t));
77593 __ip_vs_get_timeouts(net, &t);
77594 if (copy_to_user(user, &t, sizeof(t)) != 0)
77595 ret = -EFAULT;
77596 @@ -3089,7 +3090,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77597 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77598 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77599 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77600 - (atomic_read(&dest->conn_flags) &
77601 + (atomic_read_unchecked(&dest->conn_flags) &
77602 IP_VS_CONN_F_FWD_MASK)) ||
77603 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77604 atomic_read(&dest->weight)) ||
77605 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77606 index effa10c..9058928 100644
77607 --- a/net/netfilter/ipvs/ip_vs_sync.c
77608 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77609 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77610 cp = cp->control;
77611 if (cp) {
77612 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77613 - pkts = atomic_add_return(1, &cp->in_pkts);
77614 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77615 else
77616 pkts = sysctl_sync_threshold(ipvs);
77617 ip_vs_sync_conn(net, cp->control, pkts);
77618 @@ -758,7 +758,7 @@ control:
77619 if (!cp)
77620 return;
77621 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77622 - pkts = atomic_add_return(1, &cp->in_pkts);
77623 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77624 else
77625 pkts = sysctl_sync_threshold(ipvs);
77626 goto sloop;
77627 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77628
77629 if (opt)
77630 memcpy(&cp->in_seq, opt, sizeof(*opt));
77631 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77632 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77633 cp->state = state;
77634 cp->old_state = cp->state;
77635 /*
77636 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77637 index 7fd66de..e6fb361 100644
77638 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77639 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77640 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77641 else
77642 rc = NF_ACCEPT;
77643 /* do not touch skb anymore */
77644 - atomic_inc(&cp->in_pkts);
77645 + atomic_inc_unchecked(&cp->in_pkts);
77646 goto out;
77647 }
77648
77649 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77650 else
77651 rc = NF_ACCEPT;
77652 /* do not touch skb anymore */
77653 - atomic_inc(&cp->in_pkts);
77654 + atomic_inc_unchecked(&cp->in_pkts);
77655 goto out;
77656 }
77657
77658 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77659 index ac3af97..c134c21 100644
77660 --- a/net/netfilter/nf_conntrack_core.c
77661 +++ b/net/netfilter/nf_conntrack_core.c
77662 @@ -1530,6 +1530,10 @@ err_proto:
77663 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77664 #define DYING_NULLS_VAL ((1<<30)+1)
77665
77666 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77667 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77668 +#endif
77669 +
77670 static int nf_conntrack_init_net(struct net *net)
77671 {
77672 int ret;
77673 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77674 goto err_stat;
77675 }
77676
77677 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77678 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77679 +#else
77680 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77681 +#endif
77682 if (!net->ct.slabname) {
77683 ret = -ENOMEM;
77684 goto err_slabname;
77685 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77686 index 3c3cfc0..7a6ea1a 100644
77687 --- a/net/netfilter/nfnetlink_log.c
77688 +++ b/net/netfilter/nfnetlink_log.c
77689 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77690 };
77691
77692 static DEFINE_SPINLOCK(instances_lock);
77693 -static atomic_t global_seq;
77694 +static atomic_unchecked_t global_seq;
77695
77696 #define INSTANCE_BUCKETS 16
77697 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77698 @@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77699 /* global sequence number */
77700 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77701 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77702 - htonl(atomic_inc_return(&global_seq))))
77703 + htonl(atomic_inc_return_unchecked(&global_seq))))
77704 goto nla_put_failure;
77705
77706 if (data_len) {
77707 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77708 new file mode 100644
77709 index 0000000..6905327
77710 --- /dev/null
77711 +++ b/net/netfilter/xt_gradm.c
77712 @@ -0,0 +1,51 @@
77713 +/*
77714 + * gradm match for netfilter
77715 + * Copyright © Zbigniew Krzystolik, 2010
77716 + *
77717 + * This program is free software; you can redistribute it and/or modify
77718 + * it under the terms of the GNU General Public License; either version
77719 + * 2 or 3 as published by the Free Software Foundation.
77720 + */
77721 +#include <linux/module.h>
77722 +#include <linux/moduleparam.h>
77723 +#include <linux/skbuff.h>
77724 +#include <linux/netfilter/x_tables.h>
77725 +#include <linux/grsecurity.h>
77726 +#include <linux/netfilter/xt_gradm.h>
77727 +
77728 +static bool
77729 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77730 +{
77731 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77732 + bool retval = false;
77733 + if (gr_acl_is_enabled())
77734 + retval = true;
77735 + return retval ^ info->invflags;
77736 +}
77737 +
77738 +static struct xt_match gradm_mt_reg __read_mostly = {
77739 + .name = "gradm",
77740 + .revision = 0,
77741 + .family = NFPROTO_UNSPEC,
77742 + .match = gradm_mt,
77743 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77744 + .me = THIS_MODULE,
77745 +};
77746 +
77747 +static int __init gradm_mt_init(void)
77748 +{
77749 + return xt_register_match(&gradm_mt_reg);
77750 +}
77751 +
77752 +static void __exit gradm_mt_exit(void)
77753 +{
77754 + xt_unregister_match(&gradm_mt_reg);
77755 +}
77756 +
77757 +module_init(gradm_mt_init);
77758 +module_exit(gradm_mt_exit);
77759 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77760 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77761 +MODULE_LICENSE("GPL");
77762 +MODULE_ALIAS("ipt_gradm");
77763 +MODULE_ALIAS("ip6t_gradm");
77764 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77765 index 4fe4fb4..87a89e5 100644
77766 --- a/net/netfilter/xt_statistic.c
77767 +++ b/net/netfilter/xt_statistic.c
77768 @@ -19,7 +19,7 @@
77769 #include <linux/module.h>
77770
77771 struct xt_statistic_priv {
77772 - atomic_t count;
77773 + atomic_unchecked_t count;
77774 } ____cacheline_aligned_in_smp;
77775
77776 MODULE_LICENSE("GPL");
77777 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77778 break;
77779 case XT_STATISTIC_MODE_NTH:
77780 do {
77781 - oval = atomic_read(&info->master->count);
77782 + oval = atomic_read_unchecked(&info->master->count);
77783 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77784 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77785 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77786 if (nval == 0)
77787 ret = !ret;
77788 break;
77789 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77790 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77791 if (info->master == NULL)
77792 return -ENOMEM;
77793 - atomic_set(&info->master->count, info->u.nth.count);
77794 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77795
77796 return 0;
77797 }
77798 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77799 index b3025a6..e717db9 100644
77800 --- a/net/netlink/af_netlink.c
77801 +++ b/net/netlink/af_netlink.c
77802 @@ -753,7 +753,7 @@ static void netlink_overrun(struct sock *sk)
77803 sk->sk_error_report(sk);
77804 }
77805 }
77806 - atomic_inc(&sk->sk_drops);
77807 + atomic_inc_unchecked(&sk->sk_drops);
77808 }
77809
77810 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77811 @@ -1344,7 +1344,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
77812 if (NULL == siocb->scm)
77813 siocb->scm = &scm;
77814
77815 - err = scm_send(sock, msg, siocb->scm);
77816 + err = scm_send(sock, msg, siocb->scm, true);
77817 if (err < 0)
77818 return err;
77819
77820 @@ -1355,7 +1355,8 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
77821 dst_pid = addr->nl_pid;
77822 dst_group = ffs(addr->nl_groups);
77823 err = -EPERM;
77824 - if (dst_group && !netlink_capable(sock, NL_NONROOT_SEND))
77825 + if ((dst_group || dst_pid) &&
77826 + !netlink_capable(sock, NL_NONROOT_SEND))
77827 goto out;
77828 } else {
77829 dst_pid = nlk->dst_pid;
77830 @@ -2022,7 +2023,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77831 sk_wmem_alloc_get(s),
77832 nlk->cb,
77833 atomic_read(&s->sk_refcnt),
77834 - atomic_read(&s->sk_drops),
77835 + atomic_read_unchecked(&s->sk_drops),
77836 sock_i_ino(s)
77837 );
77838
77839 @@ -2124,6 +2125,7 @@ static void __init netlink_add_usersock_entry(void)
77840 rcu_assign_pointer(nl_table[NETLINK_USERSOCK].listeners, listeners);
77841 nl_table[NETLINK_USERSOCK].module = THIS_MODULE;
77842 nl_table[NETLINK_USERSOCK].registered = 1;
77843 + nl_table[NETLINK_USERSOCK].nl_nonroot = NL_NONROOT_SEND;
77844
77845 netlink_table_ungrab();
77846 }
77847 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77848 index 06592d8..64860f6 100644
77849 --- a/net/netrom/af_netrom.c
77850 +++ b/net/netrom/af_netrom.c
77851 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77852 struct sock *sk = sock->sk;
77853 struct nr_sock *nr = nr_sk(sk);
77854
77855 + memset(sax, 0, sizeof(*sax));
77856 lock_sock(sk);
77857 if (peer != 0) {
77858 if (sk->sk_state != TCP_ESTABLISHED) {
77859 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77860 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77861 } else {
77862 sax->fsa_ax25.sax25_family = AF_NETROM;
77863 - sax->fsa_ax25.sax25_ndigis = 0;
77864 sax->fsa_ax25.sax25_call = nr->source_addr;
77865 *uaddr_len = sizeof(struct sockaddr_ax25);
77866 }
77867 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77868 index 0f66174..e7cb04c 100644
77869 --- a/net/packet/af_packet.c
77870 +++ b/net/packet/af_packet.c
77871 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77872
77873 spin_lock(&sk->sk_receive_queue.lock);
77874 po->stats.tp_packets++;
77875 - skb->dropcount = atomic_read(&sk->sk_drops);
77876 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77877 __skb_queue_tail(&sk->sk_receive_queue, skb);
77878 spin_unlock(&sk->sk_receive_queue.lock);
77879 sk->sk_data_ready(sk, skb->len);
77880 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77881 drop_n_acct:
77882 spin_lock(&sk->sk_receive_queue.lock);
77883 po->stats.tp_drops++;
77884 - atomic_inc(&sk->sk_drops);
77885 + atomic_inc_unchecked(&sk->sk_drops);
77886 spin_unlock(&sk->sk_receive_queue.lock);
77887
77888 drop_n_restore:
77889 @@ -2641,6 +2641,7 @@ out:
77890
77891 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
77892 {
77893 + struct sock_extended_err ee;
77894 struct sock_exterr_skb *serr;
77895 struct sk_buff *skb, *skb2;
77896 int copied, err;
77897 @@ -2662,8 +2663,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
77898 sock_recv_timestamp(msg, sk, skb);
77899
77900 serr = SKB_EXT_ERR(skb);
77901 + ee = serr->ee;
77902 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
77903 - sizeof(serr->ee), &serr->ee);
77904 + sizeof ee, &ee);
77905
77906 msg->msg_flags |= MSG_ERRQUEUE;
77907 err = copied;
77908 @@ -3275,7 +3277,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77909 case PACKET_HDRLEN:
77910 if (len > sizeof(int))
77911 len = sizeof(int);
77912 - if (copy_from_user(&val, optval, len))
77913 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77914 return -EFAULT;
77915 switch (val) {
77916 case TPACKET_V1:
77917 @@ -3314,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77918 len = lv;
77919 if (put_user(len, optlen))
77920 return -EFAULT;
77921 - if (copy_to_user(optval, data, len))
77922 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77923 return -EFAULT;
77924 return 0;
77925 }
77926 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77927 index 5a940db..f0b9c12 100644
77928 --- a/net/phonet/af_phonet.c
77929 +++ b/net/phonet/af_phonet.c
77930 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77931 {
77932 struct phonet_protocol *pp;
77933
77934 - if (protocol >= PHONET_NPROTO)
77935 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77936 return NULL;
77937
77938 rcu_read_lock();
77939 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77940 {
77941 int err = 0;
77942
77943 - if (protocol >= PHONET_NPROTO)
77944 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77945 return -EINVAL;
77946
77947 err = proto_register(pp->prot, 1);
77948 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77949 index 576f22c..bc7a71b 100644
77950 --- a/net/phonet/pep.c
77951 +++ b/net/phonet/pep.c
77952 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77953
77954 case PNS_PEP_CTRL_REQ:
77955 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77956 - atomic_inc(&sk->sk_drops);
77957 + atomic_inc_unchecked(&sk->sk_drops);
77958 break;
77959 }
77960 __skb_pull(skb, 4);
77961 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77962 }
77963
77964 if (pn->rx_credits == 0) {
77965 - atomic_inc(&sk->sk_drops);
77966 + atomic_inc_unchecked(&sk->sk_drops);
77967 err = -ENOBUFS;
77968 break;
77969 }
77970 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77971 }
77972
77973 if (pn->rx_credits == 0) {
77974 - atomic_inc(&sk->sk_drops);
77975 + atomic_inc_unchecked(&sk->sk_drops);
77976 err = NET_RX_DROP;
77977 break;
77978 }
77979 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77980 index 0acc943..c727611 100644
77981 --- a/net/phonet/socket.c
77982 +++ b/net/phonet/socket.c
77983 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77984 pn->resource, sk->sk_state,
77985 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77986 sock_i_uid(sk), sock_i_ino(sk),
77987 - atomic_read(&sk->sk_refcnt), sk,
77988 - atomic_read(&sk->sk_drops), &len);
77989 + atomic_read(&sk->sk_refcnt),
77990 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77991 + NULL,
77992 +#else
77993 + sk,
77994 +#endif
77995 + atomic_read_unchecked(&sk->sk_drops), &len);
77996 }
77997 seq_printf(seq, "%*s\n", 127 - len, "");
77998 return 0;
77999 diff --git a/net/rds/cong.c b/net/rds/cong.c
78000 index e5b65ac..f3b6fb7 100644
78001 --- a/net/rds/cong.c
78002 +++ b/net/rds/cong.c
78003 @@ -78,7 +78,7 @@
78004 * finds that the saved generation number is smaller than the global generation
78005 * number, it wakes up the process.
78006 */
78007 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78008 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78009
78010 /*
78011 * Congestion monitoring
78012 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78013 rdsdebug("waking map %p for %pI4\n",
78014 map, &map->m_addr);
78015 rds_stats_inc(s_cong_update_received);
78016 - atomic_inc(&rds_cong_generation);
78017 + atomic_inc_unchecked(&rds_cong_generation);
78018 if (waitqueue_active(&map->m_waitq))
78019 wake_up(&map->m_waitq);
78020 if (waitqueue_active(&rds_poll_waitq))
78021 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78022
78023 int rds_cong_updated_since(unsigned long *recent)
78024 {
78025 - unsigned long gen = atomic_read(&rds_cong_generation);
78026 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78027
78028 if (likely(*recent == gen))
78029 return 0;
78030 diff --git a/net/rds/ib.h b/net/rds/ib.h
78031 index 8d2b3d5..227ec5b 100644
78032 --- a/net/rds/ib.h
78033 +++ b/net/rds/ib.h
78034 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78035 /* sending acks */
78036 unsigned long i_ack_flags;
78037 #ifdef KERNEL_HAS_ATOMIC64
78038 - atomic64_t i_ack_next; /* next ACK to send */
78039 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78040 #else
78041 spinlock_t i_ack_lock; /* protect i_ack_next */
78042 u64 i_ack_next; /* next ACK to send */
78043 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78044 index a1e1162..265e129 100644
78045 --- a/net/rds/ib_cm.c
78046 +++ b/net/rds/ib_cm.c
78047 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78048 /* Clear the ACK state */
78049 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78050 #ifdef KERNEL_HAS_ATOMIC64
78051 - atomic64_set(&ic->i_ack_next, 0);
78052 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78053 #else
78054 ic->i_ack_next = 0;
78055 #endif
78056 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78057 index 8d19491..05a3e65 100644
78058 --- a/net/rds/ib_recv.c
78059 +++ b/net/rds/ib_recv.c
78060 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78061 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78062 int ack_required)
78063 {
78064 - atomic64_set(&ic->i_ack_next, seq);
78065 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78066 if (ack_required) {
78067 smp_mb__before_clear_bit();
78068 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78069 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78070 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78071 smp_mb__after_clear_bit();
78072
78073 - return atomic64_read(&ic->i_ack_next);
78074 + return atomic64_read_unchecked(&ic->i_ack_next);
78075 }
78076 #endif
78077
78078 diff --git a/net/rds/iw.h b/net/rds/iw.h
78079 index 04ce3b1..48119a6 100644
78080 --- a/net/rds/iw.h
78081 +++ b/net/rds/iw.h
78082 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78083 /* sending acks */
78084 unsigned long i_ack_flags;
78085 #ifdef KERNEL_HAS_ATOMIC64
78086 - atomic64_t i_ack_next; /* next ACK to send */
78087 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78088 #else
78089 spinlock_t i_ack_lock; /* protect i_ack_next */
78090 u64 i_ack_next; /* next ACK to send */
78091 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78092 index a91e1db..cf3053f 100644
78093 --- a/net/rds/iw_cm.c
78094 +++ b/net/rds/iw_cm.c
78095 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78096 /* Clear the ACK state */
78097 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78098 #ifdef KERNEL_HAS_ATOMIC64
78099 - atomic64_set(&ic->i_ack_next, 0);
78100 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78101 #else
78102 ic->i_ack_next = 0;
78103 #endif
78104 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78105 index 4503335..db566b4 100644
78106 --- a/net/rds/iw_recv.c
78107 +++ b/net/rds/iw_recv.c
78108 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78109 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78110 int ack_required)
78111 {
78112 - atomic64_set(&ic->i_ack_next, seq);
78113 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78114 if (ack_required) {
78115 smp_mb__before_clear_bit();
78116 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78117 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78118 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78119 smp_mb__after_clear_bit();
78120
78121 - return atomic64_read(&ic->i_ack_next);
78122 + return atomic64_read_unchecked(&ic->i_ack_next);
78123 }
78124 #endif
78125
78126 diff --git a/net/rds/recv.c b/net/rds/recv.c
78127 index 5c6e9f1..9f0f17c 100644
78128 --- a/net/rds/recv.c
78129 +++ b/net/rds/recv.c
78130 @@ -410,6 +410,8 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
78131
78132 rdsdebug("size %zu flags 0x%x timeo %ld\n", size, msg_flags, timeo);
78133
78134 + msg->msg_namelen = 0;
78135 +
78136 if (msg_flags & MSG_OOB)
78137 goto out;
78138
78139 @@ -485,6 +487,7 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
78140 sin->sin_port = inc->i_hdr.h_sport;
78141 sin->sin_addr.s_addr = inc->i_saddr;
78142 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
78143 + msg->msg_namelen = sizeof(*sin);
78144 }
78145 break;
78146 }
78147 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78148 index edac9ef..16bcb98 100644
78149 --- a/net/rds/tcp.c
78150 +++ b/net/rds/tcp.c
78151 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78152 int val = 1;
78153
78154 set_fs(KERNEL_DS);
78155 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78156 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78157 sizeof(val));
78158 set_fs(oldfs);
78159 }
78160 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78161 index 1b4fd68..2234175 100644
78162 --- a/net/rds/tcp_send.c
78163 +++ b/net/rds/tcp_send.c
78164 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78165
78166 oldfs = get_fs();
78167 set_fs(KERNEL_DS);
78168 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78169 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78170 sizeof(val));
78171 set_fs(oldfs);
78172 }
78173 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78174 index 05996d0..5a1dfe0 100644
78175 --- a/net/rxrpc/af_rxrpc.c
78176 +++ b/net/rxrpc/af_rxrpc.c
78177 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78178 __be32 rxrpc_epoch;
78179
78180 /* current debugging ID */
78181 -atomic_t rxrpc_debug_id;
78182 +atomic_unchecked_t rxrpc_debug_id;
78183
78184 /* count of skbs currently in use */
78185 atomic_t rxrpc_n_skbs;
78186 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78187 index e4d9cbc..b229649 100644
78188 --- a/net/rxrpc/ar-ack.c
78189 +++ b/net/rxrpc/ar-ack.c
78190 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78191
78192 _enter("{%d,%d,%d,%d},",
78193 call->acks_hard, call->acks_unacked,
78194 - atomic_read(&call->sequence),
78195 + atomic_read_unchecked(&call->sequence),
78196 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78197
78198 stop = 0;
78199 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78200
78201 /* each Tx packet has a new serial number */
78202 sp->hdr.serial =
78203 - htonl(atomic_inc_return(&call->conn->serial));
78204 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78205
78206 hdr = (struct rxrpc_header *) txb->head;
78207 hdr->serial = sp->hdr.serial;
78208 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78209 */
78210 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78211 {
78212 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78213 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78214 }
78215
78216 /*
78217 @@ -629,7 +629,7 @@ process_further:
78218
78219 latest = ntohl(sp->hdr.serial);
78220 hard = ntohl(ack.firstPacket);
78221 - tx = atomic_read(&call->sequence);
78222 + tx = atomic_read_unchecked(&call->sequence);
78223
78224 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78225 latest,
78226 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78227 goto maybe_reschedule;
78228
78229 send_ACK_with_skew:
78230 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78231 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78232 ntohl(ack.serial));
78233 send_ACK:
78234 mtu = call->conn->trans->peer->if_mtu;
78235 @@ -1173,7 +1173,7 @@ send_ACK:
78236 ackinfo.rxMTU = htonl(5692);
78237 ackinfo.jumbo_max = htonl(4);
78238
78239 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78240 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78241 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78242 ntohl(hdr.serial),
78243 ntohs(ack.maxSkew),
78244 @@ -1191,7 +1191,7 @@ send_ACK:
78245 send_message:
78246 _debug("send message");
78247
78248 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78249 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78250 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78251 send_message_2:
78252
78253 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78254 index a3bbb36..3341fb9 100644
78255 --- a/net/rxrpc/ar-call.c
78256 +++ b/net/rxrpc/ar-call.c
78257 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78258 spin_lock_init(&call->lock);
78259 rwlock_init(&call->state_lock);
78260 atomic_set(&call->usage, 1);
78261 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78262 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78263 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78264
78265 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78266 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78267 index 4106ca9..a338d7a 100644
78268 --- a/net/rxrpc/ar-connection.c
78269 +++ b/net/rxrpc/ar-connection.c
78270 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78271 rwlock_init(&conn->lock);
78272 spin_lock_init(&conn->state_lock);
78273 atomic_set(&conn->usage, 1);
78274 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78275 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78276 conn->avail_calls = RXRPC_MAXCALLS;
78277 conn->size_align = 4;
78278 conn->header_size = sizeof(struct rxrpc_header);
78279 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78280 index e7ed43a..6afa140 100644
78281 --- a/net/rxrpc/ar-connevent.c
78282 +++ b/net/rxrpc/ar-connevent.c
78283 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78284
78285 len = iov[0].iov_len + iov[1].iov_len;
78286
78287 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78288 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78289 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78290
78291 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78292 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78293 index 529572f..c758ca7 100644
78294 --- a/net/rxrpc/ar-input.c
78295 +++ b/net/rxrpc/ar-input.c
78296 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78297 /* track the latest serial number on this connection for ACK packet
78298 * information */
78299 serial = ntohl(sp->hdr.serial);
78300 - hi_serial = atomic_read(&call->conn->hi_serial);
78301 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78302 while (serial > hi_serial)
78303 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78304 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78305 serial);
78306
78307 /* request ACK generation for any ACK or DATA packet that requests
78308 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78309 index a693aca..81e7293 100644
78310 --- a/net/rxrpc/ar-internal.h
78311 +++ b/net/rxrpc/ar-internal.h
78312 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78313 int error; /* error code for local abort */
78314 int debug_id; /* debug ID for printks */
78315 unsigned int call_counter; /* call ID counter */
78316 - atomic_t serial; /* packet serial number counter */
78317 - atomic_t hi_serial; /* highest serial number received */
78318 + atomic_unchecked_t serial; /* packet serial number counter */
78319 + atomic_unchecked_t hi_serial; /* highest serial number received */
78320 u8 avail_calls; /* number of calls available */
78321 u8 size_align; /* data size alignment (for security) */
78322 u8 header_size; /* rxrpc + security header size */
78323 @@ -346,7 +346,7 @@ struct rxrpc_call {
78324 spinlock_t lock;
78325 rwlock_t state_lock; /* lock for state transition */
78326 atomic_t usage;
78327 - atomic_t sequence; /* Tx data packet sequence counter */
78328 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78329 u32 abort_code; /* local/remote abort code */
78330 enum { /* current state of call */
78331 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78332 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78333 */
78334 extern atomic_t rxrpc_n_skbs;
78335 extern __be32 rxrpc_epoch;
78336 -extern atomic_t rxrpc_debug_id;
78337 +extern atomic_unchecked_t rxrpc_debug_id;
78338 extern struct workqueue_struct *rxrpc_workqueue;
78339
78340 /*
78341 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78342 index 87f7135..74d3703 100644
78343 --- a/net/rxrpc/ar-local.c
78344 +++ b/net/rxrpc/ar-local.c
78345 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78346 spin_lock_init(&local->lock);
78347 rwlock_init(&local->services_lock);
78348 atomic_set(&local->usage, 1);
78349 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78350 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78351 memcpy(&local->srx, srx, sizeof(*srx));
78352 }
78353
78354 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78355 index 16ae887..d24f12b 100644
78356 --- a/net/rxrpc/ar-output.c
78357 +++ b/net/rxrpc/ar-output.c
78358 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78359 sp->hdr.cid = call->cid;
78360 sp->hdr.callNumber = call->call_id;
78361 sp->hdr.seq =
78362 - htonl(atomic_inc_return(&call->sequence));
78363 + htonl(atomic_inc_return_unchecked(&call->sequence));
78364 sp->hdr.serial =
78365 - htonl(atomic_inc_return(&conn->serial));
78366 + htonl(atomic_inc_return_unchecked(&conn->serial));
78367 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78368 sp->hdr.userStatus = 0;
78369 sp->hdr.securityIndex = conn->security_ix;
78370 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78371 index bebaa43..2644591 100644
78372 --- a/net/rxrpc/ar-peer.c
78373 +++ b/net/rxrpc/ar-peer.c
78374 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78375 INIT_LIST_HEAD(&peer->error_targets);
78376 spin_lock_init(&peer->lock);
78377 atomic_set(&peer->usage, 1);
78378 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78379 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78380 memcpy(&peer->srx, srx, sizeof(*srx));
78381
78382 rxrpc_assess_MTU_size(peer);
78383 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78384 index 38047f7..9f48511 100644
78385 --- a/net/rxrpc/ar-proc.c
78386 +++ b/net/rxrpc/ar-proc.c
78387 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78388 atomic_read(&conn->usage),
78389 rxrpc_conn_states[conn->state],
78390 key_serial(conn->key),
78391 - atomic_read(&conn->serial),
78392 - atomic_read(&conn->hi_serial));
78393 + atomic_read_unchecked(&conn->serial),
78394 + atomic_read_unchecked(&conn->hi_serial));
78395
78396 return 0;
78397 }
78398 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78399 index 92df566..87ec1bf 100644
78400 --- a/net/rxrpc/ar-transport.c
78401 +++ b/net/rxrpc/ar-transport.c
78402 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78403 spin_lock_init(&trans->client_lock);
78404 rwlock_init(&trans->conn_lock);
78405 atomic_set(&trans->usage, 1);
78406 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78407 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78408
78409 if (peer->srx.transport.family == AF_INET) {
78410 switch (peer->srx.transport_type) {
78411 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78412 index f226709..0e735a8 100644
78413 --- a/net/rxrpc/rxkad.c
78414 +++ b/net/rxrpc/rxkad.c
78415 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78416
78417 len = iov[0].iov_len + iov[1].iov_len;
78418
78419 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78420 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78421 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78422
78423 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78424 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78425
78426 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78427
78428 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78429 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78430 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78431
78432 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78433 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78434 index 1e2eee8..ce3967e 100644
78435 --- a/net/sctp/proc.c
78436 +++ b/net/sctp/proc.c
78437 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78438 seq_printf(seq,
78439 "%8pK %8pK %-3d %-3d %-2d %-4d "
78440 "%4d %8d %8d %7d %5lu %-5d %5d ",
78441 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78442 + assoc, sk,
78443 + sctp_sk(sk)->type, sk->sk_state,
78444 assoc->state, hash,
78445 assoc->assoc_id,
78446 assoc->sndbuf_used,
78447 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78448 index 31c7bfc..bc380ae 100644
78449 --- a/net/sctp/socket.c
78450 +++ b/net/sctp/socket.c
78451 @@ -4577,7 +4577,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78452 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78453 if (space_left < addrlen)
78454 return -ENOMEM;
78455 - if (copy_to_user(to, &temp, addrlen))
78456 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78457 return -EFAULT;
78458 to += addrlen;
78459 cnt++;
78460 diff --git a/net/socket.c b/net/socket.c
78461 index 0452dca..5af9802 100644
78462 --- a/net/socket.c
78463 +++ b/net/socket.c
78464 @@ -88,6 +88,7 @@
78465 #include <linux/nsproxy.h>
78466 #include <linux/magic.h>
78467 #include <linux/slab.h>
78468 +#include <linux/in.h>
78469
78470 #include <asm/uaccess.h>
78471 #include <asm/unistd.h>
78472 @@ -105,6 +106,8 @@
78473 #include <linux/sockios.h>
78474 #include <linux/atalk.h>
78475
78476 +#include <linux/grsock.h>
78477 +
78478 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78479 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78480 unsigned long nr_segs, loff_t pos);
78481 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78482 &sockfs_dentry_operations, SOCKFS_MAGIC);
78483 }
78484
78485 -static struct vfsmount *sock_mnt __read_mostly;
78486 +struct vfsmount *sock_mnt __read_mostly;
78487
78488 static struct file_system_type sock_fs_type = {
78489 .name = "sockfs",
78490 @@ -1210,6 +1213,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78491 return -EAFNOSUPPORT;
78492 if (type < 0 || type >= SOCK_MAX)
78493 return -EINVAL;
78494 + if (protocol < 0)
78495 + return -EINVAL;
78496
78497 /* Compatibility.
78498
78499 @@ -1341,6 +1346,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78500 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78501 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78502
78503 + if(!gr_search_socket(family, type, protocol)) {
78504 + retval = -EACCES;
78505 + goto out;
78506 + }
78507 +
78508 + if (gr_handle_sock_all(family, type, protocol)) {
78509 + retval = -EACCES;
78510 + goto out;
78511 + }
78512 +
78513 retval = sock_create(family, type, protocol, &sock);
78514 if (retval < 0)
78515 goto out;
78516 @@ -1453,6 +1468,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78517 if (sock) {
78518 err = move_addr_to_kernel(umyaddr, addrlen, &address);
78519 if (err >= 0) {
78520 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78521 + err = -EACCES;
78522 + goto error;
78523 + }
78524 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78525 + if (err)
78526 + goto error;
78527 +
78528 err = security_socket_bind(sock,
78529 (struct sockaddr *)&address,
78530 addrlen);
78531 @@ -1461,6 +1484,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78532 (struct sockaddr *)
78533 &address, addrlen);
78534 }
78535 +error:
78536 fput_light(sock->file, fput_needed);
78537 }
78538 return err;
78539 @@ -1484,10 +1508,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78540 if ((unsigned int)backlog > somaxconn)
78541 backlog = somaxconn;
78542
78543 + if (gr_handle_sock_server_other(sock->sk)) {
78544 + err = -EPERM;
78545 + goto error;
78546 + }
78547 +
78548 + err = gr_search_listen(sock);
78549 + if (err)
78550 + goto error;
78551 +
78552 err = security_socket_listen(sock, backlog);
78553 if (!err)
78554 err = sock->ops->listen(sock, backlog);
78555
78556 +error:
78557 fput_light(sock->file, fput_needed);
78558 }
78559 return err;
78560 @@ -1531,6 +1565,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78561 newsock->type = sock->type;
78562 newsock->ops = sock->ops;
78563
78564 + if (gr_handle_sock_server_other(sock->sk)) {
78565 + err = -EPERM;
78566 + sock_release(newsock);
78567 + goto out_put;
78568 + }
78569 +
78570 + err = gr_search_accept(sock);
78571 + if (err) {
78572 + sock_release(newsock);
78573 + goto out_put;
78574 + }
78575 +
78576 /*
78577 * We don't need try_module_get here, as the listening socket (sock)
78578 * has the protocol module (sock->ops->owner) held.
78579 @@ -1569,6 +1615,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78580 fd_install(newfd, newfile);
78581 err = newfd;
78582
78583 + gr_attach_curr_ip(newsock->sk);
78584 +
78585 out_put:
78586 fput_light(sock->file, fput_needed);
78587 out:
78588 @@ -1601,6 +1649,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78589 int, addrlen)
78590 {
78591 struct socket *sock;
78592 + struct sockaddr *sck;
78593 struct sockaddr_storage address;
78594 int err, fput_needed;
78595
78596 @@ -1611,6 +1660,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78597 if (err < 0)
78598 goto out_put;
78599
78600 + sck = (struct sockaddr *)&address;
78601 +
78602 + if (gr_handle_sock_client(sck)) {
78603 + err = -EACCES;
78604 + goto out_put;
78605 + }
78606 +
78607 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78608 + if (err)
78609 + goto out_put;
78610 +
78611 err =
78612 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78613 if (err)
78614 @@ -1965,7 +2025,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78615 * checking falls down on this.
78616 */
78617 if (copy_from_user(ctl_buf,
78618 - (void __user __force *)msg_sys->msg_control,
78619 + (void __force_user *)msg_sys->msg_control,
78620 ctl_len))
78621 goto out_freectl;
78622 msg_sys->msg_control = ctl_buf;
78623 @@ -2133,7 +2193,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78624 * kernel msghdr to use the kernel address space)
78625 */
78626
78627 - uaddr = (__force void __user *)msg_sys->msg_name;
78628 + uaddr = (void __force_user *)msg_sys->msg_name;
78629 uaddr_len = COMPAT_NAMELEN(msg);
78630 if (MSG_CMSG_COMPAT & flags) {
78631 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
78632 @@ -2605,7 +2665,7 @@ static int do_siocgstamp(struct net *net, struct socket *sock,
78633 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv);
78634 set_fs(old_fs);
78635 if (!err)
78636 - err = compat_put_timeval(up, &ktv);
78637 + err = compat_put_timeval(&ktv, up);
78638
78639 return err;
78640 }
78641 @@ -2621,7 +2681,7 @@ static int do_siocgstampns(struct net *net, struct socket *sock,
78642 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts);
78643 set_fs(old_fs);
78644 if (!err)
78645 - err = compat_put_timespec(up, &kts);
78646 + err = compat_put_timespec(&kts, up);
78647
78648 return err;
78649 }
78650 @@ -2658,6 +2718,7 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32)
78651 if (copy_from_user(&ifc32, uifc32, sizeof(struct compat_ifconf)))
78652 return -EFAULT;
78653
78654 + memset(&ifc, 0, sizeof(ifc));
78655 if (ifc32.ifcbuf == 0) {
78656 ifc32.ifc_len = 0;
78657 ifc.ifc_len = 0;
78658 @@ -2761,7 +2822,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78659 }
78660
78661 ifr = compat_alloc_user_space(buf_size);
78662 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78663 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78664
78665 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78666 return -EFAULT;
78667 @@ -2785,12 +2846,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78668 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78669
78670 if (copy_in_user(rxnfc, compat_rxnfc,
78671 - (void *)(&rxnfc->fs.m_ext + 1) -
78672 - (void *)rxnfc) ||
78673 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78674 + (void __user *)rxnfc) ||
78675 copy_in_user(&rxnfc->fs.ring_cookie,
78676 &compat_rxnfc->fs.ring_cookie,
78677 - (void *)(&rxnfc->fs.location + 1) -
78678 - (void *)&rxnfc->fs.ring_cookie) ||
78679 + (void __user *)(&rxnfc->fs.location + 1) -
78680 + (void __user *)&rxnfc->fs.ring_cookie) ||
78681 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78682 sizeof(rxnfc->rule_cnt)))
78683 return -EFAULT;
78684 @@ -2802,12 +2863,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78685
78686 if (convert_out) {
78687 if (copy_in_user(compat_rxnfc, rxnfc,
78688 - (const void *)(&rxnfc->fs.m_ext + 1) -
78689 - (const void *)rxnfc) ||
78690 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78691 + (const void __user *)rxnfc) ||
78692 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78693 &rxnfc->fs.ring_cookie,
78694 - (const void *)(&rxnfc->fs.location + 1) -
78695 - (const void *)&rxnfc->fs.ring_cookie) ||
78696 + (const void __user *)(&rxnfc->fs.location + 1) -
78697 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78698 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78699 sizeof(rxnfc->rule_cnt)))
78700 return -EFAULT;
78701 @@ -2877,7 +2938,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78702 old_fs = get_fs();
78703 set_fs(KERNEL_DS);
78704 err = dev_ioctl(net, cmd,
78705 - (struct ifreq __user __force *) &kifr);
78706 + (struct ifreq __force_user *) &kifr);
78707 set_fs(old_fs);
78708
78709 return err;
78710 @@ -2986,7 +3047,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78711
78712 old_fs = get_fs();
78713 set_fs(KERNEL_DS);
78714 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78715 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78716 set_fs(old_fs);
78717
78718 if (cmd == SIOCGIFMAP && !err) {
78719 @@ -3091,7 +3152,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78720 ret |= __get_user(rtdev, &(ur4->rt_dev));
78721 if (rtdev) {
78722 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78723 - r4.rt_dev = (char __user __force *)devname;
78724 + r4.rt_dev = (char __force_user *)devname;
78725 devname[15] = 0;
78726 } else
78727 r4.rt_dev = NULL;
78728 @@ -3317,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78729 int __user *uoptlen;
78730 int err;
78731
78732 - uoptval = (char __user __force *) optval;
78733 - uoptlen = (int __user __force *) optlen;
78734 + uoptval = (char __force_user *) optval;
78735 + uoptlen = (int __force_user *) optlen;
78736
78737 set_fs(KERNEL_DS);
78738 if (level == SOL_SOCKET)
78739 @@ -3338,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78740 char __user *uoptval;
78741 int err;
78742
78743 - uoptval = (char __user __force *) optval;
78744 + uoptval = (char __force_user *) optval;
78745
78746 set_fs(KERNEL_DS);
78747 if (level == SOL_SOCKET)
78748 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78749 index eda32ae..1c9fa7c 100644
78750 --- a/net/sunrpc/sched.c
78751 +++ b/net/sunrpc/sched.c
78752 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
78753 #ifdef RPC_DEBUG
78754 static void rpc_task_set_debuginfo(struct rpc_task *task)
78755 {
78756 - static atomic_t rpc_pid;
78757 + static atomic_unchecked_t rpc_pid;
78758
78759 - task->tk_pid = atomic_inc_return(&rpc_pid);
78760 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78761 }
78762 #else
78763 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78764 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78765 index 8343737..677025e 100644
78766 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78767 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78768 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78769 static unsigned int min_max_inline = 4096;
78770 static unsigned int max_max_inline = 65536;
78771
78772 -atomic_t rdma_stat_recv;
78773 -atomic_t rdma_stat_read;
78774 -atomic_t rdma_stat_write;
78775 -atomic_t rdma_stat_sq_starve;
78776 -atomic_t rdma_stat_rq_starve;
78777 -atomic_t rdma_stat_rq_poll;
78778 -atomic_t rdma_stat_rq_prod;
78779 -atomic_t rdma_stat_sq_poll;
78780 -atomic_t rdma_stat_sq_prod;
78781 +atomic_unchecked_t rdma_stat_recv;
78782 +atomic_unchecked_t rdma_stat_read;
78783 +atomic_unchecked_t rdma_stat_write;
78784 +atomic_unchecked_t rdma_stat_sq_starve;
78785 +atomic_unchecked_t rdma_stat_rq_starve;
78786 +atomic_unchecked_t rdma_stat_rq_poll;
78787 +atomic_unchecked_t rdma_stat_rq_prod;
78788 +atomic_unchecked_t rdma_stat_sq_poll;
78789 +atomic_unchecked_t rdma_stat_sq_prod;
78790
78791 /* Temporary NFS request map and context caches */
78792 struct kmem_cache *svc_rdma_map_cachep;
78793 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
78794 len -= *ppos;
78795 if (len > *lenp)
78796 len = *lenp;
78797 - if (len && copy_to_user(buffer, str_buf, len))
78798 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78799 return -EFAULT;
78800 *lenp = len;
78801 *ppos += len;
78802 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
78803 {
78804 .procname = "rdma_stat_read",
78805 .data = &rdma_stat_read,
78806 - .maxlen = sizeof(atomic_t),
78807 + .maxlen = sizeof(atomic_unchecked_t),
78808 .mode = 0644,
78809 .proc_handler = read_reset_stat,
78810 },
78811 {
78812 .procname = "rdma_stat_recv",
78813 .data = &rdma_stat_recv,
78814 - .maxlen = sizeof(atomic_t),
78815 + .maxlen = sizeof(atomic_unchecked_t),
78816 .mode = 0644,
78817 .proc_handler = read_reset_stat,
78818 },
78819 {
78820 .procname = "rdma_stat_write",
78821 .data = &rdma_stat_write,
78822 - .maxlen = sizeof(atomic_t),
78823 + .maxlen = sizeof(atomic_unchecked_t),
78824 .mode = 0644,
78825 .proc_handler = read_reset_stat,
78826 },
78827 {
78828 .procname = "rdma_stat_sq_starve",
78829 .data = &rdma_stat_sq_starve,
78830 - .maxlen = sizeof(atomic_t),
78831 + .maxlen = sizeof(atomic_unchecked_t),
78832 .mode = 0644,
78833 .proc_handler = read_reset_stat,
78834 },
78835 {
78836 .procname = "rdma_stat_rq_starve",
78837 .data = &rdma_stat_rq_starve,
78838 - .maxlen = sizeof(atomic_t),
78839 + .maxlen = sizeof(atomic_unchecked_t),
78840 .mode = 0644,
78841 .proc_handler = read_reset_stat,
78842 },
78843 {
78844 .procname = "rdma_stat_rq_poll",
78845 .data = &rdma_stat_rq_poll,
78846 - .maxlen = sizeof(atomic_t),
78847 + .maxlen = sizeof(atomic_unchecked_t),
78848 .mode = 0644,
78849 .proc_handler = read_reset_stat,
78850 },
78851 {
78852 .procname = "rdma_stat_rq_prod",
78853 .data = &rdma_stat_rq_prod,
78854 - .maxlen = sizeof(atomic_t),
78855 + .maxlen = sizeof(atomic_unchecked_t),
78856 .mode = 0644,
78857 .proc_handler = read_reset_stat,
78858 },
78859 {
78860 .procname = "rdma_stat_sq_poll",
78861 .data = &rdma_stat_sq_poll,
78862 - .maxlen = sizeof(atomic_t),
78863 + .maxlen = sizeof(atomic_unchecked_t),
78864 .mode = 0644,
78865 .proc_handler = read_reset_stat,
78866 },
78867 {
78868 .procname = "rdma_stat_sq_prod",
78869 .data = &rdma_stat_sq_prod,
78870 - .maxlen = sizeof(atomic_t),
78871 + .maxlen = sizeof(atomic_unchecked_t),
78872 .mode = 0644,
78873 .proc_handler = read_reset_stat,
78874 },
78875 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78876 index 41cb63b..c4a1489 100644
78877 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78878 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78879 @@ -501,7 +501,7 @@ next_sge:
78880 svc_rdma_put_context(ctxt, 0);
78881 goto out;
78882 }
78883 - atomic_inc(&rdma_stat_read);
78884 + atomic_inc_unchecked(&rdma_stat_read);
78885
78886 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78887 chl_map->ch[ch_no].count -= read_wr.num_sge;
78888 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78889 dto_q);
78890 list_del_init(&ctxt->dto_q);
78891 } else {
78892 - atomic_inc(&rdma_stat_rq_starve);
78893 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78894 clear_bit(XPT_DATA, &xprt->xpt_flags);
78895 ctxt = NULL;
78896 }
78897 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78898 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78899 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78900 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78901 - atomic_inc(&rdma_stat_recv);
78902 + atomic_inc_unchecked(&rdma_stat_recv);
78903
78904 /* Build up the XDR from the receive buffers. */
78905 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78906 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78907 index 42eb7ba..c887c45 100644
78908 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78909 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78910 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78911 write_wr.wr.rdma.remote_addr = to;
78912
78913 /* Post It */
78914 - atomic_inc(&rdma_stat_write);
78915 + atomic_inc_unchecked(&rdma_stat_write);
78916 if (svc_rdma_send(xprt, &write_wr))
78917 goto err;
78918 return 0;
78919 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78920 index 73b428b..5f3f8f3 100644
78921 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78922 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78923 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78924 return;
78925
78926 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78927 - atomic_inc(&rdma_stat_rq_poll);
78928 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78929
78930 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78931 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78932 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78933 }
78934
78935 if (ctxt)
78936 - atomic_inc(&rdma_stat_rq_prod);
78937 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78938
78939 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78940 /*
78941 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78942 return;
78943
78944 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78945 - atomic_inc(&rdma_stat_sq_poll);
78946 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78947 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78948 if (wc.status != IB_WC_SUCCESS)
78949 /* Close the transport */
78950 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78951 }
78952
78953 if (ctxt)
78954 - atomic_inc(&rdma_stat_sq_prod);
78955 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78956 }
78957
78958 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78959 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78960 spin_lock_bh(&xprt->sc_lock);
78961 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78962 spin_unlock_bh(&xprt->sc_lock);
78963 - atomic_inc(&rdma_stat_sq_starve);
78964 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78965
78966 /* See if we can opportunistically reap SQ WR to make room */
78967 sq_cq_reap(xprt);
78968 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78969 index e3a6e37..be2ea77 100644
78970 --- a/net/sysctl_net.c
78971 +++ b/net/sysctl_net.c
78972 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78973 struct ctl_table *table)
78974 {
78975 /* Allow network administrator to have same access as root. */
78976 - if (capable(CAP_NET_ADMIN)) {
78977 + if (capable_nolog(CAP_NET_ADMIN)) {
78978 int mode = (table->mode >> 6) & 7;
78979 return (mode << 6) | (mode << 3) | mode;
78980 }
78981 diff --git a/net/tipc/link.c b/net/tipc/link.c
78982 index 7a614f4..b14dbd2 100644
78983 --- a/net/tipc/link.c
78984 +++ b/net/tipc/link.c
78985 @@ -1164,7 +1164,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78986 struct tipc_msg fragm_hdr;
78987 struct sk_buff *buf, *buf_chain, *prev;
78988 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78989 - const unchar *sect_crs;
78990 + const unchar __user *sect_crs;
78991 int curr_sect;
78992 u32 fragm_no;
78993
78994 @@ -1205,7 +1205,7 @@ again:
78995
78996 if (!sect_rest) {
78997 sect_rest = msg_sect[++curr_sect].iov_len;
78998 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78999 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79000 }
79001
79002 if (sect_rest < fragm_rest)
79003 @@ -1224,7 +1224,7 @@ error:
79004 }
79005 } else
79006 skb_copy_to_linear_data_offset(buf, fragm_crs,
79007 - sect_crs, sz);
79008 + (const void __force_kernel *)sect_crs, sz);
79009 sect_crs += sz;
79010 sect_rest -= sz;
79011 fragm_crs += sz;
79012 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79013 index deea0d2..fa13bd7 100644
79014 --- a/net/tipc/msg.c
79015 +++ b/net/tipc/msg.c
79016 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79017 msg_sect[cnt].iov_len);
79018 else
79019 skb_copy_to_linear_data_offset(*buf, pos,
79020 - msg_sect[cnt].iov_base,
79021 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79022 msg_sect[cnt].iov_len);
79023 pos += msg_sect[cnt].iov_len;
79024 }
79025 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79026 index f976e9cd..560d055 100644
79027 --- a/net/tipc/subscr.c
79028 +++ b/net/tipc/subscr.c
79029 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79030 {
79031 struct iovec msg_sect;
79032
79033 - msg_sect.iov_base = (void *)&sub->evt;
79034 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79035 msg_sect.iov_len = sizeof(struct tipc_event);
79036
79037 sub->evt.event = htohl(event, sub->swap);
79038 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79039 index 641f2e4..590bb48 100644
79040 --- a/net/unix/af_unix.c
79041 +++ b/net/unix/af_unix.c
79042 @@ -780,6 +780,12 @@ static struct sock *unix_find_other(struct net *net,
79043 err = -ECONNREFUSED;
79044 if (!S_ISSOCK(inode->i_mode))
79045 goto put_fail;
79046 +
79047 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79048 + err = -EACCES;
79049 + goto put_fail;
79050 + }
79051 +
79052 u = unix_find_socket_byinode(inode);
79053 if (!u)
79054 goto put_fail;
79055 @@ -800,6 +806,13 @@ static struct sock *unix_find_other(struct net *net,
79056 if (u) {
79057 struct dentry *dentry;
79058 dentry = unix_sk(u)->path.dentry;
79059 +
79060 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79061 + err = -EPERM;
79062 + sock_put(u);
79063 + goto fail;
79064 + }
79065 +
79066 if (dentry)
79067 touch_atime(&unix_sk(u)->path);
79068 } else
79069 @@ -882,11 +895,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
79070 err = security_path_mknod(&path, dentry, mode, 0);
79071 if (err)
79072 goto out_mknod_drop_write;
79073 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79074 + err = -EACCES;
79075 + goto out_mknod_drop_write;
79076 + }
79077 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79078 out_mknod_drop_write:
79079 mnt_drop_write(path.mnt);
79080 if (err)
79081 goto out_mknod_dput;
79082 +
79083 + gr_handle_create(dentry, path.mnt);
79084 +
79085 mutex_unlock(&path.dentry->d_inode->i_mutex);
79086 dput(path.dentry);
79087 path.dentry = dentry;
79088 @@ -1448,7 +1468,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
79089 if (NULL == siocb->scm)
79090 siocb->scm = &tmp_scm;
79091 wait_for_unix_gc();
79092 - err = scm_send(sock, msg, siocb->scm);
79093 + err = scm_send(sock, msg, siocb->scm, false);
79094 if (err < 0)
79095 return err;
79096
79097 @@ -1617,7 +1637,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
79098 if (NULL == siocb->scm)
79099 siocb->scm = &tmp_scm;
79100 wait_for_unix_gc();
79101 - err = scm_send(sock, msg, siocb->scm);
79102 + err = scm_send(sock, msg, siocb->scm, false);
79103 if (err < 0)
79104 return err;
79105
79106 diff --git a/net/wireless/core.h b/net/wireless/core.h
79107 index bc686ef..27845e6 100644
79108 --- a/net/wireless/core.h
79109 +++ b/net/wireless/core.h
79110 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
79111 struct mutex mtx;
79112
79113 /* rfkill support */
79114 - struct rfkill_ops rfkill_ops;
79115 + rfkill_ops_no_const rfkill_ops;
79116 struct rfkill *rfkill;
79117 struct work_struct rfkill_sync;
79118
79119 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79120 index b0eb7aa..7d73e82 100644
79121 --- a/net/wireless/wext-core.c
79122 +++ b/net/wireless/wext-core.c
79123 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79124 */
79125
79126 /* Support for very large requests */
79127 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79128 - (user_length > descr->max_tokens)) {
79129 + if (user_length > descr->max_tokens) {
79130 /* Allow userspace to GET more than max so
79131 * we can support any size GET requests.
79132 * There is still a limit : -ENOMEM.
79133 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79134 }
79135 }
79136
79137 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79138 - /*
79139 - * If this is a GET, but not NOMAX, it means that the extra
79140 - * data is not bounded by userspace, but by max_tokens. Thus
79141 - * set the length to max_tokens. This matches the extra data
79142 - * allocation.
79143 - * The driver should fill it with the number of tokens it
79144 - * provided, and it may check iwp->length rather than having
79145 - * knowledge of max_tokens. If the driver doesn't change the
79146 - * iwp->length, this ioctl just copies back max_token tokens
79147 - * filled with zeroes. Hopefully the driver isn't claiming
79148 - * them to be valid data.
79149 - */
79150 - iwp->length = descr->max_tokens;
79151 - }
79152 -
79153 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79154
79155 iwp->length += essid_compat;
79156 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79157 index ccfbd32..9b61cf9f 100644
79158 --- a/net/xfrm/xfrm_policy.c
79159 +++ b/net/xfrm/xfrm_policy.c
79160 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79161 {
79162 policy->walk.dead = 1;
79163
79164 - atomic_inc(&policy->genid);
79165 + atomic_inc_unchecked(&policy->genid);
79166
79167 if (del_timer(&policy->timer))
79168 xfrm_pol_put(policy);
79169 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79170 hlist_add_head(&policy->bydst, chain);
79171 xfrm_pol_hold(policy);
79172 net->xfrm.policy_count[dir]++;
79173 - atomic_inc(&flow_cache_genid);
79174 + atomic_inc_unchecked(&flow_cache_genid);
79175 if (delpol)
79176 __xfrm_policy_unlink(delpol, dir);
79177 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
79178 @@ -1532,7 +1532,7 @@ free_dst:
79179 goto out;
79180 }
79181
79182 -static int inline
79183 +static inline int
79184 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79185 {
79186 if (!*target) {
79187 @@ -1544,7 +1544,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79188 return 0;
79189 }
79190
79191 -static int inline
79192 +static inline int
79193 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79194 {
79195 #ifdef CONFIG_XFRM_SUB_POLICY
79196 @@ -1556,7 +1556,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79197 #endif
79198 }
79199
79200 -static int inline
79201 +static inline int
79202 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79203 {
79204 #ifdef CONFIG_XFRM_SUB_POLICY
79205 @@ -1650,7 +1650,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79206
79207 xdst->num_pols = num_pols;
79208 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79209 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79210 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79211
79212 return xdst;
79213 }
79214 @@ -2350,7 +2350,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79215 if (xdst->xfrm_genid != dst->xfrm->genid)
79216 return 0;
79217 if (xdst->num_pols > 0 &&
79218 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79219 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79220 return 0;
79221
79222 mtu = dst_mtu(dst->child);
79223 @@ -2887,7 +2887,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79224 sizeof(pol->xfrm_vec[i].saddr));
79225 pol->xfrm_vec[i].encap_family = mp->new_family;
79226 /* flush bundles */
79227 - atomic_inc(&pol->genid);
79228 + atomic_inc_unchecked(&pol->genid);
79229 }
79230 }
79231
79232 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
79233 index 5b228f9..6aca4e3 100644
79234 --- a/net/xfrm/xfrm_state.c
79235 +++ b/net/xfrm/xfrm_state.c
79236 @@ -1981,8 +1981,10 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay)
79237 goto error;
79238
79239 x->outer_mode = xfrm_get_mode(x->props.mode, family);
79240 - if (x->outer_mode == NULL)
79241 + if (x->outer_mode == NULL) {
79242 + err = -EPROTONOSUPPORT;
79243 goto error;
79244 + }
79245
79246 if (init_replay) {
79247 err = xfrm_init_replay(x);
79248 diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
79249 index 44293b3..be1d3e58 100644
79250 --- a/net/xfrm/xfrm_user.c
79251 +++ b/net/xfrm/xfrm_user.c
79252 @@ -1413,6 +1413,7 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
79253 struct xfrm_user_tmpl *up = &vec[i];
79254 struct xfrm_tmpl *kp = &xp->xfrm_vec[i];
79255
79256 + memset(up, 0, sizeof(*up));
79257 memcpy(&up->id, &kp->id, sizeof(up->id));
79258 up->family = kp->encap_family;
79259 memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr));
79260 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79261 index ff1720d..ed8475e 100644
79262 --- a/scripts/Makefile.build
79263 +++ b/scripts/Makefile.build
79264 @@ -111,7 +111,7 @@ endif
79265 endif
79266
79267 # Do not include host rules unless needed
79268 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79269 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
79270 include scripts/Makefile.host
79271 endif
79272
79273 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79274 index 686cb0d..9d653bf 100644
79275 --- a/scripts/Makefile.clean
79276 +++ b/scripts/Makefile.clean
79277 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79278 __clean-files := $(extra-y) $(always) \
79279 $(targets) $(clean-files) \
79280 $(host-progs) \
79281 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79282 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79283 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79284
79285 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79286
79287 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79288 index 1ac414f..38575f7 100644
79289 --- a/scripts/Makefile.host
79290 +++ b/scripts/Makefile.host
79291 @@ -31,6 +31,8 @@
79292 # Note: Shared libraries consisting of C++ files are not supported
79293
79294 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79295 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79296 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
79297
79298 # C code
79299 # Executables compiled from a single .c file
79300 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79301 # Shared libaries (only .c supported)
79302 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79303 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79304 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79305 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
79306 # Remove .so files from "xxx-objs"
79307 host-cobjs := $(filter-out %.so,$(host-cobjs))
79308 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
79309
79310 -#Object (.o) files used by the shared libaries
79311 +# Object (.o) files used by the shared libaries
79312 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
79313 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
79314
79315 # output directory for programs/.o files
79316 # hostprogs-y := tools/build may have been specified. Retrieve directory
79317 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
79318 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
79319 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
79320 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
79321 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
79322 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
79323 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
79324 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
79325
79326 obj-dirs += $(host-objdirs)
79327 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
79328 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
79329 $(call if_changed_dep,host-cshobjs)
79330
79331 +# Compile .c file, create position independent .o file
79332 +# host-cxxshobjs -> .o
79333 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
79334 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
79335 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
79336 + $(call if_changed_dep,host-cxxshobjs)
79337 +
79338 # Link a shared library, based on position independent .o files
79339 # *.o -> .so shared library (host-cshlib)
79340 quiet_cmd_host-cshlib = HOSTLLD -shared $@
79341 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
79342 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
79343 $(call if_changed,host-cshlib)
79344
79345 +# Link a shared library, based on position independent .o files
79346 +# *.o -> .so shared library (host-cxxshlib)
79347 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
79348 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
79349 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
79350 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
79351 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
79352 + $(call if_changed,host-cxxshlib)
79353 +
79354 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
79355 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
79356 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
79357
79358 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79359 index cb1f50c..cef2a7c 100644
79360 --- a/scripts/basic/fixdep.c
79361 +++ b/scripts/basic/fixdep.c
79362 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79363 /*
79364 * Lookup a value in the configuration string.
79365 */
79366 -static int is_defined_config(const char *name, int len, unsigned int hash)
79367 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79368 {
79369 struct item *aux;
79370
79371 @@ -211,10 +211,10 @@ static void clear_config(void)
79372 /*
79373 * Record the use of a CONFIG_* word.
79374 */
79375 -static void use_config(const char *m, int slen)
79376 +static void use_config(const char *m, unsigned int slen)
79377 {
79378 unsigned int hash = strhash(m, slen);
79379 - int c, i;
79380 + unsigned int c, i;
79381
79382 if (is_defined_config(m, slen, hash))
79383 return;
79384 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79385
79386 static void parse_config_file(const char *map, size_t len)
79387 {
79388 - const int *end = (const int *) (map + len);
79389 + const unsigned int *end = (const unsigned int *) (map + len);
79390 /* start at +1, so that p can never be < map */
79391 - const int *m = (const int *) map + 1;
79392 + const unsigned int *m = (const unsigned int *) map + 1;
79393 const char *p, *q;
79394
79395 for (; m < end; m++) {
79396 @@ -406,7 +406,7 @@ static void print_deps(void)
79397 static void traps(void)
79398 {
79399 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79400 - int *p = (int *)test;
79401 + unsigned int *p = (unsigned int *)test;
79402
79403 if (*p != INT_CONF) {
79404 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79405 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79406 new file mode 100644
79407 index 0000000..008ac1a
79408 --- /dev/null
79409 +++ b/scripts/gcc-plugin.sh
79410 @@ -0,0 +1,17 @@
79411 +#!/bin/bash
79412 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
79413 +#include "gcc-plugin.h"
79414 +#include "tree.h"
79415 +#include "tm.h"
79416 +#include "rtl.h"
79417 +#ifdef ENABLE_BUILD_WITH_CXX
79418 +#warning $2
79419 +#else
79420 +#warning $1
79421 +#endif
79422 +EOF`
79423 +if [ $? -eq 0 ]
79424 +then
79425 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
79426 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
79427 +fi
79428 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
79429 index cd9c6c6..0c8f0fa 100644
79430 --- a/scripts/link-vmlinux.sh
79431 +++ b/scripts/link-vmlinux.sh
79432 @@ -147,7 +147,7 @@ else
79433 fi;
79434
79435 # final build of init/
79436 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
79437 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
79438
79439 kallsymso=""
79440 kallsyms_vmlinux=""
79441 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79442 index 5759751..b170367 100644
79443 --- a/scripts/mod/file2alias.c
79444 +++ b/scripts/mod/file2alias.c
79445 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79446 unsigned long size, unsigned long id_size,
79447 void *symval)
79448 {
79449 - int i;
79450 + unsigned int i;
79451
79452 if (size % id_size || size < id_size) {
79453 if (cross_build != 0)
79454 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79455 /* USB is special because the bcdDevice can be matched against a numeric range */
79456 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
79457 static void do_usb_entry(struct usb_device_id *id,
79458 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79459 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79460 unsigned char range_lo, unsigned char range_hi,
79461 unsigned char max, struct module *mod)
79462 {
79463 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79464 {
79465 unsigned int devlo, devhi;
79466 unsigned char chi, clo, max;
79467 - int ndigits;
79468 + unsigned int ndigits;
79469
79470 id->match_flags = TO_NATIVE(id->match_flags);
79471 id->idVendor = TO_NATIVE(id->idVendor);
79472 @@ -504,7 +504,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79473 for (i = 0; i < count; i++) {
79474 const char *id = (char *)devs[i].id;
79475 char acpi_id[sizeof(devs[0].id)];
79476 - int j;
79477 + unsigned int j;
79478
79479 buf_printf(&mod->dev_table_buf,
79480 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79481 @@ -534,7 +534,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79482
79483 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79484 const char *id = (char *)card->devs[j].id;
79485 - int i2, j2;
79486 + unsigned int i2, j2;
79487 int dup = 0;
79488
79489 if (!id[0])
79490 @@ -560,7 +560,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79491 /* add an individual alias for every device entry */
79492 if (!dup) {
79493 char acpi_id[sizeof(card->devs[0].id)];
79494 - int k;
79495 + unsigned int k;
79496
79497 buf_printf(&mod->dev_table_buf,
79498 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79499 @@ -885,7 +885,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79500 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79501 char *alias)
79502 {
79503 - int i, j;
79504 + unsigned int i, j;
79505
79506 sprintf(alias, "dmi*");
79507
79508 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79509 index 0f84bb3..2d42035 100644
79510 --- a/scripts/mod/modpost.c
79511 +++ b/scripts/mod/modpost.c
79512 @@ -925,6 +925,7 @@ enum mismatch {
79513 ANY_INIT_TO_ANY_EXIT,
79514 ANY_EXIT_TO_ANY_INIT,
79515 EXPORT_TO_INIT_EXIT,
79516 + DATA_TO_TEXT
79517 };
79518
79519 struct sectioncheck {
79520 @@ -1033,6 +1034,12 @@ const struct sectioncheck sectioncheck[] = {
79521 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79522 .mismatch = EXPORT_TO_INIT_EXIT,
79523 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79524 +},
79525 +/* Do not reference code from writable data */
79526 +{
79527 + .fromsec = { DATA_SECTIONS, NULL },
79528 + .tosec = { TEXT_SECTIONS, NULL },
79529 + .mismatch = DATA_TO_TEXT
79530 }
79531 };
79532
79533 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
79534 continue;
79535 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79536 continue;
79537 - if (sym->st_value == addr)
79538 - return sym;
79539 /* Find a symbol nearby - addr are maybe negative */
79540 d = sym->st_value - addr;
79541 + if (d == 0)
79542 + return sym;
79543 if (d < 0)
79544 d = addr - sym->st_value;
79545 if (d < distance) {
79546 @@ -1437,6 +1444,14 @@ static void report_sec_mismatch(const char *modname,
79547 tosym, prl_to, prl_to, tosym);
79548 free(prl_to);
79549 break;
79550 + case DATA_TO_TEXT:
79551 +#if 0
79552 + fprintf(stderr,
79553 + "The %s %s:%s references\n"
79554 + "the %s %s:%s%s\n",
79555 + from, fromsec, fromsym, to, tosec, tosym, to_p);
79556 +#endif
79557 + break;
79558 }
79559 fprintf(stderr, "\n");
79560 }
79561 @@ -1671,7 +1686,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
79562 static void check_sec_ref(struct module *mod, const char *modname,
79563 struct elf_info *elf)
79564 {
79565 - int i;
79566 + unsigned int i;
79567 Elf_Shdr *sechdrs = elf->sechdrs;
79568
79569 /* Walk through all sections */
79570 @@ -1769,7 +1784,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
79571 va_end(ap);
79572 }
79573
79574 -void buf_write(struct buffer *buf, const char *s, int len)
79575 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79576 {
79577 if (buf->size - buf->pos < len) {
79578 buf->size += len + SZ;
79579 @@ -1987,7 +2002,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
79580 if (fstat(fileno(file), &st) < 0)
79581 goto close_write;
79582
79583 - if (st.st_size != b->pos)
79584 + if (st.st_size != (off_t)b->pos)
79585 goto close_write;
79586
79587 tmp = NOFAIL(malloc(b->pos));
79588 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
79589 index 51207e4..f7d603d 100644
79590 --- a/scripts/mod/modpost.h
79591 +++ b/scripts/mod/modpost.h
79592 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
79593
79594 struct buffer {
79595 char *p;
79596 - int pos;
79597 - int size;
79598 + unsigned int pos;
79599 + unsigned int size;
79600 };
79601
79602 void __attribute__((format(printf, 2, 3)))
79603 buf_printf(struct buffer *buf, const char *fmt, ...);
79604
79605 void
79606 -buf_write(struct buffer *buf, const char *s, int len);
79607 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79608
79609 struct module {
79610 struct module *next;
79611 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79612 index 9dfcd6d..099068e 100644
79613 --- a/scripts/mod/sumversion.c
79614 +++ b/scripts/mod/sumversion.c
79615 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79616 goto out;
79617 }
79618
79619 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79620 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79621 warn("writing sum in %s failed: %s\n",
79622 filename, strerror(errno));
79623 goto out;
79624 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79625 index 5c11312..72742b5 100644
79626 --- a/scripts/pnmtologo.c
79627 +++ b/scripts/pnmtologo.c
79628 @@ -237,14 +237,14 @@ static void write_header(void)
79629 fprintf(out, " * Linux logo %s\n", logoname);
79630 fputs(" */\n\n", out);
79631 fputs("#include <linux/linux_logo.h>\n\n", out);
79632 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79633 + fprintf(out, "static unsigned char %s_data[] = {\n",
79634 logoname);
79635 }
79636
79637 static void write_footer(void)
79638 {
79639 fputs("\n};\n\n", out);
79640 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79641 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79642 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79643 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79644 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79645 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79646 fputs("\n};\n\n", out);
79647
79648 /* write logo clut */
79649 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79650 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79651 logoname);
79652 write_hex_cnt = 0;
79653 for (i = 0; i < logo_clutsize; i++) {
79654 diff --git a/security/Kconfig b/security/Kconfig
79655 index e9c6ac7..58348f4 100644
79656 --- a/security/Kconfig
79657 +++ b/security/Kconfig
79658 @@ -4,6 +4,888 @@
79659
79660 menu "Security options"
79661
79662 +menu "Grsecurity"
79663 +
79664 + config ARCH_TRACK_EXEC_LIMIT
79665 + bool
79666 +
79667 + config PAX_KERNEXEC_PLUGIN
79668 + bool
79669 +
79670 + config PAX_PER_CPU_PGD
79671 + bool
79672 +
79673 + config TASK_SIZE_MAX_SHIFT
79674 + int
79675 + depends on X86_64
79676 + default 47 if !PAX_PER_CPU_PGD
79677 + default 42 if PAX_PER_CPU_PGD
79678 +
79679 + config PAX_ENABLE_PAE
79680 + bool
79681 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79682 +
79683 + config PAX_USERCOPY_SLABS
79684 + bool
79685 +
79686 +config GRKERNSEC
79687 + bool "Grsecurity"
79688 + select CRYPTO
79689 + select CRYPTO_SHA256
79690 + select PROC_FS
79691 + select STOP_MACHINE
79692 + help
79693 + If you say Y here, you will be able to configure many features
79694 + that will enhance the security of your system. It is highly
79695 + recommended that you say Y here and read through the help
79696 + for each option so that you fully understand the features and
79697 + can evaluate their usefulness for your machine.
79698 +
79699 +choice
79700 + prompt "Configuration Method"
79701 + depends on GRKERNSEC
79702 + default GRKERNSEC_CONFIG_CUSTOM
79703 + help
79704 +
79705 +config GRKERNSEC_CONFIG_AUTO
79706 + bool "Automatic"
79707 + help
79708 + If you choose this configuration method, you'll be able to answer a small
79709 + number of simple questions about how you plan to use this kernel.
79710 + The settings of grsecurity and PaX will be automatically configured for
79711 + the highest commonly-used settings within the provided constraints.
79712 +
79713 + If you require additional configuration, custom changes can still be made
79714 + from the "custom configuration" menu.
79715 +
79716 +config GRKERNSEC_CONFIG_CUSTOM
79717 + bool "Custom"
79718 + help
79719 + If you choose this configuration method, you'll be able to configure all
79720 + grsecurity and PaX settings manually. Via this method, no options are
79721 + automatically enabled.
79722 +
79723 +endchoice
79724 +
79725 +choice
79726 + prompt "Usage Type"
79727 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79728 + default GRKERNSEC_CONFIG_SERVER
79729 + help
79730 +
79731 +config GRKERNSEC_CONFIG_SERVER
79732 + bool "Server"
79733 + help
79734 + Choose this option if you plan to use this kernel on a server.
79735 +
79736 +config GRKERNSEC_CONFIG_DESKTOP
79737 + bool "Desktop"
79738 + help
79739 + Choose this option if you plan to use this kernel on a desktop.
79740 +
79741 +endchoice
79742 +
79743 +choice
79744 + prompt "Virtualization Type"
79745 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
79746 + default GRKERNSEC_CONFIG_VIRT_NONE
79747 + help
79748 +
79749 +config GRKERNSEC_CONFIG_VIRT_NONE
79750 + bool "None"
79751 + help
79752 + Choose this option if this kernel will be run on bare metal.
79753 +
79754 +config GRKERNSEC_CONFIG_VIRT_GUEST
79755 + bool "Guest"
79756 + help
79757 + Choose this option if this kernel will be run as a VM guest.
79758 +
79759 +config GRKERNSEC_CONFIG_VIRT_HOST
79760 + bool "Host"
79761 + help
79762 + Choose this option if this kernel will be run as a VM host.
79763 +
79764 +endchoice
79765 +
79766 +choice
79767 + prompt "Virtualization Hardware"
79768 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79769 + help
79770 +
79771 +config GRKERNSEC_CONFIG_VIRT_EPT
79772 + bool "EPT/RVI Processor Support"
79773 + depends on X86
79774 + help
79775 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
79776 + hardware virtualization. This allows for additional kernel hardening protections
79777 + to operate without additional performance impact.
79778 +
79779 + To see if your Intel processor supports EPT, see:
79780 + http://ark.intel.com/Products/VirtualizationTechnology
79781 + (Most Core i3/5/7 support EPT)
79782 +
79783 + To see if your AMD processor supports RVI, see:
79784 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
79785 +
79786 +config GRKERNSEC_CONFIG_VIRT_SOFT
79787 + bool "First-gen/No Hardware Virtualization"
79788 + help
79789 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
79790 + support hardware virtualization or doesn't support the EPT/RVI extensions.
79791 +
79792 +endchoice
79793 +
79794 +choice
79795 + prompt "Virtualization Software"
79796 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79797 + help
79798 +
79799 +config GRKERNSEC_CONFIG_VIRT_XEN
79800 + bool "Xen"
79801 + help
79802 + Choose this option if this kernel is running as a Xen guest or host.
79803 +
79804 +config GRKERNSEC_CONFIG_VIRT_VMWARE
79805 + bool "VMWare"
79806 + help
79807 + Choose this option if this kernel is running as a VMWare guest or host.
79808 +
79809 +config GRKERNSEC_CONFIG_VIRT_KVM
79810 + bool "KVM"
79811 + help
79812 + Choose this option if this kernel is running as a KVM guest or host.
79813 +
79814 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
79815 + bool "VirtualBox"
79816 + help
79817 + Choose this option if this kernel is running as a VirtualBox guest or host.
79818 +
79819 +endchoice
79820 +
79821 +choice
79822 + prompt "Required Priorities"
79823 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79824 + default GRKERNSEC_CONFIG_PRIORITY_PERF
79825 + help
79826 +
79827 +config GRKERNSEC_CONFIG_PRIORITY_PERF
79828 + bool "Performance"
79829 + help
79830 + Choose this option if performance is of highest priority for this deployment
79831 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
79832 + and freed memory sanitizing will be disabled.
79833 +
79834 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
79835 + bool "Security"
79836 + help
79837 + Choose this option if security is of highest priority for this deployment of
79838 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
79839 + be enabled for this kernel. In a worst-case scenario, these features can
79840 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
79841 +
79842 +endchoice
79843 +
79844 +menu "Default Special Groups"
79845 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79846 +
79847 +config GRKERNSEC_PROC_GID
79848 + int "GID exempted from /proc restrictions"
79849 + default 1001
79850 + help
79851 + Setting this GID determines which group will be exempted from
79852 + grsecurity's /proc restrictions, allowing users of the specified
79853 + group to view network statistics and the existence of other users'
79854 + processes on the system.
79855 +
79856 +config GRKERNSEC_TPE_GID
79857 + int "GID for untrusted users"
79858 + depends on GRKERNSEC_CONFIG_SERVER
79859 + default 1005
79860 + help
79861 + Setting this GID determines which group untrusted users should
79862 + be added to. These users will be placed under grsecurity's Trusted Path
79863 + Execution mechanism, preventing them from executing their own binaries.
79864 + The users will only be able to execute binaries in directories owned and
79865 + writable only by the root user.
79866 +
79867 +config GRKERNSEC_SYMLINKOWN_GID
79868 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
79869 + depends on GRKERNSEC_CONFIG_SERVER
79870 + default 1006
79871 + help
79872 + Setting this GID determines what group kernel-enforced
79873 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
79874 + is enabled, a sysctl option with name "symlinkown_gid" is created.
79875 +
79876 +
79877 +endmenu
79878 +
79879 +menu "Customize Configuration"
79880 +depends on GRKERNSEC
79881 +
79882 +menu "PaX"
79883 +
79884 +config PAX
79885 + bool "Enable various PaX features"
79886 + default y if GRKERNSEC_CONFIG_AUTO
79887 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79888 + help
79889 + This allows you to enable various PaX features. PaX adds
79890 + intrusion prevention mechanisms to the kernel that reduce
79891 + the risks posed by exploitable memory corruption bugs.
79892 +
79893 +menu "PaX Control"
79894 + depends on PAX
79895 +
79896 +config PAX_SOFTMODE
79897 + bool 'Support soft mode'
79898 + help
79899 + Enabling this option will allow you to run PaX in soft mode, that
79900 + is, PaX features will not be enforced by default, only on executables
79901 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79902 + support as they are the only way to mark executables for soft mode use.
79903 +
79904 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79905 + line option on boot. Furthermore you can control various PaX features
79906 + at runtime via the entries in /proc/sys/kernel/pax.
79907 +
79908 +config PAX_EI_PAX
79909 + bool 'Use legacy ELF header marking'
79910 + default y if GRKERNSEC_CONFIG_AUTO
79911 + help
79912 + Enabling this option will allow you to control PaX features on
79913 + a per executable basis via the 'chpax' utility available at
79914 + http://pax.grsecurity.net/. The control flags will be read from
79915 + an otherwise reserved part of the ELF header. This marking has
79916 + numerous drawbacks (no support for soft-mode, toolchain does not
79917 + know about the non-standard use of the ELF header) therefore it
79918 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79919 + support.
79920 +
79921 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79922 + support as well, they will override the legacy EI_PAX marks.
79923 +
79924 + If you enable none of the marking options then all applications
79925 + will run with PaX enabled on them by default.
79926 +
79927 +config PAX_PT_PAX_FLAGS
79928 + bool 'Use ELF program header marking'
79929 + default y if GRKERNSEC_CONFIG_AUTO
79930 + help
79931 + Enabling this option will allow you to control PaX features on
79932 + a per executable basis via the 'paxctl' utility available at
79933 + http://pax.grsecurity.net/. The control flags will be read from
79934 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79935 + has the benefits of supporting both soft mode and being fully
79936 + integrated into the toolchain (the binutils patch is available
79937 + from http://pax.grsecurity.net).
79938 +
79939 + Note that if you enable the legacy EI_PAX marking support as well,
79940 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79941 +
79942 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79943 + must make sure that the marks are the same if a binary has both marks.
79944 +
79945 + If you enable none of the marking options then all applications
79946 + will run with PaX enabled on them by default.
79947 +
79948 +config PAX_XATTR_PAX_FLAGS
79949 + bool 'Use filesystem extended attributes marking'
79950 + default y if GRKERNSEC_CONFIG_AUTO
79951 + select CIFS_XATTR if CIFS
79952 + select EXT2_FS_XATTR if EXT2_FS
79953 + select EXT3_FS_XATTR if EXT3_FS
79954 + select EXT4_FS_XATTR if EXT4_FS
79955 + select JFFS2_FS_XATTR if JFFS2_FS
79956 + select REISERFS_FS_XATTR if REISERFS_FS
79957 + select SQUASHFS_XATTR if SQUASHFS
79958 + select TMPFS_XATTR if TMPFS
79959 + select UBIFS_FS_XATTR if UBIFS_FS
79960 + help
79961 + Enabling this option will allow you to control PaX features on
79962 + a per executable basis via the 'setfattr' utility. The control
79963 + flags will be read from the user.pax.flags extended attribute of
79964 + the file. This marking has the benefit of supporting binary-only
79965 + applications that self-check themselves (e.g., skype) and would
79966 + not tolerate chpax/paxctl changes. The main drawback is that
79967 + extended attributes are not supported by some filesystems (e.g.,
79968 + isofs, udf, vfat) so copying files through such filesystems will
79969 + lose the extended attributes and these PaX markings.
79970 +
79971 + Note that if you enable the legacy EI_PAX marking support as well,
79972 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79973 +
79974 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79975 + must make sure that the marks are the same if a binary has both marks.
79976 +
79977 + If you enable none of the marking options then all applications
79978 + will run with PaX enabled on them by default.
79979 +
79980 +choice
79981 + prompt 'MAC system integration'
79982 + default PAX_HAVE_ACL_FLAGS
79983 + help
79984 + Mandatory Access Control systems have the option of controlling
79985 + PaX flags on a per executable basis, choose the method supported
79986 + by your particular system.
79987 +
79988 + - "none": if your MAC system does not interact with PaX,
79989 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79990 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79991 +
79992 + NOTE: this option is for developers/integrators only.
79993 +
79994 + config PAX_NO_ACL_FLAGS
79995 + bool 'none'
79996 +
79997 + config PAX_HAVE_ACL_FLAGS
79998 + bool 'direct'
79999 +
80000 + config PAX_HOOK_ACL_FLAGS
80001 + bool 'hook'
80002 +endchoice
80003 +
80004 +endmenu
80005 +
80006 +menu "Non-executable pages"
80007 + depends on PAX
80008 +
80009 +config PAX_NOEXEC
80010 + bool "Enforce non-executable pages"
80011 + default y if GRKERNSEC_CONFIG_AUTO
80012 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80013 + help
80014 + By design some architectures do not allow for protecting memory
80015 + pages against execution or even if they do, Linux does not make
80016 + use of this feature. In practice this means that if a page is
80017 + readable (such as the stack or heap) it is also executable.
80018 +
80019 + There is a well known exploit technique that makes use of this
80020 + fact and a common programming mistake where an attacker can
80021 + introduce code of his choice somewhere in the attacked program's
80022 + memory (typically the stack or the heap) and then execute it.
80023 +
80024 + If the attacked program was running with different (typically
80025 + higher) privileges than that of the attacker, then he can elevate
80026 + his own privilege level (e.g. get a root shell, write to files for
80027 + which he does not have write access to, etc).
80028 +
80029 + Enabling this option will let you choose from various features
80030 + that prevent the injection and execution of 'foreign' code in
80031 + a program.
80032 +
80033 + This will also break programs that rely on the old behaviour and
80034 + expect that dynamically allocated memory via the malloc() family
80035 + of functions is executable (which it is not). Notable examples
80036 + are the XFree86 4.x server, the java runtime and wine.
80037 +
80038 +config PAX_PAGEEXEC
80039 + bool "Paging based non-executable pages"
80040 + default y if GRKERNSEC_CONFIG_AUTO
80041 + 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)
80042 + select S390_SWITCH_AMODE if S390
80043 + select S390_EXEC_PROTECT if S390
80044 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80045 + help
80046 + This implementation is based on the paging feature of the CPU.
80047 + On i386 without hardware non-executable bit support there is a
80048 + variable but usually low performance impact, however on Intel's
80049 + P4 core based CPUs it is very high so you should not enable this
80050 + for kernels meant to be used on such CPUs.
80051 +
80052 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80053 + with hardware non-executable bit support there is no performance
80054 + impact, on ppc the impact is negligible.
80055 +
80056 + Note that several architectures require various emulations due to
80057 + badly designed userland ABIs, this will cause a performance impact
80058 + but will disappear as soon as userland is fixed. For example, ppc
80059 + userland MUST have been built with secure-plt by a recent toolchain.
80060 +
80061 +config PAX_SEGMEXEC
80062 + bool "Segmentation based non-executable pages"
80063 + default y if GRKERNSEC_CONFIG_AUTO
80064 + depends on PAX_NOEXEC && X86_32
80065 + help
80066 + This implementation is based on the segmentation feature of the
80067 + CPU and has a very small performance impact, however applications
80068 + will be limited to a 1.5 GB address space instead of the normal
80069 + 3 GB.
80070 +
80071 +config PAX_EMUTRAMP
80072 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80073 + default y if PARISC
80074 + help
80075 + There are some programs and libraries that for one reason or
80076 + another attempt to execute special small code snippets from
80077 + non-executable memory pages. Most notable examples are the
80078 + signal handler return code generated by the kernel itself and
80079 + the GCC trampolines.
80080 +
80081 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80082 + such programs will no longer work under your kernel.
80083 +
80084 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80085 + utilities to enable trampoline emulation for the affected programs
80086 + yet still have the protection provided by the non-executable pages.
80087 +
80088 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80089 + your system will not even boot.
80090 +
80091 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80092 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80093 + for the affected files.
80094 +
80095 + NOTE: enabling this feature *may* open up a loophole in the
80096 + protection provided by non-executable pages that an attacker
80097 + could abuse. Therefore the best solution is to not have any
80098 + files on your system that would require this option. This can
80099 + be achieved by not using libc5 (which relies on the kernel
80100 + signal handler return code) and not using or rewriting programs
80101 + that make use of the nested function implementation of GCC.
80102 + Skilled users can just fix GCC itself so that it implements
80103 + nested function calls in a way that does not interfere with PaX.
80104 +
80105 +config PAX_EMUSIGRT
80106 + bool "Automatically emulate sigreturn trampolines"
80107 + depends on PAX_EMUTRAMP && PARISC
80108 + default y
80109 + help
80110 + Enabling this option will have the kernel automatically detect
80111 + and emulate signal return trampolines executing on the stack
80112 + that would otherwise lead to task termination.
80113 +
80114 + This solution is intended as a temporary one for users with
80115 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80116 + Modula-3 runtime, etc) or executables linked to such, basically
80117 + everything that does not specify its own SA_RESTORER function in
80118 + normal executable memory like glibc 2.1+ does.
80119 +
80120 + On parisc you MUST enable this option, otherwise your system will
80121 + not even boot.
80122 +
80123 + NOTE: this feature cannot be disabled on a per executable basis
80124 + and since it *does* open up a loophole in the protection provided
80125 + by non-executable pages, the best solution is to not have any
80126 + files on your system that would require this option.
80127 +
80128 +config PAX_MPROTECT
80129 + bool "Restrict mprotect()"
80130 + default y if GRKERNSEC_CONFIG_AUTO
80131 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80132 + help
80133 + Enabling this option will prevent programs from
80134 + - changing the executable status of memory pages that were
80135 + not originally created as executable,
80136 + - making read-only executable pages writable again,
80137 + - creating executable pages from anonymous memory,
80138 + - making read-only-after-relocations (RELRO) data pages writable again.
80139 +
80140 + You should say Y here to complete the protection provided by
80141 + the enforcement of non-executable pages.
80142 +
80143 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80144 + this feature on a per file basis.
80145 +
80146 +config PAX_MPROTECT_COMPAT
80147 + bool "Use legacy/compat protection demoting (read help)"
80148 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80149 + depends on PAX_MPROTECT
80150 + help
80151 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80152 + by sending the proper error code to the application. For some broken
80153 + userland, this can cause problems with Python or other applications. The
80154 + current implementation however allows for applications like clamav to
80155 + detect if JIT compilation/execution is allowed and to fall back gracefully
80156 + to an interpreter-based mode if it does not. While we encourage everyone
80157 + to use the current implementation as-is and push upstream to fix broken
80158 + userland (note that the RWX logging option can assist with this), in some
80159 + environments this may not be possible. Having to disable MPROTECT
80160 + completely on certain binaries reduces the security benefit of PaX,
80161 + so this option is provided for those environments to revert to the old
80162 + behavior.
80163 +
80164 +config PAX_ELFRELOCS
80165 + bool "Allow ELF text relocations (read help)"
80166 + depends on PAX_MPROTECT
80167 + default n
80168 + help
80169 + Non-executable pages and mprotect() restrictions are effective
80170 + in preventing the introduction of new executable code into an
80171 + attacked task's address space. There remain only two venues
80172 + for this kind of attack: if the attacker can execute already
80173 + existing code in the attacked task then he can either have it
80174 + create and mmap() a file containing his code or have it mmap()
80175 + an already existing ELF library that does not have position
80176 + independent code in it and use mprotect() on it to make it
80177 + writable and copy his code there. While protecting against
80178 + the former approach is beyond PaX, the latter can be prevented
80179 + by having only PIC ELF libraries on one's system (which do not
80180 + need to relocate their code). If you are sure this is your case,
80181 + as is the case with all modern Linux distributions, then leave
80182 + this option disabled. You should say 'n' here.
80183 +
80184 +config PAX_ETEXECRELOCS
80185 + bool "Allow ELF ET_EXEC text relocations"
80186 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80187 + select PAX_ELFRELOCS
80188 + default y
80189 + help
80190 + On some architectures there are incorrectly created applications
80191 + that require text relocations and would not work without enabling
80192 + this option. If you are an alpha, ia64 or parisc user, you should
80193 + enable this option and disable it once you have made sure that
80194 + none of your applications need it.
80195 +
80196 +config PAX_EMUPLT
80197 + bool "Automatically emulate ELF PLT"
80198 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80199 + default y
80200 + help
80201 + Enabling this option will have the kernel automatically detect
80202 + and emulate the Procedure Linkage Table entries in ELF files.
80203 + On some architectures such entries are in writable memory, and
80204 + become non-executable leading to task termination. Therefore
80205 + it is mandatory that you enable this option on alpha, parisc,
80206 + sparc and sparc64, otherwise your system would not even boot.
80207 +
80208 + NOTE: this feature *does* open up a loophole in the protection
80209 + provided by the non-executable pages, therefore the proper
80210 + solution is to modify the toolchain to produce a PLT that does
80211 + not need to be writable.
80212 +
80213 +config PAX_DLRESOLVE
80214 + bool 'Emulate old glibc resolver stub'
80215 + depends on PAX_EMUPLT && SPARC
80216 + default n
80217 + help
80218 + This option is needed if userland has an old glibc (before 2.4)
80219 + that puts a 'save' instruction into the runtime generated resolver
80220 + stub that needs special emulation.
80221 +
80222 +config PAX_KERNEXEC
80223 + bool "Enforce non-executable kernel pages"
80224 + 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))
80225 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80226 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80227 + select PAX_KERNEXEC_PLUGIN if X86_64
80228 + help
80229 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80230 + that is, enabling this option will make it harder to inject
80231 + and execute 'foreign' code in kernel memory itself.
80232 +
80233 + Note that on x86_64 kernels there is a known regression when
80234 + this feature and KVM/VMX are both enabled in the host kernel.
80235 +
80236 +choice
80237 + prompt "Return Address Instrumentation Method"
80238 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80239 + depends on PAX_KERNEXEC_PLUGIN
80240 + help
80241 + Select the method used to instrument function pointer dereferences.
80242 + Note that binary modules cannot be instrumented by this approach.
80243 +
80244 + Note that the implementation requires a gcc with plugin support,
80245 + i.e., gcc 4.5 or newer. You may need to install the supporting
80246 + headers explicitly in addition to the normal gcc package.
80247 +
80248 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80249 + bool "bts"
80250 + help
80251 + This method is compatible with binary only modules but has
80252 + a higher runtime overhead.
80253 +
80254 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80255 + bool "or"
80256 + depends on !PARAVIRT
80257 + help
80258 + This method is incompatible with binary only modules but has
80259 + a lower runtime overhead.
80260 +endchoice
80261 +
80262 +config PAX_KERNEXEC_PLUGIN_METHOD
80263 + string
80264 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80265 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80266 + default ""
80267 +
80268 +config PAX_KERNEXEC_MODULE_TEXT
80269 + int "Minimum amount of memory reserved for module code"
80270 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
80271 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80272 + depends on PAX_KERNEXEC && X86_32 && MODULES
80273 + help
80274 + Due to implementation details the kernel must reserve a fixed
80275 + amount of memory for module code at compile time that cannot be
80276 + changed at runtime. Here you can specify the minimum amount
80277 + in MB that will be reserved. Due to the same implementation
80278 + details this size will always be rounded up to the next 2/4 MB
80279 + boundary (depends on PAE) so the actually available memory for
80280 + module code will usually be more than this minimum.
80281 +
80282 + The default 4 MB should be enough for most users but if you have
80283 + an excessive number of modules (e.g., most distribution configs
80284 + compile many drivers as modules) or use huge modules such as
80285 + nvidia's kernel driver, you will need to adjust this amount.
80286 + A good rule of thumb is to look at your currently loaded kernel
80287 + modules and add up their sizes.
80288 +
80289 +endmenu
80290 +
80291 +menu "Address Space Layout Randomization"
80292 + depends on PAX
80293 +
80294 +config PAX_ASLR
80295 + bool "Address Space Layout Randomization"
80296 + default y if GRKERNSEC_CONFIG_AUTO
80297 + help
80298 + Many if not most exploit techniques rely on the knowledge of
80299 + certain addresses in the attacked program. The following options
80300 + will allow the kernel to apply a certain amount of randomization
80301 + to specific parts of the program thereby forcing an attacker to
80302 + guess them in most cases. Any failed guess will most likely crash
80303 + the attacked program which allows the kernel to detect such attempts
80304 + and react on them. PaX itself provides no reaction mechanisms,
80305 + instead it is strongly encouraged that you make use of Nergal's
80306 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80307 + (http://www.grsecurity.net/) built-in crash detection features or
80308 + develop one yourself.
80309 +
80310 + By saying Y here you can choose to randomize the following areas:
80311 + - top of the task's kernel stack
80312 + - top of the task's userland stack
80313 + - base address for mmap() requests that do not specify one
80314 + (this includes all libraries)
80315 + - base address of the main executable
80316 +
80317 + It is strongly recommended to say Y here as address space layout
80318 + randomization has negligible impact on performance yet it provides
80319 + a very effective protection.
80320 +
80321 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80322 + this feature on a per file basis.
80323 +
80324 +config PAX_RANDKSTACK
80325 + bool "Randomize kernel stack base"
80326 + default y if GRKERNSEC_CONFIG_AUTO
80327 + depends on X86_TSC && X86
80328 + help
80329 + By saying Y here the kernel will randomize every task's kernel
80330 + stack on every system call. This will not only force an attacker
80331 + to guess it but also prevent him from making use of possible
80332 + leaked information about it.
80333 +
80334 + Since the kernel stack is a rather scarce resource, randomization
80335 + may cause unexpected stack overflows, therefore you should very
80336 + carefully test your system. Note that once enabled in the kernel
80337 + configuration, this feature cannot be disabled on a per file basis.
80338 +
80339 +config PAX_RANDUSTACK
80340 + bool "Randomize user stack base"
80341 + default y if GRKERNSEC_CONFIG_AUTO
80342 + depends on PAX_ASLR
80343 + help
80344 + By saying Y here the kernel will randomize every task's userland
80345 + stack. The randomization is done in two steps where the second
80346 + one may apply a big amount of shift to the top of the stack and
80347 + cause problems for programs that want to use lots of memory (more
80348 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80349 + For this reason the second step can be controlled by 'chpax' or
80350 + 'paxctl' on a per file basis.
80351 +
80352 +config PAX_RANDMMAP
80353 + bool "Randomize mmap() base"
80354 + default y if GRKERNSEC_CONFIG_AUTO
80355 + depends on PAX_ASLR
80356 + help
80357 + By saying Y here the kernel will use a randomized base address for
80358 + mmap() requests that do not specify one themselves. As a result
80359 + all dynamically loaded libraries will appear at random addresses
80360 + and therefore be harder to exploit by a technique where an attacker
80361 + attempts to execute library code for his purposes (e.g. spawn a
80362 + shell from an exploited program that is running at an elevated
80363 + privilege level).
80364 +
80365 + Furthermore, if a program is relinked as a dynamic ELF file, its
80366 + base address will be randomized as well, completing the full
80367 + randomization of the address space layout. Attacking such programs
80368 + becomes a guess game. You can find an example of doing this at
80369 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80370 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80371 +
80372 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80373 + feature on a per file basis.
80374 +
80375 +endmenu
80376 +
80377 +menu "Miscellaneous hardening features"
80378 +
80379 +config PAX_MEMORY_SANITIZE
80380 + bool "Sanitize all freed memory"
80381 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80382 + depends on !HIBERNATION
80383 + help
80384 + By saying Y here the kernel will erase memory pages as soon as they
80385 + are freed. This in turn reduces the lifetime of data stored in the
80386 + pages, making it less likely that sensitive information such as
80387 + passwords, cryptographic secrets, etc stay in memory for too long.
80388 +
80389 + This is especially useful for programs whose runtime is short, long
80390 + lived processes and the kernel itself benefit from this as long as
80391 + they operate on whole memory pages and ensure timely freeing of pages
80392 + that may hold sensitive information.
80393 +
80394 + The tradeoff is performance impact, on a single CPU system kernel
80395 + compilation sees a 3% slowdown, other systems and workloads may vary
80396 + and you are advised to test this feature on your expected workload
80397 + before deploying it.
80398 +
80399 + Note that this feature does not protect data stored in live pages,
80400 + e.g., process memory swapped to disk may stay there for a long time.
80401 +
80402 +config PAX_MEMORY_STACKLEAK
80403 + bool "Sanitize kernel stack"
80404 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80405 + depends on X86
80406 + help
80407 + By saying Y here the kernel will erase the kernel stack before it
80408 + returns from a system call. This in turn reduces the information
80409 + that a kernel stack leak bug can reveal.
80410 +
80411 + Note that such a bug can still leak information that was put on
80412 + the stack by the current system call (the one eventually triggering
80413 + the bug) but traces of earlier system calls on the kernel stack
80414 + cannot leak anymore.
80415 +
80416 + The tradeoff is performance impact: on a single CPU system kernel
80417 + compilation sees a 1% slowdown, other systems and workloads may vary
80418 + and you are advised to test this feature on your expected workload
80419 + before deploying it.
80420 +
80421 + Note that the full feature requires a gcc with plugin support,
80422 + i.e., gcc 4.5 or newer. You may need to install the supporting
80423 + headers explicitly in addition to the normal gcc package. Using
80424 + older gcc versions means that functions with large enough stack
80425 + frames may leave uninitialized memory behind that may be exposed
80426 + to a later syscall leaking the stack.
80427 +
80428 +config PAX_MEMORY_UDEREF
80429 + bool "Prevent invalid userland pointer dereference"
80430 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
80431 + depends on X86 && !UML_X86 && !XEN
80432 + select PAX_PER_CPU_PGD if X86_64
80433 + help
80434 + By saying Y here the kernel will be prevented from dereferencing
80435 + userland pointers in contexts where the kernel expects only kernel
80436 + pointers. This is both a useful runtime debugging feature and a
80437 + security measure that prevents exploiting a class of kernel bugs.
80438 +
80439 + The tradeoff is that some virtualization solutions may experience
80440 + a huge slowdown and therefore you should not enable this feature
80441 + for kernels meant to run in such environments. Whether a given VM
80442 + solution is affected or not is best determined by simply trying it
80443 + out, the performance impact will be obvious right on boot as this
80444 + mechanism engages from very early on. A good rule of thumb is that
80445 + VMs running on CPUs without hardware virtualization support (i.e.,
80446 + the majority of IA-32 CPUs) will likely experience the slowdown.
80447 +
80448 +config PAX_REFCOUNT
80449 + bool "Prevent various kernel object reference counter overflows"
80450 + default y if GRKERNSEC_CONFIG_AUTO
80451 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80452 + help
80453 + By saying Y here the kernel will detect and prevent overflowing
80454 + various (but not all) kinds of object reference counters. Such
80455 + overflows can normally occur due to bugs only and are often, if
80456 + not always, exploitable.
80457 +
80458 + The tradeoff is that data structures protected by an overflowed
80459 + refcount will never be freed and therefore will leak memory. Note
80460 + that this leak also happens even without this protection but in
80461 + that case the overflow can eventually trigger the freeing of the
80462 + data structure while it is still being used elsewhere, resulting
80463 + in the exploitable situation that this feature prevents.
80464 +
80465 + Since this has a negligible performance impact, you should enable
80466 + this feature.
80467 +
80468 +config PAX_USERCOPY
80469 + bool "Harden heap object copies between kernel and userland"
80470 + default y if GRKERNSEC_CONFIG_AUTO
80471 + depends on X86 || PPC || SPARC || ARM
80472 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80473 + select PAX_USERCOPY_SLABS
80474 + help
80475 + By saying Y here the kernel will enforce the size of heap objects
80476 + when they are copied in either direction between the kernel and
80477 + userland, even if only a part of the heap object is copied.
80478 +
80479 + Specifically, this checking prevents information leaking from the
80480 + kernel heap during kernel to userland copies (if the kernel heap
80481 + object is otherwise fully initialized) and prevents kernel heap
80482 + overflows during userland to kernel copies.
80483 +
80484 + Note that the current implementation provides the strictest bounds
80485 + checks for the SLUB allocator.
80486 +
80487 + Enabling this option also enables per-slab cache protection against
80488 + data in a given cache being copied into/out of via userland
80489 + accessors. Though the whitelist of regions will be reduced over
80490 + time, it notably protects important data structures like task structs.
80491 +
80492 + If frame pointers are enabled on x86, this option will also restrict
80493 + copies into and out of the kernel stack to local variables within a
80494 + single frame.
80495 +
80496 + Since this has a negligible performance impact, you should enable
80497 + this feature.
80498 +
80499 +config PAX_SIZE_OVERFLOW
80500 + bool "Prevent various integer overflows in function size parameters"
80501 + default y if GRKERNSEC_CONFIG_AUTO
80502 + depends on X86
80503 + help
80504 + By saying Y here the kernel recomputes expressions of function
80505 + arguments marked by a size_overflow attribute with double integer
80506 + precision (DImode/TImode for 32/64 bit integer types).
80507 +
80508 + The recomputed argument is checked against TYPE_MAX and an event
80509 + is logged on overflow and the triggering process is killed.
80510 +
80511 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
80512 +
80513 + Note that the implementation requires a gcc with plugin support,
80514 + i.e., gcc 4.5 or newer. You may need to install the supporting
80515 + headers explicitly in addition to the normal gcc package.
80516 +
80517 +config PAX_LATENT_ENTROPY
80518 + bool "Generate some entropy during boot"
80519 + default y if GRKERNSEC_CONFIG_AUTO
80520 + help
80521 + By saying Y here the kernel will instrument early boot code to
80522 + extract some entropy from both original and artificially created
80523 + program state. This will help especially embedded systems where
80524 + there is little 'natural' source of entropy normally. The cost
80525 + is some slowdown of the boot process.
80526 +
80527 + Note that the implementation requires a gcc with plugin support,
80528 + i.e., gcc 4.5 or newer. You may need to install the supporting
80529 + headers explicitly in addition to the normal gcc package.
80530 +
80531 + Note that entropy extracted this way is not cryptographically
80532 + secure!
80533 +
80534 +endmenu
80535 +
80536 +endmenu
80537 +
80538 +source grsecurity/Kconfig
80539 +
80540 +endmenu
80541 +
80542 +endmenu
80543 +
80544 source security/keys/Kconfig
80545
80546 config SECURITY_DMESG_RESTRICT
80547 @@ -103,7 +985,7 @@ config INTEL_TXT
80548 config LSM_MMAP_MIN_ADDR
80549 int "Low address space for LSM to protect from user allocation"
80550 depends on SECURITY && SECURITY_SELINUX
80551 - default 32768 if ARM
80552 + default 32768 if ALPHA || ARM || PARISC || SPARC32
80553 default 65536
80554 help
80555 This is the portion of low virtual memory which should be protected
80556 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
80557 index 8ea39aa..8569ac5 100644
80558 --- a/security/apparmor/lsm.c
80559 +++ b/security/apparmor/lsm.c
80560 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
80561 return error;
80562 }
80563
80564 -static struct security_operations apparmor_ops = {
80565 +static struct security_operations apparmor_ops __read_only = {
80566 .name = "apparmor",
80567
80568 .ptrace_access_check = apparmor_ptrace_access_check,
80569 diff --git a/security/commoncap.c b/security/commoncap.c
80570 index 6dbae46..d5611fd 100644
80571 --- a/security/commoncap.c
80572 +++ b/security/commoncap.c
80573 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
80574 return 0;
80575 }
80576
80577 +/* returns:
80578 + 1 for suid privilege
80579 + 2 for sgid privilege
80580 + 3 for fscap privilege
80581 +*/
80582 +int is_privileged_binary(const struct dentry *dentry)
80583 +{
80584 + struct cpu_vfs_cap_data capdata;
80585 + struct inode *inode = dentry->d_inode;
80586 +
80587 + if (!inode || S_ISDIR(inode->i_mode))
80588 + return 0;
80589 +
80590 + if (inode->i_mode & S_ISUID)
80591 + return 1;
80592 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
80593 + return 2;
80594 +
80595 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
80596 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
80597 + return 3;
80598 + }
80599 +
80600 + return 0;
80601 +}
80602 +
80603 /*
80604 * Attempt to get the on-exec apply capability sets for an executable file from
80605 * its xattrs and, if present, apply them to the proposed credentials being
80606 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
80607 const struct cred *cred = current_cred();
80608 kuid_t root_uid = make_kuid(cred->user_ns, 0);
80609
80610 + if (gr_acl_enable_at_secure())
80611 + return 1;
80612 +
80613 if (!uid_eq(cred->uid, root_uid)) {
80614 if (bprm->cap_effective)
80615 return 1;
80616 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
80617 index 3ccf7ac..d73ad64 100644
80618 --- a/security/integrity/ima/ima.h
80619 +++ b/security/integrity/ima/ima.h
80620 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80621 extern spinlock_t ima_queue_lock;
80622
80623 struct ima_h_table {
80624 - atomic_long_t len; /* number of stored measurements in the list */
80625 - atomic_long_t violations;
80626 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
80627 + atomic_long_unchecked_t violations;
80628 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
80629 };
80630 extern struct ima_h_table ima_htable;
80631 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
80632 index 88a2788..581ab92 100644
80633 --- a/security/integrity/ima/ima_api.c
80634 +++ b/security/integrity/ima/ima_api.c
80635 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80636 int result;
80637
80638 /* can overflow, only indicator */
80639 - atomic_long_inc(&ima_htable.violations);
80640 + atomic_long_inc_unchecked(&ima_htable.violations);
80641
80642 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
80643 if (!entry) {
80644 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
80645 index e1aa2b4..52027bf 100644
80646 --- a/security/integrity/ima/ima_fs.c
80647 +++ b/security/integrity/ima/ima_fs.c
80648 @@ -28,12 +28,12 @@
80649 static int valid_policy = 1;
80650 #define TMPBUFLEN 12
80651 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
80652 - loff_t *ppos, atomic_long_t *val)
80653 + loff_t *ppos, atomic_long_unchecked_t *val)
80654 {
80655 char tmpbuf[TMPBUFLEN];
80656 ssize_t len;
80657
80658 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
80659 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
80660 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
80661 }
80662
80663 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
80664 index 55a6271..ad829c3 100644
80665 --- a/security/integrity/ima/ima_queue.c
80666 +++ b/security/integrity/ima/ima_queue.c
80667 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
80668 INIT_LIST_HEAD(&qe->later);
80669 list_add_tail_rcu(&qe->later, &ima_measurements);
80670
80671 - atomic_long_inc(&ima_htable.len);
80672 + atomic_long_inc_unchecked(&ima_htable.len);
80673 key = ima_hash_key(entry->digest);
80674 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
80675 return 0;
80676 diff --git a/security/keys/compat.c b/security/keys/compat.c
80677 index c92d42b..341e7ea 100644
80678 --- a/security/keys/compat.c
80679 +++ b/security/keys/compat.c
80680 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
80681 if (ret == 0)
80682 goto no_payload_free;
80683
80684 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80685 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80686
80687 if (iov != iovstack)
80688 kfree(iov);
80689 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
80690 index 0f5b3f0..b8d47c1 100644
80691 --- a/security/keys/keyctl.c
80692 +++ b/security/keys/keyctl.c
80693 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
80694 /*
80695 * Copy the iovec data from userspace
80696 */
80697 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80698 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
80699 unsigned ioc)
80700 {
80701 for (; ioc > 0; ioc--) {
80702 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80703 * If successful, 0 will be returned.
80704 */
80705 long keyctl_instantiate_key_common(key_serial_t id,
80706 - const struct iovec *payload_iov,
80707 + const struct iovec __user *payload_iov,
80708 unsigned ioc,
80709 size_t plen,
80710 key_serial_t ringid)
80711 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
80712 [0].iov_len = plen
80713 };
80714
80715 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
80716 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
80717 }
80718
80719 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
80720 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
80721 if (ret == 0)
80722 goto no_payload_free;
80723
80724 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80725 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80726
80727 if (iov != iovstack)
80728 kfree(iov);
80729 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
80730 index 7445875..262834f 100644
80731 --- a/security/keys/keyring.c
80732 +++ b/security/keys/keyring.c
80733 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
80734 ret = -EFAULT;
80735
80736 for (loop = 0; loop < klist->nkeys; loop++) {
80737 + key_serial_t serial;
80738 key = rcu_deref_link_locked(klist, loop,
80739 keyring);
80740 + serial = key->serial;
80741
80742 tmp = sizeof(key_serial_t);
80743 if (tmp > buflen)
80744 tmp = buflen;
80745
80746 - if (copy_to_user(buffer,
80747 - &key->serial,
80748 - tmp) != 0)
80749 + if (copy_to_user(buffer, &serial, tmp))
80750 goto error;
80751
80752 buflen -= tmp;
80753 diff --git a/security/min_addr.c b/security/min_addr.c
80754 index f728728..6457a0c 100644
80755 --- a/security/min_addr.c
80756 +++ b/security/min_addr.c
80757 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
80758 */
80759 static void update_mmap_min_addr(void)
80760 {
80761 +#ifndef SPARC
80762 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80763 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80764 mmap_min_addr = dac_mmap_min_addr;
80765 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80766 #else
80767 mmap_min_addr = dac_mmap_min_addr;
80768 #endif
80769 +#endif
80770 }
80771
80772 /*
80773 diff --git a/security/security.c b/security/security.c
80774 index 860aeb3..45765c0 100644
80775 --- a/security/security.c
80776 +++ b/security/security.c
80777 @@ -20,6 +20,7 @@
80778 #include <linux/ima.h>
80779 #include <linux/evm.h>
80780 #include <linux/fsnotify.h>
80781 +#include <linux/mm.h>
80782 #include <linux/mman.h>
80783 #include <linux/mount.h>
80784 #include <linux/personality.h>
80785 @@ -32,8 +33,8 @@
80786 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
80787 CONFIG_DEFAULT_SECURITY;
80788
80789 -static struct security_operations *security_ops;
80790 -static struct security_operations default_security_ops = {
80791 +static struct security_operations *security_ops __read_only;
80792 +static struct security_operations default_security_ops __read_only = {
80793 .name = "default",
80794 };
80795
80796 @@ -74,7 +75,9 @@ int __init security_init(void)
80797
80798 void reset_security_ops(void)
80799 {
80800 + pax_open_kernel();
80801 security_ops = &default_security_ops;
80802 + pax_close_kernel();
80803 }
80804
80805 /* Save user chosen LSM */
80806 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80807 index db10db2..99a640f 100644
80808 --- a/security/selinux/hooks.c
80809 +++ b/security/selinux/hooks.c
80810 @@ -95,8 +95,6 @@
80811
80812 #define NUM_SEL_MNT_OPTS 5
80813
80814 -extern struct security_operations *security_ops;
80815 -
80816 /* SECMARK reference count */
80817 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80818
80819 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80820
80821 #endif
80822
80823 -static struct security_operations selinux_ops = {
80824 +static struct security_operations selinux_ops __read_only = {
80825 .name = "selinux",
80826
80827 .ptrace_access_check = selinux_ptrace_access_check,
80828 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80829 index c220f31..89fab3f 100644
80830 --- a/security/selinux/include/xfrm.h
80831 +++ b/security/selinux/include/xfrm.h
80832 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80833
80834 static inline void selinux_xfrm_notify_policyload(void)
80835 {
80836 - atomic_inc(&flow_cache_genid);
80837 + atomic_inc_unchecked(&flow_cache_genid);
80838 }
80839 #else
80840 static inline int selinux_xfrm_enabled(void)
80841 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80842 index ee0bb57..57fcd43 100644
80843 --- a/security/smack/smack_lsm.c
80844 +++ b/security/smack/smack_lsm.c
80845 @@ -3432,7 +3432,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80846 return 0;
80847 }
80848
80849 -struct security_operations smack_ops = {
80850 +struct security_operations smack_ops __read_only = {
80851 .name = "smack",
80852
80853 .ptrace_access_check = smack_ptrace_access_check,
80854 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80855 index c2d04a5..e6a1aeb 100644
80856 --- a/security/tomoyo/tomoyo.c
80857 +++ b/security/tomoyo/tomoyo.c
80858 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80859 * tomoyo_security_ops is a "struct security_operations" which is used for
80860 * registering TOMOYO.
80861 */
80862 -static struct security_operations tomoyo_security_ops = {
80863 +static struct security_operations tomoyo_security_ops __read_only = {
80864 .name = "tomoyo",
80865 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80866 .cred_prepare = tomoyo_cred_prepare,
80867 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
80868 index 51d6709..1f3dbe2 100644
80869 --- a/security/yama/Kconfig
80870 +++ b/security/yama/Kconfig
80871 @@ -1,6 +1,6 @@
80872 config SECURITY_YAMA
80873 bool "Yama support"
80874 - depends on SECURITY
80875 + depends on SECURITY && !GRKERNSEC
80876 select SECURITYFS
80877 select SECURITY_PATH
80878 default n
80879 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80880 index 270790d..c67dfcb 100644
80881 --- a/sound/aoa/codecs/onyx.c
80882 +++ b/sound/aoa/codecs/onyx.c
80883 @@ -54,7 +54,7 @@ struct onyx {
80884 spdif_locked:1,
80885 analog_locked:1,
80886 original_mute:2;
80887 - int open_count;
80888 + local_t open_count;
80889 struct codec_info *codec_info;
80890
80891 /* mutex serializes concurrent access to the device
80892 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80893 struct onyx *onyx = cii->codec_data;
80894
80895 mutex_lock(&onyx->mutex);
80896 - onyx->open_count++;
80897 + local_inc(&onyx->open_count);
80898 mutex_unlock(&onyx->mutex);
80899
80900 return 0;
80901 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80902 struct onyx *onyx = cii->codec_data;
80903
80904 mutex_lock(&onyx->mutex);
80905 - onyx->open_count--;
80906 - if (!onyx->open_count)
80907 + if (local_dec_and_test(&onyx->open_count))
80908 onyx->spdif_locked = onyx->analog_locked = 0;
80909 mutex_unlock(&onyx->mutex);
80910
80911 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80912 index ffd2025..df062c9 100644
80913 --- a/sound/aoa/codecs/onyx.h
80914 +++ b/sound/aoa/codecs/onyx.h
80915 @@ -11,6 +11,7 @@
80916 #include <linux/i2c.h>
80917 #include <asm/pmac_low_i2c.h>
80918 #include <asm/prom.h>
80919 +#include <asm/local.h>
80920
80921 /* PCM3052 register definitions */
80922
80923 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80924 index 08fde00..0bf641a 100644
80925 --- a/sound/core/oss/pcm_oss.c
80926 +++ b/sound/core/oss/pcm_oss.c
80927 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80928 if (in_kernel) {
80929 mm_segment_t fs;
80930 fs = snd_enter_user();
80931 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80932 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80933 snd_leave_user(fs);
80934 } else {
80935 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80936 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80937 }
80938 if (ret != -EPIPE && ret != -ESTRPIPE)
80939 break;
80940 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80941 if (in_kernel) {
80942 mm_segment_t fs;
80943 fs = snd_enter_user();
80944 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80945 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80946 snd_leave_user(fs);
80947 } else {
80948 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80949 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80950 }
80951 if (ret == -EPIPE) {
80952 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80953 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80954 struct snd_pcm_plugin_channel *channels;
80955 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80956 if (!in_kernel) {
80957 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80958 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80959 return -EFAULT;
80960 buf = runtime->oss.buffer;
80961 }
80962 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80963 }
80964 } else {
80965 tmp = snd_pcm_oss_write2(substream,
80966 - (const char __force *)buf,
80967 + (const char __force_kernel *)buf,
80968 runtime->oss.period_bytes, 0);
80969 if (tmp <= 0)
80970 goto err;
80971 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80972 struct snd_pcm_runtime *runtime = substream->runtime;
80973 snd_pcm_sframes_t frames, frames1;
80974 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80975 - char __user *final_dst = (char __force __user *)buf;
80976 + char __user *final_dst = (char __force_user *)buf;
80977 if (runtime->oss.plugin_first) {
80978 struct snd_pcm_plugin_channel *channels;
80979 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80980 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80981 xfer += tmp;
80982 runtime->oss.buffer_used -= tmp;
80983 } else {
80984 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80985 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80986 runtime->oss.period_bytes, 0);
80987 if (tmp <= 0)
80988 goto err;
80989 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80990 size1);
80991 size1 /= runtime->channels; /* frames */
80992 fs = snd_enter_user();
80993 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80994 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80995 snd_leave_user(fs);
80996 }
80997 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80998 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80999 index 91cdf94..4085161 100644
81000 --- a/sound/core/pcm_compat.c
81001 +++ b/sound/core/pcm_compat.c
81002 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81003 int err;
81004
81005 fs = snd_enter_user();
81006 - err = snd_pcm_delay(substream, &delay);
81007 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81008 snd_leave_user(fs);
81009 if (err < 0)
81010 return err;
81011 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81012 index 53b5ada..2db94c8 100644
81013 --- a/sound/core/pcm_native.c
81014 +++ b/sound/core/pcm_native.c
81015 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81016 switch (substream->stream) {
81017 case SNDRV_PCM_STREAM_PLAYBACK:
81018 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81019 - (void __user *)arg);
81020 + (void __force_user *)arg);
81021 break;
81022 case SNDRV_PCM_STREAM_CAPTURE:
81023 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81024 - (void __user *)arg);
81025 + (void __force_user *)arg);
81026 break;
81027 default:
81028 result = -EINVAL;
81029 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81030 index 5cf8d65..912a79c 100644
81031 --- a/sound/core/seq/seq_device.c
81032 +++ b/sound/core/seq/seq_device.c
81033 @@ -64,7 +64,7 @@ struct ops_list {
81034 int argsize; /* argument size */
81035
81036 /* operators */
81037 - struct snd_seq_dev_ops ops;
81038 + struct snd_seq_dev_ops *ops;
81039
81040 /* registred devices */
81041 struct list_head dev_list; /* list of devices */
81042 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81043
81044 mutex_lock(&ops->reg_mutex);
81045 /* copy driver operators */
81046 - ops->ops = *entry;
81047 + ops->ops = entry;
81048 ops->driver |= DRIVER_LOADED;
81049 ops->argsize = argsize;
81050
81051 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81052 dev->name, ops->id, ops->argsize, dev->argsize);
81053 return -EINVAL;
81054 }
81055 - if (ops->ops.init_device(dev) >= 0) {
81056 + if (ops->ops->init_device(dev) >= 0) {
81057 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81058 ops->num_init_devices++;
81059 } else {
81060 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81061 dev->name, ops->id, ops->argsize, dev->argsize);
81062 return -EINVAL;
81063 }
81064 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81065 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81066 dev->status = SNDRV_SEQ_DEVICE_FREE;
81067 dev->driver_data = NULL;
81068 ops->num_init_devices--;
81069 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81070 index 621e60e..f4543f5 100644
81071 --- a/sound/drivers/mts64.c
81072 +++ b/sound/drivers/mts64.c
81073 @@ -29,6 +29,7 @@
81074 #include <sound/initval.h>
81075 #include <sound/rawmidi.h>
81076 #include <sound/control.h>
81077 +#include <asm/local.h>
81078
81079 #define CARD_NAME "Miditerminal 4140"
81080 #define DRIVER_NAME "MTS64"
81081 @@ -67,7 +68,7 @@ struct mts64 {
81082 struct pardevice *pardev;
81083 int pardev_claimed;
81084
81085 - int open_count;
81086 + local_t open_count;
81087 int current_midi_output_port;
81088 int current_midi_input_port;
81089 u8 mode[MTS64_NUM_INPUT_PORTS];
81090 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81091 {
81092 struct mts64 *mts = substream->rmidi->private_data;
81093
81094 - if (mts->open_count == 0) {
81095 + if (local_read(&mts->open_count) == 0) {
81096 /* We don't need a spinlock here, because this is just called
81097 if the device has not been opened before.
81098 So there aren't any IRQs from the device */
81099 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81100
81101 msleep(50);
81102 }
81103 - ++(mts->open_count);
81104 + local_inc(&mts->open_count);
81105
81106 return 0;
81107 }
81108 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81109 struct mts64 *mts = substream->rmidi->private_data;
81110 unsigned long flags;
81111
81112 - --(mts->open_count);
81113 - if (mts->open_count == 0) {
81114 + if (local_dec_return(&mts->open_count) == 0) {
81115 /* We need the spinlock_irqsave here because we can still
81116 have IRQs at this point */
81117 spin_lock_irqsave(&mts->lock, flags);
81118 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81119
81120 msleep(500);
81121
81122 - } else if (mts->open_count < 0)
81123 - mts->open_count = 0;
81124 + } else if (local_read(&mts->open_count) < 0)
81125 + local_set(&mts->open_count, 0);
81126
81127 return 0;
81128 }
81129 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81130 index b953fb4..1999c01 100644
81131 --- a/sound/drivers/opl4/opl4_lib.c
81132 +++ b/sound/drivers/opl4/opl4_lib.c
81133 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81134 MODULE_DESCRIPTION("OPL4 driver");
81135 MODULE_LICENSE("GPL");
81136
81137 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81138 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81139 {
81140 int timeout = 10;
81141 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81142 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81143 index 3e32bd3..46fc152 100644
81144 --- a/sound/drivers/portman2x4.c
81145 +++ b/sound/drivers/portman2x4.c
81146 @@ -48,6 +48,7 @@
81147 #include <sound/initval.h>
81148 #include <sound/rawmidi.h>
81149 #include <sound/control.h>
81150 +#include <asm/local.h>
81151
81152 #define CARD_NAME "Portman 2x4"
81153 #define DRIVER_NAME "portman"
81154 @@ -85,7 +86,7 @@ struct portman {
81155 struct pardevice *pardev;
81156 int pardev_claimed;
81157
81158 - int open_count;
81159 + local_t open_count;
81160 int mode[PORTMAN_NUM_INPUT_PORTS];
81161 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81162 };
81163 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81164 index ea995af..f1bfa37 100644
81165 --- a/sound/firewire/amdtp.c
81166 +++ b/sound/firewire/amdtp.c
81167 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81168 ptr = s->pcm_buffer_pointer + data_blocks;
81169 if (ptr >= pcm->runtime->buffer_size)
81170 ptr -= pcm->runtime->buffer_size;
81171 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81172 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81173
81174 s->pcm_period_pointer += data_blocks;
81175 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81176 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
81177 */
81178 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81179 {
81180 - ACCESS_ONCE(s->source_node_id_field) =
81181 + ACCESS_ONCE_RW(s->source_node_id_field) =
81182 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81183 }
81184 EXPORT_SYMBOL(amdtp_out_stream_update);
81185 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81186 index b680c5e..061b7a0 100644
81187 --- a/sound/firewire/amdtp.h
81188 +++ b/sound/firewire/amdtp.h
81189 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
81190 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81191 struct snd_pcm_substream *pcm)
81192 {
81193 - ACCESS_ONCE(s->pcm) = pcm;
81194 + ACCESS_ONCE_RW(s->pcm) = pcm;
81195 }
81196
81197 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
81198 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81199 index d428ffe..751ef78 100644
81200 --- a/sound/firewire/isight.c
81201 +++ b/sound/firewire/isight.c
81202 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81203 ptr += count;
81204 if (ptr >= runtime->buffer_size)
81205 ptr -= runtime->buffer_size;
81206 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81207 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81208
81209 isight->period_counter += count;
81210 if (isight->period_counter >= runtime->period_size) {
81211 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81212 if (err < 0)
81213 return err;
81214
81215 - ACCESS_ONCE(isight->pcm_active) = true;
81216 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81217
81218 return 0;
81219 }
81220 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81221 {
81222 struct isight *isight = substream->private_data;
81223
81224 - ACCESS_ONCE(isight->pcm_active) = false;
81225 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81226
81227 mutex_lock(&isight->mutex);
81228 isight_stop_streaming(isight);
81229 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81230
81231 switch (cmd) {
81232 case SNDRV_PCM_TRIGGER_START:
81233 - ACCESS_ONCE(isight->pcm_running) = true;
81234 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81235 break;
81236 case SNDRV_PCM_TRIGGER_STOP:
81237 - ACCESS_ONCE(isight->pcm_running) = false;
81238 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81239 break;
81240 default:
81241 return -EINVAL;
81242 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81243 index 7bd5e33..1fcab12 100644
81244 --- a/sound/isa/cmi8330.c
81245 +++ b/sound/isa/cmi8330.c
81246 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81247
81248 struct snd_pcm *pcm;
81249 struct snd_cmi8330_stream {
81250 - struct snd_pcm_ops ops;
81251 + snd_pcm_ops_no_const ops;
81252 snd_pcm_open_callback_t open;
81253 void *private_data; /* sb or wss */
81254 } streams[2];
81255 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81256 index 733b014..56ce96f 100644
81257 --- a/sound/oss/sb_audio.c
81258 +++ b/sound/oss/sb_audio.c
81259 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
81260 buf16 = (signed short *)(localbuf + localoffs);
81261 while (c)
81262 {
81263 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81264 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81265 if (copy_from_user(lbuf8,
81266 userbuf+useroffs + p,
81267 locallen))
81268 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81269 index 09d4648..cf234c7 100644
81270 --- a/sound/oss/swarm_cs4297a.c
81271 +++ b/sound/oss/swarm_cs4297a.c
81272 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
81273 {
81274 struct cs4297a_state *s;
81275 u32 pwr, id;
81276 - mm_segment_t fs;
81277 int rval;
81278 #ifndef CONFIG_BCM_CS4297A_CSWARM
81279 u64 cfg;
81280 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
81281 if (!rval) {
81282 char *sb1250_duart_present;
81283
81284 +#if 0
81285 + mm_segment_t fs;
81286 fs = get_fs();
81287 set_fs(KERNEL_DS);
81288 -#if 0
81289 val = SOUND_MASK_LINE;
81290 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81291 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81292 val = initvol[i].vol;
81293 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81294 }
81295 + set_fs(fs);
81296 // cs4297a_write_ac97(s, 0x18, 0x0808);
81297 #else
81298 // cs4297a_write_ac97(s, 0x5e, 0x180);
81299 cs4297a_write_ac97(s, 0x02, 0x0808);
81300 cs4297a_write_ac97(s, 0x18, 0x0808);
81301 #endif
81302 - set_fs(fs);
81303
81304 list_add(&s->list, &cs4297a_devs);
81305
81306 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81307 index 2fdaadb..7df8fc6 100644
81308 --- a/sound/pci/hda/hda_codec.h
81309 +++ b/sound/pci/hda/hda_codec.h
81310 @@ -611,7 +611,7 @@ struct hda_bus_ops {
81311 /* notify power-up/down from codec to controller */
81312 void (*pm_notify)(struct hda_bus *bus);
81313 #endif
81314 -};
81315 +} __no_const;
81316
81317 /* template to pass to the bus constructor */
81318 struct hda_bus_template {
81319 @@ -711,6 +711,7 @@ struct hda_codec_ops {
81320 #endif
81321 void (*reboot_notify)(struct hda_codec *codec);
81322 };
81323 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81324
81325 /* record for amp information cache */
81326 struct hda_cache_head {
81327 @@ -741,7 +742,7 @@ struct hda_pcm_ops {
81328 struct snd_pcm_substream *substream);
81329 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81330 struct snd_pcm_substream *substream);
81331 -};
81332 +} __no_const;
81333
81334 /* PCM information for each substream */
81335 struct hda_pcm_stream {
81336 @@ -799,7 +800,7 @@ struct hda_codec {
81337 const char *modelname; /* model name for preset */
81338
81339 /* set by patch */
81340 - struct hda_codec_ops patch_ops;
81341 + hda_codec_ops_no_const patch_ops;
81342
81343 /* PCM to create, set by patch_ops.build_pcms callback */
81344 unsigned int num_pcms;
81345 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81346 index 0da778a..bc38b84 100644
81347 --- a/sound/pci/ice1712/ice1712.h
81348 +++ b/sound/pci/ice1712/ice1712.h
81349 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81350 unsigned int mask_flags; /* total mask bits */
81351 struct snd_akm4xxx_ops {
81352 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81353 - } ops;
81354 + } __no_const ops;
81355 };
81356
81357 struct snd_ice1712_spdif {
81358 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81359 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81360 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81361 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81362 - } ops;
81363 + } __no_const ops;
81364 };
81365
81366
81367 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81368 index a8159b81..5f006a5 100644
81369 --- a/sound/pci/ymfpci/ymfpci_main.c
81370 +++ b/sound/pci/ymfpci/ymfpci_main.c
81371 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81372 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81373 break;
81374 }
81375 - if (atomic_read(&chip->interrupt_sleep_count)) {
81376 - atomic_set(&chip->interrupt_sleep_count, 0);
81377 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81378 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81379 wake_up(&chip->interrupt_sleep);
81380 }
81381 __end:
81382 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81383 continue;
81384 init_waitqueue_entry(&wait, current);
81385 add_wait_queue(&chip->interrupt_sleep, &wait);
81386 - atomic_inc(&chip->interrupt_sleep_count);
81387 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81388 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81389 remove_wait_queue(&chip->interrupt_sleep, &wait);
81390 }
81391 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81392 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81393 spin_unlock(&chip->reg_lock);
81394
81395 - if (atomic_read(&chip->interrupt_sleep_count)) {
81396 - atomic_set(&chip->interrupt_sleep_count, 0);
81397 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81398 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81399 wake_up(&chip->interrupt_sleep);
81400 }
81401 }
81402 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81403 spin_lock_init(&chip->reg_lock);
81404 spin_lock_init(&chip->voice_lock);
81405 init_waitqueue_head(&chip->interrupt_sleep);
81406 - atomic_set(&chip->interrupt_sleep_count, 0);
81407 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81408 chip->card = card;
81409 chip->pci = pci;
81410 chip->irq = -1;
81411 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
81412 new file mode 100644
81413 index 0000000..50f2f2f
81414 --- /dev/null
81415 +++ b/tools/gcc/.gitignore
81416 @@ -0,0 +1 @@
81417 +size_overflow_hash.h
81418 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81419 new file mode 100644
81420 index 0000000..1d09b7e
81421 --- /dev/null
81422 +++ b/tools/gcc/Makefile
81423 @@ -0,0 +1,43 @@
81424 +#CC := gcc
81425 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81426 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81427 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81428 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81429 +
81430 +ifeq ($(PLUGINCC),$(HOSTCC))
81431 +HOSTLIBS := hostlibs
81432 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81433 +else
81434 +HOSTLIBS := hostcxxlibs
81435 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
81436 +endif
81437 +
81438 +$(HOSTLIBS)-y := constify_plugin.so
81439 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81440 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81441 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81442 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81443 +$(HOSTLIBS)-y += colorize_plugin.so
81444 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81445 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
81446 +
81447 +always := $($(HOSTLIBS)-y)
81448 +
81449 +constify_plugin-objs := constify_plugin.o
81450 +stackleak_plugin-objs := stackleak_plugin.o
81451 +kallocstat_plugin-objs := kallocstat_plugin.o
81452 +kernexec_plugin-objs := kernexec_plugin.o
81453 +checker_plugin-objs := checker_plugin.o
81454 +colorize_plugin-objs := colorize_plugin.o
81455 +size_overflow_plugin-objs := size_overflow_plugin.o
81456 +latent_entropy_plugin-objs := latent_entropy_plugin.o
81457 +
81458 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
81459 +
81460 +quiet_cmd_build_size_overflow_hash = GENHASH $@
81461 + cmd_build_size_overflow_hash = \
81462 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
81463 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
81464 + $(call if_changed,build_size_overflow_hash)
81465 +
81466 +targets += size_overflow_hash.h
81467 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81468 new file mode 100644
81469 index 0000000..d41b5af
81470 --- /dev/null
81471 +++ b/tools/gcc/checker_plugin.c
81472 @@ -0,0 +1,171 @@
81473 +/*
81474 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81475 + * Licensed under the GPL v2
81476 + *
81477 + * Note: the choice of the license means that the compilation process is
81478 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81479 + * but for the kernel it doesn't matter since it doesn't link against
81480 + * any of the gcc libraries
81481 + *
81482 + * gcc plugin to implement various sparse (source code checker) features
81483 + *
81484 + * TODO:
81485 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81486 + *
81487 + * BUGS:
81488 + * - none known
81489 + */
81490 +#include "gcc-plugin.h"
81491 +#include "config.h"
81492 +#include "system.h"
81493 +#include "coretypes.h"
81494 +#include "tree.h"
81495 +#include "tree-pass.h"
81496 +#include "flags.h"
81497 +#include "intl.h"
81498 +#include "toplev.h"
81499 +#include "plugin.h"
81500 +//#include "expr.h" where are you...
81501 +#include "diagnostic.h"
81502 +#include "plugin-version.h"
81503 +#include "tm.h"
81504 +#include "function.h"
81505 +#include "basic-block.h"
81506 +#include "gimple.h"
81507 +#include "rtl.h"
81508 +#include "emit-rtl.h"
81509 +#include "tree-flow.h"
81510 +#include "target.h"
81511 +
81512 +extern void c_register_addr_space (const char *str, addr_space_t as);
81513 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
81514 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
81515 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
81516 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
81517 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
81518 +
81519 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81520 +extern rtx emit_move_insn(rtx x, rtx y);
81521 +
81522 +int plugin_is_GPL_compatible;
81523 +
81524 +static struct plugin_info checker_plugin_info = {
81525 + .version = "201111150100",
81526 +};
81527 +
81528 +#define ADDR_SPACE_KERNEL 0
81529 +#define ADDR_SPACE_FORCE_KERNEL 1
81530 +#define ADDR_SPACE_USER 2
81531 +#define ADDR_SPACE_FORCE_USER 3
81532 +#define ADDR_SPACE_IOMEM 0
81533 +#define ADDR_SPACE_FORCE_IOMEM 0
81534 +#define ADDR_SPACE_PERCPU 0
81535 +#define ADDR_SPACE_FORCE_PERCPU 0
81536 +#define ADDR_SPACE_RCU 0
81537 +#define ADDR_SPACE_FORCE_RCU 0
81538 +
81539 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
81540 +{
81541 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
81542 +}
81543 +
81544 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
81545 +{
81546 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
81547 +}
81548 +
81549 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
81550 +{
81551 + return default_addr_space_valid_pointer_mode(mode, as);
81552 +}
81553 +
81554 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
81555 +{
81556 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
81557 +}
81558 +
81559 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
81560 +{
81561 + return default_addr_space_legitimize_address(x, oldx, mode, as);
81562 +}
81563 +
81564 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
81565 +{
81566 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
81567 + return true;
81568 +
81569 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
81570 + return true;
81571 +
81572 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
81573 + return true;
81574 +
81575 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
81576 + return true;
81577 +
81578 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
81579 + return true;
81580 +
81581 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
81582 + return true;
81583 +
81584 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
81585 + return true;
81586 +
81587 + return subset == superset;
81588 +}
81589 +
81590 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
81591 +{
81592 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
81593 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
81594 +
81595 + return op;
81596 +}
81597 +
81598 +static void register_checker_address_spaces(void *event_data, void *data)
81599 +{
81600 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
81601 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
81602 + c_register_addr_space("__user", ADDR_SPACE_USER);
81603 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
81604 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
81605 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
81606 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
81607 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
81608 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
81609 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
81610 +
81611 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
81612 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
81613 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
81614 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
81615 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
81616 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
81617 + targetm.addr_space.convert = checker_addr_space_convert;
81618 +}
81619 +
81620 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81621 +{
81622 + const char * const plugin_name = plugin_info->base_name;
81623 + const int argc = plugin_info->argc;
81624 + const struct plugin_argument * const argv = plugin_info->argv;
81625 + int i;
81626 +
81627 + if (!plugin_default_version_check(version, &gcc_version)) {
81628 + error(G_("incompatible gcc/plugin versions"));
81629 + return 1;
81630 + }
81631 +
81632 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
81633 +
81634 + for (i = 0; i < argc; ++i)
81635 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81636 +
81637 + if (TARGET_64BIT == 0)
81638 + return 0;
81639 +
81640 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
81641 +
81642 + return 0;
81643 +}
81644 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
81645 new file mode 100644
81646 index 0000000..846aeb0
81647 --- /dev/null
81648 +++ b/tools/gcc/colorize_plugin.c
81649 @@ -0,0 +1,148 @@
81650 +/*
81651 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
81652 + * Licensed under the GPL v2
81653 + *
81654 + * Note: the choice of the license means that the compilation process is
81655 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81656 + * but for the kernel it doesn't matter since it doesn't link against
81657 + * any of the gcc libraries
81658 + *
81659 + * gcc plugin to colorize diagnostic output
81660 + *
81661 + */
81662 +
81663 +#include "gcc-plugin.h"
81664 +#include "config.h"
81665 +#include "system.h"
81666 +#include "coretypes.h"
81667 +#include "tree.h"
81668 +#include "tree-pass.h"
81669 +#include "flags.h"
81670 +#include "intl.h"
81671 +#include "toplev.h"
81672 +#include "plugin.h"
81673 +#include "diagnostic.h"
81674 +#include "plugin-version.h"
81675 +#include "tm.h"
81676 +
81677 +int plugin_is_GPL_compatible;
81678 +
81679 +static struct plugin_info colorize_plugin_info = {
81680 + .version = "201203092200",
81681 + .help = NULL,
81682 +};
81683 +
81684 +#define GREEN "\033[32m\033[2m"
81685 +#define LIGHTGREEN "\033[32m\033[1m"
81686 +#define YELLOW "\033[33m\033[2m"
81687 +#define LIGHTYELLOW "\033[33m\033[1m"
81688 +#define RED "\033[31m\033[2m"
81689 +#define LIGHTRED "\033[31m\033[1m"
81690 +#define BLUE "\033[34m\033[2m"
81691 +#define LIGHTBLUE "\033[34m\033[1m"
81692 +#define BRIGHT "\033[m\033[1m"
81693 +#define NORMAL "\033[m"
81694 +
81695 +static diagnostic_starter_fn old_starter;
81696 +static diagnostic_finalizer_fn old_finalizer;
81697 +
81698 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81699 +{
81700 + const char *color;
81701 + char *newprefix;
81702 +
81703 + switch (diagnostic->kind) {
81704 + case DK_NOTE:
81705 + color = LIGHTBLUE;
81706 + break;
81707 +
81708 + case DK_PEDWARN:
81709 + case DK_WARNING:
81710 + color = LIGHTYELLOW;
81711 + break;
81712 +
81713 + case DK_ERROR:
81714 + case DK_FATAL:
81715 + case DK_ICE:
81716 + case DK_PERMERROR:
81717 + case DK_SORRY:
81718 + color = LIGHTRED;
81719 + break;
81720 +
81721 + default:
81722 + color = NORMAL;
81723 + }
81724 +
81725 + old_starter(context, diagnostic);
81726 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
81727 + return;
81728 + pp_destroy_prefix(context->printer);
81729 + pp_set_prefix(context->printer, newprefix);
81730 +}
81731 +
81732 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81733 +{
81734 + old_finalizer(context, diagnostic);
81735 +}
81736 +
81737 +static void colorize_arm(void)
81738 +{
81739 + old_starter = diagnostic_starter(global_dc);
81740 + old_finalizer = diagnostic_finalizer(global_dc);
81741 +
81742 + diagnostic_starter(global_dc) = start_colorize;
81743 + diagnostic_finalizer(global_dc) = finalize_colorize;
81744 +}
81745 +
81746 +static unsigned int execute_colorize_rearm(void)
81747 +{
81748 + if (diagnostic_starter(global_dc) == start_colorize)
81749 + return 0;
81750 +
81751 + colorize_arm();
81752 + return 0;
81753 +}
81754 +
81755 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
81756 + .pass = {
81757 + .type = SIMPLE_IPA_PASS,
81758 + .name = "colorize_rearm",
81759 + .gate = NULL,
81760 + .execute = execute_colorize_rearm,
81761 + .sub = NULL,
81762 + .next = NULL,
81763 + .static_pass_number = 0,
81764 + .tv_id = TV_NONE,
81765 + .properties_required = 0,
81766 + .properties_provided = 0,
81767 + .properties_destroyed = 0,
81768 + .todo_flags_start = 0,
81769 + .todo_flags_finish = 0
81770 + }
81771 +};
81772 +
81773 +static void colorize_start_unit(void *gcc_data, void *user_data)
81774 +{
81775 + colorize_arm();
81776 +}
81777 +
81778 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81779 +{
81780 + const char * const plugin_name = plugin_info->base_name;
81781 + struct register_pass_info colorize_rearm_pass_info = {
81782 + .pass = &pass_ipa_colorize_rearm.pass,
81783 + .reference_pass_name = "*free_lang_data",
81784 + .ref_pass_instance_number = 1,
81785 + .pos_op = PASS_POS_INSERT_AFTER
81786 + };
81787 +
81788 + if (!plugin_default_version_check(version, &gcc_version)) {
81789 + error(G_("incompatible gcc/plugin versions"));
81790 + return 1;
81791 + }
81792 +
81793 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
81794 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
81795 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
81796 + return 0;
81797 +}
81798 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
81799 new file mode 100644
81800 index 0000000..048d4ff
81801 --- /dev/null
81802 +++ b/tools/gcc/constify_plugin.c
81803 @@ -0,0 +1,328 @@
81804 +/*
81805 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81806 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81807 + * Licensed under the GPL v2, or (at your option) v3
81808 + *
81809 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81810 + *
81811 + * Homepage:
81812 + * http://www.grsecurity.net/~ephox/const_plugin/
81813 + *
81814 + * Usage:
81815 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81816 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81817 + */
81818 +
81819 +#include "gcc-plugin.h"
81820 +#include "config.h"
81821 +#include "system.h"
81822 +#include "coretypes.h"
81823 +#include "tree.h"
81824 +#include "tree-pass.h"
81825 +#include "flags.h"
81826 +#include "intl.h"
81827 +#include "toplev.h"
81828 +#include "plugin.h"
81829 +#include "diagnostic.h"
81830 +#include "plugin-version.h"
81831 +#include "tm.h"
81832 +#include "function.h"
81833 +#include "basic-block.h"
81834 +#include "gimple.h"
81835 +#include "rtl.h"
81836 +#include "emit-rtl.h"
81837 +#include "tree-flow.h"
81838 +
81839 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81840 +
81841 +int plugin_is_GPL_compatible;
81842 +
81843 +static struct plugin_info const_plugin_info = {
81844 + .version = "201205300030",
81845 + .help = "no-constify\tturn off constification\n",
81846 +};
81847 +
81848 +static void deconstify_tree(tree node);
81849 +
81850 +static void deconstify_type(tree type)
81851 +{
81852 + tree field;
81853 +
81854 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
81855 + tree type = TREE_TYPE(field);
81856 +
81857 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81858 + continue;
81859 + if (!TYPE_READONLY(type))
81860 + continue;
81861 +
81862 + deconstify_tree(field);
81863 + }
81864 + TYPE_READONLY(type) = 0;
81865 + C_TYPE_FIELDS_READONLY(type) = 0;
81866 +}
81867 +
81868 +static void deconstify_tree(tree node)
81869 +{
81870 + tree old_type, new_type, field;
81871 +
81872 + old_type = TREE_TYPE(node);
81873 +
81874 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
81875 +
81876 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81877 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81878 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81879 + DECL_FIELD_CONTEXT(field) = new_type;
81880 +
81881 + deconstify_type(new_type);
81882 +
81883 + TREE_READONLY(node) = 0;
81884 + TREE_TYPE(node) = new_type;
81885 +}
81886 +
81887 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81888 +{
81889 + tree type;
81890 +
81891 + *no_add_attrs = true;
81892 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81893 + error("%qE attribute does not apply to functions", name);
81894 + return NULL_TREE;
81895 + }
81896 +
81897 + if (TREE_CODE(*node) == VAR_DECL) {
81898 + error("%qE attribute does not apply to variables", name);
81899 + return NULL_TREE;
81900 + }
81901 +
81902 + if (TYPE_P(*node)) {
81903 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81904 + *no_add_attrs = false;
81905 + else
81906 + error("%qE attribute applies to struct and union types only", name);
81907 + return NULL_TREE;
81908 + }
81909 +
81910 + type = TREE_TYPE(*node);
81911 +
81912 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81913 + error("%qE attribute applies to struct and union types only", name);
81914 + return NULL_TREE;
81915 + }
81916 +
81917 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81918 + error("%qE attribute is already applied to the type", name);
81919 + return NULL_TREE;
81920 + }
81921 +
81922 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81923 + error("%qE attribute used on type that is not constified", name);
81924 + return NULL_TREE;
81925 + }
81926 +
81927 + if (TREE_CODE(*node) == TYPE_DECL) {
81928 + deconstify_tree(*node);
81929 + return NULL_TREE;
81930 + }
81931 +
81932 + return NULL_TREE;
81933 +}
81934 +
81935 +static void constify_type(tree type)
81936 +{
81937 + TYPE_READONLY(type) = 1;
81938 + C_TYPE_FIELDS_READONLY(type) = 1;
81939 +}
81940 +
81941 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81942 +{
81943 + *no_add_attrs = true;
81944 + if (!TYPE_P(*node)) {
81945 + error("%qE attribute applies to types only", name);
81946 + return NULL_TREE;
81947 + }
81948 +
81949 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81950 + error("%qE attribute applies to struct and union types only", name);
81951 + return NULL_TREE;
81952 + }
81953 +
81954 + *no_add_attrs = false;
81955 + constify_type(*node);
81956 + return NULL_TREE;
81957 +}
81958 +
81959 +static struct attribute_spec no_const_attr = {
81960 + .name = "no_const",
81961 + .min_length = 0,
81962 + .max_length = 0,
81963 + .decl_required = false,
81964 + .type_required = false,
81965 + .function_type_required = false,
81966 + .handler = handle_no_const_attribute,
81967 +#if BUILDING_GCC_VERSION >= 4007
81968 + .affects_type_identity = true
81969 +#endif
81970 +};
81971 +
81972 +static struct attribute_spec do_const_attr = {
81973 + .name = "do_const",
81974 + .min_length = 0,
81975 + .max_length = 0,
81976 + .decl_required = false,
81977 + .type_required = false,
81978 + .function_type_required = false,
81979 + .handler = handle_do_const_attribute,
81980 +#if BUILDING_GCC_VERSION >= 4007
81981 + .affects_type_identity = true
81982 +#endif
81983 +};
81984 +
81985 +static void register_attributes(void *event_data, void *data)
81986 +{
81987 + register_attribute(&no_const_attr);
81988 + register_attribute(&do_const_attr);
81989 +}
81990 +
81991 +static bool is_fptr(tree field)
81992 +{
81993 + tree ptr = TREE_TYPE(field);
81994 +
81995 + if (TREE_CODE(ptr) != POINTER_TYPE)
81996 + return false;
81997 +
81998 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81999 +}
82000 +
82001 +static bool walk_struct(tree node)
82002 +{
82003 + tree field;
82004 +
82005 + if (TYPE_FIELDS(node) == NULL_TREE)
82006 + return false;
82007 +
82008 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82009 + gcc_assert(!TYPE_READONLY(node));
82010 + deconstify_type(node);
82011 + return false;
82012 + }
82013 +
82014 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82015 + tree type = TREE_TYPE(field);
82016 + enum tree_code code = TREE_CODE(type);
82017 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82018 + if (!(walk_struct(type)))
82019 + return false;
82020 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82021 + return false;
82022 + }
82023 + return true;
82024 +}
82025 +
82026 +static void finish_type(void *event_data, void *data)
82027 +{
82028 + tree type = (tree)event_data;
82029 +
82030 + if (type == NULL_TREE)
82031 + return;
82032 +
82033 + if (TYPE_READONLY(type))
82034 + return;
82035 +
82036 + if (walk_struct(type))
82037 + constify_type(type);
82038 +}
82039 +
82040 +static unsigned int check_local_variables(void);
82041 +
82042 +struct gimple_opt_pass pass_local_variable = {
82043 + {
82044 + .type = GIMPLE_PASS,
82045 + .name = "check_local_variables",
82046 + .gate = NULL,
82047 + .execute = check_local_variables,
82048 + .sub = NULL,
82049 + .next = NULL,
82050 + .static_pass_number = 0,
82051 + .tv_id = TV_NONE,
82052 + .properties_required = 0,
82053 + .properties_provided = 0,
82054 + .properties_destroyed = 0,
82055 + .todo_flags_start = 0,
82056 + .todo_flags_finish = 0
82057 + }
82058 +};
82059 +
82060 +static unsigned int check_local_variables(void)
82061 +{
82062 + tree var;
82063 + referenced_var_iterator rvi;
82064 +
82065 +#if BUILDING_GCC_VERSION == 4005
82066 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82067 +#else
82068 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82069 +#endif
82070 + tree type = TREE_TYPE(var);
82071 +
82072 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82073 + continue;
82074 +
82075 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82076 + continue;
82077 +
82078 + if (!TYPE_READONLY(type))
82079 + continue;
82080 +
82081 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82082 +// continue;
82083 +
82084 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82085 +// continue;
82086 +
82087 + if (walk_struct(type)) {
82088 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82089 + return 1;
82090 + }
82091 + }
82092 + return 0;
82093 +}
82094 +
82095 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82096 +{
82097 + const char * const plugin_name = plugin_info->base_name;
82098 + const int argc = plugin_info->argc;
82099 + const struct plugin_argument * const argv = plugin_info->argv;
82100 + int i;
82101 + bool constify = true;
82102 +
82103 + struct register_pass_info local_variable_pass_info = {
82104 + .pass = &pass_local_variable.pass,
82105 + .reference_pass_name = "*referenced_vars",
82106 + .ref_pass_instance_number = 1,
82107 + .pos_op = PASS_POS_INSERT_AFTER
82108 + };
82109 +
82110 + if (!plugin_default_version_check(version, &gcc_version)) {
82111 + error(G_("incompatible gcc/plugin versions"));
82112 + return 1;
82113 + }
82114 +
82115 + for (i = 0; i < argc; ++i) {
82116 + if (!(strcmp(argv[i].key, "no-constify"))) {
82117 + constify = false;
82118 + continue;
82119 + }
82120 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82121 + }
82122 +
82123 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82124 + if (constify) {
82125 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82126 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82127 + }
82128 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82129 +
82130 + return 0;
82131 +}
82132 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82133 new file mode 100644
82134 index 0000000..68b646e
82135 --- /dev/null
82136 +++ b/tools/gcc/generate_size_overflow_hash.sh
82137 @@ -0,0 +1,94 @@
82138 +#!/bin/bash
82139 +
82140 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82141 +
82142 +header1="size_overflow_hash.h"
82143 +database="size_overflow_hash.data"
82144 +n=65536
82145 +
82146 +usage() {
82147 +cat <<EOF
82148 +usage: $0 options
82149 +OPTIONS:
82150 + -h|--help help
82151 + -o header file
82152 + -d database file
82153 + -n hash array size
82154 +EOF
82155 + return 0
82156 +}
82157 +
82158 +while true
82159 +do
82160 + case "$1" in
82161 + -h|--help) usage && exit 0;;
82162 + -n) n=$2; shift 2;;
82163 + -o) header1="$2"; shift 2;;
82164 + -d) database="$2"; shift 2;;
82165 + --) shift 1; break ;;
82166 + *) break ;;
82167 + esac
82168 +done
82169 +
82170 +create_defines() {
82171 + for i in `seq 1 10`
82172 + do
82173 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
82174 + done
82175 + echo >> "$header1"
82176 +}
82177 +
82178 +create_structs () {
82179 + rm -f "$header1"
82180 +
82181 + create_defines
82182 +
82183 + cat "$database" | while read data
82184 + do
82185 + data_array=($data)
82186 + struct_hash_name="${data_array[0]}"
82187 + funcn="${data_array[1]}"
82188 + params="${data_array[2]}"
82189 + next="${data_array[5]}"
82190 +
82191 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
82192 +
82193 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
82194 + echo -en "\t.param\t= " >> "$header1"
82195 + line=
82196 + for param_num in ${params//-/ };
82197 + do
82198 + line="${line}PARAM"$param_num"|"
82199 + done
82200 +
82201 + echo -e "${line%?},\n};\n" >> "$header1"
82202 + done
82203 +}
82204 +
82205 +create_headers () {
82206 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
82207 +}
82208 +
82209 +create_array_elements () {
82210 + index=0
82211 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
82212 + do
82213 + data_array=($data)
82214 + i="${data_array[3]}"
82215 + hash="${data_array[4]}"
82216 + while [[ $index -lt $i ]]
82217 + do
82218 + echo -e "\t["$index"]\t= NULL," >> "$header1"
82219 + index=$(($index + 1))
82220 + done
82221 + index=$(($index + 1))
82222 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
82223 + done
82224 + echo '};' >> $header1
82225 +}
82226 +
82227 +create_structs
82228 +create_headers
82229 +create_array_elements
82230 +
82231 +exit 0
82232 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82233 new file mode 100644
82234 index 0000000..a86e422
82235 --- /dev/null
82236 +++ b/tools/gcc/kallocstat_plugin.c
82237 @@ -0,0 +1,167 @@
82238 +/*
82239 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82240 + * Licensed under the GPL v2
82241 + *
82242 + * Note: the choice of the license means that the compilation process is
82243 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82244 + * but for the kernel it doesn't matter since it doesn't link against
82245 + * any of the gcc libraries
82246 + *
82247 + * gcc plugin to find the distribution of k*alloc sizes
82248 + *
82249 + * TODO:
82250 + *
82251 + * BUGS:
82252 + * - none known
82253 + */
82254 +#include "gcc-plugin.h"
82255 +#include "config.h"
82256 +#include "system.h"
82257 +#include "coretypes.h"
82258 +#include "tree.h"
82259 +#include "tree-pass.h"
82260 +#include "flags.h"
82261 +#include "intl.h"
82262 +#include "toplev.h"
82263 +#include "plugin.h"
82264 +//#include "expr.h" where are you...
82265 +#include "diagnostic.h"
82266 +#include "plugin-version.h"
82267 +#include "tm.h"
82268 +#include "function.h"
82269 +#include "basic-block.h"
82270 +#include "gimple.h"
82271 +#include "rtl.h"
82272 +#include "emit-rtl.h"
82273 +
82274 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82275 +
82276 +int plugin_is_GPL_compatible;
82277 +
82278 +static const char * const kalloc_functions[] = {
82279 + "__kmalloc",
82280 + "kmalloc",
82281 + "kmalloc_large",
82282 + "kmalloc_node",
82283 + "kmalloc_order",
82284 + "kmalloc_order_trace",
82285 + "kmalloc_slab",
82286 + "kzalloc",
82287 + "kzalloc_node",
82288 +};
82289 +
82290 +static struct plugin_info kallocstat_plugin_info = {
82291 + .version = "201111150100",
82292 +};
82293 +
82294 +static unsigned int execute_kallocstat(void);
82295 +
82296 +static struct gimple_opt_pass kallocstat_pass = {
82297 + .pass = {
82298 + .type = GIMPLE_PASS,
82299 + .name = "kallocstat",
82300 + .gate = NULL,
82301 + .execute = execute_kallocstat,
82302 + .sub = NULL,
82303 + .next = NULL,
82304 + .static_pass_number = 0,
82305 + .tv_id = TV_NONE,
82306 + .properties_required = 0,
82307 + .properties_provided = 0,
82308 + .properties_destroyed = 0,
82309 + .todo_flags_start = 0,
82310 + .todo_flags_finish = 0
82311 + }
82312 +};
82313 +
82314 +static bool is_kalloc(const char *fnname)
82315 +{
82316 + size_t i;
82317 +
82318 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82319 + if (!strcmp(fnname, kalloc_functions[i]))
82320 + return true;
82321 + return false;
82322 +}
82323 +
82324 +static unsigned int execute_kallocstat(void)
82325 +{
82326 + basic_block bb;
82327 +
82328 + // 1. loop through BBs and GIMPLE statements
82329 + FOR_EACH_BB(bb) {
82330 + gimple_stmt_iterator gsi;
82331 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82332 + // gimple match:
82333 + tree fndecl, size;
82334 + gimple call_stmt;
82335 + const char *fnname;
82336 +
82337 + // is it a call
82338 + call_stmt = gsi_stmt(gsi);
82339 + if (!is_gimple_call(call_stmt))
82340 + continue;
82341 + fndecl = gimple_call_fndecl(call_stmt);
82342 + if (fndecl == NULL_TREE)
82343 + continue;
82344 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82345 + continue;
82346 +
82347 + // is it a call to k*alloc
82348 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82349 + if (!is_kalloc(fnname))
82350 + continue;
82351 +
82352 + // is the size arg the result of a simple const assignment
82353 + size = gimple_call_arg(call_stmt, 0);
82354 + while (true) {
82355 + gimple def_stmt;
82356 + expanded_location xloc;
82357 + size_t size_val;
82358 +
82359 + if (TREE_CODE(size) != SSA_NAME)
82360 + break;
82361 + def_stmt = SSA_NAME_DEF_STMT(size);
82362 + if (!def_stmt || !is_gimple_assign(def_stmt))
82363 + break;
82364 + if (gimple_num_ops(def_stmt) != 2)
82365 + break;
82366 + size = gimple_assign_rhs1(def_stmt);
82367 + if (!TREE_CONSTANT(size))
82368 + continue;
82369 + xloc = expand_location(gimple_location(def_stmt));
82370 + if (!xloc.file)
82371 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82372 + size_val = TREE_INT_CST_LOW(size);
82373 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82374 + break;
82375 + }
82376 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82377 +//debug_tree(gimple_call_fn(call_stmt));
82378 +//print_node(stderr, "pax", fndecl, 4);
82379 + }
82380 + }
82381 +
82382 + return 0;
82383 +}
82384 +
82385 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82386 +{
82387 + const char * const plugin_name = plugin_info->base_name;
82388 + struct register_pass_info kallocstat_pass_info = {
82389 + .pass = &kallocstat_pass.pass,
82390 + .reference_pass_name = "ssa",
82391 + .ref_pass_instance_number = 1,
82392 + .pos_op = PASS_POS_INSERT_AFTER
82393 + };
82394 +
82395 + if (!plugin_default_version_check(version, &gcc_version)) {
82396 + error(G_("incompatible gcc/plugin versions"));
82397 + return 1;
82398 + }
82399 +
82400 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82401 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82402 +
82403 + return 0;
82404 +}
82405 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82406 new file mode 100644
82407 index 0000000..98011fa
82408 --- /dev/null
82409 +++ b/tools/gcc/kernexec_plugin.c
82410 @@ -0,0 +1,427 @@
82411 +/*
82412 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82413 + * Licensed under the GPL v2
82414 + *
82415 + * Note: the choice of the license means that the compilation process is
82416 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82417 + * but for the kernel it doesn't matter since it doesn't link against
82418 + * any of the gcc libraries
82419 + *
82420 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82421 + *
82422 + * TODO:
82423 + *
82424 + * BUGS:
82425 + * - none known
82426 + */
82427 +#include "gcc-plugin.h"
82428 +#include "config.h"
82429 +#include "system.h"
82430 +#include "coretypes.h"
82431 +#include "tree.h"
82432 +#include "tree-pass.h"
82433 +#include "flags.h"
82434 +#include "intl.h"
82435 +#include "toplev.h"
82436 +#include "plugin.h"
82437 +//#include "expr.h" where are you...
82438 +#include "diagnostic.h"
82439 +#include "plugin-version.h"
82440 +#include "tm.h"
82441 +#include "function.h"
82442 +#include "basic-block.h"
82443 +#include "gimple.h"
82444 +#include "rtl.h"
82445 +#include "emit-rtl.h"
82446 +#include "tree-flow.h"
82447 +
82448 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82449 +extern rtx emit_move_insn(rtx x, rtx y);
82450 +
82451 +int plugin_is_GPL_compatible;
82452 +
82453 +static struct plugin_info kernexec_plugin_info = {
82454 + .version = "201111291120",
82455 + .help = "method=[bts|or]\tinstrumentation method\n"
82456 +};
82457 +
82458 +static unsigned int execute_kernexec_reload(void);
82459 +static unsigned int execute_kernexec_fptr(void);
82460 +static unsigned int execute_kernexec_retaddr(void);
82461 +static bool kernexec_cmodel_check(void);
82462 +
82463 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82464 +static void (*kernexec_instrument_retaddr)(rtx);
82465 +
82466 +static struct gimple_opt_pass kernexec_reload_pass = {
82467 + .pass = {
82468 + .type = GIMPLE_PASS,
82469 + .name = "kernexec_reload",
82470 + .gate = kernexec_cmodel_check,
82471 + .execute = execute_kernexec_reload,
82472 + .sub = NULL,
82473 + .next = NULL,
82474 + .static_pass_number = 0,
82475 + .tv_id = TV_NONE,
82476 + .properties_required = 0,
82477 + .properties_provided = 0,
82478 + .properties_destroyed = 0,
82479 + .todo_flags_start = 0,
82480 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82481 + }
82482 +};
82483 +
82484 +static struct gimple_opt_pass kernexec_fptr_pass = {
82485 + .pass = {
82486 + .type = GIMPLE_PASS,
82487 + .name = "kernexec_fptr",
82488 + .gate = kernexec_cmodel_check,
82489 + .execute = execute_kernexec_fptr,
82490 + .sub = NULL,
82491 + .next = NULL,
82492 + .static_pass_number = 0,
82493 + .tv_id = TV_NONE,
82494 + .properties_required = 0,
82495 + .properties_provided = 0,
82496 + .properties_destroyed = 0,
82497 + .todo_flags_start = 0,
82498 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82499 + }
82500 +};
82501 +
82502 +static struct rtl_opt_pass kernexec_retaddr_pass = {
82503 + .pass = {
82504 + .type = RTL_PASS,
82505 + .name = "kernexec_retaddr",
82506 + .gate = kernexec_cmodel_check,
82507 + .execute = execute_kernexec_retaddr,
82508 + .sub = NULL,
82509 + .next = NULL,
82510 + .static_pass_number = 0,
82511 + .tv_id = TV_NONE,
82512 + .properties_required = 0,
82513 + .properties_provided = 0,
82514 + .properties_destroyed = 0,
82515 + .todo_flags_start = 0,
82516 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
82517 + }
82518 +};
82519 +
82520 +static bool kernexec_cmodel_check(void)
82521 +{
82522 + tree section;
82523 +
82524 + if (ix86_cmodel != CM_KERNEL)
82525 + return false;
82526 +
82527 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
82528 + if (!section || !TREE_VALUE(section))
82529 + return true;
82530 +
82531 + section = TREE_VALUE(TREE_VALUE(section));
82532 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
82533 + return true;
82534 +
82535 + return false;
82536 +}
82537 +
82538 +/*
82539 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
82540 + */
82541 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
82542 +{
82543 + gimple asm_movabs_stmt;
82544 +
82545 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
82546 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
82547 + gimple_asm_set_volatile(asm_movabs_stmt, true);
82548 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
82549 + update_stmt(asm_movabs_stmt);
82550 +}
82551 +
82552 +/*
82553 + * find all asm() stmts that clobber r10 and add a reload of r10
82554 + */
82555 +static unsigned int execute_kernexec_reload(void)
82556 +{
82557 + basic_block bb;
82558 +
82559 + // 1. loop through BBs and GIMPLE statements
82560 + FOR_EACH_BB(bb) {
82561 + gimple_stmt_iterator gsi;
82562 +
82563 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82564 + // gimple match: __asm__ ("" : : : "r10");
82565 + gimple asm_stmt;
82566 + size_t nclobbers;
82567 +
82568 + // is it an asm ...
82569 + asm_stmt = gsi_stmt(gsi);
82570 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
82571 + continue;
82572 +
82573 + // ... clobbering r10
82574 + nclobbers = gimple_asm_nclobbers(asm_stmt);
82575 + while (nclobbers--) {
82576 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
82577 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
82578 + continue;
82579 + kernexec_reload_fptr_mask(&gsi);
82580 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
82581 + break;
82582 + }
82583 + }
82584 + }
82585 +
82586 + return 0;
82587 +}
82588 +
82589 +/*
82590 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
82591 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
82592 + */
82593 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
82594 +{
82595 + gimple assign_intptr, assign_new_fptr, call_stmt;
82596 + tree intptr, old_fptr, new_fptr, kernexec_mask;
82597 +
82598 + call_stmt = gsi_stmt(*gsi);
82599 + old_fptr = gimple_call_fn(call_stmt);
82600 +
82601 + // create temporary unsigned long variable used for bitops and cast fptr to it
82602 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
82603 + add_referenced_var(intptr);
82604 + mark_sym_for_renaming(intptr);
82605 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
82606 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82607 + update_stmt(assign_intptr);
82608 +
82609 + // apply logical or to temporary unsigned long and bitmask
82610 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
82611 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
82612 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
82613 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82614 + update_stmt(assign_intptr);
82615 +
82616 + // cast temporary unsigned long back to a temporary fptr variable
82617 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
82618 + add_referenced_var(new_fptr);
82619 + mark_sym_for_renaming(new_fptr);
82620 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
82621 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
82622 + update_stmt(assign_new_fptr);
82623 +
82624 + // replace call stmt fn with the new fptr
82625 + gimple_call_set_fn(call_stmt, new_fptr);
82626 + update_stmt(call_stmt);
82627 +}
82628 +
82629 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
82630 +{
82631 + gimple asm_or_stmt, call_stmt;
82632 + tree old_fptr, new_fptr, input, output;
82633 + VEC(tree, gc) *inputs = NULL;
82634 + VEC(tree, gc) *outputs = NULL;
82635 +
82636 + call_stmt = gsi_stmt(*gsi);
82637 + old_fptr = gimple_call_fn(call_stmt);
82638 +
82639 + // create temporary fptr variable
82640 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
82641 + add_referenced_var(new_fptr);
82642 + mark_sym_for_renaming(new_fptr);
82643 +
82644 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
82645 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
82646 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
82647 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
82648 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
82649 + VEC_safe_push(tree, gc, inputs, input);
82650 + VEC_safe_push(tree, gc, outputs, output);
82651 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
82652 + gimple_asm_set_volatile(asm_or_stmt, true);
82653 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
82654 + update_stmt(asm_or_stmt);
82655 +
82656 + // replace call stmt fn with the new fptr
82657 + gimple_call_set_fn(call_stmt, new_fptr);
82658 + update_stmt(call_stmt);
82659 +}
82660 +
82661 +/*
82662 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
82663 + */
82664 +static unsigned int execute_kernexec_fptr(void)
82665 +{
82666 + basic_block bb;
82667 +
82668 + // 1. loop through BBs and GIMPLE statements
82669 + FOR_EACH_BB(bb) {
82670 + gimple_stmt_iterator gsi;
82671 +
82672 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82673 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
82674 + tree fn;
82675 + gimple call_stmt;
82676 +
82677 + // is it a call ...
82678 + call_stmt = gsi_stmt(gsi);
82679 + if (!is_gimple_call(call_stmt))
82680 + continue;
82681 + fn = gimple_call_fn(call_stmt);
82682 + if (TREE_CODE(fn) == ADDR_EXPR)
82683 + continue;
82684 + if (TREE_CODE(fn) != SSA_NAME)
82685 + gcc_unreachable();
82686 +
82687 + // ... through a function pointer
82688 + fn = SSA_NAME_VAR(fn);
82689 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
82690 + continue;
82691 + fn = TREE_TYPE(fn);
82692 + if (TREE_CODE(fn) != POINTER_TYPE)
82693 + continue;
82694 + fn = TREE_TYPE(fn);
82695 + if (TREE_CODE(fn) != FUNCTION_TYPE)
82696 + continue;
82697 +
82698 + kernexec_instrument_fptr(&gsi);
82699 +
82700 +//debug_tree(gimple_call_fn(call_stmt));
82701 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82702 + }
82703 + }
82704 +
82705 + return 0;
82706 +}
82707 +
82708 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
82709 +static void kernexec_instrument_retaddr_bts(rtx insn)
82710 +{
82711 + rtx btsq;
82712 + rtvec argvec, constraintvec, labelvec;
82713 + int line;
82714 +
82715 + // create asm volatile("btsq $63,(%%rsp)":::)
82716 + argvec = rtvec_alloc(0);
82717 + constraintvec = rtvec_alloc(0);
82718 + labelvec = rtvec_alloc(0);
82719 + line = expand_location(RTL_LOCATION(insn)).line;
82720 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82721 + MEM_VOLATILE_P(btsq) = 1;
82722 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
82723 + emit_insn_before(btsq, insn);
82724 +}
82725 +
82726 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
82727 +static void kernexec_instrument_retaddr_or(rtx insn)
82728 +{
82729 + rtx orq;
82730 + rtvec argvec, constraintvec, labelvec;
82731 + int line;
82732 +
82733 + // create asm volatile("orq %%r10,(%%rsp)":::)
82734 + argvec = rtvec_alloc(0);
82735 + constraintvec = rtvec_alloc(0);
82736 + labelvec = rtvec_alloc(0);
82737 + line = expand_location(RTL_LOCATION(insn)).line;
82738 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82739 + MEM_VOLATILE_P(orq) = 1;
82740 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
82741 + emit_insn_before(orq, insn);
82742 +}
82743 +
82744 +/*
82745 + * find all asm level function returns and forcibly set the highest bit of the return address
82746 + */
82747 +static unsigned int execute_kernexec_retaddr(void)
82748 +{
82749 + rtx insn;
82750 +
82751 + // 1. find function returns
82752 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82753 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
82754 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
82755 + rtx body;
82756 +
82757 + // is it a retn
82758 + if (!JUMP_P(insn))
82759 + continue;
82760 + body = PATTERN(insn);
82761 + if (GET_CODE(body) == PARALLEL)
82762 + body = XVECEXP(body, 0, 0);
82763 + if (GET_CODE(body) != RETURN)
82764 + continue;
82765 + kernexec_instrument_retaddr(insn);
82766 + }
82767 +
82768 +// print_simple_rtl(stderr, get_insns());
82769 +// print_rtl(stderr, get_insns());
82770 +
82771 + return 0;
82772 +}
82773 +
82774 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82775 +{
82776 + const char * const plugin_name = plugin_info->base_name;
82777 + const int argc = plugin_info->argc;
82778 + const struct plugin_argument * const argv = plugin_info->argv;
82779 + int i;
82780 + struct register_pass_info kernexec_reload_pass_info = {
82781 + .pass = &kernexec_reload_pass.pass,
82782 + .reference_pass_name = "ssa",
82783 + .ref_pass_instance_number = 1,
82784 + .pos_op = PASS_POS_INSERT_AFTER
82785 + };
82786 + struct register_pass_info kernexec_fptr_pass_info = {
82787 + .pass = &kernexec_fptr_pass.pass,
82788 + .reference_pass_name = "ssa",
82789 + .ref_pass_instance_number = 1,
82790 + .pos_op = PASS_POS_INSERT_AFTER
82791 + };
82792 + struct register_pass_info kernexec_retaddr_pass_info = {
82793 + .pass = &kernexec_retaddr_pass.pass,
82794 + .reference_pass_name = "pro_and_epilogue",
82795 + .ref_pass_instance_number = 1,
82796 + .pos_op = PASS_POS_INSERT_AFTER
82797 + };
82798 +
82799 + if (!plugin_default_version_check(version, &gcc_version)) {
82800 + error(G_("incompatible gcc/plugin versions"));
82801 + return 1;
82802 + }
82803 +
82804 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
82805 +
82806 + if (TARGET_64BIT == 0)
82807 + return 0;
82808 +
82809 + for (i = 0; i < argc; ++i) {
82810 + if (!strcmp(argv[i].key, "method")) {
82811 + if (!argv[i].value) {
82812 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82813 + continue;
82814 + }
82815 + if (!strcmp(argv[i].value, "bts")) {
82816 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
82817 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
82818 + } else if (!strcmp(argv[i].value, "or")) {
82819 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
82820 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
82821 + fix_register("r10", 1, 1);
82822 + } else
82823 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82824 + continue;
82825 + }
82826 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82827 + }
82828 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
82829 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
82830 +
82831 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
82832 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
82833 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
82834 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
82835 +
82836 + return 0;
82837 +}
82838 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
82839 new file mode 100644
82840 index 0000000..b8008f7
82841 --- /dev/null
82842 +++ b/tools/gcc/latent_entropy_plugin.c
82843 @@ -0,0 +1,295 @@
82844 +/*
82845 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
82846 + * Licensed under the GPL v2
82847 + *
82848 + * Note: the choice of the license means that the compilation process is
82849 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82850 + * but for the kernel it doesn't matter since it doesn't link against
82851 + * any of the gcc libraries
82852 + *
82853 + * gcc plugin to help generate a little bit of entropy from program state,
82854 + * used during boot in the kernel
82855 + *
82856 + * TODO:
82857 + * - add ipa pass to identify not explicitly marked candidate functions
82858 + * - mix in more program state (function arguments/return values, loop variables, etc)
82859 + * - more instrumentation control via attribute parameters
82860 + *
82861 + * BUGS:
82862 + * - LTO needs -flto-partition=none for now
82863 + */
82864 +#include "gcc-plugin.h"
82865 +#include "config.h"
82866 +#include "system.h"
82867 +#include "coretypes.h"
82868 +#include "tree.h"
82869 +#include "tree-pass.h"
82870 +#include "flags.h"
82871 +#include "intl.h"
82872 +#include "toplev.h"
82873 +#include "plugin.h"
82874 +//#include "expr.h" where are you...
82875 +#include "diagnostic.h"
82876 +#include "plugin-version.h"
82877 +#include "tm.h"
82878 +#include "function.h"
82879 +#include "basic-block.h"
82880 +#include "gimple.h"
82881 +#include "rtl.h"
82882 +#include "emit-rtl.h"
82883 +#include "tree-flow.h"
82884 +
82885 +int plugin_is_GPL_compatible;
82886 +
82887 +static tree latent_entropy_decl;
82888 +
82889 +static struct plugin_info latent_entropy_plugin_info = {
82890 + .version = "201207271820",
82891 + .help = NULL
82892 +};
82893 +
82894 +static unsigned int execute_latent_entropy(void);
82895 +static bool gate_latent_entropy(void);
82896 +
82897 +static struct gimple_opt_pass latent_entropy_pass = {
82898 + .pass = {
82899 + .type = GIMPLE_PASS,
82900 + .name = "latent_entropy",
82901 + .gate = gate_latent_entropy,
82902 + .execute = execute_latent_entropy,
82903 + .sub = NULL,
82904 + .next = NULL,
82905 + .static_pass_number = 0,
82906 + .tv_id = TV_NONE,
82907 + .properties_required = PROP_gimple_leh | PROP_cfg,
82908 + .properties_provided = 0,
82909 + .properties_destroyed = 0,
82910 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
82911 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
82912 + }
82913 +};
82914 +
82915 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82916 +{
82917 + if (TREE_CODE(*node) != FUNCTION_DECL) {
82918 + *no_add_attrs = true;
82919 + error("%qE attribute only applies to functions", name);
82920 + }
82921 + return NULL_TREE;
82922 +}
82923 +
82924 +static struct attribute_spec latent_entropy_attr = {
82925 + .name = "latent_entropy",
82926 + .min_length = 0,
82927 + .max_length = 0,
82928 + .decl_required = true,
82929 + .type_required = false,
82930 + .function_type_required = false,
82931 + .handler = handle_latent_entropy_attribute,
82932 +#if BUILDING_GCC_VERSION >= 4007
82933 + .affects_type_identity = false
82934 +#endif
82935 +};
82936 +
82937 +static void register_attributes(void *event_data, void *data)
82938 +{
82939 + register_attribute(&latent_entropy_attr);
82940 +}
82941 +
82942 +static bool gate_latent_entropy(void)
82943 +{
82944 + tree latent_entropy_attr;
82945 +
82946 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
82947 + return latent_entropy_attr != NULL_TREE;
82948 +}
82949 +
82950 +static unsigned HOST_WIDE_INT seed;
82951 +static unsigned HOST_WIDE_INT get_random_const(void)
82952 +{
82953 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
82954 + return seed;
82955 +}
82956 +
82957 +static enum tree_code get_op(tree *rhs)
82958 +{
82959 + static enum tree_code op;
82960 + unsigned HOST_WIDE_INT random_const;
82961 +
82962 + random_const = get_random_const();
82963 +
82964 + switch (op) {
82965 + case BIT_XOR_EXPR:
82966 + op = PLUS_EXPR;
82967 + break;
82968 +
82969 + case PLUS_EXPR:
82970 + if (rhs) {
82971 + op = LROTATE_EXPR;
82972 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
82973 + break;
82974 + }
82975 +
82976 + case LROTATE_EXPR:
82977 + default:
82978 + op = BIT_XOR_EXPR;
82979 + break;
82980 + }
82981 + if (rhs)
82982 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
82983 + return op;
82984 +}
82985 +
82986 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
82987 +{
82988 + gimple_stmt_iterator gsi;
82989 + gimple assign;
82990 + tree addxorrol, rhs;
82991 + enum tree_code op;
82992 +
82993 + op = get_op(&rhs);
82994 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
82995 + assign = gimple_build_assign(local_entropy, addxorrol);
82996 + find_referenced_vars_in(assign);
82997 +//debug_bb(bb);
82998 + gsi = gsi_after_labels(bb);
82999 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83000 + update_stmt(assign);
83001 +}
83002 +
83003 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83004 +{
83005 + gimple_stmt_iterator gsi;
83006 + gimple assign;
83007 + tree addxorrol, temp;
83008 +
83009 + // 1. create temporary copy of latent_entropy
83010 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83011 + add_referenced_var(temp);
83012 + mark_sym_for_renaming(temp);
83013 +
83014 + // 2. read...
83015 + assign = gimple_build_assign(temp, latent_entropy_decl);
83016 + find_referenced_vars_in(assign);
83017 + gsi = gsi_after_labels(bb);
83018 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83019 + update_stmt(assign);
83020 +
83021 + // 3. ...modify...
83022 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83023 + assign = gimple_build_assign(temp, addxorrol);
83024 + find_referenced_vars_in(assign);
83025 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83026 + update_stmt(assign);
83027 +
83028 + // 4. ...write latent_entropy
83029 + assign = gimple_build_assign(latent_entropy_decl, temp);
83030 + find_referenced_vars_in(assign);
83031 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83032 + update_stmt(assign);
83033 +}
83034 +
83035 +static unsigned int execute_latent_entropy(void)
83036 +{
83037 + basic_block bb;
83038 + gimple assign;
83039 + gimple_stmt_iterator gsi;
83040 + tree local_entropy;
83041 +
83042 + if (!latent_entropy_decl) {
83043 + struct varpool_node *node;
83044 +
83045 + for (node = varpool_nodes; node; node = node->next) {
83046 + tree var = node->decl;
83047 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83048 + continue;
83049 + latent_entropy_decl = var;
83050 +// debug_tree(var);
83051 + break;
83052 + }
83053 + if (!latent_entropy_decl) {
83054 +// debug_tree(current_function_decl);
83055 + return 0;
83056 + }
83057 + }
83058 +
83059 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83060 +
83061 + // 1. create local entropy variable
83062 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83063 + add_referenced_var(local_entropy);
83064 + mark_sym_for_renaming(local_entropy);
83065 +
83066 + // 2. initialize local entropy variable
83067 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83068 + if (dom_info_available_p(CDI_DOMINATORS))
83069 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83070 + gsi = gsi_start_bb(bb);
83071 +
83072 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83073 +// gimple_set_location(assign, loc);
83074 + find_referenced_vars_in(assign);
83075 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83076 + update_stmt(assign);
83077 + bb = bb->next_bb;
83078 +
83079 + // 3. instrument each BB with an operation on the local entropy variable
83080 + while (bb != EXIT_BLOCK_PTR) {
83081 + perturb_local_entropy(bb, local_entropy);
83082 + bb = bb->next_bb;
83083 + };
83084 +
83085 + // 4. mix local entropy into the global entropy variable
83086 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83087 + return 0;
83088 +}
83089 +
83090 +static void start_unit_callback(void *gcc_data, void *user_data)
83091 +{
83092 +#if BUILDING_GCC_VERSION >= 4007
83093 + seed = get_random_seed(false);
83094 +#else
83095 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83096 + seed *= seed;
83097 +#endif
83098 +
83099 + if (in_lto_p)
83100 + return;
83101 +
83102 + // extern u64 latent_entropy
83103 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83104 +
83105 + TREE_STATIC(latent_entropy_decl) = 1;
83106 + TREE_PUBLIC(latent_entropy_decl) = 1;
83107 + TREE_USED(latent_entropy_decl) = 1;
83108 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83109 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83110 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83111 + DECL_INITIAL(latent_entropy_decl) = NULL;
83112 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83113 +// varpool_finalize_decl(latent_entropy_decl);
83114 +// varpool_mark_needed_node(latent_entropy_decl);
83115 +}
83116 +
83117 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83118 +{
83119 + const char * const plugin_name = plugin_info->base_name;
83120 + struct register_pass_info latent_entropy_pass_info = {
83121 + .pass = &latent_entropy_pass.pass,
83122 + .reference_pass_name = "optimized",
83123 + .ref_pass_instance_number = 1,
83124 + .pos_op = PASS_POS_INSERT_BEFORE
83125 + };
83126 +
83127 + if (!plugin_default_version_check(version, &gcc_version)) {
83128 + error(G_("incompatible gcc/plugin versions"));
83129 + return 1;
83130 + }
83131 +
83132 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83133 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83134 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83135 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83136 +
83137 + return 0;
83138 +}
83139 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83140 new file mode 100644
83141 index 0000000..50e9970
83142 --- /dev/null
83143 +++ b/tools/gcc/size_overflow_hash.data
83144 @@ -0,0 +1,3164 @@
83145 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
83146 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
83147 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
83148 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
83149 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
83150 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
83151 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
83152 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
83153 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
83154 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
83155 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
83156 +_000013_hash kmemdup 2 64015 _000013_hash NULL
83157 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
83158 +_000015_hash memdup_user 2 59590 _000015_hash NULL
83159 +_000016_hash module_alloc 1 63630 _000016_hash NULL
83160 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
83161 +_000018_hash read_kcore 3 63488 _000018_hash NULL
83162 +_000019_hash read_ldt 2 47570 _000019_hash NULL
83163 +_000020_hash read_zero 3 19366 _000020_hash NULL
83164 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
83165 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
83166 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
83167 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
83168 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
83169 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
83170 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
83171 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
83172 +_000029_hash adu_write 3 30487 _000029_hash NULL
83173 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
83174 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
83175 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
83176 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
83177 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
83178 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
83179 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
83180 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
83181 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
83182 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
83183 +_000041_hash alloc_context 1 3194 _000041_hash NULL
83184 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
83185 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
83186 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
83187 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
83188 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
83189 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
83190 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
83191 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
83192 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
83193 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
83194 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
83195 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
83196 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
83197 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
83198 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
83199 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
83200 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
83201 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
83202 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
83203 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
83204 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
83205 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
83206 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
83207 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
83208 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
83209 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
83210 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
83211 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
83212 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
83213 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
83214 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
83215 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
83216 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
83217 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
83218 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
83219 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
83220 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
83221 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
83222 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
83223 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
83224 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
83225 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
83226 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
83227 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
83228 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
83229 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
83230 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
83231 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
83232 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
83233 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
83234 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
83235 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
83236 +_000096_hash capi_write 3 35104 _000096_hash NULL
83237 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
83238 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
83239 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
83240 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
83241 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
83242 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
83243 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
83244 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
83245 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
83246 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
83247 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
83248 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
83249 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
83250 +_000111_hash change_xattr 5 61390 _000111_hash NULL
83251 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
83252 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
83253 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
83254 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
83255 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
83256 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
83257 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
83258 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
83259 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
83260 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
83261 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
83262 +_000123_hash cmm_write 3 2896 _000123_hash NULL
83263 +_000124_hash cm_write 3 36858 _000124_hash NULL
83264 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
83265 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
83266 +_000127_hash command_file_write 3 31318 _000127_hash NULL
83267 +_000128_hash command_write 3 58841 _000128_hash NULL
83268 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
83269 +_000130_hash concat_writev 3 21451 _000130_hash NULL
83270 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
83271 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
83272 +_000133_hash copy_items 6 50140 _000133_hash NULL
83273 +_000134_hash copy_macs 4 45534 _000134_hash NULL
83274 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
83275 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
83276 +_000137_hash cosa_write 3 1774 _000137_hash NULL
83277 +_000138_hash create_entry 2 33479 _000138_hash NULL
83278 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
83279 +_000141_hash create_xattr 5 54106 _000141_hash NULL
83280 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
83281 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
83282 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
83283 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
83284 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
83285 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
83286 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
83287 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
83288 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
83289 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
83290 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
83291 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
83292 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
83293 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
83294 +_000158_hash dev_config 3 8506 _000158_hash NULL
83295 +_000159_hash device_write 3 45156 _000159_hash NULL
83296 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
83297 +_000161_hash devres_alloc 2 551 _000161_hash NULL
83298 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
83299 +_000163_hash direct_entry 3 38836 _000163_hash NULL
83300 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
83301 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
83302 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
83303 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
83304 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
83305 +_000169_hash dm_read 3 15674 _000169_hash NULL
83306 +_000170_hash dm_write 3 2513 _000170_hash NULL
83307 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
83308 +_000172_hash dns_query 3 9676 _000172_hash NULL
83309 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
83310 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
83311 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
83312 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
83313 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
83314 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
83315 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
83316 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
83317 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
83318 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
83319 +_000183_hash dsp_write 2 46218 _000183_hash NULL
83320 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
83321 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
83322 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
83323 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
83324 +_000188_hash dvb_play 3 50814 _000188_hash NULL
83325 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
83326 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
83327 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
83328 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
83329 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
83330 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
83331 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
83332 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
83333 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
83334 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
83335 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
83336 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
83337 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
83338 +_000202_hash ep_read 3 58813 _000202_hash NULL
83339 +_000203_hash ep_write 3 59008 _000203_hash NULL
83340 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
83341 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
83342 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
83343 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
83344 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
83345 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
83346 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
83347 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
83348 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
83349 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
83350 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
83351 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
83352 +_000216_hash fl_create 5 56435 _000216_hash NULL
83353 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
83354 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
83355 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
83356 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
83357 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
83358 +_000222_hash get_arg 3 5694 _000222_hash NULL
83359 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
83360 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
83361 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
83362 +_000226_hash get_registers 3 26187 _000226_hash NULL
83363 +_000227_hash get_scq 2 10897 _000227_hash NULL
83364 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
83365 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
83366 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
83367 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
83368 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
83369 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
83370 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
83371 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
83372 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
83373 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
83374 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
83375 +_000239_hash handle_request 9 10024 _000239_hash NULL
83376 +_000240_hash hash_new 1 62224 _000240_hash NULL
83377 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
83378 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
83379 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
83380 +_000244_hash heap_init 2 49617 _000244_hash NULL
83381 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
83382 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
83383 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
83384 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
83385 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
83386 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
83387 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
83388 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
83389 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
83390 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
83391 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
83392 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
83393 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
83394 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
83395 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
83396 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
83397 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
83398 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
83399 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
83400 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
83401 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
83402 +_000266_hash ieee80211_build_probe_req 7-5 27660 _000266_hash NULL
83403 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
83404 +_000268_hash if_write 3 51756 _000268_hash NULL
83405 +_000269_hash ilo_write 3 64378 _000269_hash NULL
83406 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
83407 +_000271_hash init_data_container 1 60709 _000271_hash NULL
83408 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
83409 +_000273_hash insert_dent 7 65034 _000273_hash NULL
83410 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
83411 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
83412 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
83413 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
83414 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
83415 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
83416 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
83417 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
83418 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
83419 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
83420 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
83421 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
83422 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
83423 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
83424 +_000288_hash irias_new_octseq_value 2 13596 _003296_hash NULL nohasharray
83425 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
83426 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
83427 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
83428 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
83429 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
83430 +_000294_hash isdn_read 3 50021 _000294_hash NULL
83431 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
83432 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
83433 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
83434 +_000298_hash iso_callback 3 43208 _000298_hash NULL
83435 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
83436 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
83437 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
83438 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
83439 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
83440 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
83441 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
83442 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
83443 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
83444 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
83445 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
83446 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
83447 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
83448 +_000314_hash kmalloc_node 1 50163 _003293_hash NULL nohasharray
83449 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
83450 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
83451 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
83452 +_000319_hash kone_receive 4 4690 _000319_hash NULL
83453 +_000320_hash kone_send 4 63435 _000320_hash NULL
83454 +_000321_hash krealloc 2 14908 _000321_hash NULL
83455 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
83456 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
83457 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
83458 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
83459 +_000326_hash kzalloc 1 54740 _000326_hash NULL
83460 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
83461 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
83462 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
83463 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
83464 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
83465 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
83466 +_000333_hash __lgread 4 31668 _000333_hash NULL
83467 +_000334_hash libipw_alloc_txb 1-3-2 27579 _000334_hash NULL
83468 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
83469 +_000336_hash listxattr 3 12769 _000336_hash NULL
83470 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
83471 +_000338_hash load_msg 2 95 _000338_hash NULL
83472 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
83473 +_000340_hash lp_write 3 9511 _000340_hash NULL
83474 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
83475 +_000342_hash mce_write 3 26201 _000342_hash NULL
83476 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
83477 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
83478 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
83479 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
83480 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
83481 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
83482 +_000350_hash mem_rw 3 22085 _000350_hash NULL
83483 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
83484 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
83485 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
83486 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
83487 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
83488 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
83489 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
83490 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
83491 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
83492 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
83493 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
83494 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
83495 +_000363_hash mtdchar_write 3 56831 _002688_hash NULL nohasharray
83496 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
83497 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
83498 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
83499 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
83500 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
83501 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
83502 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
83503 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
83504 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
83505 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
83506 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
83507 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
83508 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
83509 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
83510 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
83511 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
83512 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
83513 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
83514 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
83515 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
83516 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
83517 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
83518 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
83519 +_000391_hash nvram_write 3 3894 _000391_hash NULL
83520 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
83521 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
83522 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
83523 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
83524 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
83525 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
83526 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
83527 +_000399_hash opticon_write 4 60775 _000399_hash NULL
83528 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
83529 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
83530 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
83531 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
83532 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
83533 +_000405_hash parse_command 2 37079 _000405_hash NULL
83534 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
83535 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
83536 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
83537 +_000409_hash pg_write 3 40766 _000409_hash NULL
83538 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
83539 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
83540 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
83541 +_000413_hash pkt_add 3 39897 _000413_hash NULL
83542 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
83543 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
83544 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
83545 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
83546 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
83547 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
83548 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
83549 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
83550 +_000422_hash ppp_write 3 34034 _000422_hash NULL
83551 +_000423_hash pp_read 3 33210 _000423_hash NULL
83552 +_000424_hash pp_write 3 39554 _000424_hash NULL
83553 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
83554 +_000426_hash printer_write 3 60276 _000426_hash NULL
83555 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
83556 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
83557 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
83558 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
83559 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
83560 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
83561 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
83562 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
83563 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
83564 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
83565 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
83566 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
83567 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
83568 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
83569 +_000442_hash pt_write 3 40159 _000442_hash NULL
83570 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
83571 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
83572 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
83573 +_000446_hash r3964_write 4 57662 _000446_hash NULL
83574 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
83575 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
83576 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
83577 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
83578 +_000451_hash rbd_add 3 16366 _000451_hash NULL
83579 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
83580 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
83581 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
83582 +_000455_hash read 3 9397 _000455_hash NULL
83583 +_000456_hash read_buf 2 20469 _000456_hash NULL
83584 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
83585 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
83586 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
83587 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
83588 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
83589 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
83590 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
83591 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
83592 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
83593 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
83594 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
83595 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
83596 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
83597 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
83598 +_000471_hash revalidate 2 19043 _000471_hash NULL
83599 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
83600 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
83601 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
83602 +_000475_hash rngapi_reset 3 34366 _002911_hash NULL nohasharray
83603 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
83604 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
83605 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
83606 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
83607 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
83608 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
83609 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
83610 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
83611 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
83612 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
83613 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
83614 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
83615 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
83616 +_000489_hash savemem 3 58129 _000489_hash NULL
83617 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
83618 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
83619 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
83620 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
83621 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
83622 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
83623 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
83624 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
83625 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
83626 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
83627 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
83628 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
83629 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
83630 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
83631 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
83632 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
83633 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
83634 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
83635 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
83636 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
83637 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
83638 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
83639 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
83640 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
83641 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
83642 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
83643 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
83644 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
83645 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
83646 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
83647 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
83648 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
83649 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
83650 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
83651 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
83652 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
83653 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
83654 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
83655 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
83656 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
83657 +_000532_hash set_registers 3 53582 _000532_hash NULL
83658 +_000533_hash setsockopt 5 54539 _000533_hash NULL
83659 +_000534_hash setup_req 3 5848 _000534_hash NULL
83660 +_000535_hash setup_window 7 59178 _000535_hash NULL
83661 +_000536_hash setxattr 4 37006 _000536_hash NULL
83662 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
83663 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
83664 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
83665 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
83666 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
83667 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
83668 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
83669 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
83670 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
83671 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
83672 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
83673 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
83674 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
83675 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
83676 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
83677 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
83678 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
83679 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
83680 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
83681 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
83682 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
83683 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
83684 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
83685 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
83686 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
83687 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
83688 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
83689 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
83690 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
83691 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
83692 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
83693 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
83694 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
83695 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
83696 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
83697 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
83698 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
83699 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
83700 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
83701 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
83702 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
83703 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
83704 +_000581_hash spidev_write 3 44510 _000581_hash NULL
83705 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
83706 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
83707 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
83708 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
83709 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
83710 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
83711 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
83712 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
83713 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
83714 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
83715 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
83716 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
83717 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
83718 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
83719 +_000597_hash tower_write 3 8580 _000597_hash NULL
83720 +_000598_hash tpm_write 3 50798 _000598_hash NULL
83721 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
83722 +_000600_hash trusted_update 3 12664 _000600_hash NULL
83723 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
83724 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
83725 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
83726 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
83727 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
83728 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
83729 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
83730 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
83731 +_000609_hash uea_request 4 47613 _000609_hash NULL
83732 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
83733 +_000611_hash uio_write 3 43202 _000611_hash NULL
83734 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
83735 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
83736 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
83737 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
83738 +_000616_hash usblp_write 3 23178 _000616_hash NULL
83739 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
83740 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
83741 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
83742 +_000621_hash user_update 3 41332 _000621_hash NULL
83743 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
83744 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
83745 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
83746 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
83747 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
83748 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
83749 +_000629_hash vcs_write 3 3910 _000629_hash NULL
83750 +_000630_hash vfd_write 3 14717 _000630_hash NULL
83751 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
83752 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
83753 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
83754 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
83755 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
83756 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
83757 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
83758 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
83759 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
83760 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
83761 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
83762 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
83763 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
83764 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
83765 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
83766 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
83767 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
83768 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
83769 +_000651_hash wdm_write 3 53735 _000651_hash NULL
83770 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
83771 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
83772 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
83773 +_000655_hash write 3 62671 _000655_hash NULL
83774 +_000656_hash write_flush 3 50803 _000656_hash NULL
83775 +_000657_hash write_rio 3 54837 _000657_hash NULL
83776 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
83777 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
83778 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
83779 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
83780 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
83781 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
83782 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
83783 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
83784 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
83785 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
83786 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
83787 +_000669_hash zoran_write 3 22404 _000669_hash NULL
83788 +_000671_hash acpi_ex_allocate_name_string 2-1 7685 _002855_hash NULL nohasharray
83789 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
83790 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
83791 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
83792 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
83793 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
83794 +_000677_hash add_res_range 4 21310 _000677_hash NULL
83795 +_000678_hash addtgt 3 54703 _000678_hash NULL
83796 +_000679_hash add_uuid 4 49831 _000679_hash NULL
83797 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
83798 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
83799 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
83800 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
83801 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
83802 +_000685_hash alloc_async 1 14208 _000685_hash NULL
83803 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
83804 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
83805 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
83806 +_000689_hash alloc_context 1 41283 _000689_hash NULL
83807 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
83808 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
83809 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
83810 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
83811 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
83812 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
83813 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
83814 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
83815 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
83816 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
83817 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
83818 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
83819 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
83820 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
83821 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
83822 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
83823 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
83824 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
83825 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
83826 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
83827 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
83828 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
83829 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
83830 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
83831 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
83832 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
83833 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
83834 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
83835 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
83836 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
83837 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
83838 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
83839 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
83840 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
83841 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
83842 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
83843 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
83844 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
83845 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
83846 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
83847 +_000736_hash ati_create_gatt_pages 1 4722 _003185_hash NULL nohasharray
83848 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
83849 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
83850 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
83851 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
83852 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
83853 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
83854 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
83855 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
83856 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
83857 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
83858 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
83859 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
83860 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
83861 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
83862 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
83863 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
83864 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
83865 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
83866 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
83867 +_000759_hash ca_extend 2 64541 _000759_hash NULL
83868 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
83869 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
83870 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
83871 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
83872 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
83873 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
83874 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
83875 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
83876 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
83877 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
83878 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
83879 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
83880 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
83881 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
83882 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
83883 +_000778_hash cifs_writedata_alloc 1 32880 _003119_hash NULL nohasharray
83884 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
83885 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
83886 +_000781_hash construct_key 3 11329 _000781_hash NULL
83887 +_000782_hash context_alloc 3 24645 _000782_hash NULL
83888 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
83889 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
83890 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
83891 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
83892 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
83893 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
83894 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
83895 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
83896 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
83897 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
83898 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
83899 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
83900 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
83901 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
83902 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
83903 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
83904 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
83905 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
83906 +_000805_hash depth_write 3 3021 _000805_hash NULL
83907 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
83908 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
83909 +_000808_hash dev_write 3 7708 _000808_hash NULL
83910 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
83911 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
83912 +_000811_hash disconnect 4 32521 _000811_hash NULL
83913 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
83914 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
83915 +_000815_hash do_dccp_setsockopt 5 54377 _003160_hash NULL nohasharray
83916 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
83917 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
83918 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
83919 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
83920 +_000820_hash do_sync 1 9604 _000820_hash NULL
83921 +_000821_hash dup_array 3 33551 _000821_hash NULL
83922 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
83923 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
83924 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
83925 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
83926 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
83927 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
83928 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
83929 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
83930 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
83931 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
83932 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
83933 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
83934 +_000834_hash enable_write 3 30456 _000834_hash NULL
83935 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
83936 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
83937 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
83938 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
83939 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
83940 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
83941 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
83942 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
83943 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
83944 +_000844_hash fillonedir 3 41746 _000844_hash NULL
83945 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
83946 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
83947 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
83948 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
83949 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
83950 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
83951 +_000851_hash get_entry 4 16003 _000851_hash NULL
83952 +_000852_hash get_free_de 2 33714 _000852_hash NULL
83953 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
83954 +_000854_hash getxattr 4 24398 _000854_hash NULL
83955 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
83956 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
83957 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
83958 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
83959 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
83960 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
83961 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
83962 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
83963 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
83964 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
83965 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
83966 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
83967 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
83968 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
83969 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
83970 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
83971 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
83972 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
83973 +_000876_hash ieee80211_send_probe_req 6-4 6924 _000876_hash NULL
83974 +_000877_hash if_writecmd 2 815 _000877_hash NULL
83975 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
83976 +_000880_hash init_ipath 1 48187 _000880_hash NULL
83977 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
83978 +_000883_hash init_q 4 132 _000883_hash NULL
83979 +_000884_hash init_state 2 60165 _000884_hash NULL
83980 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
83981 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
83982 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
83983 +_000888_hash interfaces 2 38859 _000888_hash NULL
83984 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
83985 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
83986 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
83987 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
83988 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
83989 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
83990 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
83991 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
83992 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
83993 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
83994 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
83995 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
83996 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
83997 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
83998 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
83999 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
84000 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
84001 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
84002 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
84003 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
84004 +_000911_hash isdn_write 3 45863 _000911_hash NULL
84005 +_000912_hash isku_receive 4 54130 _000912_hash NULL
84006 +_000913_hash isku_send 4 41542 _000913_hash NULL
84007 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
84008 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
84009 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
84010 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
84011 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
84012 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
84013 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
84014 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
84015 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
84016 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
84017 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
84018 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
84019 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
84020 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
84021 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
84022 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
84023 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
84024 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
84025 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
84026 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
84027 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
84028 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
84029 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
84030 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
84031 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
84032 +_000940_hash kvm_write_guest_page 5 63555 _002809_hash NULL nohasharray
84033 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
84034 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
84035 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
84036 +_000945_hash lc_create 3 48662 _000945_hash NULL
84037 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
84038 +_000947_hash linear_conf 2 23485 _003314_hash NULL nohasharray
84039 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
84040 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
84041 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
84042 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
84043 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
84044 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
84045 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
84046 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
84047 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
84048 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
84049 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
84050 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
84051 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
84052 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
84053 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
84054 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
84055 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
84056 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
84057 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
84058 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
84059 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
84060 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
84061 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
84062 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
84063 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
84064 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
84065 +_000977_hash new_dir 3 31919 _000977_hash NULL
84066 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
84067 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
84068 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
84069 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
84070 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
84071 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
84072 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
84073 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
84074 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
84075 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
84076 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
84077 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
84078 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
84079 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
84080 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
84081 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
84082 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
84083 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
84084 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
84085 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
84086 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
84087 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
84088 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
84089 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
84090 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
84091 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
84092 +_001008_hash osst_write 3 31581 _001008_hash NULL
84093 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
84094 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
84095 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
84096 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
84097 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
84098 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
84099 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
84100 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
84101 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
84102 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
84103 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
84104 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
84105 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
84106 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
84107 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
84108 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
84109 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
84110 +_001030_hash play_iframe 3 8219 _001030_hash NULL
84111 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
84112 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
84113 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
84114 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
84115 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
84116 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
84117 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
84118 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
84119 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
84120 +_001042_hash proc_write 3 51003 _001042_hash NULL
84121 +_001043_hash profile_load 3 58267 _001043_hash NULL
84122 +_001044_hash profile_remove 3 8556 _001044_hash NULL
84123 +_001045_hash profile_replace 3 14652 _001045_hash NULL
84124 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
84125 +_001047_hash pyra_send 4 12061 _001047_hash NULL
84126 +_001048_hash qc_capture 3 19298 _001048_hash NULL
84127 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
84128 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
84129 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
84130 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
84131 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
84132 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
84133 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
84134 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
84135 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
84136 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
84137 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
84138 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
84139 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
84140 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
84141 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
84142 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
84143 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
84144 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
84145 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
84146 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
84147 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
84148 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
84149 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
84150 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
84151 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
84152 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
84153 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
84154 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
84155 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
84156 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
84157 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
84158 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
84159 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
84160 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
84161 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
84162 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
84163 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
84164 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
84165 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
84166 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
84167 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
84168 +_001092_hash security_context_to_sid_default 2 3492 _003366_hash NULL nohasharray
84169 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
84170 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
84171 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
84172 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
84173 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
84174 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
84175 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
84176 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
84177 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
84178 +_001102_hash set_connectable 4 56458 _001102_hash NULL
84179 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
84180 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
84181 +_001105_hash setkey 3 14987 _001105_hash NULL
84182 +_001106_hash set_le 4 30581 _001106_hash NULL
84183 +_001107_hash set_link_security 4 4502 _001107_hash NULL
84184 +_001108_hash set_local_name 4 55757 _001108_hash NULL
84185 +_001109_hash set_powered 4 12129 _001109_hash NULL
84186 +_001110_hash set_ssp 4 62411 _001110_hash NULL
84187 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
84188 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
84189 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
84190 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
84191 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
84192 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
84193 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
84194 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
84195 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
84196 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
84197 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
84198 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
84199 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
84200 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
84201 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
84202 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
84203 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
84204 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
84205 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
84206 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
84207 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
84208 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
84209 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
84210 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
84211 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
84212 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
84213 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
84214 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
84215 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
84216 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
84217 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
84218 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
84219 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
84220 +_001148_hash sound_write 3 5102 _001148_hash NULL
84221 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
84222 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
84223 +_001151_hash spidev_message 3 5518 _001151_hash NULL
84224 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
84225 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
84226 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
84227 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
84228 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
84229 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
84230 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
84231 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
84232 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
84233 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
84234 +_001163_hash st_write 3 16874 _001163_hash NULL
84235 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
84236 +_001165_hash symtab_init 2 61050 _001165_hash NULL
84237 +_001166_hash sys_bind 3 10799 _001166_hash NULL
84238 +_001167_hash sys_connect 3 15291 _003291_hash NULL nohasharray
84239 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
84240 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
84241 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
84242 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
84243 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
84244 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
84245 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
84246 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
84247 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
84248 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
84249 +_001178_hash sys_semop 3 39457 _001178_hash NULL
84250 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
84251 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
84252 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
84253 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
84254 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
84255 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
84256 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
84257 +_001186_hash timeout_write 3 50991 _001186_hash NULL
84258 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
84259 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
84260 +_001189_hash tm6000_read_write_usb 7 50774 _002917_hash NULL nohasharray
84261 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
84262 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
84263 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
84264 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
84265 +_001195_hash ts_write 3 64336 _001195_hash NULL
84266 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
84267 +_001197_hash tty_write 3 5494 _001197_hash NULL
84268 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
84269 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
84270 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
84271 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
84272 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
84273 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
84274 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
84275 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
84276 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
84277 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
84278 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
84279 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
84280 +_001211_hash uvc_alloc_entity 3-4 20836 _001211_hash NULL
84281 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
84282 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
84283 +_001214_hash vb2_read 3 42703 _001214_hash NULL
84284 +_001215_hash vb2_write 3 31948 _001215_hash NULL
84285 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
84286 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
84287 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
84288 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
84289 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
84290 +_001223_hash vmalloc 1 15464 _001223_hash NULL
84291 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
84292 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
84293 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
84294 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
84295 +_001228_hash vzalloc 1 47421 _001228_hash NULL
84296 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
84297 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
84298 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
84299 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
84300 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
84301 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
84302 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
84303 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
84304 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
84305 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
84306 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
84307 +_001240_hash xfs_dir_cilookup_result 3 64288 _003139_hash NULL nohasharray
84308 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
84309 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
84310 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
84311 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
84312 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
84313 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
84314 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
84315 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
84316 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
84317 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
84318 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
84319 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
84320 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
84321 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
84322 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
84323 +_001256_hash add_child 4 45201 _001256_hash NULL
84324 +_001257_hash add_port 2 54941 _001257_hash NULL
84325 +_001258_hash adu_read 3 24177 _001258_hash NULL
84326 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
84327 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
84328 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
84329 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
84330 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
84331 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
84332 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
84333 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
84334 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
84335 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
84336 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
84337 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
84338 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
84339 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
84340 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
84341 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
84342 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
84343 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
84344 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
84345 +_001280_hash async_setkey 3 35521 _001280_hash NULL
84346 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
84347 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
84348 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
84349 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
84350 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
84351 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
84352 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
84353 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
84354 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
84355 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
84356 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
84357 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
84358 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
84359 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
84360 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
84361 +_001298_hash bm_init 2 13529 _001298_hash NULL
84362 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
84363 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
84364 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
84365 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
84366 +_001303_hash cache_read 3 24790 _001303_hash NULL
84367 +_001304_hash cache_write 3 13589 _001304_hash NULL
84368 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
84369 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
84370 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
84371 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
84372 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
84373 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
84374 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
84375 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
84376 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
84377 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
84378 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
84379 +_001317_hash copy_oldmem_page 3-1 26164 _001317_hash NULL
84380 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
84381 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
84382 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
84383 +_001321_hash crypto_authenc_setkey 3 80 _003311_hash NULL nohasharray
84384 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
84385 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
84386 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
84387 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
84388 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
84389 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
84390 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
84391 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
84392 +_001331_hash dev_read 3 56369 _001331_hash NULL
84393 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
84394 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
84395 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
84396 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
84397 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
84398 +_001338_hash do_readlink 2 43518 _001338_hash NULL
84399 +_001339_hash __do_replace 5 37227 _001339_hash NULL
84400 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
84401 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
84402 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
84403 +_001343_hash dump_midi 3 51040 _001343_hash NULL
84404 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
84405 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
84406 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5-2 4303 _001346_hash NULL
84407 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
84408 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
84409 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
84410 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
84411 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
84412 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
84413 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
84414 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
84415 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
84416 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
84417 +_001358_hash filldir 3 55137 _001358_hash NULL
84418 +_001359_hash filldir64 3 46469 _001359_hash NULL
84419 +_001360_hash fops_read 3 40672 _001360_hash NULL
84420 +_001361_hash from_buffer 3 18625 _001361_hash NULL
84421 +_001362_hash fsm_init 2 16134 _001362_hash NULL
84422 +_001363_hash get_subdir 3 62581 _001363_hash NULL
84423 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
84424 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
84425 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
84426 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
84427 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
84428 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
84429 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
84430 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
84431 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
84432 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
84433 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
84434 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
84435 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
84436 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
84437 +_001379_hash ilo_read 3 32531 _001379_hash NULL
84438 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
84439 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
84440 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
84441 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
84442 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
84443 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
84444 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
84445 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
84446 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
84447 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
84448 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
84449 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
84450 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
84451 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
84452 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
84453 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
84454 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
84455 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
84456 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
84457 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
84458 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
84459 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
84460 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
84461 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
84462 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
84463 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
84464 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
84465 +_001412_hash keyring_read 3 13438 _001412_hash NULL
84466 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
84467 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
84468 +_001415_hash kmp_init 2 41373 _001415_hash NULL
84469 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
84470 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
84471 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
84472 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
84473 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
84474 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
84475 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
84476 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
84477 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
84478 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
84479 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
84480 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
84481 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
84482 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
84483 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
84484 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
84485 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
84486 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
84487 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
84488 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
84489 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
84490 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
84491 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
84492 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
84493 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
84494 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
84495 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
84496 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
84497 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
84498 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
84499 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
84500 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
84501 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
84502 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
84503 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
84504 +_001454_hash override_release 2 52032 _001454_hash NULL
84505 +_001455_hash packet_snd 3 13634 _001455_hash NULL
84506 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
84507 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
84508 +_001458_hash pg_read 3 17276 _001458_hash NULL
84509 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
84510 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
84511 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
84512 +_001462_hash pms_capture 4 27142 _001462_hash NULL
84513 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
84514 +_001464_hash printer_read 3 54851 _001464_hash NULL
84515 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
84516 +_001466_hash pt_read 3 49136 _001466_hash NULL
84517 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
84518 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
84519 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
84520 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
84521 +_001471_hash qcam_read 3 13977 _001471_hash NULL
84522 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
84523 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
84524 +_001474_hash read_flush 3 43851 _001474_hash NULL
84525 +_001475_hash read_profile 3 27859 _001475_hash NULL
84526 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
84527 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
84528 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
84529 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
84530 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
84531 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
84532 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
84533 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
84534 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
84535 +_001486_hash roccat_read 3 41093 _001486_hash NULL
84536 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
84537 +_001488_hash scsi_register 2 49094 _001488_hash NULL
84538 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
84539 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
84540 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
84541 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
84542 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
84543 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
84544 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
84545 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
84546 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
84547 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
84548 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
84549 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
84550 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
84551 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
84552 +_001503_hash set_arg 3 42824 _001503_hash NULL
84553 +_001504_hash sg_read 3 25799 _001504_hash NULL
84554 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
84555 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
84556 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
84557 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
84558 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
84559 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
84560 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
84561 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
84562 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
84563 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
84564 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
84565 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
84566 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
84567 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
84568 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
84569 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
84570 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
84571 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
84572 +_001525_hash store_msg 3 56417 _001525_hash NULL
84573 +_001526_hash str_to_user 2 11411 _001526_hash NULL
84574 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
84575 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
84576 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
84577 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
84578 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
84579 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
84580 +_001533_hash sys_process_vm_readv 3-5 19090 _003125_hash NULL nohasharray
84581 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
84582 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
84583 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
84584 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
84585 +_001540_hash team_options_register 3 20091 _001540_hash NULL
84586 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
84587 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
84588 +_001543_hash tipc_send 4 51238 _001543_hash NULL
84589 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
84590 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
84591 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
84592 +_001547_hash tnode_new 3 44757 _001547_hash NULL
84593 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
84594 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
84595 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
84596 +_001551_hash tpm_read 3 50344 _001551_hash NULL
84597 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
84598 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
84599 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
84600 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
84601 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
84602 +_001558_hash uio_read 3 49300 _001558_hash NULL
84603 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
84604 +_001560_hash unlink1 3 63059 _001560_hash NULL
84605 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
84606 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
84607 +_001564_hash usblp_read 3 57342 _003306_hash NULL nohasharray
84608 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
84609 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
84610 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
84611 +_001568_hash user_read 3 51881 _001568_hash NULL
84612 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
84613 +_001570_hash vcs_read 3 8017 _001570_hash NULL
84614 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
84615 +_001572_hash venus_create 4 20555 _001572_hash NULL
84616 +_001573_hash venus_link 5 32165 _001573_hash NULL
84617 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
84618 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
84619 +_001576_hash venus_remove 4 59781 _001576_hash NULL
84620 +_001577_hash venus_rename 4-5 17707 _003279_hash NULL nohasharray
84621 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
84622 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
84623 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
84624 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
84625 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
84626 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
84627 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
84628 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
84629 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
84630 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
84631 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
84632 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
84633 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
84634 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
84635 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
84636 +_001596_hash wdm_read 3 6549 _001596_hash NULL
84637 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
84638 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
84639 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
84640 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
84641 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
84642 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
84643 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
84644 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
84645 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
84646 +_001606_hash xz_dec_lzma2_create 2 36353 _002745_hash NULL nohasharray
84647 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
84648 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
84649 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
84650 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
84651 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
84652 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
84653 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
84654 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
84655 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
84656 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
84657 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
84658 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
84659 +_001619_hash __alloc_bootmem_low 1 43423 _003150_hash NULL nohasharray
84660 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
84661 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
84662 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
84663 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
84664 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
84665 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
84666 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
84667 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
84668 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
84669 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
84670 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
84671 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
84672 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
84673 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
84674 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
84675 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
84676 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
84677 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
84678 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
84679 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
84680 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
84681 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
84682 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
84683 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
84684 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
84685 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
84686 +_001648_hash blk_queue_init_tags 2 44355 _002686_hash NULL nohasharray
84687 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
84688 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
84689 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
84690 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
84691 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
84692 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
84693 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
84694 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
84695 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
84696 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
84697 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
84698 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
84699 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
84700 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
84701 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
84702 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
84703 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
84704 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
84705 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
84706 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
84707 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
84708 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
84709 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
84710 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
84711 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
84712 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
84713 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
84714 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
84715 +_001677_hash create_subvol 4 2347 _001677_hash NULL
84716 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
84717 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
84718 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
84719 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
84720 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
84721 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
84722 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
84723 +_001687_hash debug_output 3 18575 _001687_hash NULL
84724 +_001688_hash debug_read 3 19322 _001688_hash NULL
84725 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
84726 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
84727 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
84728 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
84729 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
84730 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
84731 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
84732 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
84733 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
84734 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
84735 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
84736 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
84737 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
84738 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
84739 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
84740 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
84741 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
84742 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
84743 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
84744 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
84745 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
84746 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
84747 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
84748 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
84749 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
84750 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
84751 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
84752 +_001716_hash filter_read 3 61692 _001716_hash NULL
84753 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
84754 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
84755 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
84756 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
84757 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
84758 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
84759 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
84760 +_001724_hash ht40allow_map_read 3 55209 _002830_hash NULL nohasharray
84761 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
84762 +_001726_hash hysdn_conf_read 3 42324 _003205_hash NULL nohasharray
84763 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
84764 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
84765 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
84766 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
84767 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
84768 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
84769 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
84770 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
84771 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
84772 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
84773 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
84774 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
84775 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
84776 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
84777 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
84778 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
84779 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
84780 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
84781 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
84782 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
84783 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
84784 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
84785 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
84786 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
84787 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
84788 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
84789 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
84790 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
84791 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
84792 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
84793 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
84794 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
84795 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
84796 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
84797 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
84798 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
84799 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
84800 +_001765_hash ipw_write 3 59807 _001765_hash NULL
84801 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
84802 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
84803 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
84804 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
84805 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
84806 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
84807 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
84808 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
84809 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
84810 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
84811 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
84812 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
84813 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
84814 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
84815 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
84816 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
84817 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
84818 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
84819 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
84820 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
84821 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
84822 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
84823 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
84824 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
84825 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
84826 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
84827 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
84828 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
84829 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
84830 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
84831 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
84832 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
84833 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
84834 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
84835 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
84836 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
84837 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
84838 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
84839 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
84840 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
84841 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
84842 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
84843 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _003026_hash NULL nohasharray
84844 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
84845 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
84846 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
84847 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
84848 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
84849 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
84850 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
84851 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
84852 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
84853 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
84854 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
84855 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
84856 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
84857 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
84858 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
84859 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
84860 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
84861 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
84862 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
84863 +_001828_hash key_key_read 3 3241 _001828_hash NULL
84864 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
84865 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
84866 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
84867 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
84868 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
84869 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
84870 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
84871 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
84872 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
84873 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
84874 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
84875 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
84876 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
84877 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
84878 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
84879 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
84880 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
84881 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
84882 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
84883 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
84884 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
84885 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
84886 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
84887 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
84888 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
84889 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
84890 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
84891 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
84892 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
84893 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
84894 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
84895 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
84896 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
84897 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
84898 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
84899 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
84900 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
84901 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
84902 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
84903 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
84904 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
84905 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
84906 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
84907 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
84908 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
84909 +_001876_hash nfsd_vfs_read 6 62605 _003003_hash NULL nohasharray
84910 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
84911 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
84912 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
84913 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
84914 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
84915 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
84916 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
84917 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
84918 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
84919 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
84920 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
84921 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
84922 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
84923 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
84924 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
84925 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
84926 +_001893_hash page_readlink 3 23346 _001893_hash NULL
84927 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
84928 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
84929 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
84930 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
84931 +_001898_hash pms_read 3 53873 _001898_hash NULL
84932 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
84933 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
84934 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
84935 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
84936 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
84937 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
84938 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
84939 +_001906_hash proc_read 3 43614 _001906_hash NULL
84940 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
84941 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
84942 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
84943 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
84944 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
84945 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
84946 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
84947 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
84948 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
84949 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
84950 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
84951 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
84952 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
84953 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
84954 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
84955 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
84956 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
84957 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
84958 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
84959 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
84960 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
84961 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
84962 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
84963 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
84964 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
84965 +_001932_hash queues_read 3 24877 _001932_hash NULL
84966 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
84967 +_001934_hash rcname_read 3 25919 _001934_hash NULL
84968 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
84969 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
84970 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
84971 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
84972 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
84973 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
84974 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
84975 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
84976 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
84977 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
84978 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
84979 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
84980 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
84981 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
84982 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
84983 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
84984 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
84985 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
84986 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
84987 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
84988 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
84989 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
84990 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
84991 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
84992 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
84993 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
84994 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
84995 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
84996 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
84997 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
84998 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
84999 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
85000 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
85001 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
85002 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
85003 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
85004 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
85005 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
85006 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
85007 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
85008 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
85009 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
85010 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
85011 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
85012 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
85013 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
85014 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
85015 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
85016 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
85017 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
85018 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
85019 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
85020 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
85021 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
85022 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003089_hash NULL nohasharray
85023 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
85024 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
85025 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
85026 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
85027 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
85028 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
85029 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
85030 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
85031 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
85032 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
85033 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
85034 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
85035 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
85036 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
85037 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
85038 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
85039 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
85040 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
85041 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
85042 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
85043 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
85044 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
85045 +_002013_hash sel_read_policyvers 3 55 _003257_hash NULL nohasharray
85046 +_002014_hash send_msg 4 37323 _002014_hash NULL
85047 +_002015_hash send_packet 4 52960 _002015_hash NULL
85048 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
85049 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
85050 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
85051 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
85052 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
85053 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
85054 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
85055 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
85056 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
85057 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
85058 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
85059 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
85060 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
85061 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
85062 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
85063 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
85064 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
85065 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
85066 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
85067 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
85068 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
85069 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
85070 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
85071 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
85072 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
85073 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
85074 +_002045_hash st_read 3 51251 _002045_hash NULL
85075 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
85076 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
85077 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
85078 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
85079 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
85080 +_002051_hash sys_readv 3 50664 _002051_hash NULL
85081 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
85082 +_002053_hash sys_writev 3 28384 _002053_hash NULL
85083 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
85084 +_002055_hash ts_read 3 44687 _002055_hash NULL
85085 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
85086 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
85087 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
85088 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
85089 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
85090 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
85091 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
85092 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
85093 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
85094 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
85095 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
85096 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
85097 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
85098 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
85099 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
85100 +_002074_hash waiters_read 3 40902 _002074_hash NULL
85101 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
85102 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
85103 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
85104 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
85105 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
85106 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
85107 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
85108 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
85109 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
85110 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
85111 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
85112 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
85113 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
85114 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
85115 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
85116 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
85117 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
85118 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
85119 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
85120 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
85121 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
85122 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
85123 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
85124 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
85125 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
85126 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
85127 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
85128 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
85129 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
85130 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
85131 +_002106_hash cx18_read 3 23699 _002106_hash NULL
85132 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
85133 +_002108_hash depth_read 3 31112 _002108_hash NULL
85134 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
85135 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
85136 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
85137 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
85138 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
85139 +_002115_hash enable_read 3 2117 _002115_hash NULL
85140 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
85141 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
85142 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
85143 +_002119_hash frequency_read 3 64031 _003106_hash NULL nohasharray
85144 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
85145 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
85146 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
85147 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
85148 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
85149 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
85150 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
85151 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
85152 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
85153 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
85154 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
85155 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
85156 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
85157 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
85158 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
85159 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
85160 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
85161 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
85162 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
85163 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
85164 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
85165 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
85166 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
85167 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
85168 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
85169 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
85170 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
85171 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
85172 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
85173 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
85174 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
85175 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
85176 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
85177 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
85178 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
85179 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
85180 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
85181 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002859_hash NULL nohasharray
85182 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
85183 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
85184 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
85185 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
85186 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
85187 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
85188 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
85189 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
85190 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
85191 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
85192 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
85193 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
85194 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
85195 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
85196 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
85197 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
85198 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
85199 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
85200 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
85201 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
85202 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
85203 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
85204 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
85205 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
85206 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
85207 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
85208 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
85209 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
85210 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
85211 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
85212 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
85213 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
85214 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
85215 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
85216 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
85217 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
85218 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
85219 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
85220 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
85221 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
85222 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
85223 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
85224 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
85225 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
85226 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
85227 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
85228 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
85229 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
85230 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
85231 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
85232 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
85233 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
85234 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
85235 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
85236 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
85237 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
85238 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
85239 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
85240 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
85241 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
85242 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
85243 +_002220_hash power_read 3 15939 _002220_hash NULL
85244 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
85245 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
85246 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
85247 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
85248 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
85249 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
85250 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
85251 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
85252 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
85253 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
85254 +_002231_hash read_tree_block 3 841 _002231_hash NULL
85255 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
85256 +_002234_hash recv_msg 4 48709 _002234_hash NULL
85257 +_002235_hash recv_stream 4 30138 _002235_hash NULL
85258 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
85259 +_002237_hash request_key_async 4 6990 _002237_hash NULL
85260 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
85261 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
85262 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
85263 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
85264 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
85265 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
85266 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
85267 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
85268 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
85269 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
85270 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
85271 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
85272 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
85273 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
85274 +_002252_hash send_stream 4 3397 _002252_hash NULL
85275 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
85276 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
85277 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
85278 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
85279 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
85280 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
85281 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
85282 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
85283 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
85284 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
85285 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
85286 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
85287 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
85288 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
85289 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
85290 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
85291 +_002270_hash timeout_read 3 47915 _002270_hash NULL
85292 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
85293 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
85294 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
85295 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
85296 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
85297 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
85298 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
85299 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
85300 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
85301 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
85302 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
85303 +_002283_hash user_power_read 3 39414 _002283_hash NULL
85304 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
85305 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
85306 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
85307 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
85308 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
85309 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
85310 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
85311 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
85312 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
85313 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
85314 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
85315 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
85316 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
85317 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
85318 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
85319 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
85320 +_002300_hash spi_execute 5 28736 _002300_hash NULL
85321 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
85322 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
85323 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
85324 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
85325 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
85326 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
85327 +_002308_hash write_leb 5 36957 _002308_hash NULL
85328 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
85329 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
85330 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
85331 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
85332 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
85333 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
85334 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
85335 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
85336 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
85337 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
85338 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
85339 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
85340 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
85341 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
85342 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
85343 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
85344 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
85345 +_002329_hash recover_head 3 17904 _002329_hash NULL
85346 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
85347 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
85348 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
85349 +_002334_hash amthi_read 4 45831 _002334_hash NULL
85350 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
85351 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
85352 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
85353 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
85354 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
85355 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
85356 +_002341_hash card_send_command 3 40757 _002341_hash NULL
85357 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
85358 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
85359 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
85360 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
85361 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
85362 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
85363 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
85364 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
85365 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
85366 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
85367 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
85368 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
85369 +_002354_hash fir16_create 3 5574 _002354_hash NULL
85370 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
85371 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
85372 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
85373 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
85374 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
85375 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
85376 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
85377 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
85378 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
85379 +_002365_hash keymap_store 4 45406 _002365_hash NULL
85380 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
85381 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
85382 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
85383 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
85384 +_002370_hash lirc_write 3 20604 _002370_hash NULL
85385 +_002371_hash _malloc 1 54077 _002371_hash NULL
85386 +_002372_hash mei_read 3 6507 _002372_hash NULL
85387 +_002373_hash mei_write 3 4005 _002373_hash NULL
85388 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
85389 +_002375_hash msg_set 3 51725 _002375_hash NULL
85390 +_002376_hash newpart 6 47485 _002376_hash NULL
85391 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
85392 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
85393 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
85394 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
85395 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
85396 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
85397 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
85398 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
85399 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
85400 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
85401 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
85402 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
85403 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
85404 +_002393_hash sep_read 3 17161 _002393_hash NULL
85405 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
85406 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
85407 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
85408 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
85409 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
85410 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
85411 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
85412 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
85413 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
85414 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
85415 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
85416 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
85417 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
85418 +_002411_hash mempool_create 1 29437 _002411_hash NULL
85419 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
85420 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
85421 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
85422 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
85423 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
85424 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
85425 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
85426 +_002419_hash add_partition 2 55588 _002419_hash NULL
85427 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
85428 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
85429 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
85430 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
85431 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
85432 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
85433 +_002427_hash bioset_create 1 5580 _002427_hash NULL
85434 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
85435 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
85436 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
85437 +_002431_hash prison_create 1 43623 _002431_hash NULL
85438 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
85439 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
85440 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
85441 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
85442 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
85443 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
85444 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
85445 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
85446 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
85447 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
85448 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
85449 +_002443_hash comedi_read 3 13199 _002443_hash NULL
85450 +_002444_hash comedi_write 3 47926 _002444_hash NULL
85451 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
85452 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
85453 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
85454 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
85455 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
85456 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
85457 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
85458 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
85459 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
85460 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
85461 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
85462 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
85463 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
85464 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
85465 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
85466 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
85467 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
85468 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
85469 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
85470 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
85471 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
85472 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
85473 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
85474 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
85475 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
85476 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
85477 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
85478 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
85479 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
85480 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
85481 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
85482 +_002476_hash flash_read 3 57843 _002476_hash NULL
85483 +_002477_hash flash_write 3 62354 _002477_hash NULL
85484 +_002478_hash gather_array 3 56641 _002478_hash NULL
85485 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
85486 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
85487 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
85488 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
85489 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
85490 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
85491 +_002486_hash ieee80211_alloc_txb 1-2 52477 _002486_hash NULL
85492 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
85493 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
85494 +_002489_hash init_cdev 1 8274 _002489_hash NULL
85495 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
85496 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
85497 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
85498 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
85499 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
85500 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
85501 +_002496_hash options_write 3 47243 _002496_hash NULL
85502 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
85503 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
85504 +_002499_hash portnames_read 3 41958 _002499_hash NULL
85505 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
85506 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
85507 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
85508 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
85509 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
85510 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
85511 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
85512 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
85513 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
85514 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
85515 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
85516 +_002511_hash queue_reply 3 22416 _002511_hash NULL
85517 +_002512_hash Realloc 2 34961 _002512_hash NULL
85518 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
85519 +_002514_hash rtllib_alloc_txb 1-2 21687 _002514_hash NULL
85520 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
85521 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
85522 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
85523 +_002518_hash split 2 11691 _002518_hash NULL
85524 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
85525 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
85526 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
85527 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
85528 +_002523_hash tunables_read 3 36385 _002523_hash NULL
85529 +_002524_hash tunables_write 3 59563 _002524_hash NULL
85530 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
85531 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
85532 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
85533 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
85534 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
85535 +_002530_hash xsd_read 3 15653 _002530_hash NULL
85536 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
85537 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _003110_hash NULL nohasharray
85538 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
85539 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
85540 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
85541 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
85542 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
85543 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
85544 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
85545 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
85546 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
85547 +_002546_hash compat_readv 3 30273 _002546_hash NULL
85548 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
85549 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
85550 +_002551_hash compat_writev 3 60063 _002551_hash NULL
85551 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
85552 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
85553 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
85554 +_002555_hash xd_rw 4 49020 _002555_hash NULL
85555 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
85556 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
85557 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
85558 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
85559 +_002560_hash ms_rw 4 17220 _002560_hash NULL
85560 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
85561 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
85562 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
85563 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
85564 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
85565 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
85566 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
85567 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
85568 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
85569 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
85570 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
85571 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
85572 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
85573 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
85574 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
85575 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
85576 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
85577 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
85578 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
85579 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
85580 +_002584_hash fb_read 3 33506 _002584_hash NULL
85581 +_002585_hash fb_write 3 46924 _002585_hash NULL
85582 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
85583 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
85584 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
85585 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
85586 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
85587 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
85588 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
85589 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
85590 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
85591 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
85592 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
85593 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
85594 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
85595 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
85596 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
85597 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
85598 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
85599 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
85600 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
85601 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
85602 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
85603 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
85604 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
85605 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
85606 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
85607 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
85608 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
85609 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
85610 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
85611 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
85612 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
85613 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
85614 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
85615 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
85616 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
85617 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
85618 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
85619 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
85620 +_002626_hash create_table 2 16213 _002626_hash NULL
85621 +_002627_hash mem_read 3 57631 _002627_hash NULL
85622 +_002628_hash mem_write 3 22232 _002628_hash NULL
85623 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
85624 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
85625 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
85626 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
85627 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
85628 +_002634_hash alloc_dummy_extent_buffer 2 56374 _002634_hash NULL
85629 +_002635_hash alloc_fdtable 1 17389 _002635_hash NULL
85630 +_002636_hash alloc_large_system_hash 2 22391 _002636_hash NULL
85631 +_002637_hash alloc_ldt 2 21972 _002637_hash NULL
85632 +_002638_hash __alloc_skb 1 23940 _002638_hash NULL
85633 +_002639_hash __ata_change_queue_depth 3 23484 _002639_hash NULL
85634 +_002640_hash btrfs_alloc_free_block 3 8986 _002640_hash NULL
85635 +_002641_hash btrfs_find_device_for_logical 2 44993 _002641_hash NULL
85636 +_002642_hash ccid3_hc_rx_getsockopt 3 62331 _002642_hash NULL
85637 +_002643_hash ccid3_hc_tx_getsockopt 3 16314 _002643_hash NULL
85638 +_002644_hash cifs_readdata_alloc 1 26360 _002644_hash NULL
85639 +_002645_hash cistpl_vers_1 4 15023 _002645_hash NULL
85640 +_002646_hash cmm_read 3 57520 _002646_hash NULL
85641 +_002647_hash cosa_read 3 25966 _002647_hash NULL
85642 +_002648_hash dm_table_create 3 35687 _002648_hash NULL
85643 +_002649_hash dpcm_state_read_file 3 65489 _002649_hash NULL
85644 +_002651_hash edac_mc_alloc 4 3611 _002651_hash NULL
85645 +_002652_hash ep0_read 3 38095 _002652_hash NULL
85646 +_002653_hash event_buffer_read 3 48772 _002765_hash NULL nohasharray
85647 +_002654_hash extend_netdev_table 2 21453 _002654_hash NULL
85648 +_002655_hash extract_entropy_user 3 26952 _002655_hash NULL
85649 +_002656_hash fcoe_ctlr_device_add 3 1793 _002656_hash NULL
85650 +_002657_hash fd_do_readv 3 51297 _002657_hash NULL
85651 +_002658_hash fd_do_writev 3 29329 _002658_hash NULL
85652 +_002659_hash ffs_ep0_read 3 2672 _002659_hash NULL
85653 +_002660_hash fill_readbuf 3 32464 _002660_hash NULL
85654 +_002661_hash fw_iso_buffer_alloc 2 13704 _002661_hash NULL
85655 +_002662_hash get_fd_set 1 3866 _002662_hash NULL
85656 +_002663_hash hidraw_report_event 3 20503 _002663_hash NULL
85657 +_002664_hash ieee80211_if_read_ht_opmode 3 29044 _002664_hash NULL
85658 +_002665_hash ieee80211_if_read_num_mcast_sta 3 12419 _002665_hash NULL
85659 +_002666_hash iwl_dbgfs_calib_disabled_read 3 22649 _002666_hash NULL
85660 +_002667_hash iwl_dbgfs_rf_reset_read 3 26512 _002667_hash NULL
85661 +_002668_hash ixgbe_alloc_q_vector 4-6 24439 _002668_hash NULL
85662 +_002670_hash joydev_handle_JSIOCSAXMAP 3 48898 _002836_hash NULL nohasharray
85663 +_002671_hash joydev_handle_JSIOCSBTNMAP 3 15643 _002671_hash NULL
85664 +_002672_hash __kfifo_from_user_r 3 60345 _002672_hash NULL
85665 +_002673_hash kstrtoint_from_user 2 8778 _002673_hash NULL
85666 +_002674_hash kstrtol_from_user 2 10168 _002674_hash NULL
85667 +_002675_hash kstrtoll_from_user 2 19500 _002675_hash NULL
85668 +_002676_hash kstrtos16_from_user 2 28300 _002676_hash NULL
85669 +_002677_hash kstrtos8_from_user 2 58268 _002677_hash NULL
85670 +_002678_hash kstrtou16_from_user 2 54274 _002678_hash NULL
85671 +_002679_hash kstrtou8_from_user 2 55599 _002679_hash NULL
85672 +_002680_hash kstrtouint_from_user 2 10536 _002680_hash NULL
85673 +_002681_hash kstrtoul_from_user 2 64569 _002681_hash NULL
85674 +_002682_hash kstrtoull_from_user 2 63026 _002682_hash NULL
85675 +_002683_hash l2cap_create_iframe_pdu 3 40055 _002683_hash NULL
85676 +_002684_hash l2tp_ip6_recvmsg 4 62874 _002684_hash NULL
85677 +_002685_hash mem_cgroup_read 5 22461 _002685_hash NULL
85678 +_002686_hash nfs_fscache_get_super_cookie 3 44355 _002686_hash &_001648_hash
85679 +_002687_hash nfs_pgarray_set 2 1085 _002687_hash NULL
85680 +_002688_hash ntfs_rl_realloc 3 56831 _002688_hash &_000363_hash
85681 +_002689_hash ntfs_rl_realloc_nofail 3 32173 _002689_hash NULL
85682 +_002690_hash pn533_dep_link_up 5 22154 _002690_hash NULL
85683 +_002691_hash port_fops_write 3 54627 _002691_hash NULL
85684 +_002692_hash ptp_read 4 63251 _002692_hash NULL
85685 +_002693_hash qla4xxx_change_queue_depth 2 1268 _002693_hash NULL
85686 +_002694_hash reqsk_queue_alloc 2 40272 _002694_hash NULL
85687 +_002695_hash resize_info_buffer 2 62889 _002695_hash NULL
85688 +_002696_hash rfkill_fop_write 3 64808 _002696_hash NULL
85689 +_002697_hash rt2x00debug_write_rfcsr 3 41473 _002697_hash NULL
85690 +_002698_hash rvmalloc 1 46873 _002698_hash NULL
85691 +_002699_hash rw_copy_check_uvector 3 45748 _002699_hash NULL
85692 +_002700_hash sctp_getsockopt_active_key 2 45483 _002700_hash NULL
85693 +_002701_hash sctp_getsockopt_adaptation_layer 2 45375 _002701_hash NULL
85694 +_002702_hash sctp_getsockopt_assoc_ids 2 9043 _002702_hash NULL
85695 +_002703_hash sctp_getsockopt_associnfo 2 58169 _002703_hash NULL
85696 +_002704_hash sctp_getsockopt_assoc_number 2 6384 _002704_hash NULL
85697 +_002705_hash sctp_getsockopt_auto_asconf 2 46584 _002705_hash NULL
85698 +_002706_hash sctp_getsockopt_context 2 52490 _002706_hash NULL
85699 +_002707_hash sctp_getsockopt_default_send_param 2 63056 _002707_hash NULL
85700 +_002708_hash sctp_getsockopt_disable_fragments 2 12330 _002708_hash NULL
85701 +_002709_hash sctp_getsockopt_fragment_interleave 2 51215 _002709_hash NULL
85702 +_002710_hash sctp_getsockopt_initmsg 2 26042 _002710_hash NULL
85703 +_002711_hash sctp_getsockopt_mappedv4 2 20044 _002711_hash NULL
85704 +_002712_hash sctp_getsockopt_nodelay 2 9560 _002712_hash NULL
85705 +_002713_hash sctp_getsockopt_partial_delivery_point 2 60952 _002713_hash NULL
85706 +_002714_hash sctp_getsockopt_peeloff 2 59190 _002714_hash NULL
85707 +_002715_hash sctp_getsockopt_peer_addr_info 2 6024 _002715_hash NULL
85708 +_002716_hash sctp_getsockopt_peer_addr_params 2 53645 _002716_hash NULL
85709 +_002717_hash sctp_getsockopt_primary_addr 2 24639 _002717_hash NULL
85710 +_002718_hash sctp_getsockopt_rtoinfo 2 62027 _002718_hash NULL
85711 +_002719_hash sctp_getsockopt_sctp_status 2 56540 _002719_hash NULL
85712 +_002720_hash self_check_write 5 50856 _002720_hash NULL
85713 +_002721_hash smk_read_mapped 3 7562 _002721_hash NULL
85714 +_002722_hash smk_set_cipso 3 20379 _002722_hash NULL
85715 +_002723_hash smk_user_access 3 24440 _002723_hash NULL
85716 +_002724_hash smk_write_mapped 3 13519 _002724_hash NULL
85717 +_002725_hash smk_write_rules_list 3 18565 _002725_hash NULL
85718 +_002726_hash snd_mixart_BA0_read 5 45069 _002726_hash NULL
85719 +_002727_hash snd_mixart_BA1_read 5 5082 _002727_hash NULL
85720 +_002728_hash snd_pcm_oss_read2 3 54387 _002728_hash NULL
85721 +_002729_hash syslog_print 2 307 _002729_hash NULL
85722 +_002730_hash tcp_dma_try_early_copy 3 4457 _002730_hash NULL
85723 +_002731_hash tcp_send_rcvq 3 11316 _002731_hash NULL
85724 +_002732_hash tomoyo_init_log 2 61526 _002732_hash NULL
85725 +_002733_hash ubi_dump_flash 4 46381 _002733_hash NULL
85726 +_002734_hash ubi_eba_atomic_leb_change 5 60379 _002734_hash NULL
85727 +_002735_hash ubi_eba_write_leb 5-6 36029 _002735_hash NULL
85728 +_002737_hash ubi_eba_write_leb_st 5 44343 _002737_hash NULL
85729 +_002738_hash ubi_self_check_all_ff 4 41959 _002738_hash NULL
85730 +_002739_hash unix_bind 3 15668 _002739_hash NULL
85731 +_002740_hash usbvision_rvmalloc 1 19655 _002740_hash NULL
85732 +_002742_hash v4l2_ctrl_new 7 24927 _002742_hash NULL
85733 +_002743_hash v4l2_event_subscribe 3 53687 _002743_hash NULL
85734 +_002744_hash v9fs_direct_read 3 45546 _002744_hash NULL
85735 +_002745_hash v9fs_file_readn 4 36353 _002745_hash &_001606_hash
85736 +_002746_hash __videobuf_alloc_vb 1 5665 _002746_hash NULL
85737 +_002747_hash wm8350_write 3 24480 _002747_hash NULL
85738 +_002748_hash xfs_buf_read_uncached 3 42844 _002748_hash NULL
85739 +_002749_hash yurex_write 3 8761 _002749_hash NULL
85740 +_002750_hash alloc_skb 1 55439 _002750_hash NULL
85741 +_002751_hash alloc_skb_fclone 1 3467 _002751_hash NULL
85742 +_002752_hash ata_scsi_change_queue_depth 2 23126 _002752_hash NULL
85743 +_002753_hash ath6kl_disconnect_timeout_write 3 794 _002753_hash NULL
85744 +_002754_hash ath6kl_keepalive_write 3 45600 _002754_hash NULL
85745 +_002755_hash ath6kl_lrssi_roam_write 3 8362 _002755_hash NULL
85746 +_002756_hash ath6kl_regread_write 3 14220 _002756_hash NULL
85747 +_002757_hash core_sys_select 1 47494 _002757_hash NULL
85748 +_002758_hash do_syslog 3 56807 _002758_hash NULL
85749 +_002759_hash expand_fdtable 2 39273 _002759_hash NULL
85750 +_002760_hash fd_execute_cmd 3 1132 _002760_hash NULL
85751 +_002761_hash get_chars 3 40373 _002761_hash NULL
85752 +_002762_hash hid_report_raw_event 4 2762 _002762_hash NULL
85753 +_002763_hash inet_csk_listen_start 2 38233 _002763_hash NULL
85754 +_002764_hash kstrtou32_from_user 2 30361 _002764_hash NULL
85755 +_002765_hash l2cap_segment_sdu 4 48772 _002765_hash &_002653_hash
85756 +_002766_hash __netdev_alloc_skb 2 18595 _002766_hash NULL
85757 +_002767_hash nfs_readdata_alloc 2 65015 _002767_hash NULL
85758 +_002768_hash nfs_writedata_alloc 2 12133 _002768_hash NULL
85759 +_002769_hash ntfs_rl_append 2-4 6037 _002769_hash NULL
85760 +_002771_hash ntfs_rl_insert 2-4 4931 _002771_hash NULL
85761 +_002773_hash ntfs_rl_replace 2-4 14136 _002773_hash NULL
85762 +_002775_hash ntfs_rl_split 2-4 52328 _002775_hash NULL
85763 +_002777_hash port_fops_read 3 49626 _002777_hash NULL
85764 +_002778_hash random_read 3 13815 _002778_hash NULL
85765 +_002779_hash sg_proc_write_adio 3 45704 _002779_hash NULL
85766 +_002780_hash sg_proc_write_dressz 3 46316 _002780_hash NULL
85767 +_002781_hash tcp_sendmsg 4 30296 _002781_hash NULL
85768 +_002782_hash tomoyo_write_log2 2 34318 _002782_hash NULL
85769 +_002783_hash ubi_leb_change 4 10289 _002783_hash NULL
85770 +_002784_hash ubi_leb_write 4-5 5478 _002784_hash NULL
85771 +_002786_hash urandom_read 3 30462 _002786_hash NULL
85772 +_002787_hash v9fs_cached_file_read 3 2514 _002787_hash NULL
85773 +_002788_hash __videobuf_alloc_cached 1 12740 _002788_hash NULL
85774 +_002789_hash __videobuf_alloc_uncached 1 55711 _002789_hash NULL
85775 +_002790_hash wm8350_block_write 3 19727 _002790_hash NULL
85776 +_002791_hash alloc_tx 2 32143 _002791_hash NULL
85777 +_002792_hash alloc_wr 1-2 24635 _002792_hash NULL
85778 +_002794_hash ath6kl_endpoint_stats_write 3 59621 _002794_hash NULL
85779 +_002795_hash ath6kl_fwlog_mask_write 3 24810 _002795_hash NULL
85780 +_002796_hash ath9k_wmi_cmd 4 327 _002796_hash NULL
85781 +_002797_hash atm_alloc_charge 2 19517 _002879_hash NULL nohasharray
85782 +_002798_hash ax25_output 2 22736 _002798_hash NULL
85783 +_002799_hash bcsp_prepare_pkt 3 12961 _002799_hash NULL
85784 +_002800_hash bt_skb_alloc 1 6404 _002800_hash NULL
85785 +_002801_hash capinc_tty_write 3 28539 _002801_hash NULL
85786 +_002802_hash cfpkt_create_pfx 1-2 23594 _002802_hash NULL
85787 +_002804_hash cmd_complete 6 51629 _002804_hash NULL
85788 +_002805_hash cmtp_add_msgpart 4 9252 _002805_hash NULL
85789 +_002806_hash cmtp_send_interopmsg 7 376 _002806_hash NULL
85790 +_002807_hash cxgb3_get_cpl_reply_skb 2 10620 _002807_hash NULL
85791 +_002808_hash dbg_leb_change 4 23555 _002808_hash NULL
85792 +_002809_hash dbg_leb_write 4-5 63555 _002809_hash &_000940_hash
85793 +_002811_hash dccp_listen_start 2 35918 _002811_hash NULL
85794 +_002812_hash __dev_alloc_skb 1 28681 _002812_hash NULL
85795 +_002813_hash diva_os_alloc_message_buffer 1 64568 _002813_hash NULL
85796 +_002814_hash dn_alloc_skb 2 6631 _002814_hash NULL
85797 +_002815_hash do_pselect 1 62061 _002815_hash NULL
85798 +_002816_hash _fc_frame_alloc 1 43568 _002816_hash NULL
85799 +_002817_hash find_skb 2 20431 _002817_hash NULL
85800 +_002818_hash fm_send_cmd 5 39639 _002818_hash NULL
85801 +_002819_hash gem_alloc_skb 2 51715 _002819_hash NULL
85802 +_002820_hash get_packet 3 41914 _002820_hash NULL
85803 +_002821_hash get_packet 3 5747 _002821_hash NULL
85804 +_002822_hash get_packet_pg 4 28023 _002822_hash NULL
85805 +_002823_hash get_skb 2 63008 _002823_hash NULL
85806 +_002824_hash hidp_queue_report 3 1881 _002824_hash NULL
85807 +_002825_hash __hidp_send_ctrl_message 4 28303 _002825_hash NULL
85808 +_002826_hash hycapi_rx_capipkt 3 11602 _002826_hash NULL
85809 +_002827_hash i2400m_net_rx 5 27170 _002827_hash NULL
85810 +_002828_hash igmpv3_newpack 2 35912 _002828_hash NULL
85811 +_002829_hash inet_listen 2 14723 _002829_hash NULL
85812 +_002830_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _002830_hash &_001724_hash
85813 +_002831_hash isdn_ppp_ccp_xmit_reset 6 63297 _002831_hash NULL
85814 +_002832_hash kmsg_read 3 46514 _002832_hash NULL
85815 +_002833_hash _l2_alloc_skb 1 11883 _002833_hash NULL
85816 +_002834_hash l3_alloc_skb 1 32289 _002834_hash NULL
85817 +_002835_hash llc_alloc_frame 4 64366 _002835_hash NULL
85818 +_002836_hash mac_drv_rx_init 2 48898 _002836_hash &_002670_hash
85819 +_002837_hash mgmt_event 4 12810 _002837_hash NULL
85820 +_002838_hash mI_alloc_skb 1 24770 _002838_hash NULL
85821 +_002839_hash nci_skb_alloc 2 49757 _002839_hash NULL
85822 +_002840_hash netdev_alloc_skb 2 62437 _002840_hash NULL
85823 +_002841_hash __netdev_alloc_skb_ip_align 2 55067 _002841_hash NULL
85824 +_002842_hash new_skb 1 21148 _002842_hash NULL
85825 +_002843_hash nfc_alloc_recv_skb 1 10244 _002843_hash NULL
85826 +_002844_hash nfcwilink_skb_alloc 1 16167 _002844_hash NULL
85827 +_002845_hash nfulnl_alloc_skb 2 65207 _002845_hash NULL
85828 +_002846_hash ni65_alloc_mem 3 10664 _002846_hash NULL
85829 +_002847_hash pep_alloc_skb 3 46303 _002847_hash NULL
85830 +_002848_hash pn_raw_send 2 54330 _002848_hash NULL
85831 +_002849_hash __pskb_copy 2 9038 _002849_hash NULL
85832 +_002850_hash refill_pool 2 19477 _002850_hash NULL
85833 +_002851_hash rfcomm_wmalloc 2 58090 _002851_hash NULL
85834 +_002852_hash rx 4 57944 _002852_hash NULL
85835 +_002853_hash sctp_ulpevent_new 1 33377 _002853_hash NULL
85836 +_002854_hash send_command 4 10832 _002854_hash NULL
85837 +_002855_hash skb_copy_expand 2-3 7685 _002855_hash &_000671_hash
85838 +_002857_hash sk_stream_alloc_skb 2 57622 _002857_hash NULL
85839 +_002858_hash sock_alloc_send_pskb 2 21246 _002858_hash NULL
85840 +_002859_hash sock_rmalloc 2 59740 _002859_hash &_002157_hash
85841 +_002860_hash sock_wmalloc 2 16472 _002860_hash NULL
85842 +_002861_hash solos_param_store 4 34755 _002861_hash NULL
85843 +_002862_hash sys_select 1 38827 _002862_hash NULL
85844 +_002863_hash sys_syslog 3 10746 _002863_hash NULL
85845 +_002864_hash t4vf_pktgl_to_skb 2 39005 _002864_hash NULL
85846 +_002865_hash tcp_collapse 5-6 63294 _002865_hash NULL
85847 +_002867_hash tipc_cfg_reply_alloc 1 27606 _002867_hash NULL
85848 +_002868_hash ubifs_leb_change 4 17789 _002868_hash NULL
85849 +_002869_hash ubifs_leb_write 4-5 22679 _002869_hash NULL
85850 +_002871_hash ulog_alloc_skb 1 23427 _002871_hash NULL
85851 +_002872_hash _alloc_mISDN_skb 3 52232 _002872_hash NULL
85852 +_002873_hash ath9k_multi_regread 4 65056 _002873_hash NULL
85853 +_002874_hash ath_rxbuf_alloc 2 24745 _002874_hash NULL
85854 +_002875_hash ax25_send_frame 2 19964 _002875_hash NULL
85855 +_002876_hash bchannel_get_rxbuf 2 37213 _002876_hash NULL
85856 +_002877_hash cfpkt_create 1 18197 _002877_hash NULL
85857 +_002878_hash console_store 4 36007 _002878_hash NULL
85858 +_002879_hash dev_alloc_skb 1 19517 _002879_hash &_002797_hash
85859 +_002880_hash dn_nsp_do_disc 2-6 49474 _002880_hash NULL
85860 +_002882_hash do_write_orph_node 2 64343 _002882_hash NULL
85861 +_002883_hash dsp_cmx_send_member 2 15625 _002883_hash NULL
85862 +_002884_hash fc_frame_alloc 2 1596 _002884_hash NULL
85863 +_002885_hash fc_frame_alloc_fill 2 59394 _002885_hash NULL
85864 +_002886_hash fmc_send_cmd 5 20435 _002886_hash NULL
85865 +_002887_hash hci_send_cmd 3 43810 _002887_hash NULL
85866 +_002888_hash hci_si_event 3 1404 _002888_hash NULL
85867 +_002889_hash hfcpci_empty_bfifo 4 62323 _002889_hash NULL
85868 +_002890_hash hidp_send_ctrl_message 4 43702 _002890_hash NULL
85869 +_002891_hash hysdn_sched_rx 3 60533 _002891_hash NULL
85870 +_002892_hash inet_dccp_listen 2 28565 _002892_hash NULL
85871 +_002893_hash ip6_append_data 4-5 36490 _002893_hash NULL
85872 +_002894_hash __ip_append_data 7-8 36191 _002894_hash NULL
85873 +_002895_hash l1oip_socket_recv 6 56537 _002895_hash NULL
85874 +_002896_hash l2cap_build_cmd 4 48676 _002896_hash NULL
85875 +_002897_hash l2down_create 4 21755 _002897_hash NULL
85876 +_002898_hash l2up_create 3 6430 _002898_hash NULL
85877 +_002899_hash ldisc_receive 4 41516 _002899_hash NULL
85878 +_002902_hash lro_gen_skb 6 2644 _002902_hash NULL
85879 +_002903_hash macvtap_alloc_skb 2-4-3 50629 _002903_hash NULL
85880 +_002906_hash mgmt_device_found 10 14146 _002906_hash NULL
85881 +_002907_hash nci_send_cmd 3 58206 _002907_hash NULL
85882 +_002908_hash netdev_alloc_skb_ip_align 2 40811 _002908_hash NULL
85883 +_002909_hash nfcwilink_send_bts_cmd 3 10802 _002909_hash NULL
85884 +_002910_hash nfqnl_mangle 2 14583 _002910_hash NULL
85885 +_002911_hash p54_alloc_skb 3 34366 _002911_hash &_000475_hash
85886 +_002912_hash packet_alloc_skb 2-5-4 62602 _002912_hash NULL
85887 +_002915_hash pep_indicate 5 38611 _002915_hash NULL
85888 +_002916_hash pep_reply 5 50582 _002916_hash NULL
85889 +_002917_hash pipe_handler_request 5 50774 _002917_hash &_001189_hash
85890 +_002918_hash ql_process_mac_rx_page 4 15543 _002918_hash NULL
85891 +_002919_hash ql_process_mac_rx_skb 4 6689 _002919_hash NULL
85892 +_002920_hash rfcomm_tty_write 3 51603 _002920_hash NULL
85893 +_002921_hash send_mpa_reject 3 7135 _002921_hash NULL
85894 +_002922_hash send_mpa_reply 3 32372 _002922_hash NULL
85895 +_002923_hash set_rxd_buffer_pointer 8 9950 _002923_hash NULL
85896 +_002924_hash sge_rx 3 50594 _002924_hash NULL
85897 +_002925_hash skb_cow_data 2 11565 _002925_hash NULL
85898 +_002926_hash smp_build_cmd 3 45853 _002926_hash NULL
85899 +_002927_hash sock_alloc_send_skb 2 23720 _002927_hash NULL
85900 +_002928_hash sys_pselect6 1 57449 _002928_hash NULL
85901 +_002929_hash tcp_fragment 3 20436 _002929_hash NULL
85902 +_002930_hash teiup_create 3 43201 _002930_hash NULL
85903 +_002931_hash tg3_run_loopback 2 30093 _002931_hash NULL
85904 +_002932_hash tun_alloc_skb 2-4-3 41216 _002932_hash NULL
85905 +_002935_hash ubifs_write_node 5 11258 _002935_hash NULL
85906 +_002936_hash use_pool 2 64607 _002936_hash NULL
85907 +_002937_hash vxge_rx_alloc 3 52024 _002937_hash NULL
85908 +_002938_hash add_packet 3 54433 _002938_hash NULL
85909 +_002939_hash add_rx_skb 3 8257 _002939_hash NULL
85910 +_002940_hash ath6kl_buf_alloc 1 57304 _002940_hash NULL
85911 +_002941_hash bat_iv_ogm_aggregate_new 2 2620 _002941_hash NULL
85912 +_002942_hash bnx2fc_process_l2_frame_compl 3 65072 _002942_hash NULL
85913 +_002943_hash brcmu_pkt_buf_get_skb 1 5556 _002943_hash NULL
85914 +_002944_hash br_send_bpdu 3 29669 _002944_hash NULL
85915 +_002945_hash bt_skb_send_alloc 2 6581 _002945_hash NULL
85916 +_002946_hash c4iw_reject_cr 3 28174 _002946_hash NULL
85917 +_002947_hash carl9170_rx_copy_data 2 21656 _002947_hash NULL
85918 +_002948_hash cfpkt_add_body 3 44630 _002948_hash NULL
85919 +_002949_hash cfpkt_append 3 61206 _002949_hash NULL
85920 +_002950_hash cosa_net_setup_rx 2 38594 _002950_hash NULL
85921 +_002951_hash cxgb4_pktgl_to_skb 2 61899 _002951_hash NULL
85922 +_002952_hash dn_alloc_send_pskb 2 4465 _002952_hash NULL
85923 +_002953_hash dn_nsp_return_disc 2 60296 _002953_hash NULL
85924 +_002954_hash dn_nsp_send_disc 2 23469 _002954_hash NULL
85925 +_002955_hash dsp_tone_hw_message 3 17678 _002955_hash NULL
85926 +_002956_hash dvb_net_sec 3 37884 _002956_hash NULL
85927 +_002957_hash e1000_check_copybreak 3 62448 _002957_hash NULL
85928 +_002958_hash fast_rx_path 3 59214 _002958_hash NULL
85929 +_002959_hash fc_fcp_frame_alloc 2 12624 _002959_hash NULL
85930 +_002960_hash fcoe_ctlr_send_keep_alive 3 15308 _002960_hash NULL
85931 +_002961_hash fwnet_incoming_packet 3 40380 _002961_hash NULL
85932 +_002962_hash fwnet_pd_new 4 39947 _002962_hash NULL
85933 +_002963_hash got_frame 2 16028 _002963_hash NULL
85934 +_002964_hash gsm_mux_rx_netchar 3 33336 _002964_hash NULL
85935 +_002965_hash hdlcdev_rx 3 997 _002965_hash NULL
85936 +_002966_hash hdlc_empty_fifo 2 18397 _002966_hash NULL
85937 +_002967_hash hfc_empty_fifo 2 57972 _002967_hash NULL
85938 +_002968_hash hfcpci_empty_fifo 4 2427 _002968_hash NULL
85939 +_002969_hash hfcsusb_rx_frame 3 52745 _002969_hash NULL
85940 +_002970_hash hidp_output_raw_report 3 5629 _002970_hash NULL
85941 +_002971_hash hscx_empty_fifo 2 13360 _002971_hash NULL
85942 +_002972_hash hysdn_rx_netpkt 3 16136 _002972_hash NULL
85943 +_002973_hash ieee80211_fragment 4 33112 _002973_hash NULL
85944 +_002974_hash ieee80211_probereq_get 4-6 29069 _002974_hash NULL
85945 +_002976_hash ieee80211_send_auth 5 24121 _002976_hash NULL
85946 +_002977_hash ieee80211_set_probe_resp 3 10077 _002977_hash NULL
85947 +_002978_hash ieee80211_tdls_mgmt 8 9581 _002978_hash NULL
85948 +_002979_hash ip6_ufo_append_data 5-7-6 4780 _002979_hash NULL
85949 +_002982_hash ip_ufo_append_data 6-8-7 12775 _002982_hash NULL
85950 +_002985_hash ipw_packet_received_skb 2 1230 _002985_hash NULL
85951 +_002986_hash iwch_reject_cr 3 23901 _002986_hash NULL
85952 +_002987_hash iwm_rx_packet_alloc 3 9898 _002987_hash NULL
85953 +_002988_hash ixgb_check_copybreak 3 5847 _002988_hash NULL
85954 +_002989_hash l1oip_socket_parse 4 4507 _002989_hash NULL
85955 +_002990_hash l2cap_send_cmd 4 14548 _002990_hash NULL
85956 +_002991_hash l2tp_ip6_sendmsg 4 7461 _002991_hash NULL
85957 +_002993_hash lowpan_fragment_xmit 3-4 22095 _002993_hash NULL
85958 +_002996_hash mcs_unwrap_fir 3 25733 _002996_hash NULL
85959 +_002997_hash mcs_unwrap_mir 3 9455 _002997_hash NULL
85960 +_002998_hash mld_newpack 2 50950 _002998_hash NULL
85961 +_002999_hash nfc_alloc_send_skb 4 3167 _002999_hash NULL
85962 +_003000_hash p54_download_eeprom 4 43842 _003000_hash NULL
85963 +_003002_hash ppp_tx_cp 5 62044 _003002_hash NULL
85964 +_003003_hash prism2_send_mgmt 4 62605 _003003_hash &_001876_hash
85965 +_003004_hash prism2_sta_send_mgmt 5 43916 _003004_hash NULL
85966 +_003005_hash _queue_data 4 54983 _003005_hash NULL
85967 +_003006_hash read_dma 3 55086 _003006_hash NULL
85968 +_003007_hash read_fifo 3 826 _003007_hash NULL
85969 +_003008_hash receive_copy 3 12216 _003008_hash NULL
85970 +_003009_hash rtl8169_try_rx_copy 3 705 _003009_hash NULL
85971 +_003010_hash _rtl92s_firmware_downloadcode 3 14021 _003010_hash NULL
85972 +_003011_hash rx_data 4 60442 _003011_hash NULL
85973 +_003012_hash sis190_try_rx_copy 3 57069 _003012_hash NULL
85974 +_003013_hash skge_rx_get 3 40598 _003013_hash NULL
85975 +_003014_hash tcp_mark_head_lost 2 35895 _003014_hash NULL
85976 +_003015_hash tcp_match_skb_to_sack 3-4 23568 _003015_hash NULL
85977 +_003017_hash tso_fragment 3 29050 _003017_hash NULL
85978 +_003018_hash tt_response_fill_table 1 57902 _003018_hash NULL
85979 +_003020_hash udpv6_sendmsg 4 22316 _003020_hash NULL
85980 +_003021_hash velocity_rx_copy 2 34583 _003021_hash NULL
85981 +_003022_hash W6692_empty_Bfifo 2 47804 _003022_hash NULL
85982 +_003023_hash zd_mac_rx 3 38296 _003023_hash NULL
85983 +_003024_hash ath6kl_wmi_get_new_buf 1 52304 _003024_hash NULL
85984 +_003025_hash bat_iv_ogm_queue_add 3 30870 _003025_hash NULL
85985 +_003026_hash brcmf_alloc_pkt_and_read 2 63116 _003026_hash &_001808_hash
85986 +_003027_hash brcmf_sdcard_recv_buf 6 38179 _003027_hash NULL
85987 +_003028_hash brcmf_sdcard_rwdata 5 65041 _003028_hash NULL
85988 +_003029_hash brcmf_sdcard_send_buf 6 7713 _003029_hash NULL
85989 +_003030_hash carl9170_handle_mpdu 3 11056 _003030_hash NULL
85990 +_003031_hash cfpkt_add_trail 3 27260 _003031_hash NULL
85991 +_003032_hash cfpkt_pad_trail 2 55511 _003032_hash NULL
85992 +_003033_hash dvb_net_sec_callback 2 28786 _003033_hash NULL
85993 +_003034_hash fwnet_receive_packet 9 50537 _003034_hash NULL
85994 +_003035_hash handle_rx_packet 3 58993 _003035_hash NULL
85995 +_003036_hash HDLC_irq 2 8709 _003036_hash NULL
85996 +_003037_hash hdlc_rpr_irq 2 10240 _003037_hash NULL
85997 +_003043_hash ipwireless_network_packet_received 4 51277 _003043_hash NULL
85998 +_003044_hash l2cap_bredr_sig_cmd 3 49065 _003044_hash NULL
85999 +_003045_hash l2cap_sock_alloc_skb_cb 2 33532 _003045_hash NULL
86000 +_003046_hash llcp_allocate_pdu 3 19866 _003046_hash NULL
86001 +_003047_hash ppp_cp_event 6 2965 _003047_hash NULL
86002 +_003048_hash receive_client_update_packet 3 49104 _003048_hash NULL
86003 +_003049_hash receive_server_sync_packet 3 59021 _003049_hash NULL
86004 +_003050_hash sky2_receive 2 13407 _003050_hash NULL
86005 +_003051_hash tcp_sacktag_walk 5-6 49703 _003051_hash NULL
86006 +_003053_hash tcp_write_xmit 2 64602 _003053_hash NULL
86007 +_003054_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _003054_hash NULL
86008 +_003055_hash ath6kl_wmi_beginscan_cmd 8 25462 _003055_hash NULL
86009 +_003056_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _003056_hash NULL
86010 +_003057_hash ath6kl_wmi_set_appie_cmd 5 39266 _003057_hash NULL
86011 +_003058_hash ath6kl_wmi_set_ie_cmd 6 37260 _003058_hash NULL
86012 +_003059_hash ath6kl_wmi_startscan_cmd 8 33674 _003059_hash NULL
86013 +_003060_hash ath6kl_wmi_test_cmd 3 27312 _003060_hash NULL
86014 +_003061_hash brcmf_sdbrcm_membytes 3-5 37324 _003061_hash NULL
86015 +_003063_hash brcmf_sdbrcm_read_control 3 22721 _003063_hash NULL
86016 +_003064_hash brcmf_tx_frame 3 20978 _003064_hash NULL
86017 +_003065_hash __carl9170_rx 3 56784 _003065_hash NULL
86018 +_003066_hash cfpkt_setlen 2 49343 _003066_hash NULL
86019 +_003067_hash hdlc_irq_one 2 3944 _003067_hash NULL
86020 +_003069_hash tcp_push_one 2 48816 _003069_hash NULL
86021 +_003070_hash __tcp_push_pending_frames 2 48148 _003070_hash NULL
86022 +_003071_hash brcmf_sdbrcm_bus_txctl 3 42492 _003071_hash NULL
86023 +_003072_hash carl9170_rx 3 13272 _003072_hash NULL
86024 +_003073_hash carl9170_rx_stream 3 1334 _003073_hash NULL
86025 +_003074_hash tcp_push 3 10680 _003074_hash NULL
86026 +_003075_hash create_log 2 8225 _003075_hash NULL
86027 +_003076_hash expand_files 2 17080 _003076_hash NULL
86028 +_003077_hash iio_device_alloc 1 41440 _003077_hash NULL
86029 +_003078_hash OS_mem_token_alloc 1 14276 _003078_hash NULL
86030 +_003079_hash packet_came 3 18072 _003079_hash NULL
86031 +_003080_hash softsynth_write 3 3455 _003080_hash NULL
86032 +_003081_hash alloc_fd 1 37637 _003081_hash NULL
86033 +_003082_hash sys_dup3 2 33421 _003082_hash NULL
86034 +_003083_hash do_fcntl 3 31468 _003083_hash NULL
86035 +_003084_hash sys_dup2 2 25284 _003084_hash NULL
86036 +_003085_hash sys_fcntl 3 19267 _003085_hash NULL
86037 +_003086_hash sys_fcntl64 3 29031 _003086_hash NULL
86038 +_003087_hash cmpk_message_handle_tx 4 54024 _003087_hash NULL
86039 +_003088_hash comedi_buf_alloc 3 24822 _003088_hash NULL
86040 +_003089_hash compat_rw_copy_check_uvector 3 22001 _003089_hash &_001989_hash
86041 +_003090_hash compat_sys_fcntl64 3 60256 _003090_hash NULL
86042 +_003091_hash evtchn_write 3 43278 _003091_hash NULL
86043 +_003092_hash fw_download_code 3 13249 _003092_hash NULL
86044 +_003093_hash fwSendNullPacket 2 54618 _003093_hash NULL
86045 +_003095_hash ieee80211_authentication_req 3 63973 _003095_hash NULL
86046 +_003097_hash rtllib_authentication_req 3 26713 _003097_hash NULL
86047 +_003098_hash SendTxCommandPacket 3 42901 _003098_hash NULL
86048 +_003099_hash snd_nm256_capture_copy 5 28622 _003099_hash NULL
86049 +_003100_hash snd_nm256_playback_copy 5 38567 _003100_hash NULL
86050 +_003101_hash tomoyo_init_log 2 14806 _003101_hash NULL
86051 +_003102_hash usbdux_attach_common 4 51764 _003271_hash NULL nohasharray
86052 +_003103_hash compat_sys_fcntl 3 15654 _003103_hash NULL
86053 +_003104_hash ieee80211_auth_challenge 3 18810 _003104_hash NULL
86054 +_003105_hash ieee80211_rtl_auth_challenge 3 61897 _003105_hash NULL
86055 +_003106_hash resize_async_buffer 4 64031 _003106_hash &_002119_hash
86056 +_003107_hash rtllib_auth_challenge 3 12493 _003107_hash NULL
86057 +_003108_hash tomoyo_write_log2 2 11732 _003108_hash NULL
86058 +_003109_hash allocate_probes 1 40204 _003109_hash NULL
86059 +_003110_hash alloc_ftrace_hash 1 57431 _003110_hash &_002532_hash
86060 +_003111_hash __alloc_preds 2 9492 _003111_hash NULL
86061 +_003112_hash __alloc_pred_stack 2 26687 _003112_hash NULL
86062 +_003113_hash alloc_sched_domains 1 47756 _003113_hash NULL
86063 +_003114_hash alloc_trace_probe 6 38720 _003114_hash NULL
86064 +_003115_hash alloc_trace_uprobe 3 13870 _003115_hash NULL
86065 +_003116_hash arcfb_write 3 8702 _003116_hash NULL
86066 +_003117_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003117_hash NULL
86067 +_003118_hash ath6kl_usb_post_recv_transfers 2 32892 _003118_hash NULL
86068 +_003119_hash ath6kl_usb_submit_ctrl_in 6 32880 _003119_hash &_000778_hash
86069 +_003120_hash ath6kl_usb_submit_ctrl_out 6 9978 _003120_hash NULL
86070 +_003121_hash auok190xfb_write 3 37001 _003121_hash NULL
86071 +_003122_hash beacon_interval_write 3 17952 _003122_hash NULL
86072 +_003123_hash blk_dropped_read 3 4168 _003123_hash NULL
86073 +_003124_hash blk_msg_write 3 13655 _003124_hash NULL
86074 +_003125_hash brcmf_usbdev_qinit 2 19090 _003125_hash &_001533_hash
86075 +_003126_hash brcmf_usb_dl_cmd 4 53130 _003126_hash NULL
86076 +_003127_hash broadsheetfb_write 3 39976 _003127_hash NULL
86077 +_003128_hash broadsheet_spiflash_rewrite_sector 2 54864 _003128_hash NULL
86078 +_003129_hash cyttsp_probe 4 1940 _003129_hash NULL
86079 +_003130_hash da9052_group_write 3 4534 _003130_hash NULL
86080 +_003131_hash dccpprobe_read 3 52549 _003131_hash NULL
86081 +_003132_hash drm_property_create_bitmask 5 30195 _003132_hash NULL
86082 +_003133_hash dtim_interval_write 3 30489 _003133_hash NULL
86083 +_003134_hash dynamic_ps_timeout_write 3 37713 _003134_hash NULL
86084 +_003135_hash event_enable_read 3 7074 _003135_hash NULL
86085 +_003136_hash event_enable_write 3 45238 _003136_hash NULL
86086 +_003137_hash event_filter_read 3 23494 _003137_hash NULL
86087 +_003138_hash event_filter_write 3 56609 _003138_hash NULL
86088 +_003139_hash event_id_read 3 64288 _003139_hash &_001240_hash
86089 +_003140_hash f_audio_buffer_alloc 1 41110 _003140_hash NULL
86090 +_003141_hash fb_sys_read 3 13778 _003141_hash NULL
86091 +_003142_hash fb_sys_write 3 33130 _003142_hash NULL
86092 +_003143_hash forced_ps_write 3 37209 _003143_hash NULL
86093 +_003144_hash __fprog_create 2 41263 _003144_hash NULL
86094 +_003145_hash fq_codel_zalloc 1 15378 _003145_hash NULL
86095 +_003146_hash ftrace_pid_write 3 39710 _003146_hash NULL
86096 +_003147_hash ftrace_profile_read 3 21327 _003147_hash NULL
86097 +_003148_hash ftrace_profile_write 3 53327 _003148_hash NULL
86098 +_003149_hash ftrace_write 3 29551 _003149_hash NULL
86099 +_003150_hash gdm_wimax_netif_rx 3 43423 _003150_hash &_001619_hash
86100 +_003151_hash gpio_power_write 3 1991 _003151_hash NULL
86101 +_003152_hash hecubafb_write 3 26942 _003152_hash NULL
86102 +_003153_hash hsc_msg_alloc 1 60990 _003153_hash NULL
86103 +_003154_hash hsc_write 3 55875 _003154_hash NULL
86104 +_003155_hash hsi_alloc_controller 1 41802 _003155_hash NULL
86105 +_003156_hash hsi_register_board_info 2 13820 _003156_hash NULL
86106 +_003157_hash i915_ring_stop_read 3 42549 _003157_hash NULL
86107 +_003158_hash i915_ring_stop_write 3 59010 _003158_hash NULL
86108 +_003159_hash ieee802154_alloc_device 1 13767 _003159_hash NULL
86109 +_003160_hash intel_sdvo_write_cmd 4 54377 _003160_hash &_000815_hash
86110 +_003161_hash ivtvfb_write 3 40023 _003161_hash NULL
86111 +_003162_hash metronomefb_write 3 8823 _003162_hash NULL
86112 +_003163_hash mwifiex_usb_submit_rx_urb 2 54558 _003163_hash NULL
86113 +_003164_hash nfc_hci_hcp_message_tx 6 14534 _003164_hash NULL
86114 +_003165_hash nfc_hci_set_param 5 40697 _003165_hash NULL
86115 +_003166_hash nfc_shdlc_alloc_skb 2 12741 _003166_hash NULL
86116 +_003167_hash odev_update 2 50169 _003167_hash NULL
86117 +_003168_hash oz_add_farewell 5 20652 _003168_hash NULL
86118 +_003169_hash oz_cdev_read 3 20659 _003169_hash NULL
86119 +_003170_hash oz_cdev_write 3 33852 _003170_hash NULL
86120 +_003171_hash oz_ep_alloc 2 5587 _003171_hash NULL
86121 +_003172_hash oz_events_read 3 47535 _003172_hash NULL
86122 +_003173_hash pmcraid_copy_sglist 3 38431 _003173_hash NULL
86123 +_003174_hash prctl_set_mm 3 64538 _003174_hash NULL
86124 +_003175_hash ptp_filter_init 2 36780 _003175_hash NULL
86125 +_003176_hash rb_simple_read 3 45972 _003176_hash NULL
86126 +_003177_hash rb_simple_write 3 20890 _003177_hash NULL
86127 +_003178_hash read_file_dfs 3 43145 _003178_hash NULL
86128 +_003179_hash rx_streaming_always_write 3 32357 _003179_hash NULL
86129 +_003180_hash rx_streaming_interval_write 3 50120 _003180_hash NULL
86130 +_003181_hash shmem_pread_fast 3 34147 _003181_hash NULL
86131 +_003182_hash shmem_pread_slow 3 3198 _003182_hash NULL
86132 +_003183_hash shmem_pwrite_fast 3 46842 _003183_hash NULL
86133 +_003184_hash shmem_pwrite_slow 3 31741 _003184_hash NULL
86134 +_003185_hash show_header 3 4722 _003185_hash &_000736_hash
86135 +_003186_hash split_scan_timeout_write 3 52128 _003186_hash NULL
86136 +_003187_hash stack_max_size_read 3 1445 _003187_hash NULL
86137 +_003188_hash stack_max_size_write 3 36068 _003188_hash NULL
86138 +_003189_hash subsystem_filter_read 3 62310 _003189_hash NULL
86139 +_003190_hash subsystem_filter_write 3 13022 _003190_hash NULL
86140 +_003191_hash suspend_dtim_interval_write 3 48854 _003191_hash NULL
86141 +_003192_hash system_enable_read 3 25815 _003192_hash NULL
86142 +_003193_hash system_enable_write 3 61396 _003193_hash NULL
86143 +_003194_hash trace_options_core_read 3 47390 _003194_hash NULL
86144 +_003195_hash trace_options_core_write 3 61551 _003195_hash NULL
86145 +_003196_hash trace_options_read 3 11419 _003196_hash NULL
86146 +_003197_hash trace_options_write 3 48275 _003197_hash NULL
86147 +_003198_hash trace_parser_get_init 2 31379 _003198_hash NULL
86148 +_003199_hash traceprobe_probes_write 3 64969 _003199_hash NULL
86149 +_003200_hash trace_seq_to_user 3 65398 _003200_hash NULL
86150 +_003201_hash tracing_buffers_read 3 11124 _003201_hash NULL
86151 +_003202_hash tracing_clock_write 3 27961 _003202_hash NULL
86152 +_003203_hash tracing_cpumask_read 3 7010 _003203_hash NULL
86153 +_003204_hash tracing_ctrl_read 3 46922 _003204_hash NULL
86154 +_003205_hash tracing_ctrl_write 3 42324 _003205_hash &_001726_hash
86155 +_003206_hash tracing_entries_read 3 8345 _003206_hash NULL
86156 +_003207_hash tracing_entries_write 3 60563 _003207_hash NULL
86157 +_003208_hash tracing_max_lat_read 3 8890 _003208_hash NULL
86158 +_003209_hash tracing_max_lat_write 3 8728 _003209_hash NULL
86159 +_003210_hash tracing_read_dyn_info 3 45468 _003210_hash NULL
86160 +_003211_hash tracing_readme_read 3 16493 _003211_hash NULL
86161 +_003212_hash tracing_saved_cmdlines_read 3 21434 _003212_hash NULL
86162 +_003213_hash tracing_set_trace_read 3 44122 _003213_hash NULL
86163 +_003214_hash tracing_set_trace_write 3 57096 _003214_hash NULL
86164 +_003215_hash tracing_stats_read 3 34537 _003215_hash NULL
86165 +_003216_hash tracing_total_entries_read 3 62817 _003216_hash NULL
86166 +_003217_hash tracing_trace_options_write 3 153 _003217_hash NULL
86167 +_003218_hash ttm_put_pages 2 9179 _003218_hash NULL
86168 +_003219_hash udl_prime_create 2 57159 _003219_hash NULL
86169 +_003220_hash ufx_alloc_urb_list 3 10349 _003220_hash NULL
86170 +_003221_hash u_memcpya 2-3 30139 _003221_hash NULL
86171 +_003223_hash viafb_dfph_proc_write 3 49288 _003223_hash NULL
86172 +_003224_hash viafb_dfpl_proc_write 3 627 _003224_hash NULL
86173 +_003225_hash viafb_dvp0_proc_write 3 23023 _003225_hash NULL
86174 +_003226_hash viafb_dvp1_proc_write 3 48864 _003226_hash NULL
86175 +_003227_hash viafb_vt1636_proc_write 3 16018 _003227_hash NULL
86176 +_003228_hash vivi_read 3 23073 _003228_hash NULL
86177 +_003229_hash wl1271_rx_filter_alloc_field 5 46721 _003229_hash NULL
86178 +_003230_hash wl12xx_cmd_build_probe_req 6-8 3098 _003230_hash NULL
86179 +_003232_hash wlcore_alloc_hw 1 7785 _003232_hash NULL
86180 +_003233_hash alloc_and_copy_ftrace_hash 1 29368 _003233_hash NULL
86181 +_003234_hash create_trace_probe 1 20175 _003234_hash NULL
86182 +_003235_hash create_trace_uprobe 1 13184 _003235_hash NULL
86183 +_003236_hash intel_sdvo_set_value 4 2311 _003236_hash NULL
86184 +_003237_hash mmio_read 4 40348 _003237_hash NULL
86185 +_003238_hash nfc_hci_execute_cmd 5 43882 _003238_hash NULL
86186 +_003239_hash nfc_hci_send_event 5 21452 _003239_hash NULL
86187 +_003240_hash nfc_hci_send_response 5 56462 _003240_hash NULL
86188 +_003241_hash picolcd_fb_write 3 2318 _003241_hash NULL
86189 +_003242_hash probes_write 3 29711 _003242_hash NULL
86190 +_003243_hash sys_prctl 4 8766 _003243_hash NULL
86191 +_003244_hash tracing_read_pipe 3 35312 _003244_hash NULL
86192 +_003245_hash brcmf_usb_attach 1-2 44656 _003245_hash NULL
86193 +_003247_hash dlfb_ops_write 3 64150 _003247_hash NULL
86194 +_003248_hash nfc_hci_send_cmd 5 55714 _003248_hash NULL
86195 +_003249_hash ufx_ops_write 3 54848 _003249_hash NULL
86196 +_003250_hash viafb_iga1_odev_proc_write 3 36241 _003250_hash NULL
86197 +_003251_hash viafb_iga2_odev_proc_write 3 2363 _003251_hash NULL
86198 +_003252_hash xenfb_write 3 43412 _003252_hash NULL
86199 +_003253_hash acl_alloc 1 35979 _003253_hash NULL
86200 +_003254_hash acl_alloc_stack_init 1 60630 _003254_hash NULL
86201 +_003255_hash acl_alloc_num 1-2 60778 _003255_hash NULL
86202 +_003257_hash padzero 1 55 _003257_hash &_002013_hash
86203 +_003258_hash __get_vm_area_node 1 55305 _003258_hash NULL
86204 +_003259_hash get_vm_area 1 18080 _003259_hash NULL
86205 +_003260_hash __get_vm_area 1 61599 _003260_hash NULL
86206 +_003261_hash get_vm_area_caller 1 10527 _003261_hash NULL
86207 +_003262_hash __get_vm_area_caller 1 56416 _003302_hash NULL nohasharray
86208 +_003263_hash alloc_vm_area 1 36149 _003263_hash NULL
86209 +_003264_hash __ioremap_caller 1-2 21800 _003264_hash NULL
86210 +_003266_hash vmap 2 15025 _003266_hash NULL
86211 +_003267_hash ioremap_cache 1-2 47189 _003267_hash NULL
86212 +_003269_hash ioremap_nocache 1-2 2439 _003269_hash NULL
86213 +_003271_hash ioremap_prot 1-2 51764 _003271_hash &_003102_hash
86214 +_003273_hash ioremap_wc 1-2 62695 _003273_hash NULL
86215 +_003274_hash acpi_os_ioremap 1-2 49523 _003274_hash NULL
86216 +_003276_hash ca91cx42_alloc_resource 2 10502 _003276_hash NULL
86217 +_003277_hash devm_ioremap_nocache 2-3 2036 _003277_hash NULL
86218 +_003279_hash __einj_error_trigger 1 17707 _003279_hash &_001577_hash
86219 +_003280_hash io_mapping_map_wc 2 19284 _003280_hash NULL
86220 +_003281_hash ioremap 1-2 23172 _003281_hash NULL
86221 +_003283_hash lguest_map 1-2 42008 _003283_hash NULL
86222 +_003285_hash msix_map_region 3 3411 _003285_hash NULL
86223 +_003286_hash pci_iomap 3 47575 _003286_hash NULL
86224 +_003287_hash sfi_map_memory 1-2 5183 _003287_hash NULL
86225 +_003289_hash tsi148_alloc_resource 2 24563 _003289_hash NULL
86226 +_003290_hash vb2_vmalloc_get_userptr 3 31374 _003290_hash NULL
86227 +_003291_hash xlate_dev_mem_ptr 1 15291 _003291_hash &_001167_hash
86228 +_003292_hash a4t_cs_init 3 27734 _003292_hash NULL
86229 +_003293_hash aac_nark_ioremap 2 50163 _003293_hash &_000314_hash
86230 +_003294_hash aac_rkt_ioremap 2 3333 _003294_hash NULL
86231 +_003295_hash aac_rx_ioremap 2 52410 _003295_hash NULL
86232 +_003296_hash aac_sa_ioremap 2 13596 _003296_hash &_000288_hash
86233 +_003297_hash aac_src_ioremap 2 41688 _003297_hash NULL
86234 +_003298_hash aac_srcv_ioremap 2 6659 _003298_hash NULL
86235 +_003299_hash acpi_map 1-2 58725 _003299_hash NULL
86236 +_003301_hash acpi_os_read_memory 1-3 54186 _003301_hash NULL
86237 +_003302_hash acpi_os_write_memory 1-3 56416 _003302_hash &_003262_hash
86238 +_003303_hash c101_run 2 37279 _003303_hash NULL
86239 +_003304_hash ca91cx42_master_set 4 23146 _003304_hash NULL
86240 +_003305_hash check586 2 29914 _003305_hash NULL
86241 +_003306_hash check_mirror 1-2 57342 _003306_hash &_001564_hash
86242 +_003308_hash cru_detect 1 11272 _003308_hash NULL
86243 +_003309_hash cs553x_init_one 3 58886 _003309_hash NULL
86244 +_003310_hash cycx_setup 4 47562 _003310_hash NULL
86245 +_003311_hash DepcaSignature 2 80 _003311_hash &_001321_hash
86246 +_003312_hash devm_ioremap 2-3 29235 _003312_hash NULL
86247 +_003314_hash divasa_remap_pci_bar 3-4 23485 _003314_hash &_000947_hash
86248 +_003316_hash dma_declare_coherent_memory 2-4 14244 _003316_hash NULL
86249 +_003318_hash doc_probe 1 23285 _003318_hash NULL
86250 +_003319_hash DoC_Probe 1 57534 _003319_hash NULL
86251 +_003320_hash ems_pcmcia_add_card 2 62627 _003320_hash NULL
86252 +_003321_hash gdth_init_isa 1 28091 _003321_hash NULL
86253 +_003322_hash gdth_search_isa 1 58595 _003322_hash NULL
86254 +_003323_hash isp1760_register 1-2 628 _003323_hash NULL
86255 +_003325_hash mthca_map_reg 2-3 5664 _003325_hash NULL
86256 +_003327_hash n2_run 3 53459 _003327_hash NULL
86257 +_003328_hash pcim_iomap 3 58334 _003328_hash NULL
86258 +_003329_hash probe_bios 1 17467 _003329_hash NULL
86259 +_003330_hash register_device 2-3 60015 _003330_hash NULL
86260 +_003332_hash remap_pci_mem 1-2 15966 _003332_hash NULL
86261 +_003334_hash rtl_port_map 1-2 2385 _003334_hash NULL
86262 +_003336_hash sfi_map_table 1 5462 _003336_hash NULL
86263 +_003337_hash sriov_enable_migration 2 14889 _003337_hash NULL
86264 +_003338_hash ssb_bus_scan 2 36578 _003338_hash NULL
86265 +_003339_hash ssb_ioremap 2 5228 _003339_hash NULL
86266 +_003340_hash tpm_tis_init 2-3 15304 _003340_hash NULL
86267 +_003342_hash tsi148_master_set 4 14685 _003342_hash NULL
86268 +_003343_hash acpi_os_map_memory 1-2 11161 _003343_hash NULL
86269 +_003345_hash com90xx_found 3 13974 _003345_hash NULL
86270 +_003346_hash dmam_declare_coherent_memory 2-4 43679 _003346_hash NULL
86271 +_003348_hash gdth_isa_probe_one 1 48925 _003348_hash NULL
86272 +_003349_hash sfi_check_table 1 6772 _003349_hash NULL
86273 +_003350_hash sfi_sysfs_install_table 1 51688 _003350_hash NULL
86274 +_003351_hash sriov_enable 2 59689 _003351_hash NULL
86275 +_003352_hash ssb_bus_register 3 65183 _003352_hash NULL
86276 +_003353_hash acpi_ex_system_memory_space_handler 2 31192 _003353_hash NULL
86277 +_003354_hash acpi_tb_check_xsdt 1 21862 _003354_hash NULL
86278 +_003355_hash acpi_tb_install_table 1 12988 _003355_hash NULL
86279 +_003356_hash acpi_tb_parse_root_table 1 53455 _003356_hash NULL
86280 +_003357_hash check_vendor_extension 1 3254 _003357_hash NULL
86281 +_003358_hash pci_enable_sriov 2 35745 _003358_hash NULL
86282 +_003359_hash ssb_bus_pcmciabus_register 3 56020 _003359_hash NULL
86283 +_003360_hash ssb_bus_ssbbus_register 2 2217 _003360_hash NULL
86284 +_003361_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003361_hash NULL
86285 +_003364_hash alloc_vm_area 1 15989 _003364_hash NULL
86286 +_003366_hash efi_ioremap 1-2 3492 _003366_hash &_001092_hash
86287 +_003368_hash init_chip_wc_pat 2 62768 _003368_hash NULL
86288 +_003369_hash io_mapping_create_wc 1-2 1354 _003369_hash NULL
86289 +_003371_hash iommu_map_mmio_space 1 30919 _003371_hash NULL
86290 +_003372_hash arch_gnttab_map_shared 3 41306 _003372_hash NULL
86291 +_003373_hash arch_gnttab_map_status 3 49812 _003373_hash NULL
86292 +_003374_hash intel_render_ring_init_dri 2-3 45446 _003374_hash NULL
86293 +_003376_hash persistent_ram_iomap 1-2 47156 _003376_hash NULL
86294 +_003378_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _003378_hash NULL
86295 +_003379_hash ttm_bo_ioremap 2-3 31082 _003379_hash NULL
86296 +_003381_hash ttm_bo_kmap_ttm 3 5922 _003381_hash NULL
86297 +_003382_hash atyfb_setup_generic 3 49151 _003382_hash NULL
86298 +_003383_hash do_test 1 15766 _003383_hash NULL
86299 +_003384_hash mga_ioremap 1-2 8571 _003384_hash NULL
86300 +_003386_hash mid_get_vbt_data_r0 2 10876 _003386_hash NULL
86301 +_003387_hash mid_get_vbt_data_r10 2 6308 _003387_hash NULL
86302 +_003388_hash mid_get_vbt_data_r1 2 26170 _003388_hash NULL
86303 +_003389_hash persistent_ram_buffer_map 1-2 11332 _003389_hash NULL
86304 +_003391_hash read_vbt_r0 1 503 _003391_hash NULL
86305 +_003392_hash read_vbt_r10 1 60679 _003392_hash NULL
86306 +_003393_hash tpci200_slot_map_space 2 3848 _003393_hash NULL
86307 +_003394_hash ttm_bo_kmap 2-3 60118 _003394_hash NULL
86308 +_003395_hash persistent_ram_new 1-2 14588 _003395_hash NULL
86309 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
86310 new file mode 100644
86311 index 0000000..e9310fa
86312 --- /dev/null
86313 +++ b/tools/gcc/size_overflow_plugin.c
86314 @@ -0,0 +1,1612 @@
86315 +/*
86316 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
86317 + * Licensed under the GPL v2, or (at your option) v3
86318 + *
86319 + * Homepage:
86320 + * http://www.grsecurity.net/~ephox/overflow_plugin/
86321 + *
86322 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
86323 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
86324 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
86325 + *
86326 + * Usage:
86327 + * $ 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
86328 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
86329 + */
86330 +
86331 +#include "gcc-plugin.h"
86332 +#include "config.h"
86333 +#include "system.h"
86334 +#include "coretypes.h"
86335 +#include "tree.h"
86336 +#include "tree-pass.h"
86337 +#include "intl.h"
86338 +#include "plugin-version.h"
86339 +#include "tm.h"
86340 +#include "toplev.h"
86341 +#include "function.h"
86342 +#include "tree-flow.h"
86343 +#include "plugin.h"
86344 +#include "gimple.h"
86345 +#include "c-common.h"
86346 +#include "diagnostic.h"
86347 +#include "cfgloop.h"
86348 +
86349 +struct size_overflow_hash {
86350 + const struct size_overflow_hash * const next;
86351 + const char * const name;
86352 + const unsigned int param;
86353 +};
86354 +
86355 +#include "size_overflow_hash.h"
86356 +
86357 +#define __unused __attribute__((__unused__))
86358 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
86359 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
86360 +#define BEFORE_STMT true
86361 +#define AFTER_STMT false
86362 +#define CREATE_NEW_VAR NULL_TREE
86363 +#define CODES_LIMIT 32
86364 +#define MAX_PARAM 10
86365 +#define MY_STMT GF_PLF_1
86366 +#define NO_CAST_CHECK GF_PLF_2
86367 +
86368 +#if BUILDING_GCC_VERSION == 4005
86369 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
86370 +#endif
86371 +
86372 +int plugin_is_GPL_compatible;
86373 +void debug_gimple_stmt(gimple gs);
86374 +
86375 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs);
86376 +static tree report_size_overflow_decl;
86377 +static const_tree const_char_ptr_type_node;
86378 +static unsigned int handle_function(void);
86379 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before);
86380 +static tree get_size_overflow_type(gimple stmt, tree node);
86381 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
86382 +
86383 +static struct plugin_info size_overflow_plugin_info = {
86384 + .version = "20120820beta",
86385 + .help = "no-size-overflow\tturn off size overflow checking\n",
86386 +};
86387 +
86388 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
86389 +{
86390 + unsigned int arg_count;
86391 +
86392 + if (TREE_CODE(*node) == FUNCTION_DECL)
86393 + arg_count = type_num_arguments(TREE_TYPE(*node));
86394 + else if (TREE_CODE(*node) == FUNCTION_TYPE || TREE_CODE(*node) == METHOD_TYPE)
86395 + arg_count = type_num_arguments(*node);
86396 + else {
86397 + *no_add_attrs = true;
86398 + error("%qE attribute only applies to functions", name);
86399 + return NULL_TREE;
86400 + }
86401 +
86402 + for (; args; args = TREE_CHAIN(args)) {
86403 + tree position = TREE_VALUE(args);
86404 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
86405 + error("handle_size_overflow_attribute: overflow parameter outside range.");
86406 + *no_add_attrs = true;
86407 + }
86408 + }
86409 + return NULL_TREE;
86410 +}
86411 +
86412 +static struct attribute_spec size_overflow_attr = {
86413 + .name = "size_overflow",
86414 + .min_length = 1,
86415 + .max_length = -1,
86416 + .decl_required = true,
86417 + .type_required = false,
86418 + .function_type_required = false,
86419 + .handler = handle_size_overflow_attribute,
86420 +#if BUILDING_GCC_VERSION >= 4007
86421 + .affects_type_identity = false
86422 +#endif
86423 +};
86424 +
86425 +static void register_attributes(void __unused *event_data, void __unused *data)
86426 +{
86427 + register_attribute(&size_overflow_attr);
86428 +}
86429 +
86430 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
86431 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
86432 +{
86433 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
86434 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
86435 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
86436 +
86437 + unsigned int m = 0x57559429;
86438 + unsigned int n = 0x5052acdb;
86439 + const unsigned int *key4 = (const unsigned int *)key;
86440 + unsigned int h = len;
86441 + unsigned int k = len + seed + n;
86442 + unsigned long long p;
86443 +
86444 + while (len >= 8) {
86445 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
86446 + len -= 8;
86447 + }
86448 + if (len >= 4) {
86449 + cwmixb(key4[0]) key4 += 1;
86450 + len -= 4;
86451 + }
86452 + if (len)
86453 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
86454 + cwmixb(h ^ (k + n));
86455 + return k ^ h;
86456 +
86457 +#undef cwfold
86458 +#undef cwmixa
86459 +#undef cwmixb
86460 +}
86461 +
86462 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
86463 +{
86464 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
86465 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
86466 + return fn ^ codes;
86467 +}
86468 +
86469 +static inline const_tree get_original_function_decl(const_tree fndecl)
86470 +{
86471 + if (DECL_ABSTRACT_ORIGIN(fndecl))
86472 + return DECL_ABSTRACT_ORIGIN(fndecl);
86473 + return fndecl;
86474 +}
86475 +
86476 +static inline gimple get_def_stmt(const_tree node)
86477 +{
86478 + gcc_assert(node != NULL_TREE);
86479 + gcc_assert(TREE_CODE(node) == SSA_NAME);
86480 + return SSA_NAME_DEF_STMT(node);
86481 +}
86482 +
86483 +static unsigned char get_tree_code(tree type)
86484 +{
86485 + switch (TREE_CODE(type)) {
86486 + case ARRAY_TYPE:
86487 + return 0;
86488 + case BOOLEAN_TYPE:
86489 + return 1;
86490 + case ENUMERAL_TYPE:
86491 + return 2;
86492 + case FUNCTION_TYPE:
86493 + return 3;
86494 + case INTEGER_TYPE:
86495 + return 4;
86496 + case POINTER_TYPE:
86497 + return 5;
86498 + case RECORD_TYPE:
86499 + return 6;
86500 + case UNION_TYPE:
86501 + return 7;
86502 + case VOID_TYPE:
86503 + return 8;
86504 + case REAL_TYPE:
86505 + return 9;
86506 + case VECTOR_TYPE:
86507 + return 10;
86508 + case REFERENCE_TYPE:
86509 + return 11;
86510 + default:
86511 + debug_tree(type);
86512 + gcc_unreachable();
86513 + }
86514 +}
86515 +
86516 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
86517 +{
86518 + gcc_assert(type != NULL_TREE);
86519 +
86520 + while (type && len < CODES_LIMIT) {
86521 + tree_codes[len] = get_tree_code(type);
86522 + len++;
86523 + type = TREE_TYPE(type);
86524 + }
86525 + return len;
86526 +}
86527 +
86528 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
86529 +{
86530 + tree arg;
86531 + const_tree result, type = TREE_TYPE(fndecl);
86532 + enum tree_code code = TREE_CODE(type);
86533 + size_t len = 0;
86534 +
86535 + gcc_assert(code == FUNCTION_TYPE);
86536 +
86537 + arg = TYPE_ARG_TYPES(type);
86538 + // skip builtins __builtin_constant_p
86539 + if (!arg && DECL_BUILT_IN(fndecl))
86540 + return 0;
86541 + gcc_assert(arg != NULL_TREE);
86542 +
86543 + if (TREE_CODE_CLASS(code) == tcc_type)
86544 + result = type;
86545 + else
86546 + result = DECL_RESULT(fndecl);
86547 +
86548 + gcc_assert(result != NULL_TREE);
86549 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
86550 +
86551 + while (arg && len < CODES_LIMIT) {
86552 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
86553 + arg = TREE_CHAIN(arg);
86554 + }
86555 +
86556 + gcc_assert(len != 0);
86557 + return len;
86558 +}
86559 +
86560 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
86561 +{
86562 + unsigned int hash;
86563 + const struct size_overflow_hash *entry;
86564 + unsigned char tree_codes[CODES_LIMIT];
86565 + size_t len;
86566 + const char *func_name = NAME(fndecl);
86567 +
86568 + len = get_function_decl(fndecl, tree_codes);
86569 + if (len == 0)
86570 + return NULL;
86571 +
86572 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
86573 +
86574 + entry = size_overflow_hash[hash];
86575 + while (entry) {
86576 + if (!strcmp(entry->name, func_name))
86577 + return entry;
86578 + entry = entry->next;
86579 + }
86580 +
86581 + return NULL;
86582 +}
86583 +
86584 +static void check_arg_type(const_tree arg)
86585 +{
86586 + const_tree type = TREE_TYPE(arg);
86587 + enum tree_code code = TREE_CODE(type);
86588 +
86589 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
86590 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
86591 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
86592 +}
86593 +
86594 +static int find_arg_number(const_tree arg, const_tree func)
86595 +{
86596 + tree var;
86597 + bool match = false;
86598 + unsigned int argnum = 1;
86599 +
86600 + if (TREE_CODE(arg) == SSA_NAME)
86601 + arg = SSA_NAME_VAR(arg);
86602 +
86603 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
86604 + if (strcmp(NAME(arg), NAME(var))) {
86605 + argnum++;
86606 + continue;
86607 + }
86608 + check_arg_type(var);
86609 +
86610 + match = true;
86611 + break;
86612 + }
86613 + if (!match) {
86614 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
86615 + return 0;
86616 + }
86617 + return argnum;
86618 +}
86619 +
86620 +static void print_missing_msg(const_tree func, unsigned int argnum)
86621 +{
86622 + unsigned int new_hash;
86623 + size_t len;
86624 + unsigned char tree_codes[CODES_LIMIT];
86625 + location_t loc = DECL_SOURCE_LOCATION(func);
86626 + const char *curfunc = NAME(func);
86627 +
86628 + len = get_function_decl(func, tree_codes);
86629 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
86630 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
86631 +}
86632 +
86633 +static void check_missing_attribute(const_tree arg)
86634 +{
86635 + const_tree type = TREE_TYPE(arg);
86636 + const_tree func = get_original_function_decl(current_function_decl);
86637 + unsigned int argnum;
86638 + const struct size_overflow_hash *hash;
86639 +
86640 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
86641 +
86642 + if (TREE_CODE(type) == POINTER_TYPE)
86643 + return;
86644 +
86645 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
86646 + return;
86647 +
86648 + argnum = find_arg_number(arg, func);
86649 + if (argnum == 0)
86650 + return;
86651 +
86652 + hash = get_function_hash(func);
86653 + if (!hash || !(hash->param & (1U << argnum)))
86654 + print_missing_msg(func, argnum);
86655 +}
86656 +
86657 +static tree create_new_var(tree type)
86658 +{
86659 + tree new_var = create_tmp_var(type, "cicus");
86660 +
86661 + add_referenced_var(new_var);
86662 + mark_sym_for_renaming(new_var);
86663 + return new_var;
86664 +}
86665 +
86666 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
86667 +{
86668 + gimple assign;
86669 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86670 + tree type = TREE_TYPE(rhs1);
86671 + tree lhs = create_new_var(type);
86672 +
86673 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
86674 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
86675 +
86676 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86677 + update_stmt(assign);
86678 + gimple_set_plf(assign, MY_STMT, true);
86679 + return assign;
86680 +}
86681 +
86682 +static bool is_bool(const_tree node)
86683 +{
86684 + const_tree type;
86685 +
86686 + if (node == NULL_TREE)
86687 + return false;
86688 +
86689 + type = TREE_TYPE(node);
86690 + if (!INTEGRAL_TYPE_P(type))
86691 + return false;
86692 + if (TREE_CODE(type) == BOOLEAN_TYPE)
86693 + return true;
86694 + if (TYPE_PRECISION(type) == 1)
86695 + return true;
86696 + return false;
86697 +}
86698 +
86699 +static tree cast_a_tree(tree type, tree var)
86700 +{
86701 + gcc_assert(type != NULL_TREE);
86702 + gcc_assert(var != NULL_TREE);
86703 + gcc_assert(fold_convertible_p(type, var));
86704 +
86705 + return fold_convert(type, var);
86706 +}
86707 +
86708 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
86709 +{
86710 + gimple assign;
86711 +
86712 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
86713 + if (gsi_end_p(*gsi) && before == BEFORE_STMT)
86714 + gcc_unreachable();
86715 +
86716 + if (lhs == CREATE_NEW_VAR)
86717 + lhs = create_new_var(dst_type);
86718 +
86719 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
86720 +
86721 + if (!gsi_end_p(*gsi)) {
86722 + location_t loc = gimple_location(gsi_stmt(*gsi));
86723 + gimple_set_location(assign, loc);
86724 + }
86725 +
86726 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
86727 +
86728 + if (before)
86729 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
86730 + else
86731 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
86732 + update_stmt(assign);
86733 + gimple_set_plf(assign, MY_STMT, true);
86734 +
86735 + return assign;
86736 +}
86737 +
86738 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
86739 +{
86740 + const_gimple assign;
86741 + gimple_stmt_iterator gsi;
86742 +
86743 + if (new_rhs1 == NULL_TREE)
86744 + return NULL_TREE;
86745 +
86746 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
86747 + gsi = gsi_for_stmt(stmt);
86748 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
86749 + return gimple_get_lhs(assign);
86750 + }
86751 + return new_rhs1;
86752 +}
86753 +
86754 +static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
86755 +{
86756 + tree size_overflow_type = get_size_overflow_type(stmt, node);
86757 +
86758 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
86759 +
86760 + if (new_rhs2 != NULL_TREE)
86761 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
86762 +
86763 + if (new_rhs3 != NULL_TREE)
86764 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
86765 +
86766 + return dup_assign(visited, potentionally_overflowed, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
86767 +}
86768 +
86769 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
86770 +{
86771 + const_tree oldstmt_rhs1;
86772 + tree size_overflow_type, lhs;
86773 + enum tree_code code;
86774 + gimple stmt;
86775 + gimple_stmt_iterator gsi;
86776 +
86777 + if (!*potentionally_overflowed)
86778 + return NULL_TREE;
86779 +
86780 + if (rhs1 == NULL_TREE) {
86781 + debug_gimple_stmt(oldstmt);
86782 + error("create_assign: rhs1 is NULL_TREE");
86783 + gcc_unreachable();
86784 + }
86785 +
86786 + if (gimple_code(oldstmt) == GIMPLE_ASM)
86787 + lhs = rhs1;
86788 + else
86789 + lhs = gimple_get_lhs(oldstmt);
86790 +
86791 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
86792 + code = TREE_CODE(oldstmt_rhs1);
86793 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
86794 + check_missing_attribute(oldstmt_rhs1);
86795 +
86796 + gsi = gsi_for_stmt(oldstmt);
86797 + pointer_set_insert(visited, oldstmt);
86798 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
86799 + basic_block next_bb, cur_bb;
86800 + const_edge e;
86801 +
86802 + gcc_assert(before == false);
86803 + gcc_assert(stmt_can_throw_internal(oldstmt));
86804 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
86805 + gcc_assert(!gsi_end_p(gsi));
86806 +
86807 + cur_bb = gimple_bb(oldstmt);
86808 + next_bb = cur_bb->next_bb;
86809 + e = find_edge(cur_bb, next_bb);
86810 + gcc_assert(e != NULL);
86811 + gcc_assert(e->flags & EDGE_FALLTHRU);
86812 +
86813 + gsi = gsi_after_labels(next_bb);
86814 + gcc_assert(!gsi_end_p(gsi));
86815 +
86816 + before = true;
86817 + oldstmt = gsi_stmt(gsi);
86818 + pointer_set_insert(visited, oldstmt);
86819 + }
86820 +
86821 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
86822 +
86823 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
86824 + gimple_set_plf(stmt, MY_STMT, true);
86825 + return gimple_get_lhs(stmt);
86826 +}
86827 +
86828 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
86829 +{
86830 + gimple stmt;
86831 + gimple_stmt_iterator gsi;
86832 + tree new_var, lhs = gimple_get_lhs(oldstmt);
86833 +
86834 + if (!*potentionally_overflowed)
86835 + return NULL_TREE;
86836 +
86837 + if (gimple_plf(oldstmt, MY_STMT))
86838 + return lhs;
86839 +
86840 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
86841 + rhs1 = gimple_assign_rhs1(oldstmt);
86842 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
86843 + }
86844 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
86845 + rhs2 = gimple_assign_rhs2(oldstmt);
86846 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
86847 + }
86848 +
86849 + stmt = gimple_copy(oldstmt);
86850 + gimple_set_location(stmt, gimple_location(oldstmt));
86851 + gimple_set_plf(stmt, MY_STMT, true);
86852 +
86853 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
86854 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
86855 +
86856 + if (is_bool(lhs))
86857 + new_var = SSA_NAME_VAR(lhs);
86858 + else
86859 + new_var = create_new_var(size_overflow_type);
86860 + new_var = make_ssa_name(new_var, stmt);
86861 + gimple_set_lhs(stmt, new_var);
86862 +
86863 + if (rhs1 != NULL_TREE) {
86864 + if (!gimple_assign_cast_p(oldstmt))
86865 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
86866 + gimple_assign_set_rhs1(stmt, rhs1);
86867 + }
86868 +
86869 + if (rhs2 != NULL_TREE)
86870 + gimple_assign_set_rhs2(stmt, rhs2);
86871 +#if BUILDING_GCC_VERSION >= 4007
86872 + if (rhs3 != NULL_TREE)
86873 + gimple_assign_set_rhs3(stmt, rhs3);
86874 +#endif
86875 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
86876 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
86877 +
86878 + gsi = gsi_for_stmt(oldstmt);
86879 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
86880 + update_stmt(stmt);
86881 + pointer_set_insert(visited, oldstmt);
86882 + return gimple_get_lhs(stmt);
86883 +}
86884 +
86885 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
86886 +{
86887 + basic_block bb;
86888 + gimple phi;
86889 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
86890 +
86891 + bb = gsi_bb(gsi);
86892 +
86893 + phi = create_phi_node(result, bb);
86894 + gsi = gsi_last(phi_nodes(bb));
86895 + gsi_remove(&gsi, false);
86896 +
86897 + gsi = gsi_for_stmt(oldstmt);
86898 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
86899 + gimple_set_bb(phi, bb);
86900 + gimple_set_plf(phi, MY_STMT, true);
86901 + return phi;
86902 +}
86903 +
86904 +static basic_block create_a_first_bb(void)
86905 +{
86906 + basic_block first_bb;
86907 +
86908 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86909 + if (dom_info_available_p(CDI_DOMINATORS))
86910 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
86911 + return first_bb;
86912 +}
86913 +
86914 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
86915 +{
86916 + basic_block bb;
86917 + const_gimple newstmt;
86918 + gimple_stmt_iterator gsi;
86919 + bool before = BEFORE_STMT;
86920 +
86921 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
86922 + gsi = gsi_for_stmt(get_def_stmt(arg));
86923 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
86924 + return gimple_get_lhs(newstmt);
86925 + }
86926 +
86927 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
86928 + gsi = gsi_after_labels(bb);
86929 + if (bb->index == 0) {
86930 + bb = create_a_first_bb();
86931 + gsi = gsi_start_bb(bb);
86932 + }
86933 + if (gsi_end_p(gsi))
86934 + before = AFTER_STMT;
86935 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
86936 + return gimple_get_lhs(newstmt);
86937 +}
86938 +
86939 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
86940 +{
86941 + gimple newstmt;
86942 + gimple_stmt_iterator gsi;
86943 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
86944 + gimple def_newstmt = get_def_stmt(new_rhs);
86945 +
86946 + gsi_insert = gsi_insert_after;
86947 + gsi = gsi_for_stmt(def_newstmt);
86948 +
86949 + switch (gimple_code(get_def_stmt(arg))) {
86950 + case GIMPLE_PHI:
86951 + newstmt = gimple_build_assign(new_var, new_rhs);
86952 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
86953 + gsi_insert = gsi_insert_before;
86954 + break;
86955 + case GIMPLE_ASM:
86956 + case GIMPLE_CALL:
86957 + newstmt = gimple_build_assign(new_var, new_rhs);
86958 + break;
86959 + case GIMPLE_ASSIGN:
86960 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
86961 + break;
86962 + default:
86963 + /* unknown gimple_code (handle_build_new_phi_arg) */
86964 + gcc_unreachable();
86965 + }
86966 +
86967 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
86968 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
86969 + gimple_set_plf(newstmt, MY_STMT, true);
86970 + update_stmt(newstmt);
86971 + return newstmt;
86972 +}
86973 +
86974 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree arg, tree new_var)
86975 +{
86976 + const_gimple newstmt;
86977 + tree new_rhs;
86978 +
86979 + new_rhs = expand(visited, potentionally_overflowed, arg);
86980 + if (new_rhs == NULL_TREE)
86981 + return NULL_TREE;
86982 +
86983 + new_rhs = cast_to_new_size_overflow_type(get_def_stmt(new_rhs), new_rhs, size_overflow_type, AFTER_STMT);
86984 +
86985 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
86986 + return gimple_get_lhs(newstmt);
86987 +}
86988 +
86989 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, tree orig_result)
86990 +{
86991 + gimple phi, oldstmt = get_def_stmt(orig_result);
86992 + tree new_result, size_overflow_type;
86993 + unsigned int i;
86994 + unsigned int n = gimple_phi_num_args(oldstmt);
86995 +
86996 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
86997 +
86998 + new_result = create_new_var(size_overflow_type);
86999 +
87000 + pointer_set_insert(visited, oldstmt);
87001 + phi = overflow_create_phi_node(oldstmt, new_result);
87002 + for (i = 0; i < n; i++) {
87003 + tree arg, lhs;
87004 +
87005 + arg = gimple_phi_arg_def(oldstmt, i);
87006 + if (is_gimple_constant(arg))
87007 + arg = cast_a_tree(size_overflow_type, arg);
87008 + lhs = build_new_phi_arg(visited, potentionally_overflowed, size_overflow_type, arg, new_result);
87009 + if (lhs == NULL_TREE)
87010 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
87011 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
87012 + }
87013 +
87014 + update_stmt(phi);
87015 + return gimple_phi_result(phi);
87016 +}
87017 +
87018 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
87019 +{
87020 + const_gimple assign;
87021 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87022 + tree origtype = TREE_TYPE(orig_rhs);
87023 +
87024 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
87025 +
87026 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87027 + return gimple_get_lhs(assign);
87028 +}
87029 +
87030 +static void change_rhs1(gimple stmt, tree new_rhs1)
87031 +{
87032 + tree assign_rhs;
87033 + const_tree rhs = gimple_assign_rhs1(stmt);
87034 +
87035 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
87036 + gimple_assign_set_rhs1(stmt, assign_rhs);
87037 + update_stmt(stmt);
87038 +}
87039 +
87040 +static bool check_mode_type(const_gimple stmt)
87041 +{
87042 + const_tree lhs = gimple_get_lhs(stmt);
87043 + const_tree lhs_type = TREE_TYPE(lhs);
87044 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
87045 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
87046 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
87047 +
87048 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
87049 + return false;
87050 +
87051 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
87052 + return false;
87053 +
87054 + return true;
87055 +}
87056 +
87057 +static bool check_undefined_integer_operation(const_gimple stmt)
87058 +{
87059 + const_gimple def_stmt;
87060 + const_tree lhs = gimple_get_lhs(stmt);
87061 + const_tree rhs1 = gimple_assign_rhs1(stmt);
87062 + const_tree rhs1_type = TREE_TYPE(rhs1);
87063 + const_tree lhs_type = TREE_TYPE(lhs);
87064 +
87065 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
87066 + return false;
87067 +
87068 + def_stmt = get_def_stmt(rhs1);
87069 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
87070 + return false;
87071 +
87072 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
87073 + return false;
87074 + return true;
87075 +}
87076 +
87077 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
87078 +{
87079 + const_tree rhs1, lhs, rhs1_type, lhs_type;
87080 + enum machine_mode lhs_mode, rhs_mode;
87081 + gimple def_stmt = get_def_stmt(no_const_rhs);
87082 +
87083 + if (!gimple_assign_cast_p(def_stmt))
87084 + return false;
87085 +
87086 + rhs1 = gimple_assign_rhs1(def_stmt);
87087 + lhs = gimple_get_lhs(def_stmt);
87088 + rhs1_type = TREE_TYPE(rhs1);
87089 + lhs_type = TREE_TYPE(lhs);
87090 + rhs_mode = TYPE_MODE(rhs1_type);
87091 + lhs_mode = TYPE_MODE(lhs_type);
87092 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
87093 + return false;
87094 +
87095 + return true;
87096 +}
87097 +
87098 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt)
87099 +{
87100 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
87101 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
87102 + const_tree rhs1_type = TREE_TYPE(rhs1);
87103 + const_tree lhs_type = TREE_TYPE(lhs);
87104 +
87105 + *potentionally_overflowed = true;
87106 +
87107 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
87108 +
87109 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
87110 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87111 +
87112 + if (gimple_plf(stmt, MY_STMT))
87113 + return lhs;
87114 +
87115 + if (gimple_plf(stmt, NO_CAST_CHECK))
87116 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
87117 +
87118 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
87119 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
87120 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87121 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
87122 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87123 + }
87124 +
87125 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
87126 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
87127 +
87128 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
87129 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87130 +
87131 + change_rhs1(stmt, new_rhs1);
87132 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, potentionally_overflowed, BEFORE_STMT);
87133 +
87134 + rhs1 = gimple_assign_rhs1(stmt);
87135 + rhs1_type = TREE_TYPE(rhs1);
87136 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
87137 + return create_assign(visited, potentionally_overflowed, stmt, rhs1, AFTER_STMT);
87138 +
87139 + if (!check_mode_type(stmt))
87140 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87141 +
87142 + size_overflow_type = get_size_overflow_type(stmt, lhs);
87143 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87144 +
87145 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, potentionally_overflowed, BEFORE_STMT);
87146 +
87147 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87148 +}
87149 +
87150 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87151 +{
87152 + gimple def_stmt = get_def_stmt(lhs);
87153 + tree rhs1 = gimple_assign_rhs1(def_stmt);
87154 +
87155 + if (is_gimple_constant(rhs1))
87156 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87157 +
87158 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
87159 + switch (TREE_CODE(rhs1)) {
87160 + case SSA_NAME:
87161 + return handle_unary_rhs(visited, potentionally_overflowed, def_stmt);
87162 + case ARRAY_REF:
87163 + case BIT_FIELD_REF:
87164 + case ADDR_EXPR:
87165 + case COMPONENT_REF:
87166 + case INDIRECT_REF:
87167 +#if BUILDING_GCC_VERSION >= 4006
87168 + case MEM_REF:
87169 +#endif
87170 + case PARM_DECL:
87171 + case TARGET_MEM_REF:
87172 + case VAR_DECL:
87173 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87174 +
87175 + default:
87176 + debug_gimple_stmt(def_stmt);
87177 + debug_tree(rhs1);
87178 + gcc_unreachable();
87179 + }
87180 +}
87181 +
87182 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
87183 +{
87184 + gimple cond_stmt;
87185 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
87186 +
87187 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
87188 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
87189 + update_stmt(cond_stmt);
87190 +}
87191 +
87192 +static tree create_string_param(tree string)
87193 +{
87194 + tree i_type, a_type;
87195 + const int length = TREE_STRING_LENGTH(string);
87196 +
87197 + gcc_assert(length > 0);
87198 +
87199 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
87200 + a_type = build_array_type(char_type_node, i_type);
87201 +
87202 + TREE_TYPE(string) = a_type;
87203 + TREE_CONSTANT(string) = 1;
87204 + TREE_READONLY(string) = 1;
87205 +
87206 + return build1(ADDR_EXPR, ptr_type_node, string);
87207 +}
87208 +
87209 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
87210 +{
87211 + gimple func_stmt;
87212 + const_gimple def_stmt;
87213 + const_tree loc_line;
87214 + tree loc_file, ssa_name, current_func;
87215 + expanded_location xloc;
87216 + char ssa_name_buf[256];
87217 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
87218 +
87219 + def_stmt = get_def_stmt(arg);
87220 + xloc = expand_location(gimple_location(def_stmt));
87221 +
87222 + if (!gimple_has_location(def_stmt)) {
87223 + xloc = expand_location(gimple_location(stmt));
87224 + if (!gimple_has_location(stmt))
87225 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
87226 + }
87227 +
87228 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
87229 +
87230 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
87231 + loc_file = create_string_param(loc_file);
87232 +
87233 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
87234 + current_func = create_string_param(current_func);
87235 +
87236 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
87237 + ssa_name = build_string(256, ssa_name_buf);
87238 + ssa_name = create_string_param(ssa_name);
87239 +
87240 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
87241 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
87242 +
87243 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
87244 +}
87245 +
87246 +static void __unused print_the_code_insertions(const_gimple stmt)
87247 +{
87248 + location_t loc = gimple_location(stmt);
87249 +
87250 + inform(loc, "Integer size_overflow check applied here.");
87251 +}
87252 +
87253 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
87254 +{
87255 + basic_block cond_bb, join_bb, bb_true;
87256 + edge e;
87257 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87258 +
87259 + cond_bb = gimple_bb(stmt);
87260 + if (before)
87261 + gsi_prev(&gsi);
87262 + if (gsi_end_p(gsi))
87263 + e = split_block_after_labels(cond_bb);
87264 + else
87265 + e = split_block(cond_bb, gsi_stmt(gsi));
87266 + cond_bb = e->src;
87267 + join_bb = e->dest;
87268 + e->flags = EDGE_FALSE_VALUE;
87269 + e->probability = REG_BR_PROB_BASE;
87270 +
87271 + bb_true = create_empty_bb(cond_bb);
87272 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
87273 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
87274 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
87275 +
87276 + if (dom_info_available_p(CDI_DOMINATORS)) {
87277 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
87278 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
87279 + }
87280 +
87281 + if (current_loops != NULL) {
87282 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
87283 + add_bb_to_loop(bb_true, cond_bb->loop_father);
87284 + }
87285 +
87286 + insert_cond(cond_bb, arg, cond_code, type_value);
87287 + insert_cond_result(bb_true, stmt, arg, min);
87288 +
87289 +// print_the_code_insertions(stmt);
87290 +}
87291 +
87292 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool *potentionally_overflowed, bool before)
87293 +{
87294 + const_tree rhs_type = TREE_TYPE(rhs);
87295 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
87296 +
87297 + gcc_assert(rhs_type != NULL_TREE);
87298 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
87299 +
87300 + if (!*potentionally_overflowed)
87301 + return;
87302 +
87303 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
87304 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
87305 +
87306 + gcc_assert(!TREE_OVERFLOW(type_max));
87307 +
87308 + cast_rhs_type = TREE_TYPE(cast_rhs);
87309 + type_max_type = TREE_TYPE(type_max);
87310 + type_min_type = TREE_TYPE(type_min);
87311 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
87312 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
87313 +
87314 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
87315 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
87316 +}
87317 +
87318 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
87319 +{
87320 + gimple change_rhs_def_stmt;
87321 + tree lhs = gimple_get_lhs(def_stmt);
87322 + tree lhs_type = TREE_TYPE(lhs);
87323 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
87324 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
87325 +
87326 + if (change_rhs == NULL_TREE)
87327 + return get_size_overflow_type(def_stmt, lhs);
87328 +
87329 + change_rhs_def_stmt = get_def_stmt(change_rhs);
87330 +
87331 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
87332 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
87333 +
87334 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
87335 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
87336 +
87337 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
87338 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
87339 +
87340 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
87341 + debug_gimple_stmt(def_stmt);
87342 + gcc_unreachable();
87343 + }
87344 +
87345 + return get_size_overflow_type(def_stmt, lhs);
87346 +}
87347 +
87348 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
87349 +{
87350 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
87351 + return false;
87352 + if (!is_gimple_constant(rhs))
87353 + return false;
87354 + return true;
87355 +}
87356 +
87357 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
87358 +{
87359 + gimple def_stmt;
87360 +
87361 + def_stmt = get_def_stmt(new_rhs);
87362 + // get_size_overflow_type
87363 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
87364 + gcc_assert(gimple_assign_cast_p(def_stmt));
87365 + return gimple_assign_rhs1(def_stmt);
87366 +}
87367 +
87368 +static tree cast_to_int_TI_type_and_check(bool *potentionally_overflowed, gimple stmt, tree new_rhs)
87369 +{
87370 + gimple_stmt_iterator gsi;
87371 + const_gimple cast_stmt;
87372 + gimple def_stmt;
87373 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
87374 +
87375 + if (mode != TImode && mode != DImode) {
87376 + def_stmt = get_def_stmt(new_rhs);
87377 + gcc_assert(gimple_assign_cast_p(def_stmt));
87378 + new_rhs = gimple_assign_rhs1(def_stmt);
87379 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
87380 + }
87381 +
87382 + gcc_assert(mode == TImode || mode == DImode);
87383 +
87384 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
87385 + return new_rhs;
87386 +
87387 + gsi = gsi_for_stmt(stmt);
87388 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87389 + new_rhs = gimple_get_lhs(cast_stmt);
87390 +
87391 + if (mode == DImode)
87392 + return new_rhs;
87393 +
87394 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, potentionally_overflowed, BEFORE_STMT);
87395 +
87396 + return new_rhs;
87397 +}
87398 +
87399 +static bool is_an_integer_trunction(const_gimple stmt)
87400 +{
87401 + gimple rhs1_def_stmt, rhs2_def_stmt;
87402 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
87403 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
87404 + const_tree rhs1 = gimple_assign_rhs1(stmt);
87405 + const_tree rhs2 = gimple_assign_rhs2(stmt);
87406 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
87407 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
87408 +
87409 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
87410 + return false;
87411 +
87412 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
87413 +
87414 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
87415 + return false;
87416 +
87417 + rhs1_def_stmt = get_def_stmt(rhs1);
87418 + rhs2_def_stmt = get_def_stmt(rhs2);
87419 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
87420 + return false;
87421 +
87422 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
87423 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
87424 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
87425 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
87426 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
87427 + return false;
87428 +
87429 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
87430 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
87431 + return true;
87432 +}
87433 +
87434 +static tree handle_integer_truncation(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87435 +{
87436 + tree new_rhs1, new_rhs2;
87437 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
87438 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
87439 + gimple assign, stmt = get_def_stmt(lhs);
87440 + tree rhs1 = gimple_assign_rhs1(stmt);
87441 + tree rhs2 = gimple_assign_rhs2(stmt);
87442 +
87443 + if (!is_an_integer_trunction(stmt))
87444 + return NULL_TREE;
87445 +
87446 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
87447 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
87448 +
87449 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
87450 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
87451 +
87452 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
87453 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
87454 +
87455 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
87456 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(potentionally_overflowed, stmt, new_rhs1_def_stmt_rhs1);
87457 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(potentionally_overflowed, stmt, new_rhs2_def_stmt_rhs1);
87458 + }
87459 +
87460 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
87461 + new_lhs = gimple_get_lhs(assign);
87462 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, potentionally_overflowed, AFTER_STMT);
87463 +
87464 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
87465 +}
87466 +
87467 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
87468 +{
87469 + const_gimple def_stmt;
87470 +
87471 + if (TREE_CODE(rhs) != SSA_NAME)
87472 + return false;
87473 +
87474 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
87475 + return false;
87476 +
87477 + def_stmt = get_def_stmt(rhs);
87478 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
87479 + return false;
87480 +
87481 + return true;
87482 +}
87483 +
87484 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool *potentionally_overflowed, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
87485 +{
87486 + tree new_rhs, size_overflow_type, orig_rhs;
87487 + void (*gimple_assign_set_rhs)(gimple, tree);
87488 + tree rhs1 = gimple_assign_rhs1(stmt);
87489 + tree rhs2 = gimple_assign_rhs2(stmt);
87490 + tree lhs = gimple_get_lhs(stmt);
87491 +
87492 + if (change_rhs == NULL_TREE)
87493 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87494 +
87495 + if (new_rhs2 == NULL_TREE) {
87496 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
87497 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
87498 + orig_rhs = rhs1;
87499 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
87500 + } else {
87501 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
87502 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
87503 + orig_rhs = rhs2;
87504 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
87505 + }
87506 +
87507 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
87508 +
87509 + if (check_overflow)
87510 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, potentionally_overflowed, BEFORE_STMT);
87511 +
87512 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
87513 + gimple_assign_set_rhs(stmt, new_rhs);
87514 + update_stmt(stmt);
87515 +
87516 + return create_assign(visited, potentionally_overflowed, stmt, lhs, AFTER_STMT);
87517 +}
87518 +
87519 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87520 +{
87521 + tree rhs1, rhs2, new_lhs;
87522 + gimple def_stmt = get_def_stmt(lhs);
87523 + tree new_rhs1 = NULL_TREE;
87524 + tree new_rhs2 = NULL_TREE;
87525 +
87526 + rhs1 = gimple_assign_rhs1(def_stmt);
87527 + rhs2 = gimple_assign_rhs2(def_stmt);
87528 +
87529 + /* no DImode/TImode division in the 32/64 bit kernel */
87530 + switch (gimple_assign_rhs_code(def_stmt)) {
87531 + case RDIV_EXPR:
87532 + case TRUNC_DIV_EXPR:
87533 + case CEIL_DIV_EXPR:
87534 + case FLOOR_DIV_EXPR:
87535 + case ROUND_DIV_EXPR:
87536 + case TRUNC_MOD_EXPR:
87537 + case CEIL_MOD_EXPR:
87538 + case FLOOR_MOD_EXPR:
87539 + case ROUND_MOD_EXPR:
87540 + case EXACT_DIV_EXPR:
87541 + case POINTER_PLUS_EXPR:
87542 + case BIT_AND_EXPR:
87543 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87544 + default:
87545 + break;
87546 + }
87547 +
87548 + *potentionally_overflowed = true;
87549 +
87550 + new_lhs = handle_integer_truncation(visited, potentionally_overflowed, lhs);
87551 + if (new_lhs != NULL_TREE)
87552 + return new_lhs;
87553 +
87554 + if (TREE_CODE(rhs1) == SSA_NAME)
87555 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
87556 + if (TREE_CODE(rhs2) == SSA_NAME)
87557 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
87558 +
87559 + if (is_a_neg_overflow(def_stmt, rhs2))
87560 + return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
87561 + if (is_a_neg_overflow(def_stmt, rhs1))
87562 + return handle_intentional_overflow(visited, potentionally_overflowed, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
87563 +
87564 + if (is_a_constant_overflow(def_stmt, rhs2))
87565 + return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
87566 + if (is_a_constant_overflow(def_stmt, rhs1))
87567 + return handle_intentional_overflow(visited, potentionally_overflowed, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
87568 +
87569 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
87570 +}
87571 +
87572 +#if BUILDING_GCC_VERSION >= 4007
87573 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree size_overflow_type, tree rhs)
87574 +{
87575 + if (is_gimple_constant(rhs))
87576 + return cast_a_tree(size_overflow_type, rhs);
87577 + if (TREE_CODE(rhs) != SSA_NAME)
87578 + return NULL_TREE;
87579 + return expand(visited, potentionally_overflowed, rhs);
87580 +}
87581 +
87582 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87583 +{
87584 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
87585 + gimple def_stmt = get_def_stmt(lhs);
87586 +
87587 + *potentionally_overflowed = true;
87588 +
87589 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
87590 +
87591 + rhs1 = gimple_assign_rhs1(def_stmt);
87592 + rhs2 = gimple_assign_rhs2(def_stmt);
87593 + rhs3 = gimple_assign_rhs3(def_stmt);
87594 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs1);
87595 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs2);
87596 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, size_overflow_type, rhs3);
87597 +
87598 + return follow_overflow_type_and_dup(visited, potentionally_overflowed, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
87599 +}
87600 +#endif
87601 +
87602 +static tree get_size_overflow_type(gimple stmt, tree node)
87603 +{
87604 + tree type;
87605 +
87606 + gcc_assert(node != NULL_TREE);
87607 +
87608 + type = TREE_TYPE(node);
87609 +
87610 + if (gimple_plf(stmt, MY_STMT))
87611 + return TREE_TYPE(node);
87612 +
87613 + switch (TYPE_MODE(type)) {
87614 + case QImode:
87615 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
87616 + case HImode:
87617 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
87618 + case SImode:
87619 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
87620 + case DImode:
87621 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
87622 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
87623 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
87624 + default:
87625 + debug_tree(node);
87626 + error("get_size_overflow_type: unsupported gcc configuration.");
87627 + gcc_unreachable();
87628 + }
87629 +}
87630 +
87631 +static tree expand_visited(gimple def_stmt)
87632 +{
87633 + const_gimple next_stmt;
87634 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
87635 +
87636 + gsi_next(&gsi);
87637 + next_stmt = gsi_stmt(gsi);
87638 +
87639 + switch (gimple_code(next_stmt)) {
87640 + case GIMPLE_ASSIGN:
87641 + return gimple_get_lhs(next_stmt);
87642 + case GIMPLE_PHI:
87643 + return gimple_phi_result(next_stmt);
87644 + case GIMPLE_CALL:
87645 + return gimple_call_lhs(next_stmt);
87646 + default:
87647 + return NULL_TREE;
87648 + }
87649 +}
87650 +
87651 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree lhs)
87652 +{
87653 + gimple def_stmt;
87654 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
87655 +
87656 + if (is_gimple_constant(lhs))
87657 + return NULL_TREE;
87658 +
87659 + if (TREE_CODE(lhs) == ADDR_EXPR)
87660 + return NULL_TREE;
87661 +
87662 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
87663 +
87664 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
87665 + check_missing_attribute(lhs);
87666 +
87667 + def_stmt = get_def_stmt(lhs);
87668 +
87669 + if (!def_stmt)
87670 + return NULL_TREE;
87671 +
87672 + if (gimple_plf(def_stmt, MY_STMT))
87673 + return lhs;
87674 +
87675 + if (pointer_set_contains(visited, def_stmt))
87676 + return expand_visited(def_stmt);
87677 +
87678 + switch (gimple_code(def_stmt)) {
87679 + case GIMPLE_NOP:
87680 + check_missing_attribute(lhs);
87681 + return NULL_TREE;
87682 + case GIMPLE_PHI:
87683 + return build_new_phi(visited, potentionally_overflowed, lhs);
87684 + case GIMPLE_CALL:
87685 + case GIMPLE_ASM:
87686 + return create_assign(visited, potentionally_overflowed, def_stmt, lhs, AFTER_STMT);
87687 + case GIMPLE_ASSIGN:
87688 + switch (gimple_num_ops(def_stmt)) {
87689 + case 2:
87690 + return handle_unary_ops(visited, potentionally_overflowed, lhs);
87691 + case 3:
87692 + return handle_binary_ops(visited, potentionally_overflowed, lhs);
87693 +#if BUILDING_GCC_VERSION >= 4007
87694 + case 4:
87695 + return handle_ternary_ops(visited, potentionally_overflowed, lhs);
87696 +#endif
87697 + }
87698 + default:
87699 + debug_gimple_stmt(def_stmt);
87700 + error("expand: unknown gimple code");
87701 + gcc_unreachable();
87702 + }
87703 +}
87704 +
87705 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
87706 +{
87707 + const_gimple assign;
87708 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87709 + tree origtype = TREE_TYPE(origarg);
87710 +
87711 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
87712 +
87713 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87714 +
87715 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
87716 + update_stmt(stmt);
87717 +}
87718 +
87719 +static tree get_function_arg(unsigned int argnum, const_gimple stmt, const_tree fndecl)
87720 +{
87721 + const char *origid;
87722 + tree arg;
87723 + const_tree origarg;
87724 +
87725 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
87726 + gcc_assert(gimple_call_num_args(stmt) > argnum);
87727 + return gimple_call_arg(stmt, argnum);
87728 + }
87729 +
87730 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
87731 + while (origarg && argnum) {
87732 + argnum--;
87733 + origarg = TREE_CHAIN(origarg);
87734 + }
87735 +
87736 + gcc_assert(argnum == 0);
87737 +
87738 + gcc_assert(origarg != NULL_TREE);
87739 + origid = NAME(origarg);
87740 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
87741 + if (!strcmp(origid, NAME(arg)))
87742 + return arg;
87743 + }
87744 + return NULL_TREE;
87745 +}
87746 +
87747 +static void handle_function_arg(gimple stmt, const_tree fndecl, unsigned int argnum)
87748 +{
87749 + struct pointer_set_t *visited;
87750 + tree arg, newarg;
87751 + bool potentionally_overflowed;
87752 +
87753 + arg = get_function_arg(argnum, stmt, fndecl);
87754 + if (arg == NULL_TREE)
87755 + return;
87756 +
87757 + if (is_gimple_constant(arg))
87758 + return;
87759 + if (TREE_CODE(arg) != SSA_NAME)
87760 + return;
87761 +
87762 + check_arg_type(arg);
87763 +
87764 + visited = pointer_set_create();
87765 + potentionally_overflowed = false;
87766 + newarg = expand(visited, &potentionally_overflowed, arg);
87767 + pointer_set_destroy(visited);
87768 +
87769 + if (newarg == NULL_TREE || !potentionally_overflowed)
87770 + return;
87771 +
87772 + change_function_arg(stmt, arg, argnum, newarg);
87773 +
87774 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, &potentionally_overflowed, BEFORE_STMT);
87775 +}
87776 +
87777 +static void handle_function_by_attribute(gimple stmt, const_tree attr, const_tree fndecl)
87778 +{
87779 + tree p = TREE_VALUE(attr);
87780 + do {
87781 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
87782 + p = TREE_CHAIN(p);
87783 + } while (p);
87784 +}
87785 +
87786 +static void handle_function_by_hash(gimple stmt, const_tree fndecl)
87787 +{
87788 + const_tree orig_fndecl;
87789 + unsigned int num;
87790 + const struct size_overflow_hash *hash;
87791 +
87792 + orig_fndecl = get_original_function_decl(fndecl);
87793 + hash = get_function_hash(orig_fndecl);
87794 + if (!hash)
87795 + return;
87796 +
87797 + for (num = 1; num <= MAX_PARAM; num++)
87798 + if (hash->param & (1U << num))
87799 + handle_function_arg(stmt, fndecl, num - 1);
87800 +}
87801 +
87802 +static void set_plf_false(void)
87803 +{
87804 + basic_block bb;
87805 +
87806 + FOR_ALL_BB(bb) {
87807 + gimple_stmt_iterator si;
87808 +
87809 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
87810 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
87811 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
87812 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
87813 + }
87814 +}
87815 +
87816 +static unsigned int handle_function(void)
87817 +{
87818 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
87819 +
87820 + set_plf_false();
87821 +
87822 + do {
87823 + gimple_stmt_iterator gsi;
87824 + next = bb->next_bb;
87825 +
87826 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87827 + const_tree fndecl, attr;
87828 + gimple stmt = gsi_stmt(gsi);
87829 +
87830 + if (!(is_gimple_call(stmt)))
87831 + continue;
87832 + fndecl = gimple_call_fndecl(stmt);
87833 + if (fndecl == NULL_TREE)
87834 + continue;
87835 + if (gimple_call_num_args(stmt) == 0)
87836 + continue;
87837 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
87838 + if (!attr || !TREE_VALUE(attr))
87839 + handle_function_by_hash(stmt, fndecl);
87840 + else
87841 + handle_function_by_attribute(stmt, attr, fndecl);
87842 + gsi = gsi_for_stmt(stmt);
87843 + next = gimple_bb(stmt)->next_bb;
87844 + }
87845 + bb = next;
87846 + } while (bb);
87847 + return 0;
87848 +}
87849 +
87850 +static struct gimple_opt_pass size_overflow_pass = {
87851 + .pass = {
87852 + .type = GIMPLE_PASS,
87853 + .name = "size_overflow",
87854 + .gate = NULL,
87855 + .execute = handle_function,
87856 + .sub = NULL,
87857 + .next = NULL,
87858 + .static_pass_number = 0,
87859 + .tv_id = TV_NONE,
87860 + .properties_required = PROP_cfg | PROP_referenced_vars,
87861 + .properties_provided = 0,
87862 + .properties_destroyed = 0,
87863 + .todo_flags_start = 0,
87864 + .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
87865 + }
87866 +};
87867 +
87868 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
87869 +{
87870 + tree fntype;
87871 +
87872 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
87873 +
87874 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
87875 + fntype = build_function_type_list(void_type_node,
87876 + const_char_ptr_type_node,
87877 + unsigned_type_node,
87878 + const_char_ptr_type_node,
87879 + const_char_ptr_type_node,
87880 + NULL_TREE);
87881 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
87882 +
87883 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
87884 + TREE_PUBLIC(report_size_overflow_decl) = 1;
87885 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
87886 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
87887 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
87888 +}
87889 +
87890 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87891 +{
87892 + int i;
87893 + const char * const plugin_name = plugin_info->base_name;
87894 + const int argc = plugin_info->argc;
87895 + const struct plugin_argument * const argv = plugin_info->argv;
87896 + bool enable = true;
87897 +
87898 + struct register_pass_info size_overflow_pass_info = {
87899 + .pass = &size_overflow_pass.pass,
87900 + .reference_pass_name = "ssa",
87901 + .ref_pass_instance_number = 1,
87902 + .pos_op = PASS_POS_INSERT_AFTER
87903 + };
87904 +
87905 + if (!plugin_default_version_check(version, &gcc_version)) {
87906 + error(G_("incompatible gcc/plugin versions"));
87907 + return 1;
87908 + }
87909 +
87910 + for (i = 0; i < argc; ++i) {
87911 + if (!strcmp(argv[i].key, "no-size-overflow")) {
87912 + enable = false;
87913 + continue;
87914 + }
87915 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87916 + }
87917 +
87918 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
87919 + if (enable) {
87920 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
87921 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
87922 + }
87923 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
87924 +
87925 + return 0;
87926 +}
87927 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
87928 new file mode 100644
87929 index 0000000..38d2014
87930 --- /dev/null
87931 +++ b/tools/gcc/stackleak_plugin.c
87932 @@ -0,0 +1,313 @@
87933 +/*
87934 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
87935 + * Licensed under the GPL v2
87936 + *
87937 + * Note: the choice of the license means that the compilation process is
87938 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
87939 + * but for the kernel it doesn't matter since it doesn't link against
87940 + * any of the gcc libraries
87941 + *
87942 + * gcc plugin to help implement various PaX features
87943 + *
87944 + * - track lowest stack pointer
87945 + *
87946 + * TODO:
87947 + * - initialize all local variables
87948 + *
87949 + * BUGS:
87950 + * - none known
87951 + */
87952 +#include "gcc-plugin.h"
87953 +#include "config.h"
87954 +#include "system.h"
87955 +#include "coretypes.h"
87956 +#include "tree.h"
87957 +#include "tree-pass.h"
87958 +#include "flags.h"
87959 +#include "intl.h"
87960 +#include "toplev.h"
87961 +#include "plugin.h"
87962 +//#include "expr.h" where are you...
87963 +#include "diagnostic.h"
87964 +#include "plugin-version.h"
87965 +#include "tm.h"
87966 +#include "function.h"
87967 +#include "basic-block.h"
87968 +#include "gimple.h"
87969 +#include "rtl.h"
87970 +#include "emit-rtl.h"
87971 +
87972 +extern void print_gimple_stmt(FILE *, gimple, int, int);
87973 +
87974 +int plugin_is_GPL_compatible;
87975 +
87976 +static int track_frame_size = -1;
87977 +static const char track_function[] = "pax_track_stack";
87978 +static const char check_function[] = "pax_check_alloca";
87979 +static bool init_locals;
87980 +
87981 +static struct plugin_info stackleak_plugin_info = {
87982 + .version = "201203140940",
87983 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
87984 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
87985 +};
87986 +
87987 +static bool gate_stackleak_track_stack(void);
87988 +static unsigned int execute_stackleak_tree_instrument(void);
87989 +static unsigned int execute_stackleak_final(void);
87990 +
87991 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
87992 + .pass = {
87993 + .type = GIMPLE_PASS,
87994 + .name = "stackleak_tree_instrument",
87995 + .gate = gate_stackleak_track_stack,
87996 + .execute = execute_stackleak_tree_instrument,
87997 + .sub = NULL,
87998 + .next = NULL,
87999 + .static_pass_number = 0,
88000 + .tv_id = TV_NONE,
88001 + .properties_required = PROP_gimple_leh | PROP_cfg,
88002 + .properties_provided = 0,
88003 + .properties_destroyed = 0,
88004 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
88005 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
88006 + }
88007 +};
88008 +
88009 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
88010 + .pass = {
88011 + .type = RTL_PASS,
88012 + .name = "stackleak_final",
88013 + .gate = gate_stackleak_track_stack,
88014 + .execute = execute_stackleak_final,
88015 + .sub = NULL,
88016 + .next = NULL,
88017 + .static_pass_number = 0,
88018 + .tv_id = TV_NONE,
88019 + .properties_required = 0,
88020 + .properties_provided = 0,
88021 + .properties_destroyed = 0,
88022 + .todo_flags_start = 0,
88023 + .todo_flags_finish = TODO_dump_func
88024 + }
88025 +};
88026 +
88027 +static bool gate_stackleak_track_stack(void)
88028 +{
88029 + return track_frame_size >= 0;
88030 +}
88031 +
88032 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
88033 +{
88034 + gimple check_alloca;
88035 + tree fntype, fndecl, alloca_size;
88036 +
88037 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
88038 + fndecl = build_fn_decl(check_function, fntype);
88039 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
88040 +
88041 + // insert call to void pax_check_alloca(unsigned long size)
88042 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
88043 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
88044 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
88045 +}
88046 +
88047 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
88048 +{
88049 + gimple track_stack;
88050 + tree fntype, fndecl;
88051 +
88052 + fntype = build_function_type_list(void_type_node, NULL_TREE);
88053 + fndecl = build_fn_decl(track_function, fntype);
88054 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
88055 +
88056 + // insert call to void pax_track_stack(void)
88057 + track_stack = gimple_build_call(fndecl, 0);
88058 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
88059 +}
88060 +
88061 +#if BUILDING_GCC_VERSION == 4005
88062 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
88063 +{
88064 + tree fndecl;
88065 +
88066 + if (!is_gimple_call(stmt))
88067 + return false;
88068 + fndecl = gimple_call_fndecl(stmt);
88069 + if (!fndecl)
88070 + return false;
88071 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
88072 + return false;
88073 +// print_node(stderr, "pax", fndecl, 4);
88074 + return DECL_FUNCTION_CODE(fndecl) == code;
88075 +}
88076 +#endif
88077 +
88078 +static bool is_alloca(gimple stmt)
88079 +{
88080 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
88081 + return true;
88082 +
88083 +#if BUILDING_GCC_VERSION >= 4007
88084 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
88085 + return true;
88086 +#endif
88087 +
88088 + return false;
88089 +}
88090 +
88091 +static unsigned int execute_stackleak_tree_instrument(void)
88092 +{
88093 + basic_block bb, entry_bb;
88094 + bool prologue_instrumented = false, is_leaf = true;
88095 +
88096 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
88097 +
88098 + // 1. loop through BBs and GIMPLE statements
88099 + FOR_EACH_BB(bb) {
88100 + gimple_stmt_iterator gsi;
88101 +
88102 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
88103 + gimple stmt;
88104 +
88105 + stmt = gsi_stmt(gsi);
88106 +
88107 + if (is_gimple_call(stmt))
88108 + is_leaf = false;
88109 +
88110 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
88111 + if (!is_alloca(stmt))
88112 + continue;
88113 +
88114 + // 2. insert stack overflow check before each __builtin_alloca call
88115 + stackleak_check_alloca(&gsi);
88116 +
88117 + // 3. insert track call after each __builtin_alloca call
88118 + stackleak_add_instrumentation(&gsi);
88119 + if (bb == entry_bb)
88120 + prologue_instrumented = true;
88121 + }
88122 + }
88123 +
88124 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
88125 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
88126 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
88127 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
88128 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
88129 + return 0;
88130 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
88131 + return 0;
88132 +
88133 + // 4. insert track call at the beginning
88134 + if (!prologue_instrumented) {
88135 + gimple_stmt_iterator gsi;
88136 +
88137 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88138 + if (dom_info_available_p(CDI_DOMINATORS))
88139 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
88140 + gsi = gsi_start_bb(bb);
88141 + stackleak_add_instrumentation(&gsi);
88142 + }
88143 +
88144 + return 0;
88145 +}
88146 +
88147 +static unsigned int execute_stackleak_final(void)
88148 +{
88149 + rtx insn;
88150 +
88151 + if (cfun->calls_alloca)
88152 + return 0;
88153 +
88154 + // keep calls only if function frame is big enough
88155 + if (get_frame_size() >= track_frame_size)
88156 + return 0;
88157 +
88158 + // 1. find pax_track_stack calls
88159 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
88160 + // 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))
88161 + rtx body;
88162 +
88163 + if (!CALL_P(insn))
88164 + continue;
88165 + body = PATTERN(insn);
88166 + if (GET_CODE(body) != CALL)
88167 + continue;
88168 + body = XEXP(body, 0);
88169 + if (GET_CODE(body) != MEM)
88170 + continue;
88171 + body = XEXP(body, 0);
88172 + if (GET_CODE(body) != SYMBOL_REF)
88173 + continue;
88174 + if (strcmp(XSTR(body, 0), track_function))
88175 + continue;
88176 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
88177 + // 2. delete call
88178 + insn = delete_insn_and_edges(insn);
88179 +#if BUILDING_GCC_VERSION >= 4007
88180 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
88181 + insn = delete_insn_and_edges(insn);
88182 +#endif
88183 + }
88184 +
88185 +// print_simple_rtl(stderr, get_insns());
88186 +// print_rtl(stderr, get_insns());
88187 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
88188 +
88189 + return 0;
88190 +}
88191 +
88192 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
88193 +{
88194 + const char * const plugin_name = plugin_info->base_name;
88195 + const int argc = plugin_info->argc;
88196 + const struct plugin_argument * const argv = plugin_info->argv;
88197 + int i;
88198 + struct register_pass_info stackleak_tree_instrument_pass_info = {
88199 + .pass = &stackleak_tree_instrument_pass.pass,
88200 +// .reference_pass_name = "tree_profile",
88201 + .reference_pass_name = "optimized",
88202 + .ref_pass_instance_number = 1,
88203 + .pos_op = PASS_POS_INSERT_BEFORE
88204 + };
88205 + struct register_pass_info stackleak_final_pass_info = {
88206 + .pass = &stackleak_final_rtl_opt_pass.pass,
88207 + .reference_pass_name = "final",
88208 + .ref_pass_instance_number = 1,
88209 + .pos_op = PASS_POS_INSERT_BEFORE
88210 + };
88211 +
88212 + if (!plugin_default_version_check(version, &gcc_version)) {
88213 + error(G_("incompatible gcc/plugin versions"));
88214 + return 1;
88215 + }
88216 +
88217 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
88218 +
88219 + for (i = 0; i < argc; ++i) {
88220 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
88221 + if (!argv[i].value) {
88222 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
88223 + continue;
88224 + }
88225 + track_frame_size = atoi(argv[i].value);
88226 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
88227 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
88228 + continue;
88229 + }
88230 + if (!strcmp(argv[i].key, "initialize-locals")) {
88231 + if (argv[i].value) {
88232 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
88233 + continue;
88234 + }
88235 + init_locals = true;
88236 + continue;
88237 + }
88238 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
88239 + }
88240 +
88241 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
88242 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
88243 +
88244 + return 0;
88245 +}
88246 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
88247 index 6789d78..4afd019e 100644
88248 --- a/tools/perf/util/include/asm/alternative-asm.h
88249 +++ b/tools/perf/util/include/asm/alternative-asm.h
88250 @@ -5,4 +5,7 @@
88251
88252 #define altinstruction_entry #
88253
88254 + .macro pax_force_retaddr rip=0, reload=0
88255 + .endm
88256 +
88257 #endif
88258 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
88259 index af0f22f..9a7d479 100644
88260 --- a/usr/gen_init_cpio.c
88261 +++ b/usr/gen_init_cpio.c
88262 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
88263 int retval;
88264 int rc = -1;
88265 int namesize;
88266 - int i;
88267 + unsigned int i;
88268
88269 mode |= S_IFREG;
88270
88271 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
88272 *env_var = *expanded = '\0';
88273 strncat(env_var, start + 2, end - start - 2);
88274 strncat(expanded, new_location, start - new_location);
88275 - strncat(expanded, getenv(env_var), PATH_MAX);
88276 - strncat(expanded, end + 1, PATH_MAX);
88277 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
88278 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
88279 strncpy(new_location, expanded, PATH_MAX);
88280 + new_location[PATH_MAX] = 0;
88281 } else
88282 break;
88283 }
88284 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
88285 index 44ee712..7da730b 100644
88286 --- a/virt/kvm/kvm_main.c
88287 +++ b/virt/kvm/kvm_main.c
88288 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
88289
88290 static cpumask_var_t cpus_hardware_enabled;
88291 static int kvm_usage_count = 0;
88292 -static atomic_t hardware_enable_failed;
88293 +static atomic_unchecked_t hardware_enable_failed;
88294
88295 struct kmem_cache *kvm_vcpu_cache;
88296 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
88297 @@ -2291,7 +2291,7 @@ static void hardware_enable_nolock(void *junk)
88298
88299 if (r) {
88300 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
88301 - atomic_inc(&hardware_enable_failed);
88302 + atomic_inc_unchecked(&hardware_enable_failed);
88303 printk(KERN_INFO "kvm: enabling virtualization on "
88304 "CPU%d failed\n", cpu);
88305 }
88306 @@ -2345,10 +2345,10 @@ static int hardware_enable_all(void)
88307
88308 kvm_usage_count++;
88309 if (kvm_usage_count == 1) {
88310 - atomic_set(&hardware_enable_failed, 0);
88311 + atomic_set_unchecked(&hardware_enable_failed, 0);
88312 on_each_cpu(hardware_enable_nolock, NULL, 1);
88313
88314 - if (atomic_read(&hardware_enable_failed)) {
88315 + if (atomic_read_unchecked(&hardware_enable_failed)) {
88316 hardware_disable_all_nolock();
88317 r = -EBUSY;
88318 }
88319 @@ -2709,7 +2709,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
88320 kvm_arch_vcpu_put(vcpu);
88321 }
88322
88323 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88324 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88325 struct module *module)
88326 {
88327 int r;
88328 @@ -2772,7 +2772,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88329 if (!vcpu_align)
88330 vcpu_align = __alignof__(struct kvm_vcpu);
88331 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
88332 - 0, NULL);
88333 + SLAB_USERCOPY, NULL);
88334 if (!kvm_vcpu_cache) {
88335 r = -ENOMEM;
88336 goto out_free_3;
88337 @@ -2782,9 +2782,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
88338 if (r)
88339 goto out_free;
88340
88341 - kvm_chardev_ops.owner = module;
88342 - kvm_vm_fops.owner = module;
88343 - kvm_vcpu_fops.owner = module;
88344 + pax_open_kernel();
88345 + *(void **)&kvm_chardev_ops.owner = module;
88346 + *(void **)&kvm_vm_fops.owner = module;
88347 + *(void **)&kvm_vcpu_fops.owner = module;
88348 + pax_close_kernel();
88349
88350 r = misc_register(&kvm_dev);
88351 if (r) {