]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.5.0-201208081934.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.0-201208081934.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b4a898f..cd023f2 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 @@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56 +ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60 @@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64 +builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70 +clut_vga16.c
71 +common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78 +config.c
79 config.mak
80 config.mak.autogen
81 +config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85 @@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89 +dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93 +exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97 @@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101 +gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108 +hash
109 +hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113 @@ -145,7 +163,7 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117 -kconfig
118 +kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 @@ -153,7 +171,7 @@ kxgettext
123 lkc_defs.h
124 lex.c
125 lex.*.c
126 -linux
127 +lib1funcs.S
128 logo_*.c
129 logo_*_clut224.c
130 logo_*_mono.c
131 @@ -164,14 +182,15 @@ machtypes.h
132 map
133 map_hugetlb
134 maui_boot.h
135 -media
136 mconf
137 +mdp
138 miboot*
139 mk_elfconfig
140 mkboot
141 mkbugboot
142 mkcpustr
143 mkdep
144 +mkpiggy
145 mkprep
146 mkregtable
147 mktables
148 @@ -188,6 +207,8 @@ oui.c*
149 page-types
150 parse.c
151 parse.h
152 +parse-events*
153 +pasyms.h
154 patches*
155 pca200e.bin
156 pca200e_ecd.bin2
157 @@ -197,6 +218,7 @@ perf-archive
158 piggyback
159 piggy.gzip
160 piggy.S
161 +pmu-*
162 pnmtologo
163 ppc_defs.h*
164 pss_boot.h
165 @@ -206,7 +228,10 @@ r200_reg_safe.h
166 r300_reg_safe.h
167 r420_reg_safe.h
168 r600_reg_safe.h
169 +realmode.lds
170 +realmode.relocs
171 recordmcount
172 +regdb.c
173 relocs
174 rlim_names.h
175 rn50_reg_safe.h
176 @@ -216,8 +241,11 @@ series
177 setup
178 setup.bin
179 setup.elf
180 +size_overflow_hash.h
181 sImage
182 +slabinfo
183 sm_tbl*
184 +sortextable
185 split-include
186 syscalltab.h
187 tables.c
188 @@ -227,6 +255,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192 +user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196 @@ -238,13 +267,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200 +vdsox32.lds
201 +vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208 +vmlinux.bin.bz2
209 vmlinux.lds
210 +vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214 @@ -252,9 +285,11 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218 +utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222 zImage*
223 zconf.hash.c
224 +zconf.lex.c
225 zoffset.h
226 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
227 index a92c5eb..7530459 100644
228 --- a/Documentation/kernel-parameters.txt
229 +++ b/Documentation/kernel-parameters.txt
230 @@ -2051,6 +2051,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
231 the specified number of seconds. This is to be used if
232 your oopses keep scrolling off the screen.
233
234 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
235 + virtualization environments that don't cope well with the
236 + expand down segment used by UDEREF on X86-32 or the frequent
237 + page table updates on X86-64.
238 +
239 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
240 +
241 pcbit= [HW,ISDN]
242
243 pcd. [PARIDE]
244 diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
245 index 13d6166..8c235b6 100644
246 --- a/Documentation/sysctl/fs.txt
247 +++ b/Documentation/sysctl/fs.txt
248 @@ -163,16 +163,22 @@ This value can be used to query and set the core dump mode for setuid
249 or otherwise protected/tainted binaries. The modes are
250
251 0 - (default) - traditional behaviour. Any process which has changed
252 - privilege levels or is execute only will not be dumped
253 + privilege levels or is execute only will not be dumped.
254 1 - (debug) - all processes dump core when possible. The core dump is
255 owned by the current user and no security is applied. This is
256 intended for system debugging situations only. Ptrace is unchecked.
257 + This is insecure as it allows regular users to examine the memory
258 + contents of privileged processes.
259 2 - (suidsafe) - any binary which normally would not be dumped is dumped
260 - readable by root only. This allows the end user to remove
261 - such a dump but not access it directly. For security reasons
262 - core dumps in this mode will not overwrite one another or
263 - other files. This mode is appropriate when administrators are
264 - attempting to debug problems in a normal environment.
265 + anyway, but only if the "core_pattern" kernel sysctl is set to
266 + either a pipe handler or a fully qualified path. (For more details
267 + on this limitation, see CVE-2006-2451.) This mode is appropriate
268 + when administrators are attempting to debug problems in a normal
269 + environment, and either have a core dump pipe handler that knows
270 + to treat privileged core dumps with care, or specific directory
271 + defined for catching core dumps. If a core dump happens without
272 + a pipe handler or fully qualifid path, a message will be emitted
273 + to syslog warning about the lack of a correct setting.
274
275 ==============================================================
276
277 diff --git a/Makefile b/Makefile
278 index 4bb09e1..40bec19 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..9269ea1 100644
802 --- a/arch/arm/include/asm/atomic.h
803 +++ b/arch/arm/include/asm/atomic.h
804 @@ -17,17 +17,35 @@
805 #include <asm/barrier.h>
806 #include <asm/cmpxchg.h>
807
808 +#ifdef CONFIG_GENERIC_ATOMIC64
809 +#include <asm-generic/atomic64.h>
810 +#endif
811 +
812 #define ATOMIC_INIT(i) { (i) }
813
814 #ifdef __KERNEL__
815
816 +#define _ASM_EXTABLE(from, to) \
817 +" .pushsection __ex_table,\"a\"\n"\
818 +" .align 3\n" \
819 +" .long " #from ", " #to"\n" \
820 +" .popsection"
821 +
822 /*
823 * On ARM, ordinary assignment (str instruction) doesn't clear the local
824 * strex/ldrex monitor on some implementations. The reason we can use it for
825 * atomic_set() is the clrex or dummy strex done on every exception return.
826 */
827 #define atomic_read(v) (*(volatile int *)&(v)->counter)
828 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
829 +{
830 + return v->counter;
831 +}
832 #define atomic_set(v,i) (((v)->counter) = (i))
833 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
834 +{
835 + v->counter = i;
836 +}
837
838 #if __LINUX_ARM_ARCH__ >= 6
839
840 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
841 int result;
842
843 __asm__ __volatile__("@ atomic_add\n"
844 +"1: ldrex %1, [%3]\n"
845 +" adds %0, %1, %4\n"
846 +
847 +#ifdef CONFIG_PAX_REFCOUNT
848 +" bvc 3f\n"
849 +"2: bkpt 0xf103\n"
850 +"3:\n"
851 +#endif
852 +
853 +" strex %1, %0, [%3]\n"
854 +" teq %1, #0\n"
855 +" bne 1b"
856 +
857 +#ifdef CONFIG_PAX_REFCOUNT
858 +"\n4:\n"
859 + _ASM_EXTABLE(2b, 4b)
860 +#endif
861 +
862 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
863 + : "r" (&v->counter), "Ir" (i)
864 + : "cc");
865 +}
866 +
867 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
868 +{
869 + unsigned long tmp;
870 + int result;
871 +
872 + __asm__ __volatile__("@ atomic_add_unchecked\n"
873 "1: ldrex %0, [%3]\n"
874 " add %0, %0, %4\n"
875 " strex %1, %0, [%3]\n"
876 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
877 smp_mb();
878
879 __asm__ __volatile__("@ atomic_add_return\n"
880 +"1: ldrex %1, [%3]\n"
881 +" adds %0, %1, %4\n"
882 +
883 +#ifdef CONFIG_PAX_REFCOUNT
884 +" bvc 3f\n"
885 +" mov %0, %1\n"
886 +"2: bkpt 0xf103\n"
887 +"3:\n"
888 +#endif
889 +
890 +" strex %1, %0, [%3]\n"
891 +" teq %1, #0\n"
892 +" bne 1b"
893 +
894 +#ifdef CONFIG_PAX_REFCOUNT
895 +"\n4:\n"
896 + _ASM_EXTABLE(2b, 4b)
897 +#endif
898 +
899 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
900 + : "r" (&v->counter), "Ir" (i)
901 + : "cc");
902 +
903 + smp_mb();
904 +
905 + return result;
906 +}
907 +
908 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
909 +{
910 + unsigned long tmp;
911 + int result;
912 +
913 + smp_mb();
914 +
915 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
916 "1: ldrex %0, [%3]\n"
917 " add %0, %0, %4\n"
918 " strex %1, %0, [%3]\n"
919 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
920 int result;
921
922 __asm__ __volatile__("@ atomic_sub\n"
923 +"1: ldrex %1, [%3]\n"
924 +" subs %0, %1, %4\n"
925 +
926 +#ifdef CONFIG_PAX_REFCOUNT
927 +" bvc 3f\n"
928 +"2: bkpt 0xf103\n"
929 +"3:\n"
930 +#endif
931 +
932 +" strex %1, %0, [%3]\n"
933 +" teq %1, #0\n"
934 +" bne 1b"
935 +
936 +#ifdef CONFIG_PAX_REFCOUNT
937 +"\n4:\n"
938 + _ASM_EXTABLE(2b, 4b)
939 +#endif
940 +
941 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
942 + : "r" (&v->counter), "Ir" (i)
943 + : "cc");
944 +}
945 +
946 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
947 +{
948 + unsigned long tmp;
949 + int result;
950 +
951 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
952 "1: ldrex %0, [%3]\n"
953 " sub %0, %0, %4\n"
954 " strex %1, %0, [%3]\n"
955 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
956 smp_mb();
957
958 __asm__ __volatile__("@ atomic_sub_return\n"
959 -"1: ldrex %0, [%3]\n"
960 -" sub %0, %0, %4\n"
961 +"1: ldrex %1, [%3]\n"
962 +" sub %0, %1, %4\n"
963 +
964 +#ifdef CONFIG_PAX_REFCOUNT
965 +" bvc 3f\n"
966 +" mov %0, %1\n"
967 +"2: bkpt 0xf103\n"
968 +"3:\n"
969 +#endif
970 +
971 " strex %1, %0, [%3]\n"
972 " teq %1, #0\n"
973 " bne 1b"
974 +
975 +#ifdef CONFIG_PAX_REFCOUNT
976 +"\n4:\n"
977 + _ASM_EXTABLE(2b, 4b)
978 +#endif
979 +
980 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
981 : "r" (&v->counter), "Ir" (i)
982 : "cc");
983 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
984 return oldval;
985 }
986
987 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
988 +{
989 + unsigned long oldval, res;
990 +
991 + smp_mb();
992 +
993 + do {
994 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
995 + "ldrex %1, [%3]\n"
996 + "mov %0, #0\n"
997 + "teq %1, %4\n"
998 + "strexeq %0, %5, [%3]\n"
999 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1000 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1001 + : "cc");
1002 + } while (res);
1003 +
1004 + smp_mb();
1005 +
1006 + return oldval;
1007 +}
1008 +
1009 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1010 {
1011 unsigned long tmp, tmp2;
1012 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1013
1014 return val;
1015 }
1016 +
1017 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1018 +{
1019 + return atomic_add_return(i, v);
1020 +}
1021 +
1022 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1023 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1024 +{
1025 + (void) atomic_add_return(i, v);
1026 +}
1027
1028 static inline int atomic_sub_return(int i, atomic_t *v)
1029 {
1030 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1031 return val;
1032 }
1033 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1034 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1035 +{
1036 + (void) atomic_sub_return(i, v);
1037 +}
1038
1039 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1040 {
1041 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1042 return ret;
1043 }
1044
1045 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1046 +{
1047 + return atomic_cmpxchg(v, old, new);
1048 +}
1049 +
1050 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1051 {
1052 unsigned long flags;
1053 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 #endif /* __LINUX_ARM_ARCH__ */
1055
1056 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1057 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1058 +{
1059 + return xchg(&v->counter, new);
1060 +}
1061
1062 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1063 {
1064 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1065 }
1066
1067 #define atomic_inc(v) atomic_add(1, v)
1068 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_add_unchecked(1, v);
1071 +}
1072 #define atomic_dec(v) atomic_sub(1, v)
1073 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1074 +{
1075 + atomic_sub_unchecked(1, v);
1076 +}
1077
1078 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1079 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1080 +{
1081 + return atomic_add_return_unchecked(1, v) == 0;
1082 +}
1083 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1084 #define atomic_inc_return(v) (atomic_add_return(1, v))
1085 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1086 +{
1087 + return atomic_add_return_unchecked(1, v);
1088 +}
1089 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1090 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1091
1092 @@ -241,6 +428,14 @@ typedef struct {
1093 u64 __aligned(8) counter;
1094 } atomic64_t;
1095
1096 +#ifdef CONFIG_PAX_REFCOUNT
1097 +typedef struct {
1098 + u64 __aligned(8) counter;
1099 +} atomic64_unchecked_t;
1100 +#else
1101 +typedef atomic64_t atomic64_unchecked_t;
1102 +#endif
1103 +
1104 #define ATOMIC64_INIT(i) { (i) }
1105
1106 static inline u64 atomic64_read(const atomic64_t *v)
1107 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1108 return result;
1109 }
1110
1111 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1112 +{
1113 + u64 result;
1114 +
1115 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1116 +" ldrexd %0, %H0, [%1]"
1117 + : "=&r" (result)
1118 + : "r" (&v->counter), "Qo" (v->counter)
1119 + );
1120 +
1121 + return result;
1122 +}
1123 +
1124 static inline void atomic64_set(atomic64_t *v, u64 i)
1125 {
1126 u64 tmp;
1127 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1128 : "cc");
1129 }
1130
1131 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1132 +{
1133 + u64 tmp;
1134 +
1135 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1136 +"1: ldrexd %0, %H0, [%2]\n"
1137 +" strexd %0, %3, %H3, [%2]\n"
1138 +" teq %0, #0\n"
1139 +" bne 1b"
1140 + : "=&r" (tmp), "=Qo" (v->counter)
1141 + : "r" (&v->counter), "r" (i)
1142 + : "cc");
1143 +}
1144 +
1145 static inline void atomic64_add(u64 i, atomic64_t *v)
1146 {
1147 u64 result;
1148 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1149 __asm__ __volatile__("@ atomic64_add\n"
1150 "1: ldrexd %0, %H0, [%3]\n"
1151 " adds %0, %0, %4\n"
1152 +" adcs %H0, %H0, %H4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +"2: bkpt 0xf103\n"
1157 +"3:\n"
1158 +#endif
1159 +
1160 +" strexd %1, %0, %H0, [%3]\n"
1161 +" teq %1, #0\n"
1162 +" bne 1b"
1163 +
1164 +#ifdef CONFIG_PAX_REFCOUNT
1165 +"\n4:\n"
1166 + _ASM_EXTABLE(2b, 4b)
1167 +#endif
1168 +
1169 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1170 + : "r" (&v->counter), "r" (i)
1171 + : "cc");
1172 +}
1173 +
1174 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1175 +{
1176 + u64 result;
1177 + unsigned long tmp;
1178 +
1179 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1180 +"1: ldrexd %0, %H0, [%3]\n"
1181 +" adds %0, %0, %4\n"
1182 " adc %H0, %H0, %H4\n"
1183 " strexd %1, %0, %H0, [%3]\n"
1184 " teq %1, #0\n"
1185 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1186
1187 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1188 {
1189 - u64 result;
1190 - unsigned long tmp;
1191 + u64 result, tmp;
1192
1193 smp_mb();
1194
1195 __asm__ __volatile__("@ atomic64_add_return\n"
1196 +"1: ldrexd %1, %H1, [%3]\n"
1197 +" adds %0, %1, %4\n"
1198 +" adcs %H0, %H1, %H4\n"
1199 +
1200 +#ifdef CONFIG_PAX_REFCOUNT
1201 +" bvc 3f\n"
1202 +" mov %0, %1\n"
1203 +" mov %H0, %H1\n"
1204 +"2: bkpt 0xf103\n"
1205 +"3:\n"
1206 +#endif
1207 +
1208 +" strexd %1, %0, %H0, [%3]\n"
1209 +" teq %1, #0\n"
1210 +" bne 1b"
1211 +
1212 +#ifdef CONFIG_PAX_REFCOUNT
1213 +"\n4:\n"
1214 + _ASM_EXTABLE(2b, 4b)
1215 +#endif
1216 +
1217 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1218 + : "r" (&v->counter), "r" (i)
1219 + : "cc");
1220 +
1221 + smp_mb();
1222 +
1223 + return result;
1224 +}
1225 +
1226 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1227 +{
1228 + u64 result;
1229 + unsigned long tmp;
1230 +
1231 + smp_mb();
1232 +
1233 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " adds %0, %0, %4\n"
1236 " adc %H0, %H0, %H4\n"
1237 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1238 __asm__ __volatile__("@ atomic64_sub\n"
1239 "1: ldrexd %0, %H0, [%3]\n"
1240 " subs %0, %0, %4\n"
1241 +" sbcs %H0, %H0, %H4\n"
1242 +
1243 +#ifdef CONFIG_PAX_REFCOUNT
1244 +" bvc 3f\n"
1245 +"2: bkpt 0xf103\n"
1246 +"3:\n"
1247 +#endif
1248 +
1249 +" strexd %1, %0, %H0, [%3]\n"
1250 +" teq %1, #0\n"
1251 +" bne 1b"
1252 +
1253 +#ifdef CONFIG_PAX_REFCOUNT
1254 +"\n4:\n"
1255 + _ASM_EXTABLE(2b, 4b)
1256 +#endif
1257 +
1258 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1259 + : "r" (&v->counter), "r" (i)
1260 + : "cc");
1261 +}
1262 +
1263 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1264 +{
1265 + u64 result;
1266 + unsigned long tmp;
1267 +
1268 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%3]\n"
1270 +" subs %0, %0, %4\n"
1271 " sbc %H0, %H0, %H4\n"
1272 " strexd %1, %0, %H0, [%3]\n"
1273 " teq %1, #0\n"
1274 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1275
1276 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1277 {
1278 - u64 result;
1279 - unsigned long tmp;
1280 + u64 result, tmp;
1281
1282 smp_mb();
1283
1284 __asm__ __volatile__("@ atomic64_sub_return\n"
1285 -"1: ldrexd %0, %H0, [%3]\n"
1286 -" subs %0, %0, %4\n"
1287 -" sbc %H0, %H0, %H4\n"
1288 +"1: ldrexd %1, %H1, [%3]\n"
1289 +" subs %0, %1, %4\n"
1290 +" sbc %H0, %H1, %H4\n"
1291 +
1292 +#ifdef CONFIG_PAX_REFCOUNT
1293 +" bvc 3f\n"
1294 +" mov %0, %1\n"
1295 +" mov %H0, %H1\n"
1296 +"2: bkpt 0xf103\n"
1297 +"3:\n"
1298 +#endif
1299 +
1300 " strexd %1, %0, %H0, [%3]\n"
1301 " teq %1, #0\n"
1302 " bne 1b"
1303 +
1304 +#ifdef CONFIG_PAX_REFCOUNT
1305 +"\n4:\n"
1306 + _ASM_EXTABLE(2b, 4b)
1307 +#endif
1308 +
1309 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1310 : "r" (&v->counter), "r" (i)
1311 : "cc");
1312 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1313 return oldval;
1314 }
1315
1316 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1317 +{
1318 + u64 oldval;
1319 + unsigned long res;
1320 +
1321 + smp_mb();
1322 +
1323 + do {
1324 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1325 + "ldrexd %1, %H1, [%3]\n"
1326 + "mov %0, #0\n"
1327 + "teq %1, %4\n"
1328 + "teqeq %H1, %H4\n"
1329 + "strexdeq %0, %5, %H5, [%3]"
1330 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1331 + : "r" (&ptr->counter), "r" (old), "r" (new)
1332 + : "cc");
1333 + } while (res);
1334 +
1335 + smp_mb();
1336 +
1337 + return oldval;
1338 +}
1339 +
1340 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1341 {
1342 u64 result;
1343 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1344
1345 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1346 {
1347 - u64 result;
1348 - unsigned long tmp;
1349 + u64 result, tmp;
1350
1351 smp_mb();
1352
1353 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1354 -"1: ldrexd %0, %H0, [%3]\n"
1355 -" subs %0, %0, #1\n"
1356 -" sbc %H0, %H0, #0\n"
1357 +"1: ldrexd %1, %H1, [%3]\n"
1358 +" subs %0, %1, #1\n"
1359 +" sbc %H0, %H1, #0\n"
1360 +
1361 +#ifdef CONFIG_PAX_REFCOUNT
1362 +" bvc 3f\n"
1363 +" mov %0, %1\n"
1364 +" mov %H0, %H1\n"
1365 +"2: bkpt 0xf103\n"
1366 +"3:\n"
1367 +#endif
1368 +
1369 " teq %H0, #0\n"
1370 -" bmi 2f\n"
1371 +" bmi 4f\n"
1372 " strexd %1, %0, %H0, [%3]\n"
1373 " teq %1, #0\n"
1374 " bne 1b\n"
1375 -"2:"
1376 +"4:\n"
1377 +
1378 +#ifdef CONFIG_PAX_REFCOUNT
1379 + _ASM_EXTABLE(2b, 4b)
1380 +#endif
1381 +
1382 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1383 : "r" (&v->counter)
1384 : "cc");
1385 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1386 " teq %0, %5\n"
1387 " teqeq %H0, %H5\n"
1388 " moveq %1, #0\n"
1389 -" beq 2f\n"
1390 +" beq 4f\n"
1391 " adds %0, %0, %6\n"
1392 " adc %H0, %H0, %H6\n"
1393 +
1394 +#ifdef CONFIG_PAX_REFCOUNT
1395 +" bvc 3f\n"
1396 +"2: bkpt 0xf103\n"
1397 +"3:\n"
1398 +#endif
1399 +
1400 " strexd %2, %0, %H0, [%4]\n"
1401 " teq %2, #0\n"
1402 " bne 1b\n"
1403 -"2:"
1404 +"4:\n"
1405 +
1406 +#ifdef CONFIG_PAX_REFCOUNT
1407 + _ASM_EXTABLE(2b, 4b)
1408 +#endif
1409 +
1410 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1411 : "r" (&v->counter), "r" (u), "r" (a)
1412 : "cc");
1413 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1414
1415 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1416 #define atomic64_inc(v) atomic64_add(1LL, (v))
1417 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1418 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1419 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1420 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1421 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1422 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1423 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1424 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1425 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1426 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1427 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1428 index 75fe66b..2255c86 100644
1429 --- a/arch/arm/include/asm/cache.h
1430 +++ b/arch/arm/include/asm/cache.h
1431 @@ -4,8 +4,10 @@
1432 #ifndef __ASMARM_CACHE_H
1433 #define __ASMARM_CACHE_H
1434
1435 +#include <linux/const.h>
1436 +
1437 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1438 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1439 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1440
1441 /*
1442 * Memory returned by kmalloc() may be used for DMA, so we must make
1443 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1444 index 004c1bc..d9d6d91 100644
1445 --- a/arch/arm/include/asm/cacheflush.h
1446 +++ b/arch/arm/include/asm/cacheflush.h
1447 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1448 void (*dma_unmap_area)(const void *, size_t, int);
1449
1450 void (*dma_flush_range)(const void *, const void *);
1451 -};
1452 +} __no_const;
1453
1454 /*
1455 * Select the calling method
1456 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1457 index 7eb18c1..e38b6d2 100644
1458 --- a/arch/arm/include/asm/cmpxchg.h
1459 +++ b/arch/arm/include/asm/cmpxchg.h
1460 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1461
1462 #define xchg(ptr,x) \
1463 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1464 +#define xchg_unchecked(ptr,x) \
1465 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1466
1467 #include <asm-generic/cmpxchg-local.h>
1468
1469 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1470 index 38050b1..9d90e8b 100644
1471 --- a/arch/arm/include/asm/elf.h
1472 +++ b/arch/arm/include/asm/elf.h
1473 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1474 the loader. We need to make sure that it is out of the way of the program
1475 that it will "exec", and that there is sufficient room for the brk. */
1476
1477 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1478 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1479 +
1480 +#ifdef CONFIG_PAX_ASLR
1481 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1482 +
1483 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1484 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1485 +#endif
1486
1487 /* When the program starts, a1 contains a pointer to a function to be
1488 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1489 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1490 extern void elf_set_personality(const struct elf32_hdr *);
1491 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1492
1493 -struct mm_struct;
1494 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1495 -#define arch_randomize_brk arch_randomize_brk
1496 -
1497 #endif
1498 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1499 index e51b1e8..32a3113 100644
1500 --- a/arch/arm/include/asm/kmap_types.h
1501 +++ b/arch/arm/include/asm/kmap_types.h
1502 @@ -21,6 +21,7 @@ enum km_type {
1503 KM_L1_CACHE,
1504 KM_L2_CACHE,
1505 KM_KDB,
1506 + KM_CLEARPAGE,
1507 KM_TYPE_NR
1508 };
1509
1510 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1511 index 53426c6..c7baff3 100644
1512 --- a/arch/arm/include/asm/outercache.h
1513 +++ b/arch/arm/include/asm/outercache.h
1514 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1515 #endif
1516 void (*set_debug)(unsigned long);
1517 void (*resume)(void);
1518 -};
1519 +} __no_const;
1520
1521 #ifdef CONFIG_OUTER_CACHE
1522
1523 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1524 index ecf9019..b71d9a1 100644
1525 --- a/arch/arm/include/asm/page.h
1526 +++ b/arch/arm/include/asm/page.h
1527 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1528 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1529 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1530 unsigned long vaddr, struct vm_area_struct *vma);
1531 -};
1532 +} __no_const;
1533
1534 #ifdef MULTI_USER
1535 extern struct cpu_user_fns cpu_user;
1536 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1537 index 943504f..bf8d667 100644
1538 --- a/arch/arm/include/asm/pgalloc.h
1539 +++ b/arch/arm/include/asm/pgalloc.h
1540 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1541 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1542 }
1543
1544 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1545 +{
1546 + pud_populate(mm, pud, pmd);
1547 +}
1548 +
1549 #else /* !CONFIG_ARM_LPAE */
1550
1551 /*
1552 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1553 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1554 #define pmd_free(mm, pmd) do { } while (0)
1555 #define pud_populate(mm,pmd,pte) BUG()
1556 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1557
1558 #endif /* CONFIG_ARM_LPAE */
1559
1560 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1561 index af7b0bd..6750a8c 100644
1562 --- a/arch/arm/include/asm/thread_info.h
1563 +++ b/arch/arm/include/asm/thread_info.h
1564 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1565 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1566 #define TIF_SYSCALL_TRACE 8
1567 #define TIF_SYSCALL_AUDIT 9
1568 +
1569 +/* within 8 bits of TIF_SYSCALL_TRACE
1570 + to meet flexible second operand requirements
1571 +*/
1572 +#define TIF_GRSEC_SETXID 10
1573 +
1574 #define TIF_POLLING_NRFLAG 16
1575 #define TIF_USING_IWMMXT 17
1576 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1577 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1578 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1579 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1580 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1581 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1582
1583 /* Checks for any syscall work in entry-common.S */
1584 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1585 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1586 + _TIF_GRSEC_SETXID)
1587
1588 /*
1589 * Change these and you break ASM code in entry-common.S
1590 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1591 index 71f6536..602f279 100644
1592 --- a/arch/arm/include/asm/uaccess.h
1593 +++ b/arch/arm/include/asm/uaccess.h
1594 @@ -22,6 +22,8 @@
1595 #define VERIFY_READ 0
1596 #define VERIFY_WRITE 1
1597
1598 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1599 +
1600 /*
1601 * The exception table consists of pairs of addresses: the first is the
1602 * address of an instruction that is allowed to fault, and the second is
1603 @@ -387,8 +389,23 @@ do { \
1604
1605
1606 #ifdef CONFIG_MMU
1607 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1608 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1609 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1610 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1611 +
1612 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1613 +{
1614 + if (!__builtin_constant_p(n))
1615 + check_object_size(to, n, false);
1616 + return ___copy_from_user(to, from, n);
1617 +}
1618 +
1619 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1620 +{
1621 + if (!__builtin_constant_p(n))
1622 + check_object_size(from, n, true);
1623 + return ___copy_to_user(to, from, n);
1624 +}
1625 +
1626 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1627 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1628 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1629 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1630
1631 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1632 {
1633 + if ((long)n < 0)
1634 + return n;
1635 +
1636 if (access_ok(VERIFY_READ, from, n))
1637 n = __copy_from_user(to, from, n);
1638 else /* security hole - plug it */
1639 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1640
1641 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1642 {
1643 + if ((long)n < 0)
1644 + return n;
1645 +
1646 if (access_ok(VERIFY_WRITE, to, n))
1647 n = __copy_to_user(to, from, n);
1648 return n;
1649 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1650 index b57c75e..ed2d6b2 100644
1651 --- a/arch/arm/kernel/armksyms.c
1652 +++ b/arch/arm/kernel/armksyms.c
1653 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1654 #ifdef CONFIG_MMU
1655 EXPORT_SYMBOL(copy_page);
1656
1657 -EXPORT_SYMBOL(__copy_from_user);
1658 -EXPORT_SYMBOL(__copy_to_user);
1659 +EXPORT_SYMBOL(___copy_from_user);
1660 +EXPORT_SYMBOL(___copy_to_user);
1661 EXPORT_SYMBOL(__clear_user);
1662
1663 EXPORT_SYMBOL(__get_user_1);
1664 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1665 index 19c95ea..7160f7c 100644
1666 --- a/arch/arm/kernel/process.c
1667 +++ b/arch/arm/kernel/process.c
1668 @@ -28,7 +28,6 @@
1669 #include <linux/tick.h>
1670 #include <linux/utsname.h>
1671 #include <linux/uaccess.h>
1672 -#include <linux/random.h>
1673 #include <linux/hw_breakpoint.h>
1674 #include <linux/cpuidle.h>
1675
1676 @@ -255,9 +254,10 @@ void machine_power_off(void)
1677 machine_shutdown();
1678 if (pm_power_off)
1679 pm_power_off();
1680 + BUG();
1681 }
1682
1683 -void machine_restart(char *cmd)
1684 +__noreturn void machine_restart(char *cmd)
1685 {
1686 machine_shutdown();
1687
1688 @@ -499,12 +499,6 @@ unsigned long get_wchan(struct task_struct *p)
1689 return 0;
1690 }
1691
1692 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1693 -{
1694 - unsigned long range_end = mm->brk + 0x02000000;
1695 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1696 -}
1697 -
1698 #ifdef CONFIG_MMU
1699 /*
1700 * The vectors page is always readable from user space for the
1701 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1702 index 14e3826..d832d89 100644
1703 --- a/arch/arm/kernel/ptrace.c
1704 +++ b/arch/arm/kernel/ptrace.c
1705 @@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1706 return ret;
1707 }
1708
1709 +#ifdef CONFIG_GRKERNSEC_SETXID
1710 +extern void gr_delayed_cred_worker(void);
1711 +#endif
1712 +
1713 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1714 {
1715 unsigned long ip;
1716
1717 +#ifdef CONFIG_GRKERNSEC_SETXID
1718 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1719 + gr_delayed_cred_worker();
1720 +#endif
1721 +
1722 if (why)
1723 audit_syscall_exit(regs);
1724 else
1725 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1726 index e15d83b..8c466dd 100644
1727 --- a/arch/arm/kernel/setup.c
1728 +++ b/arch/arm/kernel/setup.c
1729 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1730 struct cpu_tlb_fns cpu_tlb __read_mostly;
1731 #endif
1732 #ifdef MULTI_USER
1733 -struct cpu_user_fns cpu_user __read_mostly;
1734 +struct cpu_user_fns cpu_user __read_only;
1735 #endif
1736 #ifdef MULTI_CACHE
1737 -struct cpu_cache_fns cpu_cache __read_mostly;
1738 +struct cpu_cache_fns cpu_cache __read_only;
1739 #endif
1740 #ifdef CONFIG_OUTER_CACHE
1741 -struct outer_cache_fns outer_cache __read_mostly;
1742 +struct outer_cache_fns outer_cache __read_only;
1743 EXPORT_SYMBOL(outer_cache);
1744 #endif
1745
1746 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1747 index 3647170..065e1cd 100644
1748 --- a/arch/arm/kernel/traps.c
1749 +++ b/arch/arm/kernel/traps.c
1750 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1751
1752 static DEFINE_RAW_SPINLOCK(die_lock);
1753
1754 +extern void gr_handle_kernel_exploit(void);
1755 +
1756 /*
1757 * This function is protected against re-entrancy.
1758 */
1759 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1760 panic("Fatal exception in interrupt");
1761 if (panic_on_oops)
1762 panic("Fatal exception");
1763 +
1764 + gr_handle_kernel_exploit();
1765 +
1766 if (ret != NOTIFY_STOP)
1767 do_exit(SIGSEGV);
1768 }
1769 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1770 index 66a477a..bee61d3 100644
1771 --- a/arch/arm/lib/copy_from_user.S
1772 +++ b/arch/arm/lib/copy_from_user.S
1773 @@ -16,7 +16,7 @@
1774 /*
1775 * Prototype:
1776 *
1777 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1778 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1779 *
1780 * Purpose:
1781 *
1782 @@ -84,11 +84,11 @@
1783
1784 .text
1785
1786 -ENTRY(__copy_from_user)
1787 +ENTRY(___copy_from_user)
1788
1789 #include "copy_template.S"
1790
1791 -ENDPROC(__copy_from_user)
1792 +ENDPROC(___copy_from_user)
1793
1794 .pushsection .fixup,"ax"
1795 .align 0
1796 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1797 index 6ee2f67..d1cce76 100644
1798 --- a/arch/arm/lib/copy_page.S
1799 +++ b/arch/arm/lib/copy_page.S
1800 @@ -10,6 +10,7 @@
1801 * ASM optimised string functions
1802 */
1803 #include <linux/linkage.h>
1804 +#include <linux/const.h>
1805 #include <asm/assembler.h>
1806 #include <asm/asm-offsets.h>
1807 #include <asm/cache.h>
1808 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1809 index d066df6..df28194 100644
1810 --- a/arch/arm/lib/copy_to_user.S
1811 +++ b/arch/arm/lib/copy_to_user.S
1812 @@ -16,7 +16,7 @@
1813 /*
1814 * Prototype:
1815 *
1816 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1817 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1818 *
1819 * Purpose:
1820 *
1821 @@ -88,11 +88,11 @@
1822 .text
1823
1824 ENTRY(__copy_to_user_std)
1825 -WEAK(__copy_to_user)
1826 +WEAK(___copy_to_user)
1827
1828 #include "copy_template.S"
1829
1830 -ENDPROC(__copy_to_user)
1831 +ENDPROC(___copy_to_user)
1832 ENDPROC(__copy_to_user_std)
1833
1834 .pushsection .fixup,"ax"
1835 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1836 index 025f742..8432b08 100644
1837 --- a/arch/arm/lib/uaccess_with_memcpy.c
1838 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1839 @@ -104,7 +104,7 @@ out:
1840 }
1841
1842 unsigned long
1843 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1844 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1845 {
1846 /*
1847 * This test is stubbed out of the main function above to keep
1848 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1849 index f261cd2..4ae63fb 100644
1850 --- a/arch/arm/mach-kirkwood/common.c
1851 +++ b/arch/arm/mach-kirkwood/common.c
1852 @@ -128,7 +128,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1853 clk_gate_ops.disable(hw);
1854 }
1855
1856 -static struct clk_ops clk_gate_fn_ops;
1857 +static clk_ops_no_const clk_gate_fn_ops;
1858
1859 static struct clk __init *clk_register_gate_fn(struct device *dev,
1860 const char *name,
1861 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1862 index 2c5d0ed..7d9099c 100644
1863 --- a/arch/arm/mach-omap2/board-n8x0.c
1864 +++ b/arch/arm/mach-omap2/board-n8x0.c
1865 @@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1866 }
1867 #endif
1868
1869 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1870 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1871 .late_init = n8x0_menelaus_late_init,
1872 };
1873
1874 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1875 index c3bd834..e81ef02 100644
1876 --- a/arch/arm/mm/fault.c
1877 +++ b/arch/arm/mm/fault.c
1878 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1879 }
1880 #endif
1881
1882 +#ifdef CONFIG_PAX_PAGEEXEC
1883 + if (fsr & FSR_LNX_PF) {
1884 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1885 + do_group_exit(SIGKILL);
1886 + }
1887 +#endif
1888 +
1889 tsk->thread.address = addr;
1890 tsk->thread.error_code = fsr;
1891 tsk->thread.trap_no = 14;
1892 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1893 }
1894 #endif /* CONFIG_MMU */
1895
1896 +#ifdef CONFIG_PAX_PAGEEXEC
1897 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1898 +{
1899 + long i;
1900 +
1901 + printk(KERN_ERR "PAX: bytes at PC: ");
1902 + for (i = 0; i < 20; i++) {
1903 + unsigned char c;
1904 + if (get_user(c, (__force unsigned char __user *)pc+i))
1905 + printk(KERN_CONT "?? ");
1906 + else
1907 + printk(KERN_CONT "%02x ", c);
1908 + }
1909 + printk("\n");
1910 +
1911 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1912 + for (i = -1; i < 20; i++) {
1913 + unsigned long c;
1914 + if (get_user(c, (__force unsigned long __user *)sp+i))
1915 + printk(KERN_CONT "???????? ");
1916 + else
1917 + printk(KERN_CONT "%08lx ", c);
1918 + }
1919 + printk("\n");
1920 +}
1921 +#endif
1922 +
1923 /*
1924 * First Level Translation Fault Handler
1925 *
1926 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1927 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1928 struct siginfo info;
1929
1930 +#ifdef CONFIG_PAX_REFCOUNT
1931 + if (fsr_fs(ifsr) == 2) {
1932 + unsigned int bkpt;
1933 +
1934 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1935 + current->thread.error_code = ifsr;
1936 + current->thread.trap_no = 0;
1937 + pax_report_refcount_overflow(regs);
1938 + fixup_exception(regs);
1939 + return;
1940 + }
1941 + }
1942 +#endif
1943 +
1944 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1945 return;
1946
1947 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1948 index ce8cb19..3ec539d 100644
1949 --- a/arch/arm/mm/mmap.c
1950 +++ b/arch/arm/mm/mmap.c
1951 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1952 if (len > TASK_SIZE)
1953 return -ENOMEM;
1954
1955 +#ifdef CONFIG_PAX_RANDMMAP
1956 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1957 +#endif
1958 +
1959 if (addr) {
1960 if (do_align)
1961 addr = COLOUR_ALIGN(addr, pgoff);
1962 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1963 addr = PAGE_ALIGN(addr);
1964
1965 vma = find_vma(mm, addr);
1966 - if (TASK_SIZE - len >= addr &&
1967 - (!vma || addr + len <= vma->vm_start))
1968 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1969 return addr;
1970 }
1971 if (len > mm->cached_hole_size) {
1972 - start_addr = addr = mm->free_area_cache;
1973 + start_addr = addr = mm->free_area_cache;
1974 } else {
1975 - start_addr = addr = mm->mmap_base;
1976 - mm->cached_hole_size = 0;
1977 + start_addr = addr = mm->mmap_base;
1978 + mm->cached_hole_size = 0;
1979 }
1980
1981 full_search:
1982 @@ -124,14 +127,14 @@ full_search:
1983 * Start a new search - just in case we missed
1984 * some holes.
1985 */
1986 - if (start_addr != TASK_UNMAPPED_BASE) {
1987 - start_addr = addr = TASK_UNMAPPED_BASE;
1988 + if (start_addr != mm->mmap_base) {
1989 + start_addr = addr = mm->mmap_base;
1990 mm->cached_hole_size = 0;
1991 goto full_search;
1992 }
1993 return -ENOMEM;
1994 }
1995 - if (!vma || addr + len <= vma->vm_start) {
1996 + if (check_heap_stack_gap(vma, addr, len)) {
1997 /*
1998 * Remember the place where we stopped the search:
1999 */
2000 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2001
2002 if (mmap_is_legacy()) {
2003 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2004 +
2005 +#ifdef CONFIG_PAX_RANDMMAP
2006 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2007 + mm->mmap_base += mm->delta_mmap;
2008 +#endif
2009 +
2010 mm->get_unmapped_area = arch_get_unmapped_area;
2011 mm->unmap_area = arch_unmap_area;
2012 } else {
2013 mm->mmap_base = mmap_base(random_factor);
2014 +
2015 +#ifdef CONFIG_PAX_RANDMMAP
2016 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2017 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2018 +#endif
2019 +
2020 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2021 mm->unmap_area = arch_unmap_area_topdown;
2022 }
2023 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2024 index fd556f7..af2e7d2 100644
2025 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2026 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2027 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2028 value in bridge_virt_base */
2029 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2030 const int win);
2031 -};
2032 +} __no_const;
2033
2034 /*
2035 * Information needed to setup one address mapping.
2036 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2037 index 71a6827..e7fbc23 100644
2038 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2039 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2040 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2041 int (*started)(unsigned ch);
2042 int (*flush)(unsigned ch);
2043 int (*stop)(unsigned ch);
2044 -};
2045 +} __no_const;
2046
2047 extern void *samsung_dmadev_get_ops(void);
2048 extern void *s3c_dma_get_ops(void);
2049 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2050 index 5f28cae..3d23723 100644
2051 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2052 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2053 @@ -14,7 +14,7 @@
2054 struct s5p_ehci_platdata {
2055 int (*phy_init)(struct platform_device *pdev, int type);
2056 int (*phy_exit)(struct platform_device *pdev, int type);
2057 -};
2058 +} __no_const;
2059
2060 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2061
2062 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2063 index c3a58a1..78fbf54 100644
2064 --- a/arch/avr32/include/asm/cache.h
2065 +++ b/arch/avr32/include/asm/cache.h
2066 @@ -1,8 +1,10 @@
2067 #ifndef __ASM_AVR32_CACHE_H
2068 #define __ASM_AVR32_CACHE_H
2069
2070 +#include <linux/const.h>
2071 +
2072 #define L1_CACHE_SHIFT 5
2073 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2074 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2075
2076 /*
2077 * Memory returned by kmalloc() may be used for DMA, so we must make
2078 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2079 index 3b3159b..425ea94 100644
2080 --- a/arch/avr32/include/asm/elf.h
2081 +++ b/arch/avr32/include/asm/elf.h
2082 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2083 the loader. We need to make sure that it is out of the way of the program
2084 that it will "exec", and that there is sufficient room for the brk. */
2085
2086 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2087 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2088
2089 +#ifdef CONFIG_PAX_ASLR
2090 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2091 +
2092 +#define PAX_DELTA_MMAP_LEN 15
2093 +#define PAX_DELTA_STACK_LEN 15
2094 +#endif
2095
2096 /* This yields a mask that user programs can use to figure out what
2097 instruction set this CPU supports. This could be done in user space,
2098 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2099 index b7f5c68..556135c 100644
2100 --- a/arch/avr32/include/asm/kmap_types.h
2101 +++ b/arch/avr32/include/asm/kmap_types.h
2102 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2103 D(11) KM_IRQ1,
2104 D(12) KM_SOFTIRQ0,
2105 D(13) KM_SOFTIRQ1,
2106 -D(14) KM_TYPE_NR
2107 +D(14) KM_CLEARPAGE,
2108 +D(15) KM_TYPE_NR
2109 };
2110
2111 #undef D
2112 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2113 index f7040a1..db9f300 100644
2114 --- a/arch/avr32/mm/fault.c
2115 +++ b/arch/avr32/mm/fault.c
2116 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2117
2118 int exception_trace = 1;
2119
2120 +#ifdef CONFIG_PAX_PAGEEXEC
2121 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2122 +{
2123 + unsigned long i;
2124 +
2125 + printk(KERN_ERR "PAX: bytes at PC: ");
2126 + for (i = 0; i < 20; i++) {
2127 + unsigned char c;
2128 + if (get_user(c, (unsigned char *)pc+i))
2129 + printk(KERN_CONT "???????? ");
2130 + else
2131 + printk(KERN_CONT "%02x ", c);
2132 + }
2133 + printk("\n");
2134 +}
2135 +#endif
2136 +
2137 /*
2138 * This routine handles page faults. It determines the address and the
2139 * problem, and then passes it off to one of the appropriate routines.
2140 @@ -156,6 +173,16 @@ bad_area:
2141 up_read(&mm->mmap_sem);
2142
2143 if (user_mode(regs)) {
2144 +
2145 +#ifdef CONFIG_PAX_PAGEEXEC
2146 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2147 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2148 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2149 + do_group_exit(SIGKILL);
2150 + }
2151 + }
2152 +#endif
2153 +
2154 if (exception_trace && printk_ratelimit())
2155 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2156 "sp %08lx ecr %lu\n",
2157 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2158 index 568885a..f8008df 100644
2159 --- a/arch/blackfin/include/asm/cache.h
2160 +++ b/arch/blackfin/include/asm/cache.h
2161 @@ -7,6 +7,7 @@
2162 #ifndef __ARCH_BLACKFIN_CACHE_H
2163 #define __ARCH_BLACKFIN_CACHE_H
2164
2165 +#include <linux/const.h>
2166 #include <linux/linkage.h> /* for asmlinkage */
2167
2168 /*
2169 @@ -14,7 +15,7 @@
2170 * Blackfin loads 32 bytes for cache
2171 */
2172 #define L1_CACHE_SHIFT 5
2173 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2174 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2175 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2176
2177 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2178 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2179 index aea2718..3639a60 100644
2180 --- a/arch/cris/include/arch-v10/arch/cache.h
2181 +++ b/arch/cris/include/arch-v10/arch/cache.h
2182 @@ -1,8 +1,9 @@
2183 #ifndef _ASM_ARCH_CACHE_H
2184 #define _ASM_ARCH_CACHE_H
2185
2186 +#include <linux/const.h>
2187 /* Etrax 100LX have 32-byte cache-lines. */
2188 -#define L1_CACHE_BYTES 32
2189 #define L1_CACHE_SHIFT 5
2190 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2191
2192 #endif /* _ASM_ARCH_CACHE_H */
2193 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2194 index 7caf25d..ee65ac5 100644
2195 --- a/arch/cris/include/arch-v32/arch/cache.h
2196 +++ b/arch/cris/include/arch-v32/arch/cache.h
2197 @@ -1,11 +1,12 @@
2198 #ifndef _ASM_CRIS_ARCH_CACHE_H
2199 #define _ASM_CRIS_ARCH_CACHE_H
2200
2201 +#include <linux/const.h>
2202 #include <arch/hwregs/dma.h>
2203
2204 /* A cache-line is 32 bytes. */
2205 -#define L1_CACHE_BYTES 32
2206 #define L1_CACHE_SHIFT 5
2207 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2208
2209 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2210
2211 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2212 index b86329d..6709906 100644
2213 --- a/arch/frv/include/asm/atomic.h
2214 +++ b/arch/frv/include/asm/atomic.h
2215 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2216 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2217 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2218
2219 +#define atomic64_read_unchecked(v) atomic64_read(v)
2220 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2221 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2222 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2223 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2224 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2225 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2226 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2227 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2228 +
2229 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2230 {
2231 int c, old;
2232 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2233 index 2797163..c2a401d 100644
2234 --- a/arch/frv/include/asm/cache.h
2235 +++ b/arch/frv/include/asm/cache.h
2236 @@ -12,10 +12,11 @@
2237 #ifndef __ASM_CACHE_H
2238 #define __ASM_CACHE_H
2239
2240 +#include <linux/const.h>
2241
2242 /* bytes per L1 cache line */
2243 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2244 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2245 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2246
2247 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2248 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2249 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2250 index f8e16b2..c73ff79 100644
2251 --- a/arch/frv/include/asm/kmap_types.h
2252 +++ b/arch/frv/include/asm/kmap_types.h
2253 @@ -23,6 +23,7 @@ enum km_type {
2254 KM_IRQ1,
2255 KM_SOFTIRQ0,
2256 KM_SOFTIRQ1,
2257 + KM_CLEARPAGE,
2258 KM_TYPE_NR
2259 };
2260
2261 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2262 index 385fd30..6c3d97e 100644
2263 --- a/arch/frv/mm/elf-fdpic.c
2264 +++ b/arch/frv/mm/elf-fdpic.c
2265 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2266 if (addr) {
2267 addr = PAGE_ALIGN(addr);
2268 vma = find_vma(current->mm, addr);
2269 - if (TASK_SIZE - len >= addr &&
2270 - (!vma || addr + len <= vma->vm_start))
2271 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2272 goto success;
2273 }
2274
2275 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2276 for (; vma; vma = vma->vm_next) {
2277 if (addr > limit)
2278 break;
2279 - if (addr + len <= vma->vm_start)
2280 + if (check_heap_stack_gap(vma, addr, len))
2281 goto success;
2282 addr = vma->vm_end;
2283 }
2284 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2285 for (; vma; vma = vma->vm_next) {
2286 if (addr > limit)
2287 break;
2288 - if (addr + len <= vma->vm_start)
2289 + if (check_heap_stack_gap(vma, addr, len))
2290 goto success;
2291 addr = vma->vm_end;
2292 }
2293 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2294 index c635028..6d9445a 100644
2295 --- a/arch/h8300/include/asm/cache.h
2296 +++ b/arch/h8300/include/asm/cache.h
2297 @@ -1,8 +1,10 @@
2298 #ifndef __ARCH_H8300_CACHE_H
2299 #define __ARCH_H8300_CACHE_H
2300
2301 +#include <linux/const.h>
2302 +
2303 /* bytes per L1 cache line */
2304 -#define L1_CACHE_BYTES 4
2305 +#define L1_CACHE_BYTES _AC(4,UL)
2306
2307 /* m68k-elf-gcc 2.95.2 doesn't like these */
2308
2309 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2310 index 0f01de2..d37d309 100644
2311 --- a/arch/hexagon/include/asm/cache.h
2312 +++ b/arch/hexagon/include/asm/cache.h
2313 @@ -21,9 +21,11 @@
2314 #ifndef __ASM_CACHE_H
2315 #define __ASM_CACHE_H
2316
2317 +#include <linux/const.h>
2318 +
2319 /* Bytes per L1 cache line */
2320 -#define L1_CACHE_SHIFT (5)
2321 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2322 +#define L1_CACHE_SHIFT 5
2323 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2324
2325 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2326 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2327 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2328 index 7d91166..88ab87e 100644
2329 --- a/arch/ia64/include/asm/atomic.h
2330 +++ b/arch/ia64/include/asm/atomic.h
2331 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2332 #define atomic64_inc(v) atomic64_add(1, (v))
2333 #define atomic64_dec(v) atomic64_sub(1, (v))
2334
2335 +#define atomic64_read_unchecked(v) atomic64_read(v)
2336 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2337 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2338 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2339 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2340 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2341 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2342 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2343 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2344 +
2345 /* Atomic operations are already serializing */
2346 #define smp_mb__before_atomic_dec() barrier()
2347 #define smp_mb__after_atomic_dec() barrier()
2348 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2349 index 988254a..e1ee885 100644
2350 --- a/arch/ia64/include/asm/cache.h
2351 +++ b/arch/ia64/include/asm/cache.h
2352 @@ -1,6 +1,7 @@
2353 #ifndef _ASM_IA64_CACHE_H
2354 #define _ASM_IA64_CACHE_H
2355
2356 +#include <linux/const.h>
2357
2358 /*
2359 * Copyright (C) 1998-2000 Hewlett-Packard Co
2360 @@ -9,7 +10,7 @@
2361
2362 /* Bytes per L1 (data) cache line. */
2363 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2364 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2365 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2366
2367 #ifdef CONFIG_SMP
2368 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2369 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2370 index b5298eb..67c6e62 100644
2371 --- a/arch/ia64/include/asm/elf.h
2372 +++ b/arch/ia64/include/asm/elf.h
2373 @@ -42,6 +42,13 @@
2374 */
2375 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2376
2377 +#ifdef CONFIG_PAX_ASLR
2378 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2379 +
2380 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2381 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2382 +#endif
2383 +
2384 #define PT_IA_64_UNWIND 0x70000001
2385
2386 /* IA-64 relocations: */
2387 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2388 index 96a8d92..617a1cf 100644
2389 --- a/arch/ia64/include/asm/pgalloc.h
2390 +++ b/arch/ia64/include/asm/pgalloc.h
2391 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2392 pgd_val(*pgd_entry) = __pa(pud);
2393 }
2394
2395 +static inline void
2396 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2397 +{
2398 + pgd_populate(mm, pgd_entry, pud);
2399 +}
2400 +
2401 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2402 {
2403 return quicklist_alloc(0, GFP_KERNEL, NULL);
2404 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2405 pud_val(*pud_entry) = __pa(pmd);
2406 }
2407
2408 +static inline void
2409 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2410 +{
2411 + pud_populate(mm, pud_entry, pmd);
2412 +}
2413 +
2414 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2415 {
2416 return quicklist_alloc(0, GFP_KERNEL, NULL);
2417 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2418 index 815810c..d60bd4c 100644
2419 --- a/arch/ia64/include/asm/pgtable.h
2420 +++ b/arch/ia64/include/asm/pgtable.h
2421 @@ -12,7 +12,7 @@
2422 * David Mosberger-Tang <davidm@hpl.hp.com>
2423 */
2424
2425 -
2426 +#include <linux/const.h>
2427 #include <asm/mman.h>
2428 #include <asm/page.h>
2429 #include <asm/processor.h>
2430 @@ -142,6 +142,17 @@
2431 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2432 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2434 +
2435 +#ifdef CONFIG_PAX_PAGEEXEC
2436 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2437 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2438 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2439 +#else
2440 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2441 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2442 +# define PAGE_COPY_NOEXEC PAGE_COPY
2443 +#endif
2444 +
2445 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2446 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2447 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2448 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2449 index 54ff557..70c88b7 100644
2450 --- a/arch/ia64/include/asm/spinlock.h
2451 +++ b/arch/ia64/include/asm/spinlock.h
2452 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2453 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2454
2455 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2456 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2457 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2458 }
2459
2460 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2461 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2462 index 449c8c0..432a3d2 100644
2463 --- a/arch/ia64/include/asm/uaccess.h
2464 +++ b/arch/ia64/include/asm/uaccess.h
2465 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2466 const void *__cu_from = (from); \
2467 long __cu_len = (n); \
2468 \
2469 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2470 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2471 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2472 __cu_len; \
2473 })
2474 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2475 long __cu_len = (n); \
2476 \
2477 __chk_user_ptr(__cu_from); \
2478 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2479 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2480 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2481 __cu_len; \
2482 })
2483 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2484 index 24603be..948052d 100644
2485 --- a/arch/ia64/kernel/module.c
2486 +++ b/arch/ia64/kernel/module.c
2487 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2488 void
2489 module_free (struct module *mod, void *module_region)
2490 {
2491 - if (mod && mod->arch.init_unw_table &&
2492 - module_region == mod->module_init) {
2493 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2494 unw_remove_unwind_table(mod->arch.init_unw_table);
2495 mod->arch.init_unw_table = NULL;
2496 }
2497 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2498 }
2499
2500 static inline int
2501 +in_init_rx (const struct module *mod, uint64_t addr)
2502 +{
2503 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2504 +}
2505 +
2506 +static inline int
2507 +in_init_rw (const struct module *mod, uint64_t addr)
2508 +{
2509 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2510 +}
2511 +
2512 +static inline int
2513 in_init (const struct module *mod, uint64_t addr)
2514 {
2515 - return addr - (uint64_t) mod->module_init < mod->init_size;
2516 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2517 +}
2518 +
2519 +static inline int
2520 +in_core_rx (const struct module *mod, uint64_t addr)
2521 +{
2522 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2523 +}
2524 +
2525 +static inline int
2526 +in_core_rw (const struct module *mod, uint64_t addr)
2527 +{
2528 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2529 }
2530
2531 static inline int
2532 in_core (const struct module *mod, uint64_t addr)
2533 {
2534 - return addr - (uint64_t) mod->module_core < mod->core_size;
2535 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2536 }
2537
2538 static inline int
2539 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2540 break;
2541
2542 case RV_BDREL:
2543 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2544 + if (in_init_rx(mod, val))
2545 + val -= (uint64_t) mod->module_init_rx;
2546 + else if (in_init_rw(mod, val))
2547 + val -= (uint64_t) mod->module_init_rw;
2548 + else if (in_core_rx(mod, val))
2549 + val -= (uint64_t) mod->module_core_rx;
2550 + else if (in_core_rw(mod, val))
2551 + val -= (uint64_t) mod->module_core_rw;
2552 break;
2553
2554 case RV_LTV:
2555 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2556 * addresses have been selected...
2557 */
2558 uint64_t gp;
2559 - if (mod->core_size > MAX_LTOFF)
2560 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2561 /*
2562 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2563 * at the end of the module.
2564 */
2565 - gp = mod->core_size - MAX_LTOFF / 2;
2566 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2567 else
2568 - gp = mod->core_size / 2;
2569 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2570 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2571 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2572 mod->arch.gp = gp;
2573 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2574 }
2575 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2576 index d9439ef..b9a4303 100644
2577 --- a/arch/ia64/kernel/sys_ia64.c
2578 +++ b/arch/ia64/kernel/sys_ia64.c
2579 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2580 if (REGION_NUMBER(addr) == RGN_HPAGE)
2581 addr = 0;
2582 #endif
2583 +
2584 +#ifdef CONFIG_PAX_RANDMMAP
2585 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2586 + addr = mm->free_area_cache;
2587 + else
2588 +#endif
2589 +
2590 if (!addr)
2591 addr = mm->free_area_cache;
2592
2593 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2594 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2595 /* At this point: (!vma || addr < vma->vm_end). */
2596 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2597 - if (start_addr != TASK_UNMAPPED_BASE) {
2598 + if (start_addr != mm->mmap_base) {
2599 /* Start a new search --- just in case we missed some holes. */
2600 - addr = TASK_UNMAPPED_BASE;
2601 + addr = mm->mmap_base;
2602 goto full_search;
2603 }
2604 return -ENOMEM;
2605 }
2606 - if (!vma || addr + len <= vma->vm_start) {
2607 + if (check_heap_stack_gap(vma, addr, len)) {
2608 /* Remember the address where we stopped this search: */
2609 mm->free_area_cache = addr + len;
2610 return addr;
2611 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2612 index 0ccb28f..8992469 100644
2613 --- a/arch/ia64/kernel/vmlinux.lds.S
2614 +++ b/arch/ia64/kernel/vmlinux.lds.S
2615 @@ -198,7 +198,7 @@ SECTIONS {
2616 /* Per-cpu data: */
2617 . = ALIGN(PERCPU_PAGE_SIZE);
2618 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2619 - __phys_per_cpu_start = __per_cpu_load;
2620 + __phys_per_cpu_start = per_cpu_load;
2621 /*
2622 * ensure percpu data fits
2623 * into percpu page size
2624 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2625 index 02d29c2..ea893df 100644
2626 --- a/arch/ia64/mm/fault.c
2627 +++ b/arch/ia64/mm/fault.c
2628 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2629 return pte_present(pte);
2630 }
2631
2632 +#ifdef CONFIG_PAX_PAGEEXEC
2633 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2634 +{
2635 + unsigned long i;
2636 +
2637 + printk(KERN_ERR "PAX: bytes at PC: ");
2638 + for (i = 0; i < 8; i++) {
2639 + unsigned int c;
2640 + if (get_user(c, (unsigned int *)pc+i))
2641 + printk(KERN_CONT "???????? ");
2642 + else
2643 + printk(KERN_CONT "%08x ", c);
2644 + }
2645 + printk("\n");
2646 +}
2647 +#endif
2648 +
2649 void __kprobes
2650 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2651 {
2652 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2653 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2654 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2655
2656 - if ((vma->vm_flags & mask) != mask)
2657 + if ((vma->vm_flags & mask) != mask) {
2658 +
2659 +#ifdef CONFIG_PAX_PAGEEXEC
2660 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2661 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2662 + goto bad_area;
2663 +
2664 + up_read(&mm->mmap_sem);
2665 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2666 + do_group_exit(SIGKILL);
2667 + }
2668 +#endif
2669 +
2670 goto bad_area;
2671
2672 + }
2673 +
2674 /*
2675 * If for any reason at all we couldn't handle the fault, make
2676 * sure we exit gracefully rather than endlessly redo the
2677 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2678 index 5ca674b..e0e1b70 100644
2679 --- a/arch/ia64/mm/hugetlbpage.c
2680 +++ b/arch/ia64/mm/hugetlbpage.c
2681 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2682 /* At this point: (!vmm || addr < vmm->vm_end). */
2683 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2684 return -ENOMEM;
2685 - if (!vmm || (addr + len) <= vmm->vm_start)
2686 + if (check_heap_stack_gap(vmm, addr, len))
2687 return addr;
2688 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2689 }
2690 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2691 index 0eab454..bd794f2 100644
2692 --- a/arch/ia64/mm/init.c
2693 +++ b/arch/ia64/mm/init.c
2694 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2695 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2696 vma->vm_end = vma->vm_start + PAGE_SIZE;
2697 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2698 +
2699 +#ifdef CONFIG_PAX_PAGEEXEC
2700 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2701 + vma->vm_flags &= ~VM_EXEC;
2702 +
2703 +#ifdef CONFIG_PAX_MPROTECT
2704 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2705 + vma->vm_flags &= ~VM_MAYEXEC;
2706 +#endif
2707 +
2708 + }
2709 +#endif
2710 +
2711 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2712 down_write(&current->mm->mmap_sem);
2713 if (insert_vm_struct(current->mm, vma)) {
2714 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2715 index 40b3ee9..8c2c112 100644
2716 --- a/arch/m32r/include/asm/cache.h
2717 +++ b/arch/m32r/include/asm/cache.h
2718 @@ -1,8 +1,10 @@
2719 #ifndef _ASM_M32R_CACHE_H
2720 #define _ASM_M32R_CACHE_H
2721
2722 +#include <linux/const.h>
2723 +
2724 /* L1 cache line size */
2725 #define L1_CACHE_SHIFT 4
2726 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2727 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2728
2729 #endif /* _ASM_M32R_CACHE_H */
2730 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2731 index 82abd15..d95ae5d 100644
2732 --- a/arch/m32r/lib/usercopy.c
2733 +++ b/arch/m32r/lib/usercopy.c
2734 @@ -14,6 +14,9 @@
2735 unsigned long
2736 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2737 {
2738 + if ((long)n < 0)
2739 + return n;
2740 +
2741 prefetch(from);
2742 if (access_ok(VERIFY_WRITE, to, n))
2743 __copy_user(to,from,n);
2744 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2745 unsigned long
2746 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2747 {
2748 + if ((long)n < 0)
2749 + return n;
2750 +
2751 prefetchw(to);
2752 if (access_ok(VERIFY_READ, from, n))
2753 __copy_user_zeroing(to,from,n);
2754 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2755 index 0395c51..5f26031 100644
2756 --- a/arch/m68k/include/asm/cache.h
2757 +++ b/arch/m68k/include/asm/cache.h
2758 @@ -4,9 +4,11 @@
2759 #ifndef __ARCH_M68K_CACHE_H
2760 #define __ARCH_M68K_CACHE_H
2761
2762 +#include <linux/const.h>
2763 +
2764 /* bytes per L1 cache line */
2765 #define L1_CACHE_SHIFT 4
2766 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2767 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2768
2769 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2770
2771 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2772 index 4efe96a..60e8699 100644
2773 --- a/arch/microblaze/include/asm/cache.h
2774 +++ b/arch/microblaze/include/asm/cache.h
2775 @@ -13,11 +13,12 @@
2776 #ifndef _ASM_MICROBLAZE_CACHE_H
2777 #define _ASM_MICROBLAZE_CACHE_H
2778
2779 +#include <linux/const.h>
2780 #include <asm/registers.h>
2781
2782 #define L1_CACHE_SHIFT 5
2783 /* word-granular cache in microblaze */
2784 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2785 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2786
2787 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2788
2789 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2790 index 3f4c5cb..3439c6e 100644
2791 --- a/arch/mips/include/asm/atomic.h
2792 +++ b/arch/mips/include/asm/atomic.h
2793 @@ -21,6 +21,10 @@
2794 #include <asm/cmpxchg.h>
2795 #include <asm/war.h>
2796
2797 +#ifdef CONFIG_GENERIC_ATOMIC64
2798 +#include <asm-generic/atomic64.h>
2799 +#endif
2800 +
2801 #define ATOMIC_INIT(i) { (i) }
2802
2803 /*
2804 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2805 */
2806 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2807
2808 +#define atomic64_read_unchecked(v) atomic64_read(v)
2809 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2810 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2811 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2812 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2813 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2814 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2815 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2816 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2817 +
2818 #endif /* CONFIG_64BIT */
2819
2820 /*
2821 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2822 index b4db69f..8f3b093 100644
2823 --- a/arch/mips/include/asm/cache.h
2824 +++ b/arch/mips/include/asm/cache.h
2825 @@ -9,10 +9,11 @@
2826 #ifndef _ASM_CACHE_H
2827 #define _ASM_CACHE_H
2828
2829 +#include <linux/const.h>
2830 #include <kmalloc.h>
2831
2832 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2833 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2834 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2835
2836 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2837 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2838 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2839 index 455c0ac..ad65fbe 100644
2840 --- a/arch/mips/include/asm/elf.h
2841 +++ b/arch/mips/include/asm/elf.h
2842 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2843 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2844 #endif
2845
2846 +#ifdef CONFIG_PAX_ASLR
2847 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2848 +
2849 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2850 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2851 +#endif
2852 +
2853 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2854 struct linux_binprm;
2855 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2856 int uses_interp);
2857
2858 -struct mm_struct;
2859 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2860 -#define arch_randomize_brk arch_randomize_brk
2861 -
2862 #endif /* _ASM_ELF_H */
2863 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2864 index c1f6afa..38cc6e9 100644
2865 --- a/arch/mips/include/asm/exec.h
2866 +++ b/arch/mips/include/asm/exec.h
2867 @@ -12,6 +12,6 @@
2868 #ifndef _ASM_EXEC_H
2869 #define _ASM_EXEC_H
2870
2871 -extern unsigned long arch_align_stack(unsigned long sp);
2872 +#define arch_align_stack(x) ((x) & ~0xfUL)
2873
2874 #endif /* _ASM_EXEC_H */
2875 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2876 index da9bd7d..91aa7ab 100644
2877 --- a/arch/mips/include/asm/page.h
2878 +++ b/arch/mips/include/asm/page.h
2879 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2880 #ifdef CONFIG_CPU_MIPS32
2881 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2882 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2883 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2884 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2885 #else
2886 typedef struct { unsigned long long pte; } pte_t;
2887 #define pte_val(x) ((x).pte)
2888 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2889 index 881d18b..cea38bc 100644
2890 --- a/arch/mips/include/asm/pgalloc.h
2891 +++ b/arch/mips/include/asm/pgalloc.h
2892 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2893 {
2894 set_pud(pud, __pud((unsigned long)pmd));
2895 }
2896 +
2897 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2898 +{
2899 + pud_populate(mm, pud, pmd);
2900 +}
2901 #endif
2902
2903 /*
2904 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2905 index ca97e0e..cd08920 100644
2906 --- a/arch/mips/include/asm/thread_info.h
2907 +++ b/arch/mips/include/asm/thread_info.h
2908 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2909 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2910 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2911 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2912 +/* li takes a 32bit immediate */
2913 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2914 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2915
2916 #ifdef CONFIG_MIPS32_O32
2917 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2918 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2919 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2920 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2921 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2922 +
2923 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2924
2925 /* work to do in syscall_trace_leave() */
2926 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2927 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2928
2929 /* work to do on interrupt/exception return */
2930 #define _TIF_WORK_MASK (0x0000ffef & \
2931 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2932 /* work to do on any return to u-space */
2933 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2934 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2935
2936 #endif /* __KERNEL__ */
2937
2938 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2939 index 9fdd8bc..4bd7f1a 100644
2940 --- a/arch/mips/kernel/binfmt_elfn32.c
2941 +++ b/arch/mips/kernel/binfmt_elfn32.c
2942 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2943 #undef ELF_ET_DYN_BASE
2944 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2945
2946 +#ifdef CONFIG_PAX_ASLR
2947 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2948 +
2949 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2950 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2951 +#endif
2952 +
2953 #include <asm/processor.h>
2954 #include <linux/module.h>
2955 #include <linux/elfcore.h>
2956 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2957 index ff44823..97f8906 100644
2958 --- a/arch/mips/kernel/binfmt_elfo32.c
2959 +++ b/arch/mips/kernel/binfmt_elfo32.c
2960 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2961 #undef ELF_ET_DYN_BASE
2962 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2963
2964 +#ifdef CONFIG_PAX_ASLR
2965 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2966 +
2967 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2968 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2969 +#endif
2970 +
2971 #include <asm/processor.h>
2972
2973 /*
2974 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2975 index e9a5fd7..378809a 100644
2976 --- a/arch/mips/kernel/process.c
2977 +++ b/arch/mips/kernel/process.c
2978 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2979 out:
2980 return pc;
2981 }
2982 -
2983 -/*
2984 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2985 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2986 - */
2987 -unsigned long arch_align_stack(unsigned long sp)
2988 -{
2989 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2990 - sp -= get_random_int() & ~PAGE_MASK;
2991 -
2992 - return sp & ALMASK;
2993 -}
2994 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2995 index 4812c6d..2069554 100644
2996 --- a/arch/mips/kernel/ptrace.c
2997 +++ b/arch/mips/kernel/ptrace.c
2998 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2999 return arch;
3000 }
3001
3002 +#ifdef CONFIG_GRKERNSEC_SETXID
3003 +extern void gr_delayed_cred_worker(void);
3004 +#endif
3005 +
3006 /*
3007 * Notification of system call entry/exit
3008 * - triggered by current->work.syscall_trace
3009 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3010 /* do the secure computing check first */
3011 secure_computing_strict(regs->regs[2]);
3012
3013 +#ifdef CONFIG_GRKERNSEC_SETXID
3014 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3015 + gr_delayed_cred_worker();
3016 +#endif
3017 +
3018 if (!(current->ptrace & PT_PTRACED))
3019 goto out;
3020
3021 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3022 index a632bc1..0b77c7c 100644
3023 --- a/arch/mips/kernel/scall32-o32.S
3024 +++ b/arch/mips/kernel/scall32-o32.S
3025 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3026
3027 stack_done:
3028 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3029 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3030 + li t1, _TIF_SYSCALL_WORK
3031 and t0, t1
3032 bnez t0, syscall_trace_entry # -> yes
3033
3034 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3035 index 3b5a5e9..e1ee86d 100644
3036 --- a/arch/mips/kernel/scall64-64.S
3037 +++ b/arch/mips/kernel/scall64-64.S
3038 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3039
3040 sd a3, PT_R26(sp) # save a3 for syscall restarting
3041
3042 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3043 + li t1, _TIF_SYSCALL_WORK
3044 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3045 and t0, t1, t0
3046 bnez t0, syscall_trace_entry
3047 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3048 index 6be6f70..1859577 100644
3049 --- a/arch/mips/kernel/scall64-n32.S
3050 +++ b/arch/mips/kernel/scall64-n32.S
3051 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3052
3053 sd a3, PT_R26(sp) # save a3 for syscall restarting
3054
3055 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3056 + li t1, _TIF_SYSCALL_WORK
3057 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3058 and t0, t1, t0
3059 bnez t0, n32_syscall_trace_entry
3060 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3061 index 5422855..74e63a3 100644
3062 --- a/arch/mips/kernel/scall64-o32.S
3063 +++ b/arch/mips/kernel/scall64-o32.S
3064 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3065 PTR 4b, bad_stack
3066 .previous
3067
3068 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3069 + li t1, _TIF_SYSCALL_WORK
3070 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3071 and t0, t1, t0
3072 bnez t0, trace_a_syscall
3073 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3074 index c14f6df..537e729 100644
3075 --- a/arch/mips/mm/fault.c
3076 +++ b/arch/mips/mm/fault.c
3077 @@ -27,6 +27,23 @@
3078 #include <asm/highmem.h> /* For VMALLOC_END */
3079 #include <linux/kdebug.h>
3080
3081 +#ifdef CONFIG_PAX_PAGEEXEC
3082 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3083 +{
3084 + unsigned long i;
3085 +
3086 + printk(KERN_ERR "PAX: bytes at PC: ");
3087 + for (i = 0; i < 5; i++) {
3088 + unsigned int c;
3089 + if (get_user(c, (unsigned int *)pc+i))
3090 + printk(KERN_CONT "???????? ");
3091 + else
3092 + printk(KERN_CONT "%08x ", c);
3093 + }
3094 + printk("\n");
3095 +}
3096 +#endif
3097 +
3098 /*
3099 * This routine handles page faults. It determines the address,
3100 * and the problem, and then passes it off to one of the appropriate
3101 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3102 index 302d779..7d35bf8 100644
3103 --- a/arch/mips/mm/mmap.c
3104 +++ b/arch/mips/mm/mmap.c
3105 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3106 do_color_align = 1;
3107
3108 /* requesting a specific address */
3109 +
3110 +#ifdef CONFIG_PAX_RANDMMAP
3111 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3112 +#endif
3113 +
3114 if (addr) {
3115 if (do_color_align)
3116 addr = COLOUR_ALIGN(addr, pgoff);
3117 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3118 addr = PAGE_ALIGN(addr);
3119
3120 vma = find_vma(mm, addr);
3121 - if (TASK_SIZE - len >= addr &&
3122 - (!vma || addr + len <= vma->vm_start))
3123 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3124 return addr;
3125 }
3126
3127 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3128 /* At this point: (!vma || addr < vma->vm_end). */
3129 if (TASK_SIZE - len < addr)
3130 return -ENOMEM;
3131 - if (!vma || addr + len <= vma->vm_start)
3132 + if (check_heap_stack_gap(vmm, addr, len))
3133 return addr;
3134 addr = vma->vm_end;
3135 if (do_color_align)
3136 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3137 /* make sure it can fit in the remaining address space */
3138 if (likely(addr > len)) {
3139 vma = find_vma(mm, addr - len);
3140 - if (!vma || addr <= vma->vm_start) {
3141 + if (check_heap_stack_gap(vmm, addr - len, len))
3142 /* cache the address as a hint for next time */
3143 return mm->free_area_cache = addr - len;
3144 }
3145 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3146 * return with success:
3147 */
3148 vma = find_vma(mm, addr);
3149 - if (likely(!vma || addr + len <= vma->vm_start)) {
3150 + if (check_heap_stack_gap(vmm, addr, len)) {
3151 /* cache the address as a hint for next time */
3152 return mm->free_area_cache = addr;
3153 }
3154 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3155 mm->unmap_area = arch_unmap_area_topdown;
3156 }
3157 }
3158 -
3159 -static inline unsigned long brk_rnd(void)
3160 -{
3161 - unsigned long rnd = get_random_int();
3162 -
3163 - rnd = rnd << PAGE_SHIFT;
3164 - /* 8MB for 32bit, 256MB for 64bit */
3165 - if (TASK_IS_32BIT_ADDR)
3166 - rnd = rnd & 0x7ffffful;
3167 - else
3168 - rnd = rnd & 0xffffffful;
3169 -
3170 - return rnd;
3171 -}
3172 -
3173 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3174 -{
3175 - unsigned long base = mm->brk;
3176 - unsigned long ret;
3177 -
3178 - ret = PAGE_ALIGN(base + brk_rnd());
3179 -
3180 - if (ret < mm->brk)
3181 - return mm->brk;
3182 -
3183 - return ret;
3184 -}
3185 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3186 index 967d144..db12197 100644
3187 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3188 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3189 @@ -11,12 +11,14 @@
3190 #ifndef _ASM_PROC_CACHE_H
3191 #define _ASM_PROC_CACHE_H
3192
3193 +#include <linux/const.h>
3194 +
3195 /* L1 cache */
3196
3197 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3198 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3199 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3200 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3201 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3202 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3203
3204 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3205 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3206 index bcb5df2..84fabd2 100644
3207 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3208 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3209 @@ -16,13 +16,15 @@
3210 #ifndef _ASM_PROC_CACHE_H
3211 #define _ASM_PROC_CACHE_H
3212
3213 +#include <linux/const.h>
3214 +
3215 /*
3216 * L1 cache
3217 */
3218 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3219 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3220 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3221 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3222 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3223 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3224
3225 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3226 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3227 index 4ce7a01..449202a 100644
3228 --- a/arch/openrisc/include/asm/cache.h
3229 +++ b/arch/openrisc/include/asm/cache.h
3230 @@ -19,11 +19,13 @@
3231 #ifndef __ASM_OPENRISC_CACHE_H
3232 #define __ASM_OPENRISC_CACHE_H
3233
3234 +#include <linux/const.h>
3235 +
3236 /* FIXME: How can we replace these with values from the CPU...
3237 * they shouldn't be hard-coded!
3238 */
3239
3240 -#define L1_CACHE_BYTES 16
3241 #define L1_CACHE_SHIFT 4
3242 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3243
3244 #endif /* __ASM_OPENRISC_CACHE_H */
3245 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3246 index 6c6defc..d30653d 100644
3247 --- a/arch/parisc/include/asm/atomic.h
3248 +++ b/arch/parisc/include/asm/atomic.h
3249 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3250
3251 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3252
3253 +#define atomic64_read_unchecked(v) atomic64_read(v)
3254 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3255 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3256 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3257 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3258 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3259 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3260 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3261 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3262 +
3263 #endif /* !CONFIG_64BIT */
3264
3265
3266 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3267 index 47f11c7..3420df2 100644
3268 --- a/arch/parisc/include/asm/cache.h
3269 +++ b/arch/parisc/include/asm/cache.h
3270 @@ -5,6 +5,7 @@
3271 #ifndef __ARCH_PARISC_CACHE_H
3272 #define __ARCH_PARISC_CACHE_H
3273
3274 +#include <linux/const.h>
3275
3276 /*
3277 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3278 @@ -15,13 +16,13 @@
3279 * just ruin performance.
3280 */
3281 #ifdef CONFIG_PA20
3282 -#define L1_CACHE_BYTES 64
3283 #define L1_CACHE_SHIFT 6
3284 #else
3285 -#define L1_CACHE_BYTES 32
3286 #define L1_CACHE_SHIFT 5
3287 #endif
3288
3289 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3290 +
3291 #ifndef __ASSEMBLY__
3292
3293 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3294 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3295 index 19f6cb1..6c78cf2 100644
3296 --- a/arch/parisc/include/asm/elf.h
3297 +++ b/arch/parisc/include/asm/elf.h
3298 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3299
3300 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3301
3302 +#ifdef CONFIG_PAX_ASLR
3303 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3304 +
3305 +#define PAX_DELTA_MMAP_LEN 16
3306 +#define PAX_DELTA_STACK_LEN 16
3307 +#endif
3308 +
3309 /* This yields a mask that user programs can use to figure out what
3310 instruction set this CPU supports. This could be done in user space,
3311 but it's not easy, and we've already done it here. */
3312 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3313 index fc987a1..6e068ef 100644
3314 --- a/arch/parisc/include/asm/pgalloc.h
3315 +++ b/arch/parisc/include/asm/pgalloc.h
3316 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3317 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3318 }
3319
3320 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3321 +{
3322 + pgd_populate(mm, pgd, pmd);
3323 +}
3324 +
3325 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3326 {
3327 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3328 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3329 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3330 #define pmd_free(mm, x) do { } while (0)
3331 #define pgd_populate(mm, pmd, pte) BUG()
3332 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3333
3334 #endif
3335
3336 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3337 index ee99f23..802b0a1 100644
3338 --- a/arch/parisc/include/asm/pgtable.h
3339 +++ b/arch/parisc/include/asm/pgtable.h
3340 @@ -212,6 +212,17 @@ struct vm_area_struct;
3341 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3342 #define PAGE_COPY PAGE_EXECREAD
3343 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3344 +
3345 +#ifdef CONFIG_PAX_PAGEEXEC
3346 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3347 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3348 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3349 +#else
3350 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3351 +# define PAGE_COPY_NOEXEC PAGE_COPY
3352 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3353 +#endif
3354 +
3355 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3356 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3357 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3358 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3359 index 4ba2c93..f5e3974 100644
3360 --- a/arch/parisc/include/asm/uaccess.h
3361 +++ b/arch/parisc/include/asm/uaccess.h
3362 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3363 const void __user *from,
3364 unsigned long n)
3365 {
3366 - int sz = __compiletime_object_size(to);
3367 + size_t sz = __compiletime_object_size(to);
3368 int ret = -EFAULT;
3369
3370 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3371 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3372 ret = __copy_from_user(to, from, n);
3373 else
3374 copy_from_user_overflow();
3375 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3376 index 5e34ccf..672bc9c 100644
3377 --- a/arch/parisc/kernel/module.c
3378 +++ b/arch/parisc/kernel/module.c
3379 @@ -98,16 +98,38 @@
3380
3381 /* three functions to determine where in the module core
3382 * or init pieces the location is */
3383 +static inline int in_init_rx(struct module *me, void *loc)
3384 +{
3385 + return (loc >= me->module_init_rx &&
3386 + loc < (me->module_init_rx + me->init_size_rx));
3387 +}
3388 +
3389 +static inline int in_init_rw(struct module *me, void *loc)
3390 +{
3391 + return (loc >= me->module_init_rw &&
3392 + loc < (me->module_init_rw + me->init_size_rw));
3393 +}
3394 +
3395 static inline int in_init(struct module *me, void *loc)
3396 {
3397 - return (loc >= me->module_init &&
3398 - loc <= (me->module_init + me->init_size));
3399 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3400 +}
3401 +
3402 +static inline int in_core_rx(struct module *me, void *loc)
3403 +{
3404 + return (loc >= me->module_core_rx &&
3405 + loc < (me->module_core_rx + me->core_size_rx));
3406 +}
3407 +
3408 +static inline int in_core_rw(struct module *me, void *loc)
3409 +{
3410 + return (loc >= me->module_core_rw &&
3411 + loc < (me->module_core_rw + me->core_size_rw));
3412 }
3413
3414 static inline int in_core(struct module *me, void *loc)
3415 {
3416 - return (loc >= me->module_core &&
3417 - loc <= (me->module_core + me->core_size));
3418 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3419 }
3420
3421 static inline int in_local(struct module *me, void *loc)
3422 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3423 }
3424
3425 /* align things a bit */
3426 - me->core_size = ALIGN(me->core_size, 16);
3427 - me->arch.got_offset = me->core_size;
3428 - me->core_size += gots * sizeof(struct got_entry);
3429 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3430 + me->arch.got_offset = me->core_size_rw;
3431 + me->core_size_rw += gots * sizeof(struct got_entry);
3432
3433 - me->core_size = ALIGN(me->core_size, 16);
3434 - me->arch.fdesc_offset = me->core_size;
3435 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3436 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3437 + me->arch.fdesc_offset = me->core_size_rw;
3438 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3439
3440 me->arch.got_max = gots;
3441 me->arch.fdesc_max = fdescs;
3442 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3443
3444 BUG_ON(value == 0);
3445
3446 - got = me->module_core + me->arch.got_offset;
3447 + got = me->module_core_rw + me->arch.got_offset;
3448 for (i = 0; got[i].addr; i++)
3449 if (got[i].addr == value)
3450 goto out;
3451 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3452 #ifdef CONFIG_64BIT
3453 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3454 {
3455 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3456 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3457
3458 if (!value) {
3459 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3460 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3461
3462 /* Create new one */
3463 fdesc->addr = value;
3464 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3465 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3466 return (Elf_Addr)fdesc;
3467 }
3468 #endif /* CONFIG_64BIT */
3469 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3470
3471 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3472 end = table + sechdrs[me->arch.unwind_section].sh_size;
3473 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3474 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3475
3476 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3477 me->arch.unwind_section, table, end, gp);
3478 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3479 index c9b9322..02d8940 100644
3480 --- a/arch/parisc/kernel/sys_parisc.c
3481 +++ b/arch/parisc/kernel/sys_parisc.c
3482 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3483 /* At this point: (!vma || addr < vma->vm_end). */
3484 if (TASK_SIZE - len < addr)
3485 return -ENOMEM;
3486 - if (!vma || addr + len <= vma->vm_start)
3487 + if (check_heap_stack_gap(vma, addr, len))
3488 return addr;
3489 addr = vma->vm_end;
3490 }
3491 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3492 /* At this point: (!vma || addr < vma->vm_end). */
3493 if (TASK_SIZE - len < addr)
3494 return -ENOMEM;
3495 - if (!vma || addr + len <= vma->vm_start)
3496 + if (check_heap_stack_gap(vma, addr, len))
3497 return addr;
3498 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3499 if (addr < vma->vm_end) /* handle wraparound */
3500 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3501 if (flags & MAP_FIXED)
3502 return addr;
3503 if (!addr)
3504 - addr = TASK_UNMAPPED_BASE;
3505 + addr = current->mm->mmap_base;
3506
3507 if (filp) {
3508 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3509 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3510 index 45ba99f..8e22c33 100644
3511 --- a/arch/parisc/kernel/traps.c
3512 +++ b/arch/parisc/kernel/traps.c
3513 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3514
3515 down_read(&current->mm->mmap_sem);
3516 vma = find_vma(current->mm,regs->iaoq[0]);
3517 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3518 - && (vma->vm_flags & VM_EXEC)) {
3519 -
3520 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3521 fault_address = regs->iaoq[0];
3522 fault_space = regs->iasq[0];
3523
3524 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3525 index 18162ce..94de376 100644
3526 --- a/arch/parisc/mm/fault.c
3527 +++ b/arch/parisc/mm/fault.c
3528 @@ -15,6 +15,7 @@
3529 #include <linux/sched.h>
3530 #include <linux/interrupt.h>
3531 #include <linux/module.h>
3532 +#include <linux/unistd.h>
3533
3534 #include <asm/uaccess.h>
3535 #include <asm/traps.h>
3536 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3537 static unsigned long
3538 parisc_acctyp(unsigned long code, unsigned int inst)
3539 {
3540 - if (code == 6 || code == 16)
3541 + if (code == 6 || code == 7 || code == 16)
3542 return VM_EXEC;
3543
3544 switch (inst & 0xf0000000) {
3545 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3546 }
3547 #endif
3548
3549 +#ifdef CONFIG_PAX_PAGEEXEC
3550 +/*
3551 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3552 + *
3553 + * returns 1 when task should be killed
3554 + * 2 when rt_sigreturn trampoline was detected
3555 + * 3 when unpatched PLT trampoline was detected
3556 + */
3557 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3558 +{
3559 +
3560 +#ifdef CONFIG_PAX_EMUPLT
3561 + int err;
3562 +
3563 + do { /* PaX: unpatched PLT emulation */
3564 + unsigned int bl, depwi;
3565 +
3566 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3567 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3568 +
3569 + if (err)
3570 + break;
3571 +
3572 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3573 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3574 +
3575 + err = get_user(ldw, (unsigned int *)addr);
3576 + err |= get_user(bv, (unsigned int *)(addr+4));
3577 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3578 +
3579 + if (err)
3580 + break;
3581 +
3582 + if (ldw == 0x0E801096U &&
3583 + bv == 0xEAC0C000U &&
3584 + ldw2 == 0x0E881095U)
3585 + {
3586 + unsigned int resolver, map;
3587 +
3588 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3589 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3590 + if (err)
3591 + break;
3592 +
3593 + regs->gr[20] = instruction_pointer(regs)+8;
3594 + regs->gr[21] = map;
3595 + regs->gr[22] = resolver;
3596 + regs->iaoq[0] = resolver | 3UL;
3597 + regs->iaoq[1] = regs->iaoq[0] + 4;
3598 + return 3;
3599 + }
3600 + }
3601 + } while (0);
3602 +#endif
3603 +
3604 +#ifdef CONFIG_PAX_EMUTRAMP
3605 +
3606 +#ifndef CONFIG_PAX_EMUSIGRT
3607 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3608 + return 1;
3609 +#endif
3610 +
3611 + do { /* PaX: rt_sigreturn emulation */
3612 + unsigned int ldi1, ldi2, bel, nop;
3613 +
3614 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3615 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3616 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3617 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3618 +
3619 + if (err)
3620 + break;
3621 +
3622 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3623 + ldi2 == 0x3414015AU &&
3624 + bel == 0xE4008200U &&
3625 + nop == 0x08000240U)
3626 + {
3627 + regs->gr[25] = (ldi1 & 2) >> 1;
3628 + regs->gr[20] = __NR_rt_sigreturn;
3629 + regs->gr[31] = regs->iaoq[1] + 16;
3630 + regs->sr[0] = regs->iasq[1];
3631 + regs->iaoq[0] = 0x100UL;
3632 + regs->iaoq[1] = regs->iaoq[0] + 4;
3633 + regs->iasq[0] = regs->sr[2];
3634 + regs->iasq[1] = regs->sr[2];
3635 + return 2;
3636 + }
3637 + } while (0);
3638 +#endif
3639 +
3640 + return 1;
3641 +}
3642 +
3643 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3644 +{
3645 + unsigned long i;
3646 +
3647 + printk(KERN_ERR "PAX: bytes at PC: ");
3648 + for (i = 0; i < 5; i++) {
3649 + unsigned int c;
3650 + if (get_user(c, (unsigned int *)pc+i))
3651 + printk(KERN_CONT "???????? ");
3652 + else
3653 + printk(KERN_CONT "%08x ", c);
3654 + }
3655 + printk("\n");
3656 +}
3657 +#endif
3658 +
3659 int fixup_exception(struct pt_regs *regs)
3660 {
3661 const struct exception_table_entry *fix;
3662 @@ -192,8 +303,33 @@ good_area:
3663
3664 acc_type = parisc_acctyp(code,regs->iir);
3665
3666 - if ((vma->vm_flags & acc_type) != acc_type)
3667 + if ((vma->vm_flags & acc_type) != acc_type) {
3668 +
3669 +#ifdef CONFIG_PAX_PAGEEXEC
3670 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3671 + (address & ~3UL) == instruction_pointer(regs))
3672 + {
3673 + up_read(&mm->mmap_sem);
3674 + switch (pax_handle_fetch_fault(regs)) {
3675 +
3676 +#ifdef CONFIG_PAX_EMUPLT
3677 + case 3:
3678 + return;
3679 +#endif
3680 +
3681 +#ifdef CONFIG_PAX_EMUTRAMP
3682 + case 2:
3683 + return;
3684 +#endif
3685 +
3686 + }
3687 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3688 + do_group_exit(SIGKILL);
3689 + }
3690 +#endif
3691 +
3692 goto bad_area;
3693 + }
3694
3695 /*
3696 * If for any reason at all we couldn't handle the fault, make
3697 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3698 index da29032..f76c24c 100644
3699 --- a/arch/powerpc/include/asm/atomic.h
3700 +++ b/arch/powerpc/include/asm/atomic.h
3701 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3702 return t1;
3703 }
3704
3705 +#define atomic64_read_unchecked(v) atomic64_read(v)
3706 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3707 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3708 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3709 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3710 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3711 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3712 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3713 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3714 +
3715 #endif /* __powerpc64__ */
3716
3717 #endif /* __KERNEL__ */
3718 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3719 index 9e495c9..b6878e5 100644
3720 --- a/arch/powerpc/include/asm/cache.h
3721 +++ b/arch/powerpc/include/asm/cache.h
3722 @@ -3,6 +3,7 @@
3723
3724 #ifdef __KERNEL__
3725
3726 +#include <linux/const.h>
3727
3728 /* bytes per L1 cache line */
3729 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3730 @@ -22,7 +23,7 @@
3731 #define L1_CACHE_SHIFT 7
3732 #endif
3733
3734 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3735 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3736
3737 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3738
3739 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3740 index 3bf9cca..e7457d0 100644
3741 --- a/arch/powerpc/include/asm/elf.h
3742 +++ b/arch/powerpc/include/asm/elf.h
3743 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3744 the loader. We need to make sure that it is out of the way of the program
3745 that it will "exec", and that there is sufficient room for the brk. */
3746
3747 -extern unsigned long randomize_et_dyn(unsigned long base);
3748 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3749 +#define ELF_ET_DYN_BASE (0x20000000)
3750 +
3751 +#ifdef CONFIG_PAX_ASLR
3752 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3753 +
3754 +#ifdef __powerpc64__
3755 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3756 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3757 +#else
3758 +#define PAX_DELTA_MMAP_LEN 15
3759 +#define PAX_DELTA_STACK_LEN 15
3760 +#endif
3761 +#endif
3762
3763 /*
3764 * Our registers are always unsigned longs, whether we're a 32 bit
3765 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3766 (0x7ff >> (PAGE_SHIFT - 12)) : \
3767 (0x3ffff >> (PAGE_SHIFT - 12)))
3768
3769 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3770 -#define arch_randomize_brk arch_randomize_brk
3771 -
3772 #endif /* __KERNEL__ */
3773
3774 /*
3775 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3776 index 8196e9c..d83a9f3 100644
3777 --- a/arch/powerpc/include/asm/exec.h
3778 +++ b/arch/powerpc/include/asm/exec.h
3779 @@ -4,6 +4,6 @@
3780 #ifndef _ASM_POWERPC_EXEC_H
3781 #define _ASM_POWERPC_EXEC_H
3782
3783 -extern unsigned long arch_align_stack(unsigned long sp);
3784 +#define arch_align_stack(x) ((x) & ~0xfUL)
3785
3786 #endif /* _ASM_POWERPC_EXEC_H */
3787 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3788 index bca8fdc..61e9580 100644
3789 --- a/arch/powerpc/include/asm/kmap_types.h
3790 +++ b/arch/powerpc/include/asm/kmap_types.h
3791 @@ -27,6 +27,7 @@ enum km_type {
3792 KM_PPC_SYNC_PAGE,
3793 KM_PPC_SYNC_ICACHE,
3794 KM_KDB,
3795 + KM_CLEARPAGE,
3796 KM_TYPE_NR
3797 };
3798
3799 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3800 index d4a7f64..451de1c 100644
3801 --- a/arch/powerpc/include/asm/mman.h
3802 +++ b/arch/powerpc/include/asm/mman.h
3803 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3804 }
3805 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3806
3807 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3808 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3809 {
3810 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3811 }
3812 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3813 index f072e97..b436dee 100644
3814 --- a/arch/powerpc/include/asm/page.h
3815 +++ b/arch/powerpc/include/asm/page.h
3816 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3817 * and needs to be executable. This means the whole heap ends
3818 * up being executable.
3819 */
3820 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3821 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3822 +#define VM_DATA_DEFAULT_FLAGS32 \
3823 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3824 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3825
3826 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3827 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3828 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3829 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3830 #endif
3831
3832 +#define ktla_ktva(addr) (addr)
3833 +#define ktva_ktla(addr) (addr)
3834 +
3835 /*
3836 * Use the top bit of the higher-level page table entries to indicate whether
3837 * the entries we point to contain hugepages. This works because we know that
3838 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3839 index fed85e6..da5c71b 100644
3840 --- a/arch/powerpc/include/asm/page_64.h
3841 +++ b/arch/powerpc/include/asm/page_64.h
3842 @@ -146,15 +146,18 @@ do { \
3843 * stack by default, so in the absence of a PT_GNU_STACK program header
3844 * we turn execute permission off.
3845 */
3846 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3847 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3848 +#define VM_STACK_DEFAULT_FLAGS32 \
3849 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3850 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3851
3852 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3853 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3854
3855 +#ifndef CONFIG_PAX_PAGEEXEC
3856 #define VM_STACK_DEFAULT_FLAGS \
3857 (is_32bit_task() ? \
3858 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3859 +#endif
3860
3861 #include <asm-generic/getorder.h>
3862
3863 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3864 index 292725c..f87ae14 100644
3865 --- a/arch/powerpc/include/asm/pgalloc-64.h
3866 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3867 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3868 #ifndef CONFIG_PPC_64K_PAGES
3869
3870 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3871 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3872
3873 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3874 {
3875 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3876 pud_set(pud, (unsigned long)pmd);
3877 }
3878
3879 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3880 +{
3881 + pud_populate(mm, pud, pmd);
3882 +}
3883 +
3884 #define pmd_populate(mm, pmd, pte_page) \
3885 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3886 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3887 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3888 #else /* CONFIG_PPC_64K_PAGES */
3889
3890 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3891 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3892
3893 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3894 pte_t *pte)
3895 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3896 index 2e0e411..7899c68 100644
3897 --- a/arch/powerpc/include/asm/pgtable.h
3898 +++ b/arch/powerpc/include/asm/pgtable.h
3899 @@ -2,6 +2,7 @@
3900 #define _ASM_POWERPC_PGTABLE_H
3901 #ifdef __KERNEL__
3902
3903 +#include <linux/const.h>
3904 #ifndef __ASSEMBLY__
3905 #include <asm/processor.h> /* For TASK_SIZE */
3906 #include <asm/mmu.h>
3907 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3908 index 4aad413..85d86bf 100644
3909 --- a/arch/powerpc/include/asm/pte-hash32.h
3910 +++ b/arch/powerpc/include/asm/pte-hash32.h
3911 @@ -21,6 +21,7 @@
3912 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3913 #define _PAGE_USER 0x004 /* usermode access allowed */
3914 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3915 +#define _PAGE_EXEC _PAGE_GUARDED
3916 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3917 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3918 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3919 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3920 index f0cb7f4..d1296c4 100644
3921 --- a/arch/powerpc/include/asm/reg.h
3922 +++ b/arch/powerpc/include/asm/reg.h
3923 @@ -212,6 +212,7 @@
3924 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3925 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3926 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3927 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3928 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3929 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3930 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3931 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3932 index 68831e9..379c695 100644
3933 --- a/arch/powerpc/include/asm/thread_info.h
3934 +++ b/arch/powerpc/include/asm/thread_info.h
3935 @@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3936 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3937 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3938 #define TIF_SINGLESTEP 8 /* singlestepping active */
3939 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3940 #define TIF_SECCOMP 10 /* secure computing */
3941 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3942 #define TIF_NOERROR 12 /* Force successful syscall return */
3943 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3944 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3945 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3946 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3947 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3948
3949 /* as above, but as bit values */
3950 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3951 @@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3952 #define _TIF_NOERROR (1<<TIF_NOERROR)
3953 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3954 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3955 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3956 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3957 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3958 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3959 + _TIF_GRSEC_SETXID)
3960
3961 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3962 _TIF_NOTIFY_RESUME)
3963 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3964 index 17bb40c..353c98b 100644
3965 --- a/arch/powerpc/include/asm/uaccess.h
3966 +++ b/arch/powerpc/include/asm/uaccess.h
3967 @@ -13,6 +13,8 @@
3968 #define VERIFY_READ 0
3969 #define VERIFY_WRITE 1
3970
3971 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3972 +
3973 /*
3974 * The fs value determines whether argument validity checking should be
3975 * performed or not. If get_fs() == USER_DS, checking is performed, with
3976 @@ -329,52 +331,6 @@ do { \
3977 extern unsigned long __copy_tofrom_user(void __user *to,
3978 const void __user *from, unsigned long size);
3979
3980 -#ifndef __powerpc64__
3981 -
3982 -static inline unsigned long copy_from_user(void *to,
3983 - const void __user *from, unsigned long n)
3984 -{
3985 - unsigned long over;
3986 -
3987 - if (access_ok(VERIFY_READ, from, n))
3988 - return __copy_tofrom_user((__force void __user *)to, from, n);
3989 - if ((unsigned long)from < TASK_SIZE) {
3990 - over = (unsigned long)from + n - TASK_SIZE;
3991 - return __copy_tofrom_user((__force void __user *)to, from,
3992 - n - over) + over;
3993 - }
3994 - return n;
3995 -}
3996 -
3997 -static inline unsigned long copy_to_user(void __user *to,
3998 - const void *from, unsigned long n)
3999 -{
4000 - unsigned long over;
4001 -
4002 - if (access_ok(VERIFY_WRITE, to, n))
4003 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4004 - if ((unsigned long)to < TASK_SIZE) {
4005 - over = (unsigned long)to + n - TASK_SIZE;
4006 - return __copy_tofrom_user(to, (__force void __user *)from,
4007 - n - over) + over;
4008 - }
4009 - return n;
4010 -}
4011 -
4012 -#else /* __powerpc64__ */
4013 -
4014 -#define __copy_in_user(to, from, size) \
4015 - __copy_tofrom_user((to), (from), (size))
4016 -
4017 -extern unsigned long copy_from_user(void *to, const void __user *from,
4018 - unsigned long n);
4019 -extern unsigned long copy_to_user(void __user *to, const void *from,
4020 - unsigned long n);
4021 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4022 - unsigned long n);
4023 -
4024 -#endif /* __powerpc64__ */
4025 -
4026 static inline unsigned long __copy_from_user_inatomic(void *to,
4027 const void __user *from, unsigned long n)
4028 {
4029 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4030 if (ret == 0)
4031 return 0;
4032 }
4033 +
4034 + if (!__builtin_constant_p(n))
4035 + check_object_size(to, n, false);
4036 +
4037 return __copy_tofrom_user((__force void __user *)to, from, n);
4038 }
4039
4040 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4041 if (ret == 0)
4042 return 0;
4043 }
4044 +
4045 + if (!__builtin_constant_p(n))
4046 + check_object_size(from, n, true);
4047 +
4048 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4049 }
4050
4051 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4052 return __copy_to_user_inatomic(to, from, size);
4053 }
4054
4055 +#ifndef __powerpc64__
4056 +
4057 +static inline unsigned long __must_check copy_from_user(void *to,
4058 + const void __user *from, unsigned long n)
4059 +{
4060 + unsigned long over;
4061 +
4062 + if ((long)n < 0)
4063 + return n;
4064 +
4065 + if (access_ok(VERIFY_READ, from, n)) {
4066 + if (!__builtin_constant_p(n))
4067 + check_object_size(to, n, false);
4068 + return __copy_tofrom_user((__force void __user *)to, from, n);
4069 + }
4070 + if ((unsigned long)from < TASK_SIZE) {
4071 + over = (unsigned long)from + n - TASK_SIZE;
4072 + if (!__builtin_constant_p(n - over))
4073 + check_object_size(to, n - over, false);
4074 + return __copy_tofrom_user((__force void __user *)to, from,
4075 + n - over) + over;
4076 + }
4077 + return n;
4078 +}
4079 +
4080 +static inline unsigned long __must_check copy_to_user(void __user *to,
4081 + const void *from, unsigned long n)
4082 +{
4083 + unsigned long over;
4084 +
4085 + if ((long)n < 0)
4086 + return n;
4087 +
4088 + if (access_ok(VERIFY_WRITE, to, n)) {
4089 + if (!__builtin_constant_p(n))
4090 + check_object_size(from, n, true);
4091 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4092 + }
4093 + if ((unsigned long)to < TASK_SIZE) {
4094 + over = (unsigned long)to + n - TASK_SIZE;
4095 + if (!__builtin_constant_p(n))
4096 + check_object_size(from, n - over, true);
4097 + return __copy_tofrom_user(to, (__force void __user *)from,
4098 + n - over) + over;
4099 + }
4100 + return n;
4101 +}
4102 +
4103 +#else /* __powerpc64__ */
4104 +
4105 +#define __copy_in_user(to, from, size) \
4106 + __copy_tofrom_user((to), (from), (size))
4107 +
4108 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4109 +{
4110 + if ((long)n < 0 || n > INT_MAX)
4111 + return n;
4112 +
4113 + if (!__builtin_constant_p(n))
4114 + check_object_size(to, n, false);
4115 +
4116 + if (likely(access_ok(VERIFY_READ, from, n)))
4117 + n = __copy_from_user(to, from, n);
4118 + else
4119 + memset(to, 0, n);
4120 + return n;
4121 +}
4122 +
4123 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4124 +{
4125 + if ((long)n < 0 || n > INT_MAX)
4126 + return n;
4127 +
4128 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4129 + if (!__builtin_constant_p(n))
4130 + check_object_size(from, n, true);
4131 + n = __copy_to_user(to, from, n);
4132 + }
4133 + return n;
4134 +}
4135 +
4136 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4137 + unsigned long n);
4138 +
4139 +#endif /* __powerpc64__ */
4140 +
4141 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4142
4143 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4144 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4145 index 7215cc2..a9730c1 100644
4146 --- a/arch/powerpc/kernel/exceptions-64e.S
4147 +++ b/arch/powerpc/kernel/exceptions-64e.S
4148 @@ -661,6 +661,7 @@ storage_fault_common:
4149 std r14,_DAR(r1)
4150 std r15,_DSISR(r1)
4151 addi r3,r1,STACK_FRAME_OVERHEAD
4152 + bl .save_nvgprs
4153 mr r4,r14
4154 mr r5,r15
4155 ld r14,PACA_EXGEN+EX_R14(r13)
4156 @@ -669,8 +670,7 @@ storage_fault_common:
4157 cmpdi r3,0
4158 bne- 1f
4159 b .ret_from_except_lite
4160 -1: bl .save_nvgprs
4161 - mr r5,r3
4162 +1: mr r5,r3
4163 addi r3,r1,STACK_FRAME_OVERHEAD
4164 ld r4,_DAR(r1)
4165 bl .bad_page_fault
4166 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4167 index 1c06d29..c2a339b 100644
4168 --- a/arch/powerpc/kernel/exceptions-64s.S
4169 +++ b/arch/powerpc/kernel/exceptions-64s.S
4170 @@ -888,10 +888,10 @@ handle_page_fault:
4171 11: ld r4,_DAR(r1)
4172 ld r5,_DSISR(r1)
4173 addi r3,r1,STACK_FRAME_OVERHEAD
4174 + bl .save_nvgprs
4175 bl .do_page_fault
4176 cmpdi r3,0
4177 beq+ 12f
4178 - bl .save_nvgprs
4179 mr r5,r3
4180 addi r3,r1,STACK_FRAME_OVERHEAD
4181 lwz r4,_DAR(r1)
4182 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4183 index 2e3200c..72095ce 100644
4184 --- a/arch/powerpc/kernel/module_32.c
4185 +++ b/arch/powerpc/kernel/module_32.c
4186 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4187 me->arch.core_plt_section = i;
4188 }
4189 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4190 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4191 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4192 return -ENOEXEC;
4193 }
4194
4195 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4196
4197 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4198 /* Init, or core PLT? */
4199 - if (location >= mod->module_core
4200 - && location < mod->module_core + mod->core_size)
4201 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4202 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4203 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4204 - else
4205 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4206 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4207 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4208 + else {
4209 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4210 + return ~0UL;
4211 + }
4212
4213 /* Find this entry, or if that fails, the next avail. entry */
4214 while (entry->jump[0]) {
4215 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4216 index 710f400..d00ebe6 100644
4217 --- a/arch/powerpc/kernel/process.c
4218 +++ b/arch/powerpc/kernel/process.c
4219 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4220 * Lookup NIP late so we have the best change of getting the
4221 * above info out without failing
4222 */
4223 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4224 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4225 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4226 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4227 #endif
4228 show_stack(current, (unsigned long *) regs->gpr[1]);
4229 if (!user_mode(regs))
4230 @@ -1189,10 +1189,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4231 newsp = stack[0];
4232 ip = stack[STACK_FRAME_LR_SAVE];
4233 if (!firstframe || ip != lr) {
4234 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4235 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4236 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4237 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4238 - printk(" (%pS)",
4239 + printk(" (%pA)",
4240 (void *)current->ret_stack[curr_frame].ret);
4241 curr_frame--;
4242 }
4243 @@ -1212,7 +1212,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4244 struct pt_regs *regs = (struct pt_regs *)
4245 (sp + STACK_FRAME_OVERHEAD);
4246 lr = regs->link;
4247 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4248 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4249 regs->trap, (void *)regs->nip, (void *)lr);
4250 firstframe = 1;
4251 }
4252 @@ -1254,58 +1254,3 @@ void __ppc64_runlatch_off(void)
4253 mtspr(SPRN_CTRLT, ctrl);
4254 }
4255 #endif /* CONFIG_PPC64 */
4256 -
4257 -unsigned long arch_align_stack(unsigned long sp)
4258 -{
4259 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4260 - sp -= get_random_int() & ~PAGE_MASK;
4261 - return sp & ~0xf;
4262 -}
4263 -
4264 -static inline unsigned long brk_rnd(void)
4265 -{
4266 - unsigned long rnd = 0;
4267 -
4268 - /* 8MB for 32bit, 1GB for 64bit */
4269 - if (is_32bit_task())
4270 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4271 - else
4272 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4273 -
4274 - return rnd << PAGE_SHIFT;
4275 -}
4276 -
4277 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4278 -{
4279 - unsigned long base = mm->brk;
4280 - unsigned long ret;
4281 -
4282 -#ifdef CONFIG_PPC_STD_MMU_64
4283 - /*
4284 - * If we are using 1TB segments and we are allowed to randomise
4285 - * the heap, we can put it above 1TB so it is backed by a 1TB
4286 - * segment. Otherwise the heap will be in the bottom 1TB
4287 - * which always uses 256MB segments and this may result in a
4288 - * performance penalty.
4289 - */
4290 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4291 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4292 -#endif
4293 -
4294 - ret = PAGE_ALIGN(base + brk_rnd());
4295 -
4296 - if (ret < mm->brk)
4297 - return mm->brk;
4298 -
4299 - return ret;
4300 -}
4301 -
4302 -unsigned long randomize_et_dyn(unsigned long base)
4303 -{
4304 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4305 -
4306 - if (ret < base)
4307 - return base;
4308 -
4309 - return ret;
4310 -}
4311 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4312 index c10fc28..c4ef063 100644
4313 --- a/arch/powerpc/kernel/ptrace.c
4314 +++ b/arch/powerpc/kernel/ptrace.c
4315 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4316 return ret;
4317 }
4318
4319 +#ifdef CONFIG_GRKERNSEC_SETXID
4320 +extern void gr_delayed_cred_worker(void);
4321 +#endif
4322 +
4323 /*
4324 * We must return the syscall number to actually look up in the table.
4325 * This can be -1L to skip running any syscall at all.
4326 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4327
4328 secure_computing_strict(regs->gpr[0]);
4329
4330 +#ifdef CONFIG_GRKERNSEC_SETXID
4331 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4332 + gr_delayed_cred_worker();
4333 +#endif
4334 +
4335 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4336 tracehook_report_syscall_entry(regs))
4337 /*
4338 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4339 {
4340 int step;
4341
4342 +#ifdef CONFIG_GRKERNSEC_SETXID
4343 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4344 + gr_delayed_cred_worker();
4345 +#endif
4346 +
4347 audit_syscall_exit(regs);
4348
4349 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4350 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4351 index 8b4c049..dcd6ef3 100644
4352 --- a/arch/powerpc/kernel/signal_32.c
4353 +++ b/arch/powerpc/kernel/signal_32.c
4354 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4355 /* Save user registers on the stack */
4356 frame = &rt_sf->uc.uc_mcontext;
4357 addr = frame;
4358 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4359 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4360 if (save_user_regs(regs, frame, 0, 1))
4361 goto badframe;
4362 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4363 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4364 index d183f87..1867f1a 100644
4365 --- a/arch/powerpc/kernel/signal_64.c
4366 +++ b/arch/powerpc/kernel/signal_64.c
4367 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4368 current->thread.fpscr.val = 0;
4369
4370 /* Set up to return from userspace. */
4371 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4372 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4373 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4374 } else {
4375 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4376 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4377 index 1589723..cefe690 100644
4378 --- a/arch/powerpc/kernel/traps.c
4379 +++ b/arch/powerpc/kernel/traps.c
4380 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4381 return flags;
4382 }
4383
4384 +extern void gr_handle_kernel_exploit(void);
4385 +
4386 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4387 int signr)
4388 {
4389 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4390 panic("Fatal exception in interrupt");
4391 if (panic_on_oops)
4392 panic("Fatal exception");
4393 +
4394 + gr_handle_kernel_exploit();
4395 +
4396 do_exit(signr);
4397 }
4398
4399 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4400 index 9eb5b9b..e45498a 100644
4401 --- a/arch/powerpc/kernel/vdso.c
4402 +++ b/arch/powerpc/kernel/vdso.c
4403 @@ -34,6 +34,7 @@
4404 #include <asm/firmware.h>
4405 #include <asm/vdso.h>
4406 #include <asm/vdso_datapage.h>
4407 +#include <asm/mman.h>
4408
4409 #include "setup.h"
4410
4411 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4412 vdso_base = VDSO32_MBASE;
4413 #endif
4414
4415 - current->mm->context.vdso_base = 0;
4416 + current->mm->context.vdso_base = ~0UL;
4417
4418 /* vDSO has a problem and was disabled, just don't "enable" it for the
4419 * process
4420 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4421 vdso_base = get_unmapped_area(NULL, vdso_base,
4422 (vdso_pages << PAGE_SHIFT) +
4423 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4424 - 0, 0);
4425 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4426 if (IS_ERR_VALUE(vdso_base)) {
4427 rc = vdso_base;
4428 goto fail_mmapsem;
4429 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4430 index 5eea6f3..5d10396 100644
4431 --- a/arch/powerpc/lib/usercopy_64.c
4432 +++ b/arch/powerpc/lib/usercopy_64.c
4433 @@ -9,22 +9,6 @@
4434 #include <linux/module.h>
4435 #include <asm/uaccess.h>
4436
4437 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4438 -{
4439 - if (likely(access_ok(VERIFY_READ, from, n)))
4440 - n = __copy_from_user(to, from, n);
4441 - else
4442 - memset(to, 0, n);
4443 - return n;
4444 -}
4445 -
4446 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4447 -{
4448 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4449 - n = __copy_to_user(to, from, n);
4450 - return n;
4451 -}
4452 -
4453 unsigned long copy_in_user(void __user *to, const void __user *from,
4454 unsigned long n)
4455 {
4456 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4457 return n;
4458 }
4459
4460 -EXPORT_SYMBOL(copy_from_user);
4461 -EXPORT_SYMBOL(copy_to_user);
4462 EXPORT_SYMBOL(copy_in_user);
4463
4464 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4465 index 08ffcf5..a0ab912 100644
4466 --- a/arch/powerpc/mm/fault.c
4467 +++ b/arch/powerpc/mm/fault.c
4468 @@ -32,6 +32,10 @@
4469 #include <linux/perf_event.h>
4470 #include <linux/magic.h>
4471 #include <linux/ratelimit.h>
4472 +#include <linux/slab.h>
4473 +#include <linux/pagemap.h>
4474 +#include <linux/compiler.h>
4475 +#include <linux/unistd.h>
4476
4477 #include <asm/firmware.h>
4478 #include <asm/page.h>
4479 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4480 }
4481 #endif
4482
4483 +#ifdef CONFIG_PAX_PAGEEXEC
4484 +/*
4485 + * PaX: decide what to do with offenders (regs->nip = fault address)
4486 + *
4487 + * returns 1 when task should be killed
4488 + */
4489 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4490 +{
4491 + return 1;
4492 +}
4493 +
4494 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4495 +{
4496 + unsigned long i;
4497 +
4498 + printk(KERN_ERR "PAX: bytes at PC: ");
4499 + for (i = 0; i < 5; i++) {
4500 + unsigned int c;
4501 + if (get_user(c, (unsigned int __user *)pc+i))
4502 + printk(KERN_CONT "???????? ");
4503 + else
4504 + printk(KERN_CONT "%08x ", c);
4505 + }
4506 + printk("\n");
4507 +}
4508 +#endif
4509 +
4510 /*
4511 * Check whether the instruction at regs->nip is a store using
4512 * an update addressing form which will update r1.
4513 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4514 * indicate errors in DSISR but can validly be set in SRR1.
4515 */
4516 if (trap == 0x400)
4517 - error_code &= 0x48200000;
4518 + error_code &= 0x58200000;
4519 else
4520 is_write = error_code & DSISR_ISSTORE;
4521 #else
4522 @@ -366,7 +397,7 @@ good_area:
4523 * "undefined". Of those that can be set, this is the only
4524 * one which seems bad.
4525 */
4526 - if (error_code & 0x10000000)
4527 + if (error_code & DSISR_GUARDED)
4528 /* Guarded storage error. */
4529 goto bad_area;
4530 #endif /* CONFIG_8xx */
4531 @@ -381,7 +412,7 @@ good_area:
4532 * processors use the same I/D cache coherency mechanism
4533 * as embedded.
4534 */
4535 - if (error_code & DSISR_PROTFAULT)
4536 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4537 goto bad_area;
4538 #endif /* CONFIG_PPC_STD_MMU */
4539
4540 @@ -463,6 +494,23 @@ bad_area:
4541 bad_area_nosemaphore:
4542 /* User mode accesses cause a SIGSEGV */
4543 if (user_mode(regs)) {
4544 +
4545 +#ifdef CONFIG_PAX_PAGEEXEC
4546 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4547 +#ifdef CONFIG_PPC_STD_MMU
4548 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4549 +#else
4550 + if (is_exec && regs->nip == address) {
4551 +#endif
4552 + switch (pax_handle_fetch_fault(regs)) {
4553 + }
4554 +
4555 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4556 + do_group_exit(SIGKILL);
4557 + }
4558 + }
4559 +#endif
4560 +
4561 _exception(SIGSEGV, regs, code, address);
4562 return 0;
4563 }
4564 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4565 index 67a42ed..1c7210c 100644
4566 --- a/arch/powerpc/mm/mmap_64.c
4567 +++ b/arch/powerpc/mm/mmap_64.c
4568 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4569 */
4570 if (mmap_is_legacy()) {
4571 mm->mmap_base = TASK_UNMAPPED_BASE;
4572 +
4573 +#ifdef CONFIG_PAX_RANDMMAP
4574 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4575 + mm->mmap_base += mm->delta_mmap;
4576 +#endif
4577 +
4578 mm->get_unmapped_area = arch_get_unmapped_area;
4579 mm->unmap_area = arch_unmap_area;
4580 } else {
4581 mm->mmap_base = mmap_base();
4582 +
4583 +#ifdef CONFIG_PAX_RANDMMAP
4584 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4585 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4586 +#endif
4587 +
4588 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4589 mm->unmap_area = arch_unmap_area_topdown;
4590 }
4591 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4592 index 73709f7..6b90313 100644
4593 --- a/arch/powerpc/mm/slice.c
4594 +++ b/arch/powerpc/mm/slice.c
4595 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4596 if ((mm->task_size - len) < addr)
4597 return 0;
4598 vma = find_vma(mm, addr);
4599 - return (!vma || (addr + len) <= vma->vm_start);
4600 + return check_heap_stack_gap(vma, addr, len);
4601 }
4602
4603 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4604 @@ -256,7 +256,7 @@ full_search:
4605 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4606 continue;
4607 }
4608 - if (!vma || addr + len <= vma->vm_start) {
4609 + if (check_heap_stack_gap(vma, addr, len)) {
4610 /*
4611 * Remember the place where we stopped the search:
4612 */
4613 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4614 }
4615 }
4616
4617 - addr = mm->mmap_base;
4618 - while (addr > len) {
4619 + if (mm->mmap_base < len)
4620 + addr = -ENOMEM;
4621 + else
4622 + addr = mm->mmap_base - len;
4623 +
4624 + while (!IS_ERR_VALUE(addr)) {
4625 /* Go down by chunk size */
4626 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4627 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4628
4629 /* Check for hit with different page size */
4630 mask = slice_range_to_mask(addr, len);
4631 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4632 * return with success:
4633 */
4634 vma = find_vma(mm, addr);
4635 - if (!vma || (addr + len) <= vma->vm_start) {
4636 + if (check_heap_stack_gap(vma, addr, len)) {
4637 /* remember the address as a hint for next time */
4638 if (use_cache)
4639 mm->free_area_cache = addr;
4640 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4641 mm->cached_hole_size = vma->vm_start - addr;
4642
4643 /* try just below the current vma->vm_start */
4644 - addr = vma->vm_start;
4645 + addr = skip_heap_stack_gap(vma, len);
4646 }
4647
4648 /*
4649 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4650 if (fixed && addr > (mm->task_size - len))
4651 return -EINVAL;
4652
4653 +#ifdef CONFIG_PAX_RANDMMAP
4654 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4655 + addr = 0;
4656 +#endif
4657 +
4658 /* If hint, make sure it matches our alignment restrictions */
4659 if (!fixed && addr) {
4660 addr = _ALIGN_UP(addr, 1ul << pshift);
4661 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4662 index 748347b..81bc6c7 100644
4663 --- a/arch/s390/include/asm/atomic.h
4664 +++ b/arch/s390/include/asm/atomic.h
4665 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4666 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4667 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4668
4669 +#define atomic64_read_unchecked(v) atomic64_read(v)
4670 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4671 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4672 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4673 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4674 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4675 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4676 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4677 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4678 +
4679 #define smp_mb__before_atomic_dec() smp_mb()
4680 #define smp_mb__after_atomic_dec() smp_mb()
4681 #define smp_mb__before_atomic_inc() smp_mb()
4682 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4683 index 2a30d5a..5e5586f 100644
4684 --- a/arch/s390/include/asm/cache.h
4685 +++ b/arch/s390/include/asm/cache.h
4686 @@ -11,8 +11,10 @@
4687 #ifndef __ARCH_S390_CACHE_H
4688 #define __ARCH_S390_CACHE_H
4689
4690 -#define L1_CACHE_BYTES 256
4691 +#include <linux/const.h>
4692 +
4693 #define L1_CACHE_SHIFT 8
4694 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4695 #define NET_SKB_PAD 32
4696
4697 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4698 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4699 index 06151e6..c08cb52 100644
4700 --- a/arch/s390/include/asm/elf.h
4701 +++ b/arch/s390/include/asm/elf.h
4702 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4703 the loader. We need to make sure that it is out of the way of the program
4704 that it will "exec", and that there is sufficient room for the brk. */
4705
4706 -extern unsigned long randomize_et_dyn(unsigned long base);
4707 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4708 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4709 +
4710 +#ifdef CONFIG_PAX_ASLR
4711 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4712 +
4713 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4714 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4715 +#endif
4716
4717 /* This yields a mask that user programs can use to figure out what
4718 instruction set this CPU supports. */
4719 @@ -210,7 +216,4 @@ struct linux_binprm;
4720 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4721 int arch_setup_additional_pages(struct linux_binprm *, int);
4722
4723 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4724 -#define arch_randomize_brk arch_randomize_brk
4725 -
4726 #endif
4727 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4728 index c4a93d6..4d2a9b4 100644
4729 --- a/arch/s390/include/asm/exec.h
4730 +++ b/arch/s390/include/asm/exec.h
4731 @@ -7,6 +7,6 @@
4732 #ifndef __ASM_EXEC_H
4733 #define __ASM_EXEC_H
4734
4735 -extern unsigned long arch_align_stack(unsigned long sp);
4736 +#define arch_align_stack(x) ((x) & ~0xfUL)
4737
4738 #endif /* __ASM_EXEC_H */
4739 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4740 index 1f3a79b..44d7f9c 100644
4741 --- a/arch/s390/include/asm/uaccess.h
4742 +++ b/arch/s390/include/asm/uaccess.h
4743 @@ -241,6 +241,10 @@ static inline unsigned long __must_check
4744 copy_to_user(void __user *to, const void *from, unsigned long n)
4745 {
4746 might_fault();
4747 +
4748 + if ((long)n < 0)
4749 + return n;
4750 +
4751 if (access_ok(VERIFY_WRITE, to, n))
4752 n = __copy_to_user(to, from, n);
4753 return n;
4754 @@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4755 static inline unsigned long __must_check
4756 __copy_from_user(void *to, const void __user *from, unsigned long n)
4757 {
4758 + if ((long)n < 0)
4759 + return n;
4760 +
4761 if (__builtin_constant_p(n) && (n <= 256))
4762 return uaccess.copy_from_user_small(n, from, to);
4763 else
4764 @@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4765 static inline unsigned long __must_check
4766 copy_from_user(void *to, const void __user *from, unsigned long n)
4767 {
4768 - unsigned int sz = __compiletime_object_size(to);
4769 + size_t sz = __compiletime_object_size(to);
4770
4771 might_fault();
4772 - if (unlikely(sz != -1 && sz < n)) {
4773 +
4774 + if ((long)n < 0)
4775 + return n;
4776 +
4777 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4778 copy_from_user_overflow();
4779 return n;
4780 }
4781 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4782 index dfcb343..eda788a 100644
4783 --- a/arch/s390/kernel/module.c
4784 +++ b/arch/s390/kernel/module.c
4785 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4786
4787 /* Increase core size by size of got & plt and set start
4788 offsets for got and plt. */
4789 - me->core_size = ALIGN(me->core_size, 4);
4790 - me->arch.got_offset = me->core_size;
4791 - me->core_size += me->arch.got_size;
4792 - me->arch.plt_offset = me->core_size;
4793 - me->core_size += me->arch.plt_size;
4794 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4795 + me->arch.got_offset = me->core_size_rw;
4796 + me->core_size_rw += me->arch.got_size;
4797 + me->arch.plt_offset = me->core_size_rx;
4798 + me->core_size_rx += me->arch.plt_size;
4799 return 0;
4800 }
4801
4802 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4803 if (info->got_initialized == 0) {
4804 Elf_Addr *gotent;
4805
4806 - gotent = me->module_core + me->arch.got_offset +
4807 + gotent = me->module_core_rw + me->arch.got_offset +
4808 info->got_offset;
4809 *gotent = val;
4810 info->got_initialized = 1;
4811 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4812 else if (r_type == R_390_GOTENT ||
4813 r_type == R_390_GOTPLTENT)
4814 *(unsigned int *) loc =
4815 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4816 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4817 else if (r_type == R_390_GOT64 ||
4818 r_type == R_390_GOTPLT64)
4819 *(unsigned long *) loc = val;
4820 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4821 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4822 if (info->plt_initialized == 0) {
4823 unsigned int *ip;
4824 - ip = me->module_core + me->arch.plt_offset +
4825 + ip = me->module_core_rx + me->arch.plt_offset +
4826 info->plt_offset;
4827 #ifndef CONFIG_64BIT
4828 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4829 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4830 val - loc + 0xffffUL < 0x1ffffeUL) ||
4831 (r_type == R_390_PLT32DBL &&
4832 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4833 - val = (Elf_Addr) me->module_core +
4834 + val = (Elf_Addr) me->module_core_rx +
4835 me->arch.plt_offset +
4836 info->plt_offset;
4837 val += rela->r_addend - loc;
4838 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4839 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4840 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4841 val = val + rela->r_addend -
4842 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4843 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4844 if (r_type == R_390_GOTOFF16)
4845 *(unsigned short *) loc = val;
4846 else if (r_type == R_390_GOTOFF32)
4847 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4848 break;
4849 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4850 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4851 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4852 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4853 rela->r_addend - loc;
4854 if (r_type == R_390_GOTPC)
4855 *(unsigned int *) loc = val;
4856 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4857 index 60055ce..ee4b252 100644
4858 --- a/arch/s390/kernel/process.c
4859 +++ b/arch/s390/kernel/process.c
4860 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4861 }
4862 return 0;
4863 }
4864 -
4865 -unsigned long arch_align_stack(unsigned long sp)
4866 -{
4867 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4868 - sp -= get_random_int() & ~PAGE_MASK;
4869 - return sp & ~0xf;
4870 -}
4871 -
4872 -static inline unsigned long brk_rnd(void)
4873 -{
4874 - /* 8MB for 32bit, 1GB for 64bit */
4875 - if (is_32bit_task())
4876 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4877 - else
4878 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4879 -}
4880 -
4881 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4882 -{
4883 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4884 -
4885 - if (ret < mm->brk)
4886 - return mm->brk;
4887 - return ret;
4888 -}
4889 -
4890 -unsigned long randomize_et_dyn(unsigned long base)
4891 -{
4892 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4893 -
4894 - if (!(current->flags & PF_RANDOMIZE))
4895 - return base;
4896 - if (ret < base)
4897 - return base;
4898 - return ret;
4899 -}
4900 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4901 index 2857c48..d047481 100644
4902 --- a/arch/s390/mm/mmap.c
4903 +++ b/arch/s390/mm/mmap.c
4904 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4905 */
4906 if (mmap_is_legacy()) {
4907 mm->mmap_base = TASK_UNMAPPED_BASE;
4908 +
4909 +#ifdef CONFIG_PAX_RANDMMAP
4910 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4911 + mm->mmap_base += mm->delta_mmap;
4912 +#endif
4913 +
4914 mm->get_unmapped_area = arch_get_unmapped_area;
4915 mm->unmap_area = arch_unmap_area;
4916 } else {
4917 mm->mmap_base = mmap_base();
4918 +
4919 +#ifdef CONFIG_PAX_RANDMMAP
4920 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4921 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4922 +#endif
4923 +
4924 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4925 mm->unmap_area = arch_unmap_area_topdown;
4926 }
4927 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4928 */
4929 if (mmap_is_legacy()) {
4930 mm->mmap_base = TASK_UNMAPPED_BASE;
4931 +
4932 +#ifdef CONFIG_PAX_RANDMMAP
4933 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4934 + mm->mmap_base += mm->delta_mmap;
4935 +#endif
4936 +
4937 mm->get_unmapped_area = s390_get_unmapped_area;
4938 mm->unmap_area = arch_unmap_area;
4939 } else {
4940 mm->mmap_base = mmap_base();
4941 +
4942 +#ifdef CONFIG_PAX_RANDMMAP
4943 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4944 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4945 +#endif
4946 +
4947 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4948 mm->unmap_area = arch_unmap_area_topdown;
4949 }
4950 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4951 index ae3d59f..f65f075 100644
4952 --- a/arch/score/include/asm/cache.h
4953 +++ b/arch/score/include/asm/cache.h
4954 @@ -1,7 +1,9 @@
4955 #ifndef _ASM_SCORE_CACHE_H
4956 #define _ASM_SCORE_CACHE_H
4957
4958 +#include <linux/const.h>
4959 +
4960 #define L1_CACHE_SHIFT 4
4961 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4962 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4963
4964 #endif /* _ASM_SCORE_CACHE_H */
4965 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4966 index f9f3cd5..58ff438 100644
4967 --- a/arch/score/include/asm/exec.h
4968 +++ b/arch/score/include/asm/exec.h
4969 @@ -1,6 +1,6 @@
4970 #ifndef _ASM_SCORE_EXEC_H
4971 #define _ASM_SCORE_EXEC_H
4972
4973 -extern unsigned long arch_align_stack(unsigned long sp);
4974 +#define arch_align_stack(x) (x)
4975
4976 #endif /* _ASM_SCORE_EXEC_H */
4977 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4978 index 2707023..1c2a3b7 100644
4979 --- a/arch/score/kernel/process.c
4980 +++ b/arch/score/kernel/process.c
4981 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4982
4983 return task_pt_regs(task)->cp0_epc;
4984 }
4985 -
4986 -unsigned long arch_align_stack(unsigned long sp)
4987 -{
4988 - return sp;
4989 -}
4990 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4991 index ef9e555..331bd29 100644
4992 --- a/arch/sh/include/asm/cache.h
4993 +++ b/arch/sh/include/asm/cache.h
4994 @@ -9,10 +9,11 @@
4995 #define __ASM_SH_CACHE_H
4996 #ifdef __KERNEL__
4997
4998 +#include <linux/const.h>
4999 #include <linux/init.h>
5000 #include <cpu/cache.h>
5001
5002 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5003 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5004
5005 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5006
5007 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5008 index afeb710..d1d1289 100644
5009 --- a/arch/sh/mm/mmap.c
5010 +++ b/arch/sh/mm/mmap.c
5011 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5012 addr = PAGE_ALIGN(addr);
5013
5014 vma = find_vma(mm, addr);
5015 - if (TASK_SIZE - len >= addr &&
5016 - (!vma || addr + len <= vma->vm_start))
5017 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5018 return addr;
5019 }
5020
5021 @@ -106,7 +105,7 @@ full_search:
5022 }
5023 return -ENOMEM;
5024 }
5025 - if (likely(!vma || addr + len <= vma->vm_start)) {
5026 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5027 /*
5028 * Remember the place where we stopped the search:
5029 */
5030 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5031 addr = PAGE_ALIGN(addr);
5032
5033 vma = find_vma(mm, addr);
5034 - if (TASK_SIZE - len >= addr &&
5035 - (!vma || addr + len <= vma->vm_start))
5036 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5037 return addr;
5038 }
5039
5040 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5041 /* make sure it can fit in the remaining address space */
5042 if (likely(addr > len)) {
5043 vma = find_vma(mm, addr-len);
5044 - if (!vma || addr <= vma->vm_start) {
5045 + if (check_heap_stack_gap(vma, addr - len, len)) {
5046 /* remember the address as a hint for next time */
5047 return (mm->free_area_cache = addr-len);
5048 }
5049 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5050 if (unlikely(mm->mmap_base < len))
5051 goto bottomup;
5052
5053 - addr = mm->mmap_base-len;
5054 - if (do_colour_align)
5055 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5056 + addr = mm->mmap_base - len;
5057
5058 do {
5059 + if (do_colour_align)
5060 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5061 /*
5062 * Lookup failure means no vma is above this address,
5063 * else if new region fits below vma->vm_start,
5064 * return with success:
5065 */
5066 vma = find_vma(mm, addr);
5067 - if (likely(!vma || addr+len <= vma->vm_start)) {
5068 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5069 /* remember the address as a hint for next time */
5070 return (mm->free_area_cache = addr);
5071 }
5072 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5073 mm->cached_hole_size = vma->vm_start - addr;
5074
5075 /* try just below the current vma->vm_start */
5076 - addr = vma->vm_start-len;
5077 - if (do_colour_align)
5078 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5079 - } while (likely(len < vma->vm_start));
5080 + addr = skip_heap_stack_gap(vma, len);
5081 + } while (!IS_ERR_VALUE(addr));
5082
5083 bottomup:
5084 /*
5085 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5086 index ce35a1c..2e7b8f9 100644
5087 --- a/arch/sparc/include/asm/atomic_64.h
5088 +++ b/arch/sparc/include/asm/atomic_64.h
5089 @@ -14,18 +14,40 @@
5090 #define ATOMIC64_INIT(i) { (i) }
5091
5092 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5093 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5094 +{
5095 + return v->counter;
5096 +}
5097 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5098 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5099 +{
5100 + return v->counter;
5101 +}
5102
5103 #define atomic_set(v, i) (((v)->counter) = i)
5104 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5105 +{
5106 + v->counter = i;
5107 +}
5108 #define atomic64_set(v, i) (((v)->counter) = i)
5109 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5110 +{
5111 + v->counter = i;
5112 +}
5113
5114 extern void atomic_add(int, atomic_t *);
5115 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5116 extern void atomic64_add(long, atomic64_t *);
5117 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5118 extern void atomic_sub(int, atomic_t *);
5119 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5120 extern void atomic64_sub(long, atomic64_t *);
5121 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5122
5123 extern int atomic_add_ret(int, atomic_t *);
5124 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5125 extern long atomic64_add_ret(long, atomic64_t *);
5126 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5127 extern int atomic_sub_ret(int, atomic_t *);
5128 extern long atomic64_sub_ret(long, atomic64_t *);
5129
5130 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5131 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5132
5133 #define atomic_inc_return(v) atomic_add_ret(1, v)
5134 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5135 +{
5136 + return atomic_add_ret_unchecked(1, v);
5137 +}
5138 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5139 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5140 +{
5141 + return atomic64_add_ret_unchecked(1, v);
5142 +}
5143
5144 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5145 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5146
5147 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5148 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5149 +{
5150 + return atomic_add_ret_unchecked(i, v);
5151 +}
5152 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5153 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5154 +{
5155 + return atomic64_add_ret_unchecked(i, v);
5156 +}
5157
5158 /*
5159 * atomic_inc_and_test - increment and test
5160 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5161 * other cases.
5162 */
5163 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5164 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5165 +{
5166 + return atomic_inc_return_unchecked(v) == 0;
5167 +}
5168 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5169
5170 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5171 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5172 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5173
5174 #define atomic_inc(v) atomic_add(1, v)
5175 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5176 +{
5177 + atomic_add_unchecked(1, v);
5178 +}
5179 #define atomic64_inc(v) atomic64_add(1, v)
5180 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5181 +{
5182 + atomic64_add_unchecked(1, v);
5183 +}
5184
5185 #define atomic_dec(v) atomic_sub(1, v)
5186 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5187 +{
5188 + atomic_sub_unchecked(1, v);
5189 +}
5190 #define atomic64_dec(v) atomic64_sub(1, v)
5191 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5192 +{
5193 + atomic64_sub_unchecked(1, v);
5194 +}
5195
5196 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5197 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5198
5199 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5200 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5201 +{
5202 + return cmpxchg(&v->counter, old, new);
5203 +}
5204 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5205 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5206 +{
5207 + return xchg(&v->counter, new);
5208 +}
5209
5210 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5211 {
5212 - int c, old;
5213 + int c, old, new;
5214 c = atomic_read(v);
5215 for (;;) {
5216 - if (unlikely(c == (u)))
5217 + if (unlikely(c == u))
5218 break;
5219 - old = atomic_cmpxchg((v), c, c + (a));
5220 +
5221 + asm volatile("addcc %2, %0, %0\n"
5222 +
5223 +#ifdef CONFIG_PAX_REFCOUNT
5224 + "tvs %%icc, 6\n"
5225 +#endif
5226 +
5227 + : "=r" (new)
5228 + : "0" (c), "ir" (a)
5229 + : "cc");
5230 +
5231 + old = atomic_cmpxchg(v, c, new);
5232 if (likely(old == c))
5233 break;
5234 c = old;
5235 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5236 #define atomic64_cmpxchg(v, o, n) \
5237 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5238 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5239 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5240 +{
5241 + return xchg(&v->counter, new);
5242 +}
5243
5244 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5245 {
5246 - long c, old;
5247 + long c, old, new;
5248 c = atomic64_read(v);
5249 for (;;) {
5250 - if (unlikely(c == (u)))
5251 + if (unlikely(c == u))
5252 break;
5253 - old = atomic64_cmpxchg((v), c, c + (a));
5254 +
5255 + asm volatile("addcc %2, %0, %0\n"
5256 +
5257 +#ifdef CONFIG_PAX_REFCOUNT
5258 + "tvs %%xcc, 6\n"
5259 +#endif
5260 +
5261 + : "=r" (new)
5262 + : "0" (c), "ir" (a)
5263 + : "cc");
5264 +
5265 + old = atomic64_cmpxchg(v, c, new);
5266 if (likely(old == c))
5267 break;
5268 c = old;
5269 }
5270 - return c != (u);
5271 + return c != u;
5272 }
5273
5274 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5275 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5276 index 5bb6991..5c2132e 100644
5277 --- a/arch/sparc/include/asm/cache.h
5278 +++ b/arch/sparc/include/asm/cache.h
5279 @@ -7,10 +7,12 @@
5280 #ifndef _SPARC_CACHE_H
5281 #define _SPARC_CACHE_H
5282
5283 +#include <linux/const.h>
5284 +
5285 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5286
5287 #define L1_CACHE_SHIFT 5
5288 -#define L1_CACHE_BYTES 32
5289 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5290
5291 #ifdef CONFIG_SPARC32
5292 #define SMP_CACHE_BYTES_SHIFT 5
5293 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5294 index 2d4d755..81b6662 100644
5295 --- a/arch/sparc/include/asm/elf_32.h
5296 +++ b/arch/sparc/include/asm/elf_32.h
5297 @@ -114,6 +114,13 @@ typedef struct {
5298
5299 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5300
5301 +#ifdef CONFIG_PAX_ASLR
5302 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5303 +
5304 +#define PAX_DELTA_MMAP_LEN 16
5305 +#define PAX_DELTA_STACK_LEN 16
5306 +#endif
5307 +
5308 /* This yields a mask that user programs can use to figure out what
5309 instruction set this cpu supports. This can NOT be done in userspace
5310 on Sparc. */
5311 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5312 index 7df8b7f..4946269 100644
5313 --- a/arch/sparc/include/asm/elf_64.h
5314 +++ b/arch/sparc/include/asm/elf_64.h
5315 @@ -180,6 +180,13 @@ typedef struct {
5316 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5317 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5318
5319 +#ifdef CONFIG_PAX_ASLR
5320 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5321 +
5322 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5323 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5324 +#endif
5325 +
5326 extern unsigned long sparc64_elf_hwcap;
5327 #define ELF_HWCAP sparc64_elf_hwcap
5328
5329 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5330 index e5b169b46..e90b4fa 100644
5331 --- a/arch/sparc/include/asm/pgalloc_32.h
5332 +++ b/arch/sparc/include/asm/pgalloc_32.h
5333 @@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5334 }
5335
5336 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5337 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5338
5339 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5340 unsigned long address)
5341 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5342 index 40b2d7a..22a665b 100644
5343 --- a/arch/sparc/include/asm/pgalloc_64.h
5344 +++ b/arch/sparc/include/asm/pgalloc_64.h
5345 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5346 }
5347
5348 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5349 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5350
5351 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5352 {
5353 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5354 index cbbbed5..0983069 100644
5355 --- a/arch/sparc/include/asm/pgtable_32.h
5356 +++ b/arch/sparc/include/asm/pgtable_32.h
5357 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5358 #define PAGE_SHARED SRMMU_PAGE_SHARED
5359 #define PAGE_COPY SRMMU_PAGE_COPY
5360 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5361 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5362 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5363 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5364 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5365
5366 /* Top-level page directory */
5367 @@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5368
5369 /* xwr */
5370 #define __P000 PAGE_NONE
5371 -#define __P001 PAGE_READONLY
5372 -#define __P010 PAGE_COPY
5373 -#define __P011 PAGE_COPY
5374 +#define __P001 PAGE_READONLY_NOEXEC
5375 +#define __P010 PAGE_COPY_NOEXEC
5376 +#define __P011 PAGE_COPY_NOEXEC
5377 #define __P100 PAGE_READONLY
5378 #define __P101 PAGE_READONLY
5379 #define __P110 PAGE_COPY
5380 #define __P111 PAGE_COPY
5381
5382 #define __S000 PAGE_NONE
5383 -#define __S001 PAGE_READONLY
5384 -#define __S010 PAGE_SHARED
5385 -#define __S011 PAGE_SHARED
5386 +#define __S001 PAGE_READONLY_NOEXEC
5387 +#define __S010 PAGE_SHARE_NOEXEC
5388 +#define __S011 PAGE_SHARE_NOEXEC
5389 #define __S100 PAGE_READONLY
5390 #define __S101 PAGE_READONLY
5391 #define __S110 PAGE_SHARED
5392 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5393 index 79da178..c2eede8 100644
5394 --- a/arch/sparc/include/asm/pgtsrmmu.h
5395 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5396 @@ -115,6 +115,11 @@
5397 SRMMU_EXEC | SRMMU_REF)
5398 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5399 SRMMU_EXEC | SRMMU_REF)
5400 +
5401 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5402 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5403 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5404 +
5405 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5406 SRMMU_DIRTY | SRMMU_REF)
5407
5408 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5409 index 9689176..63c18ea 100644
5410 --- a/arch/sparc/include/asm/spinlock_64.h
5411 +++ b/arch/sparc/include/asm/spinlock_64.h
5412 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5413
5414 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5415
5416 -static void inline arch_read_lock(arch_rwlock_t *lock)
5417 +static inline void arch_read_lock(arch_rwlock_t *lock)
5418 {
5419 unsigned long tmp1, tmp2;
5420
5421 __asm__ __volatile__ (
5422 "1: ldsw [%2], %0\n"
5423 " brlz,pn %0, 2f\n"
5424 -"4: add %0, 1, %1\n"
5425 +"4: addcc %0, 1, %1\n"
5426 +
5427 +#ifdef CONFIG_PAX_REFCOUNT
5428 +" tvs %%icc, 6\n"
5429 +#endif
5430 +
5431 " cas [%2], %0, %1\n"
5432 " cmp %0, %1\n"
5433 " bne,pn %%icc, 1b\n"
5434 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5435 " .previous"
5436 : "=&r" (tmp1), "=&r" (tmp2)
5437 : "r" (lock)
5438 - : "memory");
5439 + : "memory", "cc");
5440 }
5441
5442 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5443 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5444 {
5445 int tmp1, tmp2;
5446
5447 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5448 "1: ldsw [%2], %0\n"
5449 " brlz,a,pn %0, 2f\n"
5450 " mov 0, %0\n"
5451 -" add %0, 1, %1\n"
5452 +" addcc %0, 1, %1\n"
5453 +
5454 +#ifdef CONFIG_PAX_REFCOUNT
5455 +" tvs %%icc, 6\n"
5456 +#endif
5457 +
5458 " cas [%2], %0, %1\n"
5459 " cmp %0, %1\n"
5460 " bne,pn %%icc, 1b\n"
5461 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5462 return tmp1;
5463 }
5464
5465 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5466 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5467 {
5468 unsigned long tmp1, tmp2;
5469
5470 __asm__ __volatile__(
5471 "1: lduw [%2], %0\n"
5472 -" sub %0, 1, %1\n"
5473 +" subcc %0, 1, %1\n"
5474 +
5475 +#ifdef CONFIG_PAX_REFCOUNT
5476 +" tvs %%icc, 6\n"
5477 +#endif
5478 +
5479 " cas [%2], %0, %1\n"
5480 " cmp %0, %1\n"
5481 " bne,pn %%xcc, 1b\n"
5482 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5483 : "memory");
5484 }
5485
5486 -static void inline arch_write_lock(arch_rwlock_t *lock)
5487 +static inline void arch_write_lock(arch_rwlock_t *lock)
5488 {
5489 unsigned long mask, tmp1, tmp2;
5490
5491 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5492 : "memory");
5493 }
5494
5495 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5496 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5497 {
5498 __asm__ __volatile__(
5499 " stw %%g0, [%0]"
5500 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5501 : "memory");
5502 }
5503
5504 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5505 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5506 {
5507 unsigned long mask, tmp1, tmp2, result;
5508
5509 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5510 index e6cd224..3a71793 100644
5511 --- a/arch/sparc/include/asm/thread_info_32.h
5512 +++ b/arch/sparc/include/asm/thread_info_32.h
5513 @@ -49,6 +49,8 @@ struct thread_info {
5514 unsigned long w_saved;
5515
5516 struct restart_block restart_block;
5517 +
5518 + unsigned long lowest_stack;
5519 };
5520
5521 /*
5522 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5523 index cfa8c38..13f30d3 100644
5524 --- a/arch/sparc/include/asm/thread_info_64.h
5525 +++ b/arch/sparc/include/asm/thread_info_64.h
5526 @@ -63,6 +63,8 @@ struct thread_info {
5527 struct pt_regs *kern_una_regs;
5528 unsigned int kern_una_insn;
5529
5530 + unsigned long lowest_stack;
5531 +
5532 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5533 };
5534
5535 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5536 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5537 /* flag bit 6 is available */
5538 #define TIF_32BIT 7 /* 32-bit binary */
5539 -/* flag bit 8 is available */
5540 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5541 #define TIF_SECCOMP 9 /* secure computing */
5542 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5543 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5544 +
5545 /* NOTE: Thread flags >= 12 should be ones we have no interest
5546 * in using in assembly, else we can't use the mask as
5547 * an immediate value in instructions such as andcc.
5548 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5549 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5550 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5551 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5552 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5553
5554 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5555 _TIF_DO_NOTIFY_RESUME_MASK | \
5556 _TIF_NEED_RESCHED)
5557 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5558
5559 +#define _TIF_WORK_SYSCALL \
5560 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5561 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5562 +
5563 +
5564 /*
5565 * Thread-synchronous status.
5566 *
5567 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5568 index 0167d26..9acd8ed 100644
5569 --- a/arch/sparc/include/asm/uaccess.h
5570 +++ b/arch/sparc/include/asm/uaccess.h
5571 @@ -1,5 +1,13 @@
5572 #ifndef ___ASM_SPARC_UACCESS_H
5573 #define ___ASM_SPARC_UACCESS_H
5574 +
5575 +#ifdef __KERNEL__
5576 +#ifndef __ASSEMBLY__
5577 +#include <linux/types.h>
5578 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5579 +#endif
5580 +#endif
5581 +
5582 #if defined(__sparc__) && defined(__arch64__)
5583 #include <asm/uaccess_64.h>
5584 #else
5585 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5586 index 53a28dd..50c38c3 100644
5587 --- a/arch/sparc/include/asm/uaccess_32.h
5588 +++ b/arch/sparc/include/asm/uaccess_32.h
5589 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5590
5591 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5592 {
5593 - if (n && __access_ok((unsigned long) to, n))
5594 + if ((long)n < 0)
5595 + return n;
5596 +
5597 + if (n && __access_ok((unsigned long) to, n)) {
5598 + if (!__builtin_constant_p(n))
5599 + check_object_size(from, n, true);
5600 return __copy_user(to, (__force void __user *) from, n);
5601 - else
5602 + } else
5603 return n;
5604 }
5605
5606 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5607 {
5608 + if ((long)n < 0)
5609 + return n;
5610 +
5611 + if (!__builtin_constant_p(n))
5612 + check_object_size(from, n, true);
5613 +
5614 return __copy_user(to, (__force void __user *) from, n);
5615 }
5616
5617 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5618 {
5619 - if (n && __access_ok((unsigned long) from, n))
5620 + if ((long)n < 0)
5621 + return n;
5622 +
5623 + if (n && __access_ok((unsigned long) from, n)) {
5624 + if (!__builtin_constant_p(n))
5625 + check_object_size(to, n, false);
5626 return __copy_user((__force void __user *) to, from, n);
5627 - else
5628 + } else
5629 return n;
5630 }
5631
5632 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5633 {
5634 + if ((long)n < 0)
5635 + return n;
5636 +
5637 return __copy_user((__force void __user *) to, from, n);
5638 }
5639
5640 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5641 index 7c831d8..d440ca7 100644
5642 --- a/arch/sparc/include/asm/uaccess_64.h
5643 +++ b/arch/sparc/include/asm/uaccess_64.h
5644 @@ -10,6 +10,7 @@
5645 #include <linux/compiler.h>
5646 #include <linux/string.h>
5647 #include <linux/thread_info.h>
5648 +#include <linux/kernel.h>
5649 #include <asm/asi.h>
5650 #include <asm/spitfire.h>
5651 #include <asm-generic/uaccess-unaligned.h>
5652 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5653 static inline unsigned long __must_check
5654 copy_from_user(void *to, const void __user *from, unsigned long size)
5655 {
5656 - unsigned long ret = ___copy_from_user(to, from, size);
5657 + unsigned long ret;
5658
5659 + if ((long)size < 0 || size > INT_MAX)
5660 + return size;
5661 +
5662 + if (!__builtin_constant_p(size))
5663 + check_object_size(to, size, false);
5664 +
5665 + ret = ___copy_from_user(to, from, size);
5666 if (unlikely(ret))
5667 ret = copy_from_user_fixup(to, from, size);
5668
5669 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5670 static inline unsigned long __must_check
5671 copy_to_user(void __user *to, const void *from, unsigned long size)
5672 {
5673 - unsigned long ret = ___copy_to_user(to, from, size);
5674 + unsigned long ret;
5675
5676 + if ((long)size < 0 || size > INT_MAX)
5677 + return size;
5678 +
5679 + if (!__builtin_constant_p(size))
5680 + check_object_size(from, size, true);
5681 +
5682 + ret = ___copy_to_user(to, from, size);
5683 if (unlikely(ret))
5684 ret = copy_to_user_fixup(to, from, size);
5685 return ret;
5686 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5687 index 6cf591b..b49e65a 100644
5688 --- a/arch/sparc/kernel/Makefile
5689 +++ b/arch/sparc/kernel/Makefile
5690 @@ -3,7 +3,7 @@
5691 #
5692
5693 asflags-y := -ansi
5694 -ccflags-y := -Werror
5695 +#ccflags-y := -Werror
5696
5697 extra-y := head_$(BITS).o
5698
5699 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5700 index cb36e82..1c1462f 100644
5701 --- a/arch/sparc/kernel/process_32.c
5702 +++ b/arch/sparc/kernel/process_32.c
5703 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5704
5705 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5706 r->psr, r->pc, r->npc, r->y, print_tainted());
5707 - printk("PC: <%pS>\n", (void *) r->pc);
5708 + printk("PC: <%pA>\n", (void *) r->pc);
5709 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5710 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5711 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5712 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5713 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5714 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5715 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5716 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5717
5718 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5719 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5720 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5721 rw = (struct reg_window32 *) fp;
5722 pc = rw->ins[7];
5723 printk("[%08lx : ", pc);
5724 - printk("%pS ] ", (void *) pc);
5725 + printk("%pA ] ", (void *) pc);
5726 fp = rw->ins[6];
5727 } while (++count < 16);
5728 printk("\n");
5729 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5730 index aff0c72..9067b39 100644
5731 --- a/arch/sparc/kernel/process_64.c
5732 +++ b/arch/sparc/kernel/process_64.c
5733 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5734 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5735 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5736 if (regs->tstate & TSTATE_PRIV)
5737 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5738 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5739 }
5740
5741 void show_regs(struct pt_regs *regs)
5742 {
5743 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5744 regs->tpc, regs->tnpc, regs->y, print_tainted());
5745 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5746 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5747 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5748 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5749 regs->u_regs[3]);
5750 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5751 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5752 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5753 regs->u_regs[15]);
5754 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5755 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5756 show_regwindow(regs);
5757 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5758 }
5759 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5760 ((tp && tp->task) ? tp->task->pid : -1));
5761
5762 if (gp->tstate & TSTATE_PRIV) {
5763 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5764 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5765 (void *) gp->tpc,
5766 (void *) gp->o7,
5767 (void *) gp->i7,
5768 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5769 index 484daba..0674139 100644
5770 --- a/arch/sparc/kernel/ptrace_64.c
5771 +++ b/arch/sparc/kernel/ptrace_64.c
5772 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5773 return ret;
5774 }
5775
5776 +#ifdef CONFIG_GRKERNSEC_SETXID
5777 +extern void gr_delayed_cred_worker(void);
5778 +#endif
5779 +
5780 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5781 {
5782 int ret = 0;
5783 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5784 /* do the secure computing check first */
5785 secure_computing_strict(regs->u_regs[UREG_G1]);
5786
5787 +#ifdef CONFIG_GRKERNSEC_SETXID
5788 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5789 + gr_delayed_cred_worker();
5790 +#endif
5791 +
5792 if (test_thread_flag(TIF_SYSCALL_TRACE))
5793 ret = tracehook_report_syscall_entry(regs);
5794
5795 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5796
5797 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5798 {
5799 +#ifdef CONFIG_GRKERNSEC_SETXID
5800 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5801 + gr_delayed_cred_worker();
5802 +#endif
5803 +
5804 audit_syscall_exit(regs);
5805
5806 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5807 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5808 index 0c9b31b..7cb7aee 100644
5809 --- a/arch/sparc/kernel/sys_sparc_32.c
5810 +++ b/arch/sparc/kernel/sys_sparc_32.c
5811 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5812 if (len > TASK_SIZE - PAGE_SIZE)
5813 return -ENOMEM;
5814 if (!addr)
5815 - addr = TASK_UNMAPPED_BASE;
5816 + addr = current->mm->mmap_base;
5817
5818 if (flags & MAP_SHARED)
5819 addr = COLOUR_ALIGN(addr);
5820 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5821 /* At this point: (!vmm || addr < vmm->vm_end). */
5822 if (TASK_SIZE - PAGE_SIZE - len < addr)
5823 return -ENOMEM;
5824 - if (!vmm || addr + len <= vmm->vm_start)
5825 + if (check_heap_stack_gap(vmm, addr, len))
5826 return addr;
5827 addr = vmm->vm_end;
5828 if (flags & MAP_SHARED)
5829 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5830 index 275f74f..81bf5b8 100644
5831 --- a/arch/sparc/kernel/sys_sparc_64.c
5832 +++ b/arch/sparc/kernel/sys_sparc_64.c
5833 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5834 /* We do not accept a shared mapping if it would violate
5835 * cache aliasing constraints.
5836 */
5837 - if ((flags & MAP_SHARED) &&
5838 + if ((filp || (flags & MAP_SHARED)) &&
5839 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5840 return -EINVAL;
5841 return addr;
5842 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5843 if (filp || (flags & MAP_SHARED))
5844 do_color_align = 1;
5845
5846 +#ifdef CONFIG_PAX_RANDMMAP
5847 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5848 +#endif
5849 +
5850 if (addr) {
5851 if (do_color_align)
5852 addr = COLOUR_ALIGN(addr, pgoff);
5853 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5854 addr = PAGE_ALIGN(addr);
5855
5856 vma = find_vma(mm, addr);
5857 - if (task_size - len >= addr &&
5858 - (!vma || addr + len <= vma->vm_start))
5859 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5860 return addr;
5861 }
5862
5863 if (len > mm->cached_hole_size) {
5864 - start_addr = addr = mm->free_area_cache;
5865 + start_addr = addr = mm->free_area_cache;
5866 } else {
5867 - start_addr = addr = TASK_UNMAPPED_BASE;
5868 + start_addr = addr = mm->mmap_base;
5869 mm->cached_hole_size = 0;
5870 }
5871
5872 @@ -174,14 +177,14 @@ full_search:
5873 vma = find_vma(mm, VA_EXCLUDE_END);
5874 }
5875 if (unlikely(task_size < addr)) {
5876 - if (start_addr != TASK_UNMAPPED_BASE) {
5877 - start_addr = addr = TASK_UNMAPPED_BASE;
5878 + if (start_addr != mm->mmap_base) {
5879 + start_addr = addr = mm->mmap_base;
5880 mm->cached_hole_size = 0;
5881 goto full_search;
5882 }
5883 return -ENOMEM;
5884 }
5885 - if (likely(!vma || addr + len <= vma->vm_start)) {
5886 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5887 /*
5888 * Remember the place where we stopped the search:
5889 */
5890 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5891 /* We do not accept a shared mapping if it would violate
5892 * cache aliasing constraints.
5893 */
5894 - if ((flags & MAP_SHARED) &&
5895 + if ((filp || (flags & MAP_SHARED)) &&
5896 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5897 return -EINVAL;
5898 return addr;
5899 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5900 addr = PAGE_ALIGN(addr);
5901
5902 vma = find_vma(mm, addr);
5903 - if (task_size - len >= addr &&
5904 - (!vma || addr + len <= vma->vm_start))
5905 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5906 return addr;
5907 }
5908
5909 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5910 /* make sure it can fit in the remaining address space */
5911 if (likely(addr > len)) {
5912 vma = find_vma(mm, addr-len);
5913 - if (!vma || addr <= vma->vm_start) {
5914 + if (check_heap_stack_gap(vma, addr - len, len)) {
5915 /* remember the address as a hint for next time */
5916 return (mm->free_area_cache = addr-len);
5917 }
5918 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5919 if (unlikely(mm->mmap_base < len))
5920 goto bottomup;
5921
5922 - addr = mm->mmap_base-len;
5923 - if (do_color_align)
5924 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5925 + addr = mm->mmap_base - len;
5926
5927 do {
5928 + if (do_color_align)
5929 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5930 /*
5931 * Lookup failure means no vma is above this address,
5932 * else if new region fits below vma->vm_start,
5933 * return with success:
5934 */
5935 vma = find_vma(mm, addr);
5936 - if (likely(!vma || addr+len <= vma->vm_start)) {
5937 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5938 /* remember the address as a hint for next time */
5939 return (mm->free_area_cache = addr);
5940 }
5941 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5942 mm->cached_hole_size = vma->vm_start - addr;
5943
5944 /* try just below the current vma->vm_start */
5945 - addr = vma->vm_start-len;
5946 - if (do_color_align)
5947 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5948 - } while (likely(len < vma->vm_start));
5949 + addr = skip_heap_stack_gap(vma, len);
5950 + } while (!IS_ERR_VALUE(addr));
5951
5952 bottomup:
5953 /*
5954 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5955 gap == RLIM_INFINITY ||
5956 sysctl_legacy_va_layout) {
5957 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5958 +
5959 +#ifdef CONFIG_PAX_RANDMMAP
5960 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5961 + mm->mmap_base += mm->delta_mmap;
5962 +#endif
5963 +
5964 mm->get_unmapped_area = arch_get_unmapped_area;
5965 mm->unmap_area = arch_unmap_area;
5966 } else {
5967 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5968 gap = (task_size / 6 * 5);
5969
5970 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5971 +
5972 +#ifdef CONFIG_PAX_RANDMMAP
5973 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5974 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5975 +#endif
5976 +
5977 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5978 mm->unmap_area = arch_unmap_area_topdown;
5979 }
5980 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5981 index 1d7e274..b39c527 100644
5982 --- a/arch/sparc/kernel/syscalls.S
5983 +++ b/arch/sparc/kernel/syscalls.S
5984 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5985 #endif
5986 .align 32
5987 1: ldx [%g6 + TI_FLAGS], %l5
5988 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5989 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5990 be,pt %icc, rtrap
5991 nop
5992 call syscall_trace_leave
5993 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5994
5995 srl %i5, 0, %o5 ! IEU1
5996 srl %i2, 0, %o2 ! IEU0 Group
5997 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5998 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5999 bne,pn %icc, linux_syscall_trace32 ! CTI
6000 mov %i0, %l5 ! IEU1
6001 call %l7 ! CTI Group brk forced
6002 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6003
6004 mov %i3, %o3 ! IEU1
6005 mov %i4, %o4 ! IEU0 Group
6006 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6007 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6008 bne,pn %icc, linux_syscall_trace ! CTI Group
6009 mov %i0, %l5 ! IEU0
6010 2: call %l7 ! CTI Group brk forced
6011 @@ -226,7 +226,7 @@ ret_sys_call:
6012
6013 cmp %o0, -ERESTART_RESTARTBLOCK
6014 bgeu,pn %xcc, 1f
6015 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6016 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6017 80:
6018 /* System call success, clear Carry condition code. */
6019 andn %g3, %g2, %g3
6020 @@ -241,7 +241,7 @@ ret_sys_call:
6021 /* System call failure, set Carry condition code.
6022 * Also, get abs(errno) to return to the process.
6023 */
6024 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6025 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6026 sub %g0, %o0, %o0
6027 or %g3, %g2, %g3
6028 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6029 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6030 index a5785ea..405c5f7 100644
6031 --- a/arch/sparc/kernel/traps_32.c
6032 +++ b/arch/sparc/kernel/traps_32.c
6033 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6034 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6035 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6036
6037 +extern void gr_handle_kernel_exploit(void);
6038 +
6039 void die_if_kernel(char *str, struct pt_regs *regs)
6040 {
6041 static int die_counter;
6042 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6043 count++ < 30 &&
6044 (((unsigned long) rw) >= PAGE_OFFSET) &&
6045 !(((unsigned long) rw) & 0x7)) {
6046 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6047 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6048 (void *) rw->ins[7]);
6049 rw = (struct reg_window32 *)rw->ins[6];
6050 }
6051 }
6052 printk("Instruction DUMP:");
6053 instruction_dump ((unsigned long *) regs->pc);
6054 - if(regs->psr & PSR_PS)
6055 + if(regs->psr & PSR_PS) {
6056 + gr_handle_kernel_exploit();
6057 do_exit(SIGKILL);
6058 + }
6059 do_exit(SIGSEGV);
6060 }
6061
6062 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6063 index 3b05e66..6ea2917 100644
6064 --- a/arch/sparc/kernel/traps_64.c
6065 +++ b/arch/sparc/kernel/traps_64.c
6066 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6067 i + 1,
6068 p->trapstack[i].tstate, p->trapstack[i].tpc,
6069 p->trapstack[i].tnpc, p->trapstack[i].tt);
6070 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6071 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6072 }
6073 }
6074
6075 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6076
6077 lvl -= 0x100;
6078 if (regs->tstate & TSTATE_PRIV) {
6079 +
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + if (lvl == 6)
6082 + pax_report_refcount_overflow(regs);
6083 +#endif
6084 +
6085 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6086 die_if_kernel(buffer, regs);
6087 }
6088 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6089 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6090 {
6091 char buffer[32];
6092 -
6093 +
6094 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6095 0, lvl, SIGTRAP) == NOTIFY_STOP)
6096 return;
6097
6098 +#ifdef CONFIG_PAX_REFCOUNT
6099 + if (lvl == 6)
6100 + pax_report_refcount_overflow(regs);
6101 +#endif
6102 +
6103 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6104
6105 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6106 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6107 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6108 printk("%s" "ERROR(%d): ",
6109 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6110 - printk("TPC<%pS>\n", (void *) regs->tpc);
6111 + printk("TPC<%pA>\n", (void *) regs->tpc);
6112 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6113 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6114 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6115 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6116 smp_processor_id(),
6117 (type & 0x1) ? 'I' : 'D',
6118 regs->tpc);
6119 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6120 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6121 panic("Irrecoverable Cheetah+ parity error.");
6122 }
6123
6124 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6125 smp_processor_id(),
6126 (type & 0x1) ? 'I' : 'D',
6127 regs->tpc);
6128 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6129 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6130 }
6131
6132 struct sun4v_error_entry {
6133 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6134
6135 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6136 regs->tpc, tl);
6137 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6138 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6139 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6140 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6141 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6142 (void *) regs->u_regs[UREG_I7]);
6143 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6144 "pte[%lx] error[%lx]\n",
6145 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6146
6147 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6148 regs->tpc, tl);
6149 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6150 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6151 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6152 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6153 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6154 (void *) regs->u_regs[UREG_I7]);
6155 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6156 "pte[%lx] error[%lx]\n",
6157 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6158 fp = (unsigned long)sf->fp + STACK_BIAS;
6159 }
6160
6161 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6162 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6163 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6164 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6165 int index = tsk->curr_ret_stack;
6166 if (tsk->ret_stack && index >= graph) {
6167 pc = tsk->ret_stack[index - graph].ret;
6168 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6169 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6170 graph++;
6171 }
6172 }
6173 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6174 return (struct reg_window *) (fp + STACK_BIAS);
6175 }
6176
6177 +extern void gr_handle_kernel_exploit(void);
6178 +
6179 void die_if_kernel(char *str, struct pt_regs *regs)
6180 {
6181 static int die_counter;
6182 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6183 while (rw &&
6184 count++ < 30 &&
6185 kstack_valid(tp, (unsigned long) rw)) {
6186 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6187 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6188 (void *) rw->ins[7]);
6189
6190 rw = kernel_stack_up(rw);
6191 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6192 }
6193 user_instruction_dump ((unsigned int __user *) regs->tpc);
6194 }
6195 - if (regs->tstate & TSTATE_PRIV)
6196 + if (regs->tstate & TSTATE_PRIV) {
6197 + gr_handle_kernel_exploit();
6198 do_exit(SIGKILL);
6199 + }
6200 do_exit(SIGSEGV);
6201 }
6202 EXPORT_SYMBOL(die_if_kernel);
6203 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6204 index f81d038..e7a4680 100644
6205 --- a/arch/sparc/kernel/unaligned_64.c
6206 +++ b/arch/sparc/kernel/unaligned_64.c
6207 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6208 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6209
6210 if (__ratelimit(&ratelimit)) {
6211 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6212 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6213 regs->tpc, (void *) regs->tpc);
6214 }
6215 }
6216 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6217 index dff4096..bd9a388 100644
6218 --- a/arch/sparc/lib/Makefile
6219 +++ b/arch/sparc/lib/Makefile
6220 @@ -2,7 +2,7 @@
6221 #
6222
6223 asflags-y := -ansi -DST_DIV0=0x02
6224 -ccflags-y := -Werror
6225 +#ccflags-y := -Werror
6226
6227 lib-$(CONFIG_SPARC32) += ashrdi3.o
6228 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6229 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6230 index 4d502da..527c48d 100644
6231 --- a/arch/sparc/lib/atomic_64.S
6232 +++ b/arch/sparc/lib/atomic_64.S
6233 @@ -17,7 +17,12 @@
6234 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6235 BACKOFF_SETUP(%o2)
6236 1: lduw [%o1], %g1
6237 - add %g1, %o0, %g7
6238 + addcc %g1, %o0, %g7
6239 +
6240 +#ifdef CONFIG_PAX_REFCOUNT
6241 + tvs %icc, 6
6242 +#endif
6243 +
6244 cas [%o1], %g1, %g7
6245 cmp %g1, %g7
6246 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6247 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6248 2: BACKOFF_SPIN(%o2, %o3, 1b)
6249 ENDPROC(atomic_add)
6250
6251 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6252 + BACKOFF_SETUP(%o2)
6253 +1: lduw [%o1], %g1
6254 + add %g1, %o0, %g7
6255 + cas [%o1], %g1, %g7
6256 + cmp %g1, %g7
6257 + bne,pn %icc, 2f
6258 + nop
6259 + retl
6260 + nop
6261 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6262 +ENDPROC(atomic_add_unchecked)
6263 +
6264 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6265 BACKOFF_SETUP(%o2)
6266 1: lduw [%o1], %g1
6267 - sub %g1, %o0, %g7
6268 + subcc %g1, %o0, %g7
6269 +
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + tvs %icc, 6
6272 +#endif
6273 +
6274 cas [%o1], %g1, %g7
6275 cmp %g1, %g7
6276 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6277 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6278 2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 ENDPROC(atomic_sub)
6280
6281 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6282 + BACKOFF_SETUP(%o2)
6283 +1: lduw [%o1], %g1
6284 + sub %g1, %o0, %g7
6285 + cas [%o1], %g1, %g7
6286 + cmp %g1, %g7
6287 + bne,pn %icc, 2f
6288 + nop
6289 + retl
6290 + nop
6291 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6292 +ENDPROC(atomic_sub_unchecked)
6293 +
6294 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6295 BACKOFF_SETUP(%o2)
6296 1: lduw [%o1], %g1
6297 - add %g1, %o0, %g7
6298 + addcc %g1, %o0, %g7
6299 +
6300 +#ifdef CONFIG_PAX_REFCOUNT
6301 + tvs %icc, 6
6302 +#endif
6303 +
6304 cas [%o1], %g1, %g7
6305 cmp %g1, %g7
6306 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6307 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6308 2: BACKOFF_SPIN(%o2, %o3, 1b)
6309 ENDPROC(atomic_add_ret)
6310
6311 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6312 + BACKOFF_SETUP(%o2)
6313 +1: lduw [%o1], %g1
6314 + addcc %g1, %o0, %g7
6315 + cas [%o1], %g1, %g7
6316 + cmp %g1, %g7
6317 + bne,pn %icc, 2f
6318 + add %g7, %o0, %g7
6319 + sra %g7, 0, %o0
6320 + retl
6321 + nop
6322 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6323 +ENDPROC(atomic_add_ret_unchecked)
6324 +
6325 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6326 BACKOFF_SETUP(%o2)
6327 1: lduw [%o1], %g1
6328 - sub %g1, %o0, %g7
6329 + subcc %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 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6339 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6340 BACKOFF_SETUP(%o2)
6341 1: ldx [%o1], %g1
6342 - add %g1, %o0, %g7
6343 + addcc %g1, %o0, %g7
6344 +
6345 +#ifdef CONFIG_PAX_REFCOUNT
6346 + tvs %xcc, 6
6347 +#endif
6348 +
6349 casx [%o1], %g1, %g7
6350 cmp %g1, %g7
6351 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6352 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6353 2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 ENDPROC(atomic64_add)
6355
6356 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6357 + BACKOFF_SETUP(%o2)
6358 +1: ldx [%o1], %g1
6359 + addcc %g1, %o0, %g7
6360 + casx [%o1], %g1, %g7
6361 + cmp %g1, %g7
6362 + bne,pn %xcc, 2f
6363 + nop
6364 + retl
6365 + nop
6366 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6367 +ENDPROC(atomic64_add_unchecked)
6368 +
6369 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6370 BACKOFF_SETUP(%o2)
6371 1: ldx [%o1], %g1
6372 - sub %g1, %o0, %g7
6373 + subcc %g1, %o0, %g7
6374 +
6375 +#ifdef CONFIG_PAX_REFCOUNT
6376 + tvs %xcc, 6
6377 +#endif
6378 +
6379 casx [%o1], %g1, %g7
6380 cmp %g1, %g7
6381 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6382 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6383 2: BACKOFF_SPIN(%o2, %o3, 1b)
6384 ENDPROC(atomic64_sub)
6385
6386 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6387 + BACKOFF_SETUP(%o2)
6388 +1: ldx [%o1], %g1
6389 + subcc %g1, %o0, %g7
6390 + casx [%o1], %g1, %g7
6391 + cmp %g1, %g7
6392 + bne,pn %xcc, 2f
6393 + nop
6394 + retl
6395 + nop
6396 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6397 +ENDPROC(atomic64_sub_unchecked)
6398 +
6399 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6400 BACKOFF_SETUP(%o2)
6401 1: ldx [%o1], %g1
6402 - add %g1, %o0, %g7
6403 + addcc %g1, %o0, %g7
6404 +
6405 +#ifdef CONFIG_PAX_REFCOUNT
6406 + tvs %xcc, 6
6407 +#endif
6408 +
6409 casx [%o1], %g1, %g7
6410 cmp %g1, %g7
6411 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6412 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6413 2: BACKOFF_SPIN(%o2, %o3, 1b)
6414 ENDPROC(atomic64_add_ret)
6415
6416 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6417 + BACKOFF_SETUP(%o2)
6418 +1: ldx [%o1], %g1
6419 + addcc %g1, %o0, %g7
6420 + casx [%o1], %g1, %g7
6421 + cmp %g1, %g7
6422 + bne,pn %xcc, 2f
6423 + add %g7, %o0, %g7
6424 + mov %g7, %o0
6425 + retl
6426 + nop
6427 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6428 +ENDPROC(atomic64_add_ret_unchecked)
6429 +
6430 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6431 BACKOFF_SETUP(%o2)
6432 1: ldx [%o1], %g1
6433 - sub %g1, %o0, %g7
6434 + subcc %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 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6444 index 3b31218..345c609 100644
6445 --- a/arch/sparc/lib/ksyms.c
6446 +++ b/arch/sparc/lib/ksyms.c
6447 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6448
6449 /* Atomic counter implementation. */
6450 EXPORT_SYMBOL(atomic_add);
6451 +EXPORT_SYMBOL(atomic_add_unchecked);
6452 EXPORT_SYMBOL(atomic_add_ret);
6453 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6454 EXPORT_SYMBOL(atomic_sub);
6455 +EXPORT_SYMBOL(atomic_sub_unchecked);
6456 EXPORT_SYMBOL(atomic_sub_ret);
6457 EXPORT_SYMBOL(atomic64_add);
6458 +EXPORT_SYMBOL(atomic64_add_unchecked);
6459 EXPORT_SYMBOL(atomic64_add_ret);
6460 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6461 EXPORT_SYMBOL(atomic64_sub);
6462 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6463 EXPORT_SYMBOL(atomic64_sub_ret);
6464
6465 /* Atomic bit operations. */
6466 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6467 index 30c3ecc..736f015 100644
6468 --- a/arch/sparc/mm/Makefile
6469 +++ b/arch/sparc/mm/Makefile
6470 @@ -2,7 +2,7 @@
6471 #
6472
6473 asflags-y := -ansi
6474 -ccflags-y := -Werror
6475 +#ccflags-y := -Werror
6476
6477 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6478 obj-y += fault_$(BITS).o
6479 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6480 index f46cf6b..cc0666bae 100644
6481 --- a/arch/sparc/mm/fault_32.c
6482 +++ b/arch/sparc/mm/fault_32.c
6483 @@ -21,6 +21,9 @@
6484 #include <linux/perf_event.h>
6485 #include <linux/interrupt.h>
6486 #include <linux/kdebug.h>
6487 +#include <linux/slab.h>
6488 +#include <linux/pagemap.h>
6489 +#include <linux/compiler.h>
6490
6491 #include <asm/page.h>
6492 #include <asm/pgtable.h>
6493 @@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6494 return safe_compute_effective_address(regs, insn);
6495 }
6496
6497 +#ifdef CONFIG_PAX_PAGEEXEC
6498 +#ifdef CONFIG_PAX_DLRESOLVE
6499 +static void pax_emuplt_close(struct vm_area_struct *vma)
6500 +{
6501 + vma->vm_mm->call_dl_resolve = 0UL;
6502 +}
6503 +
6504 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6505 +{
6506 + unsigned int *kaddr;
6507 +
6508 + vmf->page = alloc_page(GFP_HIGHUSER);
6509 + if (!vmf->page)
6510 + return VM_FAULT_OOM;
6511 +
6512 + kaddr = kmap(vmf->page);
6513 + memset(kaddr, 0, PAGE_SIZE);
6514 + kaddr[0] = 0x9DE3BFA8U; /* save */
6515 + flush_dcache_page(vmf->page);
6516 + kunmap(vmf->page);
6517 + return VM_FAULT_MAJOR;
6518 +}
6519 +
6520 +static const struct vm_operations_struct pax_vm_ops = {
6521 + .close = pax_emuplt_close,
6522 + .fault = pax_emuplt_fault
6523 +};
6524 +
6525 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6526 +{
6527 + int ret;
6528 +
6529 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6530 + vma->vm_mm = current->mm;
6531 + vma->vm_start = addr;
6532 + vma->vm_end = addr + PAGE_SIZE;
6533 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6534 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6535 + vma->vm_ops = &pax_vm_ops;
6536 +
6537 + ret = insert_vm_struct(current->mm, vma);
6538 + if (ret)
6539 + return ret;
6540 +
6541 + ++current->mm->total_vm;
6542 + return 0;
6543 +}
6544 +#endif
6545 +
6546 +/*
6547 + * PaX: decide what to do with offenders (regs->pc = fault address)
6548 + *
6549 + * returns 1 when task should be killed
6550 + * 2 when patched PLT trampoline was detected
6551 + * 3 when unpatched PLT trampoline was detected
6552 + */
6553 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6554 +{
6555 +
6556 +#ifdef CONFIG_PAX_EMUPLT
6557 + int err;
6558 +
6559 + do { /* PaX: patched PLT emulation #1 */
6560 + unsigned int sethi1, sethi2, jmpl;
6561 +
6562 + err = get_user(sethi1, (unsigned int *)regs->pc);
6563 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6564 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6565 +
6566 + if (err)
6567 + break;
6568 +
6569 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6570 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6571 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6572 + {
6573 + unsigned int addr;
6574 +
6575 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6576 + addr = regs->u_regs[UREG_G1];
6577 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6578 + regs->pc = addr;
6579 + regs->npc = addr+4;
6580 + return 2;
6581 + }
6582 + } while (0);
6583 +
6584 + do { /* PaX: patched PLT emulation #2 */
6585 + unsigned int ba;
6586 +
6587 + err = get_user(ba, (unsigned int *)regs->pc);
6588 +
6589 + if (err)
6590 + break;
6591 +
6592 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6593 + unsigned int addr;
6594 +
6595 + if ((ba & 0xFFC00000U) == 0x30800000U)
6596 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6597 + else
6598 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6599 + regs->pc = addr;
6600 + regs->npc = addr+4;
6601 + return 2;
6602 + }
6603 + } while (0);
6604 +
6605 + do { /* PaX: patched PLT emulation #3 */
6606 + unsigned int sethi, bajmpl, nop;
6607 +
6608 + err = get_user(sethi, (unsigned int *)regs->pc);
6609 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6610 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6611 +
6612 + if (err)
6613 + break;
6614 +
6615 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6616 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6617 + nop == 0x01000000U)
6618 + {
6619 + unsigned int addr;
6620 +
6621 + addr = (sethi & 0x003FFFFFU) << 10;
6622 + regs->u_regs[UREG_G1] = addr;
6623 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6624 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6625 + else
6626 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6627 + regs->pc = addr;
6628 + regs->npc = addr+4;
6629 + return 2;
6630 + }
6631 + } while (0);
6632 +
6633 + do { /* PaX: unpatched PLT emulation step 1 */
6634 + unsigned int sethi, ba, nop;
6635 +
6636 + err = get_user(sethi, (unsigned int *)regs->pc);
6637 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6638 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6639 +
6640 + if (err)
6641 + break;
6642 +
6643 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6644 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6645 + nop == 0x01000000U)
6646 + {
6647 + unsigned int addr, save, call;
6648 +
6649 + if ((ba & 0xFFC00000U) == 0x30800000U)
6650 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6651 + else
6652 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6653 +
6654 + err = get_user(save, (unsigned int *)addr);
6655 + err |= get_user(call, (unsigned int *)(addr+4));
6656 + err |= get_user(nop, (unsigned int *)(addr+8));
6657 + if (err)
6658 + break;
6659 +
6660 +#ifdef CONFIG_PAX_DLRESOLVE
6661 + if (save == 0x9DE3BFA8U &&
6662 + (call & 0xC0000000U) == 0x40000000U &&
6663 + nop == 0x01000000U)
6664 + {
6665 + struct vm_area_struct *vma;
6666 + unsigned long call_dl_resolve;
6667 +
6668 + down_read(&current->mm->mmap_sem);
6669 + call_dl_resolve = current->mm->call_dl_resolve;
6670 + up_read(&current->mm->mmap_sem);
6671 + if (likely(call_dl_resolve))
6672 + goto emulate;
6673 +
6674 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6675 +
6676 + down_write(&current->mm->mmap_sem);
6677 + if (current->mm->call_dl_resolve) {
6678 + call_dl_resolve = current->mm->call_dl_resolve;
6679 + up_write(&current->mm->mmap_sem);
6680 + if (vma)
6681 + kmem_cache_free(vm_area_cachep, vma);
6682 + goto emulate;
6683 + }
6684 +
6685 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6686 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6687 + up_write(&current->mm->mmap_sem);
6688 + if (vma)
6689 + kmem_cache_free(vm_area_cachep, vma);
6690 + return 1;
6691 + }
6692 +
6693 + if (pax_insert_vma(vma, call_dl_resolve)) {
6694 + up_write(&current->mm->mmap_sem);
6695 + kmem_cache_free(vm_area_cachep, vma);
6696 + return 1;
6697 + }
6698 +
6699 + current->mm->call_dl_resolve = call_dl_resolve;
6700 + up_write(&current->mm->mmap_sem);
6701 +
6702 +emulate:
6703 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6704 + regs->pc = call_dl_resolve;
6705 + regs->npc = addr+4;
6706 + return 3;
6707 + }
6708 +#endif
6709 +
6710 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6711 + if ((save & 0xFFC00000U) == 0x05000000U &&
6712 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6713 + nop == 0x01000000U)
6714 + {
6715 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6716 + regs->u_regs[UREG_G2] = addr + 4;
6717 + addr = (save & 0x003FFFFFU) << 10;
6718 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6719 + regs->pc = addr;
6720 + regs->npc = addr+4;
6721 + return 3;
6722 + }
6723 + }
6724 + } while (0);
6725 +
6726 + do { /* PaX: unpatched PLT emulation step 2 */
6727 + unsigned int save, call, nop;
6728 +
6729 + err = get_user(save, (unsigned int *)(regs->pc-4));
6730 + err |= get_user(call, (unsigned int *)regs->pc);
6731 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6732 + if (err)
6733 + break;
6734 +
6735 + if (save == 0x9DE3BFA8U &&
6736 + (call & 0xC0000000U) == 0x40000000U &&
6737 + nop == 0x01000000U)
6738 + {
6739 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6740 +
6741 + regs->u_regs[UREG_RETPC] = regs->pc;
6742 + regs->pc = dl_resolve;
6743 + regs->npc = dl_resolve+4;
6744 + return 3;
6745 + }
6746 + } while (0);
6747 +#endif
6748 +
6749 + return 1;
6750 +}
6751 +
6752 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6753 +{
6754 + unsigned long i;
6755 +
6756 + printk(KERN_ERR "PAX: bytes at PC: ");
6757 + for (i = 0; i < 8; i++) {
6758 + unsigned int c;
6759 + if (get_user(c, (unsigned int *)pc+i))
6760 + printk(KERN_CONT "???????? ");
6761 + else
6762 + printk(KERN_CONT "%08x ", c);
6763 + }
6764 + printk("\n");
6765 +}
6766 +#endif
6767 +
6768 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6769 int text_fault)
6770 {
6771 @@ -248,6 +522,24 @@ good_area:
6772 if (!(vma->vm_flags & VM_WRITE))
6773 goto bad_area;
6774 } else {
6775 +
6776 +#ifdef CONFIG_PAX_PAGEEXEC
6777 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6778 + up_read(&mm->mmap_sem);
6779 + switch (pax_handle_fetch_fault(regs)) {
6780 +
6781 +#ifdef CONFIG_PAX_EMUPLT
6782 + case 2:
6783 + case 3:
6784 + return;
6785 +#endif
6786 +
6787 + }
6788 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6789 + do_group_exit(SIGKILL);
6790 + }
6791 +#endif
6792 +
6793 /* Allow reads even for write-only mappings */
6794 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6795 goto bad_area;
6796 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6797 index 1fe0429..8dd5dd5 100644
6798 --- a/arch/sparc/mm/fault_64.c
6799 +++ b/arch/sparc/mm/fault_64.c
6800 @@ -21,6 +21,9 @@
6801 #include <linux/kprobes.h>
6802 #include <linux/kdebug.h>
6803 #include <linux/percpu.h>
6804 +#include <linux/slab.h>
6805 +#include <linux/pagemap.h>
6806 +#include <linux/compiler.h>
6807
6808 #include <asm/page.h>
6809 #include <asm/pgtable.h>
6810 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6811 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6812 regs->tpc);
6813 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6814 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6815 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6816 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6817 dump_stack();
6818 unhandled_fault(regs->tpc, current, regs);
6819 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6820 show_regs(regs);
6821 }
6822
6823 +#ifdef CONFIG_PAX_PAGEEXEC
6824 +#ifdef CONFIG_PAX_DLRESOLVE
6825 +static void pax_emuplt_close(struct vm_area_struct *vma)
6826 +{
6827 + vma->vm_mm->call_dl_resolve = 0UL;
6828 +}
6829 +
6830 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6831 +{
6832 + unsigned int *kaddr;
6833 +
6834 + vmf->page = alloc_page(GFP_HIGHUSER);
6835 + if (!vmf->page)
6836 + return VM_FAULT_OOM;
6837 +
6838 + kaddr = kmap(vmf->page);
6839 + memset(kaddr, 0, PAGE_SIZE);
6840 + kaddr[0] = 0x9DE3BFA8U; /* save */
6841 + flush_dcache_page(vmf->page);
6842 + kunmap(vmf->page);
6843 + return VM_FAULT_MAJOR;
6844 +}
6845 +
6846 +static const struct vm_operations_struct pax_vm_ops = {
6847 + .close = pax_emuplt_close,
6848 + .fault = pax_emuplt_fault
6849 +};
6850 +
6851 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6852 +{
6853 + int ret;
6854 +
6855 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6856 + vma->vm_mm = current->mm;
6857 + vma->vm_start = addr;
6858 + vma->vm_end = addr + PAGE_SIZE;
6859 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6860 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6861 + vma->vm_ops = &pax_vm_ops;
6862 +
6863 + ret = insert_vm_struct(current->mm, vma);
6864 + if (ret)
6865 + return ret;
6866 +
6867 + ++current->mm->total_vm;
6868 + return 0;
6869 +}
6870 +#endif
6871 +
6872 +/*
6873 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6874 + *
6875 + * returns 1 when task should be killed
6876 + * 2 when patched PLT trampoline was detected
6877 + * 3 when unpatched PLT trampoline was detected
6878 + */
6879 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6880 +{
6881 +
6882 +#ifdef CONFIG_PAX_EMUPLT
6883 + int err;
6884 +
6885 + do { /* PaX: patched PLT emulation #1 */
6886 + unsigned int sethi1, sethi2, jmpl;
6887 +
6888 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6889 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6890 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6891 +
6892 + if (err)
6893 + break;
6894 +
6895 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6896 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6897 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6898 + {
6899 + unsigned long addr;
6900 +
6901 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6902 + addr = regs->u_regs[UREG_G1];
6903 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6904 +
6905 + if (test_thread_flag(TIF_32BIT))
6906 + addr &= 0xFFFFFFFFUL;
6907 +
6908 + regs->tpc = addr;
6909 + regs->tnpc = addr+4;
6910 + return 2;
6911 + }
6912 + } while (0);
6913 +
6914 + do { /* PaX: patched PLT emulation #2 */
6915 + unsigned int ba;
6916 +
6917 + err = get_user(ba, (unsigned int *)regs->tpc);
6918 +
6919 + if (err)
6920 + break;
6921 +
6922 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6923 + unsigned long addr;
6924 +
6925 + if ((ba & 0xFFC00000U) == 0x30800000U)
6926 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6927 + else
6928 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6929 +
6930 + if (test_thread_flag(TIF_32BIT))
6931 + addr &= 0xFFFFFFFFUL;
6932 +
6933 + regs->tpc = addr;
6934 + regs->tnpc = addr+4;
6935 + return 2;
6936 + }
6937 + } while (0);
6938 +
6939 + do { /* PaX: patched PLT emulation #3 */
6940 + unsigned int sethi, bajmpl, nop;
6941 +
6942 + err = get_user(sethi, (unsigned int *)regs->tpc);
6943 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6944 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6945 +
6946 + if (err)
6947 + break;
6948 +
6949 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6950 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6951 + nop == 0x01000000U)
6952 + {
6953 + unsigned long addr;
6954 +
6955 + addr = (sethi & 0x003FFFFFU) << 10;
6956 + regs->u_regs[UREG_G1] = addr;
6957 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6958 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6959 + else
6960 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6961 +
6962 + if (test_thread_flag(TIF_32BIT))
6963 + addr &= 0xFFFFFFFFUL;
6964 +
6965 + regs->tpc = addr;
6966 + regs->tnpc = addr+4;
6967 + return 2;
6968 + }
6969 + } while (0);
6970 +
6971 + do { /* PaX: patched PLT emulation #4 */
6972 + unsigned int sethi, mov1, call, mov2;
6973 +
6974 + err = get_user(sethi, (unsigned int *)regs->tpc);
6975 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6976 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6977 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6978 +
6979 + if (err)
6980 + break;
6981 +
6982 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6983 + mov1 == 0x8210000FU &&
6984 + (call & 0xC0000000U) == 0x40000000U &&
6985 + mov2 == 0x9E100001U)
6986 + {
6987 + unsigned long addr;
6988 +
6989 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6990 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6991 +
6992 + if (test_thread_flag(TIF_32BIT))
6993 + addr &= 0xFFFFFFFFUL;
6994 +
6995 + regs->tpc = addr;
6996 + regs->tnpc = addr+4;
6997 + return 2;
6998 + }
6999 + } while (0);
7000 +
7001 + do { /* PaX: patched PLT emulation #5 */
7002 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7003 +
7004 + err = get_user(sethi, (unsigned int *)regs->tpc);
7005 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7006 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7007 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7008 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7009 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7010 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7011 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7012 +
7013 + if (err)
7014 + break;
7015 +
7016 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7017 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7018 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7019 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7020 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7021 + sllx == 0x83287020U &&
7022 + jmpl == 0x81C04005U &&
7023 + nop == 0x01000000U)
7024 + {
7025 + unsigned long addr;
7026 +
7027 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7028 + regs->u_regs[UREG_G1] <<= 32;
7029 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7030 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7031 + regs->tpc = addr;
7032 + regs->tnpc = addr+4;
7033 + return 2;
7034 + }
7035 + } while (0);
7036 +
7037 + do { /* PaX: patched PLT emulation #6 */
7038 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7039 +
7040 + err = get_user(sethi, (unsigned int *)regs->tpc);
7041 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7042 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7043 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7044 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7045 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7046 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7047 +
7048 + if (err)
7049 + break;
7050 +
7051 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7052 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7053 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7054 + sllx == 0x83287020U &&
7055 + (or & 0xFFFFE000U) == 0x8A116000U &&
7056 + jmpl == 0x81C04005U &&
7057 + nop == 0x01000000U)
7058 + {
7059 + unsigned long addr;
7060 +
7061 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7062 + regs->u_regs[UREG_G1] <<= 32;
7063 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7064 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7065 + regs->tpc = addr;
7066 + regs->tnpc = addr+4;
7067 + return 2;
7068 + }
7069 + } while (0);
7070 +
7071 + do { /* PaX: unpatched PLT emulation step 1 */
7072 + unsigned int sethi, ba, nop;
7073 +
7074 + err = get_user(sethi, (unsigned int *)regs->tpc);
7075 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7076 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7077 +
7078 + if (err)
7079 + break;
7080 +
7081 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7082 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7083 + nop == 0x01000000U)
7084 + {
7085 + unsigned long addr;
7086 + unsigned int save, call;
7087 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7088 +
7089 + if ((ba & 0xFFC00000U) == 0x30800000U)
7090 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7091 + else
7092 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7093 +
7094 + if (test_thread_flag(TIF_32BIT))
7095 + addr &= 0xFFFFFFFFUL;
7096 +
7097 + err = get_user(save, (unsigned int *)addr);
7098 + err |= get_user(call, (unsigned int *)(addr+4));
7099 + err |= get_user(nop, (unsigned int *)(addr+8));
7100 + if (err)
7101 + break;
7102 +
7103 +#ifdef CONFIG_PAX_DLRESOLVE
7104 + if (save == 0x9DE3BFA8U &&
7105 + (call & 0xC0000000U) == 0x40000000U &&
7106 + nop == 0x01000000U)
7107 + {
7108 + struct vm_area_struct *vma;
7109 + unsigned long call_dl_resolve;
7110 +
7111 + down_read(&current->mm->mmap_sem);
7112 + call_dl_resolve = current->mm->call_dl_resolve;
7113 + up_read(&current->mm->mmap_sem);
7114 + if (likely(call_dl_resolve))
7115 + goto emulate;
7116 +
7117 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7118 +
7119 + down_write(&current->mm->mmap_sem);
7120 + if (current->mm->call_dl_resolve) {
7121 + call_dl_resolve = current->mm->call_dl_resolve;
7122 + up_write(&current->mm->mmap_sem);
7123 + if (vma)
7124 + kmem_cache_free(vm_area_cachep, vma);
7125 + goto emulate;
7126 + }
7127 +
7128 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7129 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7130 + up_write(&current->mm->mmap_sem);
7131 + if (vma)
7132 + kmem_cache_free(vm_area_cachep, vma);
7133 + return 1;
7134 + }
7135 +
7136 + if (pax_insert_vma(vma, call_dl_resolve)) {
7137 + up_write(&current->mm->mmap_sem);
7138 + kmem_cache_free(vm_area_cachep, vma);
7139 + return 1;
7140 + }
7141 +
7142 + current->mm->call_dl_resolve = call_dl_resolve;
7143 + up_write(&current->mm->mmap_sem);
7144 +
7145 +emulate:
7146 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7147 + regs->tpc = call_dl_resolve;
7148 + regs->tnpc = addr+4;
7149 + return 3;
7150 + }
7151 +#endif
7152 +
7153 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7154 + if ((save & 0xFFC00000U) == 0x05000000U &&
7155 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7156 + nop == 0x01000000U)
7157 + {
7158 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7159 + regs->u_regs[UREG_G2] = addr + 4;
7160 + addr = (save & 0x003FFFFFU) << 10;
7161 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7162 +
7163 + if (test_thread_flag(TIF_32BIT))
7164 + addr &= 0xFFFFFFFFUL;
7165 +
7166 + regs->tpc = addr;
7167 + regs->tnpc = addr+4;
7168 + return 3;
7169 + }
7170 +
7171 + /* PaX: 64-bit PLT stub */
7172 + err = get_user(sethi1, (unsigned int *)addr);
7173 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7174 + err |= get_user(or1, (unsigned int *)(addr+8));
7175 + err |= get_user(or2, (unsigned int *)(addr+12));
7176 + err |= get_user(sllx, (unsigned int *)(addr+16));
7177 + err |= get_user(add, (unsigned int *)(addr+20));
7178 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7179 + err |= get_user(nop, (unsigned int *)(addr+28));
7180 + if (err)
7181 + break;
7182 +
7183 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7184 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7185 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7186 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7187 + sllx == 0x89293020U &&
7188 + add == 0x8A010005U &&
7189 + jmpl == 0x89C14000U &&
7190 + nop == 0x01000000U)
7191 + {
7192 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7193 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7194 + regs->u_regs[UREG_G4] <<= 32;
7195 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7196 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7197 + regs->u_regs[UREG_G4] = addr + 24;
7198 + addr = regs->u_regs[UREG_G5];
7199 + regs->tpc = addr;
7200 + regs->tnpc = addr+4;
7201 + return 3;
7202 + }
7203 + }
7204 + } while (0);
7205 +
7206 +#ifdef CONFIG_PAX_DLRESOLVE
7207 + do { /* PaX: unpatched PLT emulation step 2 */
7208 + unsigned int save, call, nop;
7209 +
7210 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7211 + err |= get_user(call, (unsigned int *)regs->tpc);
7212 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7213 + if (err)
7214 + break;
7215 +
7216 + if (save == 0x9DE3BFA8U &&
7217 + (call & 0xC0000000U) == 0x40000000U &&
7218 + nop == 0x01000000U)
7219 + {
7220 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7221 +
7222 + if (test_thread_flag(TIF_32BIT))
7223 + dl_resolve &= 0xFFFFFFFFUL;
7224 +
7225 + regs->u_regs[UREG_RETPC] = regs->tpc;
7226 + regs->tpc = dl_resolve;
7227 + regs->tnpc = dl_resolve+4;
7228 + return 3;
7229 + }
7230 + } while (0);
7231 +#endif
7232 +
7233 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7234 + unsigned int sethi, ba, nop;
7235 +
7236 + err = get_user(sethi, (unsigned int *)regs->tpc);
7237 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7238 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7239 +
7240 + if (err)
7241 + break;
7242 +
7243 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7244 + (ba & 0xFFF00000U) == 0x30600000U &&
7245 + nop == 0x01000000U)
7246 + {
7247 + unsigned long addr;
7248 +
7249 + addr = (sethi & 0x003FFFFFU) << 10;
7250 + regs->u_regs[UREG_G1] = addr;
7251 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7252 +
7253 + if (test_thread_flag(TIF_32BIT))
7254 + addr &= 0xFFFFFFFFUL;
7255 +
7256 + regs->tpc = addr;
7257 + regs->tnpc = addr+4;
7258 + return 2;
7259 + }
7260 + } while (0);
7261 +
7262 +#endif
7263 +
7264 + return 1;
7265 +}
7266 +
7267 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7268 +{
7269 + unsigned long i;
7270 +
7271 + printk(KERN_ERR "PAX: bytes at PC: ");
7272 + for (i = 0; i < 8; i++) {
7273 + unsigned int c;
7274 + if (get_user(c, (unsigned int *)pc+i))
7275 + printk(KERN_CONT "???????? ");
7276 + else
7277 + printk(KERN_CONT "%08x ", c);
7278 + }
7279 + printk("\n");
7280 +}
7281 +#endif
7282 +
7283 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7284 {
7285 struct mm_struct *mm = current->mm;
7286 @@ -343,6 +806,29 @@ retry:
7287 if (!vma)
7288 goto bad_area;
7289
7290 +#ifdef CONFIG_PAX_PAGEEXEC
7291 + /* PaX: detect ITLB misses on non-exec pages */
7292 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7293 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7294 + {
7295 + if (address != regs->tpc)
7296 + goto good_area;
7297 +
7298 + up_read(&mm->mmap_sem);
7299 + switch (pax_handle_fetch_fault(regs)) {
7300 +
7301 +#ifdef CONFIG_PAX_EMUPLT
7302 + case 2:
7303 + case 3:
7304 + return;
7305 +#endif
7306 +
7307 + }
7308 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7309 + do_group_exit(SIGKILL);
7310 + }
7311 +#endif
7312 +
7313 /* Pure DTLB misses do not tell us whether the fault causing
7314 * load/store/atomic was a write or not, it only says that there
7315 * was no match. So in such a case we (carefully) read the
7316 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7317 index 07e1453..0a7d9e9 100644
7318 --- a/arch/sparc/mm/hugetlbpage.c
7319 +++ b/arch/sparc/mm/hugetlbpage.c
7320 @@ -67,7 +67,7 @@ full_search:
7321 }
7322 return -ENOMEM;
7323 }
7324 - if (likely(!vma || addr + len <= vma->vm_start)) {
7325 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7326 /*
7327 * Remember the place where we stopped the search:
7328 */
7329 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7330 /* make sure it can fit in the remaining address space */
7331 if (likely(addr > len)) {
7332 vma = find_vma(mm, addr-len);
7333 - if (!vma || addr <= vma->vm_start) {
7334 + if (check_heap_stack_gap(vma, addr - len, len)) {
7335 /* remember the address as a hint for next time */
7336 return (mm->free_area_cache = addr-len);
7337 }
7338 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7339 if (unlikely(mm->mmap_base < len))
7340 goto bottomup;
7341
7342 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7343 + addr = mm->mmap_base - len;
7344
7345 do {
7346 + addr &= HPAGE_MASK;
7347 /*
7348 * Lookup failure means no vma is above this address,
7349 * else if new region fits below vma->vm_start,
7350 * return with success:
7351 */
7352 vma = find_vma(mm, addr);
7353 - if (likely(!vma || addr+len <= vma->vm_start)) {
7354 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7355 /* remember the address as a hint for next time */
7356 return (mm->free_area_cache = addr);
7357 }
7358 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7359 mm->cached_hole_size = vma->vm_start - addr;
7360
7361 /* try just below the current vma->vm_start */
7362 - addr = (vma->vm_start-len) & HPAGE_MASK;
7363 - } while (likely(len < vma->vm_start));
7364 + addr = skip_heap_stack_gap(vma, len);
7365 + } while (!IS_ERR_VALUE(addr));
7366
7367 bottomup:
7368 /*
7369 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7370 if (addr) {
7371 addr = ALIGN(addr, HPAGE_SIZE);
7372 vma = find_vma(mm, addr);
7373 - if (task_size - len >= addr &&
7374 - (!vma || addr + len <= vma->vm_start))
7375 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7376 return addr;
7377 }
7378 if (mm->get_unmapped_area == arch_get_unmapped_area)
7379 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7380 index f4500c6..889656c 100644
7381 --- a/arch/tile/include/asm/atomic_64.h
7382 +++ b/arch/tile/include/asm/atomic_64.h
7383 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7384
7385 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7386
7387 +#define atomic64_read_unchecked(v) atomic64_read(v)
7388 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7389 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7390 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7391 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7392 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7393 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7394 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7395 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7396 +
7397 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7398 #define smp_mb__before_atomic_dec() smp_mb()
7399 #define smp_mb__after_atomic_dec() smp_mb()
7400 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7401 index 392e533..536b092 100644
7402 --- a/arch/tile/include/asm/cache.h
7403 +++ b/arch/tile/include/asm/cache.h
7404 @@ -15,11 +15,12 @@
7405 #ifndef _ASM_TILE_CACHE_H
7406 #define _ASM_TILE_CACHE_H
7407
7408 +#include <linux/const.h>
7409 #include <arch/chip.h>
7410
7411 /* bytes per L1 data cache line */
7412 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7413 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7414 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7415
7416 /* bytes per L2 cache line */
7417 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7418 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7419 index 9ab078a..d6635c2 100644
7420 --- a/arch/tile/include/asm/uaccess.h
7421 +++ b/arch/tile/include/asm/uaccess.h
7422 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7423 const void __user *from,
7424 unsigned long n)
7425 {
7426 - int sz = __compiletime_object_size(to);
7427 + size_t sz = __compiletime_object_size(to);
7428
7429 - if (likely(sz == -1 || sz >= n))
7430 + if (likely(sz == (size_t)-1 || sz >= n))
7431 n = _copy_from_user(to, from, n);
7432 else
7433 copy_from_user_overflow();
7434 diff --git a/arch/um/Makefile b/arch/um/Makefile
7435 index 0970910..13adb57a 100644
7436 --- a/arch/um/Makefile
7437 +++ b/arch/um/Makefile
7438 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7439 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7440 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7441
7442 +ifdef CONSTIFY_PLUGIN
7443 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7444 +endif
7445 +
7446 #This will adjust *FLAGS accordingly to the platform.
7447 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7448
7449 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7450 index 19e1bdd..3665b77 100644
7451 --- a/arch/um/include/asm/cache.h
7452 +++ b/arch/um/include/asm/cache.h
7453 @@ -1,6 +1,7 @@
7454 #ifndef __UM_CACHE_H
7455 #define __UM_CACHE_H
7456
7457 +#include <linux/const.h>
7458
7459 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7460 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7461 @@ -12,6 +13,6 @@
7462 # define L1_CACHE_SHIFT 5
7463 #endif
7464
7465 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7466 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7467
7468 #endif
7469 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7470 index 6c03acd..a5e0215 100644
7471 --- a/arch/um/include/asm/kmap_types.h
7472 +++ b/arch/um/include/asm/kmap_types.h
7473 @@ -23,6 +23,7 @@ enum km_type {
7474 KM_IRQ1,
7475 KM_SOFTIRQ0,
7476 KM_SOFTIRQ1,
7477 + KM_CLEARPAGE,
7478 KM_TYPE_NR
7479 };
7480
7481 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7482 index 7cfc3ce..cbd1a58 100644
7483 --- a/arch/um/include/asm/page.h
7484 +++ b/arch/um/include/asm/page.h
7485 @@ -14,6 +14,9 @@
7486 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7487 #define PAGE_MASK (~(PAGE_SIZE-1))
7488
7489 +#define ktla_ktva(addr) (addr)
7490 +#define ktva_ktla(addr) (addr)
7491 +
7492 #ifndef __ASSEMBLY__
7493
7494 struct page;
7495 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7496 index 0032f92..cd151e0 100644
7497 --- a/arch/um/include/asm/pgtable-3level.h
7498 +++ b/arch/um/include/asm/pgtable-3level.h
7499 @@ -58,6 +58,7 @@
7500 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7501 #define pud_populate(mm, pud, pmd) \
7502 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7503 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7504
7505 #ifdef CONFIG_64BIT
7506 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7507 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7508 index ccb9a9d..cc425bb 100644
7509 --- a/arch/um/kernel/process.c
7510 +++ b/arch/um/kernel/process.c
7511 @@ -407,22 +407,6 @@ int singlestepping(void * t)
7512 return 2;
7513 }
7514
7515 -/*
7516 - * Only x86 and x86_64 have an arch_align_stack().
7517 - * All other arches have "#define arch_align_stack(x) (x)"
7518 - * in their asm/system.h
7519 - * As this is included in UML from asm-um/system-generic.h,
7520 - * we can use it to behave as the subarch does.
7521 - */
7522 -#ifndef arch_align_stack
7523 -unsigned long arch_align_stack(unsigned long sp)
7524 -{
7525 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7526 - sp -= get_random_int() % 8192;
7527 - return sp & ~0xf;
7528 -}
7529 -#endif
7530 -
7531 unsigned long get_wchan(struct task_struct *p)
7532 {
7533 unsigned long stack_page, sp, ip;
7534 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7535 index ad8f795..2c7eec6 100644
7536 --- a/arch/unicore32/include/asm/cache.h
7537 +++ b/arch/unicore32/include/asm/cache.h
7538 @@ -12,8 +12,10 @@
7539 #ifndef __UNICORE_CACHE_H__
7540 #define __UNICORE_CACHE_H__
7541
7542 -#define L1_CACHE_SHIFT (5)
7543 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7544 +#include <linux/const.h>
7545 +
7546 +#define L1_CACHE_SHIFT 5
7547 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7548
7549 /*
7550 * Memory returned by kmalloc() may be used for DMA, so we must make
7551 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7552 index c70684f..698fa4b 100644
7553 --- a/arch/x86/Kconfig
7554 +++ b/arch/x86/Kconfig
7555 @@ -218,7 +218,7 @@ config X86_HT
7556
7557 config X86_32_LAZY_GS
7558 def_bool y
7559 - depends on X86_32 && !CC_STACKPROTECTOR
7560 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7561
7562 config ARCH_HWEIGHT_CFLAGS
7563 string
7564 @@ -1047,7 +1047,7 @@ choice
7565
7566 config NOHIGHMEM
7567 bool "off"
7568 - depends on !X86_NUMAQ
7569 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7570 ---help---
7571 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7572 However, the address space of 32-bit x86 processors is only 4
7573 @@ -1084,7 +1084,7 @@ config NOHIGHMEM
7574
7575 config HIGHMEM4G
7576 bool "4GB"
7577 - depends on !X86_NUMAQ
7578 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7579 ---help---
7580 Select this if you have a 32-bit processor and between 1 and 4
7581 gigabytes of physical RAM.
7582 @@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7583 hex
7584 default 0xB0000000 if VMSPLIT_3G_OPT
7585 default 0x80000000 if VMSPLIT_2G
7586 - default 0x78000000 if VMSPLIT_2G_OPT
7587 + default 0x70000000 if VMSPLIT_2G_OPT
7588 default 0x40000000 if VMSPLIT_1G
7589 default 0xC0000000
7590 depends on X86_32
7591 @@ -1526,6 +1526,7 @@ config SECCOMP
7592
7593 config CC_STACKPROTECTOR
7594 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7595 + depends on X86_64 || !PAX_MEMORY_UDEREF
7596 ---help---
7597 This option turns on the -fstack-protector GCC feature. This
7598 feature puts, at the beginning of functions, a canary value on
7599 @@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7600 config PHYSICAL_START
7601 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7602 default "0x1000000"
7603 + range 0x400000 0x40000000
7604 ---help---
7605 This gives the physical address where the kernel is loaded.
7606
7607 @@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7608 config PHYSICAL_ALIGN
7609 hex "Alignment value to which kernel should be aligned" if X86_32
7610 default "0x1000000"
7611 + range 0x400000 0x1000000 if PAX_KERNEXEC
7612 range 0x2000 0x1000000
7613 ---help---
7614 This value puts the alignment restrictions on physical address
7615 @@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7616 Say N if you want to disable CPU hotplug.
7617
7618 config COMPAT_VDSO
7619 - def_bool y
7620 + def_bool n
7621 prompt "Compat VDSO support"
7622 depends on X86_32 || IA32_EMULATION
7623 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7624 ---help---
7625 Map the 32-bit VDSO to the predictable old-style address too.
7626
7627 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7628 index 706e12e..62e4feb 100644
7629 --- a/arch/x86/Kconfig.cpu
7630 +++ b/arch/x86/Kconfig.cpu
7631 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7632
7633 config X86_F00F_BUG
7634 def_bool y
7635 - depends on M586MMX || M586TSC || M586 || M486 || M386
7636 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7637
7638 config X86_INVD_BUG
7639 def_bool y
7640 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7641
7642 config X86_ALIGNMENT_16
7643 def_bool y
7644 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7645 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7646
7647 config X86_INTEL_USERCOPY
7648 def_bool y
7649 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7650 # generates cmov.
7651 config X86_CMOV
7652 def_bool y
7653 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7654 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7655
7656 config X86_MINIMUM_CPU_FAMILY
7657 int
7658 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7659 index e46c214..ab62fd1 100644
7660 --- a/arch/x86/Kconfig.debug
7661 +++ b/arch/x86/Kconfig.debug
7662 @@ -84,7 +84,7 @@ config X86_PTDUMP
7663 config DEBUG_RODATA
7664 bool "Write protect kernel read-only data structures"
7665 default y
7666 - depends on DEBUG_KERNEL
7667 + depends on DEBUG_KERNEL && BROKEN
7668 ---help---
7669 Mark the kernel read-only data as write-protected in the pagetables,
7670 in order to catch accidental (and incorrect) writes to such const
7671 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7672
7673 config DEBUG_SET_MODULE_RONX
7674 bool "Set loadable kernel module data as NX and text as RO"
7675 - depends on MODULES
7676 + depends on MODULES && BROKEN
7677 ---help---
7678 This option helps catch unintended modifications to loadable
7679 kernel module's text and read-only data. It also prevents execution
7680 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7681
7682 config DEBUG_STRICT_USER_COPY_CHECKS
7683 bool "Strict copy size checks"
7684 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7685 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7686 ---help---
7687 Enabling this option turns a certain set of sanity checks for user
7688 copy operations into compile time failures.
7689 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7690 index 1f25214..39422b3 100644
7691 --- a/arch/x86/Makefile
7692 +++ b/arch/x86/Makefile
7693 @@ -46,6 +46,7 @@ else
7694 UTS_MACHINE := x86_64
7695 CHECKFLAGS += -D__x86_64__ -m64
7696
7697 + biarch := $(call cc-option,-m64)
7698 KBUILD_AFLAGS += -m64
7699 KBUILD_CFLAGS += -m64
7700
7701 @@ -222,3 +223,12 @@ define archhelp
7702 echo ' FDARGS="..." arguments for the booted kernel'
7703 echo ' FDINITRD=file initrd for the booted kernel'
7704 endef
7705 +
7706 +define OLD_LD
7707 +
7708 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7709 +*** Please upgrade your binutils to 2.18 or newer
7710 +endef
7711 +
7712 +archprepare:
7713 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7714 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7715 index 5a747dd..ff7b12c 100644
7716 --- a/arch/x86/boot/Makefile
7717 +++ b/arch/x86/boot/Makefile
7718 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7719 $(call cc-option, -fno-stack-protector) \
7720 $(call cc-option, -mpreferred-stack-boundary=2)
7721 KBUILD_CFLAGS += $(call cc-option, -m32)
7722 +ifdef CONSTIFY_PLUGIN
7723 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7724 +endif
7725 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7726 GCOV_PROFILE := n
7727
7728 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7729 index 878e4b9..20537ab 100644
7730 --- a/arch/x86/boot/bitops.h
7731 +++ b/arch/x86/boot/bitops.h
7732 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7733 u8 v;
7734 const u32 *p = (const u32 *)addr;
7735
7736 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7737 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7738 return v;
7739 }
7740
7741 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7742
7743 static inline void set_bit(int nr, void *addr)
7744 {
7745 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7746 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7747 }
7748
7749 #endif /* BOOT_BITOPS_H */
7750 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7751 index 18997e5..83d9c67 100644
7752 --- a/arch/x86/boot/boot.h
7753 +++ b/arch/x86/boot/boot.h
7754 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7755 static inline u16 ds(void)
7756 {
7757 u16 seg;
7758 - asm("movw %%ds,%0" : "=rm" (seg));
7759 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7760 return seg;
7761 }
7762
7763 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7764 static inline int memcmp(const void *s1, const void *s2, size_t len)
7765 {
7766 u8 diff;
7767 - asm("repe; cmpsb; setnz %0"
7768 + asm volatile("repe; cmpsb; setnz %0"
7769 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7770 return diff;
7771 }
7772 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7773 index e398bb5..3a382ca 100644
7774 --- a/arch/x86/boot/compressed/Makefile
7775 +++ b/arch/x86/boot/compressed/Makefile
7776 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7777 KBUILD_CFLAGS += $(cflags-y)
7778 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7779 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7780 +ifdef CONSTIFY_PLUGIN
7781 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7782 +endif
7783
7784 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7785 GCOV_PROFILE := n
7786 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7787 index 4e85f5f..39fa641 100644
7788 --- a/arch/x86/boot/compressed/eboot.c
7789 +++ b/arch/x86/boot/compressed/eboot.c
7790 @@ -142,7 +142,6 @@ again:
7791 *addr = max_addr;
7792 }
7793
7794 -free_pool:
7795 efi_call_phys1(sys_table->boottime->free_pool, map);
7796
7797 fail:
7798 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7799 if (i == map_size / desc_size)
7800 status = EFI_NOT_FOUND;
7801
7802 -free_pool:
7803 efi_call_phys1(sys_table->boottime->free_pool, map);
7804 fail:
7805 return status;
7806 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7807 index c85e3ac..6f5aa80 100644
7808 --- a/arch/x86/boot/compressed/head_32.S
7809 +++ b/arch/x86/boot/compressed/head_32.S
7810 @@ -106,7 +106,7 @@ preferred_addr:
7811 notl %eax
7812 andl %eax, %ebx
7813 #else
7814 - movl $LOAD_PHYSICAL_ADDR, %ebx
7815 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7816 #endif
7817
7818 /* Target address to relocate to for decompression */
7819 @@ -192,7 +192,7 @@ relocated:
7820 * and where it was actually loaded.
7821 */
7822 movl %ebp, %ebx
7823 - subl $LOAD_PHYSICAL_ADDR, %ebx
7824 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7825 jz 2f /* Nothing to be done if loaded at compiled addr. */
7826 /*
7827 * Process relocations.
7828 @@ -200,8 +200,7 @@ relocated:
7829
7830 1: subl $4, %edi
7831 movl (%edi), %ecx
7832 - testl %ecx, %ecx
7833 - jz 2f
7834 + jecxz 2f
7835 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7836 jmp 1b
7837 2:
7838 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7839 index 87e03a1..0d94c76 100644
7840 --- a/arch/x86/boot/compressed/head_64.S
7841 +++ b/arch/x86/boot/compressed/head_64.S
7842 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7843 notl %eax
7844 andl %eax, %ebx
7845 #else
7846 - movl $LOAD_PHYSICAL_ADDR, %ebx
7847 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7848 #endif
7849
7850 /* Target address to relocate to for decompression */
7851 @@ -263,7 +263,7 @@ preferred_addr:
7852 notq %rax
7853 andq %rax, %rbp
7854 #else
7855 - movq $LOAD_PHYSICAL_ADDR, %rbp
7856 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7857 #endif
7858
7859 /* Target address to relocate to for decompression */
7860 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7861 index 7116dcb..d9ae1d7 100644
7862 --- a/arch/x86/boot/compressed/misc.c
7863 +++ b/arch/x86/boot/compressed/misc.c
7864 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7865 case PT_LOAD:
7866 #ifdef CONFIG_RELOCATABLE
7867 dest = output;
7868 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7869 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7870 #else
7871 dest = (void *)(phdr->p_paddr);
7872 #endif
7873 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7874 error("Destination address too large");
7875 #endif
7876 #ifndef CONFIG_RELOCATABLE
7877 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7878 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7879 error("Wrong destination address");
7880 #endif
7881
7882 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7883 index 4d3ff03..e4972ff 100644
7884 --- a/arch/x86/boot/cpucheck.c
7885 +++ b/arch/x86/boot/cpucheck.c
7886 @@ -74,7 +74,7 @@ static int has_fpu(void)
7887 u16 fcw = -1, fsw = -1;
7888 u32 cr0;
7889
7890 - asm("movl %%cr0,%0" : "=r" (cr0));
7891 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7892 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7893 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7894 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7895 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7896 {
7897 u32 f0, f1;
7898
7899 - asm("pushfl ; "
7900 + asm volatile("pushfl ; "
7901 "pushfl ; "
7902 "popl %0 ; "
7903 "movl %0,%1 ; "
7904 @@ -115,7 +115,7 @@ static void get_flags(void)
7905 set_bit(X86_FEATURE_FPU, cpu.flags);
7906
7907 if (has_eflag(X86_EFLAGS_ID)) {
7908 - asm("cpuid"
7909 + asm volatile("cpuid"
7910 : "=a" (max_intel_level),
7911 "=b" (cpu_vendor[0]),
7912 "=d" (cpu_vendor[1]),
7913 @@ -124,7 +124,7 @@ static void get_flags(void)
7914
7915 if (max_intel_level >= 0x00000001 &&
7916 max_intel_level <= 0x0000ffff) {
7917 - asm("cpuid"
7918 + asm volatile("cpuid"
7919 : "=a" (tfms),
7920 "=c" (cpu.flags[4]),
7921 "=d" (cpu.flags[0])
7922 @@ -136,7 +136,7 @@ static void get_flags(void)
7923 cpu.model += ((tfms >> 16) & 0xf) << 4;
7924 }
7925
7926 - asm("cpuid"
7927 + asm volatile("cpuid"
7928 : "=a" (max_amd_level)
7929 : "a" (0x80000000)
7930 : "ebx", "ecx", "edx");
7931 @@ -144,7 +144,7 @@ static void get_flags(void)
7932 if (max_amd_level >= 0x80000001 &&
7933 max_amd_level <= 0x8000ffff) {
7934 u32 eax = 0x80000001;
7935 - asm("cpuid"
7936 + asm volatile("cpuid"
7937 : "+a" (eax),
7938 "=c" (cpu.flags[6]),
7939 "=d" (cpu.flags[1])
7940 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7941 u32 ecx = MSR_K7_HWCR;
7942 u32 eax, edx;
7943
7944 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7945 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7946 eax &= ~(1 << 15);
7947 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7948 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7949
7950 get_flags(); /* Make sure it really did something */
7951 err = check_flags();
7952 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7953 u32 ecx = MSR_VIA_FCR;
7954 u32 eax, edx;
7955
7956 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7957 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7958 eax |= (1<<1)|(1<<7);
7959 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7960 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7961
7962 set_bit(X86_FEATURE_CX8, cpu.flags);
7963 err = check_flags();
7964 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7965 u32 eax, edx;
7966 u32 level = 1;
7967
7968 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7969 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7970 - asm("cpuid"
7971 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7972 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7973 + asm volatile("cpuid"
7974 : "+a" (level), "=d" (cpu.flags[0])
7975 : : "ecx", "ebx");
7976 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7977 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7978
7979 err = check_flags();
7980 }
7981 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7982 index efe5acf..22a3784 100644
7983 --- a/arch/x86/boot/header.S
7984 +++ b/arch/x86/boot/header.S
7985 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7986 # single linked list of
7987 # struct setup_data
7988
7989 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7990 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7991
7992 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7993 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7994 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7995 +#else
7996 #define VO_INIT_SIZE (VO__end - VO__text)
7997 +#endif
7998 #if ZO_INIT_SIZE > VO_INIT_SIZE
7999 #define INIT_SIZE ZO_INIT_SIZE
8000 #else
8001 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8002 index db75d07..8e6d0af 100644
8003 --- a/arch/x86/boot/memory.c
8004 +++ b/arch/x86/boot/memory.c
8005 @@ -19,7 +19,7 @@
8006
8007 static int detect_memory_e820(void)
8008 {
8009 - int count = 0;
8010 + unsigned int count = 0;
8011 struct biosregs ireg, oreg;
8012 struct e820entry *desc = boot_params.e820_map;
8013 static struct e820entry buf; /* static so it is zeroed */
8014 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8015 index 11e8c6e..fdbb1ed 100644
8016 --- a/arch/x86/boot/video-vesa.c
8017 +++ b/arch/x86/boot/video-vesa.c
8018 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8019
8020 boot_params.screen_info.vesapm_seg = oreg.es;
8021 boot_params.screen_info.vesapm_off = oreg.di;
8022 + boot_params.screen_info.vesapm_size = oreg.cx;
8023 }
8024
8025 /*
8026 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8027 index 43eda28..5ab5fdb 100644
8028 --- a/arch/x86/boot/video.c
8029 +++ b/arch/x86/boot/video.c
8030 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8031 static unsigned int get_entry(void)
8032 {
8033 char entry_buf[4];
8034 - int i, len = 0;
8035 + unsigned int i, len = 0;
8036 int key;
8037 unsigned int v;
8038
8039 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8040 index 5b577d5..3c1fed4 100644
8041 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8042 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8043 @@ -8,6 +8,8 @@
8044 * including this sentence is retained in full.
8045 */
8046
8047 +#include <asm/alternative-asm.h>
8048 +
8049 .extern crypto_ft_tab
8050 .extern crypto_it_tab
8051 .extern crypto_fl_tab
8052 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8053 je B192; \
8054 leaq 32(r9),r9;
8055
8056 +#define ret pax_force_retaddr 0, 1; ret
8057 +
8058 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8059 movq r1,r2; \
8060 movq r3,r4; \
8061 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8062 index 3470624..201259d 100644
8063 --- a/arch/x86/crypto/aesni-intel_asm.S
8064 +++ b/arch/x86/crypto/aesni-intel_asm.S
8065 @@ -31,6 +31,7 @@
8066
8067 #include <linux/linkage.h>
8068 #include <asm/inst.h>
8069 +#include <asm/alternative-asm.h>
8070
8071 #ifdef __x86_64__
8072 .data
8073 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8074 pop %r14
8075 pop %r13
8076 pop %r12
8077 + pax_force_retaddr 0, 1
8078 ret
8079 +ENDPROC(aesni_gcm_dec)
8080
8081
8082 /*****************************************************************************
8083 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8084 pop %r14
8085 pop %r13
8086 pop %r12
8087 + pax_force_retaddr 0, 1
8088 ret
8089 +ENDPROC(aesni_gcm_enc)
8090
8091 #endif
8092
8093 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8094 pxor %xmm1, %xmm0
8095 movaps %xmm0, (TKEYP)
8096 add $0x10, TKEYP
8097 + pax_force_retaddr_bts
8098 ret
8099
8100 .align 4
8101 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8102 shufps $0b01001110, %xmm2, %xmm1
8103 movaps %xmm1, 0x10(TKEYP)
8104 add $0x20, TKEYP
8105 + pax_force_retaddr_bts
8106 ret
8107
8108 .align 4
8109 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8110
8111 movaps %xmm0, (TKEYP)
8112 add $0x10, TKEYP
8113 + pax_force_retaddr_bts
8114 ret
8115
8116 .align 4
8117 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8118 pxor %xmm1, %xmm2
8119 movaps %xmm2, (TKEYP)
8120 add $0x10, TKEYP
8121 + pax_force_retaddr_bts
8122 ret
8123
8124 /*
8125 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8126 #ifndef __x86_64__
8127 popl KEYP
8128 #endif
8129 + pax_force_retaddr 0, 1
8130 ret
8131 +ENDPROC(aesni_set_key)
8132
8133 /*
8134 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8135 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8136 popl KLEN
8137 popl KEYP
8138 #endif
8139 + pax_force_retaddr 0, 1
8140 ret
8141 +ENDPROC(aesni_enc)
8142
8143 /*
8144 * _aesni_enc1: internal ABI
8145 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8146 AESENC KEY STATE
8147 movaps 0x70(TKEYP), KEY
8148 AESENCLAST KEY STATE
8149 + pax_force_retaddr_bts
8150 ret
8151
8152 /*
8153 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8154 AESENCLAST KEY STATE2
8155 AESENCLAST KEY STATE3
8156 AESENCLAST KEY STATE4
8157 + pax_force_retaddr_bts
8158 ret
8159
8160 /*
8161 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8162 popl KLEN
8163 popl KEYP
8164 #endif
8165 + pax_force_retaddr 0, 1
8166 ret
8167 +ENDPROC(aesni_dec)
8168
8169 /*
8170 * _aesni_dec1: internal ABI
8171 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8172 AESDEC KEY STATE
8173 movaps 0x70(TKEYP), KEY
8174 AESDECLAST KEY STATE
8175 + pax_force_retaddr_bts
8176 ret
8177
8178 /*
8179 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8180 AESDECLAST KEY STATE2
8181 AESDECLAST KEY STATE3
8182 AESDECLAST KEY STATE4
8183 + pax_force_retaddr_bts
8184 ret
8185
8186 /*
8187 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8188 popl KEYP
8189 popl LEN
8190 #endif
8191 + pax_force_retaddr 0, 1
8192 ret
8193 +ENDPROC(aesni_ecb_enc)
8194
8195 /*
8196 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8197 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8198 popl KEYP
8199 popl LEN
8200 #endif
8201 + pax_force_retaddr 0, 1
8202 ret
8203 +ENDPROC(aesni_ecb_dec)
8204
8205 /*
8206 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8207 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8208 popl LEN
8209 popl IVP
8210 #endif
8211 + pax_force_retaddr 0, 1
8212 ret
8213 +ENDPROC(aesni_cbc_enc)
8214
8215 /*
8216 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8217 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8218 popl LEN
8219 popl IVP
8220 #endif
8221 + pax_force_retaddr 0, 1
8222 ret
8223 +ENDPROC(aesni_cbc_dec)
8224
8225 #ifdef __x86_64__
8226 .align 16
8227 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8228 mov $1, TCTR_LOW
8229 MOVQ_R64_XMM TCTR_LOW INC
8230 MOVQ_R64_XMM CTR TCTR_LOW
8231 + pax_force_retaddr_bts
8232 ret
8233
8234 /*
8235 @@ -2554,6 +2582,7 @@ _aesni_inc:
8236 .Linc_low:
8237 movaps CTR, IV
8238 PSHUFB_XMM BSWAP_MASK IV
8239 + pax_force_retaddr_bts
8240 ret
8241
8242 /*
8243 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8244 .Lctr_enc_ret:
8245 movups IV, (IVP)
8246 .Lctr_enc_just_ret:
8247 + pax_force_retaddr 0, 1
8248 ret
8249 +ENDPROC(aesni_ctr_enc)
8250 #endif
8251 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8252 index 391d245..67f35c2 100644
8253 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8254 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8255 @@ -20,6 +20,8 @@
8256 *
8257 */
8258
8259 +#include <asm/alternative-asm.h>
8260 +
8261 .file "blowfish-x86_64-asm.S"
8262 .text
8263
8264 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8265 jnz __enc_xor;
8266
8267 write_block();
8268 + pax_force_retaddr 0, 1
8269 ret;
8270 __enc_xor:
8271 xor_block();
8272 + pax_force_retaddr 0, 1
8273 ret;
8274
8275 .align 8
8276 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8277
8278 movq %r11, %rbp;
8279
8280 + pax_force_retaddr 0, 1
8281 ret;
8282
8283 /**********************************************************************
8284 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8285
8286 popq %rbx;
8287 popq %rbp;
8288 + pax_force_retaddr 0, 1
8289 ret;
8290
8291 __enc_xor4:
8292 @@ -349,6 +355,7 @@ __enc_xor4:
8293
8294 popq %rbx;
8295 popq %rbp;
8296 + pax_force_retaddr 0, 1
8297 ret;
8298
8299 .align 8
8300 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8301 popq %rbx;
8302 popq %rbp;
8303
8304 + pax_force_retaddr 0, 1
8305 ret;
8306
8307 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8308 index 0b33743..7a56206 100644
8309 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8310 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8311 @@ -20,6 +20,8 @@
8312 *
8313 */
8314
8315 +#include <asm/alternative-asm.h>
8316 +
8317 .file "camellia-x86_64-asm_64.S"
8318 .text
8319
8320 @@ -229,12 +231,14 @@ __enc_done:
8321 enc_outunpack(mov, RT1);
8322
8323 movq RRBP, %rbp;
8324 + pax_force_retaddr 0, 1
8325 ret;
8326
8327 __enc_xor:
8328 enc_outunpack(xor, RT1);
8329
8330 movq RRBP, %rbp;
8331 + pax_force_retaddr 0, 1
8332 ret;
8333
8334 .global camellia_dec_blk;
8335 @@ -275,6 +279,7 @@ __dec_rounds16:
8336 dec_outunpack();
8337
8338 movq RRBP, %rbp;
8339 + pax_force_retaddr 0, 1
8340 ret;
8341
8342 /**********************************************************************
8343 @@ -468,6 +473,7 @@ __enc2_done:
8344
8345 movq RRBP, %rbp;
8346 popq %rbx;
8347 + pax_force_retaddr 0, 1
8348 ret;
8349
8350 __enc2_xor:
8351 @@ -475,6 +481,7 @@ __enc2_xor:
8352
8353 movq RRBP, %rbp;
8354 popq %rbx;
8355 + pax_force_retaddr 0, 1
8356 ret;
8357
8358 .global camellia_dec_blk_2way;
8359 @@ -517,4 +524,5 @@ __dec2_rounds16:
8360
8361 movq RRBP, %rbp;
8362 movq RXOR, %rbx;
8363 + pax_force_retaddr 0, 1
8364 ret;
8365 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8366 index 6214a9b..1f4fc9a 100644
8367 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8368 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8369 @@ -1,3 +1,5 @@
8370 +#include <asm/alternative-asm.h>
8371 +
8372 # enter ECRYPT_encrypt_bytes
8373 .text
8374 .p2align 5
8375 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8376 add %r11,%rsp
8377 mov %rdi,%rax
8378 mov %rsi,%rdx
8379 + pax_force_retaddr 0, 1
8380 ret
8381 # bytesatleast65:
8382 ._bytesatleast65:
8383 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8384 add %r11,%rsp
8385 mov %rdi,%rax
8386 mov %rsi,%rdx
8387 + pax_force_retaddr
8388 ret
8389 # enter ECRYPT_ivsetup
8390 .text
8391 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8392 add %r11,%rsp
8393 mov %rdi,%rax
8394 mov %rsi,%rdx
8395 + pax_force_retaddr
8396 ret
8397 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8398 index 3ee1ff0..cbc568b 100644
8399 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8400 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8401 @@ -24,6 +24,8 @@
8402 *
8403 */
8404
8405 +#include <asm/alternative-asm.h>
8406 +
8407 .file "serpent-sse2-x86_64-asm_64.S"
8408 .text
8409
8410 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8411 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8412 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8413
8414 + pax_force_retaddr
8415 ret;
8416
8417 __enc_xor8:
8418 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8419 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8420
8421 + pax_force_retaddr
8422 ret;
8423
8424 .align 8
8425 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8426 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8427 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8428
8429 + pax_force_retaddr
8430 ret;
8431 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8432 index b2c2f57..8470cab 100644
8433 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8434 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8435 @@ -28,6 +28,8 @@
8436 * (at your option) any later version.
8437 */
8438
8439 +#include <asm/alternative-asm.h>
8440 +
8441 #define CTX %rdi // arg1
8442 #define BUF %rsi // arg2
8443 #define CNT %rdx // arg3
8444 @@ -104,6 +106,7 @@
8445 pop %r12
8446 pop %rbp
8447 pop %rbx
8448 + pax_force_retaddr 0, 1
8449 ret
8450
8451 .size \name, .-\name
8452 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8453 index 5b012a2..36d5364 100644
8454 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8455 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8456 @@ -20,6 +20,8 @@
8457 *
8458 */
8459
8460 +#include <asm/alternative-asm.h>
8461 +
8462 .file "twofish-x86_64-asm-3way.S"
8463 .text
8464
8465 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8466 popq %r13;
8467 popq %r14;
8468 popq %r15;
8469 + pax_force_retaddr 0, 1
8470 ret;
8471
8472 __enc_xor3:
8473 @@ -271,6 +274,7 @@ __enc_xor3:
8474 popq %r13;
8475 popq %r14;
8476 popq %r15;
8477 + pax_force_retaddr 0, 1
8478 ret;
8479
8480 .global twofish_dec_blk_3way
8481 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8482 popq %r13;
8483 popq %r14;
8484 popq %r15;
8485 + pax_force_retaddr 0, 1
8486 ret;
8487
8488 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8489 index 7bcf3fc..f53832f 100644
8490 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8491 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8492 @@ -21,6 +21,7 @@
8493 .text
8494
8495 #include <asm/asm-offsets.h>
8496 +#include <asm/alternative-asm.h>
8497
8498 #define a_offset 0
8499 #define b_offset 4
8500 @@ -268,6 +269,7 @@ twofish_enc_blk:
8501
8502 popq R1
8503 movq $1,%rax
8504 + pax_force_retaddr 0, 1
8505 ret
8506
8507 twofish_dec_blk:
8508 @@ -319,4 +321,5 @@ twofish_dec_blk:
8509
8510 popq R1
8511 movq $1,%rax
8512 + pax_force_retaddr 0, 1
8513 ret
8514 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8515 index 07b3a68..bd2a388 100644
8516 --- a/arch/x86/ia32/ia32_aout.c
8517 +++ b/arch/x86/ia32/ia32_aout.c
8518 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8519 unsigned long dump_start, dump_size;
8520 struct user32 dump;
8521
8522 + memset(&dump, 0, sizeof(dump));
8523 +
8524 fs = get_fs();
8525 set_fs(KERNEL_DS);
8526 has_dumped = 1;
8527 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8528 index 673ac9b..7a8c5df 100644
8529 --- a/arch/x86/ia32/ia32_signal.c
8530 +++ b/arch/x86/ia32/ia32_signal.c
8531 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8532 }
8533 seg = get_fs();
8534 set_fs(KERNEL_DS);
8535 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8536 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8537 set_fs(seg);
8538 if (ret >= 0 && uoss_ptr) {
8539 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8540 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8541 */
8542 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8543 size_t frame_size,
8544 - void **fpstate)
8545 + void __user **fpstate)
8546 {
8547 unsigned long sp;
8548
8549 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8550
8551 if (used_math()) {
8552 sp = sp - sig_xstate_ia32_size;
8553 - *fpstate = (struct _fpstate_ia32 *) sp;
8554 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8555 if (save_i387_xstate_ia32(*fpstate) < 0)
8556 return (void __user *) -1L;
8557 }
8558 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8559 sp -= frame_size;
8560 /* Align the stack pointer according to the i386 ABI,
8561 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8562 - sp = ((sp + 4) & -16ul) - 4;
8563 + sp = ((sp - 12) & -16ul) - 4;
8564 return (void __user *) sp;
8565 }
8566
8567 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8568 * These are actually not used anymore, but left because some
8569 * gdb versions depend on them as a marker.
8570 */
8571 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8572 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8573 } put_user_catch(err);
8574
8575 if (err)
8576 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8577 0xb8,
8578 __NR_ia32_rt_sigreturn,
8579 0x80cd,
8580 - 0,
8581 + 0
8582 };
8583
8584 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8585 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8586
8587 if (ka->sa.sa_flags & SA_RESTORER)
8588 restorer = ka->sa.sa_restorer;
8589 + else if (current->mm->context.vdso)
8590 + /* Return stub is in 32bit vsyscall page */
8591 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8592 else
8593 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8594 - rt_sigreturn);
8595 + restorer = &frame->retcode;
8596 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8597
8598 /*
8599 * Not actually used anymore, but left because some gdb
8600 * versions need it.
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 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8608 index 20e5f7b..eab8751 100644
8609 --- a/arch/x86/ia32/ia32entry.S
8610 +++ b/arch/x86/ia32/ia32entry.S
8611 @@ -14,8 +14,10 @@
8612 #include <asm/segment.h>
8613 #include <asm/irqflags.h>
8614 #include <asm/asm.h>
8615 +#include <asm/pgtable.h>
8616 #include <linux/linkage.h>
8617 #include <linux/err.h>
8618 +#include <asm/alternative-asm.h>
8619
8620 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8621 #include <linux/elf-em.h>
8622 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8623 ENDPROC(native_irq_enable_sysexit)
8624 #endif
8625
8626 + .macro pax_enter_kernel_user
8627 + pax_set_fptr_mask
8628 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8629 + call pax_enter_kernel_user
8630 +#endif
8631 + .endm
8632 +
8633 + .macro pax_exit_kernel_user
8634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8635 + call pax_exit_kernel_user
8636 +#endif
8637 +#ifdef CONFIG_PAX_RANDKSTACK
8638 + pushq %rax
8639 + pushq %r11
8640 + call pax_randomize_kstack
8641 + popq %r11
8642 + popq %rax
8643 +#endif
8644 + .endm
8645 +
8646 +.macro pax_erase_kstack
8647 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8648 + call pax_erase_kstack
8649 +#endif
8650 +.endm
8651 +
8652 /*
8653 * 32bit SYSENTER instruction entry.
8654 *
8655 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8656 CFI_REGISTER rsp,rbp
8657 SWAPGS_UNSAFE_STACK
8658 movq PER_CPU_VAR(kernel_stack), %rsp
8659 - addq $(KERNEL_STACK_OFFSET),%rsp
8660 - /*
8661 - * No need to follow this irqs on/off section: the syscall
8662 - * disabled irqs, here we enable it straight after entry:
8663 - */
8664 - ENABLE_INTERRUPTS(CLBR_NONE)
8665 movl %ebp,%ebp /* zero extension */
8666 pushq_cfi $__USER32_DS
8667 /*CFI_REL_OFFSET ss,0*/
8668 @@ -134,22 +156,37 @@ ENTRY(ia32_sysenter_target)
8669 CFI_REL_OFFSET rsp,0
8670 pushfq_cfi
8671 /*CFI_REL_OFFSET rflags,0*/
8672 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8673 - CFI_REGISTER rip,r10
8674 + orl $X86_EFLAGS_IF,(%rsp)
8675 + GET_THREAD_INFO(%r11)
8676 + movl TI_sysenter_return(%r11), %r11d
8677 + CFI_REGISTER rip,r11
8678 pushq_cfi $__USER32_CS
8679 /*CFI_REL_OFFSET cs,0*/
8680 movl %eax, %eax
8681 - pushq_cfi %r10
8682 + pushq_cfi %r11
8683 CFI_REL_OFFSET rip,0
8684 pushq_cfi %rax
8685 cld
8686 SAVE_ARGS 0,1,0
8687 + pax_enter_kernel_user
8688 + /*
8689 + * No need to follow this irqs on/off section: the syscall
8690 + * disabled irqs, here we enable it straight after entry:
8691 + */
8692 + ENABLE_INTERRUPTS(CLBR_NONE)
8693 /* no need to do an access_ok check here because rbp has been
8694 32bit zero extended */
8695 +
8696 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8697 + mov $PAX_USER_SHADOW_BASE,%r11
8698 + add %r11,%rbp
8699 +#endif
8700 +
8701 1: movl (%rbp),%ebp
8702 _ASM_EXTABLE(1b,ia32_badarg)
8703 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8704 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8705 + GET_THREAD_INFO(%r11)
8706 + orl $TS_COMPAT,TI_status(%r11)
8707 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8708 CFI_REMEMBER_STATE
8709 jnz sysenter_tracesys
8710 cmpq $(IA32_NR_syscalls-1),%rax
8711 @@ -159,12 +196,15 @@ sysenter_do_call:
8712 sysenter_dispatch:
8713 call *ia32_sys_call_table(,%rax,8)
8714 movq %rax,RAX-ARGOFFSET(%rsp)
8715 + GET_THREAD_INFO(%r11)
8716 DISABLE_INTERRUPTS(CLBR_NONE)
8717 TRACE_IRQS_OFF
8718 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8719 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8720 jnz sysexit_audit
8721 sysexit_from_sys_call:
8722 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8723 + pax_exit_kernel_user
8724 + pax_erase_kstack
8725 + andl $~TS_COMPAT,TI_status(%r11)
8726 /* clear IF, that popfq doesn't enable interrupts early */
8727 andl $~0x200,EFLAGS-R11(%rsp)
8728 movl RIP-R11(%rsp),%edx /* User %eip */
8729 @@ -190,6 +230,9 @@ sysexit_from_sys_call:
8730 movl %eax,%esi /* 2nd arg: syscall number */
8731 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8732 call __audit_syscall_entry
8733 +
8734 + pax_erase_kstack
8735 +
8736 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8737 cmpq $(IA32_NR_syscalls-1),%rax
8738 ja ia32_badsys
8739 @@ -201,7 +244,7 @@ sysexit_from_sys_call:
8740 .endm
8741
8742 .macro auditsys_exit exit
8743 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8744 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8745 jnz ia32_ret_from_sys_call
8746 TRACE_IRQS_ON
8747 sti
8748 @@ -212,11 +255,12 @@ sysexit_from_sys_call:
8749 1: setbe %al /* 1 if error, 0 if not */
8750 movzbl %al,%edi /* zero-extend that into %edi */
8751 call __audit_syscall_exit
8752 + GET_THREAD_INFO(%r11)
8753 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8754 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8755 cli
8756 TRACE_IRQS_OFF
8757 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8758 + testl %edi,TI_flags(%r11)
8759 jz \exit
8760 CLEAR_RREGS -ARGOFFSET
8761 jmp int_with_check
8762 @@ -234,7 +278,7 @@ sysexit_audit:
8763
8764 sysenter_tracesys:
8765 #ifdef CONFIG_AUDITSYSCALL
8766 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8767 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8768 jz sysenter_auditsys
8769 #endif
8770 SAVE_REST
8771 @@ -242,6 +286,9 @@ sysenter_tracesys:
8772 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8773 movq %rsp,%rdi /* &pt_regs -> arg1 */
8774 call syscall_trace_enter
8775 +
8776 + pax_erase_kstack
8777 +
8778 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8779 RESTORE_REST
8780 cmpq $(IA32_NR_syscalls-1),%rax
8781 @@ -273,19 +320,20 @@ ENDPROC(ia32_sysenter_target)
8782 ENTRY(ia32_cstar_target)
8783 CFI_STARTPROC32 simple
8784 CFI_SIGNAL_FRAME
8785 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8786 + CFI_DEF_CFA rsp,0
8787 CFI_REGISTER rip,rcx
8788 /*CFI_REGISTER rflags,r11*/
8789 SWAPGS_UNSAFE_STACK
8790 movl %esp,%r8d
8791 CFI_REGISTER rsp,r8
8792 movq PER_CPU_VAR(kernel_stack),%rsp
8793 + SAVE_ARGS 8*6,0,0
8794 + pax_enter_kernel_user
8795 /*
8796 * No need to follow this irqs on/off section: the syscall
8797 * disabled irqs and here we enable it straight after entry:
8798 */
8799 ENABLE_INTERRUPTS(CLBR_NONE)
8800 - SAVE_ARGS 8,0,0
8801 movl %eax,%eax /* zero extension */
8802 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8803 movq %rcx,RIP-ARGOFFSET(%rsp)
8804 @@ -301,10 +349,17 @@ ENTRY(ia32_cstar_target)
8805 /* no need to do an access_ok check here because r8 has been
8806 32bit zero extended */
8807 /* hardware stack frame is complete now */
8808 +
8809 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8810 + mov $PAX_USER_SHADOW_BASE,%r11
8811 + add %r11,%r8
8812 +#endif
8813 +
8814 1: movl (%r8),%r9d
8815 _ASM_EXTABLE(1b,ia32_badarg)
8816 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8817 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8818 + GET_THREAD_INFO(%r11)
8819 + orl $TS_COMPAT,TI_status(%r11)
8820 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8821 CFI_REMEMBER_STATE
8822 jnz cstar_tracesys
8823 cmpq $IA32_NR_syscalls-1,%rax
8824 @@ -314,12 +369,15 @@ cstar_do_call:
8825 cstar_dispatch:
8826 call *ia32_sys_call_table(,%rax,8)
8827 movq %rax,RAX-ARGOFFSET(%rsp)
8828 + GET_THREAD_INFO(%r11)
8829 DISABLE_INTERRUPTS(CLBR_NONE)
8830 TRACE_IRQS_OFF
8831 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8832 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8833 jnz sysretl_audit
8834 sysretl_from_sys_call:
8835 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8836 + pax_exit_kernel_user
8837 + pax_erase_kstack
8838 + andl $~TS_COMPAT,TI_status(%r11)
8839 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8840 movl RIP-ARGOFFSET(%rsp),%ecx
8841 CFI_REGISTER rip,rcx
8842 @@ -347,7 +405,7 @@ sysretl_audit:
8843
8844 cstar_tracesys:
8845 #ifdef CONFIG_AUDITSYSCALL
8846 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8847 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8848 jz cstar_auditsys
8849 #endif
8850 xchgl %r9d,%ebp
8851 @@ -356,6 +414,9 @@ cstar_tracesys:
8852 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8853 movq %rsp,%rdi /* &pt_regs -> arg1 */
8854 call syscall_trace_enter
8855 +
8856 + pax_erase_kstack
8857 +
8858 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8859 RESTORE_REST
8860 xchgl %ebp,%r9d
8861 @@ -401,19 +462,21 @@ ENTRY(ia32_syscall)
8862 CFI_REL_OFFSET rip,RIP-RIP
8863 PARAVIRT_ADJUST_EXCEPTION_FRAME
8864 SWAPGS
8865 - /*
8866 - * No need to follow this irqs on/off section: the syscall
8867 - * disabled irqs and here we enable it straight after entry:
8868 - */
8869 - ENABLE_INTERRUPTS(CLBR_NONE)
8870 movl %eax,%eax
8871 pushq_cfi %rax
8872 cld
8873 /* note the registers are not zero extended to the sf.
8874 this could be a problem. */
8875 SAVE_ARGS 0,1,0
8876 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8877 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8878 + pax_enter_kernel_user
8879 + /*
8880 + * No need to follow this irqs on/off section: the syscall
8881 + * disabled irqs and here we enable it straight after entry:
8882 + */
8883 + ENABLE_INTERRUPTS(CLBR_NONE)
8884 + GET_THREAD_INFO(%r11)
8885 + orl $TS_COMPAT,TI_status(%r11)
8886 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8887 jnz ia32_tracesys
8888 cmpq $(IA32_NR_syscalls-1),%rax
8889 ja ia32_badsys
8890 @@ -432,6 +495,9 @@ ia32_tracesys:
8891 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8892 movq %rsp,%rdi /* &pt_regs -> arg1 */
8893 call syscall_trace_enter
8894 +
8895 + pax_erase_kstack
8896 +
8897 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8898 RESTORE_REST
8899 cmpq $(IA32_NR_syscalls-1),%rax
8900 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8901 index 4540bec..714d913 100644
8902 --- a/arch/x86/ia32/sys_ia32.c
8903 +++ b/arch/x86/ia32/sys_ia32.c
8904 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8905 */
8906 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8907 {
8908 - typeof(ubuf->st_uid) uid = 0;
8909 - typeof(ubuf->st_gid) gid = 0;
8910 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8911 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8912 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8913 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8914 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8915 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8916 return ret;
8917 }
8918
8919 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8920 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8921 int options)
8922 {
8923 return compat_sys_wait4(pid, stat_addr, options, NULL);
8924 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8925 mm_segment_t old_fs = get_fs();
8926
8927 set_fs(KERNEL_DS);
8928 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8929 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8930 set_fs(old_fs);
8931 if (put_compat_timespec(&t, interval))
8932 return -EFAULT;
8933 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8934 mm_segment_t old_fs = get_fs();
8935
8936 set_fs(KERNEL_DS);
8937 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8938 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8939 set_fs(old_fs);
8940 if (!ret) {
8941 switch (_NSIG_WORDS) {
8942 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8943 if (copy_siginfo_from_user32(&info, uinfo))
8944 return -EFAULT;
8945 set_fs(KERNEL_DS);
8946 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8947 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8948 set_fs(old_fs);
8949 return ret;
8950 }
8951 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8952 return -EFAULT;
8953
8954 set_fs(KERNEL_DS);
8955 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8956 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8957 count);
8958 set_fs(old_fs);
8959
8960 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8961 index 952bd01..7692c6f 100644
8962 --- a/arch/x86/include/asm/alternative-asm.h
8963 +++ b/arch/x86/include/asm/alternative-asm.h
8964 @@ -15,6 +15,45 @@
8965 .endm
8966 #endif
8967
8968 +#ifdef KERNEXEC_PLUGIN
8969 + .macro pax_force_retaddr_bts rip=0
8970 + btsq $63,\rip(%rsp)
8971 + .endm
8972 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8973 + .macro pax_force_retaddr rip=0, reload=0
8974 + btsq $63,\rip(%rsp)
8975 + .endm
8976 + .macro pax_force_fptr ptr
8977 + btsq $63,\ptr
8978 + .endm
8979 + .macro pax_set_fptr_mask
8980 + .endm
8981 +#endif
8982 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8983 + .macro pax_force_retaddr rip=0, reload=0
8984 + .if \reload
8985 + pax_set_fptr_mask
8986 + .endif
8987 + orq %r10,\rip(%rsp)
8988 + .endm
8989 + .macro pax_force_fptr ptr
8990 + orq %r10,\ptr
8991 + .endm
8992 + .macro pax_set_fptr_mask
8993 + movabs $0x8000000000000000,%r10
8994 + .endm
8995 +#endif
8996 +#else
8997 + .macro pax_force_retaddr rip=0, reload=0
8998 + .endm
8999 + .macro pax_force_fptr ptr
9000 + .endm
9001 + .macro pax_force_retaddr_bts rip=0
9002 + .endm
9003 + .macro pax_set_fptr_mask
9004 + .endm
9005 +#endif
9006 +
9007 .macro altinstruction_entry orig alt feature orig_len alt_len
9008 .long \orig - .
9009 .long \alt - .
9010 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9011 index 49331be..9706065 100644
9012 --- a/arch/x86/include/asm/alternative.h
9013 +++ b/arch/x86/include/asm/alternative.h
9014 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9015 ".section .discard,\"aw\",@progbits\n" \
9016 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9017 ".previous\n" \
9018 - ".section .altinstr_replacement, \"ax\"\n" \
9019 + ".section .altinstr_replacement, \"a\"\n" \
9020 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9021 ".previous"
9022
9023 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9024 index eaff479..3025a63 100644
9025 --- a/arch/x86/include/asm/apic.h
9026 +++ b/arch/x86/include/asm/apic.h
9027 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9028
9029 #ifdef CONFIG_X86_LOCAL_APIC
9030
9031 -extern unsigned int apic_verbosity;
9032 +extern int apic_verbosity;
9033 extern int local_apic_timer_c2_ok;
9034
9035 extern int disable_apic;
9036 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9037 index 20370c6..a2eb9b0 100644
9038 --- a/arch/x86/include/asm/apm.h
9039 +++ b/arch/x86/include/asm/apm.h
9040 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9041 __asm__ __volatile__(APM_DO_ZERO_SEGS
9042 "pushl %%edi\n\t"
9043 "pushl %%ebp\n\t"
9044 - "lcall *%%cs:apm_bios_entry\n\t"
9045 + "lcall *%%ss:apm_bios_entry\n\t"
9046 "setc %%al\n\t"
9047 "popl %%ebp\n\t"
9048 "popl %%edi\n\t"
9049 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9050 __asm__ __volatile__(APM_DO_ZERO_SEGS
9051 "pushl %%edi\n\t"
9052 "pushl %%ebp\n\t"
9053 - "lcall *%%cs:apm_bios_entry\n\t"
9054 + "lcall *%%ss:apm_bios_entry\n\t"
9055 "setc %%bl\n\t"
9056 "popl %%ebp\n\t"
9057 "popl %%edi\n\t"
9058 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9059 index 58cb6d4..a4b806c 100644
9060 --- a/arch/x86/include/asm/atomic.h
9061 +++ b/arch/x86/include/asm/atomic.h
9062 @@ -22,7 +22,18 @@
9063 */
9064 static inline int atomic_read(const atomic_t *v)
9065 {
9066 - return (*(volatile int *)&(v)->counter);
9067 + return (*(volatile const int *)&(v)->counter);
9068 +}
9069 +
9070 +/**
9071 + * atomic_read_unchecked - read atomic variable
9072 + * @v: pointer of type atomic_unchecked_t
9073 + *
9074 + * Atomically reads the value of @v.
9075 + */
9076 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9077 +{
9078 + return (*(volatile const int *)&(v)->counter);
9079 }
9080
9081 /**
9082 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9083 }
9084
9085 /**
9086 + * atomic_set_unchecked - set atomic variable
9087 + * @v: pointer of type atomic_unchecked_t
9088 + * @i: required value
9089 + *
9090 + * Atomically sets the value of @v to @i.
9091 + */
9092 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9093 +{
9094 + v->counter = i;
9095 +}
9096 +
9097 +/**
9098 * atomic_add - add integer to atomic variable
9099 * @i: integer value to add
9100 * @v: pointer of type atomic_t
9101 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9102 */
9103 static inline void atomic_add(int i, atomic_t *v)
9104 {
9105 - asm volatile(LOCK_PREFIX "addl %1,%0"
9106 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9107 +
9108 +#ifdef CONFIG_PAX_REFCOUNT
9109 + "jno 0f\n"
9110 + LOCK_PREFIX "subl %1,%0\n"
9111 + "int $4\n0:\n"
9112 + _ASM_EXTABLE(0b, 0b)
9113 +#endif
9114 +
9115 + : "+m" (v->counter)
9116 + : "ir" (i));
9117 +}
9118 +
9119 +/**
9120 + * atomic_add_unchecked - add integer to atomic variable
9121 + * @i: integer value to add
9122 + * @v: pointer of type atomic_unchecked_t
9123 + *
9124 + * Atomically adds @i to @v.
9125 + */
9126 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9127 +{
9128 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9129 : "+m" (v->counter)
9130 : "ir" (i));
9131 }
9132 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9133 */
9134 static inline void atomic_sub(int i, atomic_t *v)
9135 {
9136 - asm volatile(LOCK_PREFIX "subl %1,%0"
9137 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9138 +
9139 +#ifdef CONFIG_PAX_REFCOUNT
9140 + "jno 0f\n"
9141 + LOCK_PREFIX "addl %1,%0\n"
9142 + "int $4\n0:\n"
9143 + _ASM_EXTABLE(0b, 0b)
9144 +#endif
9145 +
9146 + : "+m" (v->counter)
9147 + : "ir" (i));
9148 +}
9149 +
9150 +/**
9151 + * atomic_sub_unchecked - subtract integer from atomic variable
9152 + * @i: integer value to subtract
9153 + * @v: pointer of type atomic_unchecked_t
9154 + *
9155 + * Atomically subtracts @i from @v.
9156 + */
9157 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9158 +{
9159 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9160 : "+m" (v->counter)
9161 : "ir" (i));
9162 }
9163 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9164 {
9165 unsigned char c;
9166
9167 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9168 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9169 +
9170 +#ifdef CONFIG_PAX_REFCOUNT
9171 + "jno 0f\n"
9172 + LOCK_PREFIX "addl %2,%0\n"
9173 + "int $4\n0:\n"
9174 + _ASM_EXTABLE(0b, 0b)
9175 +#endif
9176 +
9177 + "sete %1\n"
9178 : "+m" (v->counter), "=qm" (c)
9179 : "ir" (i) : "memory");
9180 return c;
9181 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9182 */
9183 static inline void atomic_inc(atomic_t *v)
9184 {
9185 - asm volatile(LOCK_PREFIX "incl %0"
9186 + asm volatile(LOCK_PREFIX "incl %0\n"
9187 +
9188 +#ifdef CONFIG_PAX_REFCOUNT
9189 + "jno 0f\n"
9190 + LOCK_PREFIX "decl %0\n"
9191 + "int $4\n0:\n"
9192 + _ASM_EXTABLE(0b, 0b)
9193 +#endif
9194 +
9195 + : "+m" (v->counter));
9196 +}
9197 +
9198 +/**
9199 + * atomic_inc_unchecked - increment atomic variable
9200 + * @v: pointer of type atomic_unchecked_t
9201 + *
9202 + * Atomically increments @v by 1.
9203 + */
9204 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9205 +{
9206 + asm volatile(LOCK_PREFIX "incl %0\n"
9207 : "+m" (v->counter));
9208 }
9209
9210 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9211 */
9212 static inline void atomic_dec(atomic_t *v)
9213 {
9214 - asm volatile(LOCK_PREFIX "decl %0"
9215 + asm volatile(LOCK_PREFIX "decl %0\n"
9216 +
9217 +#ifdef CONFIG_PAX_REFCOUNT
9218 + "jno 0f\n"
9219 + LOCK_PREFIX "incl %0\n"
9220 + "int $4\n0:\n"
9221 + _ASM_EXTABLE(0b, 0b)
9222 +#endif
9223 +
9224 + : "+m" (v->counter));
9225 +}
9226 +
9227 +/**
9228 + * atomic_dec_unchecked - decrement atomic variable
9229 + * @v: pointer of type atomic_unchecked_t
9230 + *
9231 + * Atomically decrements @v by 1.
9232 + */
9233 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9234 +{
9235 + asm volatile(LOCK_PREFIX "decl %0\n"
9236 : "+m" (v->counter));
9237 }
9238
9239 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9240 {
9241 unsigned char c;
9242
9243 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9244 + asm volatile(LOCK_PREFIX "decl %0\n"
9245 +
9246 +#ifdef CONFIG_PAX_REFCOUNT
9247 + "jno 0f\n"
9248 + LOCK_PREFIX "incl %0\n"
9249 + "int $4\n0:\n"
9250 + _ASM_EXTABLE(0b, 0b)
9251 +#endif
9252 +
9253 + "sete %1\n"
9254 : "+m" (v->counter), "=qm" (c)
9255 : : "memory");
9256 return c != 0;
9257 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9258 {
9259 unsigned char c;
9260
9261 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9262 + asm volatile(LOCK_PREFIX "incl %0\n"
9263 +
9264 +#ifdef CONFIG_PAX_REFCOUNT
9265 + "jno 0f\n"
9266 + LOCK_PREFIX "decl %0\n"
9267 + "int $4\n0:\n"
9268 + _ASM_EXTABLE(0b, 0b)
9269 +#endif
9270 +
9271 + "sete %1\n"
9272 + : "+m" (v->counter), "=qm" (c)
9273 + : : "memory");
9274 + return c != 0;
9275 +}
9276 +
9277 +/**
9278 + * atomic_inc_and_test_unchecked - increment and test
9279 + * @v: pointer of type atomic_unchecked_t
9280 + *
9281 + * Atomically increments @v by 1
9282 + * and returns true if the result is zero, or false for all
9283 + * other cases.
9284 + */
9285 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9286 +{
9287 + unsigned char c;
9288 +
9289 + asm volatile(LOCK_PREFIX "incl %0\n"
9290 + "sete %1\n"
9291 : "+m" (v->counter), "=qm" (c)
9292 : : "memory");
9293 return c != 0;
9294 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9295 {
9296 unsigned char c;
9297
9298 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9299 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9300 +
9301 +#ifdef CONFIG_PAX_REFCOUNT
9302 + "jno 0f\n"
9303 + LOCK_PREFIX "subl %2,%0\n"
9304 + "int $4\n0:\n"
9305 + _ASM_EXTABLE(0b, 0b)
9306 +#endif
9307 +
9308 + "sets %1\n"
9309 : "+m" (v->counter), "=qm" (c)
9310 : "ir" (i) : "memory");
9311 return c;
9312 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9313 goto no_xadd;
9314 #endif
9315 /* Modern 486+ processor */
9316 - return i + xadd(&v->counter, i);
9317 + return i + xadd_check_overflow(&v->counter, i);
9318
9319 #ifdef CONFIG_M386
9320 no_xadd: /* Legacy 386 processor */
9321 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9322 }
9323
9324 /**
9325 + * atomic_add_return_unchecked - add integer and return
9326 + * @i: integer value to add
9327 + * @v: pointer of type atomic_unchecked_t
9328 + *
9329 + * Atomically adds @i to @v and returns @i + @v
9330 + */
9331 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9332 +{
9333 +#ifdef CONFIG_M386
9334 + int __i;
9335 + unsigned long flags;
9336 + if (unlikely(boot_cpu_data.x86 <= 3))
9337 + goto no_xadd;
9338 +#endif
9339 + /* Modern 486+ processor */
9340 + return i + xadd(&v->counter, i);
9341 +
9342 +#ifdef CONFIG_M386
9343 +no_xadd: /* Legacy 386 processor */
9344 + raw_local_irq_save(flags);
9345 + __i = atomic_read_unchecked(v);
9346 + atomic_set_unchecked(v, i + __i);
9347 + raw_local_irq_restore(flags);
9348 + return i + __i;
9349 +#endif
9350 +}
9351 +
9352 +/**
9353 * atomic_sub_return - subtract integer and return
9354 * @v: pointer of type atomic_t
9355 * @i: integer value to subtract
9356 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9357 }
9358
9359 #define atomic_inc_return(v) (atomic_add_return(1, v))
9360 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9361 +{
9362 + return atomic_add_return_unchecked(1, v);
9363 +}
9364 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9365
9366 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9367 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9368 return cmpxchg(&v->counter, old, new);
9369 }
9370
9371 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9372 +{
9373 + return cmpxchg(&v->counter, old, new);
9374 +}
9375 +
9376 static inline int atomic_xchg(atomic_t *v, int new)
9377 {
9378 return xchg(&v->counter, new);
9379 }
9380
9381 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9382 +{
9383 + return xchg(&v->counter, new);
9384 +}
9385 +
9386 /**
9387 * __atomic_add_unless - add unless the number is already a given value
9388 * @v: pointer of type atomic_t
9389 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9390 */
9391 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9392 {
9393 - int c, old;
9394 + int c, old, new;
9395 c = atomic_read(v);
9396 for (;;) {
9397 - if (unlikely(c == (u)))
9398 + if (unlikely(c == u))
9399 break;
9400 - old = atomic_cmpxchg((v), c, c + (a));
9401 +
9402 + asm volatile("addl %2,%0\n"
9403 +
9404 +#ifdef CONFIG_PAX_REFCOUNT
9405 + "jno 0f\n"
9406 + "subl %2,%0\n"
9407 + "int $4\n0:\n"
9408 + _ASM_EXTABLE(0b, 0b)
9409 +#endif
9410 +
9411 + : "=r" (new)
9412 + : "0" (c), "ir" (a));
9413 +
9414 + old = atomic_cmpxchg(v, c, new);
9415 if (likely(old == c))
9416 break;
9417 c = old;
9418 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9419 return c;
9420 }
9421
9422 +/**
9423 + * atomic_inc_not_zero_hint - increment if not null
9424 + * @v: pointer of type atomic_t
9425 + * @hint: probable value of the atomic before the increment
9426 + *
9427 + * This version of atomic_inc_not_zero() gives a hint of probable
9428 + * value of the atomic. This helps processor to not read the memory
9429 + * before doing the atomic read/modify/write cycle, lowering
9430 + * number of bus transactions on some arches.
9431 + *
9432 + * Returns: 0 if increment was not done, 1 otherwise.
9433 + */
9434 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9435 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9436 +{
9437 + int val, c = hint, new;
9438 +
9439 + /* sanity test, should be removed by compiler if hint is a constant */
9440 + if (!hint)
9441 + return __atomic_add_unless(v, 1, 0);
9442 +
9443 + do {
9444 + asm volatile("incl %0\n"
9445 +
9446 +#ifdef CONFIG_PAX_REFCOUNT
9447 + "jno 0f\n"
9448 + "decl %0\n"
9449 + "int $4\n0:\n"
9450 + _ASM_EXTABLE(0b, 0b)
9451 +#endif
9452 +
9453 + : "=r" (new)
9454 + : "0" (c));
9455 +
9456 + val = atomic_cmpxchg(v, c, new);
9457 + if (val == c)
9458 + return 1;
9459 + c = val;
9460 + } while (c);
9461 +
9462 + return 0;
9463 +}
9464
9465 /*
9466 * atomic_dec_if_positive - decrement by 1 if old value positive
9467 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9468 #endif
9469
9470 /* These are x86-specific, used by some header files */
9471 -#define atomic_clear_mask(mask, addr) \
9472 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9473 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9474 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9475 +{
9476 + asm volatile(LOCK_PREFIX "andl %1,%0"
9477 + : "+m" (v->counter)
9478 + : "r" (~(mask))
9479 + : "memory");
9480 +}
9481
9482 -#define atomic_set_mask(mask, addr) \
9483 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9484 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9485 - : "memory")
9486 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9487 +{
9488 + asm volatile(LOCK_PREFIX "andl %1,%0"
9489 + : "+m" (v->counter)
9490 + : "r" (~(mask))
9491 + : "memory");
9492 +}
9493 +
9494 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9495 +{
9496 + asm volatile(LOCK_PREFIX "orl %1,%0"
9497 + : "+m" (v->counter)
9498 + : "r" (mask)
9499 + : "memory");
9500 +}
9501 +
9502 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9503 +{
9504 + asm volatile(LOCK_PREFIX "orl %1,%0"
9505 + : "+m" (v->counter)
9506 + : "r" (mask)
9507 + : "memory");
9508 +}
9509
9510 /* Atomic operations are already serializing on x86 */
9511 #define smp_mb__before_atomic_dec() barrier()
9512 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9513 index b154de7..aadebd8 100644
9514 --- a/arch/x86/include/asm/atomic64_32.h
9515 +++ b/arch/x86/include/asm/atomic64_32.h
9516 @@ -12,6 +12,14 @@ typedef struct {
9517 u64 __aligned(8) counter;
9518 } atomic64_t;
9519
9520 +#ifdef CONFIG_PAX_REFCOUNT
9521 +typedef struct {
9522 + u64 __aligned(8) counter;
9523 +} atomic64_unchecked_t;
9524 +#else
9525 +typedef atomic64_t atomic64_unchecked_t;
9526 +#endif
9527 +
9528 #define ATOMIC64_INIT(val) { (val) }
9529
9530 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9531 @@ -37,21 +45,31 @@ typedef struct {
9532 ATOMIC64_DECL_ONE(sym##_386)
9533
9534 ATOMIC64_DECL_ONE(add_386);
9535 +ATOMIC64_DECL_ONE(add_unchecked_386);
9536 ATOMIC64_DECL_ONE(sub_386);
9537 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9538 ATOMIC64_DECL_ONE(inc_386);
9539 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9540 ATOMIC64_DECL_ONE(dec_386);
9541 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9542 #endif
9543
9544 #define alternative_atomic64(f, out, in...) \
9545 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9546
9547 ATOMIC64_DECL(read);
9548 +ATOMIC64_DECL(read_unchecked);
9549 ATOMIC64_DECL(set);
9550 +ATOMIC64_DECL(set_unchecked);
9551 ATOMIC64_DECL(xchg);
9552 ATOMIC64_DECL(add_return);
9553 +ATOMIC64_DECL(add_return_unchecked);
9554 ATOMIC64_DECL(sub_return);
9555 +ATOMIC64_DECL(sub_return_unchecked);
9556 ATOMIC64_DECL(inc_return);
9557 +ATOMIC64_DECL(inc_return_unchecked);
9558 ATOMIC64_DECL(dec_return);
9559 +ATOMIC64_DECL(dec_return_unchecked);
9560 ATOMIC64_DECL(dec_if_positive);
9561 ATOMIC64_DECL(inc_not_zero);
9562 ATOMIC64_DECL(add_unless);
9563 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9564 }
9565
9566 /**
9567 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9568 + * @p: pointer to type atomic64_unchecked_t
9569 + * @o: expected value
9570 + * @n: new value
9571 + *
9572 + * Atomically sets @v to @n if it was equal to @o and returns
9573 + * the old value.
9574 + */
9575 +
9576 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9577 +{
9578 + return cmpxchg64(&v->counter, o, n);
9579 +}
9580 +
9581 +/**
9582 * atomic64_xchg - xchg atomic64 variable
9583 * @v: pointer to type atomic64_t
9584 * @n: value to assign
9585 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9586 }
9587
9588 /**
9589 + * atomic64_set_unchecked - set atomic64 variable
9590 + * @v: pointer to type atomic64_unchecked_t
9591 + * @n: value to assign
9592 + *
9593 + * Atomically sets the value of @v to @n.
9594 + */
9595 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9596 +{
9597 + unsigned high = (unsigned)(i >> 32);
9598 + unsigned low = (unsigned)i;
9599 + alternative_atomic64(set, /* no output */,
9600 + "S" (v), "b" (low), "c" (high)
9601 + : "eax", "edx", "memory");
9602 +}
9603 +
9604 +/**
9605 * atomic64_read - read atomic64 variable
9606 * @v: pointer to type atomic64_t
9607 *
9608 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9609 }
9610
9611 /**
9612 + * atomic64_read_unchecked - read atomic64 variable
9613 + * @v: pointer to type atomic64_unchecked_t
9614 + *
9615 + * Atomically reads the value of @v and returns it.
9616 + */
9617 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9618 +{
9619 + long long r;
9620 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9621 + return r;
9622 + }
9623 +
9624 +/**
9625 * atomic64_add_return - add and return
9626 * @i: integer value to add
9627 * @v: pointer to type atomic64_t
9628 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9629 return i;
9630 }
9631
9632 +/**
9633 + * atomic64_add_return_unchecked - add and return
9634 + * @i: integer value to add
9635 + * @v: pointer to type atomic64_unchecked_t
9636 + *
9637 + * Atomically adds @i to @v and returns @i + *@v
9638 + */
9639 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9640 +{
9641 + alternative_atomic64(add_return_unchecked,
9642 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9643 + ASM_NO_INPUT_CLOBBER("memory"));
9644 + return i;
9645 +}
9646 +
9647 /*
9648 * Other variants with different arithmetic operators:
9649 */
9650 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9651 return a;
9652 }
9653
9654 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9655 +{
9656 + long long a;
9657 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9658 + "S" (v) : "memory", "ecx");
9659 + return a;
9660 +}
9661 +
9662 static inline long long atomic64_dec_return(atomic64_t *v)
9663 {
9664 long long a;
9665 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9666 }
9667
9668 /**
9669 + * atomic64_add_unchecked - add integer to atomic64 variable
9670 + * @i: integer value to add
9671 + * @v: pointer to type atomic64_unchecked_t
9672 + *
9673 + * Atomically adds @i to @v.
9674 + */
9675 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9676 +{
9677 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9678 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9679 + ASM_NO_INPUT_CLOBBER("memory"));
9680 + return i;
9681 +}
9682 +
9683 +/**
9684 * atomic64_sub - subtract the atomic64 variable
9685 * @i: integer value to subtract
9686 * @v: pointer to type atomic64_t
9687 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9688 index 0e1cbfc..5623683 100644
9689 --- a/arch/x86/include/asm/atomic64_64.h
9690 +++ b/arch/x86/include/asm/atomic64_64.h
9691 @@ -18,7 +18,19 @@
9692 */
9693 static inline long atomic64_read(const atomic64_t *v)
9694 {
9695 - return (*(volatile long *)&(v)->counter);
9696 + return (*(volatile const long *)&(v)->counter);
9697 +}
9698 +
9699 +/**
9700 + * atomic64_read_unchecked - read atomic64 variable
9701 + * @v: pointer of type atomic64_unchecked_t
9702 + *
9703 + * Atomically reads the value of @v.
9704 + * Doesn't imply a read memory barrier.
9705 + */
9706 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9707 +{
9708 + return (*(volatile const long *)&(v)->counter);
9709 }
9710
9711 /**
9712 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9713 }
9714
9715 /**
9716 + * atomic64_set_unchecked - set atomic64 variable
9717 + * @v: pointer to type atomic64_unchecked_t
9718 + * @i: required value
9719 + *
9720 + * Atomically sets the value of @v to @i.
9721 + */
9722 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9723 +{
9724 + v->counter = i;
9725 +}
9726 +
9727 +/**
9728 * atomic64_add - add integer to atomic64 variable
9729 * @i: integer value to add
9730 * @v: pointer to type atomic64_t
9731 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9732 */
9733 static inline void atomic64_add(long i, atomic64_t *v)
9734 {
9735 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9736 +
9737 +#ifdef CONFIG_PAX_REFCOUNT
9738 + "jno 0f\n"
9739 + LOCK_PREFIX "subq %1,%0\n"
9740 + "int $4\n0:\n"
9741 + _ASM_EXTABLE(0b, 0b)
9742 +#endif
9743 +
9744 + : "=m" (v->counter)
9745 + : "er" (i), "m" (v->counter));
9746 +}
9747 +
9748 +/**
9749 + * atomic64_add_unchecked - add integer to atomic64 variable
9750 + * @i: integer value to add
9751 + * @v: pointer to type atomic64_unchecked_t
9752 + *
9753 + * Atomically adds @i to @v.
9754 + */
9755 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9756 +{
9757 asm volatile(LOCK_PREFIX "addq %1,%0"
9758 : "=m" (v->counter)
9759 : "er" (i), "m" (v->counter));
9760 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9761 */
9762 static inline void atomic64_sub(long i, atomic64_t *v)
9763 {
9764 - asm volatile(LOCK_PREFIX "subq %1,%0"
9765 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9766 +
9767 +#ifdef CONFIG_PAX_REFCOUNT
9768 + "jno 0f\n"
9769 + LOCK_PREFIX "addq %1,%0\n"
9770 + "int $4\n0:\n"
9771 + _ASM_EXTABLE(0b, 0b)
9772 +#endif
9773 +
9774 + : "=m" (v->counter)
9775 + : "er" (i), "m" (v->counter));
9776 +}
9777 +
9778 +/**
9779 + * atomic64_sub_unchecked - subtract the atomic64 variable
9780 + * @i: integer value to subtract
9781 + * @v: pointer to type atomic64_unchecked_t
9782 + *
9783 + * Atomically subtracts @i from @v.
9784 + */
9785 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9786 +{
9787 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9788 : "=m" (v->counter)
9789 : "er" (i), "m" (v->counter));
9790 }
9791 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9792 {
9793 unsigned char c;
9794
9795 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9796 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9797 +
9798 +#ifdef CONFIG_PAX_REFCOUNT
9799 + "jno 0f\n"
9800 + LOCK_PREFIX "addq %2,%0\n"
9801 + "int $4\n0:\n"
9802 + _ASM_EXTABLE(0b, 0b)
9803 +#endif
9804 +
9805 + "sete %1\n"
9806 : "=m" (v->counter), "=qm" (c)
9807 : "er" (i), "m" (v->counter) : "memory");
9808 return c;
9809 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9810 */
9811 static inline void atomic64_inc(atomic64_t *v)
9812 {
9813 + asm volatile(LOCK_PREFIX "incq %0\n"
9814 +
9815 +#ifdef CONFIG_PAX_REFCOUNT
9816 + "jno 0f\n"
9817 + LOCK_PREFIX "decq %0\n"
9818 + "int $4\n0:\n"
9819 + _ASM_EXTABLE(0b, 0b)
9820 +#endif
9821 +
9822 + : "=m" (v->counter)
9823 + : "m" (v->counter));
9824 +}
9825 +
9826 +/**
9827 + * atomic64_inc_unchecked - increment atomic64 variable
9828 + * @v: pointer to type atomic64_unchecked_t
9829 + *
9830 + * Atomically increments @v by 1.
9831 + */
9832 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9833 +{
9834 asm volatile(LOCK_PREFIX "incq %0"
9835 : "=m" (v->counter)
9836 : "m" (v->counter));
9837 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9838 */
9839 static inline void atomic64_dec(atomic64_t *v)
9840 {
9841 - asm volatile(LOCK_PREFIX "decq %0"
9842 + asm volatile(LOCK_PREFIX "decq %0\n"
9843 +
9844 +#ifdef CONFIG_PAX_REFCOUNT
9845 + "jno 0f\n"
9846 + LOCK_PREFIX "incq %0\n"
9847 + "int $4\n0:\n"
9848 + _ASM_EXTABLE(0b, 0b)
9849 +#endif
9850 +
9851 + : "=m" (v->counter)
9852 + : "m" (v->counter));
9853 +}
9854 +
9855 +/**
9856 + * atomic64_dec_unchecked - decrement atomic64 variable
9857 + * @v: pointer to type atomic64_t
9858 + *
9859 + * Atomically decrements @v by 1.
9860 + */
9861 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9862 +{
9863 + asm volatile(LOCK_PREFIX "decq %0\n"
9864 : "=m" (v->counter)
9865 : "m" (v->counter));
9866 }
9867 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9868 {
9869 unsigned char c;
9870
9871 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9872 + asm volatile(LOCK_PREFIX "decq %0\n"
9873 +
9874 +#ifdef CONFIG_PAX_REFCOUNT
9875 + "jno 0f\n"
9876 + LOCK_PREFIX "incq %0\n"
9877 + "int $4\n0:\n"
9878 + _ASM_EXTABLE(0b, 0b)
9879 +#endif
9880 +
9881 + "sete %1\n"
9882 : "=m" (v->counter), "=qm" (c)
9883 : "m" (v->counter) : "memory");
9884 return c != 0;
9885 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9886 {
9887 unsigned char c;
9888
9889 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9890 + asm volatile(LOCK_PREFIX "incq %0\n"
9891 +
9892 +#ifdef CONFIG_PAX_REFCOUNT
9893 + "jno 0f\n"
9894 + LOCK_PREFIX "decq %0\n"
9895 + "int $4\n0:\n"
9896 + _ASM_EXTABLE(0b, 0b)
9897 +#endif
9898 +
9899 + "sete %1\n"
9900 : "=m" (v->counter), "=qm" (c)
9901 : "m" (v->counter) : "memory");
9902 return c != 0;
9903 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9904 {
9905 unsigned char c;
9906
9907 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9908 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9909 +
9910 +#ifdef CONFIG_PAX_REFCOUNT
9911 + "jno 0f\n"
9912 + LOCK_PREFIX "subq %2,%0\n"
9913 + "int $4\n0:\n"
9914 + _ASM_EXTABLE(0b, 0b)
9915 +#endif
9916 +
9917 + "sets %1\n"
9918 : "=m" (v->counter), "=qm" (c)
9919 : "er" (i), "m" (v->counter) : "memory");
9920 return c;
9921 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9922 */
9923 static inline long atomic64_add_return(long i, atomic64_t *v)
9924 {
9925 + return i + xadd_check_overflow(&v->counter, i);
9926 +}
9927 +
9928 +/**
9929 + * atomic64_add_return_unchecked - add and return
9930 + * @i: integer value to add
9931 + * @v: pointer to type atomic64_unchecked_t
9932 + *
9933 + * Atomically adds @i to @v and returns @i + @v
9934 + */
9935 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9936 +{
9937 return i + xadd(&v->counter, i);
9938 }
9939
9940 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9941 }
9942
9943 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9944 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9945 +{
9946 + return atomic64_add_return_unchecked(1, v);
9947 +}
9948 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9949
9950 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9951 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9952 return cmpxchg(&v->counter, old, new);
9953 }
9954
9955 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9956 +{
9957 + return cmpxchg(&v->counter, old, new);
9958 +}
9959 +
9960 static inline long atomic64_xchg(atomic64_t *v, long new)
9961 {
9962 return xchg(&v->counter, new);
9963 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9964 */
9965 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9966 {
9967 - long c, old;
9968 + long c, old, new;
9969 c = atomic64_read(v);
9970 for (;;) {
9971 - if (unlikely(c == (u)))
9972 + if (unlikely(c == u))
9973 break;
9974 - old = atomic64_cmpxchg((v), c, c + (a));
9975 +
9976 + asm volatile("add %2,%0\n"
9977 +
9978 +#ifdef CONFIG_PAX_REFCOUNT
9979 + "jno 0f\n"
9980 + "sub %2,%0\n"
9981 + "int $4\n0:\n"
9982 + _ASM_EXTABLE(0b, 0b)
9983 +#endif
9984 +
9985 + : "=r" (new)
9986 + : "0" (c), "ir" (a));
9987 +
9988 + old = atomic64_cmpxchg(v, c, new);
9989 if (likely(old == c))
9990 break;
9991 c = old;
9992 }
9993 - return c != (u);
9994 + return c != u;
9995 }
9996
9997 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9998 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9999 index a6983b2..63f48a2 100644
10000 --- a/arch/x86/include/asm/bitops.h
10001 +++ b/arch/x86/include/asm/bitops.h
10002 @@ -40,7 +40,7 @@
10003 * a mask operation on a byte.
10004 */
10005 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10006 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10007 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10008 #define CONST_MASK(nr) (1 << ((nr) & 7))
10009
10010 /**
10011 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10012 index b13fe63..0dab13a 100644
10013 --- a/arch/x86/include/asm/boot.h
10014 +++ b/arch/x86/include/asm/boot.h
10015 @@ -11,10 +11,15 @@
10016 #include <asm/pgtable_types.h>
10017
10018 /* Physical address where kernel should be loaded. */
10019 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10020 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10021 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10022 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10023
10024 +#ifndef __ASSEMBLY__
10025 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10026 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10027 +#endif
10028 +
10029 /* Minimum kernel alignment, as a power of two */
10030 #ifdef CONFIG_X86_64
10031 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10032 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10033 index 48f99f1..d78ebf9 100644
10034 --- a/arch/x86/include/asm/cache.h
10035 +++ b/arch/x86/include/asm/cache.h
10036 @@ -5,12 +5,13 @@
10037
10038 /* L1 cache line size */
10039 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10040 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10041 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10042
10043 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10044 +#define __read_only __attribute__((__section__(".data..read_only")))
10045
10046 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10047 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10048 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10049
10050 #ifdef CONFIG_X86_VSMP
10051 #ifdef CONFIG_SMP
10052 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10053 index 9863ee3..4a1f8e1 100644
10054 --- a/arch/x86/include/asm/cacheflush.h
10055 +++ b/arch/x86/include/asm/cacheflush.h
10056 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10057 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10058
10059 if (pg_flags == _PGMT_DEFAULT)
10060 - return -1;
10061 + return ~0UL;
10062 else if (pg_flags == _PGMT_WC)
10063 return _PAGE_CACHE_WC;
10064 else if (pg_flags == _PGMT_UC_MINUS)
10065 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10066 index 46fc474..b02b0f9 100644
10067 --- a/arch/x86/include/asm/checksum_32.h
10068 +++ b/arch/x86/include/asm/checksum_32.h
10069 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10070 int len, __wsum sum,
10071 int *src_err_ptr, int *dst_err_ptr);
10072
10073 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10074 + int len, __wsum sum,
10075 + int *src_err_ptr, int *dst_err_ptr);
10076 +
10077 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10078 + int len, __wsum sum,
10079 + int *src_err_ptr, int *dst_err_ptr);
10080 +
10081 /*
10082 * Note: when you get a NULL pointer exception here this means someone
10083 * passed in an incorrect kernel address to one of these functions.
10084 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10085 int *err_ptr)
10086 {
10087 might_sleep();
10088 - return csum_partial_copy_generic((__force void *)src, dst,
10089 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10090 len, sum, err_ptr, NULL);
10091 }
10092
10093 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10094 {
10095 might_sleep();
10096 if (access_ok(VERIFY_WRITE, dst, len))
10097 - return csum_partial_copy_generic(src, (__force void *)dst,
10098 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10099 len, sum, NULL, err_ptr);
10100
10101 if (len)
10102 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10103 index 99480e5..d81165b 100644
10104 --- a/arch/x86/include/asm/cmpxchg.h
10105 +++ b/arch/x86/include/asm/cmpxchg.h
10106 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10107 __compiletime_error("Bad argument size for cmpxchg");
10108 extern void __xadd_wrong_size(void)
10109 __compiletime_error("Bad argument size for xadd");
10110 +extern void __xadd_check_overflow_wrong_size(void)
10111 + __compiletime_error("Bad argument size for xadd_check_overflow");
10112 extern void __add_wrong_size(void)
10113 __compiletime_error("Bad argument size for add");
10114 +extern void __add_check_overflow_wrong_size(void)
10115 + __compiletime_error("Bad argument size for add_check_overflow");
10116
10117 /*
10118 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10119 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10120 __ret; \
10121 })
10122
10123 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10124 + ({ \
10125 + __typeof__ (*(ptr)) __ret = (arg); \
10126 + switch (sizeof(*(ptr))) { \
10127 + case __X86_CASE_L: \
10128 + asm volatile (lock #op "l %0, %1\n" \
10129 + "jno 0f\n" \
10130 + "mov %0,%1\n" \
10131 + "int $4\n0:\n" \
10132 + _ASM_EXTABLE(0b, 0b) \
10133 + : "+r" (__ret), "+m" (*(ptr)) \
10134 + : : "memory", "cc"); \
10135 + break; \
10136 + case __X86_CASE_Q: \
10137 + asm volatile (lock #op "q %q0, %1\n" \
10138 + "jno 0f\n" \
10139 + "mov %0,%1\n" \
10140 + "int $4\n0:\n" \
10141 + _ASM_EXTABLE(0b, 0b) \
10142 + : "+r" (__ret), "+m" (*(ptr)) \
10143 + : : "memory", "cc"); \
10144 + break; \
10145 + default: \
10146 + __ ## op ## _check_overflow_wrong_size(); \
10147 + } \
10148 + __ret; \
10149 + })
10150 +
10151 /*
10152 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10153 * Since this is generally used to protect other memory information, we
10154 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10155 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10156 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10157
10158 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10159 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10160 +
10161 #define __add(ptr, inc, lock) \
10162 ({ \
10163 __typeof__ (*(ptr)) __ret = (inc); \
10164 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10165 index f91e80f..7f9bd27 100644
10166 --- a/arch/x86/include/asm/cpufeature.h
10167 +++ b/arch/x86/include/asm/cpufeature.h
10168 @@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10169 ".section .discard,\"aw\",@progbits\n"
10170 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10171 ".previous\n"
10172 - ".section .altinstr_replacement,\"ax\"\n"
10173 + ".section .altinstr_replacement,\"a\"\n"
10174 "3: movb $1,%0\n"
10175 "4:\n"
10176 ".previous\n"
10177 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10178 index 8bf1c06..f723dfd 100644
10179 --- a/arch/x86/include/asm/desc.h
10180 +++ b/arch/x86/include/asm/desc.h
10181 @@ -4,6 +4,7 @@
10182 #include <asm/desc_defs.h>
10183 #include <asm/ldt.h>
10184 #include <asm/mmu.h>
10185 +#include <asm/pgtable.h>
10186
10187 #include <linux/smp.h>
10188 #include <linux/percpu.h>
10189 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10190
10191 desc->type = (info->read_exec_only ^ 1) << 1;
10192 desc->type |= info->contents << 2;
10193 + desc->type |= info->seg_not_present ^ 1;
10194
10195 desc->s = 1;
10196 desc->dpl = 0x3;
10197 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10198 }
10199
10200 extern struct desc_ptr idt_descr;
10201 -extern gate_desc idt_table[];
10202 extern struct desc_ptr nmi_idt_descr;
10203 -extern gate_desc nmi_idt_table[];
10204 -
10205 -struct gdt_page {
10206 - struct desc_struct gdt[GDT_ENTRIES];
10207 -} __attribute__((aligned(PAGE_SIZE)));
10208 -
10209 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10210 +extern gate_desc idt_table[256];
10211 +extern gate_desc nmi_idt_table[256];
10212
10213 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10214 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10215 {
10216 - return per_cpu(gdt_page, cpu).gdt;
10217 + return cpu_gdt_table[cpu];
10218 }
10219
10220 #ifdef CONFIG_X86_64
10221 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10222 unsigned long base, unsigned dpl, unsigned flags,
10223 unsigned short seg)
10224 {
10225 - gate->a = (seg << 16) | (base & 0xffff);
10226 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10227 + gate->gate.offset_low = base;
10228 + gate->gate.seg = seg;
10229 + gate->gate.reserved = 0;
10230 + gate->gate.type = type;
10231 + gate->gate.s = 0;
10232 + gate->gate.dpl = dpl;
10233 + gate->gate.p = 1;
10234 + gate->gate.offset_high = base >> 16;
10235 }
10236
10237 #endif
10238 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10239
10240 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10241 {
10242 + pax_open_kernel();
10243 memcpy(&idt[entry], gate, sizeof(*gate));
10244 + pax_close_kernel();
10245 }
10246
10247 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10248 {
10249 + pax_open_kernel();
10250 memcpy(&ldt[entry], desc, 8);
10251 + pax_close_kernel();
10252 }
10253
10254 static inline void
10255 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10256 default: size = sizeof(*gdt); break;
10257 }
10258
10259 + pax_open_kernel();
10260 memcpy(&gdt[entry], desc, size);
10261 + pax_close_kernel();
10262 }
10263
10264 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10265 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10266
10267 static inline void native_load_tr_desc(void)
10268 {
10269 + pax_open_kernel();
10270 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10271 + pax_close_kernel();
10272 }
10273
10274 static inline void native_load_gdt(const struct desc_ptr *dtr)
10275 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10276 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10277 unsigned int i;
10278
10279 + pax_open_kernel();
10280 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10281 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10282 + pax_close_kernel();
10283 }
10284
10285 #define _LDT_empty(info) \
10286 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10287 }
10288
10289 #ifdef CONFIG_X86_64
10290 -static inline void set_nmi_gate(int gate, void *addr)
10291 +static inline void set_nmi_gate(int gate, const void *addr)
10292 {
10293 gate_desc s;
10294
10295 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10296 }
10297 #endif
10298
10299 -static inline void _set_gate(int gate, unsigned type, void *addr,
10300 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10301 unsigned dpl, unsigned ist, unsigned seg)
10302 {
10303 gate_desc s;
10304 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10305 * Pentium F0 0F bugfix can have resulted in the mapped
10306 * IDT being write-protected.
10307 */
10308 -static inline void set_intr_gate(unsigned int n, void *addr)
10309 +static inline void set_intr_gate(unsigned int n, const void *addr)
10310 {
10311 BUG_ON((unsigned)n > 0xFF);
10312 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10313 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10314 /*
10315 * This routine sets up an interrupt gate at directory privilege level 3.
10316 */
10317 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10318 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10319 {
10320 BUG_ON((unsigned)n > 0xFF);
10321 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10322 }
10323
10324 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10325 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10326 {
10327 BUG_ON((unsigned)n > 0xFF);
10328 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10329 }
10330
10331 -static inline void set_trap_gate(unsigned int n, void *addr)
10332 +static inline void set_trap_gate(unsigned int n, const void *addr)
10333 {
10334 BUG_ON((unsigned)n > 0xFF);
10335 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10336 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10337 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10338 {
10339 BUG_ON((unsigned)n > 0xFF);
10340 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10341 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10342 }
10343
10344 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10345 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10346 {
10347 BUG_ON((unsigned)n > 0xFF);
10348 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10349 }
10350
10351 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10352 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10353 {
10354 BUG_ON((unsigned)n > 0xFF);
10355 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10356 }
10357
10358 +#ifdef CONFIG_X86_32
10359 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10360 +{
10361 + struct desc_struct d;
10362 +
10363 + if (likely(limit))
10364 + limit = (limit - 1UL) >> PAGE_SHIFT;
10365 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10366 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10367 +}
10368 +#endif
10369 +
10370 #endif /* _ASM_X86_DESC_H */
10371 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10372 index 278441f..b95a174 100644
10373 --- a/arch/x86/include/asm/desc_defs.h
10374 +++ b/arch/x86/include/asm/desc_defs.h
10375 @@ -31,6 +31,12 @@ struct desc_struct {
10376 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10377 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10378 };
10379 + struct {
10380 + u16 offset_low;
10381 + u16 seg;
10382 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10383 + unsigned offset_high: 16;
10384 + } gate;
10385 };
10386 } __attribute__((packed));
10387
10388 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10389 index 3778256..c5d4fce 100644
10390 --- a/arch/x86/include/asm/e820.h
10391 +++ b/arch/x86/include/asm/e820.h
10392 @@ -69,7 +69,7 @@ struct e820map {
10393 #define ISA_START_ADDRESS 0xa0000
10394 #define ISA_END_ADDRESS 0x100000
10395
10396 -#define BIOS_BEGIN 0x000a0000
10397 +#define BIOS_BEGIN 0x000c0000
10398 #define BIOS_END 0x00100000
10399
10400 #define BIOS_ROM_BASE 0xffe00000
10401 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10402 index 5939f44..f8845f6 100644
10403 --- a/arch/x86/include/asm/elf.h
10404 +++ b/arch/x86/include/asm/elf.h
10405 @@ -243,7 +243,25 @@ extern int force_personality32;
10406 the loader. We need to make sure that it is out of the way of the program
10407 that it will "exec", and that there is sufficient room for the brk. */
10408
10409 +#ifdef CONFIG_PAX_SEGMEXEC
10410 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10411 +#else
10412 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10413 +#endif
10414 +
10415 +#ifdef CONFIG_PAX_ASLR
10416 +#ifdef CONFIG_X86_32
10417 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10418 +
10419 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10420 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10421 +#else
10422 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10423 +
10424 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10425 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10426 +#endif
10427 +#endif
10428
10429 /* This yields a mask that user programs can use to figure out what
10430 instruction set this CPU supports. This could be done in user space,
10431 @@ -296,16 +314,12 @@ do { \
10432
10433 #define ARCH_DLINFO \
10434 do { \
10435 - if (vdso_enabled) \
10436 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10437 - (unsigned long)current->mm->context.vdso); \
10438 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10439 } while (0)
10440
10441 #define ARCH_DLINFO_X32 \
10442 do { \
10443 - if (vdso_enabled) \
10444 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10445 - (unsigned long)current->mm->context.vdso); \
10446 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10447 } while (0)
10448
10449 #define AT_SYSINFO 32
10450 @@ -320,7 +334,7 @@ else \
10451
10452 #endif /* !CONFIG_X86_32 */
10453
10454 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10455 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10456
10457 #define VDSO_ENTRY \
10458 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10459 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10460 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10461 #define compat_arch_setup_additional_pages syscall32_setup_pages
10462
10463 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10464 -#define arch_randomize_brk arch_randomize_brk
10465 -
10466 /*
10467 * True on X86_32 or when emulating IA32 on X86_64
10468 */
10469 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10470 index cc70c1c..d96d011 100644
10471 --- a/arch/x86/include/asm/emergency-restart.h
10472 +++ b/arch/x86/include/asm/emergency-restart.h
10473 @@ -15,6 +15,6 @@ enum reboot_type {
10474
10475 extern enum reboot_type reboot_type;
10476
10477 -extern void machine_emergency_restart(void);
10478 +extern void machine_emergency_restart(void) __noreturn;
10479
10480 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10481 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10482 index 75f4c6d..ee3eb8f 100644
10483 --- a/arch/x86/include/asm/fpu-internal.h
10484 +++ b/arch/x86/include/asm/fpu-internal.h
10485 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10486 {
10487 int err;
10488
10489 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10490 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10491 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10492 +#endif
10493 +
10494 /* See comment in fxsave() below. */
10495 #ifdef CONFIG_AS_FXSAVEQ
10496 asm volatile("1: fxrstorq %[fx]\n\t"
10497 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10498 {
10499 int err;
10500
10501 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10502 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10503 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10504 +#endif
10505 +
10506 /*
10507 * Clear the bytes not touched by the fxsave and reserved
10508 * for the SW usage.
10509 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10510 "emms\n\t" /* clear stack tags */
10511 "fildl %P[addr]", /* set F?P to defined value */
10512 X86_FEATURE_FXSAVE_LEAK,
10513 - [addr] "m" (tsk->thread.fpu.has_fpu));
10514 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10515
10516 return fpu_restore_checking(&tsk->thread.fpu);
10517 }
10518 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10519 index 71ecbcb..bac10b7 100644
10520 --- a/arch/x86/include/asm/futex.h
10521 +++ b/arch/x86/include/asm/futex.h
10522 @@ -11,16 +11,18 @@
10523 #include <asm/processor.h>
10524
10525 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10526 + typecheck(u32 __user *, uaddr); \
10527 asm volatile("1:\t" insn "\n" \
10528 "2:\t.section .fixup,\"ax\"\n" \
10529 "3:\tmov\t%3, %1\n" \
10530 "\tjmp\t2b\n" \
10531 "\t.previous\n" \
10532 _ASM_EXTABLE(1b, 3b) \
10533 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10534 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10535 : "i" (-EFAULT), "0" (oparg), "1" (0))
10536
10537 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10538 + typecheck(u32 __user *, uaddr); \
10539 asm volatile("1:\tmovl %2, %0\n" \
10540 "\tmovl\t%0, %3\n" \
10541 "\t" insn "\n" \
10542 @@ -33,7 +35,7 @@
10543 _ASM_EXTABLE(1b, 4b) \
10544 _ASM_EXTABLE(2b, 4b) \
10545 : "=&a" (oldval), "=&r" (ret), \
10546 - "+m" (*uaddr), "=&r" (tem) \
10547 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10548 : "r" (oparg), "i" (-EFAULT), "1" (0))
10549
10550 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10551 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10552
10553 switch (op) {
10554 case FUTEX_OP_SET:
10555 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10556 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10557 break;
10558 case FUTEX_OP_ADD:
10559 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10560 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10561 uaddr, oparg);
10562 break;
10563 case FUTEX_OP_OR:
10564 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10565 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10566 return -EFAULT;
10567
10568 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10569 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10570 "2:\t.section .fixup, \"ax\"\n"
10571 "3:\tmov %3, %0\n"
10572 "\tjmp 2b\n"
10573 "\t.previous\n"
10574 _ASM_EXTABLE(1b, 3b)
10575 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10576 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10577 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10578 : "memory"
10579 );
10580 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10581 index eb92a6e..b98b2f4 100644
10582 --- a/arch/x86/include/asm/hw_irq.h
10583 +++ b/arch/x86/include/asm/hw_irq.h
10584 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10585 extern void enable_IO_APIC(void);
10586
10587 /* Statistics */
10588 -extern atomic_t irq_err_count;
10589 -extern atomic_t irq_mis_count;
10590 +extern atomic_unchecked_t irq_err_count;
10591 +extern atomic_unchecked_t irq_mis_count;
10592
10593 /* EISA */
10594 extern void eisa_set_level_irq(unsigned int irq);
10595 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10596 index d8e8eef..99f81ae 100644
10597 --- a/arch/x86/include/asm/io.h
10598 +++ b/arch/x86/include/asm/io.h
10599 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10600
10601 #include <linux/vmalloc.h>
10602
10603 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10604 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10605 +{
10606 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10607 +}
10608 +
10609 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10610 +{
10611 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10612 +}
10613 +
10614 /*
10615 * Convert a virtual cached pointer to an uncached pointer
10616 */
10617 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10618 index bba3cf8..06bc8da 100644
10619 --- a/arch/x86/include/asm/irqflags.h
10620 +++ b/arch/x86/include/asm/irqflags.h
10621 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10622 sti; \
10623 sysexit
10624
10625 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10626 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10627 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10628 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10629 +
10630 #else
10631 #define INTERRUPT_RETURN iret
10632 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10633 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10634 index 5478825..839e88c 100644
10635 --- a/arch/x86/include/asm/kprobes.h
10636 +++ b/arch/x86/include/asm/kprobes.h
10637 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10638 #define RELATIVEJUMP_SIZE 5
10639 #define RELATIVECALL_OPCODE 0xe8
10640 #define RELATIVE_ADDR_SIZE 4
10641 -#define MAX_STACK_SIZE 64
10642 -#define MIN_STACK_SIZE(ADDR) \
10643 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10644 - THREAD_SIZE - (unsigned long)(ADDR))) \
10645 - ? (MAX_STACK_SIZE) \
10646 - : (((unsigned long)current_thread_info()) + \
10647 - THREAD_SIZE - (unsigned long)(ADDR)))
10648 +#define MAX_STACK_SIZE 64UL
10649 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10650
10651 #define flush_insn_slot(p) do { } while (0)
10652
10653 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10654 index db7c1f2..92f130a 100644
10655 --- a/arch/x86/include/asm/kvm_host.h
10656 +++ b/arch/x86/include/asm/kvm_host.h
10657 @@ -680,7 +680,7 @@ struct kvm_x86_ops {
10658 int (*check_intercept)(struct kvm_vcpu *vcpu,
10659 struct x86_instruction_info *info,
10660 enum x86_intercept_stage stage);
10661 -};
10662 +} __do_const;
10663
10664 struct kvm_arch_async_pf {
10665 u32 token;
10666 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10667 index c8bed0d..e5721fa 100644
10668 --- a/arch/x86/include/asm/local.h
10669 +++ b/arch/x86/include/asm/local.h
10670 @@ -17,26 +17,58 @@ typedef struct {
10671
10672 static inline void local_inc(local_t *l)
10673 {
10674 - asm volatile(_ASM_INC "%0"
10675 + asm volatile(_ASM_INC "%0\n"
10676 +
10677 +#ifdef CONFIG_PAX_REFCOUNT
10678 + "jno 0f\n"
10679 + _ASM_DEC "%0\n"
10680 + "int $4\n0:\n"
10681 + _ASM_EXTABLE(0b, 0b)
10682 +#endif
10683 +
10684 : "+m" (l->a.counter));
10685 }
10686
10687 static inline void local_dec(local_t *l)
10688 {
10689 - asm volatile(_ASM_DEC "%0"
10690 + asm volatile(_ASM_DEC "%0\n"
10691 +
10692 +#ifdef CONFIG_PAX_REFCOUNT
10693 + "jno 0f\n"
10694 + _ASM_INC "%0\n"
10695 + "int $4\n0:\n"
10696 + _ASM_EXTABLE(0b, 0b)
10697 +#endif
10698 +
10699 : "+m" (l->a.counter));
10700 }
10701
10702 static inline void local_add(long i, local_t *l)
10703 {
10704 - asm volatile(_ASM_ADD "%1,%0"
10705 + asm volatile(_ASM_ADD "%1,%0\n"
10706 +
10707 +#ifdef CONFIG_PAX_REFCOUNT
10708 + "jno 0f\n"
10709 + _ASM_SUB "%1,%0\n"
10710 + "int $4\n0:\n"
10711 + _ASM_EXTABLE(0b, 0b)
10712 +#endif
10713 +
10714 : "+m" (l->a.counter)
10715 : "ir" (i));
10716 }
10717
10718 static inline void local_sub(long i, local_t *l)
10719 {
10720 - asm volatile(_ASM_SUB "%1,%0"
10721 + asm volatile(_ASM_SUB "%1,%0\n"
10722 +
10723 +#ifdef CONFIG_PAX_REFCOUNT
10724 + "jno 0f\n"
10725 + _ASM_ADD "%1,%0\n"
10726 + "int $4\n0:\n"
10727 + _ASM_EXTABLE(0b, 0b)
10728 +#endif
10729 +
10730 : "+m" (l->a.counter)
10731 : "ir" (i));
10732 }
10733 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10734 {
10735 unsigned char c;
10736
10737 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10738 + asm volatile(_ASM_SUB "%2,%0\n"
10739 +
10740 +#ifdef CONFIG_PAX_REFCOUNT
10741 + "jno 0f\n"
10742 + _ASM_ADD "%2,%0\n"
10743 + "int $4\n0:\n"
10744 + _ASM_EXTABLE(0b, 0b)
10745 +#endif
10746 +
10747 + "sete %1\n"
10748 : "+m" (l->a.counter), "=qm" (c)
10749 : "ir" (i) : "memory");
10750 return c;
10751 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10752 {
10753 unsigned char c;
10754
10755 - asm volatile(_ASM_DEC "%0; sete %1"
10756 + asm volatile(_ASM_DEC "%0\n"
10757 +
10758 +#ifdef CONFIG_PAX_REFCOUNT
10759 + "jno 0f\n"
10760 + _ASM_INC "%0\n"
10761 + "int $4\n0:\n"
10762 + _ASM_EXTABLE(0b, 0b)
10763 +#endif
10764 +
10765 + "sete %1\n"
10766 : "+m" (l->a.counter), "=qm" (c)
10767 : : "memory");
10768 return c != 0;
10769 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10770 {
10771 unsigned char c;
10772
10773 - asm volatile(_ASM_INC "%0; sete %1"
10774 + asm volatile(_ASM_INC "%0\n"
10775 +
10776 +#ifdef CONFIG_PAX_REFCOUNT
10777 + "jno 0f\n"
10778 + _ASM_DEC "%0\n"
10779 + "int $4\n0:\n"
10780 + _ASM_EXTABLE(0b, 0b)
10781 +#endif
10782 +
10783 + "sete %1\n"
10784 : "+m" (l->a.counter), "=qm" (c)
10785 : : "memory");
10786 return c != 0;
10787 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10788 {
10789 unsigned char c;
10790
10791 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10792 + asm volatile(_ASM_ADD "%2,%0\n"
10793 +
10794 +#ifdef CONFIG_PAX_REFCOUNT
10795 + "jno 0f\n"
10796 + _ASM_SUB "%2,%0\n"
10797 + "int $4\n0:\n"
10798 + _ASM_EXTABLE(0b, 0b)
10799 +#endif
10800 +
10801 + "sets %1\n"
10802 : "+m" (l->a.counter), "=qm" (c)
10803 : "ir" (i) : "memory");
10804 return c;
10805 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10806 #endif
10807 /* Modern 486+ processor */
10808 __i = i;
10809 - asm volatile(_ASM_XADD "%0, %1;"
10810 + asm volatile(_ASM_XADD "%0, %1\n"
10811 +
10812 +#ifdef CONFIG_PAX_REFCOUNT
10813 + "jno 0f\n"
10814 + _ASM_MOV "%0,%1\n"
10815 + "int $4\n0:\n"
10816 + _ASM_EXTABLE(0b, 0b)
10817 +#endif
10818 +
10819 : "+r" (i), "+m" (l->a.counter)
10820 : : "memory");
10821 return i + __i;
10822 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10823 index 593e51d..fa69c9a 100644
10824 --- a/arch/x86/include/asm/mman.h
10825 +++ b/arch/x86/include/asm/mman.h
10826 @@ -5,4 +5,14 @@
10827
10828 #include <asm-generic/mman.h>
10829
10830 +#ifdef __KERNEL__
10831 +#ifndef __ASSEMBLY__
10832 +#ifdef CONFIG_X86_32
10833 +#define arch_mmap_check i386_mmap_check
10834 +int i386_mmap_check(unsigned long addr, unsigned long len,
10835 + unsigned long flags);
10836 +#endif
10837 +#endif
10838 +#endif
10839 +
10840 #endif /* _ASM_X86_MMAN_H */
10841 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10842 index 5f55e69..e20bfb1 100644
10843 --- a/arch/x86/include/asm/mmu.h
10844 +++ b/arch/x86/include/asm/mmu.h
10845 @@ -9,7 +9,7 @@
10846 * we put the segment information here.
10847 */
10848 typedef struct {
10849 - void *ldt;
10850 + struct desc_struct *ldt;
10851 int size;
10852
10853 #ifdef CONFIG_X86_64
10854 @@ -18,7 +18,19 @@ typedef struct {
10855 #endif
10856
10857 struct mutex lock;
10858 - void *vdso;
10859 + unsigned long vdso;
10860 +
10861 +#ifdef CONFIG_X86_32
10862 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10863 + unsigned long user_cs_base;
10864 + unsigned long user_cs_limit;
10865 +
10866 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10867 + cpumask_t cpu_user_cs_mask;
10868 +#endif
10869 +
10870 +#endif
10871 +#endif
10872 } mm_context_t;
10873
10874 #ifdef CONFIG_SMP
10875 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10876 index cdbf367..adb37ac 100644
10877 --- a/arch/x86/include/asm/mmu_context.h
10878 +++ b/arch/x86/include/asm/mmu_context.h
10879 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10880
10881 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10882 {
10883 +
10884 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10885 + unsigned int i;
10886 + pgd_t *pgd;
10887 +
10888 + pax_open_kernel();
10889 + pgd = get_cpu_pgd(smp_processor_id());
10890 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10891 + set_pgd_batched(pgd+i, native_make_pgd(0));
10892 + pax_close_kernel();
10893 +#endif
10894 +
10895 #ifdef CONFIG_SMP
10896 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10897 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10898 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10899 struct task_struct *tsk)
10900 {
10901 unsigned cpu = smp_processor_id();
10902 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10903 + int tlbstate = TLBSTATE_OK;
10904 +#endif
10905
10906 if (likely(prev != next)) {
10907 #ifdef CONFIG_SMP
10908 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10909 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10910 +#endif
10911 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10912 this_cpu_write(cpu_tlbstate.active_mm, next);
10913 #endif
10914 cpumask_set_cpu(cpu, mm_cpumask(next));
10915
10916 /* Re-load page tables */
10917 +#ifdef CONFIG_PAX_PER_CPU_PGD
10918 + pax_open_kernel();
10919 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10920 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10921 + pax_close_kernel();
10922 + load_cr3(get_cpu_pgd(cpu));
10923 +#else
10924 load_cr3(next->pgd);
10925 +#endif
10926
10927 /* stop flush ipis for the previous mm */
10928 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10929 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10930 */
10931 if (unlikely(prev->context.ldt != next->context.ldt))
10932 load_LDT_nolock(&next->context);
10933 - }
10934 +
10935 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10936 + if (!(__supported_pte_mask & _PAGE_NX)) {
10937 + smp_mb__before_clear_bit();
10938 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10939 + smp_mb__after_clear_bit();
10940 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10941 + }
10942 +#endif
10943 +
10944 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10945 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10946 + prev->context.user_cs_limit != next->context.user_cs_limit))
10947 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10948 #ifdef CONFIG_SMP
10949 + else if (unlikely(tlbstate != TLBSTATE_OK))
10950 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10951 +#endif
10952 +#endif
10953 +
10954 + }
10955 else {
10956 +
10957 +#ifdef CONFIG_PAX_PER_CPU_PGD
10958 + pax_open_kernel();
10959 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10960 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10961 + pax_close_kernel();
10962 + load_cr3(get_cpu_pgd(cpu));
10963 +#endif
10964 +
10965 +#ifdef CONFIG_SMP
10966 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10967 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
10968
10969 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10970 * tlb flush IPI delivery. We must reload CR3
10971 * to make sure to use no freed page tables.
10972 */
10973 +
10974 +#ifndef CONFIG_PAX_PER_CPU_PGD
10975 load_cr3(next->pgd);
10976 +#endif
10977 +
10978 load_LDT_nolock(&next->context);
10979 +
10980 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10981 + if (!(__supported_pte_mask & _PAGE_NX))
10982 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10983 +#endif
10984 +
10985 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10986 +#ifdef CONFIG_PAX_PAGEEXEC
10987 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10988 +#endif
10989 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10990 +#endif
10991 +
10992 }
10993 +#endif
10994 }
10995 -#endif
10996 }
10997
10998 #define activate_mm(prev, next) \
10999 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11000 index 9eae775..c914fea 100644
11001 --- a/arch/x86/include/asm/module.h
11002 +++ b/arch/x86/include/asm/module.h
11003 @@ -5,6 +5,7 @@
11004
11005 #ifdef CONFIG_X86_64
11006 /* X86_64 does not define MODULE_PROC_FAMILY */
11007 +#define MODULE_PROC_FAMILY ""
11008 #elif defined CONFIG_M386
11009 #define MODULE_PROC_FAMILY "386 "
11010 #elif defined CONFIG_M486
11011 @@ -59,8 +60,20 @@
11012 #error unknown processor family
11013 #endif
11014
11015 -#ifdef CONFIG_X86_32
11016 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11017 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11018 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11019 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11020 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11021 +#else
11022 +#define MODULE_PAX_KERNEXEC ""
11023 #endif
11024
11025 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11026 +#define MODULE_PAX_UDEREF "UDEREF "
11027 +#else
11028 +#define MODULE_PAX_UDEREF ""
11029 +#endif
11030 +
11031 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11032 +
11033 #endif /* _ASM_X86_MODULE_H */
11034 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11035 index 320f7bb..e89f8f8 100644
11036 --- a/arch/x86/include/asm/page_64_types.h
11037 +++ b/arch/x86/include/asm/page_64_types.h
11038 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11039
11040 /* duplicated to the one in bootmem.h */
11041 extern unsigned long max_pfn;
11042 -extern unsigned long phys_base;
11043 +extern const unsigned long phys_base;
11044
11045 extern unsigned long __phys_addr(unsigned long);
11046 #define __phys_reloc_hide(x) (x)
11047 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11048 index 6cbbabf..11b3aed 100644
11049 --- a/arch/x86/include/asm/paravirt.h
11050 +++ b/arch/x86/include/asm/paravirt.h
11051 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11052 val);
11053 }
11054
11055 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11056 +{
11057 + pgdval_t val = native_pgd_val(pgd);
11058 +
11059 + if (sizeof(pgdval_t) > sizeof(long))
11060 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11061 + val, (u64)val >> 32);
11062 + else
11063 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11064 + val);
11065 +}
11066 +
11067 static inline void pgd_clear(pgd_t *pgdp)
11068 {
11069 set_pgd(pgdp, __pgd(0));
11070 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11071 pv_mmu_ops.set_fixmap(idx, phys, flags);
11072 }
11073
11074 +#ifdef CONFIG_PAX_KERNEXEC
11075 +static inline unsigned long pax_open_kernel(void)
11076 +{
11077 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11078 +}
11079 +
11080 +static inline unsigned long pax_close_kernel(void)
11081 +{
11082 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11083 +}
11084 +#else
11085 +static inline unsigned long pax_open_kernel(void) { return 0; }
11086 +static inline unsigned long pax_close_kernel(void) { return 0; }
11087 +#endif
11088 +
11089 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11090
11091 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11092 @@ -965,7 +992,7 @@ extern void default_banner(void);
11093
11094 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11095 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11096 -#define PARA_INDIRECT(addr) *%cs:addr
11097 +#define PARA_INDIRECT(addr) *%ss:addr
11098 #endif
11099
11100 #define INTERRUPT_RETURN \
11101 @@ -1040,6 +1067,21 @@ extern void default_banner(void);
11102 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11103 CLBR_NONE, \
11104 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11105 +
11106 +#define GET_CR0_INTO_RDI \
11107 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11108 + mov %rax,%rdi
11109 +
11110 +#define SET_RDI_INTO_CR0 \
11111 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11112 +
11113 +#define GET_CR3_INTO_RDI \
11114 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11115 + mov %rax,%rdi
11116 +
11117 +#define SET_RDI_INTO_CR3 \
11118 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11119 +
11120 #endif /* CONFIG_X86_32 */
11121
11122 #endif /* __ASSEMBLY__ */
11123 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11124 index 8e8b9a4..f07d725 100644
11125 --- a/arch/x86/include/asm/paravirt_types.h
11126 +++ b/arch/x86/include/asm/paravirt_types.h
11127 @@ -84,20 +84,20 @@ struct pv_init_ops {
11128 */
11129 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11130 unsigned long addr, unsigned len);
11131 -};
11132 +} __no_const;
11133
11134
11135 struct pv_lazy_ops {
11136 /* Set deferred update mode, used for batching operations. */
11137 void (*enter)(void);
11138 void (*leave)(void);
11139 -};
11140 +} __no_const;
11141
11142 struct pv_time_ops {
11143 unsigned long long (*sched_clock)(void);
11144 unsigned long long (*steal_clock)(int cpu);
11145 unsigned long (*get_tsc_khz)(void);
11146 -};
11147 +} __no_const;
11148
11149 struct pv_cpu_ops {
11150 /* hooks for various privileged instructions */
11151 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11152
11153 void (*start_context_switch)(struct task_struct *prev);
11154 void (*end_context_switch)(struct task_struct *next);
11155 -};
11156 +} __no_const;
11157
11158 struct pv_irq_ops {
11159 /*
11160 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11161 unsigned long start_eip,
11162 unsigned long start_esp);
11163 #endif
11164 -};
11165 +} __no_const;
11166
11167 struct pv_mmu_ops {
11168 unsigned long (*read_cr2)(void);
11169 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11170 struct paravirt_callee_save make_pud;
11171
11172 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11173 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11174 #endif /* PAGETABLE_LEVELS == 4 */
11175 #endif /* PAGETABLE_LEVELS >= 3 */
11176
11177 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11178 an mfn. We can tell which is which from the index. */
11179 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11180 phys_addr_t phys, pgprot_t flags);
11181 +
11182 +#ifdef CONFIG_PAX_KERNEXEC
11183 + unsigned long (*pax_open_kernel)(void);
11184 + unsigned long (*pax_close_kernel)(void);
11185 +#endif
11186 +
11187 };
11188
11189 struct arch_spinlock;
11190 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11191 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11192 int (*spin_trylock)(struct arch_spinlock *lock);
11193 void (*spin_unlock)(struct arch_spinlock *lock);
11194 -};
11195 +} __no_const;
11196
11197 /* This contains all the paravirt structures: we get a convenient
11198 * number for each function using the offset which we use to indicate
11199 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11200 index b4389a4..7024269 100644
11201 --- a/arch/x86/include/asm/pgalloc.h
11202 +++ b/arch/x86/include/asm/pgalloc.h
11203 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11204 pmd_t *pmd, pte_t *pte)
11205 {
11206 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11207 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11208 +}
11209 +
11210 +static inline void pmd_populate_user(struct mm_struct *mm,
11211 + pmd_t *pmd, pte_t *pte)
11212 +{
11213 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11214 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11215 }
11216
11217 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11218
11219 #ifdef CONFIG_X86_PAE
11220 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11221 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11222 +{
11223 + pud_populate(mm, pudp, pmd);
11224 +}
11225 #else /* !CONFIG_X86_PAE */
11226 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11227 {
11228 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11229 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11230 }
11231 +
11232 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11233 +{
11234 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11235 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11236 +}
11237 #endif /* CONFIG_X86_PAE */
11238
11239 #if PAGETABLE_LEVELS > 3
11240 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11241 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11242 }
11243
11244 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11245 +{
11246 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11247 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11248 +}
11249 +
11250 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11251 {
11252 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11253 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11254 index 98391db..8f6984e 100644
11255 --- a/arch/x86/include/asm/pgtable-2level.h
11256 +++ b/arch/x86/include/asm/pgtable-2level.h
11257 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11258
11259 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11260 {
11261 + pax_open_kernel();
11262 *pmdp = pmd;
11263 + pax_close_kernel();
11264 }
11265
11266 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11267 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11268 index cb00ccc..17e9054 100644
11269 --- a/arch/x86/include/asm/pgtable-3level.h
11270 +++ b/arch/x86/include/asm/pgtable-3level.h
11271 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11272
11273 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11274 {
11275 + pax_open_kernel();
11276 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11277 + pax_close_kernel();
11278 }
11279
11280 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11281 {
11282 + pax_open_kernel();
11283 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11284 + pax_close_kernel();
11285 }
11286
11287 /*
11288 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11289 index 49afb3f..91a8c63 100644
11290 --- a/arch/x86/include/asm/pgtable.h
11291 +++ b/arch/x86/include/asm/pgtable.h
11292 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11293
11294 #ifndef __PAGETABLE_PUD_FOLDED
11295 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11296 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11297 #define pgd_clear(pgd) native_pgd_clear(pgd)
11298 #endif
11299
11300 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11301
11302 #define arch_end_context_switch(prev) do {} while(0)
11303
11304 +#define pax_open_kernel() native_pax_open_kernel()
11305 +#define pax_close_kernel() native_pax_close_kernel()
11306 #endif /* CONFIG_PARAVIRT */
11307
11308 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11309 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11310 +
11311 +#ifdef CONFIG_PAX_KERNEXEC
11312 +static inline unsigned long native_pax_open_kernel(void)
11313 +{
11314 + unsigned long cr0;
11315 +
11316 + preempt_disable();
11317 + barrier();
11318 + cr0 = read_cr0() ^ X86_CR0_WP;
11319 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11320 + write_cr0(cr0);
11321 + return cr0 ^ X86_CR0_WP;
11322 +}
11323 +
11324 +static inline unsigned long native_pax_close_kernel(void)
11325 +{
11326 + unsigned long cr0;
11327 +
11328 + cr0 = read_cr0() ^ X86_CR0_WP;
11329 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11330 + write_cr0(cr0);
11331 + barrier();
11332 + preempt_enable_no_resched();
11333 + return cr0 ^ X86_CR0_WP;
11334 +}
11335 +#else
11336 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11337 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11338 +#endif
11339 +
11340 /*
11341 * The following only work if pte_present() is true.
11342 * Undefined behaviour if not..
11343 */
11344 +static inline int pte_user(pte_t pte)
11345 +{
11346 + return pte_val(pte) & _PAGE_USER;
11347 +}
11348 +
11349 static inline int pte_dirty(pte_t pte)
11350 {
11351 return pte_flags(pte) & _PAGE_DIRTY;
11352 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11353 return pte_clear_flags(pte, _PAGE_RW);
11354 }
11355
11356 +static inline pte_t pte_mkread(pte_t pte)
11357 +{
11358 + return __pte(pte_val(pte) | _PAGE_USER);
11359 +}
11360 +
11361 static inline pte_t pte_mkexec(pte_t pte)
11362 {
11363 - return pte_clear_flags(pte, _PAGE_NX);
11364 +#ifdef CONFIG_X86_PAE
11365 + if (__supported_pte_mask & _PAGE_NX)
11366 + return pte_clear_flags(pte, _PAGE_NX);
11367 + else
11368 +#endif
11369 + return pte_set_flags(pte, _PAGE_USER);
11370 +}
11371 +
11372 +static inline pte_t pte_exprotect(pte_t pte)
11373 +{
11374 +#ifdef CONFIG_X86_PAE
11375 + if (__supported_pte_mask & _PAGE_NX)
11376 + return pte_set_flags(pte, _PAGE_NX);
11377 + else
11378 +#endif
11379 + return pte_clear_flags(pte, _PAGE_USER);
11380 }
11381
11382 static inline pte_t pte_mkdirty(pte_t pte)
11383 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11384 #endif
11385
11386 #ifndef __ASSEMBLY__
11387 +
11388 +#ifdef CONFIG_PAX_PER_CPU_PGD
11389 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11390 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11391 +{
11392 + return cpu_pgd[cpu];
11393 +}
11394 +#endif
11395 +
11396 #include <linux/mm_types.h>
11397
11398 static inline int pte_none(pte_t pte)
11399 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11400
11401 static inline int pgd_bad(pgd_t pgd)
11402 {
11403 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11404 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11405 }
11406
11407 static inline int pgd_none(pgd_t pgd)
11408 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11409 * pgd_offset() returns a (pgd_t *)
11410 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11411 */
11412 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11413 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11414 +
11415 +#ifdef CONFIG_PAX_PER_CPU_PGD
11416 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11417 +#endif
11418 +
11419 /*
11420 * a shortcut which implies the use of the kernel's pgd, instead
11421 * of a process's
11422 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11423 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11424 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11425
11426 +#ifdef CONFIG_X86_32
11427 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11428 +#else
11429 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11430 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11431 +
11432 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11433 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11434 +#else
11435 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11436 +#endif
11437 +
11438 +#endif
11439 +
11440 #ifndef __ASSEMBLY__
11441
11442 extern int direct_gbpages;
11443 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11444 * dst and src can be on the same page, but the range must not overlap,
11445 * and must not cross a page boundary.
11446 */
11447 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11448 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11449 {
11450 - memcpy(dst, src, count * sizeof(pgd_t));
11451 + pax_open_kernel();
11452 + while (count--)
11453 + *dst++ = *src++;
11454 + pax_close_kernel();
11455 }
11456
11457 +#ifdef CONFIG_PAX_PER_CPU_PGD
11458 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11459 +#endif
11460 +
11461 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11462 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11463 +#else
11464 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11465 +#endif
11466
11467 #include <asm-generic/pgtable.h>
11468 #endif /* __ASSEMBLY__ */
11469 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11470 index 0c92113..34a77c6 100644
11471 --- a/arch/x86/include/asm/pgtable_32.h
11472 +++ b/arch/x86/include/asm/pgtable_32.h
11473 @@ -25,9 +25,6 @@
11474 struct mm_struct;
11475 struct vm_area_struct;
11476
11477 -extern pgd_t swapper_pg_dir[1024];
11478 -extern pgd_t initial_page_table[1024];
11479 -
11480 static inline void pgtable_cache_init(void) { }
11481 static inline void check_pgt_cache(void) { }
11482 void paging_init(void);
11483 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11484 # include <asm/pgtable-2level.h>
11485 #endif
11486
11487 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11488 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11489 +#ifdef CONFIG_X86_PAE
11490 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11491 +#endif
11492 +
11493 #if defined(CONFIG_HIGHPTE)
11494 #define pte_offset_map(dir, address) \
11495 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11496 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11497 /* Clear a kernel PTE and flush it from the TLB */
11498 #define kpte_clear_flush(ptep, vaddr) \
11499 do { \
11500 + pax_open_kernel(); \
11501 pte_clear(&init_mm, (vaddr), (ptep)); \
11502 + pax_close_kernel(); \
11503 __flush_tlb_one((vaddr)); \
11504 } while (0)
11505
11506 @@ -74,6 +79,9 @@ do { \
11507
11508 #endif /* !__ASSEMBLY__ */
11509
11510 +#define HAVE_ARCH_UNMAPPED_AREA
11511 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11512 +
11513 /*
11514 * kern_addr_valid() is (1) for FLATMEM and (0) for
11515 * SPARSEMEM and DISCONTIGMEM
11516 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11517 index ed5903b..c7fe163 100644
11518 --- a/arch/x86/include/asm/pgtable_32_types.h
11519 +++ b/arch/x86/include/asm/pgtable_32_types.h
11520 @@ -8,7 +8,7 @@
11521 */
11522 #ifdef CONFIG_X86_PAE
11523 # include <asm/pgtable-3level_types.h>
11524 -# define PMD_SIZE (1UL << PMD_SHIFT)
11525 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11526 # define PMD_MASK (~(PMD_SIZE - 1))
11527 #else
11528 # include <asm/pgtable-2level_types.h>
11529 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11530 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11531 #endif
11532
11533 +#ifdef CONFIG_PAX_KERNEXEC
11534 +#ifndef __ASSEMBLY__
11535 +extern unsigned char MODULES_EXEC_VADDR[];
11536 +extern unsigned char MODULES_EXEC_END[];
11537 +#endif
11538 +#include <asm/boot.h>
11539 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11540 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11541 +#else
11542 +#define ktla_ktva(addr) (addr)
11543 +#define ktva_ktla(addr) (addr)
11544 +#endif
11545 +
11546 #define MODULES_VADDR VMALLOC_START
11547 #define MODULES_END VMALLOC_END
11548 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11549 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11550 index 975f709..9f779c9 100644
11551 --- a/arch/x86/include/asm/pgtable_64.h
11552 +++ b/arch/x86/include/asm/pgtable_64.h
11553 @@ -16,10 +16,14 @@
11554
11555 extern pud_t level3_kernel_pgt[512];
11556 extern pud_t level3_ident_pgt[512];
11557 +extern pud_t level3_vmalloc_start_pgt[512];
11558 +extern pud_t level3_vmalloc_end_pgt[512];
11559 +extern pud_t level3_vmemmap_pgt[512];
11560 +extern pud_t level2_vmemmap_pgt[512];
11561 extern pmd_t level2_kernel_pgt[512];
11562 extern pmd_t level2_fixmap_pgt[512];
11563 -extern pmd_t level2_ident_pgt[512];
11564 -extern pgd_t init_level4_pgt[];
11565 +extern pmd_t level2_ident_pgt[512*2];
11566 +extern pgd_t init_level4_pgt[512];
11567
11568 #define swapper_pg_dir init_level4_pgt
11569
11570 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11571
11572 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11573 {
11574 + pax_open_kernel();
11575 *pmdp = pmd;
11576 + pax_close_kernel();
11577 }
11578
11579 static inline void native_pmd_clear(pmd_t *pmd)
11580 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11581
11582 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11583 {
11584 + pax_open_kernel();
11585 *pudp = pud;
11586 + pax_close_kernel();
11587 }
11588
11589 static inline void native_pud_clear(pud_t *pud)
11590 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11591
11592 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11593 {
11594 + pax_open_kernel();
11595 + *pgdp = pgd;
11596 + pax_close_kernel();
11597 +}
11598 +
11599 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11600 +{
11601 *pgdp = pgd;
11602 }
11603
11604 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11605 index 766ea16..5b96cb3 100644
11606 --- a/arch/x86/include/asm/pgtable_64_types.h
11607 +++ b/arch/x86/include/asm/pgtable_64_types.h
11608 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11609 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11610 #define MODULES_END _AC(0xffffffffff000000, UL)
11611 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11612 +#define MODULES_EXEC_VADDR MODULES_VADDR
11613 +#define MODULES_EXEC_END MODULES_END
11614 +
11615 +#define ktla_ktva(addr) (addr)
11616 +#define ktva_ktla(addr) (addr)
11617
11618 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11619 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11620 index 013286a..8b42f4f 100644
11621 --- a/arch/x86/include/asm/pgtable_types.h
11622 +++ b/arch/x86/include/asm/pgtable_types.h
11623 @@ -16,13 +16,12 @@
11624 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11625 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11626 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11627 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11628 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11629 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11630 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11631 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11632 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11633 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11634 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11635 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11636 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11637 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11638
11639 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11640 @@ -40,7 +39,6 @@
11641 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11642 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11643 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11644 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11645 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11646 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11647 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11648 @@ -57,8 +55,10 @@
11649
11650 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11651 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11652 -#else
11653 +#elif defined(CONFIG_KMEMCHECK)
11654 #define _PAGE_NX (_AT(pteval_t, 0))
11655 +#else
11656 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11657 #endif
11658
11659 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11660 @@ -96,6 +96,9 @@
11661 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11662 _PAGE_ACCESSED)
11663
11664 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11665 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11666 +
11667 #define __PAGE_KERNEL_EXEC \
11668 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11669 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11670 @@ -106,7 +109,7 @@
11671 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11672 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11673 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11674 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11675 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11676 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11677 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11678 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11679 @@ -168,8 +171,8 @@
11680 * bits are combined, this will alow user to access the high address mapped
11681 * VDSO in the presence of CONFIG_COMPAT_VDSO
11682 */
11683 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11684 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11685 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11686 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11687 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11688 #endif
11689
11690 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11691 {
11692 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11693 }
11694 +#endif
11695
11696 +#if PAGETABLE_LEVELS == 3
11697 +#include <asm-generic/pgtable-nopud.h>
11698 +#endif
11699 +
11700 +#if PAGETABLE_LEVELS == 2
11701 +#include <asm-generic/pgtable-nopmd.h>
11702 +#endif
11703 +
11704 +#ifndef __ASSEMBLY__
11705 #if PAGETABLE_LEVELS > 3
11706 typedef struct { pudval_t pud; } pud_t;
11707
11708 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11709 return pud.pud;
11710 }
11711 #else
11712 -#include <asm-generic/pgtable-nopud.h>
11713 -
11714 static inline pudval_t native_pud_val(pud_t pud)
11715 {
11716 return native_pgd_val(pud.pgd);
11717 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11718 return pmd.pmd;
11719 }
11720 #else
11721 -#include <asm-generic/pgtable-nopmd.h>
11722 -
11723 static inline pmdval_t native_pmd_val(pmd_t pmd)
11724 {
11725 return native_pgd_val(pmd.pud.pgd);
11726 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11727
11728 extern pteval_t __supported_pte_mask;
11729 extern void set_nx(void);
11730 -extern int nx_enabled;
11731
11732 #define pgprot_writecombine pgprot_writecombine
11733 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11734 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11735 index 39bc577..538233f 100644
11736 --- a/arch/x86/include/asm/processor.h
11737 +++ b/arch/x86/include/asm/processor.h
11738 @@ -276,7 +276,7 @@ struct tss_struct {
11739
11740 } ____cacheline_aligned;
11741
11742 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11743 +extern struct tss_struct init_tss[NR_CPUS];
11744
11745 /*
11746 * Save the original ist values for checking stack pointers during debugging
11747 @@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11748 */
11749 #define TASK_SIZE PAGE_OFFSET
11750 #define TASK_SIZE_MAX TASK_SIZE
11751 +
11752 +#ifdef CONFIG_PAX_SEGMEXEC
11753 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11754 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11755 +#else
11756 #define STACK_TOP TASK_SIZE
11757 -#define STACK_TOP_MAX STACK_TOP
11758 +#endif
11759 +
11760 +#define STACK_TOP_MAX TASK_SIZE
11761
11762 #define INIT_THREAD { \
11763 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11764 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11765 .vm86_info = NULL, \
11766 .sysenter_cs = __KERNEL_CS, \
11767 .io_bitmap_ptr = NULL, \
11768 @@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11769 */
11770 #define INIT_TSS { \
11771 .x86_tss = { \
11772 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11773 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11774 .ss0 = __KERNEL_DS, \
11775 .ss1 = __KERNEL_CS, \
11776 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11777 @@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11778 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11779
11780 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11781 -#define KSTK_TOP(info) \
11782 -({ \
11783 - unsigned long *__ptr = (unsigned long *)(info); \
11784 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11785 -})
11786 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11787
11788 /*
11789 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11790 @@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11791 #define task_pt_regs(task) \
11792 ({ \
11793 struct pt_regs *__regs__; \
11794 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11795 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11796 __regs__ - 1; \
11797 })
11798
11799 @@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11800 /*
11801 * User space process size. 47bits minus one guard page.
11802 */
11803 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11804 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11805
11806 /* This decides where the kernel will search for a free chunk of vm
11807 * space during mmap's.
11808 */
11809 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11810 - 0xc0000000 : 0xFFFFe000)
11811 + 0xc0000000 : 0xFFFFf000)
11812
11813 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11814 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11815 @@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11816 #define STACK_TOP_MAX TASK_SIZE_MAX
11817
11818 #define INIT_THREAD { \
11819 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11820 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11821 }
11822
11823 #define INIT_TSS { \
11824 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11825 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11826 }
11827
11828 /*
11829 @@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11830 */
11831 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11832
11833 +#ifdef CONFIG_PAX_SEGMEXEC
11834 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11835 +#endif
11836 +
11837 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11838
11839 /* Get/set a process' ability to use the timestamp counter instruction */
11840 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11841 #define cpu_has_amd_erratum(x) (false)
11842 #endif /* CONFIG_CPU_SUP_AMD */
11843
11844 -extern unsigned long arch_align_stack(unsigned long sp);
11845 +#define arch_align_stack(x) ((x) & ~0xfUL)
11846 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11847
11848 void default_idle(void);
11849 bool set_pm_idle_to_default(void);
11850
11851 -void stop_this_cpu(void *dummy);
11852 +void stop_this_cpu(void *dummy) __noreturn;
11853
11854 #endif /* _ASM_X86_PROCESSOR_H */
11855 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11856 index dcfde52..dbfea06 100644
11857 --- a/arch/x86/include/asm/ptrace.h
11858 +++ b/arch/x86/include/asm/ptrace.h
11859 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11860 }
11861
11862 /*
11863 - * user_mode_vm(regs) determines whether a register set came from user mode.
11864 + * user_mode(regs) determines whether a register set came from user mode.
11865 * This is true if V8086 mode was enabled OR if the register set was from
11866 * protected mode with RPL-3 CS value. This tricky test checks that with
11867 * one comparison. Many places in the kernel can bypass this full check
11868 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11869 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11870 + * be used.
11871 */
11872 -static inline int user_mode(struct pt_regs *regs)
11873 +static inline int user_mode_novm(struct pt_regs *regs)
11874 {
11875 #ifdef CONFIG_X86_32
11876 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11877 #else
11878 - return !!(regs->cs & 3);
11879 + return !!(regs->cs & SEGMENT_RPL_MASK);
11880 #endif
11881 }
11882
11883 -static inline int user_mode_vm(struct pt_regs *regs)
11884 +static inline int user_mode(struct pt_regs *regs)
11885 {
11886 #ifdef CONFIG_X86_32
11887 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11888 USER_RPL;
11889 #else
11890 - return user_mode(regs);
11891 + return user_mode_novm(regs);
11892 #endif
11893 }
11894
11895 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11896 #ifdef CONFIG_X86_64
11897 static inline bool user_64bit_mode(struct pt_regs *regs)
11898 {
11899 + unsigned long cs = regs->cs & 0xffff;
11900 #ifndef CONFIG_PARAVIRT
11901 /*
11902 * On non-paravirt systems, this is the only long mode CPL 3
11903 * selector. We do not allow long mode selectors in the LDT.
11904 */
11905 - return regs->cs == __USER_CS;
11906 + return cs == __USER_CS;
11907 #else
11908 /* Headers are too twisted for this to go in paravirt.h. */
11909 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11910 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11911 #endif
11912 }
11913 #endif
11914 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11915 index fce3f4a..3f69f2a 100644
11916 --- a/arch/x86/include/asm/realmode.h
11917 +++ b/arch/x86/include/asm/realmode.h
11918 @@ -30,7 +30,7 @@ struct real_mode_header {
11919 struct trampoline_header {
11920 #ifdef CONFIG_X86_32
11921 u32 start;
11922 - u16 gdt_pad;
11923 + u16 boot_cs;
11924 u16 gdt_limit;
11925 u32 gdt_base;
11926 #else
11927 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11928 index 92f29706..a79cbbb 100644
11929 --- a/arch/x86/include/asm/reboot.h
11930 +++ b/arch/x86/include/asm/reboot.h
11931 @@ -6,19 +6,19 @@
11932 struct pt_regs;
11933
11934 struct machine_ops {
11935 - void (*restart)(char *cmd);
11936 - void (*halt)(void);
11937 - void (*power_off)(void);
11938 + void (* __noreturn restart)(char *cmd);
11939 + void (* __noreturn halt)(void);
11940 + void (* __noreturn power_off)(void);
11941 void (*shutdown)(void);
11942 void (*crash_shutdown)(struct pt_regs *);
11943 - void (*emergency_restart)(void);
11944 -};
11945 + void (* __noreturn emergency_restart)(void);
11946 +} __no_const;
11947
11948 extern struct machine_ops machine_ops;
11949
11950 void native_machine_crash_shutdown(struct pt_regs *regs);
11951 void native_machine_shutdown(void);
11952 -void machine_real_restart(unsigned int type);
11953 +void machine_real_restart(unsigned int type) __noreturn;
11954 /* These must match dispatch_table in reboot_32.S */
11955 #define MRR_BIOS 0
11956 #define MRR_APM 1
11957 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11958 index 2dbe4a7..ce1db00 100644
11959 --- a/arch/x86/include/asm/rwsem.h
11960 +++ b/arch/x86/include/asm/rwsem.h
11961 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11962 {
11963 asm volatile("# beginning down_read\n\t"
11964 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11965 +
11966 +#ifdef CONFIG_PAX_REFCOUNT
11967 + "jno 0f\n"
11968 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11969 + "int $4\n0:\n"
11970 + _ASM_EXTABLE(0b, 0b)
11971 +#endif
11972 +
11973 /* adds 0x00000001 */
11974 " jns 1f\n"
11975 " call call_rwsem_down_read_failed\n"
11976 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11977 "1:\n\t"
11978 " mov %1,%2\n\t"
11979 " add %3,%2\n\t"
11980 +
11981 +#ifdef CONFIG_PAX_REFCOUNT
11982 + "jno 0f\n"
11983 + "sub %3,%2\n"
11984 + "int $4\n0:\n"
11985 + _ASM_EXTABLE(0b, 0b)
11986 +#endif
11987 +
11988 " jle 2f\n\t"
11989 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11990 " jnz 1b\n\t"
11991 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11992 long tmp;
11993 asm volatile("# beginning down_write\n\t"
11994 LOCK_PREFIX " xadd %1,(%2)\n\t"
11995 +
11996 +#ifdef CONFIG_PAX_REFCOUNT
11997 + "jno 0f\n"
11998 + "mov %1,(%2)\n"
11999 + "int $4\n0:\n"
12000 + _ASM_EXTABLE(0b, 0b)
12001 +#endif
12002 +
12003 /* adds 0xffff0001, returns the old value */
12004 " test %1,%1\n\t"
12005 /* was the count 0 before? */
12006 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12007 long tmp;
12008 asm volatile("# beginning __up_read\n\t"
12009 LOCK_PREFIX " xadd %1,(%2)\n\t"
12010 +
12011 +#ifdef CONFIG_PAX_REFCOUNT
12012 + "jno 0f\n"
12013 + "mov %1,(%2)\n"
12014 + "int $4\n0:\n"
12015 + _ASM_EXTABLE(0b, 0b)
12016 +#endif
12017 +
12018 /* subtracts 1, returns the old value */
12019 " jns 1f\n\t"
12020 " call call_rwsem_wake\n" /* expects old value in %edx */
12021 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12022 long tmp;
12023 asm volatile("# beginning __up_write\n\t"
12024 LOCK_PREFIX " xadd %1,(%2)\n\t"
12025 +
12026 +#ifdef CONFIG_PAX_REFCOUNT
12027 + "jno 0f\n"
12028 + "mov %1,(%2)\n"
12029 + "int $4\n0:\n"
12030 + _ASM_EXTABLE(0b, 0b)
12031 +#endif
12032 +
12033 /* subtracts 0xffff0001, returns the old value */
12034 " jns 1f\n\t"
12035 " call call_rwsem_wake\n" /* expects old value in %edx */
12036 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12037 {
12038 asm volatile("# beginning __downgrade_write\n\t"
12039 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12040 +
12041 +#ifdef CONFIG_PAX_REFCOUNT
12042 + "jno 0f\n"
12043 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12044 + "int $4\n0:\n"
12045 + _ASM_EXTABLE(0b, 0b)
12046 +#endif
12047 +
12048 /*
12049 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12050 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12051 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12052 */
12053 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12054 {
12055 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12056 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12057 +
12058 +#ifdef CONFIG_PAX_REFCOUNT
12059 + "jno 0f\n"
12060 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12061 + "int $4\n0:\n"
12062 + _ASM_EXTABLE(0b, 0b)
12063 +#endif
12064 +
12065 : "+m" (sem->count)
12066 : "er" (delta));
12067 }
12068 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12069 */
12070 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12071 {
12072 - return delta + xadd(&sem->count, delta);
12073 + return delta + xadd_check_overflow(&sem->count, delta);
12074 }
12075
12076 #endif /* __KERNEL__ */
12077 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12078 index c48a950..c6d7468 100644
12079 --- a/arch/x86/include/asm/segment.h
12080 +++ b/arch/x86/include/asm/segment.h
12081 @@ -64,10 +64,15 @@
12082 * 26 - ESPFIX small SS
12083 * 27 - per-cpu [ offset to per-cpu data area ]
12084 * 28 - stack_canary-20 [ for stack protector ]
12085 - * 29 - unused
12086 - * 30 - unused
12087 + * 29 - PCI BIOS CS
12088 + * 30 - PCI BIOS DS
12089 * 31 - TSS for double fault handler
12090 */
12091 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12092 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12093 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12094 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12095 +
12096 #define GDT_ENTRY_TLS_MIN 6
12097 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12098
12099 @@ -79,6 +84,8 @@
12100
12101 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12102
12103 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12104 +
12105 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12106
12107 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12108 @@ -104,6 +111,12 @@
12109 #define __KERNEL_STACK_CANARY 0
12110 #endif
12111
12112 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12113 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12114 +
12115 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12116 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12117 +
12118 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12119
12120 /*
12121 @@ -141,7 +154,7 @@
12122 */
12123
12124 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12125 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12126 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12127
12128
12129 #else
12130 @@ -165,6 +178,8 @@
12131 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12132 #define __USER32_DS __USER_DS
12133
12134 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12135 +
12136 #define GDT_ENTRY_TSS 8 /* needs two entries */
12137 #define GDT_ENTRY_LDT 10 /* needs two entries */
12138 #define GDT_ENTRY_TLS_MIN 12
12139 @@ -185,6 +200,7 @@
12140 #endif
12141
12142 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12143 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12144 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12145 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12146 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12147 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12148 {
12149 unsigned long __limit;
12150 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12151 - return __limit + 1;
12152 + return __limit;
12153 }
12154
12155 #endif /* !__ASSEMBLY__ */
12156 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12157 index f483945..64a7851 100644
12158 --- a/arch/x86/include/asm/smp.h
12159 +++ b/arch/x86/include/asm/smp.h
12160 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12161 /* cpus sharing the last level cache: */
12162 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12163 DECLARE_PER_CPU(u16, cpu_llc_id);
12164 -DECLARE_PER_CPU(int, cpu_number);
12165 +DECLARE_PER_CPU(unsigned int, cpu_number);
12166
12167 static inline struct cpumask *cpu_sibling_mask(int cpu)
12168 {
12169 @@ -79,7 +79,7 @@ struct smp_ops {
12170
12171 void (*send_call_func_ipi)(const struct cpumask *mask);
12172 void (*send_call_func_single_ipi)(int cpu);
12173 -};
12174 +} __no_const;
12175
12176 /* Globals due to paravirt */
12177 extern void set_cpu_sibling_map(int cpu);
12178 @@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12179 extern int safe_smp_processor_id(void);
12180
12181 #elif defined(CONFIG_X86_64_SMP)
12182 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12183 -
12184 -#define stack_smp_processor_id() \
12185 -({ \
12186 - struct thread_info *ti; \
12187 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12188 - ti->cpu; \
12189 -})
12190 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12191 +#define stack_smp_processor_id() raw_smp_processor_id()
12192 #define safe_smp_processor_id() smp_processor_id()
12193
12194 #endif
12195 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12196 index b315a33..8849ab0 100644
12197 --- a/arch/x86/include/asm/spinlock.h
12198 +++ b/arch/x86/include/asm/spinlock.h
12199 @@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12200 static inline void arch_read_lock(arch_rwlock_t *rw)
12201 {
12202 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12203 +
12204 +#ifdef CONFIG_PAX_REFCOUNT
12205 + "jno 0f\n"
12206 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12207 + "int $4\n0:\n"
12208 + _ASM_EXTABLE(0b, 0b)
12209 +#endif
12210 +
12211 "jns 1f\n"
12212 "call __read_lock_failed\n\t"
12213 "1:\n"
12214 @@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12215 static inline void arch_write_lock(arch_rwlock_t *rw)
12216 {
12217 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12218 +
12219 +#ifdef CONFIG_PAX_REFCOUNT
12220 + "jno 0f\n"
12221 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12222 + "int $4\n0:\n"
12223 + _ASM_EXTABLE(0b, 0b)
12224 +#endif
12225 +
12226 "jz 1f\n"
12227 "call __write_lock_failed\n\t"
12228 "1:\n"
12229 @@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12230
12231 static inline void arch_read_unlock(arch_rwlock_t *rw)
12232 {
12233 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12234 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12235 +
12236 +#ifdef CONFIG_PAX_REFCOUNT
12237 + "jno 0f\n"
12238 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12239 + "int $4\n0:\n"
12240 + _ASM_EXTABLE(0b, 0b)
12241 +#endif
12242 +
12243 :"+m" (rw->lock) : : "memory");
12244 }
12245
12246 static inline void arch_write_unlock(arch_rwlock_t *rw)
12247 {
12248 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12249 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12250 +
12251 +#ifdef CONFIG_PAX_REFCOUNT
12252 + "jno 0f\n"
12253 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12254 + "int $4\n0:\n"
12255 + _ASM_EXTABLE(0b, 0b)
12256 +#endif
12257 +
12258 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12259 }
12260
12261 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12262 index 6a99859..03cb807 100644
12263 --- a/arch/x86/include/asm/stackprotector.h
12264 +++ b/arch/x86/include/asm/stackprotector.h
12265 @@ -47,7 +47,7 @@
12266 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12267 */
12268 #define GDT_STACK_CANARY_INIT \
12269 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12270 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12271
12272 /*
12273 * Initialize the stackprotector canary value.
12274 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12275
12276 static inline void load_stack_canary_segment(void)
12277 {
12278 -#ifdef CONFIG_X86_32
12279 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12280 asm volatile ("mov %0, %%gs" : : "r" (0));
12281 #endif
12282 }
12283 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12284 index 70bbe39..4ae2bd4 100644
12285 --- a/arch/x86/include/asm/stacktrace.h
12286 +++ b/arch/x86/include/asm/stacktrace.h
12287 @@ -11,28 +11,20 @@
12288
12289 extern int kstack_depth_to_print;
12290
12291 -struct thread_info;
12292 +struct task_struct;
12293 struct stacktrace_ops;
12294
12295 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12296 - unsigned long *stack,
12297 - unsigned long bp,
12298 - const struct stacktrace_ops *ops,
12299 - void *data,
12300 - unsigned long *end,
12301 - int *graph);
12302 +typedef unsigned long walk_stack_t(struct task_struct *task,
12303 + void *stack_start,
12304 + unsigned long *stack,
12305 + unsigned long bp,
12306 + const struct stacktrace_ops *ops,
12307 + void *data,
12308 + unsigned long *end,
12309 + int *graph);
12310
12311 -extern unsigned long
12312 -print_context_stack(struct thread_info *tinfo,
12313 - unsigned long *stack, unsigned long bp,
12314 - const struct stacktrace_ops *ops, void *data,
12315 - unsigned long *end, int *graph);
12316 -
12317 -extern unsigned long
12318 -print_context_stack_bp(struct thread_info *tinfo,
12319 - unsigned long *stack, unsigned long bp,
12320 - const struct stacktrace_ops *ops, void *data,
12321 - unsigned long *end, int *graph);
12322 +extern walk_stack_t print_context_stack;
12323 +extern walk_stack_t print_context_stack_bp;
12324
12325 /* Generic stack tracer with callbacks */
12326
12327 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12328 void (*address)(void *data, unsigned long address, int reliable);
12329 /* On negative return stop dumping */
12330 int (*stack)(void *data, char *name);
12331 - walk_stack_t walk_stack;
12332 + walk_stack_t *walk_stack;
12333 };
12334
12335 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12336 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12337 index 4ec45b3..a4f0a8a 100644
12338 --- a/arch/x86/include/asm/switch_to.h
12339 +++ b/arch/x86/include/asm/switch_to.h
12340 @@ -108,7 +108,7 @@ do { \
12341 "call __switch_to\n\t" \
12342 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12343 __switch_canary \
12344 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12345 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12346 "movq %%rax,%%rdi\n\t" \
12347 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12348 "jnz ret_from_fork\n\t" \
12349 @@ -119,7 +119,7 @@ do { \
12350 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12351 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12352 [_tif_fork] "i" (_TIF_FORK), \
12353 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12354 + [thread_info] "m" (current_tinfo), \
12355 [current_task] "m" (current_task) \
12356 __switch_canary_iparam \
12357 : "memory", "cc" __EXTRA_CLOBBER)
12358 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12359 index 3fda9db4..4ca1c61 100644
12360 --- a/arch/x86/include/asm/sys_ia32.h
12361 +++ b/arch/x86/include/asm/sys_ia32.h
12362 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12363 struct old_sigaction32 __user *);
12364 asmlinkage long sys32_alarm(unsigned int);
12365
12366 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12367 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12368 asmlinkage long sys32_sysfs(int, u32, u32);
12369
12370 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12371 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12372 index 89f794f..1422765 100644
12373 --- a/arch/x86/include/asm/thread_info.h
12374 +++ b/arch/x86/include/asm/thread_info.h
12375 @@ -10,6 +10,7 @@
12376 #include <linux/compiler.h>
12377 #include <asm/page.h>
12378 #include <asm/types.h>
12379 +#include <asm/percpu.h>
12380
12381 /*
12382 * low level task data that entry.S needs immediate access to
12383 @@ -24,7 +25,6 @@ struct exec_domain;
12384 #include <linux/atomic.h>
12385
12386 struct thread_info {
12387 - struct task_struct *task; /* main task structure */
12388 struct exec_domain *exec_domain; /* execution domain */
12389 __u32 flags; /* low level flags */
12390 __u32 status; /* thread synchronous flags */
12391 @@ -34,19 +34,13 @@ struct thread_info {
12392 mm_segment_t addr_limit;
12393 struct restart_block restart_block;
12394 void __user *sysenter_return;
12395 -#ifdef CONFIG_X86_32
12396 - unsigned long previous_esp; /* ESP of the previous stack in
12397 - case of nested (IRQ) stacks
12398 - */
12399 - __u8 supervisor_stack[0];
12400 -#endif
12401 + unsigned long lowest_stack;
12402 unsigned int sig_on_uaccess_error:1;
12403 unsigned int uaccess_err:1; /* uaccess failed */
12404 };
12405
12406 -#define INIT_THREAD_INFO(tsk) \
12407 +#define INIT_THREAD_INFO \
12408 { \
12409 - .task = &tsk, \
12410 .exec_domain = &default_exec_domain, \
12411 .flags = 0, \
12412 .cpu = 0, \
12413 @@ -57,7 +51,7 @@ struct thread_info {
12414 }, \
12415 }
12416
12417 -#define init_thread_info (init_thread_union.thread_info)
12418 +#define init_thread_info (init_thread_union.stack)
12419 #define init_stack (init_thread_union.stack)
12420
12421 #else /* !__ASSEMBLY__ */
12422 @@ -98,6 +92,7 @@ struct thread_info {
12423 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12424 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12425 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12426 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12427
12428 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12429 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12430 @@ -122,16 +117,18 @@ struct thread_info {
12431 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12432 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12433 #define _TIF_X32 (1 << TIF_X32)
12434 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12435
12436 /* work to do in syscall_trace_enter() */
12437 #define _TIF_WORK_SYSCALL_ENTRY \
12438 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12439 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12440 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12441 + _TIF_GRSEC_SETXID)
12442
12443 /* work to do in syscall_trace_leave() */
12444 #define _TIF_WORK_SYSCALL_EXIT \
12445 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12446 - _TIF_SYSCALL_TRACEPOINT)
12447 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12448
12449 /* work to do on interrupt/exception return */
12450 #define _TIF_WORK_MASK \
12451 @@ -141,7 +138,8 @@ struct thread_info {
12452
12453 /* work to do on any return to user space */
12454 #define _TIF_ALLWORK_MASK \
12455 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12456 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12457 + _TIF_GRSEC_SETXID)
12458
12459 /* Only used for 64 bit */
12460 #define _TIF_DO_NOTIFY_MASK \
12461 @@ -157,45 +155,40 @@ struct thread_info {
12462
12463 #define PREEMPT_ACTIVE 0x10000000
12464
12465 -#ifdef CONFIG_X86_32
12466 -
12467 -#define STACK_WARN (THREAD_SIZE/8)
12468 -/*
12469 - * macros/functions for gaining access to the thread information structure
12470 - *
12471 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12472 - */
12473 -#ifndef __ASSEMBLY__
12474 -
12475 -
12476 -/* how to get the current stack pointer from C */
12477 -register unsigned long current_stack_pointer asm("esp") __used;
12478 -
12479 -/* how to get the thread information struct from C */
12480 -static inline struct thread_info *current_thread_info(void)
12481 -{
12482 - return (struct thread_info *)
12483 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12484 -}
12485 -
12486 -#else /* !__ASSEMBLY__ */
12487 -
12488 +#ifdef __ASSEMBLY__
12489 /* how to get the thread information struct from ASM */
12490 #define GET_THREAD_INFO(reg) \
12491 - movl $-THREAD_SIZE, reg; \
12492 - andl %esp, reg
12493 + mov PER_CPU_VAR(current_tinfo), reg
12494
12495 /* use this one if reg already contains %esp */
12496 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12497 - andl $-THREAD_SIZE, reg
12498 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12499 +#else
12500 +/* how to get the thread information struct from C */
12501 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12502 +
12503 +static __always_inline struct thread_info *current_thread_info(void)
12504 +{
12505 + return this_cpu_read_stable(current_tinfo);
12506 +}
12507 +#endif
12508 +
12509 +#ifdef CONFIG_X86_32
12510 +
12511 +#define STACK_WARN (THREAD_SIZE/8)
12512 +/*
12513 + * macros/functions for gaining access to the thread information structure
12514 + *
12515 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12516 + */
12517 +#ifndef __ASSEMBLY__
12518 +
12519 +/* how to get the current stack pointer from C */
12520 +register unsigned long current_stack_pointer asm("esp") __used;
12521
12522 #endif
12523
12524 #else /* X86_32 */
12525
12526 -#include <asm/percpu.h>
12527 -#define KERNEL_STACK_OFFSET (5*8)
12528 -
12529 /*
12530 * macros/functions for gaining access to the thread information structure
12531 * preempt_count needs to be 1 initially, until the scheduler is functional.
12532 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12533 #ifndef __ASSEMBLY__
12534 DECLARE_PER_CPU(unsigned long, kernel_stack);
12535
12536 -static inline struct thread_info *current_thread_info(void)
12537 -{
12538 - struct thread_info *ti;
12539 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12540 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12541 - return ti;
12542 -}
12543 -
12544 -#else /* !__ASSEMBLY__ */
12545 -
12546 -/* how to get the thread information struct from ASM */
12547 -#define GET_THREAD_INFO(reg) \
12548 - movq PER_CPU_VAR(kernel_stack),reg ; \
12549 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12550 -
12551 -/*
12552 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12553 - * a certain register (to be used in assembler memory operands).
12554 - */
12555 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12556 -
12557 +/* how to get the current stack pointer from C */
12558 +register unsigned long current_stack_pointer asm("rsp") __used;
12559 #endif
12560
12561 #endif /* !X86_32 */
12562 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12563 extern void arch_task_cache_init(void);
12564 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12565 extern void arch_release_task_struct(struct task_struct *tsk);
12566 +
12567 +#define __HAVE_THREAD_FUNCTIONS
12568 +#define task_thread_info(task) (&(task)->tinfo)
12569 +#define task_stack_page(task) ((task)->stack)
12570 +#define setup_thread_stack(p, org) do {} while (0)
12571 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12572 +
12573 #endif
12574 #endif /* _ASM_X86_THREAD_INFO_H */
12575 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12576 index e1f3a17..1ab364d 100644
12577 --- a/arch/x86/include/asm/uaccess.h
12578 +++ b/arch/x86/include/asm/uaccess.h
12579 @@ -7,12 +7,15 @@
12580 #include <linux/compiler.h>
12581 #include <linux/thread_info.h>
12582 #include <linux/string.h>
12583 +#include <linux/sched.h>
12584 #include <asm/asm.h>
12585 #include <asm/page.h>
12586
12587 #define VERIFY_READ 0
12588 #define VERIFY_WRITE 1
12589
12590 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12591 +
12592 /*
12593 * The fs value determines whether argument validity checking should be
12594 * performed or not. If get_fs() == USER_DS, checking is performed, with
12595 @@ -28,7 +31,12 @@
12596
12597 #define get_ds() (KERNEL_DS)
12598 #define get_fs() (current_thread_info()->addr_limit)
12599 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12600 +void __set_fs(mm_segment_t x);
12601 +void set_fs(mm_segment_t x);
12602 +#else
12603 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12604 +#endif
12605
12606 #define segment_eq(a, b) ((a).seg == (b).seg)
12607
12608 @@ -76,8 +84,33 @@
12609 * checks that the pointer is in the user space range - after calling
12610 * this function, memory access functions may still return -EFAULT.
12611 */
12612 -#define access_ok(type, addr, size) \
12613 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12614 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12615 +#define access_ok(type, addr, size) \
12616 +({ \
12617 + long __size = size; \
12618 + unsigned long __addr = (unsigned long)addr; \
12619 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12620 + unsigned long __end_ao = __addr + __size - 1; \
12621 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12622 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12623 + while(__addr_ao <= __end_ao) { \
12624 + char __c_ao; \
12625 + __addr_ao += PAGE_SIZE; \
12626 + if (__size > PAGE_SIZE) \
12627 + cond_resched(); \
12628 + if (__get_user(__c_ao, (char __user *)__addr)) \
12629 + break; \
12630 + if (type != VERIFY_WRITE) { \
12631 + __addr = __addr_ao; \
12632 + continue; \
12633 + } \
12634 + if (__put_user(__c_ao, (char __user *)__addr)) \
12635 + break; \
12636 + __addr = __addr_ao; \
12637 + } \
12638 + } \
12639 + __ret_ao; \
12640 +})
12641
12642 /*
12643 * The exception table consists of pairs of addresses relative to the
12644 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12645 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12646 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12647
12648 -
12649 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12650 +#define __copyuser_seg "gs;"
12651 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12652 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12653 +#else
12654 +#define __copyuser_seg
12655 +#define __COPYUSER_SET_ES
12656 +#define __COPYUSER_RESTORE_ES
12657 +#endif
12658
12659 #ifdef CONFIG_X86_32
12660 #define __put_user_asm_u64(x, addr, err, errret) \
12661 - asm volatile("1: movl %%eax,0(%2)\n" \
12662 - "2: movl %%edx,4(%2)\n" \
12663 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12664 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12665 "3:\n" \
12666 ".section .fixup,\"ax\"\n" \
12667 "4: movl %3,%0\n" \
12668 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12669 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12670
12671 #define __put_user_asm_ex_u64(x, addr) \
12672 - asm volatile("1: movl %%eax,0(%1)\n" \
12673 - "2: movl %%edx,4(%1)\n" \
12674 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12675 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12676 "3:\n" \
12677 _ASM_EXTABLE_EX(1b, 2b) \
12678 _ASM_EXTABLE_EX(2b, 3b) \
12679 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12680 __typeof__(*(ptr)) __pu_val; \
12681 __chk_user_ptr(ptr); \
12682 might_fault(); \
12683 - __pu_val = x; \
12684 + __pu_val = (x); \
12685 switch (sizeof(*(ptr))) { \
12686 case 1: \
12687 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12688 @@ -379,7 +420,7 @@ do { \
12689 } while (0)
12690
12691 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12692 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12693 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12694 "2:\n" \
12695 ".section .fixup,\"ax\"\n" \
12696 "3: mov %3,%0\n" \
12697 @@ -387,7 +428,7 @@ do { \
12698 " jmp 2b\n" \
12699 ".previous\n" \
12700 _ASM_EXTABLE(1b, 3b) \
12701 - : "=r" (err), ltype(x) \
12702 + : "=r" (err), ltype (x) \
12703 : "m" (__m(addr)), "i" (errret), "0" (err))
12704
12705 #define __get_user_size_ex(x, ptr, size) \
12706 @@ -412,7 +453,7 @@ do { \
12707 } while (0)
12708
12709 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12710 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12711 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12712 "2:\n" \
12713 _ASM_EXTABLE_EX(1b, 2b) \
12714 : ltype(x) : "m" (__m(addr)))
12715 @@ -429,13 +470,24 @@ do { \
12716 int __gu_err; \
12717 unsigned long __gu_val; \
12718 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12719 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12720 + (x) = (__typeof__(*(ptr)))__gu_val; \
12721 __gu_err; \
12722 })
12723
12724 /* FIXME: this hack is definitely wrong -AK */
12725 struct __large_struct { unsigned long buf[100]; };
12726 -#define __m(x) (*(struct __large_struct __user *)(x))
12727 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12728 +#define ____m(x) \
12729 +({ \
12730 + unsigned long ____x = (unsigned long)(x); \
12731 + if (____x < PAX_USER_SHADOW_BASE) \
12732 + ____x += PAX_USER_SHADOW_BASE; \
12733 + (void __user *)____x; \
12734 +})
12735 +#else
12736 +#define ____m(x) (x)
12737 +#endif
12738 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12739
12740 /*
12741 * Tell gcc we read from memory instead of writing: this is because
12742 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12743 * aliasing issues.
12744 */
12745 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12746 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12747 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12748 "2:\n" \
12749 ".section .fixup,\"ax\"\n" \
12750 "3: mov %3,%0\n" \
12751 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12752 ".previous\n" \
12753 _ASM_EXTABLE(1b, 3b) \
12754 : "=r"(err) \
12755 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12756 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12757
12758 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12759 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12760 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12761 "2:\n" \
12762 _ASM_EXTABLE_EX(1b, 2b) \
12763 : : ltype(x), "m" (__m(addr)))
12764 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12765 * On error, the variable @x is set to zero.
12766 */
12767
12768 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12769 +#define __get_user(x, ptr) get_user((x), (ptr))
12770 +#else
12771 #define __get_user(x, ptr) \
12772 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12773 +#endif
12774
12775 /**
12776 * __put_user: - Write a simple value into user space, with less checking.
12777 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12778 * Returns zero on success, or -EFAULT on error.
12779 */
12780
12781 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12782 +#define __put_user(x, ptr) put_user((x), (ptr))
12783 +#else
12784 #define __put_user(x, ptr) \
12785 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12786 +#endif
12787
12788 #define __get_user_unaligned __get_user
12789 #define __put_user_unaligned __put_user
12790 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12791 #define get_user_ex(x, ptr) do { \
12792 unsigned long __gue_val; \
12793 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12794 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12795 + (x) = (__typeof__(*(ptr)))__gue_val; \
12796 } while (0)
12797
12798 #ifdef CONFIG_X86_WP_WORKS_OK
12799 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12800 index 576e39b..ccd0a39 100644
12801 --- a/arch/x86/include/asm/uaccess_32.h
12802 +++ b/arch/x86/include/asm/uaccess_32.h
12803 @@ -11,15 +11,15 @@
12804 #include <asm/page.h>
12805
12806 unsigned long __must_check __copy_to_user_ll
12807 - (void __user *to, const void *from, unsigned long n);
12808 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12809 unsigned long __must_check __copy_from_user_ll
12810 - (void *to, const void __user *from, unsigned long n);
12811 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12812 unsigned long __must_check __copy_from_user_ll_nozero
12813 - (void *to, const void __user *from, unsigned long n);
12814 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12815 unsigned long __must_check __copy_from_user_ll_nocache
12816 - (void *to, const void __user *from, unsigned long n);
12817 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12818 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12819 - (void *to, const void __user *from, unsigned long n);
12820 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12821
12822 /**
12823 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12824 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12825 static __always_inline unsigned long __must_check
12826 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12827 {
12828 + if ((long)n < 0)
12829 + return n;
12830 +
12831 if (__builtin_constant_p(n)) {
12832 unsigned long ret;
12833
12834 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12835 return ret;
12836 }
12837 }
12838 + if (!__builtin_constant_p(n))
12839 + check_object_size(from, n, true);
12840 return __copy_to_user_ll(to, from, n);
12841 }
12842
12843 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12844 __copy_to_user(void __user *to, const void *from, unsigned long n)
12845 {
12846 might_fault();
12847 +
12848 return __copy_to_user_inatomic(to, from, n);
12849 }
12850
12851 static __always_inline unsigned long
12852 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12853 {
12854 + if ((long)n < 0)
12855 + return n;
12856 +
12857 /* Avoid zeroing the tail if the copy fails..
12858 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12859 * but as the zeroing behaviour is only significant when n is not
12860 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12861 __copy_from_user(void *to, const void __user *from, unsigned long n)
12862 {
12863 might_fault();
12864 +
12865 + if ((long)n < 0)
12866 + return n;
12867 +
12868 if (__builtin_constant_p(n)) {
12869 unsigned long ret;
12870
12871 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12872 return ret;
12873 }
12874 }
12875 + if (!__builtin_constant_p(n))
12876 + check_object_size(to, n, false);
12877 return __copy_from_user_ll(to, from, n);
12878 }
12879
12880 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12881 const void __user *from, unsigned long n)
12882 {
12883 might_fault();
12884 +
12885 + if ((long)n < 0)
12886 + return n;
12887 +
12888 if (__builtin_constant_p(n)) {
12889 unsigned long ret;
12890
12891 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12892 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12893 unsigned long n)
12894 {
12895 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12896 + if ((long)n < 0)
12897 + return n;
12898 +
12899 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12900 }
12901
12902 -unsigned long __must_check copy_to_user(void __user *to,
12903 - const void *from, unsigned long n);
12904 -unsigned long __must_check _copy_from_user(void *to,
12905 - const void __user *from,
12906 - unsigned long n);
12907 -
12908 +extern void copy_to_user_overflow(void)
12909 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12910 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12911 +#else
12912 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12913 +#endif
12914 +;
12915
12916 extern void copy_from_user_overflow(void)
12917 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12918 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12919 #endif
12920 ;
12921
12922 -static inline unsigned long __must_check copy_from_user(void *to,
12923 - const void __user *from,
12924 - unsigned long n)
12925 +/**
12926 + * copy_to_user: - Copy a block of data into user space.
12927 + * @to: Destination address, in user space.
12928 + * @from: Source address, in kernel space.
12929 + * @n: Number of bytes to copy.
12930 + *
12931 + * Context: User context only. This function may sleep.
12932 + *
12933 + * Copy data from kernel space to user space.
12934 + *
12935 + * Returns number of bytes that could not be copied.
12936 + * On success, this will be zero.
12937 + */
12938 +static inline unsigned long __must_check
12939 +copy_to_user(void __user *to, const void *from, unsigned long n)
12940 {
12941 - int sz = __compiletime_object_size(to);
12942 + size_t sz = __compiletime_object_size(from);
12943
12944 - if (likely(sz == -1 || sz >= n))
12945 - n = _copy_from_user(to, from, n);
12946 - else
12947 + if (unlikely(sz != (size_t)-1 && sz < n))
12948 + copy_to_user_overflow();
12949 + else if (access_ok(VERIFY_WRITE, to, n))
12950 + n = __copy_to_user(to, from, n);
12951 + return n;
12952 +}
12953 +
12954 +/**
12955 + * copy_from_user: - Copy a block of data from user space.
12956 + * @to: Destination address, in kernel space.
12957 + * @from: Source address, in user space.
12958 + * @n: Number of bytes to copy.
12959 + *
12960 + * Context: User context only. This function may sleep.
12961 + *
12962 + * Copy data from user space to kernel space.
12963 + *
12964 + * Returns number of bytes that could not be copied.
12965 + * On success, this will be zero.
12966 + *
12967 + * If some data could not be copied, this function will pad the copied
12968 + * data to the requested size using zero bytes.
12969 + */
12970 +static inline unsigned long __must_check
12971 +copy_from_user(void *to, const void __user *from, unsigned long n)
12972 +{
12973 + size_t sz = __compiletime_object_size(to);
12974 +
12975 + if (unlikely(sz != (size_t)-1 && sz < n))
12976 copy_from_user_overflow();
12977 -
12978 + else if (access_ok(VERIFY_READ, from, n))
12979 + n = __copy_from_user(to, from, n);
12980 + else if ((long)n > 0) {
12981 + if (!__builtin_constant_p(n))
12982 + check_object_size(to, n, false);
12983 + memset(to, 0, n);
12984 + }
12985 return n;
12986 }
12987
12988 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12989 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12990 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12991 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12992
12993 #endif /* _ASM_X86_UACCESS_32_H */
12994 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12995 index 8e796fb..72fd934 100644
12996 --- a/arch/x86/include/asm/uaccess_64.h
12997 +++ b/arch/x86/include/asm/uaccess_64.h
12998 @@ -10,6 +10,9 @@
12999 #include <asm/alternative.h>
13000 #include <asm/cpufeature.h>
13001 #include <asm/page.h>
13002 +#include <asm/pgtable.h>
13003 +
13004 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13005
13006 /*
13007 * Copy To/From Userspace
13008 @@ -17,12 +20,14 @@
13009
13010 /* Handles exceptions in both to and from, but doesn't do access_ok */
13011 __must_check unsigned long
13012 -copy_user_generic_string(void *to, const void *from, unsigned len);
13013 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13014 __must_check unsigned long
13015 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13016 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13017
13018 static __always_inline __must_check unsigned long
13019 -copy_user_generic(void *to, const void *from, unsigned len)
13020 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13021 +static __always_inline __must_check unsigned long
13022 +copy_user_generic(void *to, const void *from, unsigned long len)
13023 {
13024 unsigned ret;
13025
13026 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13027 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13028 "=d" (len)),
13029 "1" (to), "2" (from), "3" (len)
13030 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13031 + : "memory", "rcx", "r8", "r9", "r11");
13032 return ret;
13033 }
13034
13035 +static __always_inline __must_check unsigned long
13036 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13037 +static __always_inline __must_check unsigned long
13038 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13039 __must_check unsigned long
13040 -_copy_to_user(void __user *to, const void *from, unsigned len);
13041 -__must_check unsigned long
13042 -_copy_from_user(void *to, const void __user *from, unsigned len);
13043 -__must_check unsigned long
13044 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13045 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13046 +
13047 +extern void copy_to_user_overflow(void)
13048 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13049 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13050 +#else
13051 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13052 +#endif
13053 +;
13054 +
13055 +extern void copy_from_user_overflow(void)
13056 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13057 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13058 +#else
13059 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13060 +#endif
13061 +;
13062
13063 static inline unsigned long __must_check copy_from_user(void *to,
13064 const void __user *from,
13065 unsigned long n)
13066 {
13067 - int sz = __compiletime_object_size(to);
13068 -
13069 might_fault();
13070 - if (likely(sz == -1 || sz >= n))
13071 - n = _copy_from_user(to, from, n);
13072 -#ifdef CONFIG_DEBUG_VM
13073 - else
13074 - WARN(1, "Buffer overflow detected!\n");
13075 -#endif
13076 +
13077 + if (access_ok(VERIFY_READ, from, n))
13078 + n = __copy_from_user(to, from, n);
13079 + else if (n < INT_MAX) {
13080 + if (!__builtin_constant_p(n))
13081 + check_object_size(to, n, false);
13082 + memset(to, 0, n);
13083 + }
13084 return n;
13085 }
13086
13087 static __always_inline __must_check
13088 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13089 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13090 {
13091 might_fault();
13092
13093 - return _copy_to_user(dst, src, size);
13094 + if (access_ok(VERIFY_WRITE, dst, size))
13095 + size = __copy_to_user(dst, src, size);
13096 + return size;
13097 }
13098
13099 static __always_inline __must_check
13100 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13101 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13102 {
13103 - int ret = 0;
13104 + size_t sz = __compiletime_object_size(dst);
13105 + unsigned ret = 0;
13106
13107 might_fault();
13108 - if (!__builtin_constant_p(size))
13109 - return copy_user_generic(dst, (__force void *)src, size);
13110 +
13111 + if (size > INT_MAX)
13112 + return size;
13113 +
13114 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13115 + if (!__access_ok(VERIFY_READ, src, size))
13116 + return size;
13117 +#endif
13118 +
13119 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13120 + copy_from_user_overflow();
13121 + return size;
13122 + }
13123 +
13124 + if (!__builtin_constant_p(size)) {
13125 + check_object_size(dst, size, false);
13126 +
13127 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13128 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13129 + src += PAX_USER_SHADOW_BASE;
13130 +#endif
13131 +
13132 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13133 + }
13134 switch (size) {
13135 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13136 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13137 ret, "b", "b", "=q", 1);
13138 return ret;
13139 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13140 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13141 ret, "w", "w", "=r", 2);
13142 return ret;
13143 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13144 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13145 ret, "l", "k", "=r", 4);
13146 return ret;
13147 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13148 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13149 ret, "q", "", "=r", 8);
13150 return ret;
13151 case 10:
13152 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13153 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13154 ret, "q", "", "=r", 10);
13155 if (unlikely(ret))
13156 return ret;
13157 __get_user_asm(*(u16 *)(8 + (char *)dst),
13158 - (u16 __user *)(8 + (char __user *)src),
13159 + (const u16 __user *)(8 + (const char __user *)src),
13160 ret, "w", "w", "=r", 2);
13161 return ret;
13162 case 16:
13163 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13164 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13165 ret, "q", "", "=r", 16);
13166 if (unlikely(ret))
13167 return ret;
13168 __get_user_asm(*(u64 *)(8 + (char *)dst),
13169 - (u64 __user *)(8 + (char __user *)src),
13170 + (const u64 __user *)(8 + (const char __user *)src),
13171 ret, "q", "", "=r", 8);
13172 return ret;
13173 default:
13174 - return copy_user_generic(dst, (__force void *)src, size);
13175 +
13176 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13177 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13178 + src += PAX_USER_SHADOW_BASE;
13179 +#endif
13180 +
13181 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13182 }
13183 }
13184
13185 static __always_inline __must_check
13186 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13187 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13188 {
13189 - int ret = 0;
13190 + size_t sz = __compiletime_object_size(src);
13191 + unsigned ret = 0;
13192
13193 might_fault();
13194 - if (!__builtin_constant_p(size))
13195 - return copy_user_generic((__force void *)dst, src, size);
13196 +
13197 + if (size > INT_MAX)
13198 + return size;
13199 +
13200 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13201 + if (!__access_ok(VERIFY_WRITE, dst, size))
13202 + return size;
13203 +#endif
13204 +
13205 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13206 + copy_to_user_overflow();
13207 + return size;
13208 + }
13209 +
13210 + if (!__builtin_constant_p(size)) {
13211 + check_object_size(src, size, true);
13212 +
13213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13214 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13215 + dst += PAX_USER_SHADOW_BASE;
13216 +#endif
13217 +
13218 + return copy_user_generic((__force_kernel void *)dst, src, size);
13219 + }
13220 switch (size) {
13221 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13222 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13223 ret, "b", "b", "iq", 1);
13224 return ret;
13225 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13226 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13227 ret, "w", "w", "ir", 2);
13228 return ret;
13229 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13230 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13231 ret, "l", "k", "ir", 4);
13232 return ret;
13233 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13234 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13235 ret, "q", "", "er", 8);
13236 return ret;
13237 case 10:
13238 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13239 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13240 ret, "q", "", "er", 10);
13241 if (unlikely(ret))
13242 return ret;
13243 asm("":::"memory");
13244 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13245 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13246 ret, "w", "w", "ir", 2);
13247 return ret;
13248 case 16:
13249 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13250 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13251 ret, "q", "", "er", 16);
13252 if (unlikely(ret))
13253 return ret;
13254 asm("":::"memory");
13255 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13256 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13257 ret, "q", "", "er", 8);
13258 return ret;
13259 default:
13260 - return copy_user_generic((__force void *)dst, src, size);
13261 +
13262 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13263 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13264 + dst += PAX_USER_SHADOW_BASE;
13265 +#endif
13266 +
13267 + return copy_user_generic((__force_kernel void *)dst, src, size);
13268 }
13269 }
13270
13271 static __always_inline __must_check
13272 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13273 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13274 {
13275 - int ret = 0;
13276 + unsigned ret = 0;
13277
13278 might_fault();
13279 - if (!__builtin_constant_p(size))
13280 - return copy_user_generic((__force void *)dst,
13281 - (__force void *)src, size);
13282 +
13283 + if (size > INT_MAX)
13284 + return size;
13285 +
13286 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13287 + if (!__access_ok(VERIFY_READ, src, size))
13288 + return size;
13289 + if (!__access_ok(VERIFY_WRITE, dst, size))
13290 + return size;
13291 +#endif
13292 +
13293 + if (!__builtin_constant_p(size)) {
13294 +
13295 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13296 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13297 + src += PAX_USER_SHADOW_BASE;
13298 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13299 + dst += PAX_USER_SHADOW_BASE;
13300 +#endif
13301 +
13302 + return copy_user_generic((__force_kernel void *)dst,
13303 + (__force_kernel const void *)src, size);
13304 + }
13305 switch (size) {
13306 case 1: {
13307 u8 tmp;
13308 - __get_user_asm(tmp, (u8 __user *)src,
13309 + __get_user_asm(tmp, (const u8 __user *)src,
13310 ret, "b", "b", "=q", 1);
13311 if (likely(!ret))
13312 __put_user_asm(tmp, (u8 __user *)dst,
13313 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13314 }
13315 case 2: {
13316 u16 tmp;
13317 - __get_user_asm(tmp, (u16 __user *)src,
13318 + __get_user_asm(tmp, (const u16 __user *)src,
13319 ret, "w", "w", "=r", 2);
13320 if (likely(!ret))
13321 __put_user_asm(tmp, (u16 __user *)dst,
13322 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13323
13324 case 4: {
13325 u32 tmp;
13326 - __get_user_asm(tmp, (u32 __user *)src,
13327 + __get_user_asm(tmp, (const u32 __user *)src,
13328 ret, "l", "k", "=r", 4);
13329 if (likely(!ret))
13330 __put_user_asm(tmp, (u32 __user *)dst,
13331 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13332 }
13333 case 8: {
13334 u64 tmp;
13335 - __get_user_asm(tmp, (u64 __user *)src,
13336 + __get_user_asm(tmp, (const u64 __user *)src,
13337 ret, "q", "", "=r", 8);
13338 if (likely(!ret))
13339 __put_user_asm(tmp, (u64 __user *)dst,
13340 @@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13341 return ret;
13342 }
13343 default:
13344 - return copy_user_generic((__force void *)dst,
13345 - (__force void *)src, size);
13346 +
13347 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13348 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13349 + src += PAX_USER_SHADOW_BASE;
13350 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13351 + dst += PAX_USER_SHADOW_BASE;
13352 +#endif
13353 +
13354 + return copy_user_generic((__force_kernel void *)dst,
13355 + (__force_kernel const void *)src, size);
13356 }
13357 }
13358
13359 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13360 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13361 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13362 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13363
13364 static __must_check __always_inline int
13365 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13366 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13367 {
13368 - return copy_user_generic(dst, (__force const void *)src, size);
13369 + if (size > INT_MAX)
13370 + return size;
13371 +
13372 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13373 + if (!__access_ok(VERIFY_READ, src, size))
13374 + return size;
13375 +
13376 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13377 + src += PAX_USER_SHADOW_BASE;
13378 +#endif
13379 +
13380 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13381 }
13382
13383 -static __must_check __always_inline int
13384 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13385 +static __must_check __always_inline unsigned long
13386 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13387 {
13388 - return copy_user_generic((__force void *)dst, src, size);
13389 + if (size > INT_MAX)
13390 + return size;
13391 +
13392 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13393 + if (!__access_ok(VERIFY_WRITE, dst, size))
13394 + return size;
13395 +
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, src, size);
13401 }
13402
13403 -extern long __copy_user_nocache(void *dst, const void __user *src,
13404 - unsigned size, int zerorest);
13405 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13406 + unsigned long size, int zerorest) __size_overflow(3);
13407
13408 -static inline int
13409 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13410 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13411 {
13412 might_sleep();
13413 +
13414 + if (size > INT_MAX)
13415 + return size;
13416 +
13417 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13418 + if (!__access_ok(VERIFY_READ, src, size))
13419 + return size;
13420 +#endif
13421 +
13422 return __copy_user_nocache(dst, src, size, 1);
13423 }
13424
13425 -static inline int
13426 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13427 - unsigned size)
13428 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13429 + unsigned long size)
13430 {
13431 + if (size > INT_MAX)
13432 + return size;
13433 +
13434 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13435 + if (!__access_ok(VERIFY_READ, src, size))
13436 + return size;
13437 +#endif
13438 +
13439 return __copy_user_nocache(dst, src, size, 0);
13440 }
13441
13442 -unsigned long
13443 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13444 +extern unsigned long
13445 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13446
13447 #endif /* _ASM_X86_UACCESS_64_H */
13448 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13449 index bb05228..d763d5b 100644
13450 --- a/arch/x86/include/asm/vdso.h
13451 +++ b/arch/x86/include/asm/vdso.h
13452 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13453 #define VDSO32_SYMBOL(base, name) \
13454 ({ \
13455 extern const char VDSO32_##name[]; \
13456 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13457 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13458 })
13459 #endif
13460
13461 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13462 index 5b238981..77fdd78 100644
13463 --- a/arch/x86/include/asm/word-at-a-time.h
13464 +++ b/arch/x86/include/asm/word-at-a-time.h
13465 @@ -11,7 +11,7 @@
13466 * and shift, for example.
13467 */
13468 struct word_at_a_time {
13469 - const unsigned long one_bits, high_bits;
13470 + unsigned long one_bits, high_bits;
13471 };
13472
13473 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13474 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13475 index c090af1..7e7bf16 100644
13476 --- a/arch/x86/include/asm/x86_init.h
13477 +++ b/arch/x86/include/asm/x86_init.h
13478 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13479 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13480 void (*find_smp_config)(void);
13481 void (*get_smp_config)(unsigned int early);
13482 -};
13483 +} __no_const;
13484
13485 /**
13486 * struct x86_init_resources - platform specific resource related ops
13487 @@ -43,7 +43,7 @@ struct x86_init_resources {
13488 void (*probe_roms)(void);
13489 void (*reserve_resources)(void);
13490 char *(*memory_setup)(void);
13491 -};
13492 +} __no_const;
13493
13494 /**
13495 * struct x86_init_irqs - platform specific interrupt setup
13496 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13497 void (*pre_vector_init)(void);
13498 void (*intr_init)(void);
13499 void (*trap_init)(void);
13500 -};
13501 +} __no_const;
13502
13503 /**
13504 * struct x86_init_oem - oem platform specific customizing functions
13505 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13506 struct x86_init_oem {
13507 void (*arch_setup)(void);
13508 void (*banner)(void);
13509 -};
13510 +} __no_const;
13511
13512 /**
13513 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13514 @@ -77,7 +77,7 @@ struct x86_init_oem {
13515 */
13516 struct x86_init_mapping {
13517 void (*pagetable_reserve)(u64 start, u64 end);
13518 -};
13519 +} __no_const;
13520
13521 /**
13522 * struct x86_init_paging - platform specific paging functions
13523 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13524 struct x86_init_paging {
13525 void (*pagetable_setup_start)(pgd_t *base);
13526 void (*pagetable_setup_done)(pgd_t *base);
13527 -};
13528 +} __no_const;
13529
13530 /**
13531 * struct x86_init_timers - platform specific timer setup
13532 @@ -102,7 +102,7 @@ struct x86_init_timers {
13533 void (*tsc_pre_init)(void);
13534 void (*timer_init)(void);
13535 void (*wallclock_init)(void);
13536 -};
13537 +} __no_const;
13538
13539 /**
13540 * struct x86_init_iommu - platform specific iommu setup
13541 @@ -110,7 +110,7 @@ struct x86_init_timers {
13542 */
13543 struct x86_init_iommu {
13544 int (*iommu_init)(void);
13545 -};
13546 +} __no_const;
13547
13548 /**
13549 * struct x86_init_pci - platform specific pci init functions
13550 @@ -124,7 +124,7 @@ struct x86_init_pci {
13551 int (*init)(void);
13552 void (*init_irq)(void);
13553 void (*fixup_irqs)(void);
13554 -};
13555 +} __no_const;
13556
13557 /**
13558 * struct x86_init_ops - functions for platform specific setup
13559 @@ -140,7 +140,7 @@ struct x86_init_ops {
13560 struct x86_init_timers timers;
13561 struct x86_init_iommu iommu;
13562 struct x86_init_pci pci;
13563 -};
13564 +} __no_const;
13565
13566 /**
13567 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13568 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13569 void (*setup_percpu_clockev)(void);
13570 void (*early_percpu_clock_init)(void);
13571 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13572 -};
13573 +} __no_const;
13574
13575 /**
13576 * struct x86_platform_ops - platform specific runtime functions
13577 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13578 int (*i8042_detect)(void);
13579 void (*save_sched_clock_state)(void);
13580 void (*restore_sched_clock_state)(void);
13581 -};
13582 +} __no_const;
13583
13584 struct pci_dev;
13585
13586 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13587 void (*teardown_msi_irq)(unsigned int irq);
13588 void (*teardown_msi_irqs)(struct pci_dev *dev);
13589 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13590 -};
13591 +} __no_const;
13592
13593 struct x86_io_apic_ops {
13594 void (*init) (void);
13595 unsigned int (*read) (unsigned int apic, unsigned int reg);
13596 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13597 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13598 -};
13599 +} __no_const;
13600
13601 extern struct x86_init_ops x86_init;
13602 extern struct x86_cpuinit_ops x86_cpuinit;
13603 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13604 index 8a1b6f9..a29c4e4 100644
13605 --- a/arch/x86/include/asm/xsave.h
13606 +++ b/arch/x86/include/asm/xsave.h
13607 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13608 {
13609 int err;
13610
13611 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13612 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13613 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13614 +#endif
13615 +
13616 /*
13617 * Clear the xsave header first, so that reserved fields are
13618 * initialized to zero.
13619 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13620 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13621 {
13622 int err;
13623 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13624 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13625 u32 lmask = mask;
13626 u32 hmask = mask >> 32;
13627
13628 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13629 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13630 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13631 +#endif
13632 +
13633 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13634 "2:\n"
13635 ".section .fixup,\"ax\"\n"
13636 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13637 index 95bf99de..de9235c 100644
13638 --- a/arch/x86/kernel/acpi/sleep.c
13639 +++ b/arch/x86/kernel/acpi/sleep.c
13640 @@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13641 #else /* CONFIG_64BIT */
13642 #ifdef CONFIG_SMP
13643 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13644 +
13645 + pax_open_kernel();
13646 early_gdt_descr.address =
13647 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13648 + pax_close_kernel();
13649 +
13650 initial_gs = per_cpu_offset(smp_processor_id());
13651 #endif
13652 initial_code = (unsigned long)wakeup_long64;
13653 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13654 index 7261083..5c12053 100644
13655 --- a/arch/x86/kernel/acpi/wakeup_32.S
13656 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13657 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13658 # and restore the stack ... but you need gdt for this to work
13659 movl saved_context_esp, %esp
13660
13661 - movl %cs:saved_magic, %eax
13662 - cmpl $0x12345678, %eax
13663 + cmpl $0x12345678, saved_magic
13664 jne bogus_magic
13665
13666 # jump to place where we left off
13667 - movl saved_eip, %eax
13668 - jmp *%eax
13669 + jmp *(saved_eip)
13670
13671 bogus_magic:
13672 jmp bogus_magic
13673 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13674 index 1f84794..e23f862 100644
13675 --- a/arch/x86/kernel/alternative.c
13676 +++ b/arch/x86/kernel/alternative.c
13677 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13678 */
13679 for (a = start; a < end; a++) {
13680 instr = (u8 *)&a->instr_offset + a->instr_offset;
13681 +
13682 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13683 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13684 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13685 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13686 +#endif
13687 +
13688 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13689 BUG_ON(a->replacementlen > a->instrlen);
13690 BUG_ON(a->instrlen > sizeof(insnbuf));
13691 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13692 for (poff = start; poff < end; poff++) {
13693 u8 *ptr = (u8 *)poff + *poff;
13694
13695 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13696 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13697 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13698 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13699 +#endif
13700 +
13701 if (!*poff || ptr < text || ptr >= text_end)
13702 continue;
13703 /* turn DS segment override prefix into lock prefix */
13704 - if (*ptr == 0x3e)
13705 + if (*ktla_ktva(ptr) == 0x3e)
13706 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13707 };
13708 mutex_unlock(&text_mutex);
13709 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13710 for (poff = start; poff < end; poff++) {
13711 u8 *ptr = (u8 *)poff + *poff;
13712
13713 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13714 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13715 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13716 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13717 +#endif
13718 +
13719 if (!*poff || ptr < text || ptr >= text_end)
13720 continue;
13721 /* turn lock prefix into DS segment override prefix */
13722 - if (*ptr == 0xf0)
13723 + if (*ktla_ktva(ptr) == 0xf0)
13724 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13725 };
13726 mutex_unlock(&text_mutex);
13727 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13728
13729 BUG_ON(p->len > MAX_PATCH_LEN);
13730 /* prep the buffer with the original instructions */
13731 - memcpy(insnbuf, p->instr, p->len);
13732 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13733 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13734 (unsigned long)p->instr, p->len);
13735
13736 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13737 if (smp_alt_once)
13738 free_init_pages("SMP alternatives",
13739 (unsigned long)__smp_locks,
13740 - (unsigned long)__smp_locks_end);
13741 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13742
13743 restart_nmi();
13744 }
13745 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13746 * instructions. And on the local CPU you need to be protected again NMI or MCE
13747 * handlers seeing an inconsistent instruction while you patch.
13748 */
13749 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13750 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13751 size_t len)
13752 {
13753 unsigned long flags;
13754 local_irq_save(flags);
13755 - memcpy(addr, opcode, len);
13756 +
13757 + pax_open_kernel();
13758 + memcpy(ktla_ktva(addr), opcode, len);
13759 sync_core();
13760 + pax_close_kernel();
13761 +
13762 local_irq_restore(flags);
13763 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13764 that causes hangs on some VIA CPUs. */
13765 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13766 */
13767 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13768 {
13769 - unsigned long flags;
13770 - char *vaddr;
13771 + unsigned char *vaddr = ktla_ktva(addr);
13772 struct page *pages[2];
13773 - int i;
13774 + size_t i;
13775
13776 if (!core_kernel_text((unsigned long)addr)) {
13777 - pages[0] = vmalloc_to_page(addr);
13778 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13779 + pages[0] = vmalloc_to_page(vaddr);
13780 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13781 } else {
13782 - pages[0] = virt_to_page(addr);
13783 + pages[0] = virt_to_page(vaddr);
13784 WARN_ON(!PageReserved(pages[0]));
13785 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13786 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13787 }
13788 BUG_ON(!pages[0]);
13789 - local_irq_save(flags);
13790 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13791 - if (pages[1])
13792 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13793 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13794 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13795 - clear_fixmap(FIX_TEXT_POKE0);
13796 - if (pages[1])
13797 - clear_fixmap(FIX_TEXT_POKE1);
13798 - local_flush_tlb();
13799 - sync_core();
13800 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13801 - that causes hangs on some VIA CPUs. */
13802 + text_poke_early(addr, opcode, len);
13803 for (i = 0; i < len; i++)
13804 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13805 - local_irq_restore(flags);
13806 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13807 return addr;
13808 }
13809
13810 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13811 index 39a222e..85a7767 100644
13812 --- a/arch/x86/kernel/apic/apic.c
13813 +++ b/arch/x86/kernel/apic/apic.c
13814 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13815 /*
13816 * Debug level, exported for io_apic.c
13817 */
13818 -unsigned int apic_verbosity;
13819 +int apic_verbosity;
13820
13821 int pic_mode;
13822
13823 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13824 apic_write(APIC_ESR, 0);
13825 v1 = apic_read(APIC_ESR);
13826 ack_APIC_irq();
13827 - atomic_inc(&irq_err_count);
13828 + atomic_inc_unchecked(&irq_err_count);
13829
13830 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13831 smp_processor_id(), v0 , v1);
13832 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13833 index 5f0ff59..f9e01bc 100644
13834 --- a/arch/x86/kernel/apic/io_apic.c
13835 +++ b/arch/x86/kernel/apic/io_apic.c
13836 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13837 }
13838 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13839
13840 -void lock_vector_lock(void)
13841 +void lock_vector_lock(void) __acquires(vector_lock)
13842 {
13843 /* Used to the online set of cpus does not change
13844 * during assign_irq_vector.
13845 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13846 raw_spin_lock(&vector_lock);
13847 }
13848
13849 -void unlock_vector_lock(void)
13850 +void unlock_vector_lock(void) __releases(vector_lock)
13851 {
13852 raw_spin_unlock(&vector_lock);
13853 }
13854 @@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13855 ack_APIC_irq();
13856 }
13857
13858 -atomic_t irq_mis_count;
13859 +atomic_unchecked_t irq_mis_count;
13860
13861 #ifdef CONFIG_GENERIC_PENDING_IRQ
13862 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13863 @@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13864 * at the cpu.
13865 */
13866 if (!(v & (1 << (i & 0x1f)))) {
13867 - atomic_inc(&irq_mis_count);
13868 + atomic_inc_unchecked(&irq_mis_count);
13869
13870 eoi_ioapic_irq(irq, cfg);
13871 }
13872 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13873 index 07b0c0d..1df6f42 100644
13874 --- a/arch/x86/kernel/apm_32.c
13875 +++ b/arch/x86/kernel/apm_32.c
13876 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13877 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13878 * even though they are called in protected mode.
13879 */
13880 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13881 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13882 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13883
13884 static const char driver_version[] = "1.16ac"; /* no spaces */
13885 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13886 BUG_ON(cpu != 0);
13887 gdt = get_cpu_gdt_table(cpu);
13888 save_desc_40 = gdt[0x40 / 8];
13889 +
13890 + pax_open_kernel();
13891 gdt[0x40 / 8] = bad_bios_desc;
13892 + pax_close_kernel();
13893
13894 apm_irq_save(flags);
13895 APM_DO_SAVE_SEGS;
13896 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13897 &call->esi);
13898 APM_DO_RESTORE_SEGS;
13899 apm_irq_restore(flags);
13900 +
13901 + pax_open_kernel();
13902 gdt[0x40 / 8] = save_desc_40;
13903 + pax_close_kernel();
13904 +
13905 put_cpu();
13906
13907 return call->eax & 0xff;
13908 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13909 BUG_ON(cpu != 0);
13910 gdt = get_cpu_gdt_table(cpu);
13911 save_desc_40 = gdt[0x40 / 8];
13912 +
13913 + pax_open_kernel();
13914 gdt[0x40 / 8] = bad_bios_desc;
13915 + pax_close_kernel();
13916
13917 apm_irq_save(flags);
13918 APM_DO_SAVE_SEGS;
13919 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13920 &call->eax);
13921 APM_DO_RESTORE_SEGS;
13922 apm_irq_restore(flags);
13923 +
13924 + pax_open_kernel();
13925 gdt[0x40 / 8] = save_desc_40;
13926 + pax_close_kernel();
13927 +
13928 put_cpu();
13929 return error;
13930 }
13931 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13932 * code to that CPU.
13933 */
13934 gdt = get_cpu_gdt_table(0);
13935 +
13936 + pax_open_kernel();
13937 set_desc_base(&gdt[APM_CS >> 3],
13938 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13939 set_desc_base(&gdt[APM_CS_16 >> 3],
13940 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13941 set_desc_base(&gdt[APM_DS >> 3],
13942 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13943 + pax_close_kernel();
13944
13945 proc_create("apm", 0, NULL, &apm_file_ops);
13946
13947 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13948 index 68de2dc..1f3c720 100644
13949 --- a/arch/x86/kernel/asm-offsets.c
13950 +++ b/arch/x86/kernel/asm-offsets.c
13951 @@ -33,6 +33,8 @@ void common(void) {
13952 OFFSET(TI_status, thread_info, status);
13953 OFFSET(TI_addr_limit, thread_info, addr_limit);
13954 OFFSET(TI_preempt_count, thread_info, preempt_count);
13955 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13956 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13957
13958 BLANK();
13959 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13960 @@ -53,8 +55,26 @@ void common(void) {
13961 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13962 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13963 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13964 +
13965 +#ifdef CONFIG_PAX_KERNEXEC
13966 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13967 #endif
13968
13969 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13970 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13971 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13972 +#ifdef CONFIG_X86_64
13973 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13974 +#endif
13975 +#endif
13976 +
13977 +#endif
13978 +
13979 + BLANK();
13980 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13981 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13982 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13983 +
13984 #ifdef CONFIG_XEN
13985 BLANK();
13986 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13987 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13988 index 1b4754f..fbb4227 100644
13989 --- a/arch/x86/kernel/asm-offsets_64.c
13990 +++ b/arch/x86/kernel/asm-offsets_64.c
13991 @@ -76,6 +76,7 @@ int main(void)
13992 BLANK();
13993 #undef ENTRY
13994
13995 + DEFINE(TSS_size, sizeof(struct tss_struct));
13996 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13997 BLANK();
13998
13999 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14000 index 6ab6aa2..8f71507 100644
14001 --- a/arch/x86/kernel/cpu/Makefile
14002 +++ b/arch/x86/kernel/cpu/Makefile
14003 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14004 CFLAGS_REMOVE_perf_event.o = -pg
14005 endif
14006
14007 -# Make sure load_percpu_segment has no stackprotector
14008 -nostackp := $(call cc-option, -fno-stack-protector)
14009 -CFLAGS_common.o := $(nostackp)
14010 -
14011 obj-y := intel_cacheinfo.o scattered.o topology.o
14012 obj-y += proc.o capflags.o powerflags.o common.o
14013 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14014 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14015 index 146bb62..ac9c74a 100644
14016 --- a/arch/x86/kernel/cpu/amd.c
14017 +++ b/arch/x86/kernel/cpu/amd.c
14018 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14019 unsigned int size)
14020 {
14021 /* AMD errata T13 (order #21922) */
14022 - if ((c->x86 == 6)) {
14023 + if (c->x86 == 6) {
14024 /* Duron Rev A0 */
14025 if (c->x86_model == 3 && c->x86_mask == 0)
14026 size = 64;
14027 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14028 index 6b9333b..4c3083a 100644
14029 --- a/arch/x86/kernel/cpu/common.c
14030 +++ b/arch/x86/kernel/cpu/common.c
14031 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14032
14033 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14034
14035 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14036 -#ifdef CONFIG_X86_64
14037 - /*
14038 - * We need valid kernel segments for data and code in long mode too
14039 - * IRET will check the segment types kkeil 2000/10/28
14040 - * Also sysret mandates a special GDT layout
14041 - *
14042 - * TLS descriptors are currently at a different place compared to i386.
14043 - * Hopefully nobody expects them at a fixed place (Wine?)
14044 - */
14045 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14046 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14047 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14048 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14049 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14050 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14051 -#else
14052 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14053 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14054 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14055 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14056 - /*
14057 - * Segments used for calling PnP BIOS have byte granularity.
14058 - * They code segments and data segments have fixed 64k limits,
14059 - * the transfer segment sizes are set at run time.
14060 - */
14061 - /* 32-bit code */
14062 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14063 - /* 16-bit code */
14064 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14065 - /* 16-bit data */
14066 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14067 - /* 16-bit data */
14068 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14069 - /* 16-bit data */
14070 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14071 - /*
14072 - * The APM segments have byte granularity and their bases
14073 - * are set at run time. All have 64k limits.
14074 - */
14075 - /* 32-bit code */
14076 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14077 - /* 16-bit code */
14078 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14079 - /* data */
14080 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14081 -
14082 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14083 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14084 - GDT_STACK_CANARY_INIT
14085 -#endif
14086 -} };
14087 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14088 -
14089 static int __init x86_xsave_setup(char *s)
14090 {
14091 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14092 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14093 {
14094 struct desc_ptr gdt_descr;
14095
14096 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14097 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14098 gdt_descr.size = GDT_SIZE - 1;
14099 load_gdt(&gdt_descr);
14100 /* Reload the per-cpu base */
14101 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14102 /* Filter out anything that depends on CPUID levels we don't have */
14103 filter_cpuid_features(c, true);
14104
14105 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14106 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14107 +#endif
14108 +
14109 /* If the model name is still unset, do table lookup. */
14110 if (!c->x86_model_id[0]) {
14111 const char *p;
14112 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14113 }
14114 __setup("clearcpuid=", setup_disablecpuid);
14115
14116 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14117 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14118 +
14119 #ifdef CONFIG_X86_64
14120 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14121 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14122 - (unsigned long) nmi_idt_table };
14123 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14124
14125 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14126 irq_stack_union) __aligned(PAGE_SIZE);
14127 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14128 EXPORT_PER_CPU_SYMBOL(current_task);
14129
14130 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14131 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14132 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14133 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14134
14135 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14136 @@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14137 {
14138 memset(regs, 0, sizeof(struct pt_regs));
14139 regs->fs = __KERNEL_PERCPU;
14140 - regs->gs = __KERNEL_STACK_CANARY;
14141 + savesegment(gs, regs->gs);
14142
14143 return regs;
14144 }
14145 @@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14146 int i;
14147
14148 cpu = stack_smp_processor_id();
14149 - t = &per_cpu(init_tss, cpu);
14150 + t = init_tss + cpu;
14151 oist = &per_cpu(orig_ist, cpu);
14152
14153 #ifdef CONFIG_NUMA
14154 @@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14155 switch_to_new_gdt(cpu);
14156 loadsegment(fs, 0);
14157
14158 - load_idt((const struct desc_ptr *)&idt_descr);
14159 + load_idt(&idt_descr);
14160
14161 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14162 syscall_init();
14163 @@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14164 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14165 barrier();
14166
14167 - x86_configure_nx();
14168 if (cpu != 0)
14169 enable_x2apic();
14170
14171 @@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14172 {
14173 int cpu = smp_processor_id();
14174 struct task_struct *curr = current;
14175 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14176 + struct tss_struct *t = init_tss + cpu;
14177 struct thread_struct *thread = &curr->thread;
14178
14179 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14180 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14181 index 3e6ff6c..54b4992 100644
14182 --- a/arch/x86/kernel/cpu/intel.c
14183 +++ b/arch/x86/kernel/cpu/intel.c
14184 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14185 * Update the IDT descriptor and reload the IDT so that
14186 * it uses the read-only mapped virtual address.
14187 */
14188 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14189 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14190 load_idt(&idt_descr);
14191 }
14192 #endif
14193 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14194 index da27c5d..569e359 100644
14195 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14196 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14197 @@ -42,6 +42,7 @@
14198 #include <asm/processor.h>
14199 #include <asm/mce.h>
14200 #include <asm/msr.h>
14201 +#include <asm/local.h>
14202
14203 #include "mce-internal.h"
14204
14205 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14206 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14207 m->cs, m->ip);
14208
14209 - if (m->cs == __KERNEL_CS)
14210 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14211 print_symbol("{%s}", m->ip);
14212 pr_cont("\n");
14213 }
14214 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14215
14216 #define PANIC_TIMEOUT 5 /* 5 seconds */
14217
14218 -static atomic_t mce_paniced;
14219 +static atomic_unchecked_t mce_paniced;
14220
14221 static int fake_panic;
14222 -static atomic_t mce_fake_paniced;
14223 +static atomic_unchecked_t mce_fake_paniced;
14224
14225 /* Panic in progress. Enable interrupts and wait for final IPI */
14226 static void wait_for_panic(void)
14227 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14228 /*
14229 * Make sure only one CPU runs in machine check panic
14230 */
14231 - if (atomic_inc_return(&mce_paniced) > 1)
14232 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14233 wait_for_panic();
14234 barrier();
14235
14236 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14237 console_verbose();
14238 } else {
14239 /* Don't log too much for fake panic */
14240 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14241 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14242 return;
14243 }
14244 /* First print corrected ones that are still unlogged */
14245 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14246 * might have been modified by someone else.
14247 */
14248 rmb();
14249 - if (atomic_read(&mce_paniced))
14250 + if (atomic_read_unchecked(&mce_paniced))
14251 wait_for_panic();
14252 if (!monarch_timeout)
14253 goto out;
14254 @@ -1579,7 +1580,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14255 }
14256
14257 /* Call the installed machine check handler for this CPU setup. */
14258 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14259 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14260 unexpected_machine_check;
14261
14262 /*
14263 @@ -1602,7 +1603,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14264 return;
14265 }
14266
14267 + pax_open_kernel();
14268 machine_check_vector = do_machine_check;
14269 + pax_close_kernel();
14270
14271 __mcheck_cpu_init_generic();
14272 __mcheck_cpu_init_vendor(c);
14273 @@ -1616,7 +1619,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14274 */
14275
14276 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14277 -static int mce_chrdev_open_count; /* #times opened */
14278 +static local_t mce_chrdev_open_count; /* #times opened */
14279 static int mce_chrdev_open_exclu; /* already open exclusive? */
14280
14281 static int mce_chrdev_open(struct inode *inode, struct file *file)
14282 @@ -1624,7 +1627,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14283 spin_lock(&mce_chrdev_state_lock);
14284
14285 if (mce_chrdev_open_exclu ||
14286 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14287 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14288 spin_unlock(&mce_chrdev_state_lock);
14289
14290 return -EBUSY;
14291 @@ -1632,7 +1635,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14292
14293 if (file->f_flags & O_EXCL)
14294 mce_chrdev_open_exclu = 1;
14295 - mce_chrdev_open_count++;
14296 + local_inc(&mce_chrdev_open_count);
14297
14298 spin_unlock(&mce_chrdev_state_lock);
14299
14300 @@ -1643,7 +1646,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14301 {
14302 spin_lock(&mce_chrdev_state_lock);
14303
14304 - mce_chrdev_open_count--;
14305 + local_dec(&mce_chrdev_open_count);
14306 mce_chrdev_open_exclu = 0;
14307
14308 spin_unlock(&mce_chrdev_state_lock);
14309 @@ -2368,7 +2371,7 @@ struct dentry *mce_get_debugfs_dir(void)
14310 static void mce_reset(void)
14311 {
14312 cpu_missing = 0;
14313 - atomic_set(&mce_fake_paniced, 0);
14314 + atomic_set_unchecked(&mce_fake_paniced, 0);
14315 atomic_set(&mce_executing, 0);
14316 atomic_set(&mce_callin, 0);
14317 atomic_set(&global_nwo, 0);
14318 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14319 index 2d5454c..51987eb 100644
14320 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14321 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14322 @@ -11,6 +11,7 @@
14323 #include <asm/processor.h>
14324 #include <asm/mce.h>
14325 #include <asm/msr.h>
14326 +#include <asm/pgtable.h>
14327
14328 /* By default disabled */
14329 int mce_p5_enabled __read_mostly;
14330 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14331 if (!cpu_has(c, X86_FEATURE_MCE))
14332 return;
14333
14334 + pax_open_kernel();
14335 machine_check_vector = pentium_machine_check;
14336 + pax_close_kernel();
14337 /* Make sure the vector pointer is visible before we enable MCEs: */
14338 wmb();
14339
14340 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14341 index 2d7998f..17c9de1 100644
14342 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14343 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14344 @@ -10,6 +10,7 @@
14345 #include <asm/processor.h>
14346 #include <asm/mce.h>
14347 #include <asm/msr.h>
14348 +#include <asm/pgtable.h>
14349
14350 /* Machine check handler for WinChip C6: */
14351 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14352 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14353 {
14354 u32 lo, hi;
14355
14356 + pax_open_kernel();
14357 machine_check_vector = winchip_machine_check;
14358 + pax_close_kernel();
14359 /* Make sure the vector pointer is visible before we enable MCEs: */
14360 wmb();
14361
14362 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14363 index 6b96110..0da73eb 100644
14364 --- a/arch/x86/kernel/cpu/mtrr/main.c
14365 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14366 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14367 u64 size_or_mask, size_and_mask;
14368 static bool mtrr_aps_delayed_init;
14369
14370 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14371 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14372
14373 const struct mtrr_ops *mtrr_if;
14374
14375 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14376 index df5e41f..816c719 100644
14377 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14378 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14379 @@ -25,7 +25,7 @@ struct mtrr_ops {
14380 int (*validate_add_page)(unsigned long base, unsigned long size,
14381 unsigned int type);
14382 int (*have_wrcomb)(void);
14383 -};
14384 +} __do_const;
14385
14386 extern int generic_get_free_region(unsigned long base, unsigned long size,
14387 int replace_reg);
14388 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14389 index c4706cf..264b0f7 100644
14390 --- a/arch/x86/kernel/cpu/perf_event.c
14391 +++ b/arch/x86/kernel/cpu/perf_event.c
14392 @@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14393 break;
14394
14395 perf_callchain_store(entry, frame.return_address);
14396 - fp = frame.next_frame;
14397 + fp = (const void __force_user *)frame.next_frame;
14398 }
14399 }
14400
14401 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14402 index 13ad899..f642b9a 100644
14403 --- a/arch/x86/kernel/crash.c
14404 +++ b/arch/x86/kernel/crash.c
14405 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14406 {
14407 #ifdef CONFIG_X86_32
14408 struct pt_regs fixed_regs;
14409 -#endif
14410
14411 -#ifdef CONFIG_X86_32
14412 - if (!user_mode_vm(regs)) {
14413 + if (!user_mode(regs)) {
14414 crash_fixup_ss_esp(&fixed_regs, regs);
14415 regs = &fixed_regs;
14416 }
14417 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14418 index 37250fe..bf2ec74 100644
14419 --- a/arch/x86/kernel/doublefault_32.c
14420 +++ b/arch/x86/kernel/doublefault_32.c
14421 @@ -11,7 +11,7 @@
14422
14423 #define DOUBLEFAULT_STACKSIZE (1024)
14424 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14425 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14426 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14427
14428 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14429
14430 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14431 unsigned long gdt, tss;
14432
14433 store_gdt(&gdt_desc);
14434 - gdt = gdt_desc.address;
14435 + gdt = (unsigned long)gdt_desc.address;
14436
14437 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14438
14439 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14440 /* 0x2 bit is always set */
14441 .flags = X86_EFLAGS_SF | 0x2,
14442 .sp = STACK_START,
14443 - .es = __USER_DS,
14444 + .es = __KERNEL_DS,
14445 .cs = __KERNEL_CS,
14446 .ss = __KERNEL_DS,
14447 - .ds = __USER_DS,
14448 + .ds = __KERNEL_DS,
14449 .fs = __KERNEL_PERCPU,
14450
14451 .__cr3 = __pa_nodebug(swapper_pg_dir),
14452 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14453 index 571246d..81f335c 100644
14454 --- a/arch/x86/kernel/dumpstack.c
14455 +++ b/arch/x86/kernel/dumpstack.c
14456 @@ -2,6 +2,9 @@
14457 * Copyright (C) 1991, 1992 Linus Torvalds
14458 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14459 */
14460 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14461 +#define __INCLUDED_BY_HIDESYM 1
14462 +#endif
14463 #include <linux/kallsyms.h>
14464 #include <linux/kprobes.h>
14465 #include <linux/uaccess.h>
14466 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14467 static void
14468 print_ftrace_graph_addr(unsigned long addr, void *data,
14469 const struct stacktrace_ops *ops,
14470 - struct thread_info *tinfo, int *graph)
14471 + struct task_struct *task, int *graph)
14472 {
14473 - struct task_struct *task;
14474 unsigned long ret_addr;
14475 int index;
14476
14477 if (addr != (unsigned long)return_to_handler)
14478 return;
14479
14480 - task = tinfo->task;
14481 index = task->curr_ret_stack;
14482
14483 if (!task->ret_stack || index < *graph)
14484 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14485 static inline void
14486 print_ftrace_graph_addr(unsigned long addr, void *data,
14487 const struct stacktrace_ops *ops,
14488 - struct thread_info *tinfo, int *graph)
14489 + struct task_struct *task, int *graph)
14490 { }
14491 #endif
14492
14493 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14494 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14495 */
14496
14497 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14498 - void *p, unsigned int size, void *end)
14499 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14500 {
14501 - void *t = tinfo;
14502 if (end) {
14503 if (p < end && p >= (end-THREAD_SIZE))
14504 return 1;
14505 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14506 }
14507
14508 unsigned long
14509 -print_context_stack(struct thread_info *tinfo,
14510 +print_context_stack(struct task_struct *task, void *stack_start,
14511 unsigned long *stack, unsigned long bp,
14512 const struct stacktrace_ops *ops, void *data,
14513 unsigned long *end, int *graph)
14514 {
14515 struct stack_frame *frame = (struct stack_frame *)bp;
14516
14517 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14518 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14519 unsigned long addr;
14520
14521 addr = *stack;
14522 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14523 } else {
14524 ops->address(data, addr, 0);
14525 }
14526 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14527 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14528 }
14529 stack++;
14530 }
14531 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14532 EXPORT_SYMBOL_GPL(print_context_stack);
14533
14534 unsigned long
14535 -print_context_stack_bp(struct thread_info *tinfo,
14536 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14537 unsigned long *stack, unsigned long bp,
14538 const struct stacktrace_ops *ops, void *data,
14539 unsigned long *end, int *graph)
14540 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14541 struct stack_frame *frame = (struct stack_frame *)bp;
14542 unsigned long *ret_addr = &frame->return_address;
14543
14544 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14545 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14546 unsigned long addr = *ret_addr;
14547
14548 if (!__kernel_text_address(addr))
14549 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14550 ops->address(data, addr, 1);
14551 frame = frame->next_frame;
14552 ret_addr = &frame->return_address;
14553 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14554 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14555 }
14556
14557 return (unsigned long)frame;
14558 @@ -189,7 +188,7 @@ void dump_stack(void)
14559
14560 bp = stack_frame(current, NULL);
14561 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14562 - current->pid, current->comm, print_tainted(),
14563 + task_pid_nr(current), current->comm, print_tainted(),
14564 init_utsname()->release,
14565 (int)strcspn(init_utsname()->version, " "),
14566 init_utsname()->version);
14567 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14568 }
14569 EXPORT_SYMBOL_GPL(oops_begin);
14570
14571 +extern void gr_handle_kernel_exploit(void);
14572 +
14573 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14574 {
14575 if (regs && kexec_should_crash(current))
14576 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14577 panic("Fatal exception in interrupt");
14578 if (panic_on_oops)
14579 panic("Fatal exception");
14580 - do_exit(signr);
14581 +
14582 + gr_handle_kernel_exploit();
14583 +
14584 + do_group_exit(signr);
14585 }
14586
14587 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14588 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14589
14590 show_regs(regs);
14591 #ifdef CONFIG_X86_32
14592 - if (user_mode_vm(regs)) {
14593 + if (user_mode(regs)) {
14594 sp = regs->sp;
14595 ss = regs->ss & 0xffff;
14596 } else {
14597 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14598 unsigned long flags = oops_begin();
14599 int sig = SIGSEGV;
14600
14601 - if (!user_mode_vm(regs))
14602 + if (!user_mode(regs))
14603 report_bug(regs->ip, regs);
14604
14605 if (__die(str, regs, err))
14606 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14607 index e0b1d78..a8ade5e 100644
14608 --- a/arch/x86/kernel/dumpstack_32.c
14609 +++ b/arch/x86/kernel/dumpstack_32.c
14610 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14611 bp = stack_frame(task, regs);
14612
14613 for (;;) {
14614 - struct thread_info *context;
14615 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14616
14617 - context = (struct thread_info *)
14618 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14619 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14620 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14621
14622 - stack = (unsigned long *)context->previous_esp;
14623 - if (!stack)
14624 + if (stack_start == task_stack_page(task))
14625 break;
14626 + stack = *(unsigned long **)stack_start;
14627 if (ops->stack(data, "IRQ") < 0)
14628 break;
14629 touch_nmi_watchdog();
14630 @@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14631 int i;
14632
14633 print_modules();
14634 - __show_regs(regs, !user_mode_vm(regs));
14635 + __show_regs(regs, !user_mode(regs));
14636
14637 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14638 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14639 @@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14640 * When in-kernel, we also print out the stack and code at the
14641 * time of the fault..
14642 */
14643 - if (!user_mode_vm(regs)) {
14644 + if (!user_mode(regs)) {
14645 unsigned int code_prologue = code_bytes * 43 / 64;
14646 unsigned int code_len = code_bytes;
14647 unsigned char c;
14648 u8 *ip;
14649 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14650
14651 printk(KERN_EMERG "Stack:\n");
14652 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14653
14654 printk(KERN_EMERG "Code: ");
14655
14656 - ip = (u8 *)regs->ip - code_prologue;
14657 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14658 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14659 /* try starting at IP */
14660 - ip = (u8 *)regs->ip;
14661 + ip = (u8 *)regs->ip + cs_base;
14662 code_len = code_len - code_prologue + 1;
14663 }
14664 for (i = 0; i < code_len; i++, ip++) {
14665 @@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14666 printk(KERN_CONT " Bad EIP value.");
14667 break;
14668 }
14669 - if (ip == (u8 *)regs->ip)
14670 + if (ip == (u8 *)regs->ip + cs_base)
14671 printk(KERN_CONT "<%02x> ", c);
14672 else
14673 printk(KERN_CONT "%02x ", c);
14674 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14675 {
14676 unsigned short ud2;
14677
14678 + ip = ktla_ktva(ip);
14679 if (ip < PAGE_OFFSET)
14680 return 0;
14681 if (probe_kernel_address((unsigned short *)ip, ud2))
14682 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14683
14684 return ud2 == 0x0b0f;
14685 }
14686 +
14687 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14688 +void pax_check_alloca(unsigned long size)
14689 +{
14690 + unsigned long sp = (unsigned long)&sp, stack_left;
14691 +
14692 + /* all kernel stacks are of the same size */
14693 + stack_left = sp & (THREAD_SIZE - 1);
14694 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14695 +}
14696 +EXPORT_SYMBOL(pax_check_alloca);
14697 +#endif
14698 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14699 index 791b761..2ab6e33 100644
14700 --- a/arch/x86/kernel/dumpstack_64.c
14701 +++ b/arch/x86/kernel/dumpstack_64.c
14702 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14703 unsigned long *irq_stack_end =
14704 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14705 unsigned used = 0;
14706 - struct thread_info *tinfo;
14707 int graph = 0;
14708 unsigned long dummy;
14709 + void *stack_start;
14710
14711 if (!task)
14712 task = current;
14713 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14714 * current stack address. If the stacks consist of nested
14715 * exceptions
14716 */
14717 - tinfo = task_thread_info(task);
14718 for (;;) {
14719 char *id;
14720 unsigned long *estack_end;
14721 +
14722 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14723 &used, &id);
14724
14725 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14726 if (ops->stack(data, id) < 0)
14727 break;
14728
14729 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14730 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14731 data, estack_end, &graph);
14732 ops->stack(data, "<EOE>");
14733 /*
14734 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14735 * second-to-last pointer (index -2 to end) in the
14736 * exception stack:
14737 */
14738 + if ((u16)estack_end[-1] != __KERNEL_DS)
14739 + goto out;
14740 stack = (unsigned long *) estack_end[-2];
14741 continue;
14742 }
14743 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14744 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14745 if (ops->stack(data, "IRQ") < 0)
14746 break;
14747 - bp = ops->walk_stack(tinfo, stack, bp,
14748 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14749 ops, data, irq_stack_end, &graph);
14750 /*
14751 * We link to the next stack (which would be
14752 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14753 /*
14754 * This handles the process stack:
14755 */
14756 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14757 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14758 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14759 +out:
14760 put_cpu();
14761 }
14762 EXPORT_SYMBOL(dump_trace);
14763 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14764
14765 return ud2 == 0x0b0f;
14766 }
14767 +
14768 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14769 +void pax_check_alloca(unsigned long size)
14770 +{
14771 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14772 + unsigned cpu, used;
14773 + char *id;
14774 +
14775 + /* check the process stack first */
14776 + stack_start = (unsigned long)task_stack_page(current);
14777 + stack_end = stack_start + THREAD_SIZE;
14778 + if (likely(stack_start <= sp && sp < stack_end)) {
14779 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14780 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14781 + return;
14782 + }
14783 +
14784 + cpu = get_cpu();
14785 +
14786 + /* check the irq stacks */
14787 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14788 + stack_start = stack_end - IRQ_STACK_SIZE;
14789 + if (stack_start <= sp && sp < stack_end) {
14790 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14791 + put_cpu();
14792 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14793 + return;
14794 + }
14795 +
14796 + /* check the exception stacks */
14797 + used = 0;
14798 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14799 + stack_start = stack_end - EXCEPTION_STKSZ;
14800 + if (stack_end && stack_start <= sp && sp < stack_end) {
14801 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14802 + put_cpu();
14803 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14804 + return;
14805 + }
14806 +
14807 + put_cpu();
14808 +
14809 + /* unknown stack */
14810 + BUG();
14811 +}
14812 +EXPORT_SYMBOL(pax_check_alloca);
14813 +#endif
14814 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14815 index 9b9f18b..9fcaa04 100644
14816 --- a/arch/x86/kernel/early_printk.c
14817 +++ b/arch/x86/kernel/early_printk.c
14818 @@ -7,6 +7,7 @@
14819 #include <linux/pci_regs.h>
14820 #include <linux/pci_ids.h>
14821 #include <linux/errno.h>
14822 +#include <linux/sched.h>
14823 #include <asm/io.h>
14824 #include <asm/processor.h>
14825 #include <asm/fcntl.h>
14826 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14827 index 623f288..0683156 100644
14828 --- a/arch/x86/kernel/entry_32.S
14829 +++ b/arch/x86/kernel/entry_32.S
14830 @@ -176,13 +176,146 @@
14831 /*CFI_REL_OFFSET gs, PT_GS*/
14832 .endm
14833 .macro SET_KERNEL_GS reg
14834 +
14835 +#ifdef CONFIG_CC_STACKPROTECTOR
14836 movl $(__KERNEL_STACK_CANARY), \reg
14837 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14838 + movl $(__USER_DS), \reg
14839 +#else
14840 + xorl \reg, \reg
14841 +#endif
14842 +
14843 movl \reg, %gs
14844 .endm
14845
14846 #endif /* CONFIG_X86_32_LAZY_GS */
14847
14848 -.macro SAVE_ALL
14849 +.macro pax_enter_kernel
14850 +#ifdef CONFIG_PAX_KERNEXEC
14851 + call pax_enter_kernel
14852 +#endif
14853 +.endm
14854 +
14855 +.macro pax_exit_kernel
14856 +#ifdef CONFIG_PAX_KERNEXEC
14857 + call pax_exit_kernel
14858 +#endif
14859 +.endm
14860 +
14861 +#ifdef CONFIG_PAX_KERNEXEC
14862 +ENTRY(pax_enter_kernel)
14863 +#ifdef CONFIG_PARAVIRT
14864 + pushl %eax
14865 + pushl %ecx
14866 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14867 + mov %eax, %esi
14868 +#else
14869 + mov %cr0, %esi
14870 +#endif
14871 + bts $16, %esi
14872 + jnc 1f
14873 + mov %cs, %esi
14874 + cmp $__KERNEL_CS, %esi
14875 + jz 3f
14876 + ljmp $__KERNEL_CS, $3f
14877 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14878 +2:
14879 +#ifdef CONFIG_PARAVIRT
14880 + mov %esi, %eax
14881 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14882 +#else
14883 + mov %esi, %cr0
14884 +#endif
14885 +3:
14886 +#ifdef CONFIG_PARAVIRT
14887 + popl %ecx
14888 + popl %eax
14889 +#endif
14890 + ret
14891 +ENDPROC(pax_enter_kernel)
14892 +
14893 +ENTRY(pax_exit_kernel)
14894 +#ifdef CONFIG_PARAVIRT
14895 + pushl %eax
14896 + pushl %ecx
14897 +#endif
14898 + mov %cs, %esi
14899 + cmp $__KERNEXEC_KERNEL_CS, %esi
14900 + jnz 2f
14901 +#ifdef CONFIG_PARAVIRT
14902 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14903 + mov %eax, %esi
14904 +#else
14905 + mov %cr0, %esi
14906 +#endif
14907 + btr $16, %esi
14908 + ljmp $__KERNEL_CS, $1f
14909 +1:
14910 +#ifdef CONFIG_PARAVIRT
14911 + mov %esi, %eax
14912 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14913 +#else
14914 + mov %esi, %cr0
14915 +#endif
14916 +2:
14917 +#ifdef CONFIG_PARAVIRT
14918 + popl %ecx
14919 + popl %eax
14920 +#endif
14921 + ret
14922 +ENDPROC(pax_exit_kernel)
14923 +#endif
14924 +
14925 +.macro pax_erase_kstack
14926 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14927 + call pax_erase_kstack
14928 +#endif
14929 +.endm
14930 +
14931 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14932 +/*
14933 + * ebp: thread_info
14934 + * ecx, edx: can be clobbered
14935 + */
14936 +ENTRY(pax_erase_kstack)
14937 + pushl %edi
14938 + pushl %eax
14939 +
14940 + mov TI_lowest_stack(%ebp), %edi
14941 + mov $-0xBEEF, %eax
14942 + std
14943 +
14944 +1: mov %edi, %ecx
14945 + and $THREAD_SIZE_asm - 1, %ecx
14946 + shr $2, %ecx
14947 + repne scasl
14948 + jecxz 2f
14949 +
14950 + cmp $2*16, %ecx
14951 + jc 2f
14952 +
14953 + mov $2*16, %ecx
14954 + repe scasl
14955 + jecxz 2f
14956 + jne 1b
14957 +
14958 +2: cld
14959 + mov %esp, %ecx
14960 + sub %edi, %ecx
14961 + shr $2, %ecx
14962 + rep stosl
14963 +
14964 + mov TI_task_thread_sp0(%ebp), %edi
14965 + sub $128, %edi
14966 + mov %edi, TI_lowest_stack(%ebp)
14967 +
14968 + popl %eax
14969 + popl %edi
14970 + ret
14971 +ENDPROC(pax_erase_kstack)
14972 +#endif
14973 +
14974 +.macro __SAVE_ALL _DS
14975 cld
14976 PUSH_GS
14977 pushl_cfi %fs
14978 @@ -205,7 +338,7 @@
14979 CFI_REL_OFFSET ecx, 0
14980 pushl_cfi %ebx
14981 CFI_REL_OFFSET ebx, 0
14982 - movl $(__USER_DS), %edx
14983 + movl $\_DS, %edx
14984 movl %edx, %ds
14985 movl %edx, %es
14986 movl $(__KERNEL_PERCPU), %edx
14987 @@ -213,6 +346,15 @@
14988 SET_KERNEL_GS %edx
14989 .endm
14990
14991 +.macro SAVE_ALL
14992 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14993 + __SAVE_ALL __KERNEL_DS
14994 + pax_enter_kernel
14995 +#else
14996 + __SAVE_ALL __USER_DS
14997 +#endif
14998 +.endm
14999 +
15000 .macro RESTORE_INT_REGS
15001 popl_cfi %ebx
15002 CFI_RESTORE ebx
15003 @@ -296,7 +438,7 @@ ENTRY(ret_from_fork)
15004 popfl_cfi
15005 jmp syscall_exit
15006 CFI_ENDPROC
15007 -END(ret_from_fork)
15008 +ENDPROC(ret_from_fork)
15009
15010 /*
15011 * Interrupt exit functions should be protected against kprobes
15012 @@ -329,7 +471,15 @@ ret_from_intr:
15013 andl $SEGMENT_RPL_MASK, %eax
15014 #endif
15015 cmpl $USER_RPL, %eax
15016 +
15017 +#ifdef CONFIG_PAX_KERNEXEC
15018 + jae resume_userspace
15019 +
15020 + pax_exit_kernel
15021 + jmp resume_kernel
15022 +#else
15023 jb resume_kernel # not returning to v8086 or userspace
15024 +#endif
15025
15026 ENTRY(resume_userspace)
15027 LOCKDEP_SYS_EXIT
15028 @@ -341,8 +491,8 @@ ENTRY(resume_userspace)
15029 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15030 # int/exception return?
15031 jne work_pending
15032 - jmp restore_all
15033 -END(ret_from_exception)
15034 + jmp restore_all_pax
15035 +ENDPROC(ret_from_exception)
15036
15037 #ifdef CONFIG_PREEMPT
15038 ENTRY(resume_kernel)
15039 @@ -357,7 +507,7 @@ need_resched:
15040 jz restore_all
15041 call preempt_schedule_irq
15042 jmp need_resched
15043 -END(resume_kernel)
15044 +ENDPROC(resume_kernel)
15045 #endif
15046 CFI_ENDPROC
15047 /*
15048 @@ -391,23 +541,34 @@ sysenter_past_esp:
15049 /*CFI_REL_OFFSET cs, 0*/
15050 /*
15051 * Push current_thread_info()->sysenter_return to the stack.
15052 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15053 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15054 */
15055 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15056 + pushl_cfi $0
15057 CFI_REL_OFFSET eip, 0
15058
15059 pushl_cfi %eax
15060 SAVE_ALL
15061 + GET_THREAD_INFO(%ebp)
15062 + movl TI_sysenter_return(%ebp),%ebp
15063 + movl %ebp,PT_EIP(%esp)
15064 ENABLE_INTERRUPTS(CLBR_NONE)
15065
15066 /*
15067 * Load the potential sixth argument from user stack.
15068 * Careful about security.
15069 */
15070 + movl PT_OLDESP(%esp),%ebp
15071 +
15072 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15073 + mov PT_OLDSS(%esp),%ds
15074 +1: movl %ds:(%ebp),%ebp
15075 + push %ss
15076 + pop %ds
15077 +#else
15078 cmpl $__PAGE_OFFSET-3,%ebp
15079 jae syscall_fault
15080 1: movl (%ebp),%ebp
15081 +#endif
15082 +
15083 movl %ebp,PT_EBP(%esp)
15084 _ASM_EXTABLE(1b,syscall_fault)
15085
15086 @@ -427,12 +588,24 @@ sysenter_do_call:
15087 testl $_TIF_ALLWORK_MASK, %ecx
15088 jne sysexit_audit
15089 sysenter_exit:
15090 +
15091 +#ifdef CONFIG_PAX_RANDKSTACK
15092 + pushl_cfi %eax
15093 + movl %esp, %eax
15094 + call pax_randomize_kstack
15095 + popl_cfi %eax
15096 +#endif
15097 +
15098 + pax_erase_kstack
15099 +
15100 /* if something modifies registers it must also disable sysexit */
15101 movl PT_EIP(%esp), %edx
15102 movl PT_OLDESP(%esp), %ecx
15103 xorl %ebp,%ebp
15104 TRACE_IRQS_ON
15105 1: mov PT_FS(%esp), %fs
15106 +2: mov PT_DS(%esp), %ds
15107 +3: mov PT_ES(%esp), %es
15108 PTGS_TO_GS
15109 ENABLE_INTERRUPTS_SYSEXIT
15110
15111 @@ -449,6 +622,9 @@ sysenter_audit:
15112 movl %eax,%edx /* 2nd arg: syscall number */
15113 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15114 call __audit_syscall_entry
15115 +
15116 + pax_erase_kstack
15117 +
15118 pushl_cfi %ebx
15119 movl PT_EAX(%esp),%eax /* reload syscall number */
15120 jmp sysenter_do_call
15121 @@ -474,10 +650,16 @@ sysexit_audit:
15122
15123 CFI_ENDPROC
15124 .pushsection .fixup,"ax"
15125 -2: movl $0,PT_FS(%esp)
15126 +4: movl $0,PT_FS(%esp)
15127 + jmp 1b
15128 +5: movl $0,PT_DS(%esp)
15129 + jmp 1b
15130 +6: movl $0,PT_ES(%esp)
15131 jmp 1b
15132 .popsection
15133 - _ASM_EXTABLE(1b,2b)
15134 + _ASM_EXTABLE(1b,4b)
15135 + _ASM_EXTABLE(2b,5b)
15136 + _ASM_EXTABLE(3b,6b)
15137 PTGS_TO_GS_EX
15138 ENDPROC(ia32_sysenter_target)
15139
15140 @@ -509,6 +691,15 @@ syscall_exit:
15141 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15142 jne syscall_exit_work
15143
15144 +restore_all_pax:
15145 +
15146 +#ifdef CONFIG_PAX_RANDKSTACK
15147 + movl %esp, %eax
15148 + call pax_randomize_kstack
15149 +#endif
15150 +
15151 + pax_erase_kstack
15152 +
15153 restore_all:
15154 TRACE_IRQS_IRET
15155 restore_all_notrace:
15156 @@ -565,14 +756,34 @@ ldt_ss:
15157 * compensating for the offset by changing to the ESPFIX segment with
15158 * a base address that matches for the difference.
15159 */
15160 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15161 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15162 mov %esp, %edx /* load kernel esp */
15163 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15164 mov %dx, %ax /* eax: new kernel esp */
15165 sub %eax, %edx /* offset (low word is 0) */
15166 +#ifdef CONFIG_SMP
15167 + movl PER_CPU_VAR(cpu_number), %ebx
15168 + shll $PAGE_SHIFT_asm, %ebx
15169 + addl $cpu_gdt_table, %ebx
15170 +#else
15171 + movl $cpu_gdt_table, %ebx
15172 +#endif
15173 shr $16, %edx
15174 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15175 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15176 +
15177 +#ifdef CONFIG_PAX_KERNEXEC
15178 + mov %cr0, %esi
15179 + btr $16, %esi
15180 + mov %esi, %cr0
15181 +#endif
15182 +
15183 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15184 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15185 +
15186 +#ifdef CONFIG_PAX_KERNEXEC
15187 + bts $16, %esi
15188 + mov %esi, %cr0
15189 +#endif
15190 +
15191 pushl_cfi $__ESPFIX_SS
15192 pushl_cfi %eax /* new kernel esp */
15193 /* Disable interrupts, but do not irqtrace this section: we
15194 @@ -601,35 +812,23 @@ work_resched:
15195 movl TI_flags(%ebp), %ecx
15196 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15197 # than syscall tracing?
15198 - jz restore_all
15199 + jz restore_all_pax
15200 testb $_TIF_NEED_RESCHED, %cl
15201 jnz work_resched
15202
15203 work_notifysig: # deal with pending signals and
15204 # notify-resume requests
15205 + movl %esp, %eax
15206 #ifdef CONFIG_VM86
15207 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15208 - movl %esp, %eax
15209 - jne work_notifysig_v86 # returning to kernel-space or
15210 + jz 1f # returning to kernel-space or
15211 # vm86-space
15212 - TRACE_IRQS_ON
15213 - ENABLE_INTERRUPTS(CLBR_NONE)
15214 - movb PT_CS(%esp), %bl
15215 - andb $SEGMENT_RPL_MASK, %bl
15216 - cmpb $USER_RPL, %bl
15217 - jb resume_kernel
15218 - xorl %edx, %edx
15219 - call do_notify_resume
15220 - jmp resume_userspace
15221
15222 - ALIGN
15223 -work_notifysig_v86:
15224 pushl_cfi %ecx # save ti_flags for do_notify_resume
15225 call save_v86_state # %eax contains pt_regs pointer
15226 popl_cfi %ecx
15227 movl %eax, %esp
15228 -#else
15229 - movl %esp, %eax
15230 +1:
15231 #endif
15232 TRACE_IRQS_ON
15233 ENABLE_INTERRUPTS(CLBR_NONE)
15234 @@ -640,7 +839,7 @@ work_notifysig_v86:
15235 xorl %edx, %edx
15236 call do_notify_resume
15237 jmp resume_userspace
15238 -END(work_pending)
15239 +ENDPROC(work_pending)
15240
15241 # perform syscall exit tracing
15242 ALIGN
15243 @@ -648,11 +847,14 @@ syscall_trace_entry:
15244 movl $-ENOSYS,PT_EAX(%esp)
15245 movl %esp, %eax
15246 call syscall_trace_enter
15247 +
15248 + pax_erase_kstack
15249 +
15250 /* What it returned is what we'll actually use. */
15251 cmpl $(NR_syscalls), %eax
15252 jnae syscall_call
15253 jmp syscall_exit
15254 -END(syscall_trace_entry)
15255 +ENDPROC(syscall_trace_entry)
15256
15257 # perform syscall exit tracing
15258 ALIGN
15259 @@ -665,20 +867,24 @@ syscall_exit_work:
15260 movl %esp, %eax
15261 call syscall_trace_leave
15262 jmp resume_userspace
15263 -END(syscall_exit_work)
15264 +ENDPROC(syscall_exit_work)
15265 CFI_ENDPROC
15266
15267 RING0_INT_FRAME # can't unwind into user space anyway
15268 syscall_fault:
15269 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15270 + push %ss
15271 + pop %ds
15272 +#endif
15273 GET_THREAD_INFO(%ebp)
15274 movl $-EFAULT,PT_EAX(%esp)
15275 jmp resume_userspace
15276 -END(syscall_fault)
15277 +ENDPROC(syscall_fault)
15278
15279 syscall_badsys:
15280 movl $-ENOSYS,PT_EAX(%esp)
15281 jmp resume_userspace
15282 -END(syscall_badsys)
15283 +ENDPROC(syscall_badsys)
15284 CFI_ENDPROC
15285 /*
15286 * End of kprobes section
15287 @@ -750,6 +956,36 @@ ENTRY(ptregs_clone)
15288 CFI_ENDPROC
15289 ENDPROC(ptregs_clone)
15290
15291 + ALIGN;
15292 +ENTRY(kernel_execve)
15293 + CFI_STARTPROC
15294 + pushl_cfi %ebp
15295 + sub $PT_OLDSS+4,%esp
15296 + pushl_cfi %edi
15297 + pushl_cfi %ecx
15298 + pushl_cfi %eax
15299 + lea 3*4(%esp),%edi
15300 + mov $PT_OLDSS/4+1,%ecx
15301 + xorl %eax,%eax
15302 + rep stosl
15303 + popl_cfi %eax
15304 + popl_cfi %ecx
15305 + popl_cfi %edi
15306 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15307 + pushl_cfi %esp
15308 + call sys_execve
15309 + add $4,%esp
15310 + CFI_ADJUST_CFA_OFFSET -4
15311 + GET_THREAD_INFO(%ebp)
15312 + test %eax,%eax
15313 + jz syscall_exit
15314 + add $PT_OLDSS+4,%esp
15315 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15316 + popl_cfi %ebp
15317 + ret
15318 + CFI_ENDPROC
15319 +ENDPROC(kernel_execve)
15320 +
15321 .macro FIXUP_ESPFIX_STACK
15322 /*
15323 * Switch back for ESPFIX stack to the normal zerobased stack
15324 @@ -759,8 +995,15 @@ ENDPROC(ptregs_clone)
15325 * normal stack and adjusts ESP with the matching offset.
15326 */
15327 /* fixup the stack */
15328 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15329 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15330 +#ifdef CONFIG_SMP
15331 + movl PER_CPU_VAR(cpu_number), %ebx
15332 + shll $PAGE_SHIFT_asm, %ebx
15333 + addl $cpu_gdt_table, %ebx
15334 +#else
15335 + movl $cpu_gdt_table, %ebx
15336 +#endif
15337 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15338 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15339 shl $16, %eax
15340 addl %esp, %eax /* the adjusted stack pointer */
15341 pushl_cfi $__KERNEL_DS
15342 @@ -813,7 +1056,7 @@ vector=vector+1
15343 .endr
15344 2: jmp common_interrupt
15345 .endr
15346 -END(irq_entries_start)
15347 +ENDPROC(irq_entries_start)
15348
15349 .previous
15350 END(interrupt)
15351 @@ -861,7 +1104,7 @@ ENTRY(coprocessor_error)
15352 pushl_cfi $do_coprocessor_error
15353 jmp error_code
15354 CFI_ENDPROC
15355 -END(coprocessor_error)
15356 +ENDPROC(coprocessor_error)
15357
15358 ENTRY(simd_coprocessor_error)
15359 RING0_INT_FRAME
15360 @@ -882,7 +1125,7 @@ ENTRY(simd_coprocessor_error)
15361 #endif
15362 jmp error_code
15363 CFI_ENDPROC
15364 -END(simd_coprocessor_error)
15365 +ENDPROC(simd_coprocessor_error)
15366
15367 ENTRY(device_not_available)
15368 RING0_INT_FRAME
15369 @@ -890,18 +1133,18 @@ ENTRY(device_not_available)
15370 pushl_cfi $do_device_not_available
15371 jmp error_code
15372 CFI_ENDPROC
15373 -END(device_not_available)
15374 +ENDPROC(device_not_available)
15375
15376 #ifdef CONFIG_PARAVIRT
15377 ENTRY(native_iret)
15378 iret
15379 _ASM_EXTABLE(native_iret, iret_exc)
15380 -END(native_iret)
15381 +ENDPROC(native_iret)
15382
15383 ENTRY(native_irq_enable_sysexit)
15384 sti
15385 sysexit
15386 -END(native_irq_enable_sysexit)
15387 +ENDPROC(native_irq_enable_sysexit)
15388 #endif
15389
15390 ENTRY(overflow)
15391 @@ -910,7 +1153,7 @@ ENTRY(overflow)
15392 pushl_cfi $do_overflow
15393 jmp error_code
15394 CFI_ENDPROC
15395 -END(overflow)
15396 +ENDPROC(overflow)
15397
15398 ENTRY(bounds)
15399 RING0_INT_FRAME
15400 @@ -918,7 +1161,7 @@ ENTRY(bounds)
15401 pushl_cfi $do_bounds
15402 jmp error_code
15403 CFI_ENDPROC
15404 -END(bounds)
15405 +ENDPROC(bounds)
15406
15407 ENTRY(invalid_op)
15408 RING0_INT_FRAME
15409 @@ -926,7 +1169,7 @@ ENTRY(invalid_op)
15410 pushl_cfi $do_invalid_op
15411 jmp error_code
15412 CFI_ENDPROC
15413 -END(invalid_op)
15414 +ENDPROC(invalid_op)
15415
15416 ENTRY(coprocessor_segment_overrun)
15417 RING0_INT_FRAME
15418 @@ -934,35 +1177,35 @@ ENTRY(coprocessor_segment_overrun)
15419 pushl_cfi $do_coprocessor_segment_overrun
15420 jmp error_code
15421 CFI_ENDPROC
15422 -END(coprocessor_segment_overrun)
15423 +ENDPROC(coprocessor_segment_overrun)
15424
15425 ENTRY(invalid_TSS)
15426 RING0_EC_FRAME
15427 pushl_cfi $do_invalid_TSS
15428 jmp error_code
15429 CFI_ENDPROC
15430 -END(invalid_TSS)
15431 +ENDPROC(invalid_TSS)
15432
15433 ENTRY(segment_not_present)
15434 RING0_EC_FRAME
15435 pushl_cfi $do_segment_not_present
15436 jmp error_code
15437 CFI_ENDPROC
15438 -END(segment_not_present)
15439 +ENDPROC(segment_not_present)
15440
15441 ENTRY(stack_segment)
15442 RING0_EC_FRAME
15443 pushl_cfi $do_stack_segment
15444 jmp error_code
15445 CFI_ENDPROC
15446 -END(stack_segment)
15447 +ENDPROC(stack_segment)
15448
15449 ENTRY(alignment_check)
15450 RING0_EC_FRAME
15451 pushl_cfi $do_alignment_check
15452 jmp error_code
15453 CFI_ENDPROC
15454 -END(alignment_check)
15455 +ENDPROC(alignment_check)
15456
15457 ENTRY(divide_error)
15458 RING0_INT_FRAME
15459 @@ -970,7 +1213,7 @@ ENTRY(divide_error)
15460 pushl_cfi $do_divide_error
15461 jmp error_code
15462 CFI_ENDPROC
15463 -END(divide_error)
15464 +ENDPROC(divide_error)
15465
15466 #ifdef CONFIG_X86_MCE
15467 ENTRY(machine_check)
15468 @@ -979,7 +1222,7 @@ ENTRY(machine_check)
15469 pushl_cfi machine_check_vector
15470 jmp error_code
15471 CFI_ENDPROC
15472 -END(machine_check)
15473 +ENDPROC(machine_check)
15474 #endif
15475
15476 ENTRY(spurious_interrupt_bug)
15477 @@ -988,7 +1231,7 @@ ENTRY(spurious_interrupt_bug)
15478 pushl_cfi $do_spurious_interrupt_bug
15479 jmp error_code
15480 CFI_ENDPROC
15481 -END(spurious_interrupt_bug)
15482 +ENDPROC(spurious_interrupt_bug)
15483 /*
15484 * End of kprobes section
15485 */
15486 @@ -1100,7 +1343,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15487
15488 ENTRY(mcount)
15489 ret
15490 -END(mcount)
15491 +ENDPROC(mcount)
15492
15493 ENTRY(ftrace_caller)
15494 cmpl $0, function_trace_stop
15495 @@ -1129,7 +1372,7 @@ ftrace_graph_call:
15496 .globl ftrace_stub
15497 ftrace_stub:
15498 ret
15499 -END(ftrace_caller)
15500 +ENDPROC(ftrace_caller)
15501
15502 #else /* ! CONFIG_DYNAMIC_FTRACE */
15503
15504 @@ -1165,7 +1408,7 @@ trace:
15505 popl %ecx
15506 popl %eax
15507 jmp ftrace_stub
15508 -END(mcount)
15509 +ENDPROC(mcount)
15510 #endif /* CONFIG_DYNAMIC_FTRACE */
15511 #endif /* CONFIG_FUNCTION_TRACER */
15512
15513 @@ -1186,7 +1429,7 @@ ENTRY(ftrace_graph_caller)
15514 popl %ecx
15515 popl %eax
15516 ret
15517 -END(ftrace_graph_caller)
15518 +ENDPROC(ftrace_graph_caller)
15519
15520 .globl return_to_handler
15521 return_to_handler:
15522 @@ -1241,15 +1484,18 @@ error_code:
15523 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15524 REG_TO_PTGS %ecx
15525 SET_KERNEL_GS %ecx
15526 - movl $(__USER_DS), %ecx
15527 + movl $(__KERNEL_DS), %ecx
15528 movl %ecx, %ds
15529 movl %ecx, %es
15530 +
15531 + pax_enter_kernel
15532 +
15533 TRACE_IRQS_OFF
15534 movl %esp,%eax # pt_regs pointer
15535 call *%edi
15536 jmp ret_from_exception
15537 CFI_ENDPROC
15538 -END(page_fault)
15539 +ENDPROC(page_fault)
15540
15541 /*
15542 * Debug traps and NMI can happen at the one SYSENTER instruction
15543 @@ -1291,7 +1537,7 @@ debug_stack_correct:
15544 call do_debug
15545 jmp ret_from_exception
15546 CFI_ENDPROC
15547 -END(debug)
15548 +ENDPROC(debug)
15549
15550 /*
15551 * NMI is doubly nasty. It can happen _while_ we're handling
15552 @@ -1328,6 +1574,9 @@ nmi_stack_correct:
15553 xorl %edx,%edx # zero error code
15554 movl %esp,%eax # pt_regs pointer
15555 call do_nmi
15556 +
15557 + pax_exit_kernel
15558 +
15559 jmp restore_all_notrace
15560 CFI_ENDPROC
15561
15562 @@ -1364,12 +1613,15 @@ nmi_espfix_stack:
15563 FIXUP_ESPFIX_STACK # %eax == %esp
15564 xorl %edx,%edx # zero error code
15565 call do_nmi
15566 +
15567 + pax_exit_kernel
15568 +
15569 RESTORE_REGS
15570 lss 12+4(%esp), %esp # back to espfix stack
15571 CFI_ADJUST_CFA_OFFSET -24
15572 jmp irq_return
15573 CFI_ENDPROC
15574 -END(nmi)
15575 +ENDPROC(nmi)
15576
15577 ENTRY(int3)
15578 RING0_INT_FRAME
15579 @@ -1381,14 +1633,14 @@ ENTRY(int3)
15580 call do_int3
15581 jmp ret_from_exception
15582 CFI_ENDPROC
15583 -END(int3)
15584 +ENDPROC(int3)
15585
15586 ENTRY(general_protection)
15587 RING0_EC_FRAME
15588 pushl_cfi $do_general_protection
15589 jmp error_code
15590 CFI_ENDPROC
15591 -END(general_protection)
15592 +ENDPROC(general_protection)
15593
15594 #ifdef CONFIG_KVM_GUEST
15595 ENTRY(async_page_fault)
15596 @@ -1396,7 +1648,7 @@ ENTRY(async_page_fault)
15597 pushl_cfi $do_async_page_fault
15598 jmp error_code
15599 CFI_ENDPROC
15600 -END(async_page_fault)
15601 +ENDPROC(async_page_fault)
15602 #endif
15603
15604 /*
15605 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15606 index 7d65133..27bce5b 100644
15607 --- a/arch/x86/kernel/entry_64.S
15608 +++ b/arch/x86/kernel/entry_64.S
15609 @@ -57,6 +57,8 @@
15610 #include <asm/percpu.h>
15611 #include <asm/asm.h>
15612 #include <linux/err.h>
15613 +#include <asm/pgtable.h>
15614 +#include <asm/alternative-asm.h>
15615
15616 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15617 #include <linux/elf-em.h>
15618 @@ -70,8 +72,9 @@
15619 #ifdef CONFIG_FUNCTION_TRACER
15620 #ifdef CONFIG_DYNAMIC_FTRACE
15621 ENTRY(mcount)
15622 + pax_force_retaddr
15623 retq
15624 -END(mcount)
15625 +ENDPROC(mcount)
15626
15627 ENTRY(ftrace_caller)
15628 cmpl $0, function_trace_stop
15629 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15630 #endif
15631
15632 GLOBAL(ftrace_stub)
15633 + pax_force_retaddr
15634 retq
15635 -END(ftrace_caller)
15636 +ENDPROC(ftrace_caller)
15637
15638 #else /* ! CONFIG_DYNAMIC_FTRACE */
15639 ENTRY(mcount)
15640 @@ -114,6 +118,7 @@ ENTRY(mcount)
15641 #endif
15642
15643 GLOBAL(ftrace_stub)
15644 + pax_force_retaddr
15645 retq
15646
15647 trace:
15648 @@ -123,12 +128,13 @@ trace:
15649 movq 8(%rbp), %rsi
15650 subq $MCOUNT_INSN_SIZE, %rdi
15651
15652 + pax_force_fptr ftrace_trace_function
15653 call *ftrace_trace_function
15654
15655 MCOUNT_RESTORE_FRAME
15656
15657 jmp ftrace_stub
15658 -END(mcount)
15659 +ENDPROC(mcount)
15660 #endif /* CONFIG_DYNAMIC_FTRACE */
15661 #endif /* CONFIG_FUNCTION_TRACER */
15662
15663 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15664
15665 MCOUNT_RESTORE_FRAME
15666
15667 + pax_force_retaddr
15668 retq
15669 -END(ftrace_graph_caller)
15670 +ENDPROC(ftrace_graph_caller)
15671
15672 GLOBAL(return_to_handler)
15673 subq $24, %rsp
15674 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15675 movq 8(%rsp), %rdx
15676 movq (%rsp), %rax
15677 addq $24, %rsp
15678 + pax_force_fptr %rdi
15679 jmp *%rdi
15680 #endif
15681
15682 @@ -180,6 +188,282 @@ ENTRY(native_usergs_sysret64)
15683 ENDPROC(native_usergs_sysret64)
15684 #endif /* CONFIG_PARAVIRT */
15685
15686 + .macro ljmpq sel, off
15687 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15688 + .byte 0x48; ljmp *1234f(%rip)
15689 + .pushsection .rodata
15690 + .align 16
15691 + 1234: .quad \off; .word \sel
15692 + .popsection
15693 +#else
15694 + pushq $\sel
15695 + pushq $\off
15696 + lretq
15697 +#endif
15698 + .endm
15699 +
15700 + .macro pax_enter_kernel
15701 + pax_set_fptr_mask
15702 +#ifdef CONFIG_PAX_KERNEXEC
15703 + call pax_enter_kernel
15704 +#endif
15705 + .endm
15706 +
15707 + .macro pax_exit_kernel
15708 +#ifdef CONFIG_PAX_KERNEXEC
15709 + call pax_exit_kernel
15710 +#endif
15711 + .endm
15712 +
15713 +#ifdef CONFIG_PAX_KERNEXEC
15714 +ENTRY(pax_enter_kernel)
15715 + pushq %rdi
15716 +
15717 +#ifdef CONFIG_PARAVIRT
15718 + PV_SAVE_REGS(CLBR_RDI)
15719 +#endif
15720 +
15721 + GET_CR0_INTO_RDI
15722 + bts $16,%rdi
15723 + jnc 3f
15724 + mov %cs,%edi
15725 + cmp $__KERNEL_CS,%edi
15726 + jnz 2f
15727 +1:
15728 +
15729 +#ifdef CONFIG_PARAVIRT
15730 + PV_RESTORE_REGS(CLBR_RDI)
15731 +#endif
15732 +
15733 + popq %rdi
15734 + pax_force_retaddr
15735 + retq
15736 +
15737 +2: ljmpq __KERNEL_CS,1f
15738 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15739 +4: SET_RDI_INTO_CR0
15740 + jmp 1b
15741 +ENDPROC(pax_enter_kernel)
15742 +
15743 +ENTRY(pax_exit_kernel)
15744 + pushq %rdi
15745 +
15746 +#ifdef CONFIG_PARAVIRT
15747 + PV_SAVE_REGS(CLBR_RDI)
15748 +#endif
15749 +
15750 + mov %cs,%rdi
15751 + cmp $__KERNEXEC_KERNEL_CS,%edi
15752 + jz 2f
15753 +1:
15754 +
15755 +#ifdef CONFIG_PARAVIRT
15756 + PV_RESTORE_REGS(CLBR_RDI);
15757 +#endif
15758 +
15759 + popq %rdi
15760 + pax_force_retaddr
15761 + retq
15762 +
15763 +2: GET_CR0_INTO_RDI
15764 + btr $16,%rdi
15765 + ljmpq __KERNEL_CS,3f
15766 +3: SET_RDI_INTO_CR0
15767 + jmp 1b
15768 +#ifdef CONFIG_PARAVIRT
15769 + PV_RESTORE_REGS(CLBR_RDI);
15770 +#endif
15771 +
15772 + popq %rdi
15773 + pax_force_retaddr
15774 + retq
15775 +ENDPROC(pax_exit_kernel)
15776 +#endif
15777 +
15778 + .macro pax_enter_kernel_user
15779 + pax_set_fptr_mask
15780 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15781 + call pax_enter_kernel_user
15782 +#endif
15783 + .endm
15784 +
15785 + .macro pax_exit_kernel_user
15786 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15787 + call pax_exit_kernel_user
15788 +#endif
15789 +#ifdef CONFIG_PAX_RANDKSTACK
15790 + pushq %rax
15791 + call pax_randomize_kstack
15792 + popq %rax
15793 +#endif
15794 + .endm
15795 +
15796 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15797 +ENTRY(pax_enter_kernel_user)
15798 + pushq %rdi
15799 + pushq %rbx
15800 +
15801 +#ifdef CONFIG_PARAVIRT
15802 + PV_SAVE_REGS(CLBR_RDI)
15803 +#endif
15804 +
15805 + GET_CR3_INTO_RDI
15806 + mov %rdi,%rbx
15807 + add $__START_KERNEL_map,%rbx
15808 + sub phys_base(%rip),%rbx
15809 +
15810 +#ifdef CONFIG_PARAVIRT
15811 + pushq %rdi
15812 + cmpl $0, pv_info+PARAVIRT_enabled
15813 + jz 1f
15814 + i = 0
15815 + .rept USER_PGD_PTRS
15816 + mov i*8(%rbx),%rsi
15817 + mov $0,%sil
15818 + lea i*8(%rbx),%rdi
15819 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15820 + i = i + 1
15821 + .endr
15822 + jmp 2f
15823 +1:
15824 +#endif
15825 +
15826 + i = 0
15827 + .rept USER_PGD_PTRS
15828 + movb $0,i*8(%rbx)
15829 + i = i + 1
15830 + .endr
15831 +
15832 +#ifdef CONFIG_PARAVIRT
15833 +2: popq %rdi
15834 +#endif
15835 + SET_RDI_INTO_CR3
15836 +
15837 +#ifdef CONFIG_PAX_KERNEXEC
15838 + GET_CR0_INTO_RDI
15839 + bts $16,%rdi
15840 + SET_RDI_INTO_CR0
15841 +#endif
15842 +
15843 +#ifdef CONFIG_PARAVIRT
15844 + PV_RESTORE_REGS(CLBR_RDI)
15845 +#endif
15846 +
15847 + popq %rbx
15848 + popq %rdi
15849 + pax_force_retaddr
15850 + retq
15851 +ENDPROC(pax_enter_kernel_user)
15852 +
15853 +ENTRY(pax_exit_kernel_user)
15854 + push %rdi
15855 +
15856 +#ifdef CONFIG_PARAVIRT
15857 + pushq %rbx
15858 + PV_SAVE_REGS(CLBR_RDI)
15859 +#endif
15860 +
15861 +#ifdef CONFIG_PAX_KERNEXEC
15862 + GET_CR0_INTO_RDI
15863 + btr $16,%rdi
15864 + SET_RDI_INTO_CR0
15865 +#endif
15866 +
15867 + GET_CR3_INTO_RDI
15868 + add $__START_KERNEL_map,%rdi
15869 + sub phys_base(%rip),%rdi
15870 +
15871 +#ifdef CONFIG_PARAVIRT
15872 + cmpl $0, pv_info+PARAVIRT_enabled
15873 + jz 1f
15874 + mov %rdi,%rbx
15875 + i = 0
15876 + .rept USER_PGD_PTRS
15877 + mov i*8(%rbx),%rsi
15878 + mov $0x67,%sil
15879 + lea i*8(%rbx),%rdi
15880 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15881 + i = i + 1
15882 + .endr
15883 + jmp 2f
15884 +1:
15885 +#endif
15886 +
15887 + i = 0
15888 + .rept USER_PGD_PTRS
15889 + movb $0x67,i*8(%rdi)
15890 + i = i + 1
15891 + .endr
15892 +
15893 +#ifdef CONFIG_PARAVIRT
15894 +2: PV_RESTORE_REGS(CLBR_RDI)
15895 + popq %rbx
15896 +#endif
15897 +
15898 + popq %rdi
15899 + pax_force_retaddr
15900 + retq
15901 +ENDPROC(pax_exit_kernel_user)
15902 +#endif
15903 +
15904 +.macro pax_erase_kstack
15905 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15906 + call pax_erase_kstack
15907 +#endif
15908 +.endm
15909 +
15910 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15911 +/*
15912 + * r11: thread_info
15913 + * rcx, rdx: can be clobbered
15914 + */
15915 +ENTRY(pax_erase_kstack)
15916 + pushq %rdi
15917 + pushq %rax
15918 + pushq %r11
15919 +
15920 + GET_THREAD_INFO(%r11)
15921 + mov TI_lowest_stack(%r11), %rdi
15922 + mov $-0xBEEF, %rax
15923 + std
15924 +
15925 +1: mov %edi, %ecx
15926 + and $THREAD_SIZE_asm - 1, %ecx
15927 + shr $3, %ecx
15928 + repne scasq
15929 + jecxz 2f
15930 +
15931 + cmp $2*8, %ecx
15932 + jc 2f
15933 +
15934 + mov $2*8, %ecx
15935 + repe scasq
15936 + jecxz 2f
15937 + jne 1b
15938 +
15939 +2: cld
15940 + mov %esp, %ecx
15941 + sub %edi, %ecx
15942 +
15943 + cmp $THREAD_SIZE_asm, %rcx
15944 + jb 3f
15945 + ud2
15946 +3:
15947 +
15948 + shr $3, %ecx
15949 + rep stosq
15950 +
15951 + mov TI_task_thread_sp0(%r11), %rdi
15952 + sub $256, %rdi
15953 + mov %rdi, TI_lowest_stack(%r11)
15954 +
15955 + popq %r11
15956 + popq %rax
15957 + popq %rdi
15958 + pax_force_retaddr
15959 + ret
15960 +ENDPROC(pax_erase_kstack)
15961 +#endif
15962
15963 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15964 #ifdef CONFIG_TRACE_IRQFLAGS
15965 @@ -271,8 +555,8 @@ ENDPROC(native_usergs_sysret64)
15966 .endm
15967
15968 .macro UNFAKE_STACK_FRAME
15969 - addq $8*6, %rsp
15970 - CFI_ADJUST_CFA_OFFSET -(6*8)
15971 + addq $8*6 + ARG_SKIP, %rsp
15972 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15973 .endm
15974
15975 /*
15976 @@ -359,7 +643,7 @@ ENDPROC(native_usergs_sysret64)
15977 movq %rsp, %rsi
15978
15979 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15980 - testl $3, CS-RBP(%rsi)
15981 + testb $3, CS-RBP(%rsi)
15982 je 1f
15983 SWAPGS
15984 /*
15985 @@ -394,9 +678,10 @@ ENTRY(save_rest)
15986 movq_cfi r15, R15+16
15987 movq %r11, 8(%rsp) /* return address */
15988 FIXUP_TOP_OF_STACK %r11, 16
15989 + pax_force_retaddr
15990 ret
15991 CFI_ENDPROC
15992 -END(save_rest)
15993 +ENDPROC(save_rest)
15994
15995 /* save complete stack frame */
15996 .pushsection .kprobes.text, "ax"
15997 @@ -425,9 +710,10 @@ ENTRY(save_paranoid)
15998 js 1f /* negative -> in kernel */
15999 SWAPGS
16000 xorl %ebx,%ebx
16001 -1: ret
16002 +1: pax_force_retaddr_bts
16003 + ret
16004 CFI_ENDPROC
16005 -END(save_paranoid)
16006 +ENDPROC(save_paranoid)
16007 .popsection
16008
16009 /*
16010 @@ -449,7 +735,7 @@ ENTRY(ret_from_fork)
16011
16012 RESTORE_REST
16013
16014 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16015 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16016 jz retint_restore_args
16017
16018 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16019 @@ -459,7 +745,7 @@ ENTRY(ret_from_fork)
16020 jmp ret_from_sys_call # go to the SYSRET fastpath
16021
16022 CFI_ENDPROC
16023 -END(ret_from_fork)
16024 +ENDPROC(ret_from_fork)
16025
16026 /*
16027 * System call entry. Up to 6 arguments in registers are supported.
16028 @@ -495,7 +781,7 @@ END(ret_from_fork)
16029 ENTRY(system_call)
16030 CFI_STARTPROC simple
16031 CFI_SIGNAL_FRAME
16032 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16033 + CFI_DEF_CFA rsp,0
16034 CFI_REGISTER rip,rcx
16035 /*CFI_REGISTER rflags,r11*/
16036 SWAPGS_UNSAFE_STACK
16037 @@ -508,16 +794,18 @@ GLOBAL(system_call_after_swapgs)
16038
16039 movq %rsp,PER_CPU_VAR(old_rsp)
16040 movq PER_CPU_VAR(kernel_stack),%rsp
16041 + SAVE_ARGS 8*6,0
16042 + pax_enter_kernel_user
16043 /*
16044 * No need to follow this irqs off/on section - it's straight
16045 * and short:
16046 */
16047 ENABLE_INTERRUPTS(CLBR_NONE)
16048 - SAVE_ARGS 8,0
16049 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16050 movq %rcx,RIP-ARGOFFSET(%rsp)
16051 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16052 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16053 + GET_THREAD_INFO(%rcx)
16054 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16055 jnz tracesys
16056 system_call_fastpath:
16057 #if __SYSCALL_MASK == ~0
16058 @@ -527,7 +815,7 @@ system_call_fastpath:
16059 cmpl $__NR_syscall_max,%eax
16060 #endif
16061 ja badsys
16062 - movq %r10,%rcx
16063 + movq R10-ARGOFFSET(%rsp),%rcx
16064 call *sys_call_table(,%rax,8) # XXX: rip relative
16065 movq %rax,RAX-ARGOFFSET(%rsp)
16066 /*
16067 @@ -541,10 +829,13 @@ sysret_check:
16068 LOCKDEP_SYS_EXIT
16069 DISABLE_INTERRUPTS(CLBR_NONE)
16070 TRACE_IRQS_OFF
16071 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16072 + GET_THREAD_INFO(%rcx)
16073 + movl TI_flags(%rcx),%edx
16074 andl %edi,%edx
16075 jnz sysret_careful
16076 CFI_REMEMBER_STATE
16077 + pax_exit_kernel_user
16078 + pax_erase_kstack
16079 /*
16080 * sysretq will re-enable interrupts:
16081 */
16082 @@ -596,14 +887,18 @@ badsys:
16083 * jump back to the normal fast path.
16084 */
16085 auditsys:
16086 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16087 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16088 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16089 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16090 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16091 movq %rax,%rsi /* 2nd arg: syscall number */
16092 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16093 call __audit_syscall_entry
16094 +
16095 + pax_erase_kstack
16096 +
16097 LOAD_ARGS 0 /* reload call-clobbered registers */
16098 + pax_set_fptr_mask
16099 jmp system_call_fastpath
16100
16101 /*
16102 @@ -624,7 +919,7 @@ sysret_audit:
16103 /* Do syscall tracing */
16104 tracesys:
16105 #ifdef CONFIG_AUDITSYSCALL
16106 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16107 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16108 jz auditsys
16109 #endif
16110 SAVE_REST
16111 @@ -632,12 +927,16 @@ tracesys:
16112 FIXUP_TOP_OF_STACK %rdi
16113 movq %rsp,%rdi
16114 call syscall_trace_enter
16115 +
16116 + pax_erase_kstack
16117 +
16118 /*
16119 * Reload arg registers from stack in case ptrace changed them.
16120 * We don't reload %rax because syscall_trace_enter() returned
16121 * the value it wants us to use in the table lookup.
16122 */
16123 LOAD_ARGS ARGOFFSET, 1
16124 + pax_set_fptr_mask
16125 RESTORE_REST
16126 #if __SYSCALL_MASK == ~0
16127 cmpq $__NR_syscall_max,%rax
16128 @@ -646,7 +945,7 @@ tracesys:
16129 cmpl $__NR_syscall_max,%eax
16130 #endif
16131 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16132 - movq %r10,%rcx /* fixup for C */
16133 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16134 call *sys_call_table(,%rax,8)
16135 movq %rax,RAX-ARGOFFSET(%rsp)
16136 /* Use IRET because user could have changed frame */
16137 @@ -667,6 +966,7 @@ GLOBAL(int_with_check)
16138 andl %edi,%edx
16139 jnz int_careful
16140 andl $~TS_COMPAT,TI_status(%rcx)
16141 + pax_erase_kstack
16142 jmp retint_swapgs
16143
16144 /* Either reschedule or signal or syscall exit tracking needed. */
16145 @@ -713,7 +1013,7 @@ int_restore_rest:
16146 TRACE_IRQS_OFF
16147 jmp int_with_check
16148 CFI_ENDPROC
16149 -END(system_call)
16150 +ENDPROC(system_call)
16151
16152 /*
16153 * Certain special system calls that need to save a complete full stack frame.
16154 @@ -729,7 +1029,7 @@ ENTRY(\label)
16155 call \func
16156 jmp ptregscall_common
16157 CFI_ENDPROC
16158 -END(\label)
16159 +ENDPROC(\label)
16160 .endm
16161
16162 PTREGSCALL stub_clone, sys_clone, %r8
16163 @@ -747,9 +1047,10 @@ ENTRY(ptregscall_common)
16164 movq_cfi_restore R12+8, r12
16165 movq_cfi_restore RBP+8, rbp
16166 movq_cfi_restore RBX+8, rbx
16167 + pax_force_retaddr
16168 ret $REST_SKIP /* pop extended registers */
16169 CFI_ENDPROC
16170 -END(ptregscall_common)
16171 +ENDPROC(ptregscall_common)
16172
16173 ENTRY(stub_execve)
16174 CFI_STARTPROC
16175 @@ -764,7 +1065,7 @@ ENTRY(stub_execve)
16176 RESTORE_REST
16177 jmp int_ret_from_sys_call
16178 CFI_ENDPROC
16179 -END(stub_execve)
16180 +ENDPROC(stub_execve)
16181
16182 /*
16183 * sigreturn is special because it needs to restore all registers on return.
16184 @@ -782,7 +1083,7 @@ ENTRY(stub_rt_sigreturn)
16185 RESTORE_REST
16186 jmp int_ret_from_sys_call
16187 CFI_ENDPROC
16188 -END(stub_rt_sigreturn)
16189 +ENDPROC(stub_rt_sigreturn)
16190
16191 #ifdef CONFIG_X86_X32_ABI
16192 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16193 @@ -851,7 +1152,7 @@ vector=vector+1
16194 2: jmp common_interrupt
16195 .endr
16196 CFI_ENDPROC
16197 -END(irq_entries_start)
16198 +ENDPROC(irq_entries_start)
16199
16200 .previous
16201 END(interrupt)
16202 @@ -871,6 +1172,16 @@ END(interrupt)
16203 subq $ORIG_RAX-RBP, %rsp
16204 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16205 SAVE_ARGS_IRQ
16206 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16207 + testb $3, CS(%rdi)
16208 + jnz 1f
16209 + pax_enter_kernel
16210 + jmp 2f
16211 +1: pax_enter_kernel_user
16212 +2:
16213 +#else
16214 + pax_enter_kernel
16215 +#endif
16216 call \func
16217 .endm
16218
16219 @@ -902,7 +1213,7 @@ ret_from_intr:
16220
16221 exit_intr:
16222 GET_THREAD_INFO(%rcx)
16223 - testl $3,CS-ARGOFFSET(%rsp)
16224 + testb $3,CS-ARGOFFSET(%rsp)
16225 je retint_kernel
16226
16227 /* Interrupt came from user space */
16228 @@ -924,12 +1235,15 @@ retint_swapgs: /* return to user-space */
16229 * The iretq could re-enable interrupts:
16230 */
16231 DISABLE_INTERRUPTS(CLBR_ANY)
16232 + pax_exit_kernel_user
16233 TRACE_IRQS_IRETQ
16234 SWAPGS
16235 jmp restore_args
16236
16237 retint_restore_args: /* return to kernel space */
16238 DISABLE_INTERRUPTS(CLBR_ANY)
16239 + pax_exit_kernel
16240 + pax_force_retaddr RIP-ARGOFFSET
16241 /*
16242 * The iretq could re-enable interrupts:
16243 */
16244 @@ -1012,7 +1326,7 @@ ENTRY(retint_kernel)
16245 #endif
16246
16247 CFI_ENDPROC
16248 -END(common_interrupt)
16249 +ENDPROC(common_interrupt)
16250 /*
16251 * End of kprobes section
16252 */
16253 @@ -1029,7 +1343,7 @@ ENTRY(\sym)
16254 interrupt \do_sym
16255 jmp ret_from_intr
16256 CFI_ENDPROC
16257 -END(\sym)
16258 +ENDPROC(\sym)
16259 .endm
16260
16261 #ifdef CONFIG_SMP
16262 @@ -1102,12 +1416,22 @@ ENTRY(\sym)
16263 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16264 call error_entry
16265 DEFAULT_FRAME 0
16266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16267 + testb $3, CS(%rsp)
16268 + jnz 1f
16269 + pax_enter_kernel
16270 + jmp 2f
16271 +1: pax_enter_kernel_user
16272 +2:
16273 +#else
16274 + pax_enter_kernel
16275 +#endif
16276 movq %rsp,%rdi /* pt_regs pointer */
16277 xorl %esi,%esi /* no error code */
16278 call \do_sym
16279 jmp error_exit /* %ebx: no swapgs flag */
16280 CFI_ENDPROC
16281 -END(\sym)
16282 +ENDPROC(\sym)
16283 .endm
16284
16285 .macro paranoidzeroentry sym do_sym
16286 @@ -1119,15 +1443,25 @@ ENTRY(\sym)
16287 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16288 call save_paranoid
16289 TRACE_IRQS_OFF
16290 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16291 + testb $3, CS(%rsp)
16292 + jnz 1f
16293 + pax_enter_kernel
16294 + jmp 2f
16295 +1: pax_enter_kernel_user
16296 +2:
16297 +#else
16298 + pax_enter_kernel
16299 +#endif
16300 movq %rsp,%rdi /* pt_regs pointer */
16301 xorl %esi,%esi /* no error code */
16302 call \do_sym
16303 jmp paranoid_exit /* %ebx: no swapgs flag */
16304 CFI_ENDPROC
16305 -END(\sym)
16306 +ENDPROC(\sym)
16307 .endm
16308
16309 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16310 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16311 .macro paranoidzeroentry_ist sym do_sym ist
16312 ENTRY(\sym)
16313 INTR_FRAME
16314 @@ -1137,14 +1471,30 @@ ENTRY(\sym)
16315 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16316 call save_paranoid
16317 TRACE_IRQS_OFF_DEBUG
16318 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16319 + testb $3, CS(%rsp)
16320 + jnz 1f
16321 + pax_enter_kernel
16322 + jmp 2f
16323 +1: pax_enter_kernel_user
16324 +2:
16325 +#else
16326 + pax_enter_kernel
16327 +#endif
16328 movq %rsp,%rdi /* pt_regs pointer */
16329 xorl %esi,%esi /* no error code */
16330 +#ifdef CONFIG_SMP
16331 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16332 + lea init_tss(%r12), %r12
16333 +#else
16334 + lea init_tss(%rip), %r12
16335 +#endif
16336 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16337 call \do_sym
16338 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16339 jmp paranoid_exit /* %ebx: no swapgs flag */
16340 CFI_ENDPROC
16341 -END(\sym)
16342 +ENDPROC(\sym)
16343 .endm
16344
16345 .macro errorentry sym do_sym
16346 @@ -1155,13 +1505,23 @@ ENTRY(\sym)
16347 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16348 call error_entry
16349 DEFAULT_FRAME 0
16350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16351 + testb $3, CS(%rsp)
16352 + jnz 1f
16353 + pax_enter_kernel
16354 + jmp 2f
16355 +1: pax_enter_kernel_user
16356 +2:
16357 +#else
16358 + pax_enter_kernel
16359 +#endif
16360 movq %rsp,%rdi /* pt_regs pointer */
16361 movq ORIG_RAX(%rsp),%rsi /* get error code */
16362 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16363 call \do_sym
16364 jmp error_exit /* %ebx: no swapgs flag */
16365 CFI_ENDPROC
16366 -END(\sym)
16367 +ENDPROC(\sym)
16368 .endm
16369
16370 /* error code is on the stack already */
16371 @@ -1174,13 +1534,23 @@ ENTRY(\sym)
16372 call save_paranoid
16373 DEFAULT_FRAME 0
16374 TRACE_IRQS_OFF
16375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16376 + testb $3, CS(%rsp)
16377 + jnz 1f
16378 + pax_enter_kernel
16379 + jmp 2f
16380 +1: pax_enter_kernel_user
16381 +2:
16382 +#else
16383 + pax_enter_kernel
16384 +#endif
16385 movq %rsp,%rdi /* pt_regs pointer */
16386 movq ORIG_RAX(%rsp),%rsi /* get error code */
16387 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16388 call \do_sym
16389 jmp paranoid_exit /* %ebx: no swapgs flag */
16390 CFI_ENDPROC
16391 -END(\sym)
16392 +ENDPROC(\sym)
16393 .endm
16394
16395 zeroentry divide_error do_divide_error
16396 @@ -1210,9 +1580,10 @@ gs_change:
16397 2: mfence /* workaround */
16398 SWAPGS
16399 popfq_cfi
16400 + pax_force_retaddr
16401 ret
16402 CFI_ENDPROC
16403 -END(native_load_gs_index)
16404 +ENDPROC(native_load_gs_index)
16405
16406 _ASM_EXTABLE(gs_change,bad_gs)
16407 .section .fixup,"ax"
16408 @@ -1231,13 +1602,14 @@ ENTRY(kernel_thread_helper)
16409 * Here we are in the child and the registers are set as they were
16410 * at kernel_thread() invocation in the parent.
16411 */
16412 + pax_force_fptr %rsi
16413 call *%rsi
16414 # exit
16415 mov %eax, %edi
16416 call do_exit
16417 ud2 # padding for call trace
16418 CFI_ENDPROC
16419 -END(kernel_thread_helper)
16420 +ENDPROC(kernel_thread_helper)
16421
16422 /*
16423 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16424 @@ -1264,11 +1636,11 @@ ENTRY(kernel_execve)
16425 RESTORE_REST
16426 testq %rax,%rax
16427 je int_ret_from_sys_call
16428 - RESTORE_ARGS
16429 UNFAKE_STACK_FRAME
16430 + pax_force_retaddr
16431 ret
16432 CFI_ENDPROC
16433 -END(kernel_execve)
16434 +ENDPROC(kernel_execve)
16435
16436 /* Call softirq on interrupt stack. Interrupts are off. */
16437 ENTRY(call_softirq)
16438 @@ -1286,9 +1658,10 @@ ENTRY(call_softirq)
16439 CFI_DEF_CFA_REGISTER rsp
16440 CFI_ADJUST_CFA_OFFSET -8
16441 decl PER_CPU_VAR(irq_count)
16442 + pax_force_retaddr
16443 ret
16444 CFI_ENDPROC
16445 -END(call_softirq)
16446 +ENDPROC(call_softirq)
16447
16448 #ifdef CONFIG_XEN
16449 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16450 @@ -1326,7 +1699,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16451 decl PER_CPU_VAR(irq_count)
16452 jmp error_exit
16453 CFI_ENDPROC
16454 -END(xen_do_hypervisor_callback)
16455 +ENDPROC(xen_do_hypervisor_callback)
16456
16457 /*
16458 * Hypervisor uses this for application faults while it executes.
16459 @@ -1385,7 +1758,7 @@ ENTRY(xen_failsafe_callback)
16460 SAVE_ALL
16461 jmp error_exit
16462 CFI_ENDPROC
16463 -END(xen_failsafe_callback)
16464 +ENDPROC(xen_failsafe_callback)
16465
16466 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16467 xen_hvm_callback_vector xen_evtchn_do_upcall
16468 @@ -1434,16 +1807,31 @@ ENTRY(paranoid_exit)
16469 TRACE_IRQS_OFF_DEBUG
16470 testl %ebx,%ebx /* swapgs needed? */
16471 jnz paranoid_restore
16472 - testl $3,CS(%rsp)
16473 + testb $3,CS(%rsp)
16474 jnz paranoid_userspace
16475 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16476 + pax_exit_kernel
16477 + TRACE_IRQS_IRETQ 0
16478 + SWAPGS_UNSAFE_STACK
16479 + RESTORE_ALL 8
16480 + pax_force_retaddr_bts
16481 + jmp irq_return
16482 +#endif
16483 paranoid_swapgs:
16484 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16485 + pax_exit_kernel_user
16486 +#else
16487 + pax_exit_kernel
16488 +#endif
16489 TRACE_IRQS_IRETQ 0
16490 SWAPGS_UNSAFE_STACK
16491 RESTORE_ALL 8
16492 jmp irq_return
16493 paranoid_restore:
16494 + pax_exit_kernel
16495 TRACE_IRQS_IRETQ_DEBUG 0
16496 RESTORE_ALL 8
16497 + pax_force_retaddr_bts
16498 jmp irq_return
16499 paranoid_userspace:
16500 GET_THREAD_INFO(%rcx)
16501 @@ -1472,7 +1860,7 @@ paranoid_schedule:
16502 TRACE_IRQS_OFF
16503 jmp paranoid_userspace
16504 CFI_ENDPROC
16505 -END(paranoid_exit)
16506 +ENDPROC(paranoid_exit)
16507
16508 /*
16509 * Exception entry point. This expects an error code/orig_rax on the stack.
16510 @@ -1499,12 +1887,13 @@ ENTRY(error_entry)
16511 movq_cfi r14, R14+8
16512 movq_cfi r15, R15+8
16513 xorl %ebx,%ebx
16514 - testl $3,CS+8(%rsp)
16515 + testb $3,CS+8(%rsp)
16516 je error_kernelspace
16517 error_swapgs:
16518 SWAPGS
16519 error_sti:
16520 TRACE_IRQS_OFF
16521 + pax_force_retaddr_bts
16522 ret
16523
16524 /*
16525 @@ -1531,7 +1920,7 @@ bstep_iret:
16526 movq %rcx,RIP+8(%rsp)
16527 jmp error_swapgs
16528 CFI_ENDPROC
16529 -END(error_entry)
16530 +ENDPROC(error_entry)
16531
16532
16533 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16534 @@ -1551,7 +1940,7 @@ ENTRY(error_exit)
16535 jnz retint_careful
16536 jmp retint_swapgs
16537 CFI_ENDPROC
16538 -END(error_exit)
16539 +ENDPROC(error_exit)
16540
16541 /*
16542 * Test if a given stack is an NMI stack or not.
16543 @@ -1609,9 +1998,11 @@ ENTRY(nmi)
16544 * If %cs was not the kernel segment, then the NMI triggered in user
16545 * space, which means it is definitely not nested.
16546 */
16547 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16548 + je 1f
16549 cmpl $__KERNEL_CS, 16(%rsp)
16550 jne first_nmi
16551 -
16552 +1:
16553 /*
16554 * Check the special variable on the stack to see if NMIs are
16555 * executing.
16556 @@ -1758,6 +2149,16 @@ end_repeat_nmi:
16557 */
16558 call save_paranoid
16559 DEFAULT_FRAME 0
16560 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16561 + testb $3, CS(%rsp)
16562 + jnz 1f
16563 + pax_enter_kernel
16564 + jmp 2f
16565 +1: pax_enter_kernel_user
16566 +2:
16567 +#else
16568 + pax_enter_kernel
16569 +#endif
16570 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16571 movq %rsp,%rdi
16572 movq $-1,%rsi
16573 @@ -1765,21 +2166,32 @@ end_repeat_nmi:
16574 testl %ebx,%ebx /* swapgs needed? */
16575 jnz nmi_restore
16576 nmi_swapgs:
16577 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16578 + pax_exit_kernel_user
16579 +#else
16580 + pax_exit_kernel
16581 +#endif
16582 SWAPGS_UNSAFE_STACK
16583 + RESTORE_ALL 8
16584 + /* Clear the NMI executing stack variable */
16585 + movq $0, 10*8(%rsp)
16586 + jmp irq_return
16587 nmi_restore:
16588 + pax_exit_kernel
16589 RESTORE_ALL 8
16590 + pax_force_retaddr_bts
16591 /* Clear the NMI executing stack variable */
16592 movq $0, 10*8(%rsp)
16593 jmp irq_return
16594 CFI_ENDPROC
16595 -END(nmi)
16596 +ENDPROC(nmi)
16597
16598 ENTRY(ignore_sysret)
16599 CFI_STARTPROC
16600 mov $-ENOSYS,%eax
16601 sysret
16602 CFI_ENDPROC
16603 -END(ignore_sysret)
16604 +ENDPROC(ignore_sysret)
16605
16606 /*
16607 * End of kprobes section
16608 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16609 index c3a7cb4..3ad00dc 100644
16610 --- a/arch/x86/kernel/ftrace.c
16611 +++ b/arch/x86/kernel/ftrace.c
16612 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16613 {
16614 unsigned char replaced[MCOUNT_INSN_SIZE];
16615
16616 + ip = ktla_ktva(ip);
16617 +
16618 /*
16619 * Note: Due to modules and __init, code can
16620 * disappear and change, we need to protect against faulting
16621 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16622 unsigned char old[MCOUNT_INSN_SIZE], *new;
16623 int ret;
16624
16625 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16626 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16627 new = ftrace_call_replace(ip, (unsigned long)func);
16628
16629 /* See comment above by declaration of modifying_ftrace_code */
16630 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16631 {
16632 unsigned char code[MCOUNT_INSN_SIZE];
16633
16634 + ip = ktla_ktva(ip);
16635 +
16636 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16637 return -EFAULT;
16638
16639 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16640 index c18f59d..9c0c9f6 100644
16641 --- a/arch/x86/kernel/head32.c
16642 +++ b/arch/x86/kernel/head32.c
16643 @@ -18,6 +18,7 @@
16644 #include <asm/io_apic.h>
16645 #include <asm/bios_ebda.h>
16646 #include <asm/tlbflush.h>
16647 +#include <asm/boot.h>
16648
16649 static void __init i386_default_early_setup(void)
16650 {
16651 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16652
16653 void __init i386_start_kernel(void)
16654 {
16655 - memblock_reserve(__pa_symbol(&_text),
16656 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16657 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16658
16659 #ifdef CONFIG_BLK_DEV_INITRD
16660 /* Reserve INITRD */
16661 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16662 index d42ab17..cb1b997 100644
16663 --- a/arch/x86/kernel/head_32.S
16664 +++ b/arch/x86/kernel/head_32.S
16665 @@ -26,6 +26,12 @@
16666 /* Physical address */
16667 #define pa(X) ((X) - __PAGE_OFFSET)
16668
16669 +#ifdef CONFIG_PAX_KERNEXEC
16670 +#define ta(X) (X)
16671 +#else
16672 +#define ta(X) ((X) - __PAGE_OFFSET)
16673 +#endif
16674 +
16675 /*
16676 * References to members of the new_cpu_data structure.
16677 */
16678 @@ -55,11 +61,7 @@
16679 * and small than max_low_pfn, otherwise will waste some page table entries
16680 */
16681
16682 -#if PTRS_PER_PMD > 1
16683 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16684 -#else
16685 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16686 -#endif
16687 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16688
16689 /* Number of possible pages in the lowmem region */
16690 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16691 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16692 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16693
16694 /*
16695 + * Real beginning of normal "text" segment
16696 + */
16697 +ENTRY(stext)
16698 +ENTRY(_stext)
16699 +
16700 +/*
16701 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16702 * %esi points to the real-mode code as a 32-bit pointer.
16703 * CS and DS must be 4 GB flat segments, but we don't depend on
16704 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16705 * can.
16706 */
16707 __HEAD
16708 +
16709 +#ifdef CONFIG_PAX_KERNEXEC
16710 + jmp startup_32
16711 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16712 +.fill PAGE_SIZE-5,1,0xcc
16713 +#endif
16714 +
16715 ENTRY(startup_32)
16716 movl pa(stack_start),%ecx
16717
16718 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16719 2:
16720 leal -__PAGE_OFFSET(%ecx),%esp
16721
16722 +#ifdef CONFIG_SMP
16723 + movl $pa(cpu_gdt_table),%edi
16724 + movl $__per_cpu_load,%eax
16725 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16726 + rorl $16,%eax
16727 + movb %al,__KERNEL_PERCPU + 4(%edi)
16728 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16729 + movl $__per_cpu_end - 1,%eax
16730 + subl $__per_cpu_start,%eax
16731 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16732 +#endif
16733 +
16734 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16735 + movl $NR_CPUS,%ecx
16736 + movl $pa(cpu_gdt_table),%edi
16737 +1:
16738 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16739 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16740 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16741 + addl $PAGE_SIZE_asm,%edi
16742 + loop 1b
16743 +#endif
16744 +
16745 +#ifdef CONFIG_PAX_KERNEXEC
16746 + movl $pa(boot_gdt),%edi
16747 + movl $__LOAD_PHYSICAL_ADDR,%eax
16748 + movw %ax,__BOOT_CS + 2(%edi)
16749 + rorl $16,%eax
16750 + movb %al,__BOOT_CS + 4(%edi)
16751 + movb %ah,__BOOT_CS + 7(%edi)
16752 + rorl $16,%eax
16753 +
16754 + ljmp $(__BOOT_CS),$1f
16755 +1:
16756 +
16757 + movl $NR_CPUS,%ecx
16758 + movl $pa(cpu_gdt_table),%edi
16759 + addl $__PAGE_OFFSET,%eax
16760 +1:
16761 + movw %ax,__KERNEL_CS + 2(%edi)
16762 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16763 + rorl $16,%eax
16764 + movb %al,__KERNEL_CS + 4(%edi)
16765 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16766 + movb %ah,__KERNEL_CS + 7(%edi)
16767 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16768 + rorl $16,%eax
16769 + addl $PAGE_SIZE_asm,%edi
16770 + loop 1b
16771 +#endif
16772 +
16773 /*
16774 * Clear BSS first so that there are no surprises...
16775 */
16776 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16777 movl %eax, pa(max_pfn_mapped)
16778
16779 /* Do early initialization of the fixmap area */
16780 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16781 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16782 +#ifdef CONFIG_COMPAT_VDSO
16783 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16784 +#else
16785 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16786 +#endif
16787 #else /* Not PAE */
16788
16789 page_pde_offset = (__PAGE_OFFSET >> 20);
16790 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16791 movl %eax, pa(max_pfn_mapped)
16792
16793 /* Do early initialization of the fixmap area */
16794 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16795 - movl %eax,pa(initial_page_table+0xffc)
16796 +#ifdef CONFIG_COMPAT_VDSO
16797 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16798 +#else
16799 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16800 +#endif
16801 #endif
16802
16803 #ifdef CONFIG_PARAVIRT
16804 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16805 cmpl $num_subarch_entries, %eax
16806 jae bad_subarch
16807
16808 - movl pa(subarch_entries)(,%eax,4), %eax
16809 - subl $__PAGE_OFFSET, %eax
16810 - jmp *%eax
16811 + jmp *pa(subarch_entries)(,%eax,4)
16812
16813 bad_subarch:
16814 WEAK(lguest_entry)
16815 @@ -256,10 +326,10 @@ WEAK(xen_entry)
16816 __INITDATA
16817
16818 subarch_entries:
16819 - .long default_entry /* normal x86/PC */
16820 - .long lguest_entry /* lguest hypervisor */
16821 - .long xen_entry /* Xen hypervisor */
16822 - .long default_entry /* Moorestown MID */
16823 + .long ta(default_entry) /* normal x86/PC */
16824 + .long ta(lguest_entry) /* lguest hypervisor */
16825 + .long ta(xen_entry) /* Xen hypervisor */
16826 + .long ta(default_entry) /* Moorestown MID */
16827 num_subarch_entries = (. - subarch_entries) / 4
16828 .previous
16829 #else
16830 @@ -310,6 +380,7 @@ default_entry:
16831 orl %edx,%eax
16832 movl %eax,%cr4
16833
16834 +#ifdef CONFIG_X86_PAE
16835 testb $X86_CR4_PAE, %al # check if PAE is enabled
16836 jz 6f
16837
16838 @@ -338,6 +409,9 @@ default_entry:
16839 /* Make changes effective */
16840 wrmsr
16841
16842 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16843 +#endif
16844 +
16845 6:
16846
16847 /*
16848 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16849 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16850 movl %eax,%ss # after changing gdt.
16851
16852 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16853 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16854 movl %eax,%ds
16855 movl %eax,%es
16856
16857 movl $(__KERNEL_PERCPU), %eax
16858 movl %eax,%fs # set this cpu's percpu
16859
16860 +#ifdef CONFIG_CC_STACKPROTECTOR
16861 movl $(__KERNEL_STACK_CANARY),%eax
16862 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16863 + movl $(__USER_DS),%eax
16864 +#else
16865 + xorl %eax,%eax
16866 +#endif
16867 movl %eax,%gs
16868
16869 xorl %eax,%eax # Clear LDT
16870 @@ -520,8 +600,11 @@ setup_once:
16871 * relocation. Manually set base address in stack canary
16872 * segment descriptor.
16873 */
16874 - movl $gdt_page,%eax
16875 + movl $cpu_gdt_table,%eax
16876 movl $stack_canary,%ecx
16877 +#ifdef CONFIG_SMP
16878 + addl $__per_cpu_load,%ecx
16879 +#endif
16880 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16881 shrl $16, %ecx
16882 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16883 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16884 /* This is global to keep gas from relaxing the jumps */
16885 ENTRY(early_idt_handler)
16886 cld
16887 - cmpl $2,%ss:early_recursion_flag
16888 + cmpl $1,%ss:early_recursion_flag
16889 je hlt_loop
16890 incl %ss:early_recursion_flag
16891
16892 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16893 pushl (20+6*4)(%esp) /* trapno */
16894 pushl $fault_msg
16895 call printk
16896 -#endif
16897 call dump_stack
16898 +#endif
16899 hlt_loop:
16900 hlt
16901 jmp hlt_loop
16902 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16903 /* This is the default interrupt "handler" :-) */
16904 ALIGN
16905 ignore_int:
16906 - cld
16907 #ifdef CONFIG_PRINTK
16908 + cmpl $2,%ss:early_recursion_flag
16909 + je hlt_loop
16910 + incl %ss:early_recursion_flag
16911 + cld
16912 pushl %eax
16913 pushl %ecx
16914 pushl %edx
16915 @@ -620,9 +706,6 @@ ignore_int:
16916 movl $(__KERNEL_DS),%eax
16917 movl %eax,%ds
16918 movl %eax,%es
16919 - cmpl $2,early_recursion_flag
16920 - je hlt_loop
16921 - incl early_recursion_flag
16922 pushl 16(%esp)
16923 pushl 24(%esp)
16924 pushl 32(%esp)
16925 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
16926 /*
16927 * BSS section
16928 */
16929 -__PAGE_ALIGNED_BSS
16930 - .align PAGE_SIZE
16931 #ifdef CONFIG_X86_PAE
16932 +.section .initial_pg_pmd,"a",@progbits
16933 initial_pg_pmd:
16934 .fill 1024*KPMDS,4,0
16935 #else
16936 +.section .initial_page_table,"a",@progbits
16937 ENTRY(initial_page_table)
16938 .fill 1024,4,0
16939 #endif
16940 +.section .initial_pg_fixmap,"a",@progbits
16941 initial_pg_fixmap:
16942 .fill 1024,4,0
16943 +.section .empty_zero_page,"a",@progbits
16944 ENTRY(empty_zero_page)
16945 .fill 4096,1,0
16946 +.section .swapper_pg_dir,"a",@progbits
16947 ENTRY(swapper_pg_dir)
16948 +#ifdef CONFIG_X86_PAE
16949 + .fill 4,8,0
16950 +#else
16951 .fill 1024,4,0
16952 +#endif
16953 +
16954 +/*
16955 + * The IDT has to be page-aligned to simplify the Pentium
16956 + * F0 0F bug workaround.. We have a special link segment
16957 + * for this.
16958 + */
16959 +.section .idt,"a",@progbits
16960 +ENTRY(idt_table)
16961 + .fill 256,8,0
16962
16963 /*
16964 * This starts the data section.
16965 */
16966 #ifdef CONFIG_X86_PAE
16967 -__PAGE_ALIGNED_DATA
16968 - /* Page-aligned for the benefit of paravirt? */
16969 - .align PAGE_SIZE
16970 +.section .initial_page_table,"a",@progbits
16971 ENTRY(initial_page_table)
16972 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16973 # if KPMDS == 3
16974 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
16975 # error "Kernel PMDs should be 1, 2 or 3"
16976 # endif
16977 .align PAGE_SIZE /* needs to be page-sized too */
16978 +
16979 +#ifdef CONFIG_PAX_PER_CPU_PGD
16980 +ENTRY(cpu_pgd)
16981 + .rept NR_CPUS
16982 + .fill 4,8,0
16983 + .endr
16984 +#endif
16985 +
16986 #endif
16987
16988 .data
16989 .balign 4
16990 ENTRY(stack_start)
16991 - .long init_thread_union+THREAD_SIZE
16992 + .long init_thread_union+THREAD_SIZE-8
16993
16994 __INITRODATA
16995 int_msg:
16996 @@ -730,7 +835,7 @@ fault_msg:
16997 * segment size, and 32-bit linear address value:
16998 */
16999
17000 - .data
17001 +.section .rodata,"a",@progbits
17002 .globl boot_gdt_descr
17003 .globl idt_descr
17004
17005 @@ -739,7 +844,7 @@ fault_msg:
17006 .word 0 # 32 bit align gdt_desc.address
17007 boot_gdt_descr:
17008 .word __BOOT_DS+7
17009 - .long boot_gdt - __PAGE_OFFSET
17010 + .long pa(boot_gdt)
17011
17012 .word 0 # 32-bit align idt_desc.address
17013 idt_descr:
17014 @@ -750,7 +855,7 @@ idt_descr:
17015 .word 0 # 32 bit align gdt_desc.address
17016 ENTRY(early_gdt_descr)
17017 .word GDT_ENTRIES*8-1
17018 - .long gdt_page /* Overwritten for secondary CPUs */
17019 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17020
17021 /*
17022 * The boot_gdt must mirror the equivalent in setup.S and is
17023 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17024 .align L1_CACHE_BYTES
17025 ENTRY(boot_gdt)
17026 .fill GDT_ENTRY_BOOT_CS,8,0
17027 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17028 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17029 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17030 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17031 +
17032 + .align PAGE_SIZE_asm
17033 +ENTRY(cpu_gdt_table)
17034 + .rept NR_CPUS
17035 + .quad 0x0000000000000000 /* NULL descriptor */
17036 + .quad 0x0000000000000000 /* 0x0b reserved */
17037 + .quad 0x0000000000000000 /* 0x13 reserved */
17038 + .quad 0x0000000000000000 /* 0x1b reserved */
17039 +
17040 +#ifdef CONFIG_PAX_KERNEXEC
17041 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17042 +#else
17043 + .quad 0x0000000000000000 /* 0x20 unused */
17044 +#endif
17045 +
17046 + .quad 0x0000000000000000 /* 0x28 unused */
17047 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17048 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17049 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17050 + .quad 0x0000000000000000 /* 0x4b reserved */
17051 + .quad 0x0000000000000000 /* 0x53 reserved */
17052 + .quad 0x0000000000000000 /* 0x5b reserved */
17053 +
17054 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17055 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17056 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17057 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17058 +
17059 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17060 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17061 +
17062 + /*
17063 + * Segments used for calling PnP BIOS have byte granularity.
17064 + * The code segments and data segments have fixed 64k limits,
17065 + * the transfer segment sizes are set at run time.
17066 + */
17067 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17068 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17069 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17070 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17071 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17072 +
17073 + /*
17074 + * The APM segments have byte granularity and their bases
17075 + * are set at run time. All have 64k limits.
17076 + */
17077 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17078 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17079 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17080 +
17081 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17082 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17083 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17084 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17085 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17086 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17087 +
17088 + /* Be sure this is zeroed to avoid false validations in Xen */
17089 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17090 + .endr
17091 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17092 index 94bf9cc..400455a 100644
17093 --- a/arch/x86/kernel/head_64.S
17094 +++ b/arch/x86/kernel/head_64.S
17095 @@ -20,6 +20,8 @@
17096 #include <asm/processor-flags.h>
17097 #include <asm/percpu.h>
17098 #include <asm/nops.h>
17099 +#include <asm/cpufeature.h>
17100 +#include <asm/alternative-asm.h>
17101
17102 #ifdef CONFIG_PARAVIRT
17103 #include <asm/asm-offsets.h>
17104 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17105 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17106 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17107 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17108 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17109 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17110 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17111 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17112 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17113 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17114
17115 .text
17116 __HEAD
17117 @@ -88,35 +96,23 @@ startup_64:
17118 */
17119 addq %rbp, init_level4_pgt + 0(%rip)
17120 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17121 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17122 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17123 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17124 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17125
17126 addq %rbp, level3_ident_pgt + 0(%rip)
17127 +#ifndef CONFIG_XEN
17128 + addq %rbp, level3_ident_pgt + 8(%rip)
17129 +#endif
17130
17131 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17132 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17133 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17134 +
17135 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17136 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17137
17138 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17139 -
17140 - /* Add an Identity mapping if I am above 1G */
17141 - leaq _text(%rip), %rdi
17142 - andq $PMD_PAGE_MASK, %rdi
17143 -
17144 - movq %rdi, %rax
17145 - shrq $PUD_SHIFT, %rax
17146 - andq $(PTRS_PER_PUD - 1), %rax
17147 - jz ident_complete
17148 -
17149 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17150 - leaq level3_ident_pgt(%rip), %rbx
17151 - movq %rdx, 0(%rbx, %rax, 8)
17152 -
17153 - movq %rdi, %rax
17154 - shrq $PMD_SHIFT, %rax
17155 - andq $(PTRS_PER_PMD - 1), %rax
17156 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17157 - leaq level2_spare_pgt(%rip), %rbx
17158 - movq %rdx, 0(%rbx, %rax, 8)
17159 -ident_complete:
17160 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17161
17162 /*
17163 * Fixup the kernel text+data virtual addresses. Note that
17164 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17165 * after the boot processor executes this code.
17166 */
17167
17168 - /* Enable PAE mode and PGE */
17169 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17170 + /* Enable PAE mode and PSE/PGE */
17171 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17172 movq %rax, %cr4
17173
17174 /* Setup early boot stage 4 level pagetables. */
17175 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17176 movl $MSR_EFER, %ecx
17177 rdmsr
17178 btsl $_EFER_SCE, %eax /* Enable System Call */
17179 - btl $20,%edi /* No Execute supported? */
17180 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17181 jnc 1f
17182 btsl $_EFER_NX, %eax
17183 + leaq init_level4_pgt(%rip), %rdi
17184 +#ifndef CONFIG_EFI
17185 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17186 +#endif
17187 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17188 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17189 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17190 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17191 1: wrmsr /* Make changes effective */
17192
17193 /* Setup cr0 */
17194 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17195 * jump. In addition we need to ensure %cs is set so we make this
17196 * a far return.
17197 */
17198 + pax_set_fptr_mask
17199 movq initial_code(%rip),%rax
17200 pushq $0 # fake return address to stop unwinder
17201 pushq $__KERNEL_CS # set correct cs
17202 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17203 bad_address:
17204 jmp bad_address
17205
17206 - .section ".init.text","ax"
17207 + __INIT
17208 .globl early_idt_handlers
17209 early_idt_handlers:
17210 # 104(%rsp) %rflags
17211 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17212 addq $16,%rsp # drop vector number and error code
17213 decl early_recursion_flag(%rip)
17214 INTERRUPT_RETURN
17215 + .previous
17216
17217 + __INITDATA
17218 .balign 4
17219 early_recursion_flag:
17220 .long 0
17221 + .previous
17222
17223 + .section .rodata,"a",@progbits
17224 #ifdef CONFIG_EARLY_PRINTK
17225 early_idt_msg:
17226 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17227 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17228 #endif /* CONFIG_EARLY_PRINTK */
17229 .previous
17230
17231 + .section .rodata,"a",@progbits
17232 #define NEXT_PAGE(name) \
17233 .balign PAGE_SIZE; \
17234 ENTRY(name)
17235 @@ -372,7 +382,6 @@ ENTRY(name)
17236 i = i + 1 ; \
17237 .endr
17238
17239 - .data
17240 /*
17241 * This default setting generates an ident mapping at address 0x100000
17242 * and a mapping for the kernel that precisely maps virtual address
17243 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17244 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17245 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17246 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17247 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17248 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17249 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17250 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17251 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17252 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17253 .org init_level4_pgt + L4_START_KERNEL*8, 0
17254 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17255 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17256
17257 +#ifdef CONFIG_PAX_PER_CPU_PGD
17258 +NEXT_PAGE(cpu_pgd)
17259 + .rept NR_CPUS
17260 + .fill 512,8,0
17261 + .endr
17262 +#endif
17263 +
17264 NEXT_PAGE(level3_ident_pgt)
17265 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17266 +#ifdef CONFIG_XEN
17267 .fill 511,8,0
17268 +#else
17269 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17270 + .fill 510,8,0
17271 +#endif
17272 +
17273 +NEXT_PAGE(level3_vmalloc_start_pgt)
17274 + .fill 512,8,0
17275 +
17276 +NEXT_PAGE(level3_vmalloc_end_pgt)
17277 + .fill 512,8,0
17278 +
17279 +NEXT_PAGE(level3_vmemmap_pgt)
17280 + .fill L3_VMEMMAP_START,8,0
17281 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17282
17283 NEXT_PAGE(level3_kernel_pgt)
17284 .fill L3_START_KERNEL,8,0
17285 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17286 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17287 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17288
17289 +NEXT_PAGE(level2_vmemmap_pgt)
17290 + .fill 512,8,0
17291 +
17292 NEXT_PAGE(level2_fixmap_pgt)
17293 - .fill 506,8,0
17294 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17295 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17296 - .fill 5,8,0
17297 + .fill 507,8,0
17298 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17299 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17300 + .fill 4,8,0
17301
17302 -NEXT_PAGE(level1_fixmap_pgt)
17303 +NEXT_PAGE(level1_vsyscall_pgt)
17304 .fill 512,8,0
17305
17306 -NEXT_PAGE(level2_ident_pgt)
17307 - /* Since I easily can, map the first 1G.
17308 + /* Since I easily can, map the first 2G.
17309 * Don't set NX because code runs from these pages.
17310 */
17311 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17312 +NEXT_PAGE(level2_ident_pgt)
17313 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17314
17315 NEXT_PAGE(level2_kernel_pgt)
17316 /*
17317 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17318 * If you want to increase this then increase MODULES_VADDR
17319 * too.)
17320 */
17321 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17322 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17323 -
17324 -NEXT_PAGE(level2_spare_pgt)
17325 - .fill 512, 8, 0
17326 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17327
17328 #undef PMDS
17329 #undef NEXT_PAGE
17330
17331 - .data
17332 + .align PAGE_SIZE
17333 +ENTRY(cpu_gdt_table)
17334 + .rept NR_CPUS
17335 + .quad 0x0000000000000000 /* NULL descriptor */
17336 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17337 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17338 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17339 + .quad 0x00cffb000000ffff /* __USER32_CS */
17340 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17341 + .quad 0x00affb000000ffff /* __USER_CS */
17342 +
17343 +#ifdef CONFIG_PAX_KERNEXEC
17344 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17345 +#else
17346 + .quad 0x0 /* unused */
17347 +#endif
17348 +
17349 + .quad 0,0 /* TSS */
17350 + .quad 0,0 /* LDT */
17351 + .quad 0,0,0 /* three TLS descriptors */
17352 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17353 + /* asm/segment.h:GDT_ENTRIES must match this */
17354 +
17355 + /* zero the remaining page */
17356 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17357 + .endr
17358 +
17359 .align 16
17360 .globl early_gdt_descr
17361 early_gdt_descr:
17362 .word GDT_ENTRIES*8-1
17363 early_gdt_descr_base:
17364 - .quad INIT_PER_CPU_VAR(gdt_page)
17365 + .quad cpu_gdt_table
17366
17367 ENTRY(phys_base)
17368 /* This must match the first entry in level2_kernel_pgt */
17369 .quad 0x0000000000000000
17370
17371 #include "../../x86/xen/xen-head.S"
17372 -
17373 - .section .bss, "aw", @nobits
17374 +
17375 + .section .rodata,"a",@progbits
17376 .align L1_CACHE_BYTES
17377 ENTRY(idt_table)
17378 - .skip IDT_ENTRIES * 16
17379 + .fill 512,8,0
17380
17381 .align L1_CACHE_BYTES
17382 ENTRY(nmi_idt_table)
17383 - .skip IDT_ENTRIES * 16
17384 + .fill 512,8,0
17385
17386 __PAGE_ALIGNED_BSS
17387 .align PAGE_SIZE
17388 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17389 index 9c3bd4a..e1d9b35 100644
17390 --- a/arch/x86/kernel/i386_ksyms_32.c
17391 +++ b/arch/x86/kernel/i386_ksyms_32.c
17392 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17393 EXPORT_SYMBOL(cmpxchg8b_emu);
17394 #endif
17395
17396 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17397 +
17398 /* Networking helper routines. */
17399 EXPORT_SYMBOL(csum_partial_copy_generic);
17400 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17401 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17402
17403 EXPORT_SYMBOL(__get_user_1);
17404 EXPORT_SYMBOL(__get_user_2);
17405 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17406
17407 EXPORT_SYMBOL(csum_partial);
17408 EXPORT_SYMBOL(empty_zero_page);
17409 +
17410 +#ifdef CONFIG_PAX_KERNEXEC
17411 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17412 +#endif
17413 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17414 index f250431..54097e7 100644
17415 --- a/arch/x86/kernel/i387.c
17416 +++ b/arch/x86/kernel/i387.c
17417 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17418 static inline bool interrupted_user_mode(void)
17419 {
17420 struct pt_regs *regs = get_irq_regs();
17421 - return regs && user_mode_vm(regs);
17422 + return regs && user_mode(regs);
17423 }
17424
17425 /*
17426 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17427 index 36d1853..bf25736 100644
17428 --- a/arch/x86/kernel/i8259.c
17429 +++ b/arch/x86/kernel/i8259.c
17430 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17431 "spurious 8259A interrupt: IRQ%d.\n", irq);
17432 spurious_irq_mask |= irqmask;
17433 }
17434 - atomic_inc(&irq_err_count);
17435 + atomic_inc_unchecked(&irq_err_count);
17436 /*
17437 * Theoretically we do not have to handle this IRQ,
17438 * but in Linux this does not cause problems and is
17439 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17440 index 8c96897..be66bfa 100644
17441 --- a/arch/x86/kernel/ioport.c
17442 +++ b/arch/x86/kernel/ioport.c
17443 @@ -6,6 +6,7 @@
17444 #include <linux/sched.h>
17445 #include <linux/kernel.h>
17446 #include <linux/capability.h>
17447 +#include <linux/security.h>
17448 #include <linux/errno.h>
17449 #include <linux/types.h>
17450 #include <linux/ioport.h>
17451 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17452
17453 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17454 return -EINVAL;
17455 +#ifdef CONFIG_GRKERNSEC_IO
17456 + if (turn_on && grsec_disable_privio) {
17457 + gr_handle_ioperm();
17458 + return -EPERM;
17459 + }
17460 +#endif
17461 if (turn_on && !capable(CAP_SYS_RAWIO))
17462 return -EPERM;
17463
17464 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17465 * because the ->io_bitmap_max value must match the bitmap
17466 * contents:
17467 */
17468 - tss = &per_cpu(init_tss, get_cpu());
17469 + tss = init_tss + get_cpu();
17470
17471 if (turn_on)
17472 bitmap_clear(t->io_bitmap_ptr, from, num);
17473 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17474 return -EINVAL;
17475 /* Trying to gain more privileges? */
17476 if (level > old) {
17477 +#ifdef CONFIG_GRKERNSEC_IO
17478 + if (grsec_disable_privio) {
17479 + gr_handle_iopl();
17480 + return -EPERM;
17481 + }
17482 +#endif
17483 if (!capable(CAP_SYS_RAWIO))
17484 return -EPERM;
17485 }
17486 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17487 index 3dafc60..aa8e9c4 100644
17488 --- a/arch/x86/kernel/irq.c
17489 +++ b/arch/x86/kernel/irq.c
17490 @@ -18,7 +18,7 @@
17491 #include <asm/mce.h>
17492 #include <asm/hw_irq.h>
17493
17494 -atomic_t irq_err_count;
17495 +atomic_unchecked_t irq_err_count;
17496
17497 /* Function pointer for generic interrupt vector handling */
17498 void (*x86_platform_ipi_callback)(void) = NULL;
17499 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17500 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17501 seq_printf(p, " Machine check polls\n");
17502 #endif
17503 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17504 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17505 #if defined(CONFIG_X86_IO_APIC)
17506 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17507 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17508 #endif
17509 return 0;
17510 }
17511 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17512
17513 u64 arch_irq_stat(void)
17514 {
17515 - u64 sum = atomic_read(&irq_err_count);
17516 + u64 sum = atomic_read_unchecked(&irq_err_count);
17517
17518 #ifdef CONFIG_X86_IO_APIC
17519 - sum += atomic_read(&irq_mis_count);
17520 + sum += atomic_read_unchecked(&irq_mis_count);
17521 #endif
17522 return sum;
17523 }
17524 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17525 index 344faf8..355f60d 100644
17526 --- a/arch/x86/kernel/irq_32.c
17527 +++ b/arch/x86/kernel/irq_32.c
17528 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17529 __asm__ __volatile__("andl %%esp,%0" :
17530 "=r" (sp) : "0" (THREAD_SIZE - 1));
17531
17532 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17533 + return sp < STACK_WARN;
17534 }
17535
17536 static void print_stack_overflow(void)
17537 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17538 * per-CPU IRQ handling contexts (thread information and stack)
17539 */
17540 union irq_ctx {
17541 - struct thread_info tinfo;
17542 - u32 stack[THREAD_SIZE/sizeof(u32)];
17543 + unsigned long previous_esp;
17544 + u32 stack[THREAD_SIZE/sizeof(u32)];
17545 } __attribute__((aligned(THREAD_SIZE)));
17546
17547 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17548 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17549 static inline int
17550 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17551 {
17552 - union irq_ctx *curctx, *irqctx;
17553 + union irq_ctx *irqctx;
17554 u32 *isp, arg1, arg2;
17555
17556 - curctx = (union irq_ctx *) current_thread_info();
17557 irqctx = __this_cpu_read(hardirq_ctx);
17558
17559 /*
17560 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17561 * handler) we can't do that and just have to keep using the
17562 * current stack (which is the irq stack already after all)
17563 */
17564 - if (unlikely(curctx == irqctx))
17565 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17566 return 0;
17567
17568 /* build the stack frame on the IRQ stack */
17569 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17570 - irqctx->tinfo.task = curctx->tinfo.task;
17571 - irqctx->tinfo.previous_esp = current_stack_pointer;
17572 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17573 + irqctx->previous_esp = current_stack_pointer;
17574
17575 - /* Copy the preempt_count so that the [soft]irq checks work. */
17576 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17577 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17578 + __set_fs(MAKE_MM_SEG(0));
17579 +#endif
17580
17581 if (unlikely(overflow))
17582 call_on_stack(print_stack_overflow, isp);
17583 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17584 : "0" (irq), "1" (desc), "2" (isp),
17585 "D" (desc->handle_irq)
17586 : "memory", "cc", "ecx");
17587 +
17588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17589 + __set_fs(current_thread_info()->addr_limit);
17590 +#endif
17591 +
17592 return 1;
17593 }
17594
17595 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17596 */
17597 void __cpuinit irq_ctx_init(int cpu)
17598 {
17599 - union irq_ctx *irqctx;
17600 -
17601 if (per_cpu(hardirq_ctx, cpu))
17602 return;
17603
17604 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17605 - THREADINFO_GFP,
17606 - THREAD_SIZE_ORDER));
17607 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17608 - irqctx->tinfo.cpu = cpu;
17609 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17610 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17611 -
17612 - per_cpu(hardirq_ctx, cpu) = irqctx;
17613 -
17614 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17615 - THREADINFO_GFP,
17616 - THREAD_SIZE_ORDER));
17617 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17618 - irqctx->tinfo.cpu = cpu;
17619 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17620 -
17621 - per_cpu(softirq_ctx, cpu) = irqctx;
17622 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17623 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17624 +
17625 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17626 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17627
17628 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17629 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17630 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17631 asmlinkage void do_softirq(void)
17632 {
17633 unsigned long flags;
17634 - struct thread_info *curctx;
17635 union irq_ctx *irqctx;
17636 u32 *isp;
17637
17638 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17639 local_irq_save(flags);
17640
17641 if (local_softirq_pending()) {
17642 - curctx = current_thread_info();
17643 irqctx = __this_cpu_read(softirq_ctx);
17644 - irqctx->tinfo.task = curctx->task;
17645 - irqctx->tinfo.previous_esp = current_stack_pointer;
17646 + irqctx->previous_esp = current_stack_pointer;
17647
17648 /* build the stack frame on the softirq stack */
17649 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17650 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17651 +
17652 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17653 + __set_fs(MAKE_MM_SEG(0));
17654 +#endif
17655
17656 call_on_stack(__do_softirq, isp);
17657 +
17658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17659 + __set_fs(current_thread_info()->addr_limit);
17660 +#endif
17661 +
17662 /*
17663 * Shouldn't happen, we returned above if in_interrupt():
17664 */
17665 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17666 if (unlikely(!desc))
17667 return false;
17668
17669 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17670 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17671 if (unlikely(overflow))
17672 print_stack_overflow();
17673 desc->handle_irq(irq, desc);
17674 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17675 index d04d3ec..ea4b374 100644
17676 --- a/arch/x86/kernel/irq_64.c
17677 +++ b/arch/x86/kernel/irq_64.c
17678 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17679 u64 estack_top, estack_bottom;
17680 u64 curbase = (u64)task_stack_page(current);
17681
17682 - if (user_mode_vm(regs))
17683 + if (user_mode(regs))
17684 return;
17685
17686 if (regs->sp >= curbase + sizeof(struct thread_info) +
17687 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17688 index 1d5d31e..ab846ed 100644
17689 --- a/arch/x86/kernel/kdebugfs.c
17690 +++ b/arch/x86/kernel/kdebugfs.c
17691 @@ -28,6 +28,8 @@ struct setup_data_node {
17692 };
17693
17694 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17695 + size_t count, loff_t *ppos) __size_overflow(3);
17696 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17697 size_t count, loff_t *ppos)
17698 {
17699 struct setup_data_node *node = file->private_data;
17700 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17701 index 3f61904..873cea9 100644
17702 --- a/arch/x86/kernel/kgdb.c
17703 +++ b/arch/x86/kernel/kgdb.c
17704 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17705 #ifdef CONFIG_X86_32
17706 switch (regno) {
17707 case GDB_SS:
17708 - if (!user_mode_vm(regs))
17709 + if (!user_mode(regs))
17710 *(unsigned long *)mem = __KERNEL_DS;
17711 break;
17712 case GDB_SP:
17713 - if (!user_mode_vm(regs))
17714 + if (!user_mode(regs))
17715 *(unsigned long *)mem = kernel_stack_pointer(regs);
17716 break;
17717 case GDB_GS:
17718 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17719 case 'k':
17720 /* clear the trace bit */
17721 linux_regs->flags &= ~X86_EFLAGS_TF;
17722 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17723 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17724
17725 /* set the trace bit if we're stepping */
17726 if (remcomInBuffer[0] == 's') {
17727 linux_regs->flags |= X86_EFLAGS_TF;
17728 - atomic_set(&kgdb_cpu_doing_single_step,
17729 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17730 raw_smp_processor_id());
17731 }
17732
17733 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17734
17735 switch (cmd) {
17736 case DIE_DEBUG:
17737 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17738 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17739 if (user_mode(regs))
17740 return single_step_cont(regs, args);
17741 break;
17742 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17743 index c5e410e..da6aaf9 100644
17744 --- a/arch/x86/kernel/kprobes-opt.c
17745 +++ b/arch/x86/kernel/kprobes-opt.c
17746 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17747 * Verify if the address gap is in 2GB range, because this uses
17748 * a relative jump.
17749 */
17750 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17751 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17752 if (abs(rel) > 0x7fffffff)
17753 return -ERANGE;
17754
17755 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17756 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17757
17758 /* Set probe function call */
17759 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17760 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17761
17762 /* Set returning jmp instruction at the tail of out-of-line buffer */
17763 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17764 - (u8 *)op->kp.addr + op->optinsn.size);
17765 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17766
17767 flush_icache_range((unsigned long) buf,
17768 (unsigned long) buf + TMPL_END_IDX +
17769 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17770 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17771
17772 /* Backup instructions which will be replaced by jump address */
17773 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17774 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17775 RELATIVE_ADDR_SIZE);
17776
17777 insn_buf[0] = RELATIVEJUMP_OPCODE;
17778 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17779 index e2f751e..dffa2a0 100644
17780 --- a/arch/x86/kernel/kprobes.c
17781 +++ b/arch/x86/kernel/kprobes.c
17782 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17783 } __attribute__((packed)) *insn;
17784
17785 insn = (struct __arch_relative_insn *)from;
17786 +
17787 + pax_open_kernel();
17788 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17789 insn->op = op;
17790 + pax_close_kernel();
17791 }
17792
17793 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17794 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17795 kprobe_opcode_t opcode;
17796 kprobe_opcode_t *orig_opcodes = opcodes;
17797
17798 - if (search_exception_tables((unsigned long)opcodes))
17799 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17800 return 0; /* Page fault may occur on this address. */
17801
17802 retry:
17803 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17804 /* Another subsystem puts a breakpoint, failed to recover */
17805 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17806 return 0;
17807 + pax_open_kernel();
17808 memcpy(dest, insn.kaddr, insn.length);
17809 + pax_close_kernel();
17810
17811 #ifdef CONFIG_X86_64
17812 if (insn_rip_relative(&insn)) {
17813 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17814 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17815 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17816 disp = (u8 *) dest + insn_offset_displacement(&insn);
17817 + pax_open_kernel();
17818 *(s32 *) disp = (s32) newdisp;
17819 + pax_close_kernel();
17820 }
17821 #endif
17822 return insn.length;
17823 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17824 * nor set current_kprobe, because it doesn't use single
17825 * stepping.
17826 */
17827 - regs->ip = (unsigned long)p->ainsn.insn;
17828 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17829 preempt_enable_no_resched();
17830 return;
17831 }
17832 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17833 if (p->opcode == BREAKPOINT_INSTRUCTION)
17834 regs->ip = (unsigned long)p->addr;
17835 else
17836 - regs->ip = (unsigned long)p->ainsn.insn;
17837 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17838 }
17839
17840 /*
17841 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17842 setup_singlestep(p, regs, kcb, 0);
17843 return 1;
17844 }
17845 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17846 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17847 /*
17848 * The breakpoint instruction was removed right
17849 * after we hit it. Another cpu has removed
17850 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17851 " movq %rax, 152(%rsp)\n"
17852 RESTORE_REGS_STRING
17853 " popfq\n"
17854 +#ifdef KERNEXEC_PLUGIN
17855 + " btsq $63,(%rsp)\n"
17856 +#endif
17857 #else
17858 " pushf\n"
17859 SAVE_REGS_STRING
17860 @@ -765,7 +775,7 @@ static void __kprobes
17861 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17862 {
17863 unsigned long *tos = stack_addr(regs);
17864 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17865 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17866 unsigned long orig_ip = (unsigned long)p->addr;
17867 kprobe_opcode_t *insn = p->ainsn.insn;
17868
17869 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17870 struct die_args *args = data;
17871 int ret = NOTIFY_DONE;
17872
17873 - if (args->regs && user_mode_vm(args->regs))
17874 + if (args->regs && user_mode(args->regs))
17875 return ret;
17876
17877 switch (val) {
17878 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17879 index ebc9873..1b9724b 100644
17880 --- a/arch/x86/kernel/ldt.c
17881 +++ b/arch/x86/kernel/ldt.c
17882 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17883 if (reload) {
17884 #ifdef CONFIG_SMP
17885 preempt_disable();
17886 - load_LDT(pc);
17887 + load_LDT_nolock(pc);
17888 if (!cpumask_equal(mm_cpumask(current->mm),
17889 cpumask_of(smp_processor_id())))
17890 smp_call_function(flush_ldt, current->mm, 1);
17891 preempt_enable();
17892 #else
17893 - load_LDT(pc);
17894 + load_LDT_nolock(pc);
17895 #endif
17896 }
17897 if (oldsize) {
17898 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17899 return err;
17900
17901 for (i = 0; i < old->size; i++)
17902 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17903 + write_ldt_entry(new->ldt, i, old->ldt + i);
17904 return 0;
17905 }
17906
17907 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17908 retval = copy_ldt(&mm->context, &old_mm->context);
17909 mutex_unlock(&old_mm->context.lock);
17910 }
17911 +
17912 + if (tsk == current) {
17913 + mm->context.vdso = 0;
17914 +
17915 +#ifdef CONFIG_X86_32
17916 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17917 + mm->context.user_cs_base = 0UL;
17918 + mm->context.user_cs_limit = ~0UL;
17919 +
17920 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17921 + cpus_clear(mm->context.cpu_user_cs_mask);
17922 +#endif
17923 +
17924 +#endif
17925 +#endif
17926 +
17927 + }
17928 +
17929 return retval;
17930 }
17931
17932 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17933 }
17934 }
17935
17936 +#ifdef CONFIG_PAX_SEGMEXEC
17937 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17938 + error = -EINVAL;
17939 + goto out_unlock;
17940 + }
17941 +#endif
17942 +
17943 fill_ldt(&ldt, &ldt_info);
17944 if (oldmode)
17945 ldt.avl = 0;
17946 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17947 index 5b19e4d..6476a76 100644
17948 --- a/arch/x86/kernel/machine_kexec_32.c
17949 +++ b/arch/x86/kernel/machine_kexec_32.c
17950 @@ -26,7 +26,7 @@
17951 #include <asm/cacheflush.h>
17952 #include <asm/debugreg.h>
17953
17954 -static void set_idt(void *newidt, __u16 limit)
17955 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17956 {
17957 struct desc_ptr curidt;
17958
17959 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
17960 }
17961
17962
17963 -static void set_gdt(void *newgdt, __u16 limit)
17964 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17965 {
17966 struct desc_ptr curgdt;
17967
17968 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
17969 }
17970
17971 control_page = page_address(image->control_code_page);
17972 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17973 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17974
17975 relocate_kernel_ptr = control_page;
17976 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17977 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17978 index 0327e2b..e43737b 100644
17979 --- a/arch/x86/kernel/microcode_intel.c
17980 +++ b/arch/x86/kernel/microcode_intel.c
17981 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17982
17983 static int get_ucode_user(void *to, const void *from, size_t n)
17984 {
17985 - return copy_from_user(to, from, n);
17986 + return copy_from_user(to, (const void __force_user *)from, n);
17987 }
17988
17989 static enum ucode_state
17990 request_microcode_user(int cpu, const void __user *buf, size_t size)
17991 {
17992 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17993 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17994 }
17995
17996 static void microcode_fini_cpu(int cpu)
17997 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17998 index f21fd94..61565cd 100644
17999 --- a/arch/x86/kernel/module.c
18000 +++ b/arch/x86/kernel/module.c
18001 @@ -35,15 +35,60 @@
18002 #define DEBUGP(fmt...)
18003 #endif
18004
18005 -void *module_alloc(unsigned long size)
18006 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18007 {
18008 - if (PAGE_ALIGN(size) > MODULES_LEN)
18009 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18010 return NULL;
18011 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18012 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18013 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18014 -1, __builtin_return_address(0));
18015 }
18016
18017 +void *module_alloc(unsigned long size)
18018 +{
18019 +
18020 +#ifdef CONFIG_PAX_KERNEXEC
18021 + return __module_alloc(size, PAGE_KERNEL);
18022 +#else
18023 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18024 +#endif
18025 +
18026 +}
18027 +
18028 +#ifdef CONFIG_PAX_KERNEXEC
18029 +#ifdef CONFIG_X86_32
18030 +void *module_alloc_exec(unsigned long size)
18031 +{
18032 + struct vm_struct *area;
18033 +
18034 + if (size == 0)
18035 + return NULL;
18036 +
18037 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18038 + return area ? area->addr : NULL;
18039 +}
18040 +EXPORT_SYMBOL(module_alloc_exec);
18041 +
18042 +void module_free_exec(struct module *mod, void *module_region)
18043 +{
18044 + vunmap(module_region);
18045 +}
18046 +EXPORT_SYMBOL(module_free_exec);
18047 +#else
18048 +void module_free_exec(struct module *mod, void *module_region)
18049 +{
18050 + module_free(mod, module_region);
18051 +}
18052 +EXPORT_SYMBOL(module_free_exec);
18053 +
18054 +void *module_alloc_exec(unsigned long size)
18055 +{
18056 + return __module_alloc(size, PAGE_KERNEL_RX);
18057 +}
18058 +EXPORT_SYMBOL(module_alloc_exec);
18059 +#endif
18060 +#endif
18061 +
18062 #ifdef CONFIG_X86_32
18063 int apply_relocate(Elf32_Shdr *sechdrs,
18064 const char *strtab,
18065 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18066 unsigned int i;
18067 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18068 Elf32_Sym *sym;
18069 - uint32_t *location;
18070 + uint32_t *plocation, location;
18071
18072 DEBUGP("Applying relocate section %u to %u\n", relsec,
18073 sechdrs[relsec].sh_info);
18074 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18075 /* This is where to make the change */
18076 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18077 - + rel[i].r_offset;
18078 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18079 + location = (uint32_t)plocation;
18080 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18081 + plocation = ktla_ktva((void *)plocation);
18082 /* This is the symbol it is referring to. Note that all
18083 undefined symbols have been resolved. */
18084 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18085 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18086 switch (ELF32_R_TYPE(rel[i].r_info)) {
18087 case R_386_32:
18088 /* We add the value into the location given */
18089 - *location += sym->st_value;
18090 + pax_open_kernel();
18091 + *plocation += sym->st_value;
18092 + pax_close_kernel();
18093 break;
18094 case R_386_PC32:
18095 /* Add the value, subtract its postition */
18096 - *location += sym->st_value - (uint32_t)location;
18097 + pax_open_kernel();
18098 + *plocation += sym->st_value - location;
18099 + pax_close_kernel();
18100 break;
18101 default:
18102 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18103 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18104 case R_X86_64_NONE:
18105 break;
18106 case R_X86_64_64:
18107 + pax_open_kernel();
18108 *(u64 *)loc = val;
18109 + pax_close_kernel();
18110 break;
18111 case R_X86_64_32:
18112 + pax_open_kernel();
18113 *(u32 *)loc = val;
18114 + pax_close_kernel();
18115 if (val != *(u32 *)loc)
18116 goto overflow;
18117 break;
18118 case R_X86_64_32S:
18119 + pax_open_kernel();
18120 *(s32 *)loc = val;
18121 + pax_close_kernel();
18122 if ((s64)val != *(s32 *)loc)
18123 goto overflow;
18124 break;
18125 case R_X86_64_PC32:
18126 val -= (u64)loc;
18127 + pax_open_kernel();
18128 *(u32 *)loc = val;
18129 + pax_close_kernel();
18130 +
18131 #if 0
18132 if ((s64)val != *(s32 *)loc)
18133 goto overflow;
18134 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18135 index a0b2f84..875ab81 100644
18136 --- a/arch/x86/kernel/nmi.c
18137 +++ b/arch/x86/kernel/nmi.c
18138 @@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18139 dotraplinkage notrace __kprobes void
18140 do_nmi(struct pt_regs *regs, long error_code)
18141 {
18142 +
18143 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18144 + if (!user_mode(regs)) {
18145 + unsigned long cs = regs->cs & 0xFFFF;
18146 + unsigned long ip = ktva_ktla(regs->ip);
18147 +
18148 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18149 + regs->ip = ip;
18150 + }
18151 +#endif
18152 +
18153 nmi_nesting_preprocess(regs);
18154
18155 nmi_enter();
18156 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18157 index 676b8c7..870ba04 100644
18158 --- a/arch/x86/kernel/paravirt-spinlocks.c
18159 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18160 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18161 arch_spin_lock(lock);
18162 }
18163
18164 -struct pv_lock_ops pv_lock_ops = {
18165 +struct pv_lock_ops pv_lock_ops __read_only = {
18166 #ifdef CONFIG_SMP
18167 .spin_is_locked = __ticket_spin_is_locked,
18168 .spin_is_contended = __ticket_spin_is_contended,
18169 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18170 index 9ce8859..b49bf51 100644
18171 --- a/arch/x86/kernel/paravirt.c
18172 +++ b/arch/x86/kernel/paravirt.c
18173 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18174 {
18175 return x;
18176 }
18177 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18178 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18179 +#endif
18180
18181 void __init default_banner(void)
18182 {
18183 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18184 if (opfunc == NULL)
18185 /* If there's no function, patch it with a ud2a (BUG) */
18186 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18187 - else if (opfunc == _paravirt_nop)
18188 + else if (opfunc == (void *)_paravirt_nop)
18189 /* If the operation is a nop, then nop the callsite */
18190 ret = paravirt_patch_nop();
18191
18192 /* identity functions just return their single argument */
18193 - else if (opfunc == _paravirt_ident_32)
18194 + else if (opfunc == (void *)_paravirt_ident_32)
18195 ret = paravirt_patch_ident_32(insnbuf, len);
18196 - else if (opfunc == _paravirt_ident_64)
18197 + else if (opfunc == (void *)_paravirt_ident_64)
18198 ret = paravirt_patch_ident_64(insnbuf, len);
18199 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18200 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18201 + ret = paravirt_patch_ident_64(insnbuf, len);
18202 +#endif
18203
18204 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18205 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18206 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18207 if (insn_len > len || start == NULL)
18208 insn_len = len;
18209 else
18210 - memcpy(insnbuf, start, insn_len);
18211 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18212
18213 return insn_len;
18214 }
18215 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18216 preempt_enable();
18217 }
18218
18219 -struct pv_info pv_info = {
18220 +struct pv_info pv_info __read_only = {
18221 .name = "bare hardware",
18222 .paravirt_enabled = 0,
18223 .kernel_rpl = 0,
18224 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18225 #endif
18226 };
18227
18228 -struct pv_init_ops pv_init_ops = {
18229 +struct pv_init_ops pv_init_ops __read_only = {
18230 .patch = native_patch,
18231 };
18232
18233 -struct pv_time_ops pv_time_ops = {
18234 +struct pv_time_ops pv_time_ops __read_only = {
18235 .sched_clock = native_sched_clock,
18236 .steal_clock = native_steal_clock,
18237 };
18238
18239 -struct pv_irq_ops pv_irq_ops = {
18240 +struct pv_irq_ops pv_irq_ops __read_only = {
18241 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18242 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18243 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18244 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18245 #endif
18246 };
18247
18248 -struct pv_cpu_ops pv_cpu_ops = {
18249 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18250 .cpuid = native_cpuid,
18251 .get_debugreg = native_get_debugreg,
18252 .set_debugreg = native_set_debugreg,
18253 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18254 .end_context_switch = paravirt_nop,
18255 };
18256
18257 -struct pv_apic_ops pv_apic_ops = {
18258 +struct pv_apic_ops pv_apic_ops __read_only = {
18259 #ifdef CONFIG_X86_LOCAL_APIC
18260 .startup_ipi_hook = paravirt_nop,
18261 #endif
18262 };
18263
18264 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18265 +#ifdef CONFIG_X86_32
18266 +#ifdef CONFIG_X86_PAE
18267 +/* 64-bit pagetable entries */
18268 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18269 +#else
18270 /* 32-bit pagetable entries */
18271 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18272 +#endif
18273 #else
18274 /* 64-bit pagetable entries */
18275 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18276 #endif
18277
18278 -struct pv_mmu_ops pv_mmu_ops = {
18279 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18280
18281 .read_cr2 = native_read_cr2,
18282 .write_cr2 = native_write_cr2,
18283 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18284 .make_pud = PTE_IDENT,
18285
18286 .set_pgd = native_set_pgd,
18287 + .set_pgd_batched = native_set_pgd_batched,
18288 #endif
18289 #endif /* PAGETABLE_LEVELS >= 3 */
18290
18291 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18292 },
18293
18294 .set_fixmap = native_set_fixmap,
18295 +
18296 +#ifdef CONFIG_PAX_KERNEXEC
18297 + .pax_open_kernel = native_pax_open_kernel,
18298 + .pax_close_kernel = native_pax_close_kernel,
18299 +#endif
18300 +
18301 };
18302
18303 EXPORT_SYMBOL_GPL(pv_time_ops);
18304 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18305 index 35ccf75..7a15747 100644
18306 --- a/arch/x86/kernel/pci-iommu_table.c
18307 +++ b/arch/x86/kernel/pci-iommu_table.c
18308 @@ -2,7 +2,7 @@
18309 #include <asm/iommu_table.h>
18310 #include <linux/string.h>
18311 #include <linux/kallsyms.h>
18312 -
18313 +#include <linux/sched.h>
18314
18315 #define DEBUG 1
18316
18317 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18318 index 735279e..5008677 100644
18319 --- a/arch/x86/kernel/process.c
18320 +++ b/arch/x86/kernel/process.c
18321 @@ -34,7 +34,8 @@
18322 * section. Since TSS's are completely CPU-local, we want them
18323 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18324 */
18325 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18326 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18327 +EXPORT_SYMBOL(init_tss);
18328
18329 #ifdef CONFIG_X86_64
18330 static DEFINE_PER_CPU(unsigned char, is_idle);
18331 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18332 task_xstate_cachep =
18333 kmem_cache_create("task_xstate", xstate_size,
18334 __alignof__(union thread_xstate),
18335 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18336 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18337 }
18338
18339 static inline void drop_fpu(struct task_struct *tsk)
18340 @@ -115,7 +116,7 @@ void exit_thread(void)
18341 unsigned long *bp = t->io_bitmap_ptr;
18342
18343 if (bp) {
18344 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18345 + struct tss_struct *tss = init_tss + get_cpu();
18346
18347 t->io_bitmap_ptr = NULL;
18348 clear_thread_flag(TIF_IO_BITMAP);
18349 @@ -147,7 +148,7 @@ void show_regs_common(void)
18350
18351 printk(KERN_CONT "\n");
18352 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18353 - current->pid, current->comm, print_tainted(),
18354 + task_pid_nr(current), current->comm, print_tainted(),
18355 init_utsname()->release,
18356 (int)strcspn(init_utsname()->version, " "),
18357 init_utsname()->version);
18358 @@ -161,6 +162,9 @@ void flush_thread(void)
18359 {
18360 struct task_struct *tsk = current;
18361
18362 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18363 + loadsegment(gs, 0);
18364 +#endif
18365 flush_ptrace_hw_breakpoint(tsk);
18366 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18367 drop_fpu(tsk);
18368 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18369 regs.di = (unsigned long) arg;
18370
18371 #ifdef CONFIG_X86_32
18372 - regs.ds = __USER_DS;
18373 - regs.es = __USER_DS;
18374 + regs.ds = __KERNEL_DS;
18375 + regs.es = __KERNEL_DS;
18376 regs.fs = __KERNEL_PERCPU;
18377 - regs.gs = __KERNEL_STACK_CANARY;
18378 + savesegment(gs, regs.gs);
18379 #else
18380 regs.ss = __KERNEL_DS;
18381 #endif
18382 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18383 void exit_idle(void)
18384 {
18385 /* idle loop has pid 0 */
18386 - if (current->pid)
18387 + if (task_pid_nr(current))
18388 return;
18389 __exit_idle();
18390 }
18391 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18392
18393 return ret;
18394 }
18395 -void stop_this_cpu(void *dummy)
18396 +__noreturn void stop_this_cpu(void *dummy)
18397 {
18398 local_irq_disable();
18399 /*
18400 @@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18401 }
18402 early_param("idle", idle_setup);
18403
18404 -unsigned long arch_align_stack(unsigned long sp)
18405 +#ifdef CONFIG_PAX_RANDKSTACK
18406 +void pax_randomize_kstack(struct pt_regs *regs)
18407 {
18408 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18409 - sp -= get_random_int() % 8192;
18410 - return sp & ~0xf;
18411 -}
18412 + struct thread_struct *thread = &current->thread;
18413 + unsigned long time;
18414
18415 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18416 -{
18417 - unsigned long range_end = mm->brk + 0x02000000;
18418 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18419 -}
18420 + if (!randomize_va_space)
18421 + return;
18422 +
18423 + if (v8086_mode(regs))
18424 + return;
18425
18426 + rdtscl(time);
18427 +
18428 + /* P4 seems to return a 0 LSB, ignore it */
18429 +#ifdef CONFIG_MPENTIUM4
18430 + time &= 0x3EUL;
18431 + time <<= 2;
18432 +#elif defined(CONFIG_X86_64)
18433 + time &= 0xFUL;
18434 + time <<= 4;
18435 +#else
18436 + time &= 0x1FUL;
18437 + time <<= 3;
18438 +#endif
18439 +
18440 + thread->sp0 ^= time;
18441 + load_sp0(init_tss + smp_processor_id(), thread);
18442 +
18443 +#ifdef CONFIG_X86_64
18444 + this_cpu_write(kernel_stack, thread->sp0);
18445 +#endif
18446 +}
18447 +#endif
18448 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18449 index 516fa18..80bd9e6 100644
18450 --- a/arch/x86/kernel/process_32.c
18451 +++ b/arch/x86/kernel/process_32.c
18452 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18453 unsigned long thread_saved_pc(struct task_struct *tsk)
18454 {
18455 return ((unsigned long *)tsk->thread.sp)[3];
18456 +//XXX return tsk->thread.eip;
18457 }
18458
18459 void __show_regs(struct pt_regs *regs, int all)
18460 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18461 unsigned long sp;
18462 unsigned short ss, gs;
18463
18464 - if (user_mode_vm(regs)) {
18465 + if (user_mode(regs)) {
18466 sp = regs->sp;
18467 ss = regs->ss & 0xffff;
18468 - gs = get_user_gs(regs);
18469 } else {
18470 sp = kernel_stack_pointer(regs);
18471 savesegment(ss, ss);
18472 - savesegment(gs, gs);
18473 }
18474 + gs = get_user_gs(regs);
18475
18476 show_regs_common();
18477
18478 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18479 struct task_struct *tsk;
18480 int err;
18481
18482 - childregs = task_pt_regs(p);
18483 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18484 *childregs = *regs;
18485 childregs->ax = 0;
18486 childregs->sp = sp;
18487
18488 p->thread.sp = (unsigned long) childregs;
18489 p->thread.sp0 = (unsigned long) (childregs+1);
18490 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18491
18492 p->thread.ip = (unsigned long) ret_from_fork;
18493
18494 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18495 struct thread_struct *prev = &prev_p->thread,
18496 *next = &next_p->thread;
18497 int cpu = smp_processor_id();
18498 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18499 + struct tss_struct *tss = init_tss + cpu;
18500 fpu_switch_t fpu;
18501
18502 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18503 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18504 */
18505 lazy_save_gs(prev->gs);
18506
18507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18508 + __set_fs(task_thread_info(next_p)->addr_limit);
18509 +#endif
18510 +
18511 /*
18512 * Load the per-thread Thread-Local Storage descriptor.
18513 */
18514 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18515 */
18516 arch_end_context_switch(next_p);
18517
18518 + this_cpu_write(current_task, next_p);
18519 + this_cpu_write(current_tinfo, &next_p->tinfo);
18520 +
18521 /*
18522 * Restore %gs if needed (which is common)
18523 */
18524 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18525
18526 switch_fpu_finish(next_p, fpu);
18527
18528 - this_cpu_write(current_task, next_p);
18529 -
18530 return prev_p;
18531 }
18532
18533 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18534 } while (count++ < 16);
18535 return 0;
18536 }
18537 -
18538 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18539 index 61cdf7f..797f06a 100644
18540 --- a/arch/x86/kernel/process_64.c
18541 +++ b/arch/x86/kernel/process_64.c
18542 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18543 struct pt_regs *childregs;
18544 struct task_struct *me = current;
18545
18546 - childregs = ((struct pt_regs *)
18547 - (THREAD_SIZE + task_stack_page(p))) - 1;
18548 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18549 *childregs = *regs;
18550
18551 childregs->ax = 0;
18552 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18553 p->thread.sp = (unsigned long) childregs;
18554 p->thread.sp0 = (unsigned long) (childregs+1);
18555 p->thread.usersp = me->thread.usersp;
18556 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18557
18558 set_tsk_thread_flag(p, TIF_FORK);
18559
18560 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18561 struct thread_struct *prev = &prev_p->thread;
18562 struct thread_struct *next = &next_p->thread;
18563 int cpu = smp_processor_id();
18564 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18565 + struct tss_struct *tss = init_tss + cpu;
18566 unsigned fsindex, gsindex;
18567 fpu_switch_t fpu;
18568
18569 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18570 prev->usersp = this_cpu_read(old_rsp);
18571 this_cpu_write(old_rsp, next->usersp);
18572 this_cpu_write(current_task, next_p);
18573 + this_cpu_write(current_tinfo, &next_p->tinfo);
18574
18575 - this_cpu_write(kernel_stack,
18576 - (unsigned long)task_stack_page(next_p) +
18577 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18578 + this_cpu_write(kernel_stack, next->sp0);
18579
18580 /*
18581 * Now maybe reload the debug registers and handle I/O bitmaps
18582 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18583 if (!p || p == current || p->state == TASK_RUNNING)
18584 return 0;
18585 stack = (unsigned long)task_stack_page(p);
18586 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18587 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18588 return 0;
18589 fp = *(u64 *)(p->thread.sp);
18590 do {
18591 - if (fp < (unsigned long)stack ||
18592 - fp >= (unsigned long)stack+THREAD_SIZE)
18593 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18594 return 0;
18595 ip = *(u64 *)(fp+8);
18596 if (!in_sched_functions(ip))
18597 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18598 index c4c6a5c..905f440 100644
18599 --- a/arch/x86/kernel/ptrace.c
18600 +++ b/arch/x86/kernel/ptrace.c
18601 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18602 unsigned long addr, unsigned long data)
18603 {
18604 int ret;
18605 - unsigned long __user *datap = (unsigned long __user *)data;
18606 + unsigned long __user *datap = (__force unsigned long __user *)data;
18607
18608 switch (request) {
18609 /* read the word at location addr in the USER area. */
18610 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18611 if ((int) addr < 0)
18612 return -EIO;
18613 ret = do_get_thread_area(child, addr,
18614 - (struct user_desc __user *)data);
18615 + (__force struct user_desc __user *) data);
18616 break;
18617
18618 case PTRACE_SET_THREAD_AREA:
18619 if ((int) addr < 0)
18620 return -EIO;
18621 ret = do_set_thread_area(child, addr,
18622 - (struct user_desc __user *)data, 0);
18623 + (__force struct user_desc __user *) data, 0);
18624 break;
18625 #endif
18626
18627 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18628 memset(info, 0, sizeof(*info));
18629 info->si_signo = SIGTRAP;
18630 info->si_code = si_code;
18631 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18632 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18633 }
18634
18635 void user_single_step_siginfo(struct task_struct *tsk,
18636 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18637 # define IS_IA32 0
18638 #endif
18639
18640 +#ifdef CONFIG_GRKERNSEC_SETXID
18641 +extern void gr_delayed_cred_worker(void);
18642 +#endif
18643 +
18644 /*
18645 * We must return the syscall number to actually look up in the table.
18646 * This can be -1L to skip running any syscall at all.
18647 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18648 {
18649 long ret = 0;
18650
18651 +#ifdef CONFIG_GRKERNSEC_SETXID
18652 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18653 + gr_delayed_cred_worker();
18654 +#endif
18655 +
18656 /*
18657 * If we stepped into a sysenter/syscall insn, it trapped in
18658 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18659 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18660 {
18661 bool step;
18662
18663 +#ifdef CONFIG_GRKERNSEC_SETXID
18664 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18665 + gr_delayed_cred_worker();
18666 +#endif
18667 +
18668 audit_syscall_exit(regs);
18669
18670 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18671 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18672 index 42eb330..139955c 100644
18673 --- a/arch/x86/kernel/pvclock.c
18674 +++ b/arch/x86/kernel/pvclock.c
18675 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18676 return pv_tsc_khz;
18677 }
18678
18679 -static atomic64_t last_value = ATOMIC64_INIT(0);
18680 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18681
18682 void pvclock_resume(void)
18683 {
18684 - atomic64_set(&last_value, 0);
18685 + atomic64_set_unchecked(&last_value, 0);
18686 }
18687
18688 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18689 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18690 * updating at the same time, and one of them could be slightly behind,
18691 * making the assumption that last_value always go forward fail to hold.
18692 */
18693 - last = atomic64_read(&last_value);
18694 + last = atomic64_read_unchecked(&last_value);
18695 do {
18696 if (ret < last)
18697 return last;
18698 - last = atomic64_cmpxchg(&last_value, last, ret);
18699 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18700 } while (unlikely(last != ret));
18701
18702 return ret;
18703 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18704 index 5de92f1..2732385 100644
18705 --- a/arch/x86/kernel/reboot.c
18706 +++ b/arch/x86/kernel/reboot.c
18707 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18708 EXPORT_SYMBOL(pm_power_off);
18709
18710 static const struct desc_ptr no_idt = {};
18711 -static int reboot_mode;
18712 +static unsigned short reboot_mode;
18713 enum reboot_type reboot_type = BOOT_ACPI;
18714 int reboot_force;
18715
18716 @@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18717 return 0;
18718 }
18719
18720 -void machine_real_restart(unsigned int type)
18721 +__noreturn void machine_real_restart(unsigned int type)
18722 {
18723 - void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18724 + void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18725 real_mode_header->machine_real_restart_asm;
18726
18727 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18728 + struct desc_struct *gdt;
18729 +#endif
18730 +
18731 local_irq_disable();
18732
18733 /*
18734 @@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18735 * boot)". This seems like a fairly standard thing that gets set by
18736 * REBOOT.COM programs, and the previous reset routine did this
18737 * too. */
18738 - *((unsigned short *)0x472) = reboot_mode;
18739 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18740
18741 /* Jump to the identity-mapped low memory code */
18742 +
18743 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18744 + gdt = get_cpu_gdt_table(smp_processor_id());
18745 + pax_open_kernel();
18746 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18747 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18748 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18749 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18750 +#endif
18751 +#ifdef CONFIG_PAX_KERNEXEC
18752 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18753 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18754 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18755 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18756 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18757 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18758 +#endif
18759 + pax_close_kernel();
18760 +#endif
18761 +
18762 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18763 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18764 + unreachable();
18765 +#else
18766 restart_lowmem(type);
18767 +#endif
18768 +
18769 }
18770 #ifdef CONFIG_APM_MODULE
18771 EXPORT_SYMBOL(machine_real_restart);
18772 @@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18773 * try to force a triple fault and then cycle between hitting the keyboard
18774 * controller and doing that
18775 */
18776 -static void native_machine_emergency_restart(void)
18777 +__noreturn static void native_machine_emergency_restart(void)
18778 {
18779 int i;
18780 int attempt = 0;
18781 @@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18782 #endif
18783 }
18784
18785 -static void __machine_emergency_restart(int emergency)
18786 +static __noreturn void __machine_emergency_restart(int emergency)
18787 {
18788 reboot_emergency = emergency;
18789 machine_ops.emergency_restart();
18790 }
18791
18792 -static void native_machine_restart(char *__unused)
18793 +static __noreturn void native_machine_restart(char *__unused)
18794 {
18795 printk("machine restart\n");
18796
18797 @@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18798 __machine_emergency_restart(0);
18799 }
18800
18801 -static void native_machine_halt(void)
18802 +static __noreturn void native_machine_halt(void)
18803 {
18804 /* Stop other cpus and apics */
18805 machine_shutdown();
18806 @@ -695,7 +725,7 @@ static void native_machine_halt(void)
18807 stop_this_cpu(NULL);
18808 }
18809
18810 -static void native_machine_power_off(void)
18811 +__noreturn static void native_machine_power_off(void)
18812 {
18813 if (pm_power_off) {
18814 if (!reboot_force)
18815 @@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18816 }
18817 /* A fallback in case there is no PM info available */
18818 tboot_shutdown(TB_SHUTDOWN_HALT);
18819 + unreachable();
18820 }
18821
18822 struct machine_ops machine_ops = {
18823 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18824 index 7a6f3b3..bed145d7 100644
18825 --- a/arch/x86/kernel/relocate_kernel_64.S
18826 +++ b/arch/x86/kernel/relocate_kernel_64.S
18827 @@ -11,6 +11,7 @@
18828 #include <asm/kexec.h>
18829 #include <asm/processor-flags.h>
18830 #include <asm/pgtable_types.h>
18831 +#include <asm/alternative-asm.h>
18832
18833 /*
18834 * Must be relocatable PIC code callable as a C function
18835 @@ -160,13 +161,14 @@ identity_mapped:
18836 xorq %rbp, %rbp
18837 xorq %r8, %r8
18838 xorq %r9, %r9
18839 - xorq %r10, %r9
18840 + xorq %r10, %r10
18841 xorq %r11, %r11
18842 xorq %r12, %r12
18843 xorq %r13, %r13
18844 xorq %r14, %r14
18845 xorq %r15, %r15
18846
18847 + pax_force_retaddr 0, 1
18848 ret
18849
18850 1:
18851 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18852 index 16be6dc..4686132 100644
18853 --- a/arch/x86/kernel/setup.c
18854 +++ b/arch/x86/kernel/setup.c
18855 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18856
18857 switch (data->type) {
18858 case SETUP_E820_EXT:
18859 - parse_e820_ext(data);
18860 + parse_e820_ext((struct setup_data __force_kernel *)data);
18861 break;
18862 case SETUP_DTB:
18863 add_dtb(pa_data);
18864 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18865 * area (640->1Mb) as ram even though it is not.
18866 * take them out.
18867 */
18868 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18869 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18870 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18871 }
18872
18873 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18874
18875 if (!boot_params.hdr.root_flags)
18876 root_mountflags &= ~MS_RDONLY;
18877 - init_mm.start_code = (unsigned long) _text;
18878 - init_mm.end_code = (unsigned long) _etext;
18879 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18880 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18881 init_mm.end_data = (unsigned long) _edata;
18882 init_mm.brk = _brk_end;
18883
18884 - code_resource.start = virt_to_phys(_text);
18885 - code_resource.end = virt_to_phys(_etext)-1;
18886 - data_resource.start = virt_to_phys(_etext);
18887 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18888 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18889 + data_resource.start = virt_to_phys(_sdata);
18890 data_resource.end = virt_to_phys(_edata)-1;
18891 bss_resource.start = virt_to_phys(&__bss_start);
18892 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18893 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18894 index 5a98aa2..2f9288d 100644
18895 --- a/arch/x86/kernel/setup_percpu.c
18896 +++ b/arch/x86/kernel/setup_percpu.c
18897 @@ -21,19 +21,17 @@
18898 #include <asm/cpu.h>
18899 #include <asm/stackprotector.h>
18900
18901 -DEFINE_PER_CPU(int, cpu_number);
18902 +#ifdef CONFIG_SMP
18903 +DEFINE_PER_CPU(unsigned int, cpu_number);
18904 EXPORT_PER_CPU_SYMBOL(cpu_number);
18905 +#endif
18906
18907 -#ifdef CONFIG_X86_64
18908 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18909 -#else
18910 -#define BOOT_PERCPU_OFFSET 0
18911 -#endif
18912
18913 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18914 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18915
18916 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18917 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18918 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18919 };
18920 EXPORT_SYMBOL(__per_cpu_offset);
18921 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18922 {
18923 #ifdef CONFIG_X86_32
18924 struct desc_struct gdt;
18925 + unsigned long base = per_cpu_offset(cpu);
18926
18927 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18928 - 0x2 | DESCTYPE_S, 0x8);
18929 - gdt.s = 1;
18930 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18931 + 0x83 | DESCTYPE_S, 0xC);
18932 write_gdt_entry(get_cpu_gdt_table(cpu),
18933 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18934 #endif
18935 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18936 /* alrighty, percpu areas up and running */
18937 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18938 for_each_possible_cpu(cpu) {
18939 +#ifdef CONFIG_CC_STACKPROTECTOR
18940 +#ifdef CONFIG_X86_32
18941 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18942 +#endif
18943 +#endif
18944 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18945 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18946 per_cpu(cpu_number, cpu) = cpu;
18947 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18948 */
18949 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18950 #endif
18951 +#ifdef CONFIG_CC_STACKPROTECTOR
18952 +#ifdef CONFIG_X86_32
18953 + if (!cpu)
18954 + per_cpu(stack_canary.canary, cpu) = canary;
18955 +#endif
18956 +#endif
18957 /*
18958 * Up to this point, the boot CPU has been using .init.data
18959 * area. Reload any changed state for the boot CPU.
18960 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18961 index 21af737..fb45e22 100644
18962 --- a/arch/x86/kernel/signal.c
18963 +++ b/arch/x86/kernel/signal.c
18964 @@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
18965 * Align the stack pointer according to the i386 ABI,
18966 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18967 */
18968 - sp = ((sp + 4) & -16ul) - 4;
18969 + sp = ((sp - 12) & -16ul) - 4;
18970 #else /* !CONFIG_X86_32 */
18971 sp = round_down(sp, 16) - 8;
18972 #endif
18973 @@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18974 * Return an always-bogus address instead so we will die with SIGSEGV.
18975 */
18976 if (onsigstack && !likely(on_sig_stack(sp)))
18977 - return (void __user *)-1L;
18978 + return (__force void __user *)-1L;
18979
18980 /* save i387 state */
18981 if (used_math() && save_i387_xstate(*fpstate) < 0)
18982 - return (void __user *)-1L;
18983 + return (__force void __user *)-1L;
18984
18985 return (void __user *)sp;
18986 }
18987 @@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18988 }
18989
18990 if (current->mm->context.vdso)
18991 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18992 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18993 else
18994 - restorer = &frame->retcode;
18995 + restorer = (void __user *)&frame->retcode;
18996 if (ka->sa.sa_flags & SA_RESTORER)
18997 restorer = ka->sa.sa_restorer;
18998
18999 @@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19000 * reasons and because gdb uses it as a signature to notice
19001 * signal handler stack frames.
19002 */
19003 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19004 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19005
19006 if (err)
19007 return -EFAULT;
19008 @@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19009 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19010
19011 /* Set up to return from userspace. */
19012 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19013 + if (current->mm->context.vdso)
19014 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19015 + else
19016 + restorer = (void __user *)&frame->retcode;
19017 if (ka->sa.sa_flags & SA_RESTORER)
19018 restorer = ka->sa.sa_restorer;
19019 put_user_ex(restorer, &frame->pretcode);
19020 @@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19021 * reasons and because gdb uses it as a signature to notice
19022 * signal handler stack frames.
19023 */
19024 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19025 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19026 } put_user_catch(err);
19027
19028 if (err)
19029 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19030 index 7bd8a08..2659b5b 100644
19031 --- a/arch/x86/kernel/smpboot.c
19032 +++ b/arch/x86/kernel/smpboot.c
19033 @@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19034 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19035 (THREAD_SIZE + task_stack_page(idle))) - 1);
19036 per_cpu(current_task, cpu) = idle;
19037 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19038
19039 #ifdef CONFIG_X86_32
19040 /* Stack for startup_32 can be just as for start_secondary onwards */
19041 @@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19042 #else
19043 clear_tsk_thread_flag(idle, TIF_FORK);
19044 initial_gs = per_cpu_offset(cpu);
19045 - per_cpu(kernel_stack, cpu) =
19046 - (unsigned long)task_stack_page(idle) -
19047 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19048 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19049 #endif
19050 +
19051 + pax_open_kernel();
19052 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19053 + pax_close_kernel();
19054 +
19055 initial_code = (unsigned long)start_secondary;
19056 stack_start = idle->thread.sp;
19057
19058 @@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19059
19060 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19061
19062 +#ifdef CONFIG_PAX_PER_CPU_PGD
19063 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19064 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19065 + KERNEL_PGD_PTRS);
19066 +#endif
19067 +
19068 err = do_boot_cpu(apicid, cpu, tidle);
19069 if (err) {
19070 pr_debug("do_boot_cpu failed %d\n", err);
19071 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19072 index c346d11..d43b163 100644
19073 --- a/arch/x86/kernel/step.c
19074 +++ b/arch/x86/kernel/step.c
19075 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19076 struct desc_struct *desc;
19077 unsigned long base;
19078
19079 - seg &= ~7UL;
19080 + seg >>= 3;
19081
19082 mutex_lock(&child->mm->context.lock);
19083 - if (unlikely((seg >> 3) >= child->mm->context.size))
19084 + if (unlikely(seg >= child->mm->context.size))
19085 addr = -1L; /* bogus selector, access would fault */
19086 else {
19087 desc = child->mm->context.ldt + seg;
19088 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19089 addr += base;
19090 }
19091 mutex_unlock(&child->mm->context.lock);
19092 - }
19093 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19094 + addr = ktla_ktva(addr);
19095
19096 return addr;
19097 }
19098 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19099 unsigned char opcode[15];
19100 unsigned long addr = convert_ip_to_linear(child, regs);
19101
19102 + if (addr == -EINVAL)
19103 + return 0;
19104 +
19105 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19106 for (i = 0; i < copied; i++) {
19107 switch (opcode[i]) {
19108 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19109 index 0b0cb5f..db6b9ed 100644
19110 --- a/arch/x86/kernel/sys_i386_32.c
19111 +++ b/arch/x86/kernel/sys_i386_32.c
19112 @@ -24,17 +24,224 @@
19113
19114 #include <asm/syscalls.h>
19115
19116 -/*
19117 - * Do a system call from kernel instead of calling sys_execve so we
19118 - * end up with proper pt_regs.
19119 - */
19120 -int kernel_execve(const char *filename,
19121 - const char *const argv[],
19122 - const char *const envp[])
19123 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19124 {
19125 - long __res;
19126 - asm volatile ("int $0x80"
19127 - : "=a" (__res)
19128 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19129 - return __res;
19130 + unsigned long pax_task_size = TASK_SIZE;
19131 +
19132 +#ifdef CONFIG_PAX_SEGMEXEC
19133 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19134 + pax_task_size = SEGMEXEC_TASK_SIZE;
19135 +#endif
19136 +
19137 + if (len > pax_task_size || addr > pax_task_size - len)
19138 + return -EINVAL;
19139 +
19140 + return 0;
19141 +}
19142 +
19143 +unsigned long
19144 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19145 + unsigned long len, unsigned long pgoff, unsigned long flags)
19146 +{
19147 + struct mm_struct *mm = current->mm;
19148 + struct vm_area_struct *vma;
19149 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19150 +
19151 +#ifdef CONFIG_PAX_SEGMEXEC
19152 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19153 + pax_task_size = SEGMEXEC_TASK_SIZE;
19154 +#endif
19155 +
19156 + pax_task_size -= PAGE_SIZE;
19157 +
19158 + if (len > pax_task_size)
19159 + return -ENOMEM;
19160 +
19161 + if (flags & MAP_FIXED)
19162 + return addr;
19163 +
19164 +#ifdef CONFIG_PAX_RANDMMAP
19165 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19166 +#endif
19167 +
19168 + if (addr) {
19169 + addr = PAGE_ALIGN(addr);
19170 + if (pax_task_size - len >= addr) {
19171 + vma = find_vma(mm, addr);
19172 + if (check_heap_stack_gap(vma, addr, len))
19173 + return addr;
19174 + }
19175 + }
19176 + if (len > mm->cached_hole_size) {
19177 + start_addr = addr = mm->free_area_cache;
19178 + } else {
19179 + start_addr = addr = mm->mmap_base;
19180 + mm->cached_hole_size = 0;
19181 + }
19182 +
19183 +#ifdef CONFIG_PAX_PAGEEXEC
19184 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19185 + start_addr = 0x00110000UL;
19186 +
19187 +#ifdef CONFIG_PAX_RANDMMAP
19188 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19189 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19190 +#endif
19191 +
19192 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19193 + start_addr = addr = mm->mmap_base;
19194 + else
19195 + addr = start_addr;
19196 + }
19197 +#endif
19198 +
19199 +full_search:
19200 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19201 + /* At this point: (!vma || addr < vma->vm_end). */
19202 + if (pax_task_size - len < addr) {
19203 + /*
19204 + * Start a new search - just in case we missed
19205 + * some holes.
19206 + */
19207 + if (start_addr != mm->mmap_base) {
19208 + start_addr = addr = mm->mmap_base;
19209 + mm->cached_hole_size = 0;
19210 + goto full_search;
19211 + }
19212 + return -ENOMEM;
19213 + }
19214 + if (check_heap_stack_gap(vma, addr, len))
19215 + break;
19216 + if (addr + mm->cached_hole_size < vma->vm_start)
19217 + mm->cached_hole_size = vma->vm_start - addr;
19218 + addr = vma->vm_end;
19219 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19220 + start_addr = addr = mm->mmap_base;
19221 + mm->cached_hole_size = 0;
19222 + goto full_search;
19223 + }
19224 + }
19225 +
19226 + /*
19227 + * Remember the place where we stopped the search:
19228 + */
19229 + mm->free_area_cache = addr + len;
19230 + return addr;
19231 +}
19232 +
19233 +unsigned long
19234 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19235 + const unsigned long len, const unsigned long pgoff,
19236 + const unsigned long flags)
19237 +{
19238 + struct vm_area_struct *vma;
19239 + struct mm_struct *mm = current->mm;
19240 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19241 +
19242 +#ifdef CONFIG_PAX_SEGMEXEC
19243 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19244 + pax_task_size = SEGMEXEC_TASK_SIZE;
19245 +#endif
19246 +
19247 + pax_task_size -= PAGE_SIZE;
19248 +
19249 + /* requested length too big for entire address space */
19250 + if (len > pax_task_size)
19251 + return -ENOMEM;
19252 +
19253 + if (flags & MAP_FIXED)
19254 + return addr;
19255 +
19256 +#ifdef CONFIG_PAX_PAGEEXEC
19257 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19258 + goto bottomup;
19259 +#endif
19260 +
19261 +#ifdef CONFIG_PAX_RANDMMAP
19262 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19263 +#endif
19264 +
19265 + /* requesting a specific address */
19266 + if (addr) {
19267 + addr = PAGE_ALIGN(addr);
19268 + if (pax_task_size - len >= addr) {
19269 + vma = find_vma(mm, addr);
19270 + if (check_heap_stack_gap(vma, addr, len))
19271 + return addr;
19272 + }
19273 + }
19274 +
19275 + /* check if free_area_cache is useful for us */
19276 + if (len <= mm->cached_hole_size) {
19277 + mm->cached_hole_size = 0;
19278 + mm->free_area_cache = mm->mmap_base;
19279 + }
19280 +
19281 + /* either no address requested or can't fit in requested address hole */
19282 + addr = mm->free_area_cache;
19283 +
19284 + /* make sure it can fit in the remaining address space */
19285 + if (addr > len) {
19286 + vma = find_vma(mm, addr-len);
19287 + if (check_heap_stack_gap(vma, addr - len, len))
19288 + /* remember the address as a hint for next time */
19289 + return (mm->free_area_cache = addr-len);
19290 + }
19291 +
19292 + if (mm->mmap_base < len)
19293 + goto bottomup;
19294 +
19295 + addr = mm->mmap_base-len;
19296 +
19297 + do {
19298 + /*
19299 + * Lookup failure means no vma is above this address,
19300 + * else if new region fits below vma->vm_start,
19301 + * return with success:
19302 + */
19303 + vma = find_vma(mm, addr);
19304 + if (check_heap_stack_gap(vma, addr, len))
19305 + /* remember the address as a hint for next time */
19306 + return (mm->free_area_cache = addr);
19307 +
19308 + /* remember the largest hole we saw so far */
19309 + if (addr + mm->cached_hole_size < vma->vm_start)
19310 + mm->cached_hole_size = vma->vm_start - addr;
19311 +
19312 + /* try just below the current vma->vm_start */
19313 + addr = skip_heap_stack_gap(vma, len);
19314 + } while (!IS_ERR_VALUE(addr));
19315 +
19316 +bottomup:
19317 + /*
19318 + * A failed mmap() very likely causes application failure,
19319 + * so fall back to the bottom-up function here. This scenario
19320 + * can happen with large stack limits and large mmap()
19321 + * allocations.
19322 + */
19323 +
19324 +#ifdef CONFIG_PAX_SEGMEXEC
19325 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19326 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19327 + else
19328 +#endif
19329 +
19330 + mm->mmap_base = TASK_UNMAPPED_BASE;
19331 +
19332 +#ifdef CONFIG_PAX_RANDMMAP
19333 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19334 + mm->mmap_base += mm->delta_mmap;
19335 +#endif
19336 +
19337 + mm->free_area_cache = mm->mmap_base;
19338 + mm->cached_hole_size = ~0UL;
19339 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19340 + /*
19341 + * Restore the topdown base:
19342 + */
19343 + mm->mmap_base = base;
19344 + mm->free_area_cache = base;
19345 + mm->cached_hole_size = ~0UL;
19346 +
19347 + return addr;
19348 }
19349 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19350 index b4d3c39..82bb73b 100644
19351 --- a/arch/x86/kernel/sys_x86_64.c
19352 +++ b/arch/x86/kernel/sys_x86_64.c
19353 @@ -95,8 +95,8 @@ out:
19354 return error;
19355 }
19356
19357 -static void find_start_end(unsigned long flags, unsigned long *begin,
19358 - unsigned long *end)
19359 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19360 + unsigned long *begin, unsigned long *end)
19361 {
19362 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19363 unsigned long new_begin;
19364 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19365 *begin = new_begin;
19366 }
19367 } else {
19368 - *begin = TASK_UNMAPPED_BASE;
19369 + *begin = mm->mmap_base;
19370 *end = TASK_SIZE;
19371 }
19372 }
19373 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19374 if (flags & MAP_FIXED)
19375 return addr;
19376
19377 - find_start_end(flags, &begin, &end);
19378 + find_start_end(mm, flags, &begin, &end);
19379
19380 if (len > end)
19381 return -ENOMEM;
19382
19383 +#ifdef CONFIG_PAX_RANDMMAP
19384 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19385 +#endif
19386 +
19387 if (addr) {
19388 addr = PAGE_ALIGN(addr);
19389 vma = find_vma(mm, addr);
19390 - if (end - len >= addr &&
19391 - (!vma || addr + len <= vma->vm_start))
19392 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19393 return addr;
19394 }
19395 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19396 @@ -172,7 +175,7 @@ full_search:
19397 }
19398 return -ENOMEM;
19399 }
19400 - if (!vma || addr + len <= vma->vm_start) {
19401 + if (check_heap_stack_gap(vma, addr, len)) {
19402 /*
19403 * Remember the place where we stopped the search:
19404 */
19405 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19406 {
19407 struct vm_area_struct *vma;
19408 struct mm_struct *mm = current->mm;
19409 - unsigned long addr = addr0, start_addr;
19410 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19411
19412 /* requested length too big for entire address space */
19413 if (len > TASK_SIZE)
19414 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19415 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19416 goto bottomup;
19417
19418 +#ifdef CONFIG_PAX_RANDMMAP
19419 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19420 +#endif
19421 +
19422 /* requesting a specific address */
19423 if (addr) {
19424 addr = PAGE_ALIGN(addr);
19425 - vma = find_vma(mm, addr);
19426 - if (TASK_SIZE - len >= addr &&
19427 - (!vma || addr + len <= vma->vm_start))
19428 - return addr;
19429 + if (TASK_SIZE - len >= addr) {
19430 + vma = find_vma(mm, addr);
19431 + if (check_heap_stack_gap(vma, addr, len))
19432 + return addr;
19433 + }
19434 }
19435
19436 /* check if free_area_cache is useful for us */
19437 @@ -240,7 +248,7 @@ try_again:
19438 * return with success:
19439 */
19440 vma = find_vma(mm, addr);
19441 - if (!vma || addr+len <= vma->vm_start)
19442 + if (check_heap_stack_gap(vma, addr, len))
19443 /* remember the address as a hint for next time */
19444 return mm->free_area_cache = addr;
19445
19446 @@ -249,8 +257,8 @@ try_again:
19447 mm->cached_hole_size = vma->vm_start - addr;
19448
19449 /* try just below the current vma->vm_start */
19450 - addr = vma->vm_start-len;
19451 - } while (len < vma->vm_start);
19452 + addr = skip_heap_stack_gap(vma, len);
19453 + } while (!IS_ERR_VALUE(addr));
19454
19455 fail:
19456 /*
19457 @@ -270,13 +278,21 @@ bottomup:
19458 * can happen with large stack limits and large mmap()
19459 * allocations.
19460 */
19461 + mm->mmap_base = TASK_UNMAPPED_BASE;
19462 +
19463 +#ifdef CONFIG_PAX_RANDMMAP
19464 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19465 + mm->mmap_base += mm->delta_mmap;
19466 +#endif
19467 +
19468 + mm->free_area_cache = mm->mmap_base;
19469 mm->cached_hole_size = ~0UL;
19470 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19471 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19472 /*
19473 * Restore the topdown base:
19474 */
19475 - mm->free_area_cache = mm->mmap_base;
19476 + mm->mmap_base = base;
19477 + mm->free_area_cache = base;
19478 mm->cached_hole_size = ~0UL;
19479
19480 return addr;
19481 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19482 index f84fe00..93fe08f 100644
19483 --- a/arch/x86/kernel/tboot.c
19484 +++ b/arch/x86/kernel/tboot.c
19485 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19486
19487 void tboot_shutdown(u32 shutdown_type)
19488 {
19489 - void (*shutdown)(void);
19490 + void (* __noreturn shutdown)(void);
19491
19492 if (!tboot_enabled())
19493 return;
19494 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19495
19496 switch_to_tboot_pt();
19497
19498 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19499 + shutdown = (void *)tboot->shutdown_entry;
19500 shutdown();
19501
19502 /* should not reach here */
19503 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19504 return 0;
19505 }
19506
19507 -static atomic_t ap_wfs_count;
19508 +static atomic_unchecked_t ap_wfs_count;
19509
19510 static int tboot_wait_for_aps(int num_aps)
19511 {
19512 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19513 {
19514 switch (action) {
19515 case CPU_DYING:
19516 - atomic_inc(&ap_wfs_count);
19517 + atomic_inc_unchecked(&ap_wfs_count);
19518 if (num_online_cpus() == 1)
19519 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19520 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19521 return NOTIFY_BAD;
19522 break;
19523 }
19524 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19525
19526 tboot_create_trampoline();
19527
19528 - atomic_set(&ap_wfs_count, 0);
19529 + atomic_set_unchecked(&ap_wfs_count, 0);
19530 register_hotcpu_notifier(&tboot_cpu_notifier);
19531
19532 acpi_os_set_prepare_sleep(&tboot_sleep);
19533 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19534 index 24d3c91..d06b473 100644
19535 --- a/arch/x86/kernel/time.c
19536 +++ b/arch/x86/kernel/time.c
19537 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19538 {
19539 unsigned long pc = instruction_pointer(regs);
19540
19541 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19542 + if (!user_mode(regs) && in_lock_functions(pc)) {
19543 #ifdef CONFIG_FRAME_POINTER
19544 - return *(unsigned long *)(regs->bp + sizeof(long));
19545 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19546 #else
19547 unsigned long *sp =
19548 (unsigned long *)kernel_stack_pointer(regs);
19549 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19550 * or above a saved flags. Eflags has bits 22-31 zero,
19551 * kernel addresses don't.
19552 */
19553 +
19554 +#ifdef CONFIG_PAX_KERNEXEC
19555 + return ktla_ktva(sp[0]);
19556 +#else
19557 if (sp[0] >> 22)
19558 return sp[0];
19559 if (sp[1] >> 22)
19560 return sp[1];
19561 #endif
19562 +
19563 +#endif
19564 }
19565 return pc;
19566 }
19567 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19568 index 9d9d2f9..ed344e4 100644
19569 --- a/arch/x86/kernel/tls.c
19570 +++ b/arch/x86/kernel/tls.c
19571 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19572 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19573 return -EINVAL;
19574
19575 +#ifdef CONFIG_PAX_SEGMEXEC
19576 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19577 + return -EINVAL;
19578 +#endif
19579 +
19580 set_tls_desc(p, idx, &info, 1);
19581
19582 return 0;
19583 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19584 index 05b31d9..501d3ba 100644
19585 --- a/arch/x86/kernel/traps.c
19586 +++ b/arch/x86/kernel/traps.c
19587 @@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19588
19589 /* Do we ignore FPU interrupts ? */
19590 char ignore_fpu_irq;
19591 -
19592 -/*
19593 - * The IDT has to be page-aligned to simplify the Pentium
19594 - * F0 0F bug workaround.
19595 - */
19596 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19597 #endif
19598
19599 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19600 @@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19601 }
19602
19603 static void __kprobes
19604 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19605 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19606 long error_code, siginfo_t *info)
19607 {
19608 struct task_struct *tsk = current;
19609
19610 #ifdef CONFIG_X86_32
19611 - if (regs->flags & X86_VM_MASK) {
19612 + if (v8086_mode(regs)) {
19613 /*
19614 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19615 * On nmi (interrupt 2), do_trap should not be called.
19616 @@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19617 }
19618 #endif
19619
19620 - if (!user_mode(regs))
19621 + if (!user_mode_novm(regs))
19622 goto kernel_trap;
19623
19624 #ifdef CONFIG_X86_32
19625 @@ -145,7 +139,7 @@ trap_signal:
19626 printk_ratelimit()) {
19627 printk(KERN_INFO
19628 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19629 - tsk->comm, tsk->pid, str,
19630 + tsk->comm, task_pid_nr(tsk), str,
19631 regs->ip, regs->sp, error_code);
19632 print_vma_addr(" in ", regs->ip);
19633 printk("\n");
19634 @@ -162,8 +156,20 @@ kernel_trap:
19635 if (!fixup_exception(regs)) {
19636 tsk->thread.error_code = error_code;
19637 tsk->thread.trap_nr = trapnr;
19638 +
19639 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19640 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19641 + str = "PAX: suspicious stack segment fault";
19642 +#endif
19643 +
19644 die(str, regs, error_code);
19645 }
19646 +
19647 +#ifdef CONFIG_PAX_REFCOUNT
19648 + if (trapnr == 4)
19649 + pax_report_refcount_overflow(regs);
19650 +#endif
19651 +
19652 return;
19653
19654 #ifdef CONFIG_X86_32
19655 @@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19656 conditional_sti(regs);
19657
19658 #ifdef CONFIG_X86_32
19659 - if (regs->flags & X86_VM_MASK)
19660 + if (v8086_mode(regs))
19661 goto gp_in_vm86;
19662 #endif
19663
19664 tsk = current;
19665 - if (!user_mode(regs))
19666 + if (!user_mode_novm(regs))
19667 goto gp_in_kernel;
19668
19669 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19670 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19671 + struct mm_struct *mm = tsk->mm;
19672 + unsigned long limit;
19673 +
19674 + down_write(&mm->mmap_sem);
19675 + limit = mm->context.user_cs_limit;
19676 + if (limit < TASK_SIZE) {
19677 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19678 + up_write(&mm->mmap_sem);
19679 + return;
19680 + }
19681 + up_write(&mm->mmap_sem);
19682 + }
19683 +#endif
19684 +
19685 tsk->thread.error_code = error_code;
19686 tsk->thread.trap_nr = X86_TRAP_GP;
19687
19688 @@ -296,6 +318,13 @@ gp_in_kernel:
19689 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19690 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19691 return;
19692 +
19693 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19694 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19695 + die("PAX: suspicious general protection fault", regs, error_code);
19696 + else
19697 +#endif
19698 +
19699 die("general protection fault", regs, error_code);
19700 }
19701
19702 @@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19703 /* It's safe to allow irq's after DR6 has been saved */
19704 preempt_conditional_sti(regs);
19705
19706 - if (regs->flags & X86_VM_MASK) {
19707 + if (v8086_mode(regs)) {
19708 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19709 X86_TRAP_DB);
19710 preempt_conditional_cli(regs);
19711 @@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19712 * We already checked v86 mode above, so we can check for kernel mode
19713 * by just checking the CPL of CS.
19714 */
19715 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19716 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19717 tsk->thread.debugreg6 &= ~DR_STEP;
19718 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19719 regs->flags &= ~X86_EFLAGS_TF;
19720 @@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19721 return;
19722 conditional_sti(regs);
19723
19724 - if (!user_mode_vm(regs))
19725 + if (!user_mode(regs))
19726 {
19727 if (!fixup_exception(regs)) {
19728 task->thread.error_code = error_code;
19729 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19730 index dc4e910..c9dedab 100644
19731 --- a/arch/x86/kernel/uprobes.c
19732 +++ b/arch/x86/kernel/uprobes.c
19733 @@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19734 int ret = NOTIFY_DONE;
19735
19736 /* We are only interested in userspace traps */
19737 - if (regs && !user_mode_vm(regs))
19738 + if (regs && !user_mode(regs))
19739 return NOTIFY_DONE;
19740
19741 switch (val) {
19742 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19743 index b9242ba..50c5edd 100644
19744 --- a/arch/x86/kernel/verify_cpu.S
19745 +++ b/arch/x86/kernel/verify_cpu.S
19746 @@ -20,6 +20,7 @@
19747 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19748 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19749 * arch/x86/kernel/head_32.S: processor startup
19750 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19751 *
19752 * verify_cpu, returns the status of longmode and SSE in register %eax.
19753 * 0: Success 1: Failure
19754 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19755 index 255f58a..5e91150 100644
19756 --- a/arch/x86/kernel/vm86_32.c
19757 +++ b/arch/x86/kernel/vm86_32.c
19758 @@ -41,6 +41,7 @@
19759 #include <linux/ptrace.h>
19760 #include <linux/audit.h>
19761 #include <linux/stddef.h>
19762 +#include <linux/grsecurity.h>
19763
19764 #include <asm/uaccess.h>
19765 #include <asm/io.h>
19766 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19767 do_exit(SIGSEGV);
19768 }
19769
19770 - tss = &per_cpu(init_tss, get_cpu());
19771 + tss = init_tss + get_cpu();
19772 current->thread.sp0 = current->thread.saved_sp0;
19773 current->thread.sysenter_cs = __KERNEL_CS;
19774 load_sp0(tss, &current->thread);
19775 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19776 struct task_struct *tsk;
19777 int tmp, ret = -EPERM;
19778
19779 +#ifdef CONFIG_GRKERNSEC_VM86
19780 + if (!capable(CAP_SYS_RAWIO)) {
19781 + gr_handle_vm86();
19782 + goto out;
19783 + }
19784 +#endif
19785 +
19786 tsk = current;
19787 if (tsk->thread.saved_sp0)
19788 goto out;
19789 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19790 int tmp, ret;
19791 struct vm86plus_struct __user *v86;
19792
19793 +#ifdef CONFIG_GRKERNSEC_VM86
19794 + if (!capable(CAP_SYS_RAWIO)) {
19795 + gr_handle_vm86();
19796 + ret = -EPERM;
19797 + goto out;
19798 + }
19799 +#endif
19800 +
19801 tsk = current;
19802 switch (cmd) {
19803 case VM86_REQUEST_IRQ:
19804 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19805 tsk->thread.saved_fs = info->regs32->fs;
19806 tsk->thread.saved_gs = get_user_gs(info->regs32);
19807
19808 - tss = &per_cpu(init_tss, get_cpu());
19809 + tss = init_tss + get_cpu();
19810 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19811 if (cpu_has_sep)
19812 tsk->thread.sysenter_cs = 0;
19813 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19814 goto cannot_handle;
19815 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19816 goto cannot_handle;
19817 - intr_ptr = (unsigned long __user *) (i << 2);
19818 + intr_ptr = (__force unsigned long __user *) (i << 2);
19819 if (get_user(segoffs, intr_ptr))
19820 goto cannot_handle;
19821 if ((segoffs >> 16) == BIOSSEG)
19822 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19823 index 22a1530..8fbaaad 100644
19824 --- a/arch/x86/kernel/vmlinux.lds.S
19825 +++ b/arch/x86/kernel/vmlinux.lds.S
19826 @@ -26,6 +26,13 @@
19827 #include <asm/page_types.h>
19828 #include <asm/cache.h>
19829 #include <asm/boot.h>
19830 +#include <asm/segment.h>
19831 +
19832 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19833 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19834 +#else
19835 +#define __KERNEL_TEXT_OFFSET 0
19836 +#endif
19837
19838 #undef i386 /* in case the preprocessor is a 32bit one */
19839
19840 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19841
19842 PHDRS {
19843 text PT_LOAD FLAGS(5); /* R_E */
19844 +#ifdef CONFIG_X86_32
19845 + module PT_LOAD FLAGS(5); /* R_E */
19846 +#endif
19847 +#ifdef CONFIG_XEN
19848 + rodata PT_LOAD FLAGS(5); /* R_E */
19849 +#else
19850 + rodata PT_LOAD FLAGS(4); /* R__ */
19851 +#endif
19852 data PT_LOAD FLAGS(6); /* RW_ */
19853 -#ifdef CONFIG_X86_64
19854 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19855 #ifdef CONFIG_SMP
19856 percpu PT_LOAD FLAGS(6); /* RW_ */
19857 #endif
19858 + text.init PT_LOAD FLAGS(5); /* R_E */
19859 + text.exit PT_LOAD FLAGS(5); /* R_E */
19860 init PT_LOAD FLAGS(7); /* RWE */
19861 -#endif
19862 note PT_NOTE FLAGS(0); /* ___ */
19863 }
19864
19865 SECTIONS
19866 {
19867 #ifdef CONFIG_X86_32
19868 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19869 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19870 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19871 #else
19872 - . = __START_KERNEL;
19873 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19874 + . = __START_KERNEL;
19875 #endif
19876
19877 /* Text and read-only data */
19878 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19879 - _text = .;
19880 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19881 /* bootstrapping code */
19882 +#ifdef CONFIG_X86_32
19883 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19884 +#else
19885 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19886 +#endif
19887 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19888 + _text = .;
19889 HEAD_TEXT
19890 #ifdef CONFIG_X86_32
19891 . = ALIGN(PAGE_SIZE);
19892 @@ -108,13 +128,48 @@ SECTIONS
19893 IRQENTRY_TEXT
19894 *(.fixup)
19895 *(.gnu.warning)
19896 - /* End of text section */
19897 - _etext = .;
19898 } :text = 0x9090
19899
19900 - NOTES :text :note
19901 + . += __KERNEL_TEXT_OFFSET;
19902
19903 - EXCEPTION_TABLE(16) :text = 0x9090
19904 +#ifdef CONFIG_X86_32
19905 + . = ALIGN(PAGE_SIZE);
19906 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19907 +
19908 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19909 + MODULES_EXEC_VADDR = .;
19910 + BYTE(0)
19911 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19912 + . = ALIGN(HPAGE_SIZE) - 1;
19913 + MODULES_EXEC_END = .;
19914 +#endif
19915 +
19916 + } :module
19917 +#endif
19918 +
19919 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19920 + /* End of text section */
19921 + BYTE(0)
19922 + _etext = . - __KERNEL_TEXT_OFFSET;
19923 + }
19924 +
19925 +#ifdef CONFIG_X86_32
19926 + . = ALIGN(PAGE_SIZE);
19927 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19928 + *(.idt)
19929 + . = ALIGN(PAGE_SIZE);
19930 + *(.empty_zero_page)
19931 + *(.initial_pg_fixmap)
19932 + *(.initial_pg_pmd)
19933 + *(.initial_page_table)
19934 + *(.swapper_pg_dir)
19935 + } :rodata
19936 +#endif
19937 +
19938 + . = ALIGN(PAGE_SIZE);
19939 + NOTES :rodata :note
19940 +
19941 + EXCEPTION_TABLE(16) :rodata
19942
19943 #if defined(CONFIG_DEBUG_RODATA)
19944 /* .text should occupy whole number of pages */
19945 @@ -126,16 +181,20 @@ SECTIONS
19946
19947 /* Data */
19948 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19949 +
19950 +#ifdef CONFIG_PAX_KERNEXEC
19951 + . = ALIGN(HPAGE_SIZE);
19952 +#else
19953 + . = ALIGN(PAGE_SIZE);
19954 +#endif
19955 +
19956 /* Start of data section */
19957 _sdata = .;
19958
19959 /* init_task */
19960 INIT_TASK_DATA(THREAD_SIZE)
19961
19962 -#ifdef CONFIG_X86_32
19963 - /* 32 bit has nosave before _edata */
19964 NOSAVE_DATA
19965 -#endif
19966
19967 PAGE_ALIGNED_DATA(PAGE_SIZE)
19968
19969 @@ -176,12 +235,19 @@ SECTIONS
19970 #endif /* CONFIG_X86_64 */
19971
19972 /* Init code and data - will be freed after init */
19973 - . = ALIGN(PAGE_SIZE);
19974 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19975 + BYTE(0)
19976 +
19977 +#ifdef CONFIG_PAX_KERNEXEC
19978 + . = ALIGN(HPAGE_SIZE);
19979 +#else
19980 + . = ALIGN(PAGE_SIZE);
19981 +#endif
19982 +
19983 __init_begin = .; /* paired with __init_end */
19984 - }
19985 + } :init.begin
19986
19987 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19988 +#ifdef CONFIG_SMP
19989 /*
19990 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19991 * output PHDR, so the next output section - .init.text - should
19992 @@ -190,12 +256,27 @@ SECTIONS
19993 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19994 #endif
19995
19996 - INIT_TEXT_SECTION(PAGE_SIZE)
19997 -#ifdef CONFIG_X86_64
19998 - :init
19999 -#endif
20000 + . = ALIGN(PAGE_SIZE);
20001 + init_begin = .;
20002 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20003 + VMLINUX_SYMBOL(_sinittext) = .;
20004 + INIT_TEXT
20005 + VMLINUX_SYMBOL(_einittext) = .;
20006 + . = ALIGN(PAGE_SIZE);
20007 + } :text.init
20008
20009 - INIT_DATA_SECTION(16)
20010 + /*
20011 + * .exit.text is discard at runtime, not link time, to deal with
20012 + * references from .altinstructions and .eh_frame
20013 + */
20014 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20015 + EXIT_TEXT
20016 + . = ALIGN(16);
20017 + } :text.exit
20018 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20019 +
20020 + . = ALIGN(PAGE_SIZE);
20021 + INIT_DATA_SECTION(16) :init
20022
20023 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20024 __x86_cpu_dev_start = .;
20025 @@ -257,19 +338,12 @@ SECTIONS
20026 }
20027
20028 . = ALIGN(8);
20029 - /*
20030 - * .exit.text is discard at runtime, not link time, to deal with
20031 - * references from .altinstructions and .eh_frame
20032 - */
20033 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20034 - EXIT_TEXT
20035 - }
20036
20037 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20038 EXIT_DATA
20039 }
20040
20041 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20042 +#ifndef CONFIG_SMP
20043 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20044 #endif
20045
20046 @@ -288,16 +362,10 @@ SECTIONS
20047 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20048 __smp_locks = .;
20049 *(.smp_locks)
20050 - . = ALIGN(PAGE_SIZE);
20051 __smp_locks_end = .;
20052 + . = ALIGN(PAGE_SIZE);
20053 }
20054
20055 -#ifdef CONFIG_X86_64
20056 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20057 - NOSAVE_DATA
20058 - }
20059 -#endif
20060 -
20061 /* BSS */
20062 . = ALIGN(PAGE_SIZE);
20063 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20064 @@ -313,6 +381,7 @@ SECTIONS
20065 __brk_base = .;
20066 . += 64 * 1024; /* 64k alignment slop space */
20067 *(.brk_reservation) /* areas brk users have reserved */
20068 + . = ALIGN(HPAGE_SIZE);
20069 __brk_limit = .;
20070 }
20071
20072 @@ -339,13 +408,12 @@ SECTIONS
20073 * for the boot processor.
20074 */
20075 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20076 -INIT_PER_CPU(gdt_page);
20077 INIT_PER_CPU(irq_stack_union);
20078
20079 /*
20080 * Build-time check on the image size:
20081 */
20082 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20083 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20084 "kernel image bigger than KERNEL_IMAGE_SIZE");
20085
20086 #ifdef CONFIG_SMP
20087 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20088 index 5db36ca..2938af9 100644
20089 --- a/arch/x86/kernel/vsyscall_64.c
20090 +++ b/arch/x86/kernel/vsyscall_64.c
20091 @@ -54,15 +54,13 @@
20092 DEFINE_VVAR(int, vgetcpu_mode);
20093 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20094
20095 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20096 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20097
20098 static int __init vsyscall_setup(char *str)
20099 {
20100 if (str) {
20101 if (!strcmp("emulate", str))
20102 vsyscall_mode = EMULATE;
20103 - else if (!strcmp("native", str))
20104 - vsyscall_mode = NATIVE;
20105 else if (!strcmp("none", str))
20106 vsyscall_mode = NONE;
20107 else
20108 @@ -309,8 +307,7 @@ done:
20109 return true;
20110
20111 sigsegv:
20112 - force_sig(SIGSEGV, current);
20113 - return true;
20114 + do_group_exit(SIGKILL);
20115 }
20116
20117 /*
20118 @@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20119 extern char __vvar_page;
20120 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20121
20122 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20123 - vsyscall_mode == NATIVE
20124 - ? PAGE_KERNEL_VSYSCALL
20125 - : PAGE_KERNEL_VVAR);
20126 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20127 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20128 (unsigned long)VSYSCALL_START);
20129
20130 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20131 index 9796c2f..f686fbf 100644
20132 --- a/arch/x86/kernel/x8664_ksyms_64.c
20133 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20134 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20135 EXPORT_SYMBOL(copy_user_generic_string);
20136 EXPORT_SYMBOL(copy_user_generic_unrolled);
20137 EXPORT_SYMBOL(__copy_user_nocache);
20138 -EXPORT_SYMBOL(_copy_from_user);
20139 -EXPORT_SYMBOL(_copy_to_user);
20140
20141 EXPORT_SYMBOL(copy_page);
20142 EXPORT_SYMBOL(clear_page);
20143 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20144 index bd18149..2ea0183 100644
20145 --- a/arch/x86/kernel/xsave.c
20146 +++ b/arch/x86/kernel/xsave.c
20147 @@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20148 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20149 return -EINVAL;
20150
20151 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20152 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20153 fx_sw_user->extended_size -
20154 FP_XSTATE_MAGIC2_SIZE));
20155 if (err)
20156 @@ -265,7 +265,7 @@ fx_only:
20157 * the other extended state.
20158 */
20159 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20160 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20161 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20162 }
20163
20164 /*
20165 @@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20166 if (use_xsave())
20167 err = restore_user_xstate(buf);
20168 else
20169 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20170 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20171 buf);
20172 if (unlikely(err)) {
20173 /*
20174 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20175 index 7df1c6d..9ea7c79 100644
20176 --- a/arch/x86/kvm/cpuid.c
20177 +++ b/arch/x86/kvm/cpuid.c
20178 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20179 struct kvm_cpuid2 *cpuid,
20180 struct kvm_cpuid_entry2 __user *entries)
20181 {
20182 - int r;
20183 + int r, i;
20184
20185 r = -E2BIG;
20186 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20187 goto out;
20188 r = -EFAULT;
20189 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20190 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20191 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20192 goto out;
20193 + for (i = 0; i < cpuid->nent; ++i) {
20194 + struct kvm_cpuid_entry2 cpuid_entry;
20195 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20196 + goto out;
20197 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20198 + }
20199 vcpu->arch.cpuid_nent = cpuid->nent;
20200 kvm_apic_set_version(vcpu);
20201 kvm_x86_ops->cpuid_update(vcpu);
20202 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20203 struct kvm_cpuid2 *cpuid,
20204 struct kvm_cpuid_entry2 __user *entries)
20205 {
20206 - int r;
20207 + int r, i;
20208
20209 r = -E2BIG;
20210 if (cpuid->nent < vcpu->arch.cpuid_nent)
20211 goto out;
20212 r = -EFAULT;
20213 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20214 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20215 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20216 goto out;
20217 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20218 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20219 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20220 + goto out;
20221 + }
20222 return 0;
20223
20224 out:
20225 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20226 index f95d242..3b49a90 100644
20227 --- a/arch/x86/kvm/emulate.c
20228 +++ b/arch/x86/kvm/emulate.c
20229 @@ -256,6 +256,7 @@ struct gprefix {
20230
20231 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20232 do { \
20233 + unsigned long _tmp; \
20234 __asm__ __volatile__ ( \
20235 _PRE_EFLAGS("0", "4", "2") \
20236 _op _suffix " %"_x"3,%1; " \
20237 @@ -270,8 +271,6 @@ struct gprefix {
20238 /* Raw emulation: instruction has two explicit operands. */
20239 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20240 do { \
20241 - unsigned long _tmp; \
20242 - \
20243 switch ((ctxt)->dst.bytes) { \
20244 case 2: \
20245 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20246 @@ -287,7 +286,6 @@ struct gprefix {
20247
20248 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20249 do { \
20250 - unsigned long _tmp; \
20251 switch ((ctxt)->dst.bytes) { \
20252 case 1: \
20253 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20254 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20255 index 93c1574..d6097dc 100644
20256 --- a/arch/x86/kvm/lapic.c
20257 +++ b/arch/x86/kvm/lapic.c
20258 @@ -54,7 +54,7 @@
20259 #define APIC_BUS_CYCLE_NS 1
20260
20261 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20262 -#define apic_debug(fmt, arg...)
20263 +#define apic_debug(fmt, arg...) do {} while (0)
20264
20265 #define APIC_LVT_NUM 6
20266 /* 14 is the version for Xeon and Pentium 8.4.8*/
20267 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20268 index 34f9709..8eca2d5 100644
20269 --- a/arch/x86/kvm/paging_tmpl.h
20270 +++ b/arch/x86/kvm/paging_tmpl.h
20271 @@ -197,7 +197,7 @@ retry_walk:
20272 if (unlikely(kvm_is_error_hva(host_addr)))
20273 goto error;
20274
20275 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20276 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20277 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20278 goto error;
20279
20280 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20281 index f75af40..285b18f 100644
20282 --- a/arch/x86/kvm/svm.c
20283 +++ b/arch/x86/kvm/svm.c
20284 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20285 int cpu = raw_smp_processor_id();
20286
20287 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20288 +
20289 + pax_open_kernel();
20290 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20291 + pax_close_kernel();
20292 +
20293 load_TR_desc();
20294 }
20295
20296 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20297 #endif
20298 #endif
20299
20300 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20301 + __set_fs(current_thread_info()->addr_limit);
20302 +#endif
20303 +
20304 reload_tss(vcpu);
20305
20306 local_irq_disable();
20307 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20308 index 32eb588..19c4fe3 100644
20309 --- a/arch/x86/kvm/vmx.c
20310 +++ b/arch/x86/kvm/vmx.c
20311 @@ -1313,7 +1313,11 @@ static void reload_tss(void)
20312 struct desc_struct *descs;
20313
20314 descs = (void *)gdt->address;
20315 +
20316 + pax_open_kernel();
20317 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20318 + pax_close_kernel();
20319 +
20320 load_TR_desc();
20321 }
20322
20323 @@ -1475,8 +1479,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
20324 * The sysexit path does not restore ds/es, so we must set them to
20325 * a reasonable value ourselves.
20326 */
20327 - loadsegment(ds, __USER_DS);
20328 - loadsegment(es, __USER_DS);
20329 + loadsegment(ds, __KERNEL_DS);
20330 + loadsegment(es, __KERNEL_DS);
20331 #endif
20332 reload_tss();
20333 #ifdef CONFIG_X86_64
20334 @@ -2653,8 +2657,11 @@ static __init int hardware_setup(void)
20335 if (!cpu_has_vmx_flexpriority())
20336 flexpriority_enabled = 0;
20337
20338 - if (!cpu_has_vmx_tpr_shadow())
20339 - kvm_x86_ops->update_cr8_intercept = NULL;
20340 + if (!cpu_has_vmx_tpr_shadow()) {
20341 + pax_open_kernel();
20342 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20343 + pax_close_kernel();
20344 + }
20345
20346 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20347 kvm_disable_largepages();
20348 @@ -3680,7 +3687,7 @@ static void vmx_set_constant_host_state(void)
20349 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20350
20351 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20352 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20353 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20354
20355 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20356 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20357 @@ -6218,6 +6225,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20358 "jmp .Lkvm_vmx_return \n\t"
20359 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20360 ".Lkvm_vmx_return: "
20361 +
20362 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20363 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20364 + ".Lkvm_vmx_return2: "
20365 +#endif
20366 +
20367 /* Save guest registers, load host registers, keep flags */
20368 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20369 "pop %0 \n\t"
20370 @@ -6266,6 +6279,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20371 #endif
20372 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20373 [wordsize]"i"(sizeof(ulong))
20374 +
20375 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20376 + ,[cs]"i"(__KERNEL_CS)
20377 +#endif
20378 +
20379 : "cc", "memory"
20380 , R"ax", R"bx", R"di", R"si"
20381 #ifdef CONFIG_X86_64
20382 @@ -6294,6 +6312,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20383 }
20384 }
20385
20386 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20387 +
20388 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20389 + loadsegment(fs, __KERNEL_PERCPU);
20390 +#endif
20391 +
20392 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20393 + __set_fs(current_thread_info()->addr_limit);
20394 +#endif
20395 +
20396 vmx->loaded_vmcs->launched = 1;
20397
20398 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20399 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20400 index be6d549..b0ba2bf 100644
20401 --- a/arch/x86/kvm/x86.c
20402 +++ b/arch/x86/kvm/x86.c
20403 @@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20404 {
20405 struct kvm *kvm = vcpu->kvm;
20406 int lm = is_long_mode(vcpu);
20407 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20408 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20409 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20410 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20411 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20412 : kvm->arch.xen_hvm_config.blob_size_32;
20413 u32 page_num = data & ~PAGE_MASK;
20414 @@ -2214,6 +2214,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20415 if (n < msr_list.nmsrs)
20416 goto out;
20417 r = -EFAULT;
20418 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20419 + goto out;
20420 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20421 num_msrs_to_save * sizeof(u32)))
20422 goto out;
20423 @@ -2339,7 +2341,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20424 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20425 struct kvm_interrupt *irq)
20426 {
20427 - if (irq->irq < 0 || irq->irq >= 256)
20428 + if (irq->irq >= 256)
20429 return -EINVAL;
20430 if (irqchip_in_kernel(vcpu->kvm))
20431 return -ENXIO;
20432 @@ -4876,7 +4878,7 @@ static void kvm_set_mmio_spte_mask(void)
20433 kvm_mmu_set_mmio_spte_mask(mask);
20434 }
20435
20436 -int kvm_arch_init(void *opaque)
20437 +int kvm_arch_init(const void *opaque)
20438 {
20439 int r;
20440 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20441 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20442 index 642d880..44e0f3f 100644
20443 --- a/arch/x86/lguest/boot.c
20444 +++ b/arch/x86/lguest/boot.c
20445 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20446 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20447 * Launcher to reboot us.
20448 */
20449 -static void lguest_restart(char *reason)
20450 +static __noreturn void lguest_restart(char *reason)
20451 {
20452 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20453 + BUG();
20454 }
20455
20456 /*G:050
20457 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20458 index 00933d5..3a64af9 100644
20459 --- a/arch/x86/lib/atomic64_386_32.S
20460 +++ b/arch/x86/lib/atomic64_386_32.S
20461 @@ -48,6 +48,10 @@ BEGIN(read)
20462 movl (v), %eax
20463 movl 4(v), %edx
20464 RET_ENDP
20465 +BEGIN(read_unchecked)
20466 + movl (v), %eax
20467 + movl 4(v), %edx
20468 +RET_ENDP
20469 #undef v
20470
20471 #define v %esi
20472 @@ -55,6 +59,10 @@ BEGIN(set)
20473 movl %ebx, (v)
20474 movl %ecx, 4(v)
20475 RET_ENDP
20476 +BEGIN(set_unchecked)
20477 + movl %ebx, (v)
20478 + movl %ecx, 4(v)
20479 +RET_ENDP
20480 #undef v
20481
20482 #define v %esi
20483 @@ -70,6 +78,20 @@ RET_ENDP
20484 BEGIN(add)
20485 addl %eax, (v)
20486 adcl %edx, 4(v)
20487 +
20488 +#ifdef CONFIG_PAX_REFCOUNT
20489 + jno 0f
20490 + subl %eax, (v)
20491 + sbbl %edx, 4(v)
20492 + int $4
20493 +0:
20494 + _ASM_EXTABLE(0b, 0b)
20495 +#endif
20496 +
20497 +RET_ENDP
20498 +BEGIN(add_unchecked)
20499 + addl %eax, (v)
20500 + adcl %edx, 4(v)
20501 RET_ENDP
20502 #undef v
20503
20504 @@ -77,6 +99,24 @@ RET_ENDP
20505 BEGIN(add_return)
20506 addl (v), %eax
20507 adcl 4(v), %edx
20508 +
20509 +#ifdef CONFIG_PAX_REFCOUNT
20510 + into
20511 +1234:
20512 + _ASM_EXTABLE(1234b, 2f)
20513 +#endif
20514 +
20515 + movl %eax, (v)
20516 + movl %edx, 4(v)
20517 +
20518 +#ifdef CONFIG_PAX_REFCOUNT
20519 +2:
20520 +#endif
20521 +
20522 +RET_ENDP
20523 +BEGIN(add_return_unchecked)
20524 + addl (v), %eax
20525 + adcl 4(v), %edx
20526 movl %eax, (v)
20527 movl %edx, 4(v)
20528 RET_ENDP
20529 @@ -86,6 +126,20 @@ RET_ENDP
20530 BEGIN(sub)
20531 subl %eax, (v)
20532 sbbl %edx, 4(v)
20533 +
20534 +#ifdef CONFIG_PAX_REFCOUNT
20535 + jno 0f
20536 + addl %eax, (v)
20537 + adcl %edx, 4(v)
20538 + int $4
20539 +0:
20540 + _ASM_EXTABLE(0b, 0b)
20541 +#endif
20542 +
20543 +RET_ENDP
20544 +BEGIN(sub_unchecked)
20545 + subl %eax, (v)
20546 + sbbl %edx, 4(v)
20547 RET_ENDP
20548 #undef v
20549
20550 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20551 sbbl $0, %edx
20552 addl (v), %eax
20553 adcl 4(v), %edx
20554 +
20555 +#ifdef CONFIG_PAX_REFCOUNT
20556 + into
20557 +1234:
20558 + _ASM_EXTABLE(1234b, 2f)
20559 +#endif
20560 +
20561 + movl %eax, (v)
20562 + movl %edx, 4(v)
20563 +
20564 +#ifdef CONFIG_PAX_REFCOUNT
20565 +2:
20566 +#endif
20567 +
20568 +RET_ENDP
20569 +BEGIN(sub_return_unchecked)
20570 + negl %edx
20571 + negl %eax
20572 + sbbl $0, %edx
20573 + addl (v), %eax
20574 + adcl 4(v), %edx
20575 movl %eax, (v)
20576 movl %edx, 4(v)
20577 RET_ENDP
20578 @@ -105,6 +180,20 @@ RET_ENDP
20579 BEGIN(inc)
20580 addl $1, (v)
20581 adcl $0, 4(v)
20582 +
20583 +#ifdef CONFIG_PAX_REFCOUNT
20584 + jno 0f
20585 + subl $1, (v)
20586 + sbbl $0, 4(v)
20587 + int $4
20588 +0:
20589 + _ASM_EXTABLE(0b, 0b)
20590 +#endif
20591 +
20592 +RET_ENDP
20593 +BEGIN(inc_unchecked)
20594 + addl $1, (v)
20595 + adcl $0, 4(v)
20596 RET_ENDP
20597 #undef v
20598
20599 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20600 movl 4(v), %edx
20601 addl $1, %eax
20602 adcl $0, %edx
20603 +
20604 +#ifdef CONFIG_PAX_REFCOUNT
20605 + into
20606 +1234:
20607 + _ASM_EXTABLE(1234b, 2f)
20608 +#endif
20609 +
20610 + movl %eax, (v)
20611 + movl %edx, 4(v)
20612 +
20613 +#ifdef CONFIG_PAX_REFCOUNT
20614 +2:
20615 +#endif
20616 +
20617 +RET_ENDP
20618 +BEGIN(inc_return_unchecked)
20619 + movl (v), %eax
20620 + movl 4(v), %edx
20621 + addl $1, %eax
20622 + adcl $0, %edx
20623 movl %eax, (v)
20624 movl %edx, 4(v)
20625 RET_ENDP
20626 @@ -123,6 +232,20 @@ RET_ENDP
20627 BEGIN(dec)
20628 subl $1, (v)
20629 sbbl $0, 4(v)
20630 +
20631 +#ifdef CONFIG_PAX_REFCOUNT
20632 + jno 0f
20633 + addl $1, (v)
20634 + adcl $0, 4(v)
20635 + int $4
20636 +0:
20637 + _ASM_EXTABLE(0b, 0b)
20638 +#endif
20639 +
20640 +RET_ENDP
20641 +BEGIN(dec_unchecked)
20642 + subl $1, (v)
20643 + sbbl $0, 4(v)
20644 RET_ENDP
20645 #undef v
20646
20647 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20648 movl 4(v), %edx
20649 subl $1, %eax
20650 sbbl $0, %edx
20651 +
20652 +#ifdef CONFIG_PAX_REFCOUNT
20653 + into
20654 +1234:
20655 + _ASM_EXTABLE(1234b, 2f)
20656 +#endif
20657 +
20658 + movl %eax, (v)
20659 + movl %edx, 4(v)
20660 +
20661 +#ifdef CONFIG_PAX_REFCOUNT
20662 +2:
20663 +#endif
20664 +
20665 +RET_ENDP
20666 +BEGIN(dec_return_unchecked)
20667 + movl (v), %eax
20668 + movl 4(v), %edx
20669 + subl $1, %eax
20670 + sbbl $0, %edx
20671 movl %eax, (v)
20672 movl %edx, 4(v)
20673 RET_ENDP
20674 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20675 adcl %edx, %edi
20676 addl (v), %eax
20677 adcl 4(v), %edx
20678 +
20679 +#ifdef CONFIG_PAX_REFCOUNT
20680 + into
20681 +1234:
20682 + _ASM_EXTABLE(1234b, 2f)
20683 +#endif
20684 +
20685 cmpl %eax, %ecx
20686 je 3f
20687 1:
20688 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20689 1:
20690 addl $1, %eax
20691 adcl $0, %edx
20692 +
20693 +#ifdef CONFIG_PAX_REFCOUNT
20694 + into
20695 +1234:
20696 + _ASM_EXTABLE(1234b, 2f)
20697 +#endif
20698 +
20699 movl %eax, (v)
20700 movl %edx, 4(v)
20701 movl $1, %eax
20702 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20703 movl 4(v), %edx
20704 subl $1, %eax
20705 sbbl $0, %edx
20706 +
20707 +#ifdef CONFIG_PAX_REFCOUNT
20708 + into
20709 +1234:
20710 + _ASM_EXTABLE(1234b, 1f)
20711 +#endif
20712 +
20713 js 1f
20714 movl %eax, (v)
20715 movl %edx, 4(v)
20716 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20717 index f5cc9eb..51fa319 100644
20718 --- a/arch/x86/lib/atomic64_cx8_32.S
20719 +++ b/arch/x86/lib/atomic64_cx8_32.S
20720 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20721 CFI_STARTPROC
20722
20723 read64 %ecx
20724 + pax_force_retaddr
20725 ret
20726 CFI_ENDPROC
20727 ENDPROC(atomic64_read_cx8)
20728
20729 +ENTRY(atomic64_read_unchecked_cx8)
20730 + CFI_STARTPROC
20731 +
20732 + read64 %ecx
20733 + pax_force_retaddr
20734 + ret
20735 + CFI_ENDPROC
20736 +ENDPROC(atomic64_read_unchecked_cx8)
20737 +
20738 ENTRY(atomic64_set_cx8)
20739 CFI_STARTPROC
20740
20741 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20742 cmpxchg8b (%esi)
20743 jne 1b
20744
20745 + pax_force_retaddr
20746 ret
20747 CFI_ENDPROC
20748 ENDPROC(atomic64_set_cx8)
20749
20750 +ENTRY(atomic64_set_unchecked_cx8)
20751 + CFI_STARTPROC
20752 +
20753 +1:
20754 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20755 + * are atomic on 586 and newer */
20756 + cmpxchg8b (%esi)
20757 + jne 1b
20758 +
20759 + pax_force_retaddr
20760 + ret
20761 + CFI_ENDPROC
20762 +ENDPROC(atomic64_set_unchecked_cx8)
20763 +
20764 ENTRY(atomic64_xchg_cx8)
20765 CFI_STARTPROC
20766
20767 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20768 cmpxchg8b (%esi)
20769 jne 1b
20770
20771 + pax_force_retaddr
20772 ret
20773 CFI_ENDPROC
20774 ENDPROC(atomic64_xchg_cx8)
20775
20776 -.macro addsub_return func ins insc
20777 -ENTRY(atomic64_\func\()_return_cx8)
20778 +.macro addsub_return func ins insc unchecked=""
20779 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20780 CFI_STARTPROC
20781 SAVE ebp
20782 SAVE ebx
20783 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20784 movl %edx, %ecx
20785 \ins\()l %esi, %ebx
20786 \insc\()l %edi, %ecx
20787 +
20788 +.ifb \unchecked
20789 +#ifdef CONFIG_PAX_REFCOUNT
20790 + into
20791 +2:
20792 + _ASM_EXTABLE(2b, 3f)
20793 +#endif
20794 +.endif
20795 +
20796 LOCK_PREFIX
20797 cmpxchg8b (%ebp)
20798 jne 1b
20799 -
20800 -10:
20801 movl %ebx, %eax
20802 movl %ecx, %edx
20803 +
20804 +.ifb \unchecked
20805 +#ifdef CONFIG_PAX_REFCOUNT
20806 +3:
20807 +#endif
20808 +.endif
20809 +
20810 RESTORE edi
20811 RESTORE esi
20812 RESTORE ebx
20813 RESTORE ebp
20814 + pax_force_retaddr
20815 ret
20816 CFI_ENDPROC
20817 -ENDPROC(atomic64_\func\()_return_cx8)
20818 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20819 .endm
20820
20821 addsub_return add add adc
20822 addsub_return sub sub sbb
20823 +addsub_return add add adc _unchecked
20824 +addsub_return sub sub sbb _unchecked
20825
20826 -.macro incdec_return func ins insc
20827 -ENTRY(atomic64_\func\()_return_cx8)
20828 +.macro incdec_return func ins insc unchecked=""
20829 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20830 CFI_STARTPROC
20831 SAVE ebx
20832
20833 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20834 movl %edx, %ecx
20835 \ins\()l $1, %ebx
20836 \insc\()l $0, %ecx
20837 +
20838 +.ifb \unchecked
20839 +#ifdef CONFIG_PAX_REFCOUNT
20840 + into
20841 +2:
20842 + _ASM_EXTABLE(2b, 3f)
20843 +#endif
20844 +.endif
20845 +
20846 LOCK_PREFIX
20847 cmpxchg8b (%esi)
20848 jne 1b
20849
20850 -10:
20851 movl %ebx, %eax
20852 movl %ecx, %edx
20853 +
20854 +.ifb \unchecked
20855 +#ifdef CONFIG_PAX_REFCOUNT
20856 +3:
20857 +#endif
20858 +.endif
20859 +
20860 RESTORE ebx
20861 + pax_force_retaddr
20862 ret
20863 CFI_ENDPROC
20864 -ENDPROC(atomic64_\func\()_return_cx8)
20865 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20866 .endm
20867
20868 incdec_return inc add adc
20869 incdec_return dec sub sbb
20870 +incdec_return inc add adc _unchecked
20871 +incdec_return dec sub sbb _unchecked
20872
20873 ENTRY(atomic64_dec_if_positive_cx8)
20874 CFI_STARTPROC
20875 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20876 movl %edx, %ecx
20877 subl $1, %ebx
20878 sbb $0, %ecx
20879 +
20880 +#ifdef CONFIG_PAX_REFCOUNT
20881 + into
20882 +1234:
20883 + _ASM_EXTABLE(1234b, 2f)
20884 +#endif
20885 +
20886 js 2f
20887 LOCK_PREFIX
20888 cmpxchg8b (%esi)
20889 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20890 movl %ebx, %eax
20891 movl %ecx, %edx
20892 RESTORE ebx
20893 + pax_force_retaddr
20894 ret
20895 CFI_ENDPROC
20896 ENDPROC(atomic64_dec_if_positive_cx8)
20897 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20898 movl %edx, %ecx
20899 addl %ebp, %ebx
20900 adcl %edi, %ecx
20901 +
20902 +#ifdef CONFIG_PAX_REFCOUNT
20903 + into
20904 +1234:
20905 + _ASM_EXTABLE(1234b, 3f)
20906 +#endif
20907 +
20908 LOCK_PREFIX
20909 cmpxchg8b (%esi)
20910 jne 1b
20911 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20912 CFI_ADJUST_CFA_OFFSET -8
20913 RESTORE ebx
20914 RESTORE ebp
20915 + pax_force_retaddr
20916 ret
20917 4:
20918 cmpl %edx, 4(%esp)
20919 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20920 xorl %ecx, %ecx
20921 addl $1, %ebx
20922 adcl %edx, %ecx
20923 +
20924 +#ifdef CONFIG_PAX_REFCOUNT
20925 + into
20926 +1234:
20927 + _ASM_EXTABLE(1234b, 3f)
20928 +#endif
20929 +
20930 LOCK_PREFIX
20931 cmpxchg8b (%esi)
20932 jne 1b
20933 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20934 movl $1, %eax
20935 3:
20936 RESTORE ebx
20937 + pax_force_retaddr
20938 ret
20939 CFI_ENDPROC
20940 ENDPROC(atomic64_inc_not_zero_cx8)
20941 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20942 index 2af5df3..62b1a5a 100644
20943 --- a/arch/x86/lib/checksum_32.S
20944 +++ b/arch/x86/lib/checksum_32.S
20945 @@ -29,7 +29,8 @@
20946 #include <asm/dwarf2.h>
20947 #include <asm/errno.h>
20948 #include <asm/asm.h>
20949 -
20950 +#include <asm/segment.h>
20951 +
20952 /*
20953 * computes a partial checksum, e.g. for TCP/UDP fragments
20954 */
20955 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20956
20957 #define ARGBASE 16
20958 #define FP 12
20959 -
20960 -ENTRY(csum_partial_copy_generic)
20961 +
20962 +ENTRY(csum_partial_copy_generic_to_user)
20963 CFI_STARTPROC
20964 +
20965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20966 + pushl_cfi %gs
20967 + popl_cfi %es
20968 + jmp csum_partial_copy_generic
20969 +#endif
20970 +
20971 +ENTRY(csum_partial_copy_generic_from_user)
20972 +
20973 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20974 + pushl_cfi %gs
20975 + popl_cfi %ds
20976 +#endif
20977 +
20978 +ENTRY(csum_partial_copy_generic)
20979 subl $4,%esp
20980 CFI_ADJUST_CFA_OFFSET 4
20981 pushl_cfi %edi
20982 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
20983 jmp 4f
20984 SRC(1: movw (%esi), %bx )
20985 addl $2, %esi
20986 -DST( movw %bx, (%edi) )
20987 +DST( movw %bx, %es:(%edi) )
20988 addl $2, %edi
20989 addw %bx, %ax
20990 adcl $0, %eax
20991 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
20992 SRC(1: movl (%esi), %ebx )
20993 SRC( movl 4(%esi), %edx )
20994 adcl %ebx, %eax
20995 -DST( movl %ebx, (%edi) )
20996 +DST( movl %ebx, %es:(%edi) )
20997 adcl %edx, %eax
20998 -DST( movl %edx, 4(%edi) )
20999 +DST( movl %edx, %es:4(%edi) )
21000
21001 SRC( movl 8(%esi), %ebx )
21002 SRC( movl 12(%esi), %edx )
21003 adcl %ebx, %eax
21004 -DST( movl %ebx, 8(%edi) )
21005 +DST( movl %ebx, %es:8(%edi) )
21006 adcl %edx, %eax
21007 -DST( movl %edx, 12(%edi) )
21008 +DST( movl %edx, %es:12(%edi) )
21009
21010 SRC( movl 16(%esi), %ebx )
21011 SRC( movl 20(%esi), %edx )
21012 adcl %ebx, %eax
21013 -DST( movl %ebx, 16(%edi) )
21014 +DST( movl %ebx, %es:16(%edi) )
21015 adcl %edx, %eax
21016 -DST( movl %edx, 20(%edi) )
21017 +DST( movl %edx, %es:20(%edi) )
21018
21019 SRC( movl 24(%esi), %ebx )
21020 SRC( movl 28(%esi), %edx )
21021 adcl %ebx, %eax
21022 -DST( movl %ebx, 24(%edi) )
21023 +DST( movl %ebx, %es:24(%edi) )
21024 adcl %edx, %eax
21025 -DST( movl %edx, 28(%edi) )
21026 +DST( movl %edx, %es:28(%edi) )
21027
21028 lea 32(%esi), %esi
21029 lea 32(%edi), %edi
21030 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21031 shrl $2, %edx # This clears CF
21032 SRC(3: movl (%esi), %ebx )
21033 adcl %ebx, %eax
21034 -DST( movl %ebx, (%edi) )
21035 +DST( movl %ebx, %es:(%edi) )
21036 lea 4(%esi), %esi
21037 lea 4(%edi), %edi
21038 dec %edx
21039 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21040 jb 5f
21041 SRC( movw (%esi), %cx )
21042 leal 2(%esi), %esi
21043 -DST( movw %cx, (%edi) )
21044 +DST( movw %cx, %es:(%edi) )
21045 leal 2(%edi), %edi
21046 je 6f
21047 shll $16,%ecx
21048 SRC(5: movb (%esi), %cl )
21049 -DST( movb %cl, (%edi) )
21050 +DST( movb %cl, %es:(%edi) )
21051 6: addl %ecx, %eax
21052 adcl $0, %eax
21053 7:
21054 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21055
21056 6001:
21057 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21058 - movl $-EFAULT, (%ebx)
21059 + movl $-EFAULT, %ss:(%ebx)
21060
21061 # zero the complete destination - computing the rest
21062 # is too much work
21063 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21064
21065 6002:
21066 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21067 - movl $-EFAULT,(%ebx)
21068 + movl $-EFAULT,%ss:(%ebx)
21069 jmp 5000b
21070
21071 .previous
21072
21073 + pushl_cfi %ss
21074 + popl_cfi %ds
21075 + pushl_cfi %ss
21076 + popl_cfi %es
21077 popl_cfi %ebx
21078 CFI_RESTORE ebx
21079 popl_cfi %esi
21080 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21081 popl_cfi %ecx # equivalent to addl $4,%esp
21082 ret
21083 CFI_ENDPROC
21084 -ENDPROC(csum_partial_copy_generic)
21085 +ENDPROC(csum_partial_copy_generic_to_user)
21086
21087 #else
21088
21089 /* Version for PentiumII/PPro */
21090
21091 #define ROUND1(x) \
21092 + nop; nop; nop; \
21093 SRC(movl x(%esi), %ebx ) ; \
21094 addl %ebx, %eax ; \
21095 - DST(movl %ebx, x(%edi) ) ;
21096 + DST(movl %ebx, %es:x(%edi)) ;
21097
21098 #define ROUND(x) \
21099 + nop; nop; nop; \
21100 SRC(movl x(%esi), %ebx ) ; \
21101 adcl %ebx, %eax ; \
21102 - DST(movl %ebx, x(%edi) ) ;
21103 + DST(movl %ebx, %es:x(%edi)) ;
21104
21105 #define ARGBASE 12
21106 -
21107 -ENTRY(csum_partial_copy_generic)
21108 +
21109 +ENTRY(csum_partial_copy_generic_to_user)
21110 CFI_STARTPROC
21111 +
21112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21113 + pushl_cfi %gs
21114 + popl_cfi %es
21115 + jmp csum_partial_copy_generic
21116 +#endif
21117 +
21118 +ENTRY(csum_partial_copy_generic_from_user)
21119 +
21120 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21121 + pushl_cfi %gs
21122 + popl_cfi %ds
21123 +#endif
21124 +
21125 +ENTRY(csum_partial_copy_generic)
21126 pushl_cfi %ebx
21127 CFI_REL_OFFSET ebx, 0
21128 pushl_cfi %edi
21129 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21130 subl %ebx, %edi
21131 lea -1(%esi),%edx
21132 andl $-32,%edx
21133 - lea 3f(%ebx,%ebx), %ebx
21134 + lea 3f(%ebx,%ebx,2), %ebx
21135 testl %esi, %esi
21136 jmp *%ebx
21137 1: addl $64,%esi
21138 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21139 jb 5f
21140 SRC( movw (%esi), %dx )
21141 leal 2(%esi), %esi
21142 -DST( movw %dx, (%edi) )
21143 +DST( movw %dx, %es:(%edi) )
21144 leal 2(%edi), %edi
21145 je 6f
21146 shll $16,%edx
21147 5:
21148 SRC( movb (%esi), %dl )
21149 -DST( movb %dl, (%edi) )
21150 +DST( movb %dl, %es:(%edi) )
21151 6: addl %edx, %eax
21152 adcl $0, %eax
21153 7:
21154 .section .fixup, "ax"
21155 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21156 - movl $-EFAULT, (%ebx)
21157 + movl $-EFAULT, %ss:(%ebx)
21158 # zero the complete destination (computing the rest is too much work)
21159 movl ARGBASE+8(%esp),%edi # dst
21160 movl ARGBASE+12(%esp),%ecx # len
21161 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21162 rep; stosb
21163 jmp 7b
21164 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21165 - movl $-EFAULT, (%ebx)
21166 + movl $-EFAULT, %ss:(%ebx)
21167 jmp 7b
21168 .previous
21169
21170 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21171 + pushl_cfi %ss
21172 + popl_cfi %ds
21173 + pushl_cfi %ss
21174 + popl_cfi %es
21175 +#endif
21176 +
21177 popl_cfi %esi
21178 CFI_RESTORE esi
21179 popl_cfi %edi
21180 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21181 CFI_RESTORE ebx
21182 ret
21183 CFI_ENDPROC
21184 -ENDPROC(csum_partial_copy_generic)
21185 +ENDPROC(csum_partial_copy_generic_to_user)
21186
21187 #undef ROUND
21188 #undef ROUND1
21189 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21190 index f2145cf..cea889d 100644
21191 --- a/arch/x86/lib/clear_page_64.S
21192 +++ b/arch/x86/lib/clear_page_64.S
21193 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21194 movl $4096/8,%ecx
21195 xorl %eax,%eax
21196 rep stosq
21197 + pax_force_retaddr
21198 ret
21199 CFI_ENDPROC
21200 ENDPROC(clear_page_c)
21201 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21202 movl $4096,%ecx
21203 xorl %eax,%eax
21204 rep stosb
21205 + pax_force_retaddr
21206 ret
21207 CFI_ENDPROC
21208 ENDPROC(clear_page_c_e)
21209 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21210 leaq 64(%rdi),%rdi
21211 jnz .Lloop
21212 nop
21213 + pax_force_retaddr
21214 ret
21215 CFI_ENDPROC
21216 .Lclear_page_end:
21217 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21218
21219 #include <asm/cpufeature.h>
21220
21221 - .section .altinstr_replacement,"ax"
21222 + .section .altinstr_replacement,"a"
21223 1: .byte 0xeb /* jmp <disp8> */
21224 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21225 2: .byte 0xeb /* jmp <disp8> */
21226 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21227 index 1e572c5..2a162cd 100644
21228 --- a/arch/x86/lib/cmpxchg16b_emu.S
21229 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21230 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21231
21232 popf
21233 mov $1, %al
21234 + pax_force_retaddr
21235 ret
21236
21237 not_same:
21238 popf
21239 xor %al,%al
21240 + pax_force_retaddr
21241 ret
21242
21243 CFI_ENDPROC
21244 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21245 index 6b34d04..dccb07f 100644
21246 --- a/arch/x86/lib/copy_page_64.S
21247 +++ b/arch/x86/lib/copy_page_64.S
21248 @@ -9,6 +9,7 @@ copy_page_c:
21249 CFI_STARTPROC
21250 movl $4096/8,%ecx
21251 rep movsq
21252 + pax_force_retaddr
21253 ret
21254 CFI_ENDPROC
21255 ENDPROC(copy_page_c)
21256 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21257
21258 ENTRY(copy_page)
21259 CFI_STARTPROC
21260 - subq $2*8,%rsp
21261 - CFI_ADJUST_CFA_OFFSET 2*8
21262 + subq $3*8,%rsp
21263 + CFI_ADJUST_CFA_OFFSET 3*8
21264 movq %rbx,(%rsp)
21265 CFI_REL_OFFSET rbx, 0
21266 movq %r12,1*8(%rsp)
21267 CFI_REL_OFFSET r12, 1*8
21268 + movq %r13,2*8(%rsp)
21269 + CFI_REL_OFFSET r13, 2*8
21270
21271 movl $(4096/64)-5,%ecx
21272 .p2align 4
21273 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21274 movq 16 (%rsi), %rdx
21275 movq 24 (%rsi), %r8
21276 movq 32 (%rsi), %r9
21277 - movq 40 (%rsi), %r10
21278 + movq 40 (%rsi), %r13
21279 movq 48 (%rsi), %r11
21280 movq 56 (%rsi), %r12
21281
21282 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21283 movq %rdx, 16 (%rdi)
21284 movq %r8, 24 (%rdi)
21285 movq %r9, 32 (%rdi)
21286 - movq %r10, 40 (%rdi)
21287 + movq %r13, 40 (%rdi)
21288 movq %r11, 48 (%rdi)
21289 movq %r12, 56 (%rdi)
21290
21291 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21292 movq 16 (%rsi), %rdx
21293 movq 24 (%rsi), %r8
21294 movq 32 (%rsi), %r9
21295 - movq 40 (%rsi), %r10
21296 + movq 40 (%rsi), %r13
21297 movq 48 (%rsi), %r11
21298 movq 56 (%rsi), %r12
21299
21300 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21301 movq %rdx, 16 (%rdi)
21302 movq %r8, 24 (%rdi)
21303 movq %r9, 32 (%rdi)
21304 - movq %r10, 40 (%rdi)
21305 + movq %r13, 40 (%rdi)
21306 movq %r11, 48 (%rdi)
21307 movq %r12, 56 (%rdi)
21308
21309 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21310 CFI_RESTORE rbx
21311 movq 1*8(%rsp),%r12
21312 CFI_RESTORE r12
21313 - addq $2*8,%rsp
21314 - CFI_ADJUST_CFA_OFFSET -2*8
21315 + movq 2*8(%rsp),%r13
21316 + CFI_RESTORE r13
21317 + addq $3*8,%rsp
21318 + CFI_ADJUST_CFA_OFFSET -3*8
21319 + pax_force_retaddr
21320 ret
21321 .Lcopy_page_end:
21322 CFI_ENDPROC
21323 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21324
21325 #include <asm/cpufeature.h>
21326
21327 - .section .altinstr_replacement,"ax"
21328 + .section .altinstr_replacement,"a"
21329 1: .byte 0xeb /* jmp <disp8> */
21330 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21331 2:
21332 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21333 index 5b2995f..78e7644 100644
21334 --- a/arch/x86/lib/copy_user_64.S
21335 +++ b/arch/x86/lib/copy_user_64.S
21336 @@ -17,6 +17,7 @@
21337 #include <asm/cpufeature.h>
21338 #include <asm/alternative-asm.h>
21339 #include <asm/asm.h>
21340 +#include <asm/pgtable.h>
21341
21342 /*
21343 * By placing feature2 after feature1 in altinstructions section, we logically
21344 @@ -30,7 +31,7 @@
21345 .byte 0xe9 /* 32bit jump */
21346 .long \orig-1f /* by default jump to orig */
21347 1:
21348 - .section .altinstr_replacement,"ax"
21349 + .section .altinstr_replacement,"a"
21350 2: .byte 0xe9 /* near jump with 32bit immediate */
21351 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21352 3: .byte 0xe9 /* near jump with 32bit immediate */
21353 @@ -69,47 +70,20 @@
21354 #endif
21355 .endm
21356
21357 -/* Standard copy_to_user with segment limit checking */
21358 -ENTRY(_copy_to_user)
21359 - CFI_STARTPROC
21360 - GET_THREAD_INFO(%rax)
21361 - movq %rdi,%rcx
21362 - addq %rdx,%rcx
21363 - jc bad_to_user
21364 - cmpq TI_addr_limit(%rax),%rcx
21365 - ja bad_to_user
21366 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21367 - copy_user_generic_unrolled,copy_user_generic_string, \
21368 - copy_user_enhanced_fast_string
21369 - CFI_ENDPROC
21370 -ENDPROC(_copy_to_user)
21371 -
21372 -/* Standard copy_from_user with segment limit checking */
21373 -ENTRY(_copy_from_user)
21374 - CFI_STARTPROC
21375 - GET_THREAD_INFO(%rax)
21376 - movq %rsi,%rcx
21377 - addq %rdx,%rcx
21378 - jc bad_from_user
21379 - cmpq TI_addr_limit(%rax),%rcx
21380 - ja bad_from_user
21381 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21382 - copy_user_generic_unrolled,copy_user_generic_string, \
21383 - copy_user_enhanced_fast_string
21384 - CFI_ENDPROC
21385 -ENDPROC(_copy_from_user)
21386 -
21387 .section .fixup,"ax"
21388 /* must zero dest */
21389 ENTRY(bad_from_user)
21390 bad_from_user:
21391 CFI_STARTPROC
21392 + testl %edx,%edx
21393 + js bad_to_user
21394 movl %edx,%ecx
21395 xorl %eax,%eax
21396 rep
21397 stosb
21398 bad_to_user:
21399 movl %edx,%eax
21400 + pax_force_retaddr
21401 ret
21402 CFI_ENDPROC
21403 ENDPROC(bad_from_user)
21404 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21405 jz 17f
21406 1: movq (%rsi),%r8
21407 2: movq 1*8(%rsi),%r9
21408 -3: movq 2*8(%rsi),%r10
21409 +3: movq 2*8(%rsi),%rax
21410 4: movq 3*8(%rsi),%r11
21411 5: movq %r8,(%rdi)
21412 6: movq %r9,1*8(%rdi)
21413 -7: movq %r10,2*8(%rdi)
21414 +7: movq %rax,2*8(%rdi)
21415 8: movq %r11,3*8(%rdi)
21416 9: movq 4*8(%rsi),%r8
21417 10: movq 5*8(%rsi),%r9
21418 -11: movq 6*8(%rsi),%r10
21419 +11: movq 6*8(%rsi),%rax
21420 12: movq 7*8(%rsi),%r11
21421 13: movq %r8,4*8(%rdi)
21422 14: movq %r9,5*8(%rdi)
21423 -15: movq %r10,6*8(%rdi)
21424 +15: movq %rax,6*8(%rdi)
21425 16: movq %r11,7*8(%rdi)
21426 leaq 64(%rsi),%rsi
21427 leaq 64(%rdi),%rdi
21428 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21429 decl %ecx
21430 jnz 21b
21431 23: xor %eax,%eax
21432 + pax_force_retaddr
21433 ret
21434
21435 .section .fixup,"ax"
21436 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21437 3: rep
21438 movsb
21439 4: xorl %eax,%eax
21440 + pax_force_retaddr
21441 ret
21442
21443 .section .fixup,"ax"
21444 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21445 1: rep
21446 movsb
21447 2: xorl %eax,%eax
21448 + pax_force_retaddr
21449 ret
21450
21451 .section .fixup,"ax"
21452 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21453 index cacddc7..09d49e4 100644
21454 --- a/arch/x86/lib/copy_user_nocache_64.S
21455 +++ b/arch/x86/lib/copy_user_nocache_64.S
21456 @@ -8,6 +8,7 @@
21457
21458 #include <linux/linkage.h>
21459 #include <asm/dwarf2.h>
21460 +#include <asm/alternative-asm.h>
21461
21462 #define FIX_ALIGNMENT 1
21463
21464 @@ -15,6 +16,7 @@
21465 #include <asm/asm-offsets.h>
21466 #include <asm/thread_info.h>
21467 #include <asm/asm.h>
21468 +#include <asm/pgtable.h>
21469
21470 .macro ALIGN_DESTINATION
21471 #ifdef FIX_ALIGNMENT
21472 @@ -48,6 +50,15 @@
21473 */
21474 ENTRY(__copy_user_nocache)
21475 CFI_STARTPROC
21476 +
21477 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21478 + mov $PAX_USER_SHADOW_BASE,%rcx
21479 + cmp %rcx,%rsi
21480 + jae 1f
21481 + add %rcx,%rsi
21482 +1:
21483 +#endif
21484 +
21485 cmpl $8,%edx
21486 jb 20f /* less then 8 bytes, go to byte copy loop */
21487 ALIGN_DESTINATION
21488 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21489 jz 17f
21490 1: movq (%rsi),%r8
21491 2: movq 1*8(%rsi),%r9
21492 -3: movq 2*8(%rsi),%r10
21493 +3: movq 2*8(%rsi),%rax
21494 4: movq 3*8(%rsi),%r11
21495 5: movnti %r8,(%rdi)
21496 6: movnti %r9,1*8(%rdi)
21497 -7: movnti %r10,2*8(%rdi)
21498 +7: movnti %rax,2*8(%rdi)
21499 8: movnti %r11,3*8(%rdi)
21500 9: movq 4*8(%rsi),%r8
21501 10: movq 5*8(%rsi),%r9
21502 -11: movq 6*8(%rsi),%r10
21503 +11: movq 6*8(%rsi),%rax
21504 12: movq 7*8(%rsi),%r11
21505 13: movnti %r8,4*8(%rdi)
21506 14: movnti %r9,5*8(%rdi)
21507 -15: movnti %r10,6*8(%rdi)
21508 +15: movnti %rax,6*8(%rdi)
21509 16: movnti %r11,7*8(%rdi)
21510 leaq 64(%rsi),%rsi
21511 leaq 64(%rdi),%rdi
21512 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21513 jnz 21b
21514 23: xorl %eax,%eax
21515 sfence
21516 + pax_force_retaddr
21517 ret
21518
21519 .section .fixup,"ax"
21520 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21521 index 2419d5f..953ee51 100644
21522 --- a/arch/x86/lib/csum-copy_64.S
21523 +++ b/arch/x86/lib/csum-copy_64.S
21524 @@ -9,6 +9,7 @@
21525 #include <asm/dwarf2.h>
21526 #include <asm/errno.h>
21527 #include <asm/asm.h>
21528 +#include <asm/alternative-asm.h>
21529
21530 /*
21531 * Checksum copy with exception handling.
21532 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21533 CFI_RESTORE rbp
21534 addq $7*8, %rsp
21535 CFI_ADJUST_CFA_OFFSET -7*8
21536 + pax_force_retaddr 0, 1
21537 ret
21538 CFI_RESTORE_STATE
21539
21540 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21541 index 25b7ae8..3b52ccd 100644
21542 --- a/arch/x86/lib/csum-wrappers_64.c
21543 +++ b/arch/x86/lib/csum-wrappers_64.c
21544 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21545 len -= 2;
21546 }
21547 }
21548 - isum = csum_partial_copy_generic((__force const void *)src,
21549 +
21550 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21551 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21552 + src += PAX_USER_SHADOW_BASE;
21553 +#endif
21554 +
21555 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21556 dst, len, isum, errp, NULL);
21557 if (unlikely(*errp))
21558 goto out_err;
21559 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21560 }
21561
21562 *errp = 0;
21563 - return csum_partial_copy_generic(src, (void __force *)dst,
21564 +
21565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21566 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21567 + dst += PAX_USER_SHADOW_BASE;
21568 +#endif
21569 +
21570 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21571 len, isum, NULL, errp);
21572 }
21573 EXPORT_SYMBOL(csum_partial_copy_to_user);
21574 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21575 index b33b1fb..219f389 100644
21576 --- a/arch/x86/lib/getuser.S
21577 +++ b/arch/x86/lib/getuser.S
21578 @@ -33,15 +33,38 @@
21579 #include <asm/asm-offsets.h>
21580 #include <asm/thread_info.h>
21581 #include <asm/asm.h>
21582 +#include <asm/segment.h>
21583 +#include <asm/pgtable.h>
21584 +#include <asm/alternative-asm.h>
21585 +
21586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21587 +#define __copyuser_seg gs;
21588 +#else
21589 +#define __copyuser_seg
21590 +#endif
21591
21592 .text
21593 ENTRY(__get_user_1)
21594 CFI_STARTPROC
21595 +
21596 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21597 GET_THREAD_INFO(%_ASM_DX)
21598 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21599 jae bad_get_user
21600 -1: movzb (%_ASM_AX),%edx
21601 +
21602 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21603 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21604 + cmp %_ASM_DX,%_ASM_AX
21605 + jae 1234f
21606 + add %_ASM_DX,%_ASM_AX
21607 +1234:
21608 +#endif
21609 +
21610 +#endif
21611 +
21612 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21613 xor %eax,%eax
21614 + pax_force_retaddr
21615 ret
21616 CFI_ENDPROC
21617 ENDPROC(__get_user_1)
21618 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21619 ENTRY(__get_user_2)
21620 CFI_STARTPROC
21621 add $1,%_ASM_AX
21622 +
21623 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21624 jc bad_get_user
21625 GET_THREAD_INFO(%_ASM_DX)
21626 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21627 jae bad_get_user
21628 -2: movzwl -1(%_ASM_AX),%edx
21629 +
21630 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21631 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21632 + cmp %_ASM_DX,%_ASM_AX
21633 + jae 1234f
21634 + add %_ASM_DX,%_ASM_AX
21635 +1234:
21636 +#endif
21637 +
21638 +#endif
21639 +
21640 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21641 xor %eax,%eax
21642 + pax_force_retaddr
21643 ret
21644 CFI_ENDPROC
21645 ENDPROC(__get_user_2)
21646 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21647 ENTRY(__get_user_4)
21648 CFI_STARTPROC
21649 add $3,%_ASM_AX
21650 +
21651 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21652 jc bad_get_user
21653 GET_THREAD_INFO(%_ASM_DX)
21654 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21655 jae bad_get_user
21656 -3: mov -3(%_ASM_AX),%edx
21657 +
21658 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21659 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21660 + cmp %_ASM_DX,%_ASM_AX
21661 + jae 1234f
21662 + add %_ASM_DX,%_ASM_AX
21663 +1234:
21664 +#endif
21665 +
21666 +#endif
21667 +
21668 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21669 xor %eax,%eax
21670 + pax_force_retaddr
21671 ret
21672 CFI_ENDPROC
21673 ENDPROC(__get_user_4)
21674 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21675 GET_THREAD_INFO(%_ASM_DX)
21676 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21677 jae bad_get_user
21678 +
21679 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21680 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21681 + cmp %_ASM_DX,%_ASM_AX
21682 + jae 1234f
21683 + add %_ASM_DX,%_ASM_AX
21684 +1234:
21685 +#endif
21686 +
21687 4: movq -7(%_ASM_AX),%_ASM_DX
21688 xor %eax,%eax
21689 + pax_force_retaddr
21690 ret
21691 CFI_ENDPROC
21692 ENDPROC(__get_user_8)
21693 @@ -91,6 +152,7 @@ bad_get_user:
21694 CFI_STARTPROC
21695 xor %edx,%edx
21696 mov $(-EFAULT),%_ASM_AX
21697 + pax_force_retaddr
21698 ret
21699 CFI_ENDPROC
21700 END(bad_get_user)
21701 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21702 index b1e6c4b..21ae8fc 100644
21703 --- a/arch/x86/lib/insn.c
21704 +++ b/arch/x86/lib/insn.c
21705 @@ -21,6 +21,11 @@
21706 #include <linux/string.h>
21707 #include <asm/inat.h>
21708 #include <asm/insn.h>
21709 +#ifdef __KERNEL__
21710 +#include <asm/pgtable_types.h>
21711 +#else
21712 +#define ktla_ktva(addr) addr
21713 +#endif
21714
21715 /* Verify next sizeof(t) bytes can be on the same instruction */
21716 #define validate_next(t, insn, n) \
21717 @@ -49,8 +54,8 @@
21718 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21719 {
21720 memset(insn, 0, sizeof(*insn));
21721 - insn->kaddr = kaddr;
21722 - insn->next_byte = kaddr;
21723 + insn->kaddr = ktla_ktva(kaddr);
21724 + insn->next_byte = ktla_ktva(kaddr);
21725 insn->x86_64 = x86_64 ? 1 : 0;
21726 insn->opnd_bytes = 4;
21727 if (x86_64)
21728 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21729 index 05a95e7..326f2fa 100644
21730 --- a/arch/x86/lib/iomap_copy_64.S
21731 +++ b/arch/x86/lib/iomap_copy_64.S
21732 @@ -17,6 +17,7 @@
21733
21734 #include <linux/linkage.h>
21735 #include <asm/dwarf2.h>
21736 +#include <asm/alternative-asm.h>
21737
21738 /*
21739 * override generic version in lib/iomap_copy.c
21740 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21741 CFI_STARTPROC
21742 movl %edx,%ecx
21743 rep movsd
21744 + pax_force_retaddr
21745 ret
21746 CFI_ENDPROC
21747 ENDPROC(__iowrite32_copy)
21748 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21749 index 1c273be..da9cc0e 100644
21750 --- a/arch/x86/lib/memcpy_64.S
21751 +++ b/arch/x86/lib/memcpy_64.S
21752 @@ -33,6 +33,7 @@
21753 rep movsq
21754 movl %edx, %ecx
21755 rep movsb
21756 + pax_force_retaddr
21757 ret
21758 .Lmemcpy_e:
21759 .previous
21760 @@ -49,6 +50,7 @@
21761 movq %rdi, %rax
21762 movq %rdx, %rcx
21763 rep movsb
21764 + pax_force_retaddr
21765 ret
21766 .Lmemcpy_e_e:
21767 .previous
21768 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21769 */
21770 movq 0*8(%rsi), %r8
21771 movq 1*8(%rsi), %r9
21772 - movq 2*8(%rsi), %r10
21773 + movq 2*8(%rsi), %rcx
21774 movq 3*8(%rsi), %r11
21775 leaq 4*8(%rsi), %rsi
21776
21777 movq %r8, 0*8(%rdi)
21778 movq %r9, 1*8(%rdi)
21779 - movq %r10, 2*8(%rdi)
21780 + movq %rcx, 2*8(%rdi)
21781 movq %r11, 3*8(%rdi)
21782 leaq 4*8(%rdi), %rdi
21783 jae .Lcopy_forward_loop
21784 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21785 subq $0x20, %rdx
21786 movq -1*8(%rsi), %r8
21787 movq -2*8(%rsi), %r9
21788 - movq -3*8(%rsi), %r10
21789 + movq -3*8(%rsi), %rcx
21790 movq -4*8(%rsi), %r11
21791 leaq -4*8(%rsi), %rsi
21792 movq %r8, -1*8(%rdi)
21793 movq %r9, -2*8(%rdi)
21794 - movq %r10, -3*8(%rdi)
21795 + movq %rcx, -3*8(%rdi)
21796 movq %r11, -4*8(%rdi)
21797 leaq -4*8(%rdi), %rdi
21798 jae .Lcopy_backward_loop
21799 @@ -130,12 +132,13 @@ ENTRY(memcpy)
21800 */
21801 movq 0*8(%rsi), %r8
21802 movq 1*8(%rsi), %r9
21803 - movq -2*8(%rsi, %rdx), %r10
21804 + movq -2*8(%rsi, %rdx), %rcx
21805 movq -1*8(%rsi, %rdx), %r11
21806 movq %r8, 0*8(%rdi)
21807 movq %r9, 1*8(%rdi)
21808 - movq %r10, -2*8(%rdi, %rdx)
21809 + movq %rcx, -2*8(%rdi, %rdx)
21810 movq %r11, -1*8(%rdi, %rdx)
21811 + pax_force_retaddr
21812 retq
21813 .p2align 4
21814 .Lless_16bytes:
21815 @@ -148,6 +151,7 @@ ENTRY(memcpy)
21816 movq -1*8(%rsi, %rdx), %r9
21817 movq %r8, 0*8(%rdi)
21818 movq %r9, -1*8(%rdi, %rdx)
21819 + pax_force_retaddr
21820 retq
21821 .p2align 4
21822 .Lless_8bytes:
21823 @@ -161,6 +165,7 @@ ENTRY(memcpy)
21824 movl -4(%rsi, %rdx), %r8d
21825 movl %ecx, (%rdi)
21826 movl %r8d, -4(%rdi, %rdx)
21827 + pax_force_retaddr
21828 retq
21829 .p2align 4
21830 .Lless_3bytes:
21831 @@ -179,6 +184,7 @@ ENTRY(memcpy)
21832 movb %cl, (%rdi)
21833
21834 .Lend:
21835 + pax_force_retaddr
21836 retq
21837 CFI_ENDPROC
21838 ENDPROC(memcpy)
21839 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21840 index ee16461..c39c199 100644
21841 --- a/arch/x86/lib/memmove_64.S
21842 +++ b/arch/x86/lib/memmove_64.S
21843 @@ -61,13 +61,13 @@ ENTRY(memmove)
21844 5:
21845 sub $0x20, %rdx
21846 movq 0*8(%rsi), %r11
21847 - movq 1*8(%rsi), %r10
21848 + movq 1*8(%rsi), %rcx
21849 movq 2*8(%rsi), %r9
21850 movq 3*8(%rsi), %r8
21851 leaq 4*8(%rsi), %rsi
21852
21853 movq %r11, 0*8(%rdi)
21854 - movq %r10, 1*8(%rdi)
21855 + movq %rcx, 1*8(%rdi)
21856 movq %r9, 2*8(%rdi)
21857 movq %r8, 3*8(%rdi)
21858 leaq 4*8(%rdi), %rdi
21859 @@ -81,10 +81,10 @@ ENTRY(memmove)
21860 4:
21861 movq %rdx, %rcx
21862 movq -8(%rsi, %rdx), %r11
21863 - lea -8(%rdi, %rdx), %r10
21864 + lea -8(%rdi, %rdx), %r9
21865 shrq $3, %rcx
21866 rep movsq
21867 - movq %r11, (%r10)
21868 + movq %r11, (%r9)
21869 jmp 13f
21870 .Lmemmove_end_forward:
21871
21872 @@ -95,14 +95,14 @@ ENTRY(memmove)
21873 7:
21874 movq %rdx, %rcx
21875 movq (%rsi), %r11
21876 - movq %rdi, %r10
21877 + movq %rdi, %r9
21878 leaq -8(%rsi, %rdx), %rsi
21879 leaq -8(%rdi, %rdx), %rdi
21880 shrq $3, %rcx
21881 std
21882 rep movsq
21883 cld
21884 - movq %r11, (%r10)
21885 + movq %r11, (%r9)
21886 jmp 13f
21887
21888 /*
21889 @@ -127,13 +127,13 @@ ENTRY(memmove)
21890 8:
21891 subq $0x20, %rdx
21892 movq -1*8(%rsi), %r11
21893 - movq -2*8(%rsi), %r10
21894 + movq -2*8(%rsi), %rcx
21895 movq -3*8(%rsi), %r9
21896 movq -4*8(%rsi), %r8
21897 leaq -4*8(%rsi), %rsi
21898
21899 movq %r11, -1*8(%rdi)
21900 - movq %r10, -2*8(%rdi)
21901 + movq %rcx, -2*8(%rdi)
21902 movq %r9, -3*8(%rdi)
21903 movq %r8, -4*8(%rdi)
21904 leaq -4*8(%rdi), %rdi
21905 @@ -151,11 +151,11 @@ ENTRY(memmove)
21906 * Move data from 16 bytes to 31 bytes.
21907 */
21908 movq 0*8(%rsi), %r11
21909 - movq 1*8(%rsi), %r10
21910 + movq 1*8(%rsi), %rcx
21911 movq -2*8(%rsi, %rdx), %r9
21912 movq -1*8(%rsi, %rdx), %r8
21913 movq %r11, 0*8(%rdi)
21914 - movq %r10, 1*8(%rdi)
21915 + movq %rcx, 1*8(%rdi)
21916 movq %r9, -2*8(%rdi, %rdx)
21917 movq %r8, -1*8(%rdi, %rdx)
21918 jmp 13f
21919 @@ -167,9 +167,9 @@ ENTRY(memmove)
21920 * Move data from 8 bytes to 15 bytes.
21921 */
21922 movq 0*8(%rsi), %r11
21923 - movq -1*8(%rsi, %rdx), %r10
21924 + movq -1*8(%rsi, %rdx), %r9
21925 movq %r11, 0*8(%rdi)
21926 - movq %r10, -1*8(%rdi, %rdx)
21927 + movq %r9, -1*8(%rdi, %rdx)
21928 jmp 13f
21929 10:
21930 cmpq $4, %rdx
21931 @@ -178,9 +178,9 @@ ENTRY(memmove)
21932 * Move data from 4 bytes to 7 bytes.
21933 */
21934 movl (%rsi), %r11d
21935 - movl -4(%rsi, %rdx), %r10d
21936 + movl -4(%rsi, %rdx), %r9d
21937 movl %r11d, (%rdi)
21938 - movl %r10d, -4(%rdi, %rdx)
21939 + movl %r9d, -4(%rdi, %rdx)
21940 jmp 13f
21941 11:
21942 cmp $2, %rdx
21943 @@ -189,9 +189,9 @@ ENTRY(memmove)
21944 * Move data from 2 bytes to 3 bytes.
21945 */
21946 movw (%rsi), %r11w
21947 - movw -2(%rsi, %rdx), %r10w
21948 + movw -2(%rsi, %rdx), %r9w
21949 movw %r11w, (%rdi)
21950 - movw %r10w, -2(%rdi, %rdx)
21951 + movw %r9w, -2(%rdi, %rdx)
21952 jmp 13f
21953 12:
21954 cmp $1, %rdx
21955 @@ -202,6 +202,7 @@ ENTRY(memmove)
21956 movb (%rsi), %r11b
21957 movb %r11b, (%rdi)
21958 13:
21959 + pax_force_retaddr
21960 retq
21961 CFI_ENDPROC
21962
21963 @@ -210,6 +211,7 @@ ENTRY(memmove)
21964 /* Forward moving data. */
21965 movq %rdx, %rcx
21966 rep movsb
21967 + pax_force_retaddr
21968 retq
21969 .Lmemmove_end_forward_efs:
21970 .previous
21971 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21972 index 2dcb380..963660a 100644
21973 --- a/arch/x86/lib/memset_64.S
21974 +++ b/arch/x86/lib/memset_64.S
21975 @@ -30,6 +30,7 @@
21976 movl %edx,%ecx
21977 rep stosb
21978 movq %r9,%rax
21979 + pax_force_retaddr
21980 ret
21981 .Lmemset_e:
21982 .previous
21983 @@ -52,6 +53,7 @@
21984 movq %rdx,%rcx
21985 rep stosb
21986 movq %r9,%rax
21987 + pax_force_retaddr
21988 ret
21989 .Lmemset_e_e:
21990 .previous
21991 @@ -59,7 +61,7 @@
21992 ENTRY(memset)
21993 ENTRY(__memset)
21994 CFI_STARTPROC
21995 - movq %rdi,%r10
21996 + movq %rdi,%r11
21997
21998 /* expand byte value */
21999 movzbl %sil,%ecx
22000 @@ -117,7 +119,8 @@ ENTRY(__memset)
22001 jnz .Lloop_1
22002
22003 .Lende:
22004 - movq %r10,%rax
22005 + movq %r11,%rax
22006 + pax_force_retaddr
22007 ret
22008
22009 CFI_RESTORE_STATE
22010 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22011 index c9f2d9b..e7fd2c0 100644
22012 --- a/arch/x86/lib/mmx_32.c
22013 +++ b/arch/x86/lib/mmx_32.c
22014 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22015 {
22016 void *p;
22017 int i;
22018 + unsigned long cr0;
22019
22020 if (unlikely(in_interrupt()))
22021 return __memcpy(to, from, len);
22022 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22023 kernel_fpu_begin();
22024
22025 __asm__ __volatile__ (
22026 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22027 - " prefetch 64(%0)\n"
22028 - " prefetch 128(%0)\n"
22029 - " prefetch 192(%0)\n"
22030 - " prefetch 256(%0)\n"
22031 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22032 + " prefetch 64(%1)\n"
22033 + " prefetch 128(%1)\n"
22034 + " prefetch 192(%1)\n"
22035 + " prefetch 256(%1)\n"
22036 "2: \n"
22037 ".section .fixup, \"ax\"\n"
22038 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22039 + "3: \n"
22040 +
22041 +#ifdef CONFIG_PAX_KERNEXEC
22042 + " movl %%cr0, %0\n"
22043 + " movl %0, %%eax\n"
22044 + " andl $0xFFFEFFFF, %%eax\n"
22045 + " movl %%eax, %%cr0\n"
22046 +#endif
22047 +
22048 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22049 +
22050 +#ifdef CONFIG_PAX_KERNEXEC
22051 + " movl %0, %%cr0\n"
22052 +#endif
22053 +
22054 " jmp 2b\n"
22055 ".previous\n"
22056 _ASM_EXTABLE(1b, 3b)
22057 - : : "r" (from));
22058 + : "=&r" (cr0) : "r" (from) : "ax");
22059
22060 for ( ; i > 5; i--) {
22061 __asm__ __volatile__ (
22062 - "1: prefetch 320(%0)\n"
22063 - "2: movq (%0), %%mm0\n"
22064 - " movq 8(%0), %%mm1\n"
22065 - " movq 16(%0), %%mm2\n"
22066 - " movq 24(%0), %%mm3\n"
22067 - " movq %%mm0, (%1)\n"
22068 - " movq %%mm1, 8(%1)\n"
22069 - " movq %%mm2, 16(%1)\n"
22070 - " movq %%mm3, 24(%1)\n"
22071 - " movq 32(%0), %%mm0\n"
22072 - " movq 40(%0), %%mm1\n"
22073 - " movq 48(%0), %%mm2\n"
22074 - " movq 56(%0), %%mm3\n"
22075 - " movq %%mm0, 32(%1)\n"
22076 - " movq %%mm1, 40(%1)\n"
22077 - " movq %%mm2, 48(%1)\n"
22078 - " movq %%mm3, 56(%1)\n"
22079 + "1: prefetch 320(%1)\n"
22080 + "2: movq (%1), %%mm0\n"
22081 + " movq 8(%1), %%mm1\n"
22082 + " movq 16(%1), %%mm2\n"
22083 + " movq 24(%1), %%mm3\n"
22084 + " movq %%mm0, (%2)\n"
22085 + " movq %%mm1, 8(%2)\n"
22086 + " movq %%mm2, 16(%2)\n"
22087 + " movq %%mm3, 24(%2)\n"
22088 + " movq 32(%1), %%mm0\n"
22089 + " movq 40(%1), %%mm1\n"
22090 + " movq 48(%1), %%mm2\n"
22091 + " movq 56(%1), %%mm3\n"
22092 + " movq %%mm0, 32(%2)\n"
22093 + " movq %%mm1, 40(%2)\n"
22094 + " movq %%mm2, 48(%2)\n"
22095 + " movq %%mm3, 56(%2)\n"
22096 ".section .fixup, \"ax\"\n"
22097 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22098 + "3:\n"
22099 +
22100 +#ifdef CONFIG_PAX_KERNEXEC
22101 + " movl %%cr0, %0\n"
22102 + " movl %0, %%eax\n"
22103 + " andl $0xFFFEFFFF, %%eax\n"
22104 + " movl %%eax, %%cr0\n"
22105 +#endif
22106 +
22107 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22108 +
22109 +#ifdef CONFIG_PAX_KERNEXEC
22110 + " movl %0, %%cr0\n"
22111 +#endif
22112 +
22113 " jmp 2b\n"
22114 ".previous\n"
22115 _ASM_EXTABLE(1b, 3b)
22116 - : : "r" (from), "r" (to) : "memory");
22117 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22118
22119 from += 64;
22120 to += 64;
22121 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22122 static void fast_copy_page(void *to, void *from)
22123 {
22124 int i;
22125 + unsigned long cr0;
22126
22127 kernel_fpu_begin();
22128
22129 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22130 * but that is for later. -AV
22131 */
22132 __asm__ __volatile__(
22133 - "1: prefetch (%0)\n"
22134 - " prefetch 64(%0)\n"
22135 - " prefetch 128(%0)\n"
22136 - " prefetch 192(%0)\n"
22137 - " prefetch 256(%0)\n"
22138 + "1: prefetch (%1)\n"
22139 + " prefetch 64(%1)\n"
22140 + " prefetch 128(%1)\n"
22141 + " prefetch 192(%1)\n"
22142 + " prefetch 256(%1)\n"
22143 "2: \n"
22144 ".section .fixup, \"ax\"\n"
22145 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22146 + "3: \n"
22147 +
22148 +#ifdef CONFIG_PAX_KERNEXEC
22149 + " movl %%cr0, %0\n"
22150 + " movl %0, %%eax\n"
22151 + " andl $0xFFFEFFFF, %%eax\n"
22152 + " movl %%eax, %%cr0\n"
22153 +#endif
22154 +
22155 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22156 +
22157 +#ifdef CONFIG_PAX_KERNEXEC
22158 + " movl %0, %%cr0\n"
22159 +#endif
22160 +
22161 " jmp 2b\n"
22162 ".previous\n"
22163 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22164 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22165
22166 for (i = 0; i < (4096-320)/64; i++) {
22167 __asm__ __volatile__ (
22168 - "1: prefetch 320(%0)\n"
22169 - "2: movq (%0), %%mm0\n"
22170 - " movntq %%mm0, (%1)\n"
22171 - " movq 8(%0), %%mm1\n"
22172 - " movntq %%mm1, 8(%1)\n"
22173 - " movq 16(%0), %%mm2\n"
22174 - " movntq %%mm2, 16(%1)\n"
22175 - " movq 24(%0), %%mm3\n"
22176 - " movntq %%mm3, 24(%1)\n"
22177 - " movq 32(%0), %%mm4\n"
22178 - " movntq %%mm4, 32(%1)\n"
22179 - " movq 40(%0), %%mm5\n"
22180 - " movntq %%mm5, 40(%1)\n"
22181 - " movq 48(%0), %%mm6\n"
22182 - " movntq %%mm6, 48(%1)\n"
22183 - " movq 56(%0), %%mm7\n"
22184 - " movntq %%mm7, 56(%1)\n"
22185 + "1: prefetch 320(%1)\n"
22186 + "2: movq (%1), %%mm0\n"
22187 + " movntq %%mm0, (%2)\n"
22188 + " movq 8(%1), %%mm1\n"
22189 + " movntq %%mm1, 8(%2)\n"
22190 + " movq 16(%1), %%mm2\n"
22191 + " movntq %%mm2, 16(%2)\n"
22192 + " movq 24(%1), %%mm3\n"
22193 + " movntq %%mm3, 24(%2)\n"
22194 + " movq 32(%1), %%mm4\n"
22195 + " movntq %%mm4, 32(%2)\n"
22196 + " movq 40(%1), %%mm5\n"
22197 + " movntq %%mm5, 40(%2)\n"
22198 + " movq 48(%1), %%mm6\n"
22199 + " movntq %%mm6, 48(%2)\n"
22200 + " movq 56(%1), %%mm7\n"
22201 + " movntq %%mm7, 56(%2)\n"
22202 ".section .fixup, \"ax\"\n"
22203 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22204 + "3:\n"
22205 +
22206 +#ifdef CONFIG_PAX_KERNEXEC
22207 + " movl %%cr0, %0\n"
22208 + " movl %0, %%eax\n"
22209 + " andl $0xFFFEFFFF, %%eax\n"
22210 + " movl %%eax, %%cr0\n"
22211 +#endif
22212 +
22213 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22214 +
22215 +#ifdef CONFIG_PAX_KERNEXEC
22216 + " movl %0, %%cr0\n"
22217 +#endif
22218 +
22219 " jmp 2b\n"
22220 ".previous\n"
22221 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22222 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22223
22224 from += 64;
22225 to += 64;
22226 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22227 static void fast_copy_page(void *to, void *from)
22228 {
22229 int i;
22230 + unsigned long cr0;
22231
22232 kernel_fpu_begin();
22233
22234 __asm__ __volatile__ (
22235 - "1: prefetch (%0)\n"
22236 - " prefetch 64(%0)\n"
22237 - " prefetch 128(%0)\n"
22238 - " prefetch 192(%0)\n"
22239 - " prefetch 256(%0)\n"
22240 + "1: prefetch (%1)\n"
22241 + " prefetch 64(%1)\n"
22242 + " prefetch 128(%1)\n"
22243 + " prefetch 192(%1)\n"
22244 + " prefetch 256(%1)\n"
22245 "2: \n"
22246 ".section .fixup, \"ax\"\n"
22247 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22248 + "3: \n"
22249 +
22250 +#ifdef CONFIG_PAX_KERNEXEC
22251 + " movl %%cr0, %0\n"
22252 + " movl %0, %%eax\n"
22253 + " andl $0xFFFEFFFF, %%eax\n"
22254 + " movl %%eax, %%cr0\n"
22255 +#endif
22256 +
22257 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22258 +
22259 +#ifdef CONFIG_PAX_KERNEXEC
22260 + " movl %0, %%cr0\n"
22261 +#endif
22262 +
22263 " jmp 2b\n"
22264 ".previous\n"
22265 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22266 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22267
22268 for (i = 0; i < 4096/64; i++) {
22269 __asm__ __volatile__ (
22270 - "1: prefetch 320(%0)\n"
22271 - "2: movq (%0), %%mm0\n"
22272 - " movq 8(%0), %%mm1\n"
22273 - " movq 16(%0), %%mm2\n"
22274 - " movq 24(%0), %%mm3\n"
22275 - " movq %%mm0, (%1)\n"
22276 - " movq %%mm1, 8(%1)\n"
22277 - " movq %%mm2, 16(%1)\n"
22278 - " movq %%mm3, 24(%1)\n"
22279 - " movq 32(%0), %%mm0\n"
22280 - " movq 40(%0), %%mm1\n"
22281 - " movq 48(%0), %%mm2\n"
22282 - " movq 56(%0), %%mm3\n"
22283 - " movq %%mm0, 32(%1)\n"
22284 - " movq %%mm1, 40(%1)\n"
22285 - " movq %%mm2, 48(%1)\n"
22286 - " movq %%mm3, 56(%1)\n"
22287 + "1: prefetch 320(%1)\n"
22288 + "2: movq (%1), %%mm0\n"
22289 + " movq 8(%1), %%mm1\n"
22290 + " movq 16(%1), %%mm2\n"
22291 + " movq 24(%1), %%mm3\n"
22292 + " movq %%mm0, (%2)\n"
22293 + " movq %%mm1, 8(%2)\n"
22294 + " movq %%mm2, 16(%2)\n"
22295 + " movq %%mm3, 24(%2)\n"
22296 + " movq 32(%1), %%mm0\n"
22297 + " movq 40(%1), %%mm1\n"
22298 + " movq 48(%1), %%mm2\n"
22299 + " movq 56(%1), %%mm3\n"
22300 + " movq %%mm0, 32(%2)\n"
22301 + " movq %%mm1, 40(%2)\n"
22302 + " movq %%mm2, 48(%2)\n"
22303 + " movq %%mm3, 56(%2)\n"
22304 ".section .fixup, \"ax\"\n"
22305 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22306 + "3:\n"
22307 +
22308 +#ifdef CONFIG_PAX_KERNEXEC
22309 + " movl %%cr0, %0\n"
22310 + " movl %0, %%eax\n"
22311 + " andl $0xFFFEFFFF, %%eax\n"
22312 + " movl %%eax, %%cr0\n"
22313 +#endif
22314 +
22315 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22316 +
22317 +#ifdef CONFIG_PAX_KERNEXEC
22318 + " movl %0, %%cr0\n"
22319 +#endif
22320 +
22321 " jmp 2b\n"
22322 ".previous\n"
22323 _ASM_EXTABLE(1b, 3b)
22324 - : : "r" (from), "r" (to) : "memory");
22325 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22326
22327 from += 64;
22328 to += 64;
22329 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22330 index 69fa106..adda88b 100644
22331 --- a/arch/x86/lib/msr-reg.S
22332 +++ b/arch/x86/lib/msr-reg.S
22333 @@ -3,6 +3,7 @@
22334 #include <asm/dwarf2.h>
22335 #include <asm/asm.h>
22336 #include <asm/msr.h>
22337 +#include <asm/alternative-asm.h>
22338
22339 #ifdef CONFIG_X86_64
22340 /*
22341 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22342 CFI_STARTPROC
22343 pushq_cfi %rbx
22344 pushq_cfi %rbp
22345 - movq %rdi, %r10 /* Save pointer */
22346 + movq %rdi, %r9 /* Save pointer */
22347 xorl %r11d, %r11d /* Return value */
22348 movl (%rdi), %eax
22349 movl 4(%rdi), %ecx
22350 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22351 movl 28(%rdi), %edi
22352 CFI_REMEMBER_STATE
22353 1: \op
22354 -2: movl %eax, (%r10)
22355 +2: movl %eax, (%r9)
22356 movl %r11d, %eax /* Return value */
22357 - movl %ecx, 4(%r10)
22358 - movl %edx, 8(%r10)
22359 - movl %ebx, 12(%r10)
22360 - movl %ebp, 20(%r10)
22361 - movl %esi, 24(%r10)
22362 - movl %edi, 28(%r10)
22363 + movl %ecx, 4(%r9)
22364 + movl %edx, 8(%r9)
22365 + movl %ebx, 12(%r9)
22366 + movl %ebp, 20(%r9)
22367 + movl %esi, 24(%r9)
22368 + movl %edi, 28(%r9)
22369 popq_cfi %rbp
22370 popq_cfi %rbx
22371 + pax_force_retaddr
22372 ret
22373 3:
22374 CFI_RESTORE_STATE
22375 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22376 index 7f951c8..ebd573a 100644
22377 --- a/arch/x86/lib/putuser.S
22378 +++ b/arch/x86/lib/putuser.S
22379 @@ -15,7 +15,9 @@
22380 #include <asm/thread_info.h>
22381 #include <asm/errno.h>
22382 #include <asm/asm.h>
22383 -
22384 +#include <asm/segment.h>
22385 +#include <asm/pgtable.h>
22386 +#include <asm/alternative-asm.h>
22387
22388 /*
22389 * __put_user_X
22390 @@ -29,52 +31,119 @@
22391 * as they get called from within inline assembly.
22392 */
22393
22394 -#define ENTER CFI_STARTPROC ; \
22395 - GET_THREAD_INFO(%_ASM_BX)
22396 -#define EXIT ret ; \
22397 +#define ENTER CFI_STARTPROC
22398 +#define EXIT pax_force_retaddr; ret ; \
22399 CFI_ENDPROC
22400
22401 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22402 +#define _DEST %_ASM_CX,%_ASM_BX
22403 +#else
22404 +#define _DEST %_ASM_CX
22405 +#endif
22406 +
22407 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22408 +#define __copyuser_seg gs;
22409 +#else
22410 +#define __copyuser_seg
22411 +#endif
22412 +
22413 .text
22414 ENTRY(__put_user_1)
22415 ENTER
22416 +
22417 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22418 + GET_THREAD_INFO(%_ASM_BX)
22419 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22420 jae bad_put_user
22421 -1: movb %al,(%_ASM_CX)
22422 +
22423 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22424 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22425 + cmp %_ASM_BX,%_ASM_CX
22426 + jb 1234f
22427 + xor %ebx,%ebx
22428 +1234:
22429 +#endif
22430 +
22431 +#endif
22432 +
22433 +1: __copyuser_seg movb %al,(_DEST)
22434 xor %eax,%eax
22435 EXIT
22436 ENDPROC(__put_user_1)
22437
22438 ENTRY(__put_user_2)
22439 ENTER
22440 +
22441 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22442 + GET_THREAD_INFO(%_ASM_BX)
22443 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22444 sub $1,%_ASM_BX
22445 cmp %_ASM_BX,%_ASM_CX
22446 jae bad_put_user
22447 -2: movw %ax,(%_ASM_CX)
22448 +
22449 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22450 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22451 + cmp %_ASM_BX,%_ASM_CX
22452 + jb 1234f
22453 + xor %ebx,%ebx
22454 +1234:
22455 +#endif
22456 +
22457 +#endif
22458 +
22459 +2: __copyuser_seg movw %ax,(_DEST)
22460 xor %eax,%eax
22461 EXIT
22462 ENDPROC(__put_user_2)
22463
22464 ENTRY(__put_user_4)
22465 ENTER
22466 +
22467 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22468 + GET_THREAD_INFO(%_ASM_BX)
22469 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22470 sub $3,%_ASM_BX
22471 cmp %_ASM_BX,%_ASM_CX
22472 jae bad_put_user
22473 -3: movl %eax,(%_ASM_CX)
22474 +
22475 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22476 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22477 + cmp %_ASM_BX,%_ASM_CX
22478 + jb 1234f
22479 + xor %ebx,%ebx
22480 +1234:
22481 +#endif
22482 +
22483 +#endif
22484 +
22485 +3: __copyuser_seg movl %eax,(_DEST)
22486 xor %eax,%eax
22487 EXIT
22488 ENDPROC(__put_user_4)
22489
22490 ENTRY(__put_user_8)
22491 ENTER
22492 +
22493 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22494 + GET_THREAD_INFO(%_ASM_BX)
22495 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22496 sub $7,%_ASM_BX
22497 cmp %_ASM_BX,%_ASM_CX
22498 jae bad_put_user
22499 -4: mov %_ASM_AX,(%_ASM_CX)
22500 +
22501 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22502 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22503 + cmp %_ASM_BX,%_ASM_CX
22504 + jb 1234f
22505 + xor %ebx,%ebx
22506 +1234:
22507 +#endif
22508 +
22509 +#endif
22510 +
22511 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22512 #ifdef CONFIG_X86_32
22513 -5: movl %edx,4(%_ASM_CX)
22514 +5: __copyuser_seg movl %edx,4(_DEST)
22515 #endif
22516 xor %eax,%eax
22517 EXIT
22518 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22519 index 1cad221..de671ee 100644
22520 --- a/arch/x86/lib/rwlock.S
22521 +++ b/arch/x86/lib/rwlock.S
22522 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22523 FRAME
22524 0: LOCK_PREFIX
22525 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22526 +
22527 +#ifdef CONFIG_PAX_REFCOUNT
22528 + jno 1234f
22529 + LOCK_PREFIX
22530 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22531 + int $4
22532 +1234:
22533 + _ASM_EXTABLE(1234b, 1234b)
22534 +#endif
22535 +
22536 1: rep; nop
22537 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22538 jne 1b
22539 LOCK_PREFIX
22540 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22541 +
22542 +#ifdef CONFIG_PAX_REFCOUNT
22543 + jno 1234f
22544 + LOCK_PREFIX
22545 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22546 + int $4
22547 +1234:
22548 + _ASM_EXTABLE(1234b, 1234b)
22549 +#endif
22550 +
22551 jnz 0b
22552 ENDFRAME
22553 + pax_force_retaddr
22554 ret
22555 CFI_ENDPROC
22556 END(__write_lock_failed)
22557 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22558 FRAME
22559 0: LOCK_PREFIX
22560 READ_LOCK_SIZE(inc) (%__lock_ptr)
22561 +
22562 +#ifdef CONFIG_PAX_REFCOUNT
22563 + jno 1234f
22564 + LOCK_PREFIX
22565 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22566 + int $4
22567 +1234:
22568 + _ASM_EXTABLE(1234b, 1234b)
22569 +#endif
22570 +
22571 1: rep; nop
22572 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22573 js 1b
22574 LOCK_PREFIX
22575 READ_LOCK_SIZE(dec) (%__lock_ptr)
22576 +
22577 +#ifdef CONFIG_PAX_REFCOUNT
22578 + jno 1234f
22579 + LOCK_PREFIX
22580 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22581 + int $4
22582 +1234:
22583 + _ASM_EXTABLE(1234b, 1234b)
22584 +#endif
22585 +
22586 js 0b
22587 ENDFRAME
22588 + pax_force_retaddr
22589 ret
22590 CFI_ENDPROC
22591 END(__read_lock_failed)
22592 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22593 index 5dff5f0..cadebf4 100644
22594 --- a/arch/x86/lib/rwsem.S
22595 +++ b/arch/x86/lib/rwsem.S
22596 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22597 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22598 CFI_RESTORE __ASM_REG(dx)
22599 restore_common_regs
22600 + pax_force_retaddr
22601 ret
22602 CFI_ENDPROC
22603 ENDPROC(call_rwsem_down_read_failed)
22604 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22605 movq %rax,%rdi
22606 call rwsem_down_write_failed
22607 restore_common_regs
22608 + pax_force_retaddr
22609 ret
22610 CFI_ENDPROC
22611 ENDPROC(call_rwsem_down_write_failed)
22612 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22613 movq %rax,%rdi
22614 call rwsem_wake
22615 restore_common_regs
22616 -1: ret
22617 +1: pax_force_retaddr
22618 + ret
22619 CFI_ENDPROC
22620 ENDPROC(call_rwsem_wake)
22621
22622 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22623 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22624 CFI_RESTORE __ASM_REG(dx)
22625 restore_common_regs
22626 + pax_force_retaddr
22627 ret
22628 CFI_ENDPROC
22629 ENDPROC(call_rwsem_downgrade_wake)
22630 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22631 index a63efd6..ccecad8 100644
22632 --- a/arch/x86/lib/thunk_64.S
22633 +++ b/arch/x86/lib/thunk_64.S
22634 @@ -8,6 +8,7 @@
22635 #include <linux/linkage.h>
22636 #include <asm/dwarf2.h>
22637 #include <asm/calling.h>
22638 +#include <asm/alternative-asm.h>
22639
22640 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22641 .macro THUNK name, func, put_ret_addr_in_rdi=0
22642 @@ -41,5 +42,6 @@
22643 SAVE_ARGS
22644 restore:
22645 RESTORE_ARGS
22646 + pax_force_retaddr
22647 ret
22648 CFI_ENDPROC
22649 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22650 index 1781b2f..18e3040 100644
22651 --- a/arch/x86/lib/usercopy_32.c
22652 +++ b/arch/x86/lib/usercopy_32.c
22653 @@ -42,10 +42,12 @@ do { \
22654 int __d0; \
22655 might_fault(); \
22656 __asm__ __volatile__( \
22657 + __COPYUSER_SET_ES \
22658 "0: rep; stosl\n" \
22659 " movl %2,%0\n" \
22660 "1: rep; stosb\n" \
22661 "2:\n" \
22662 + __COPYUSER_RESTORE_ES \
22663 ".section .fixup,\"ax\"\n" \
22664 "3: lea 0(%2,%0,4),%0\n" \
22665 " jmp 2b\n" \
22666 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22667
22668 #ifdef CONFIG_X86_INTEL_USERCOPY
22669 static unsigned long
22670 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22671 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22672 {
22673 int d0, d1;
22674 __asm__ __volatile__(
22675 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22676 " .align 2,0x90\n"
22677 "3: movl 0(%4), %%eax\n"
22678 "4: movl 4(%4), %%edx\n"
22679 - "5: movl %%eax, 0(%3)\n"
22680 - "6: movl %%edx, 4(%3)\n"
22681 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22682 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22683 "7: movl 8(%4), %%eax\n"
22684 "8: movl 12(%4),%%edx\n"
22685 - "9: movl %%eax, 8(%3)\n"
22686 - "10: movl %%edx, 12(%3)\n"
22687 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22688 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22689 "11: movl 16(%4), %%eax\n"
22690 "12: movl 20(%4), %%edx\n"
22691 - "13: movl %%eax, 16(%3)\n"
22692 - "14: movl %%edx, 20(%3)\n"
22693 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22694 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22695 "15: movl 24(%4), %%eax\n"
22696 "16: movl 28(%4), %%edx\n"
22697 - "17: movl %%eax, 24(%3)\n"
22698 - "18: movl %%edx, 28(%3)\n"
22699 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22700 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22701 "19: movl 32(%4), %%eax\n"
22702 "20: movl 36(%4), %%edx\n"
22703 - "21: movl %%eax, 32(%3)\n"
22704 - "22: movl %%edx, 36(%3)\n"
22705 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22706 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22707 "23: movl 40(%4), %%eax\n"
22708 "24: movl 44(%4), %%edx\n"
22709 - "25: movl %%eax, 40(%3)\n"
22710 - "26: movl %%edx, 44(%3)\n"
22711 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22712 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22713 "27: movl 48(%4), %%eax\n"
22714 "28: movl 52(%4), %%edx\n"
22715 - "29: movl %%eax, 48(%3)\n"
22716 - "30: movl %%edx, 52(%3)\n"
22717 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22718 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22719 "31: movl 56(%4), %%eax\n"
22720 "32: movl 60(%4), %%edx\n"
22721 - "33: movl %%eax, 56(%3)\n"
22722 - "34: movl %%edx, 60(%3)\n"
22723 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22724 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22725 " addl $-64, %0\n"
22726 " addl $64, %4\n"
22727 " addl $64, %3\n"
22728 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22729 " shrl $2, %0\n"
22730 " andl $3, %%eax\n"
22731 " cld\n"
22732 + __COPYUSER_SET_ES
22733 "99: rep; movsl\n"
22734 "36: movl %%eax, %0\n"
22735 "37: rep; movsb\n"
22736 "100:\n"
22737 + __COPYUSER_RESTORE_ES
22738 ".section .fixup,\"ax\"\n"
22739 "101: lea 0(%%eax,%0,4),%0\n"
22740 " jmp 100b\n"
22741 @@ -201,46 +205,152 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22742 }
22743
22744 static unsigned long
22745 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22746 +{
22747 + int d0, d1;
22748 + __asm__ __volatile__(
22749 + " .align 2,0x90\n"
22750 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22751 + " cmpl $67, %0\n"
22752 + " jbe 3f\n"
22753 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22754 + " .align 2,0x90\n"
22755 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22756 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22757 + "5: movl %%eax, 0(%3)\n"
22758 + "6: movl %%edx, 4(%3)\n"
22759 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22760 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22761 + "9: movl %%eax, 8(%3)\n"
22762 + "10: movl %%edx, 12(%3)\n"
22763 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22764 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22765 + "13: movl %%eax, 16(%3)\n"
22766 + "14: movl %%edx, 20(%3)\n"
22767 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22768 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22769 + "17: movl %%eax, 24(%3)\n"
22770 + "18: movl %%edx, 28(%3)\n"
22771 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22772 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22773 + "21: movl %%eax, 32(%3)\n"
22774 + "22: movl %%edx, 36(%3)\n"
22775 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22776 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22777 + "25: movl %%eax, 40(%3)\n"
22778 + "26: movl %%edx, 44(%3)\n"
22779 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22780 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22781 + "29: movl %%eax, 48(%3)\n"
22782 + "30: movl %%edx, 52(%3)\n"
22783 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22784 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22785 + "33: movl %%eax, 56(%3)\n"
22786 + "34: movl %%edx, 60(%3)\n"
22787 + " addl $-64, %0\n"
22788 + " addl $64, %4\n"
22789 + " addl $64, %3\n"
22790 + " cmpl $63, %0\n"
22791 + " ja 1b\n"
22792 + "35: movl %0, %%eax\n"
22793 + " shrl $2, %0\n"
22794 + " andl $3, %%eax\n"
22795 + " cld\n"
22796 + "99: rep; "__copyuser_seg" movsl\n"
22797 + "36: movl %%eax, %0\n"
22798 + "37: rep; "__copyuser_seg" movsb\n"
22799 + "100:\n"
22800 + ".section .fixup,\"ax\"\n"
22801 + "101: lea 0(%%eax,%0,4),%0\n"
22802 + " jmp 100b\n"
22803 + ".previous\n"
22804 + _ASM_EXTABLE(1b,100b)
22805 + _ASM_EXTABLE(2b,100b)
22806 + _ASM_EXTABLE(3b,100b)
22807 + _ASM_EXTABLE(4b,100b)
22808 + _ASM_EXTABLE(5b,100b)
22809 + _ASM_EXTABLE(6b,100b)
22810 + _ASM_EXTABLE(7b,100b)
22811 + _ASM_EXTABLE(8b,100b)
22812 + _ASM_EXTABLE(9b,100b)
22813 + _ASM_EXTABLE(10b,100b)
22814 + _ASM_EXTABLE(11b,100b)
22815 + _ASM_EXTABLE(12b,100b)
22816 + _ASM_EXTABLE(13b,100b)
22817 + _ASM_EXTABLE(14b,100b)
22818 + _ASM_EXTABLE(15b,100b)
22819 + _ASM_EXTABLE(16b,100b)
22820 + _ASM_EXTABLE(17b,100b)
22821 + _ASM_EXTABLE(18b,100b)
22822 + _ASM_EXTABLE(19b,100b)
22823 + _ASM_EXTABLE(20b,100b)
22824 + _ASM_EXTABLE(21b,100b)
22825 + _ASM_EXTABLE(22b,100b)
22826 + _ASM_EXTABLE(23b,100b)
22827 + _ASM_EXTABLE(24b,100b)
22828 + _ASM_EXTABLE(25b,100b)
22829 + _ASM_EXTABLE(26b,100b)
22830 + _ASM_EXTABLE(27b,100b)
22831 + _ASM_EXTABLE(28b,100b)
22832 + _ASM_EXTABLE(29b,100b)
22833 + _ASM_EXTABLE(30b,100b)
22834 + _ASM_EXTABLE(31b,100b)
22835 + _ASM_EXTABLE(32b,100b)
22836 + _ASM_EXTABLE(33b,100b)
22837 + _ASM_EXTABLE(34b,100b)
22838 + _ASM_EXTABLE(35b,100b)
22839 + _ASM_EXTABLE(36b,100b)
22840 + _ASM_EXTABLE(37b,100b)
22841 + _ASM_EXTABLE(99b,101b)
22842 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
22843 + : "1"(to), "2"(from), "0"(size)
22844 + : "eax", "edx", "memory");
22845 + return size;
22846 +}
22847 +
22848 +static unsigned long
22849 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22850 +static unsigned long
22851 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22852 {
22853 int d0, d1;
22854 __asm__ __volatile__(
22855 " .align 2,0x90\n"
22856 - "0: movl 32(%4), %%eax\n"
22857 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22858 " cmpl $67, %0\n"
22859 " jbe 2f\n"
22860 - "1: movl 64(%4), %%eax\n"
22861 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22862 " .align 2,0x90\n"
22863 - "2: movl 0(%4), %%eax\n"
22864 - "21: movl 4(%4), %%edx\n"
22865 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22866 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22867 " movl %%eax, 0(%3)\n"
22868 " movl %%edx, 4(%3)\n"
22869 - "3: movl 8(%4), %%eax\n"
22870 - "31: movl 12(%4),%%edx\n"
22871 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22872 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22873 " movl %%eax, 8(%3)\n"
22874 " movl %%edx, 12(%3)\n"
22875 - "4: movl 16(%4), %%eax\n"
22876 - "41: movl 20(%4), %%edx\n"
22877 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22878 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22879 " movl %%eax, 16(%3)\n"
22880 " movl %%edx, 20(%3)\n"
22881 - "10: movl 24(%4), %%eax\n"
22882 - "51: movl 28(%4), %%edx\n"
22883 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22884 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22885 " movl %%eax, 24(%3)\n"
22886 " movl %%edx, 28(%3)\n"
22887 - "11: movl 32(%4), %%eax\n"
22888 - "61: movl 36(%4), %%edx\n"
22889 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22890 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22891 " movl %%eax, 32(%3)\n"
22892 " movl %%edx, 36(%3)\n"
22893 - "12: movl 40(%4), %%eax\n"
22894 - "71: movl 44(%4), %%edx\n"
22895 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22896 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22897 " movl %%eax, 40(%3)\n"
22898 " movl %%edx, 44(%3)\n"
22899 - "13: movl 48(%4), %%eax\n"
22900 - "81: movl 52(%4), %%edx\n"
22901 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22902 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22903 " movl %%eax, 48(%3)\n"
22904 " movl %%edx, 52(%3)\n"
22905 - "14: movl 56(%4), %%eax\n"
22906 - "91: movl 60(%4), %%edx\n"
22907 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22908 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22909 " movl %%eax, 56(%3)\n"
22910 " movl %%edx, 60(%3)\n"
22911 " addl $-64, %0\n"
22912 @@ -252,9 +362,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22913 " shrl $2, %0\n"
22914 " andl $3, %%eax\n"
22915 " cld\n"
22916 - "6: rep; movsl\n"
22917 + "6: rep; "__copyuser_seg" movsl\n"
22918 " movl %%eax,%0\n"
22919 - "7: rep; movsb\n"
22920 + "7: rep; "__copyuser_seg" movsb\n"
22921 "8:\n"
22922 ".section .fixup,\"ax\"\n"
22923 "9: lea 0(%%eax,%0,4),%0\n"
22924 @@ -298,47 +408,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22925 */
22926
22927 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22928 + const void __user *from, unsigned long size) __size_overflow(3);
22929 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22930 const void __user *from, unsigned long size)
22931 {
22932 int d0, d1;
22933
22934 __asm__ __volatile__(
22935 " .align 2,0x90\n"
22936 - "0: movl 32(%4), %%eax\n"
22937 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22938 " cmpl $67, %0\n"
22939 " jbe 2f\n"
22940 - "1: movl 64(%4), %%eax\n"
22941 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22942 " .align 2,0x90\n"
22943 - "2: movl 0(%4), %%eax\n"
22944 - "21: movl 4(%4), %%edx\n"
22945 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22946 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22947 " movnti %%eax, 0(%3)\n"
22948 " movnti %%edx, 4(%3)\n"
22949 - "3: movl 8(%4), %%eax\n"
22950 - "31: movl 12(%4),%%edx\n"
22951 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22952 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22953 " movnti %%eax, 8(%3)\n"
22954 " movnti %%edx, 12(%3)\n"
22955 - "4: movl 16(%4), %%eax\n"
22956 - "41: movl 20(%4), %%edx\n"
22957 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22958 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22959 " movnti %%eax, 16(%3)\n"
22960 " movnti %%edx, 20(%3)\n"
22961 - "10: movl 24(%4), %%eax\n"
22962 - "51: movl 28(%4), %%edx\n"
22963 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22964 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22965 " movnti %%eax, 24(%3)\n"
22966 " movnti %%edx, 28(%3)\n"
22967 - "11: movl 32(%4), %%eax\n"
22968 - "61: movl 36(%4), %%edx\n"
22969 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22970 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22971 " movnti %%eax, 32(%3)\n"
22972 " movnti %%edx, 36(%3)\n"
22973 - "12: movl 40(%4), %%eax\n"
22974 - "71: movl 44(%4), %%edx\n"
22975 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22976 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22977 " movnti %%eax, 40(%3)\n"
22978 " movnti %%edx, 44(%3)\n"
22979 - "13: movl 48(%4), %%eax\n"
22980 - "81: movl 52(%4), %%edx\n"
22981 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22982 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22983 " movnti %%eax, 48(%3)\n"
22984 " movnti %%edx, 52(%3)\n"
22985 - "14: movl 56(%4), %%eax\n"
22986 - "91: movl 60(%4), %%edx\n"
22987 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22988 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22989 " movnti %%eax, 56(%3)\n"
22990 " movnti %%edx, 60(%3)\n"
22991 " addl $-64, %0\n"
22992 @@ -351,9 +463,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22993 " shrl $2, %0\n"
22994 " andl $3, %%eax\n"
22995 " cld\n"
22996 - "6: rep; movsl\n"
22997 + "6: rep; "__copyuser_seg" movsl\n"
22998 " movl %%eax,%0\n"
22999 - "7: rep; movsb\n"
23000 + "7: rep; "__copyuser_seg" movsb\n"
23001 "8:\n"
23002 ".section .fixup,\"ax\"\n"
23003 "9: lea 0(%%eax,%0,4),%0\n"
23004 @@ -392,47 +504,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23005 }
23006
23007 static unsigned long __copy_user_intel_nocache(void *to,
23008 + const void __user *from, unsigned long size) __size_overflow(3);
23009 +static unsigned long __copy_user_intel_nocache(void *to,
23010 const void __user *from, unsigned long size)
23011 {
23012 int d0, d1;
23013
23014 __asm__ __volatile__(
23015 " .align 2,0x90\n"
23016 - "0: movl 32(%4), %%eax\n"
23017 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23018 " cmpl $67, %0\n"
23019 " jbe 2f\n"
23020 - "1: movl 64(%4), %%eax\n"
23021 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23022 " .align 2,0x90\n"
23023 - "2: movl 0(%4), %%eax\n"
23024 - "21: movl 4(%4), %%edx\n"
23025 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23026 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23027 " movnti %%eax, 0(%3)\n"
23028 " movnti %%edx, 4(%3)\n"
23029 - "3: movl 8(%4), %%eax\n"
23030 - "31: movl 12(%4),%%edx\n"
23031 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23032 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23033 " movnti %%eax, 8(%3)\n"
23034 " movnti %%edx, 12(%3)\n"
23035 - "4: movl 16(%4), %%eax\n"
23036 - "41: movl 20(%4), %%edx\n"
23037 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23038 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23039 " movnti %%eax, 16(%3)\n"
23040 " movnti %%edx, 20(%3)\n"
23041 - "10: movl 24(%4), %%eax\n"
23042 - "51: movl 28(%4), %%edx\n"
23043 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23044 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23045 " movnti %%eax, 24(%3)\n"
23046 " movnti %%edx, 28(%3)\n"
23047 - "11: movl 32(%4), %%eax\n"
23048 - "61: movl 36(%4), %%edx\n"
23049 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23050 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23051 " movnti %%eax, 32(%3)\n"
23052 " movnti %%edx, 36(%3)\n"
23053 - "12: movl 40(%4), %%eax\n"
23054 - "71: movl 44(%4), %%edx\n"
23055 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23056 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23057 " movnti %%eax, 40(%3)\n"
23058 " movnti %%edx, 44(%3)\n"
23059 - "13: movl 48(%4), %%eax\n"
23060 - "81: movl 52(%4), %%edx\n"
23061 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23062 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23063 " movnti %%eax, 48(%3)\n"
23064 " movnti %%edx, 52(%3)\n"
23065 - "14: movl 56(%4), %%eax\n"
23066 - "91: movl 60(%4), %%edx\n"
23067 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23068 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23069 " movnti %%eax, 56(%3)\n"
23070 " movnti %%edx, 60(%3)\n"
23071 " addl $-64, %0\n"
23072 @@ -445,9 +559,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23073 " shrl $2, %0\n"
23074 " andl $3, %%eax\n"
23075 " cld\n"
23076 - "6: rep; movsl\n"
23077 + "6: rep; "__copyuser_seg" movsl\n"
23078 " movl %%eax,%0\n"
23079 - "7: rep; movsb\n"
23080 + "7: rep; "__copyuser_seg" movsb\n"
23081 "8:\n"
23082 ".section .fixup,\"ax\"\n"
23083 "9: lea 0(%%eax,%0,4),%0\n"
23084 @@ -487,32 +601,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23085 */
23086 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23087 unsigned long size);
23088 -unsigned long __copy_user_intel(void __user *to, const void *from,
23089 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23090 + unsigned long size);
23091 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23092 unsigned long size);
23093 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23094 const void __user *from, unsigned long size);
23095 #endif /* CONFIG_X86_INTEL_USERCOPY */
23096
23097 /* Generic arbitrary sized copy. */
23098 -#define __copy_user(to, from, size) \
23099 +#define __copy_user(to, from, size, prefix, set, restore) \
23100 do { \
23101 int __d0, __d1, __d2; \
23102 __asm__ __volatile__( \
23103 + set \
23104 " cmp $7,%0\n" \
23105 " jbe 1f\n" \
23106 " movl %1,%0\n" \
23107 " negl %0\n" \
23108 " andl $7,%0\n" \
23109 " subl %0,%3\n" \
23110 - "4: rep; movsb\n" \
23111 + "4: rep; "prefix"movsb\n" \
23112 " movl %3,%0\n" \
23113 " shrl $2,%0\n" \
23114 " andl $3,%3\n" \
23115 " .align 2,0x90\n" \
23116 - "0: rep; movsl\n" \
23117 + "0: rep; "prefix"movsl\n" \
23118 " movl %3,%0\n" \
23119 - "1: rep; movsb\n" \
23120 + "1: rep; "prefix"movsb\n" \
23121 "2:\n" \
23122 + restore \
23123 ".section .fixup,\"ax\"\n" \
23124 "5: addl %3,%0\n" \
23125 " jmp 2b\n" \
23126 @@ -537,14 +655,14 @@ do { \
23127 " negl %0\n" \
23128 " andl $7,%0\n" \
23129 " subl %0,%3\n" \
23130 - "4: rep; movsb\n" \
23131 + "4: rep; "__copyuser_seg"movsb\n" \
23132 " movl %3,%0\n" \
23133 " shrl $2,%0\n" \
23134 " andl $3,%3\n" \
23135 " .align 2,0x90\n" \
23136 - "0: rep; movsl\n" \
23137 + "0: rep; "__copyuser_seg"movsl\n" \
23138 " movl %3,%0\n" \
23139 - "1: rep; movsb\n" \
23140 + "1: rep; "__copyuser_seg"movsb\n" \
23141 "2:\n" \
23142 ".section .fixup,\"ax\"\n" \
23143 "5: addl %3,%0\n" \
23144 @@ -627,9 +745,9 @@ survive:
23145 }
23146 #endif
23147 if (movsl_is_ok(to, from, n))
23148 - __copy_user(to, from, n);
23149 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23150 else
23151 - n = __copy_user_intel(to, from, n);
23152 + n = __generic_copy_to_user_intel(to, from, n);
23153 return n;
23154 }
23155 EXPORT_SYMBOL(__copy_to_user_ll);
23156 @@ -649,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23157 unsigned long n)
23158 {
23159 if (movsl_is_ok(to, from, n))
23160 - __copy_user(to, from, n);
23161 + __copy_user(to, from, n, __copyuser_seg, "", "");
23162 else
23163 - n = __copy_user_intel((void __user *)to,
23164 - (const void *)from, n);
23165 + n = __generic_copy_from_user_intel(to, from, n);
23166 return n;
23167 }
23168 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23169 @@ -679,65 +796,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23170 if (n > 64 && cpu_has_xmm2)
23171 n = __copy_user_intel_nocache(to, from, n);
23172 else
23173 - __copy_user(to, from, n);
23174 + __copy_user(to, from, n, __copyuser_seg, "", "");
23175 #else
23176 - __copy_user(to, from, n);
23177 + __copy_user(to, from, n, __copyuser_seg, "", "");
23178 #endif
23179 return n;
23180 }
23181 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23182
23183 -/**
23184 - * copy_to_user: - Copy a block of data into user space.
23185 - * @to: Destination address, in user space.
23186 - * @from: Source address, in kernel space.
23187 - * @n: Number of bytes to copy.
23188 - *
23189 - * Context: User context only. This function may sleep.
23190 - *
23191 - * Copy data from kernel space to user space.
23192 - *
23193 - * Returns number of bytes that could not be copied.
23194 - * On success, this will be zero.
23195 - */
23196 -unsigned long
23197 -copy_to_user(void __user *to, const void *from, unsigned long n)
23198 -{
23199 - if (access_ok(VERIFY_WRITE, to, n))
23200 - n = __copy_to_user(to, from, n);
23201 - return n;
23202 -}
23203 -EXPORT_SYMBOL(copy_to_user);
23204 -
23205 -/**
23206 - * copy_from_user: - Copy a block of data from user space.
23207 - * @to: Destination address, in kernel space.
23208 - * @from: Source address, in user space.
23209 - * @n: Number of bytes to copy.
23210 - *
23211 - * Context: User context only. This function may sleep.
23212 - *
23213 - * Copy data from user space to kernel space.
23214 - *
23215 - * Returns number of bytes that could not be copied.
23216 - * On success, this will be zero.
23217 - *
23218 - * If some data could not be copied, this function will pad the copied
23219 - * data to the requested size using zero bytes.
23220 - */
23221 -unsigned long
23222 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23223 -{
23224 - if (access_ok(VERIFY_READ, from, n))
23225 - n = __copy_from_user(to, from, n);
23226 - else
23227 - memset(to, 0, n);
23228 - return n;
23229 -}
23230 -EXPORT_SYMBOL(_copy_from_user);
23231 -
23232 void copy_from_user_overflow(void)
23233 {
23234 WARN(1, "Buffer overflow detected!\n");
23235 }
23236 EXPORT_SYMBOL(copy_from_user_overflow);
23237 +
23238 +void copy_to_user_overflow(void)
23239 +{
23240 + WARN(1, "Buffer overflow detected!\n");
23241 +}
23242 +EXPORT_SYMBOL(copy_to_user_overflow);
23243 +
23244 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23245 +void __set_fs(mm_segment_t x)
23246 +{
23247 + switch (x.seg) {
23248 + case 0:
23249 + loadsegment(gs, 0);
23250 + break;
23251 + case TASK_SIZE_MAX:
23252 + loadsegment(gs, __USER_DS);
23253 + break;
23254 + case -1UL:
23255 + loadsegment(gs, __KERNEL_DS);
23256 + break;
23257 + default:
23258 + BUG();
23259 + }
23260 + return;
23261 +}
23262 +EXPORT_SYMBOL(__set_fs);
23263 +
23264 +void set_fs(mm_segment_t x)
23265 +{
23266 + current_thread_info()->addr_limit = x;
23267 + __set_fs(x);
23268 +}
23269 +EXPORT_SYMBOL(set_fs);
23270 +#endif
23271 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23272 index e5b130b..6690d31 100644
23273 --- a/arch/x86/lib/usercopy_64.c
23274 +++ b/arch/x86/lib/usercopy_64.c
23275 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23276 {
23277 long __d0;
23278 might_fault();
23279 +
23280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23281 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23282 + addr += PAX_USER_SHADOW_BASE;
23283 +#endif
23284 +
23285 /* no memory constraint because it doesn't change any memory gcc knows
23286 about */
23287 asm volatile(
23288 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23289 }
23290 EXPORT_SYMBOL(clear_user);
23291
23292 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23293 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23294 {
23295 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23296 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23297 - }
23298 - return len;
23299 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23300 +
23301 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23302 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23303 + to += PAX_USER_SHADOW_BASE;
23304 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23305 + from += PAX_USER_SHADOW_BASE;
23306 +#endif
23307 +
23308 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23309 + }
23310 + return len;
23311 }
23312 EXPORT_SYMBOL(copy_in_user);
23313
23314 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23315 * it is not necessary to optimize tail handling.
23316 */
23317 unsigned long
23318 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23319 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23320 {
23321 char c;
23322 unsigned zero_len;
23323 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23324 break;
23325 return len;
23326 }
23327 +
23328 +void copy_from_user_overflow(void)
23329 +{
23330 + WARN(1, "Buffer overflow detected!\n");
23331 +}
23332 +EXPORT_SYMBOL(copy_from_user_overflow);
23333 +
23334 +void copy_to_user_overflow(void)
23335 +{
23336 + WARN(1, "Buffer overflow detected!\n");
23337 +}
23338 +EXPORT_SYMBOL(copy_to_user_overflow);
23339 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23340 index 903ec1e..833f340 100644
23341 --- a/arch/x86/mm/extable.c
23342 +++ b/arch/x86/mm/extable.c
23343 @@ -6,12 +6,25 @@
23344 static inline unsigned long
23345 ex_insn_addr(const struct exception_table_entry *x)
23346 {
23347 - return (unsigned long)&x->insn + x->insn;
23348 +//printk(KERN_ERR "fixup %p insn:%x fixup:%x\n", x, x->insn, x->fixup);
23349 + unsigned long reloc = 0;
23350 +
23351 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23352 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23353 +#endif
23354 +
23355 + return (unsigned long)&x->insn + x->insn + reloc;
23356 }
23357 static inline unsigned long
23358 ex_fixup_addr(const struct exception_table_entry *x)
23359 {
23360 - return (unsigned long)&x->fixup + x->fixup;
23361 + unsigned long reloc = 0;
23362 +
23363 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23364 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23365 +#endif
23366 +
23367 + return (unsigned long)&x->fixup + x->fixup + reloc;
23368 }
23369
23370 int fixup_exception(struct pt_regs *regs)
23371 @@ -20,7 +33,7 @@ int fixup_exception(struct pt_regs *regs)
23372 unsigned long new_ip;
23373
23374 #ifdef CONFIG_PNPBIOS
23375 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23376 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23377 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23378 extern u32 pnp_bios_is_utter_crap;
23379 pnp_bios_is_utter_crap = 1;
23380 @@ -34,6 +47,7 @@ int fixup_exception(struct pt_regs *regs)
23381 #endif
23382
23383 fixup = search_exception_tables(regs->ip);
23384 +//printk(KERN_ERR "fixup %p %lx\n", fixup, regs->ip);
23385 if (fixup) {
23386 new_ip = ex_fixup_addr(fixup);
23387
23388 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23389 index 76dcd9d..e9dffde 100644
23390 --- a/arch/x86/mm/fault.c
23391 +++ b/arch/x86/mm/fault.c
23392 @@ -13,11 +13,18 @@
23393 #include <linux/perf_event.h> /* perf_sw_event */
23394 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23395 #include <linux/prefetch.h> /* prefetchw */
23396 +#include <linux/unistd.h>
23397 +#include <linux/compiler.h>
23398
23399 #include <asm/traps.h> /* dotraplinkage, ... */
23400 #include <asm/pgalloc.h> /* pgd_*(), ... */
23401 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23402 #include <asm/fixmap.h> /* VSYSCALL_START */
23403 +#include <asm/tlbflush.h>
23404 +
23405 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23406 +#include <asm/stacktrace.h>
23407 +#endif
23408
23409 /*
23410 * Page fault error code bits:
23411 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23412 int ret = 0;
23413
23414 /* kprobe_running() needs smp_processor_id() */
23415 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23416 + if (kprobes_built_in() && !user_mode(regs)) {
23417 preempt_disable();
23418 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23419 ret = 1;
23420 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23421 return !instr_lo || (instr_lo>>1) == 1;
23422 case 0x00:
23423 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23424 - if (probe_kernel_address(instr, opcode))
23425 + if (user_mode(regs)) {
23426 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23427 + return 0;
23428 + } else if (probe_kernel_address(instr, opcode))
23429 return 0;
23430
23431 *prefetch = (instr_lo == 0xF) &&
23432 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23433 while (instr < max_instr) {
23434 unsigned char opcode;
23435
23436 - if (probe_kernel_address(instr, opcode))
23437 + if (user_mode(regs)) {
23438 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23439 + break;
23440 + } else if (probe_kernel_address(instr, opcode))
23441 break;
23442
23443 instr++;
23444 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23445 force_sig_info(si_signo, &info, tsk);
23446 }
23447
23448 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23449 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23450 +#endif
23451 +
23452 +#ifdef CONFIG_PAX_EMUTRAMP
23453 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23454 +#endif
23455 +
23456 +#ifdef CONFIG_PAX_PAGEEXEC
23457 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23458 +{
23459 + pgd_t *pgd;
23460 + pud_t *pud;
23461 + pmd_t *pmd;
23462 +
23463 + pgd = pgd_offset(mm, address);
23464 + if (!pgd_present(*pgd))
23465 + return NULL;
23466 + pud = pud_offset(pgd, address);
23467 + if (!pud_present(*pud))
23468 + return NULL;
23469 + pmd = pmd_offset(pud, address);
23470 + if (!pmd_present(*pmd))
23471 + return NULL;
23472 + return pmd;
23473 +}
23474 +#endif
23475 +
23476 DEFINE_SPINLOCK(pgd_lock);
23477 LIST_HEAD(pgd_list);
23478
23479 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23480 for (address = VMALLOC_START & PMD_MASK;
23481 address >= TASK_SIZE && address < FIXADDR_TOP;
23482 address += PMD_SIZE) {
23483 +
23484 +#ifdef CONFIG_PAX_PER_CPU_PGD
23485 + unsigned long cpu;
23486 +#else
23487 struct page *page;
23488 +#endif
23489
23490 spin_lock(&pgd_lock);
23491 +
23492 +#ifdef CONFIG_PAX_PER_CPU_PGD
23493 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23494 + pgd_t *pgd = get_cpu_pgd(cpu);
23495 + pmd_t *ret;
23496 +#else
23497 list_for_each_entry(page, &pgd_list, lru) {
23498 + pgd_t *pgd = page_address(page);
23499 spinlock_t *pgt_lock;
23500 pmd_t *ret;
23501
23502 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23503 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23504
23505 spin_lock(pgt_lock);
23506 - ret = vmalloc_sync_one(page_address(page), address);
23507 +#endif
23508 +
23509 + ret = vmalloc_sync_one(pgd, address);
23510 +
23511 +#ifndef CONFIG_PAX_PER_CPU_PGD
23512 spin_unlock(pgt_lock);
23513 +#endif
23514
23515 if (!ret)
23516 break;
23517 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23518 * an interrupt in the middle of a task switch..
23519 */
23520 pgd_paddr = read_cr3();
23521 +
23522 +#ifdef CONFIG_PAX_PER_CPU_PGD
23523 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23524 +#endif
23525 +
23526 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23527 if (!pmd_k)
23528 return -1;
23529 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23530 * happen within a race in page table update. In the later
23531 * case just flush:
23532 */
23533 +
23534 +#ifdef CONFIG_PAX_PER_CPU_PGD
23535 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23536 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23537 +#else
23538 pgd = pgd_offset(current->active_mm, address);
23539 +#endif
23540 +
23541 pgd_ref = pgd_offset_k(address);
23542 if (pgd_none(*pgd_ref))
23543 return -1;
23544 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23545 static int is_errata100(struct pt_regs *regs, unsigned long address)
23546 {
23547 #ifdef CONFIG_X86_64
23548 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23549 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23550 return 1;
23551 #endif
23552 return 0;
23553 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23554 }
23555
23556 static const char nx_warning[] = KERN_CRIT
23557 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23558 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23559
23560 static void
23561 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23562 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23563 if (!oops_may_print())
23564 return;
23565
23566 - if (error_code & PF_INSTR) {
23567 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23568 unsigned int level;
23569
23570 pte_t *pte = lookup_address(address, &level);
23571
23572 if (pte && pte_present(*pte) && !pte_exec(*pte))
23573 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23574 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23575 }
23576
23577 +#ifdef CONFIG_PAX_KERNEXEC
23578 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23579 + if (current->signal->curr_ip)
23580 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23581 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23582 + else
23583 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23584 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23585 + }
23586 +#endif
23587 +
23588 printk(KERN_ALERT "BUG: unable to handle kernel ");
23589 if (address < PAGE_SIZE)
23590 printk(KERN_CONT "NULL pointer dereference");
23591 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23592 }
23593 #endif
23594
23595 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23596 + if (pax_is_fetch_fault(regs, error_code, address)) {
23597 +
23598 +#ifdef CONFIG_PAX_EMUTRAMP
23599 + switch (pax_handle_fetch_fault(regs)) {
23600 + case 2:
23601 + return;
23602 + }
23603 +#endif
23604 +
23605 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23606 + do_group_exit(SIGKILL);
23607 + }
23608 +#endif
23609 +
23610 if (unlikely(show_unhandled_signals))
23611 show_signal_msg(regs, error_code, address, tsk);
23612
23613 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23614 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23615 printk(KERN_ERR
23616 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23617 - tsk->comm, tsk->pid, address);
23618 + tsk->comm, task_pid_nr(tsk), address);
23619 code = BUS_MCEERR_AR;
23620 }
23621 #endif
23622 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23623 return 1;
23624 }
23625
23626 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23627 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23628 +{
23629 + pte_t *pte;
23630 + pmd_t *pmd;
23631 + spinlock_t *ptl;
23632 + unsigned char pte_mask;
23633 +
23634 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23635 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23636 + return 0;
23637 +
23638 + /* PaX: it's our fault, let's handle it if we can */
23639 +
23640 + /* PaX: take a look at read faults before acquiring any locks */
23641 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23642 + /* instruction fetch attempt from a protected page in user mode */
23643 + up_read(&mm->mmap_sem);
23644 +
23645 +#ifdef CONFIG_PAX_EMUTRAMP
23646 + switch (pax_handle_fetch_fault(regs)) {
23647 + case 2:
23648 + return 1;
23649 + }
23650 +#endif
23651 +
23652 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23653 + do_group_exit(SIGKILL);
23654 + }
23655 +
23656 + pmd = pax_get_pmd(mm, address);
23657 + if (unlikely(!pmd))
23658 + return 0;
23659 +
23660 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23661 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23662 + pte_unmap_unlock(pte, ptl);
23663 + return 0;
23664 + }
23665 +
23666 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23667 + /* write attempt to a protected page in user mode */
23668 + pte_unmap_unlock(pte, ptl);
23669 + return 0;
23670 + }
23671 +
23672 +#ifdef CONFIG_SMP
23673 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23674 +#else
23675 + if (likely(address > get_limit(regs->cs)))
23676 +#endif
23677 + {
23678 + set_pte(pte, pte_mkread(*pte));
23679 + __flush_tlb_one(address);
23680 + pte_unmap_unlock(pte, ptl);
23681 + up_read(&mm->mmap_sem);
23682 + return 1;
23683 + }
23684 +
23685 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23686 +
23687 + /*
23688 + * PaX: fill DTLB with user rights and retry
23689 + */
23690 + __asm__ __volatile__ (
23691 + "orb %2,(%1)\n"
23692 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23693 +/*
23694 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23695 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23696 + * page fault when examined during a TLB load attempt. this is true not only
23697 + * for PTEs holding a non-present entry but also present entries that will
23698 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23699 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23700 + * for our target pages since their PTEs are simply not in the TLBs at all.
23701 +
23702 + * the best thing in omitting it is that we gain around 15-20% speed in the
23703 + * fast path of the page fault handler and can get rid of tracing since we
23704 + * can no longer flush unintended entries.
23705 + */
23706 + "invlpg (%0)\n"
23707 +#endif
23708 + __copyuser_seg"testb $0,(%0)\n"
23709 + "xorb %3,(%1)\n"
23710 + :
23711 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23712 + : "memory", "cc");
23713 + pte_unmap_unlock(pte, ptl);
23714 + up_read(&mm->mmap_sem);
23715 + return 1;
23716 +}
23717 +#endif
23718 +
23719 /*
23720 * Handle a spurious fault caused by a stale TLB entry.
23721 *
23722 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23723 static inline int
23724 access_error(unsigned long error_code, struct vm_area_struct *vma)
23725 {
23726 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23727 + return 1;
23728 +
23729 if (error_code & PF_WRITE) {
23730 /* write, present and write, not present: */
23731 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23732 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23733 {
23734 struct vm_area_struct *vma;
23735 struct task_struct *tsk;
23736 - unsigned long address;
23737 struct mm_struct *mm;
23738 int fault;
23739 int write = error_code & PF_WRITE;
23740 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23741 (write ? FAULT_FLAG_WRITE : 0);
23742
23743 - tsk = current;
23744 - mm = tsk->mm;
23745 -
23746 /* Get the faulting address: */
23747 - address = read_cr2();
23748 + unsigned long address = read_cr2();
23749 +
23750 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23751 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23752 + if (!search_exception_tables(regs->ip)) {
23753 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23754 + bad_area_nosemaphore(regs, error_code, address);
23755 + return;
23756 + }
23757 + if (address < PAX_USER_SHADOW_BASE) {
23758 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23759 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23760 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23761 + } else
23762 + address -= PAX_USER_SHADOW_BASE;
23763 + }
23764 +#endif
23765 +
23766 + tsk = current;
23767 + mm = tsk->mm;
23768
23769 /*
23770 * Detect and handle instructions that would cause a page fault for
23771 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23772 * User-mode registers count as a user access even for any
23773 * potential system fault or CPU buglet:
23774 */
23775 - if (user_mode_vm(regs)) {
23776 + if (user_mode(regs)) {
23777 local_irq_enable();
23778 error_code |= PF_USER;
23779 } else {
23780 @@ -1132,6 +1339,11 @@ retry:
23781 might_sleep();
23782 }
23783
23784 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23785 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23786 + return;
23787 +#endif
23788 +
23789 vma = find_vma(mm, address);
23790 if (unlikely(!vma)) {
23791 bad_area(regs, error_code, address);
23792 @@ -1143,18 +1355,24 @@ retry:
23793 bad_area(regs, error_code, address);
23794 return;
23795 }
23796 - if (error_code & PF_USER) {
23797 - /*
23798 - * Accessing the stack below %sp is always a bug.
23799 - * The large cushion allows instructions like enter
23800 - * and pusha to work. ("enter $65535, $31" pushes
23801 - * 32 pointers and then decrements %sp by 65535.)
23802 - */
23803 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23804 - bad_area(regs, error_code, address);
23805 - return;
23806 - }
23807 + /*
23808 + * Accessing the stack below %sp is always a bug.
23809 + * The large cushion allows instructions like enter
23810 + * and pusha to work. ("enter $65535, $31" pushes
23811 + * 32 pointers and then decrements %sp by 65535.)
23812 + */
23813 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23814 + bad_area(regs, error_code, address);
23815 + return;
23816 }
23817 +
23818 +#ifdef CONFIG_PAX_SEGMEXEC
23819 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23820 + bad_area(regs, error_code, address);
23821 + return;
23822 + }
23823 +#endif
23824 +
23825 if (unlikely(expand_stack(vma, address))) {
23826 bad_area(regs, error_code, address);
23827 return;
23828 @@ -1209,3 +1427,292 @@ good_area:
23829
23830 up_read(&mm->mmap_sem);
23831 }
23832 +
23833 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23834 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23835 +{
23836 + struct mm_struct *mm = current->mm;
23837 + unsigned long ip = regs->ip;
23838 +
23839 + if (v8086_mode(regs))
23840 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23841 +
23842 +#ifdef CONFIG_PAX_PAGEEXEC
23843 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23844 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23845 + return true;
23846 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23847 + return true;
23848 + return false;
23849 + }
23850 +#endif
23851 +
23852 +#ifdef CONFIG_PAX_SEGMEXEC
23853 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23854 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23855 + return true;
23856 + return false;
23857 + }
23858 +#endif
23859 +
23860 + return false;
23861 +}
23862 +#endif
23863 +
23864 +#ifdef CONFIG_PAX_EMUTRAMP
23865 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23866 +{
23867 + int err;
23868 +
23869 + do { /* PaX: libffi trampoline emulation */
23870 + unsigned char mov, jmp;
23871 + unsigned int addr1, addr2;
23872 +
23873 +#ifdef CONFIG_X86_64
23874 + if ((regs->ip + 9) >> 32)
23875 + break;
23876 +#endif
23877 +
23878 + err = get_user(mov, (unsigned char __user *)regs->ip);
23879 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23880 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23881 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23882 +
23883 + if (err)
23884 + break;
23885 +
23886 + if (mov == 0xB8 && jmp == 0xE9) {
23887 + regs->ax = addr1;
23888 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23889 + return 2;
23890 + }
23891 + } while (0);
23892 +
23893 + do { /* PaX: gcc trampoline emulation #1 */
23894 + unsigned char mov1, mov2;
23895 + unsigned short jmp;
23896 + unsigned int addr1, addr2;
23897 +
23898 +#ifdef CONFIG_X86_64
23899 + if ((regs->ip + 11) >> 32)
23900 + break;
23901 +#endif
23902 +
23903 + err = get_user(mov1, (unsigned char __user *)regs->ip);
23904 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23905 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23906 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23907 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23908 +
23909 + if (err)
23910 + break;
23911 +
23912 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23913 + regs->cx = addr1;
23914 + regs->ax = addr2;
23915 + regs->ip = addr2;
23916 + return 2;
23917 + }
23918 + } while (0);
23919 +
23920 + do { /* PaX: gcc trampoline emulation #2 */
23921 + unsigned char mov, jmp;
23922 + unsigned int addr1, addr2;
23923 +
23924 +#ifdef CONFIG_X86_64
23925 + if ((regs->ip + 9) >> 32)
23926 + break;
23927 +#endif
23928 +
23929 + err = get_user(mov, (unsigned char __user *)regs->ip);
23930 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23931 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23932 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23933 +
23934 + if (err)
23935 + break;
23936 +
23937 + if (mov == 0xB9 && jmp == 0xE9) {
23938 + regs->cx = addr1;
23939 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23940 + return 2;
23941 + }
23942 + } while (0);
23943 +
23944 + return 1; /* PaX in action */
23945 +}
23946 +
23947 +#ifdef CONFIG_X86_64
23948 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23949 +{
23950 + int err;
23951 +
23952 + do { /* PaX: libffi trampoline emulation */
23953 + unsigned short mov1, mov2, jmp1;
23954 + unsigned char stcclc, jmp2;
23955 + unsigned long addr1, addr2;
23956 +
23957 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23958 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23959 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23960 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23961 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23962 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23963 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23964 +
23965 + if (err)
23966 + break;
23967 +
23968 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23969 + regs->r11 = addr1;
23970 + regs->r10 = addr2;
23971 + if (stcclc == 0xF8)
23972 + regs->flags &= ~X86_EFLAGS_CF;
23973 + else
23974 + regs->flags |= X86_EFLAGS_CF;
23975 + regs->ip = addr1;
23976 + return 2;
23977 + }
23978 + } while (0);
23979 +
23980 + do { /* PaX: gcc trampoline emulation #1 */
23981 + unsigned short mov1, mov2, jmp1;
23982 + unsigned char jmp2;
23983 + unsigned int addr1;
23984 + unsigned long addr2;
23985 +
23986 + err = get_user(mov1, (unsigned short __user *)regs->ip);
23987 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23988 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23989 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23990 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23991 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23992 +
23993 + if (err)
23994 + break;
23995 +
23996 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23997 + regs->r11 = addr1;
23998 + regs->r10 = addr2;
23999 + regs->ip = addr1;
24000 + return 2;
24001 + }
24002 + } while (0);
24003 +
24004 + do { /* PaX: gcc trampoline emulation #2 */
24005 + unsigned short mov1, mov2, jmp1;
24006 + unsigned char jmp2;
24007 + unsigned long addr1, addr2;
24008 +
24009 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24010 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24011 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24012 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24013 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24014 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24015 +
24016 + if (err)
24017 + break;
24018 +
24019 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24020 + regs->r11 = addr1;
24021 + regs->r10 = addr2;
24022 + regs->ip = addr1;
24023 + return 2;
24024 + }
24025 + } while (0);
24026 +
24027 + return 1; /* PaX in action */
24028 +}
24029 +#endif
24030 +
24031 +/*
24032 + * PaX: decide what to do with offenders (regs->ip = fault address)
24033 + *
24034 + * returns 1 when task should be killed
24035 + * 2 when gcc trampoline was detected
24036 + */
24037 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24038 +{
24039 + if (v8086_mode(regs))
24040 + return 1;
24041 +
24042 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24043 + return 1;
24044 +
24045 +#ifdef CONFIG_X86_32
24046 + return pax_handle_fetch_fault_32(regs);
24047 +#else
24048 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24049 + return pax_handle_fetch_fault_32(regs);
24050 + else
24051 + return pax_handle_fetch_fault_64(regs);
24052 +#endif
24053 +}
24054 +#endif
24055 +
24056 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24057 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24058 +{
24059 + long i;
24060 +
24061 + printk(KERN_ERR "PAX: bytes at PC: ");
24062 + for (i = 0; i < 20; i++) {
24063 + unsigned char c;
24064 + if (get_user(c, (unsigned char __force_user *)pc+i))
24065 + printk(KERN_CONT "?? ");
24066 + else
24067 + printk(KERN_CONT "%02x ", c);
24068 + }
24069 + printk("\n");
24070 +
24071 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24072 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24073 + unsigned long c;
24074 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24075 +#ifdef CONFIG_X86_32
24076 + printk(KERN_CONT "???????? ");
24077 +#else
24078 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24079 + printk(KERN_CONT "???????? ???????? ");
24080 + else
24081 + printk(KERN_CONT "???????????????? ");
24082 +#endif
24083 + } else {
24084 +#ifdef CONFIG_X86_64
24085 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24086 + printk(KERN_CONT "%08x ", (unsigned int)c);
24087 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24088 + } else
24089 +#endif
24090 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24091 + }
24092 + }
24093 + printk("\n");
24094 +}
24095 +#endif
24096 +
24097 +/**
24098 + * probe_kernel_write(): safely attempt to write to a location
24099 + * @dst: address to write to
24100 + * @src: pointer to the data that shall be written
24101 + * @size: size of the data chunk
24102 + *
24103 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24104 + * happens, handle that and return -EFAULT.
24105 + */
24106 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24107 +{
24108 + long ret;
24109 + mm_segment_t old_fs = get_fs();
24110 +
24111 + set_fs(KERNEL_DS);
24112 + pagefault_disable();
24113 + pax_open_kernel();
24114 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24115 + pax_close_kernel();
24116 + pagefault_enable();
24117 + set_fs(old_fs);
24118 +
24119 + return ret ? -EFAULT : 0;
24120 +}
24121 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24122 index dd74e46..7d26398 100644
24123 --- a/arch/x86/mm/gup.c
24124 +++ b/arch/x86/mm/gup.c
24125 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24126 addr = start;
24127 len = (unsigned long) nr_pages << PAGE_SHIFT;
24128 end = start + len;
24129 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24130 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24131 (void __user *)start, len)))
24132 return 0;
24133
24134 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24135 index 6f31ee5..8ee4164 100644
24136 --- a/arch/x86/mm/highmem_32.c
24137 +++ b/arch/x86/mm/highmem_32.c
24138 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24139 idx = type + KM_TYPE_NR*smp_processor_id();
24140 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24141 BUG_ON(!pte_none(*(kmap_pte-idx)));
24142 +
24143 + pax_open_kernel();
24144 set_pte(kmap_pte-idx, mk_pte(page, prot));
24145 + pax_close_kernel();
24146 +
24147 arch_flush_lazy_mmu_mode();
24148
24149 return (void *)vaddr;
24150 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24151 index f6679a7..8f795a3 100644
24152 --- a/arch/x86/mm/hugetlbpage.c
24153 +++ b/arch/x86/mm/hugetlbpage.c
24154 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24155 struct hstate *h = hstate_file(file);
24156 struct mm_struct *mm = current->mm;
24157 struct vm_area_struct *vma;
24158 - unsigned long start_addr;
24159 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24160 +
24161 +#ifdef CONFIG_PAX_SEGMEXEC
24162 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24163 + pax_task_size = SEGMEXEC_TASK_SIZE;
24164 +#endif
24165 +
24166 + pax_task_size -= PAGE_SIZE;
24167
24168 if (len > mm->cached_hole_size) {
24169 - start_addr = mm->free_area_cache;
24170 + start_addr = mm->free_area_cache;
24171 } else {
24172 - start_addr = TASK_UNMAPPED_BASE;
24173 - mm->cached_hole_size = 0;
24174 + start_addr = mm->mmap_base;
24175 + mm->cached_hole_size = 0;
24176 }
24177
24178 full_search:
24179 @@ -280,26 +287,27 @@ full_search:
24180
24181 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24182 /* At this point: (!vma || addr < vma->vm_end). */
24183 - if (TASK_SIZE - len < addr) {
24184 + if (pax_task_size - len < addr) {
24185 /*
24186 * Start a new search - just in case we missed
24187 * some holes.
24188 */
24189 - if (start_addr != TASK_UNMAPPED_BASE) {
24190 - start_addr = TASK_UNMAPPED_BASE;
24191 + if (start_addr != mm->mmap_base) {
24192 + start_addr = mm->mmap_base;
24193 mm->cached_hole_size = 0;
24194 goto full_search;
24195 }
24196 return -ENOMEM;
24197 }
24198 - if (!vma || addr + len <= vma->vm_start) {
24199 - mm->free_area_cache = addr + len;
24200 - return addr;
24201 - }
24202 + if (check_heap_stack_gap(vma, addr, len))
24203 + break;
24204 if (addr + mm->cached_hole_size < vma->vm_start)
24205 mm->cached_hole_size = vma->vm_start - addr;
24206 addr = ALIGN(vma->vm_end, huge_page_size(h));
24207 }
24208 +
24209 + mm->free_area_cache = addr + len;
24210 + return addr;
24211 }
24212
24213 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24214 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24215 struct mm_struct *mm = current->mm;
24216 struct vm_area_struct *vma;
24217 unsigned long base = mm->mmap_base;
24218 - unsigned long addr = addr0;
24219 + unsigned long addr;
24220 unsigned long largest_hole = mm->cached_hole_size;
24221 - unsigned long start_addr;
24222
24223 /* don't allow allocations above current base */
24224 if (mm->free_area_cache > base)
24225 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24226 largest_hole = 0;
24227 mm->free_area_cache = base;
24228 }
24229 -try_again:
24230 - start_addr = mm->free_area_cache;
24231
24232 /* make sure it can fit in the remaining address space */
24233 if (mm->free_area_cache < len)
24234 goto fail;
24235
24236 /* either no address requested or can't fit in requested address hole */
24237 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24238 + addr = mm->free_area_cache - len;
24239 do {
24240 + addr &= huge_page_mask(h);
24241 /*
24242 * Lookup failure means no vma is above this address,
24243 * i.e. return with success:
24244 @@ -340,10 +346,10 @@ try_again:
24245 if (!vma)
24246 return addr;
24247
24248 - if (addr + len <= vma->vm_start) {
24249 + if (check_heap_stack_gap(vma, addr, len)) {
24250 /* remember the address as a hint for next time */
24251 - mm->cached_hole_size = largest_hole;
24252 - return (mm->free_area_cache = addr);
24253 + mm->cached_hole_size = largest_hole;
24254 + return (mm->free_area_cache = addr);
24255 } else if (mm->free_area_cache == vma->vm_end) {
24256 /* pull free_area_cache down to the first hole */
24257 mm->free_area_cache = vma->vm_start;
24258 @@ -352,29 +358,34 @@ try_again:
24259
24260 /* remember the largest hole we saw so far */
24261 if (addr + largest_hole < vma->vm_start)
24262 - largest_hole = vma->vm_start - addr;
24263 + largest_hole = vma->vm_start - addr;
24264
24265 /* try just below the current vma->vm_start */
24266 - addr = (vma->vm_start - len) & huge_page_mask(h);
24267 - } while (len <= vma->vm_start);
24268 + addr = skip_heap_stack_gap(vma, len);
24269 + } while (!IS_ERR_VALUE(addr));
24270
24271 fail:
24272 /*
24273 - * if hint left us with no space for the requested
24274 - * mapping then try again:
24275 - */
24276 - if (start_addr != base) {
24277 - mm->free_area_cache = base;
24278 - largest_hole = 0;
24279 - goto try_again;
24280 - }
24281 - /*
24282 * A failed mmap() very likely causes application failure,
24283 * so fall back to the bottom-up function here. This scenario
24284 * can happen with large stack limits and large mmap()
24285 * allocations.
24286 */
24287 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24288 +
24289 +#ifdef CONFIG_PAX_SEGMEXEC
24290 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24291 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24292 + else
24293 +#endif
24294 +
24295 + mm->mmap_base = TASK_UNMAPPED_BASE;
24296 +
24297 +#ifdef CONFIG_PAX_RANDMMAP
24298 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24299 + mm->mmap_base += mm->delta_mmap;
24300 +#endif
24301 +
24302 + mm->free_area_cache = mm->mmap_base;
24303 mm->cached_hole_size = ~0UL;
24304 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24305 len, pgoff, flags);
24306 @@ -382,6 +393,7 @@ fail:
24307 /*
24308 * Restore the topdown base:
24309 */
24310 + mm->mmap_base = base;
24311 mm->free_area_cache = base;
24312 mm->cached_hole_size = ~0UL;
24313
24314 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24315 struct hstate *h = hstate_file(file);
24316 struct mm_struct *mm = current->mm;
24317 struct vm_area_struct *vma;
24318 + unsigned long pax_task_size = TASK_SIZE;
24319
24320 if (len & ~huge_page_mask(h))
24321 return -EINVAL;
24322 - if (len > TASK_SIZE)
24323 +
24324 +#ifdef CONFIG_PAX_SEGMEXEC
24325 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24326 + pax_task_size = SEGMEXEC_TASK_SIZE;
24327 +#endif
24328 +
24329 + pax_task_size -= PAGE_SIZE;
24330 +
24331 + if (len > pax_task_size)
24332 return -ENOMEM;
24333
24334 if (flags & MAP_FIXED) {
24335 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24336 if (addr) {
24337 addr = ALIGN(addr, huge_page_size(h));
24338 vma = find_vma(mm, addr);
24339 - if (TASK_SIZE - len >= addr &&
24340 - (!vma || addr + len <= vma->vm_start))
24341 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24342 return addr;
24343 }
24344 if (mm->get_unmapped_area == arch_get_unmapped_area)
24345 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24346 index bc4e9d8..ca4c14b 100644
24347 --- a/arch/x86/mm/init.c
24348 +++ b/arch/x86/mm/init.c
24349 @@ -16,6 +16,8 @@
24350 #include <asm/tlb.h>
24351 #include <asm/proto.h>
24352 #include <asm/dma.h> /* for MAX_DMA_PFN */
24353 +#include <asm/desc.h>
24354 +#include <asm/bios_ebda.h>
24355
24356 unsigned long __initdata pgt_buf_start;
24357 unsigned long __meminitdata pgt_buf_end;
24358 @@ -38,7 +40,7 @@ struct map_range {
24359 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24360 int use_pse, int use_gbpages)
24361 {
24362 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24363 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24364 phys_addr_t base;
24365
24366 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24367 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24368 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24369 * mmio resources as well as potential bios/acpi data regions.
24370 */
24371 +
24372 +#ifdef CONFIG_GRKERNSEC_KMEM
24373 +static unsigned int ebda_start __read_only;
24374 +static unsigned int ebda_end __read_only;
24375 +#endif
24376 +
24377 int devmem_is_allowed(unsigned long pagenr)
24378 {
24379 +#ifdef CONFIG_GRKERNSEC_KMEM
24380 + /* allow BDA */
24381 + if (!pagenr)
24382 + return 1;
24383 + /* allow EBDA */
24384 + if (pagenr >= ebda_start && pagenr < ebda_end)
24385 + return 1;
24386 +#else
24387 + if (!pagenr)
24388 + return 1;
24389 +#ifdef CONFIG_VM86
24390 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24391 + return 1;
24392 +#endif
24393 +#endif
24394 +
24395 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24396 + return 1;
24397 +#ifdef CONFIG_GRKERNSEC_KMEM
24398 + /* throw out everything else below 1MB */
24399 if (pagenr <= 256)
24400 - return 1;
24401 + return 0;
24402 +#endif
24403 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24404 return 0;
24405 if (!page_is_ram(pagenr))
24406 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24407 #endif
24408 }
24409
24410 +#ifdef CONFIG_GRKERNSEC_KMEM
24411 +static inline void gr_init_ebda(void)
24412 +{
24413 + unsigned int ebda_addr;
24414 + unsigned int ebda_size = 0;
24415 +
24416 + ebda_addr = get_bios_ebda();
24417 + if (ebda_addr) {
24418 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24419 + ebda_size <<= 10;
24420 + }
24421 + if (ebda_addr && ebda_size) {
24422 + ebda_start = ebda_addr >> PAGE_SHIFT;
24423 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24424 + } else {
24425 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24426 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24427 + }
24428 +}
24429 +#else
24430 +static inline void gr_init_ebda(void) { }
24431 +#endif
24432 +
24433 void free_initmem(void)
24434 {
24435 +#ifdef CONFIG_PAX_KERNEXEC
24436 +#ifdef CONFIG_X86_32
24437 + /* PaX: limit KERNEL_CS to actual size */
24438 + unsigned long addr, limit;
24439 + struct desc_struct d;
24440 + int cpu;
24441 +#else
24442 + pgd_t *pgd;
24443 + pud_t *pud;
24444 + pmd_t *pmd;
24445 + unsigned long addr, end;
24446 +#endif
24447 +#endif
24448 +
24449 + gr_init_ebda();
24450 +
24451 +#ifdef CONFIG_PAX_KERNEXEC
24452 +#ifdef CONFIG_X86_32
24453 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24454 + limit = (limit - 1UL) >> PAGE_SHIFT;
24455 +
24456 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24457 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24458 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24459 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24460 + }
24461 +
24462 + /* PaX: make KERNEL_CS read-only */
24463 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24464 + if (!paravirt_enabled())
24465 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24466 +/*
24467 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24468 + pgd = pgd_offset_k(addr);
24469 + pud = pud_offset(pgd, addr);
24470 + pmd = pmd_offset(pud, addr);
24471 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24472 + }
24473 +*/
24474 +#ifdef CONFIG_X86_PAE
24475 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24476 +/*
24477 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24478 + pgd = pgd_offset_k(addr);
24479 + pud = pud_offset(pgd, addr);
24480 + pmd = pmd_offset(pud, addr);
24481 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24482 + }
24483 +*/
24484 +#endif
24485 +
24486 +#ifdef CONFIG_MODULES
24487 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24488 +#endif
24489 +
24490 +#else
24491 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24492 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24493 + pgd = pgd_offset_k(addr);
24494 + pud = pud_offset(pgd, addr);
24495 + pmd = pmd_offset(pud, addr);
24496 + if (!pmd_present(*pmd))
24497 + continue;
24498 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24499 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24500 + else
24501 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24502 + }
24503 +
24504 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24505 + end = addr + KERNEL_IMAGE_SIZE;
24506 + for (; addr < end; addr += PMD_SIZE) {
24507 + pgd = pgd_offset_k(addr);
24508 + pud = pud_offset(pgd, addr);
24509 + pmd = pmd_offset(pud, addr);
24510 + if (!pmd_present(*pmd))
24511 + continue;
24512 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24513 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24514 + }
24515 +#endif
24516 +
24517 + flush_tlb_all();
24518 +#endif
24519 +
24520 free_init_pages("unused kernel memory",
24521 (unsigned long)(&__init_begin),
24522 (unsigned long)(&__init_end));
24523 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24524 index 575d86f..4987469 100644
24525 --- a/arch/x86/mm/init_32.c
24526 +++ b/arch/x86/mm/init_32.c
24527 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24528 }
24529
24530 /*
24531 - * Creates a middle page table and puts a pointer to it in the
24532 - * given global directory entry. This only returns the gd entry
24533 - * in non-PAE compilation mode, since the middle layer is folded.
24534 - */
24535 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24536 -{
24537 - pud_t *pud;
24538 - pmd_t *pmd_table;
24539 -
24540 -#ifdef CONFIG_X86_PAE
24541 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24542 - if (after_bootmem)
24543 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24544 - else
24545 - pmd_table = (pmd_t *)alloc_low_page();
24546 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24547 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24548 - pud = pud_offset(pgd, 0);
24549 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24550 -
24551 - return pmd_table;
24552 - }
24553 -#endif
24554 - pud = pud_offset(pgd, 0);
24555 - pmd_table = pmd_offset(pud, 0);
24556 -
24557 - return pmd_table;
24558 -}
24559 -
24560 -/*
24561 * Create a page table and place a pointer to it in a middle page
24562 * directory entry:
24563 */
24564 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24565 page_table = (pte_t *)alloc_low_page();
24566
24567 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24568 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24569 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24570 +#else
24571 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24572 +#endif
24573 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24574 }
24575
24576 return pte_offset_kernel(pmd, 0);
24577 }
24578
24579 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24580 +{
24581 + pud_t *pud;
24582 + pmd_t *pmd_table;
24583 +
24584 + pud = pud_offset(pgd, 0);
24585 + pmd_table = pmd_offset(pud, 0);
24586 +
24587 + return pmd_table;
24588 +}
24589 +
24590 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24591 {
24592 int pgd_idx = pgd_index(vaddr);
24593 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24594 int pgd_idx, pmd_idx;
24595 unsigned long vaddr;
24596 pgd_t *pgd;
24597 + pud_t *pud;
24598 pmd_t *pmd;
24599 pte_t *pte = NULL;
24600
24601 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24602 pgd = pgd_base + pgd_idx;
24603
24604 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24605 - pmd = one_md_table_init(pgd);
24606 - pmd = pmd + pmd_index(vaddr);
24607 + pud = pud_offset(pgd, vaddr);
24608 + pmd = pmd_offset(pud, vaddr);
24609 +
24610 +#ifdef CONFIG_X86_PAE
24611 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24612 +#endif
24613 +
24614 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24615 pmd++, pmd_idx++) {
24616 pte = page_table_kmap_check(one_page_table_init(pmd),
24617 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24618 }
24619 }
24620
24621 -static inline int is_kernel_text(unsigned long addr)
24622 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24623 {
24624 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24625 - return 1;
24626 - return 0;
24627 + if ((start > ktla_ktva((unsigned long)_etext) ||
24628 + end <= ktla_ktva((unsigned long)_stext)) &&
24629 + (start > ktla_ktva((unsigned long)_einittext) ||
24630 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24631 +
24632 +#ifdef CONFIG_ACPI_SLEEP
24633 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24634 +#endif
24635 +
24636 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24637 + return 0;
24638 + return 1;
24639 }
24640
24641 /*
24642 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24643 unsigned long last_map_addr = end;
24644 unsigned long start_pfn, end_pfn;
24645 pgd_t *pgd_base = swapper_pg_dir;
24646 - int pgd_idx, pmd_idx, pte_ofs;
24647 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24648 unsigned long pfn;
24649 pgd_t *pgd;
24650 + pud_t *pud;
24651 pmd_t *pmd;
24652 pte_t *pte;
24653 unsigned pages_2m, pages_4k;
24654 @@ -280,8 +281,13 @@ repeat:
24655 pfn = start_pfn;
24656 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24657 pgd = pgd_base + pgd_idx;
24658 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24659 - pmd = one_md_table_init(pgd);
24660 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24661 + pud = pud_offset(pgd, 0);
24662 + pmd = pmd_offset(pud, 0);
24663 +
24664 +#ifdef CONFIG_X86_PAE
24665 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24666 +#endif
24667
24668 if (pfn >= end_pfn)
24669 continue;
24670 @@ -293,14 +299,13 @@ repeat:
24671 #endif
24672 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24673 pmd++, pmd_idx++) {
24674 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24675 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24676
24677 /*
24678 * Map with big pages if possible, otherwise
24679 * create normal page tables:
24680 */
24681 if (use_pse) {
24682 - unsigned int addr2;
24683 pgprot_t prot = PAGE_KERNEL_LARGE;
24684 /*
24685 * first pass will use the same initial
24686 @@ -310,11 +315,7 @@ repeat:
24687 __pgprot(PTE_IDENT_ATTR |
24688 _PAGE_PSE);
24689
24690 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24691 - PAGE_OFFSET + PAGE_SIZE-1;
24692 -
24693 - if (is_kernel_text(addr) ||
24694 - is_kernel_text(addr2))
24695 + if (is_kernel_text(address, address + PMD_SIZE))
24696 prot = PAGE_KERNEL_LARGE_EXEC;
24697
24698 pages_2m++;
24699 @@ -331,7 +332,7 @@ repeat:
24700 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24701 pte += pte_ofs;
24702 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24703 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24704 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24705 pgprot_t prot = PAGE_KERNEL;
24706 /*
24707 * first pass will use the same initial
24708 @@ -339,7 +340,7 @@ repeat:
24709 */
24710 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24711
24712 - if (is_kernel_text(addr))
24713 + if (is_kernel_text(address, address + PAGE_SIZE))
24714 prot = PAGE_KERNEL_EXEC;
24715
24716 pages_4k++;
24717 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24718
24719 pud = pud_offset(pgd, va);
24720 pmd = pmd_offset(pud, va);
24721 - if (!pmd_present(*pmd))
24722 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24723 break;
24724
24725 pte = pte_offset_kernel(pmd, va);
24726 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24727
24728 static void __init pagetable_init(void)
24729 {
24730 - pgd_t *pgd_base = swapper_pg_dir;
24731 -
24732 - permanent_kmaps_init(pgd_base);
24733 + permanent_kmaps_init(swapper_pg_dir);
24734 }
24735
24736 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24737 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24738 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24739
24740 /* user-defined highmem size */
24741 @@ -734,6 +733,12 @@ void __init mem_init(void)
24742
24743 pci_iommu_alloc();
24744
24745 +#ifdef CONFIG_PAX_PER_CPU_PGD
24746 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24747 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24748 + KERNEL_PGD_PTRS);
24749 +#endif
24750 +
24751 #ifdef CONFIG_FLATMEM
24752 BUG_ON(!mem_map);
24753 #endif
24754 @@ -760,7 +765,7 @@ void __init mem_init(void)
24755 reservedpages++;
24756
24757 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24758 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24759 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24760 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24761
24762 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24763 @@ -801,10 +806,10 @@ void __init mem_init(void)
24764 ((unsigned long)&__init_end -
24765 (unsigned long)&__init_begin) >> 10,
24766
24767 - (unsigned long)&_etext, (unsigned long)&_edata,
24768 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24769 + (unsigned long)&_sdata, (unsigned long)&_edata,
24770 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24771
24772 - (unsigned long)&_text, (unsigned long)&_etext,
24773 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24774 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24775
24776 /*
24777 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24778 if (!kernel_set_to_readonly)
24779 return;
24780
24781 + start = ktla_ktva(start);
24782 pr_debug("Set kernel text: %lx - %lx for read write\n",
24783 start, start+size);
24784
24785 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24786 if (!kernel_set_to_readonly)
24787 return;
24788
24789 + start = ktla_ktva(start);
24790 pr_debug("Set kernel text: %lx - %lx for read only\n",
24791 start, start+size);
24792
24793 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24794 unsigned long start = PFN_ALIGN(_text);
24795 unsigned long size = PFN_ALIGN(_etext) - start;
24796
24797 + start = ktla_ktva(start);
24798 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24799 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24800 size >> 10);
24801 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24802 index 2b6b4a3..c17210d 100644
24803 --- a/arch/x86/mm/init_64.c
24804 +++ b/arch/x86/mm/init_64.c
24805 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24806 * around without checking the pgd every time.
24807 */
24808
24809 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24810 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24811 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24812
24813 int force_personality32;
24814 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24815
24816 for (address = start; address <= end; address += PGDIR_SIZE) {
24817 const pgd_t *pgd_ref = pgd_offset_k(address);
24818 +
24819 +#ifdef CONFIG_PAX_PER_CPU_PGD
24820 + unsigned long cpu;
24821 +#else
24822 struct page *page;
24823 +#endif
24824
24825 if (pgd_none(*pgd_ref))
24826 continue;
24827
24828 spin_lock(&pgd_lock);
24829 +
24830 +#ifdef CONFIG_PAX_PER_CPU_PGD
24831 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24832 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24833 +#else
24834 list_for_each_entry(page, &pgd_list, lru) {
24835 pgd_t *pgd;
24836 spinlock_t *pgt_lock;
24837 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24838 /* the pgt_lock only for Xen */
24839 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24840 spin_lock(pgt_lock);
24841 +#endif
24842
24843 if (pgd_none(*pgd))
24844 set_pgd(pgd, *pgd_ref);
24845 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24846 BUG_ON(pgd_page_vaddr(*pgd)
24847 != pgd_page_vaddr(*pgd_ref));
24848
24849 +#ifndef CONFIG_PAX_PER_CPU_PGD
24850 spin_unlock(pgt_lock);
24851 +#endif
24852 +
24853 }
24854 spin_unlock(&pgd_lock);
24855 }
24856 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24857 {
24858 if (pgd_none(*pgd)) {
24859 pud_t *pud = (pud_t *)spp_getpage();
24860 - pgd_populate(&init_mm, pgd, pud);
24861 + pgd_populate_kernel(&init_mm, pgd, pud);
24862 if (pud != pud_offset(pgd, 0))
24863 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24864 pud, pud_offset(pgd, 0));
24865 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24866 {
24867 if (pud_none(*pud)) {
24868 pmd_t *pmd = (pmd_t *) spp_getpage();
24869 - pud_populate(&init_mm, pud, pmd);
24870 + pud_populate_kernel(&init_mm, pud, pmd);
24871 if (pmd != pmd_offset(pud, 0))
24872 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24873 pmd, pmd_offset(pud, 0));
24874 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24875 pmd = fill_pmd(pud, vaddr);
24876 pte = fill_pte(pmd, vaddr);
24877
24878 + pax_open_kernel();
24879 set_pte(pte, new_pte);
24880 + pax_close_kernel();
24881
24882 /*
24883 * It's enough to flush this one mapping.
24884 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24885 pgd = pgd_offset_k((unsigned long)__va(phys));
24886 if (pgd_none(*pgd)) {
24887 pud = (pud_t *) spp_getpage();
24888 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24889 - _PAGE_USER));
24890 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24891 }
24892 pud = pud_offset(pgd, (unsigned long)__va(phys));
24893 if (pud_none(*pud)) {
24894 pmd = (pmd_t *) spp_getpage();
24895 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24896 - _PAGE_USER));
24897 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24898 }
24899 pmd = pmd_offset(pud, phys);
24900 BUG_ON(!pmd_none(*pmd));
24901 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24902 if (pfn >= pgt_buf_top)
24903 panic("alloc_low_page: ran out of memory");
24904
24905 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24906 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24907 clear_page(adr);
24908 *phys = pfn * PAGE_SIZE;
24909 return adr;
24910 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24911
24912 phys = __pa(virt);
24913 left = phys & (PAGE_SIZE - 1);
24914 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24915 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24916 adr = (void *)(((unsigned long)adr) | left);
24917
24918 return adr;
24919 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24920 unmap_low_page(pmd);
24921
24922 spin_lock(&init_mm.page_table_lock);
24923 - pud_populate(&init_mm, pud, __va(pmd_phys));
24924 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24925 spin_unlock(&init_mm.page_table_lock);
24926 }
24927 __flush_tlb_all();
24928 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24929 unmap_low_page(pud);
24930
24931 spin_lock(&init_mm.page_table_lock);
24932 - pgd_populate(&init_mm, pgd, __va(pud_phys));
24933 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24934 spin_unlock(&init_mm.page_table_lock);
24935 pgd_changed = true;
24936 }
24937 @@ -686,6 +700,12 @@ void __init mem_init(void)
24938
24939 pci_iommu_alloc();
24940
24941 +#ifdef CONFIG_PAX_PER_CPU_PGD
24942 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24943 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24944 + KERNEL_PGD_PTRS);
24945 +#endif
24946 +
24947 /* clear_bss() already clear the empty_zero_page */
24948
24949 reservedpages = 0;
24950 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
24951 static struct vm_area_struct gate_vma = {
24952 .vm_start = VSYSCALL_START,
24953 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24954 - .vm_page_prot = PAGE_READONLY_EXEC,
24955 - .vm_flags = VM_READ | VM_EXEC
24956 + .vm_page_prot = PAGE_READONLY,
24957 + .vm_flags = VM_READ
24958 };
24959
24960 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24961 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
24962
24963 const char *arch_vma_name(struct vm_area_struct *vma)
24964 {
24965 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24966 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24967 return "[vdso]";
24968 if (vma == &gate_vma)
24969 return "[vsyscall]";
24970 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24971 index 7b179b4..6bd1777 100644
24972 --- a/arch/x86/mm/iomap_32.c
24973 +++ b/arch/x86/mm/iomap_32.c
24974 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24975 type = kmap_atomic_idx_push();
24976 idx = type + KM_TYPE_NR * smp_processor_id();
24977 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24978 +
24979 + pax_open_kernel();
24980 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24981 + pax_close_kernel();
24982 +
24983 arch_flush_lazy_mmu_mode();
24984
24985 return (void *)vaddr;
24986 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24987 index 78fe3f1..8293b6f 100644
24988 --- a/arch/x86/mm/ioremap.c
24989 +++ b/arch/x86/mm/ioremap.c
24990 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24991 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24992 int is_ram = page_is_ram(pfn);
24993
24994 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24995 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24996 return NULL;
24997 WARN_ON_ONCE(is_ram);
24998 }
24999 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25000
25001 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25002 if (page_is_ram(start >> PAGE_SHIFT))
25003 +#ifdef CONFIG_HIGHMEM
25004 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25005 +#endif
25006 return __va(phys);
25007
25008 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25009 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25010 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25011
25012 static __initdata int after_paging_init;
25013 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25014 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25015
25016 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25017 {
25018 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25019 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25020
25021 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25022 - memset(bm_pte, 0, sizeof(bm_pte));
25023 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25024 + pmd_populate_user(&init_mm, pmd, bm_pte);
25025
25026 /*
25027 * The boot-ioremap range spans multiple pmds, for which
25028 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25029 index d87dd6d..bf3fa66 100644
25030 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25031 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25032 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25033 * memory (e.g. tracked pages)? For now, we need this to avoid
25034 * invoking kmemcheck for PnP BIOS calls.
25035 */
25036 - if (regs->flags & X86_VM_MASK)
25037 + if (v8086_mode(regs))
25038 return false;
25039 - if (regs->cs != __KERNEL_CS)
25040 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25041 return false;
25042
25043 pte = kmemcheck_pte_lookup(address);
25044 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25045 index 845df68..1d8d29f 100644
25046 --- a/arch/x86/mm/mmap.c
25047 +++ b/arch/x86/mm/mmap.c
25048 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25049 * Leave an at least ~128 MB hole with possible stack randomization.
25050 */
25051 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25052 -#define MAX_GAP (TASK_SIZE/6*5)
25053 +#define MAX_GAP (pax_task_size/6*5)
25054
25055 static int mmap_is_legacy(void)
25056 {
25057 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25058 return rnd << PAGE_SHIFT;
25059 }
25060
25061 -static unsigned long mmap_base(void)
25062 +static unsigned long mmap_base(struct mm_struct *mm)
25063 {
25064 unsigned long gap = rlimit(RLIMIT_STACK);
25065 + unsigned long pax_task_size = TASK_SIZE;
25066 +
25067 +#ifdef CONFIG_PAX_SEGMEXEC
25068 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25069 + pax_task_size = SEGMEXEC_TASK_SIZE;
25070 +#endif
25071
25072 if (gap < MIN_GAP)
25073 gap = MIN_GAP;
25074 else if (gap > MAX_GAP)
25075 gap = MAX_GAP;
25076
25077 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25078 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25079 }
25080
25081 /*
25082 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25083 * does, but not when emulating X86_32
25084 */
25085 -static unsigned long mmap_legacy_base(void)
25086 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25087 {
25088 - if (mmap_is_ia32())
25089 + if (mmap_is_ia32()) {
25090 +
25091 +#ifdef CONFIG_PAX_SEGMEXEC
25092 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25093 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25094 + else
25095 +#endif
25096 +
25097 return TASK_UNMAPPED_BASE;
25098 - else
25099 + } else
25100 return TASK_UNMAPPED_BASE + mmap_rnd();
25101 }
25102
25103 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25104 void arch_pick_mmap_layout(struct mm_struct *mm)
25105 {
25106 if (mmap_is_legacy()) {
25107 - mm->mmap_base = mmap_legacy_base();
25108 + mm->mmap_base = mmap_legacy_base(mm);
25109 +
25110 +#ifdef CONFIG_PAX_RANDMMAP
25111 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25112 + mm->mmap_base += mm->delta_mmap;
25113 +#endif
25114 +
25115 mm->get_unmapped_area = arch_get_unmapped_area;
25116 mm->unmap_area = arch_unmap_area;
25117 } else {
25118 - mm->mmap_base = mmap_base();
25119 + mm->mmap_base = mmap_base(mm);
25120 +
25121 +#ifdef CONFIG_PAX_RANDMMAP
25122 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25123 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25124 +#endif
25125 +
25126 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25127 mm->unmap_area = arch_unmap_area_topdown;
25128 }
25129 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25130 index dc0b727..dc9d71a 100644
25131 --- a/arch/x86/mm/mmio-mod.c
25132 +++ b/arch/x86/mm/mmio-mod.c
25133 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25134 break;
25135 default:
25136 {
25137 - unsigned char *ip = (unsigned char *)instptr;
25138 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25139 my_trace->opcode = MMIO_UNKNOWN_OP;
25140 my_trace->width = 0;
25141 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25142 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25143 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25144 void __iomem *addr)
25145 {
25146 - static atomic_t next_id;
25147 + static atomic_unchecked_t next_id;
25148 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25149 /* These are page-unaligned. */
25150 struct mmiotrace_map map = {
25151 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25152 .private = trace
25153 },
25154 .phys = offset,
25155 - .id = atomic_inc_return(&next_id)
25156 + .id = atomic_inc_return_unchecked(&next_id)
25157 };
25158 map.map_id = trace->id;
25159
25160 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25161 index b008656..773eac2 100644
25162 --- a/arch/x86/mm/pageattr-test.c
25163 +++ b/arch/x86/mm/pageattr-test.c
25164 @@ -36,7 +36,7 @@ enum {
25165
25166 static int pte_testbit(pte_t pte)
25167 {
25168 - return pte_flags(pte) & _PAGE_UNUSED1;
25169 + return pte_flags(pte) & _PAGE_CPA_TEST;
25170 }
25171
25172 struct split_state {
25173 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25174 index a718e0d..45efc32 100644
25175 --- a/arch/x86/mm/pageattr.c
25176 +++ b/arch/x86/mm/pageattr.c
25177 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25178 */
25179 #ifdef CONFIG_PCI_BIOS
25180 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25181 - pgprot_val(forbidden) |= _PAGE_NX;
25182 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25183 #endif
25184
25185 /*
25186 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25187 * Does not cover __inittext since that is gone later on. On
25188 * 64bit we do not enforce !NX on the low mapping
25189 */
25190 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25191 - pgprot_val(forbidden) |= _PAGE_NX;
25192 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25193 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25194
25195 +#ifdef CONFIG_DEBUG_RODATA
25196 /*
25197 * The .rodata section needs to be read-only. Using the pfn
25198 * catches all aliases.
25199 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25200 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25201 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25202 pgprot_val(forbidden) |= _PAGE_RW;
25203 +#endif
25204
25205 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25206 /*
25207 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25208 }
25209 #endif
25210
25211 +#ifdef CONFIG_PAX_KERNEXEC
25212 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25213 + pgprot_val(forbidden) |= _PAGE_RW;
25214 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25215 + }
25216 +#endif
25217 +
25218 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25219
25220 return prot;
25221 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25222 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25223 {
25224 /* change init_mm */
25225 + pax_open_kernel();
25226 set_pte_atomic(kpte, pte);
25227 +
25228 #ifdef CONFIG_X86_32
25229 if (!SHARED_KERNEL_PMD) {
25230 +
25231 +#ifdef CONFIG_PAX_PER_CPU_PGD
25232 + unsigned long cpu;
25233 +#else
25234 struct page *page;
25235 +#endif
25236
25237 +#ifdef CONFIG_PAX_PER_CPU_PGD
25238 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25239 + pgd_t *pgd = get_cpu_pgd(cpu);
25240 +#else
25241 list_for_each_entry(page, &pgd_list, lru) {
25242 - pgd_t *pgd;
25243 + pgd_t *pgd = (pgd_t *)page_address(page);
25244 +#endif
25245 +
25246 pud_t *pud;
25247 pmd_t *pmd;
25248
25249 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25250 + pgd += pgd_index(address);
25251 pud = pud_offset(pgd, address);
25252 pmd = pmd_offset(pud, address);
25253 set_pte_atomic((pte_t *)pmd, pte);
25254 }
25255 }
25256 #endif
25257 + pax_close_kernel();
25258 }
25259
25260 static int
25261 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25262 index 3d68ef6..7f69136 100644
25263 --- a/arch/x86/mm/pat.c
25264 +++ b/arch/x86/mm/pat.c
25265 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25266
25267 if (!entry) {
25268 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25269 - current->comm, current->pid, start, end - 1);
25270 + current->comm, task_pid_nr(current), start, end - 1);
25271 return -EINVAL;
25272 }
25273
25274 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25275
25276 while (cursor < to) {
25277 if (!devmem_is_allowed(pfn)) {
25278 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25279 - current->comm, from, to - 1);
25280 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25281 + current->comm, from, to - 1, cursor);
25282 return 0;
25283 }
25284 cursor += PAGE_SIZE;
25285 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25286 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25287 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25288 "for [mem %#010Lx-%#010Lx]\n",
25289 - current->comm, current->pid,
25290 + current->comm, task_pid_nr(current),
25291 cattr_name(flags),
25292 base, (unsigned long long)(base + size-1));
25293 return -EINVAL;
25294 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25295 flags = lookup_memtype(paddr);
25296 if (want_flags != flags) {
25297 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25298 - current->comm, current->pid,
25299 + current->comm, task_pid_nr(current),
25300 cattr_name(want_flags),
25301 (unsigned long long)paddr,
25302 (unsigned long long)(paddr + size - 1),
25303 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25304 free_memtype(paddr, paddr + size);
25305 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25306 " for [mem %#010Lx-%#010Lx], got %s\n",
25307 - current->comm, current->pid,
25308 + current->comm, task_pid_nr(current),
25309 cattr_name(want_flags),
25310 (unsigned long long)paddr,
25311 (unsigned long long)(paddr + size - 1),
25312 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25313 index 9f0614d..92ae64a 100644
25314 --- a/arch/x86/mm/pf_in.c
25315 +++ b/arch/x86/mm/pf_in.c
25316 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25317 int i;
25318 enum reason_type rv = OTHERS;
25319
25320 - p = (unsigned char *)ins_addr;
25321 + p = (unsigned char *)ktla_ktva(ins_addr);
25322 p += skip_prefix(p, &prf);
25323 p += get_opcode(p, &opcode);
25324
25325 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25326 struct prefix_bits prf;
25327 int i;
25328
25329 - p = (unsigned char *)ins_addr;
25330 + p = (unsigned char *)ktla_ktva(ins_addr);
25331 p += skip_prefix(p, &prf);
25332 p += get_opcode(p, &opcode);
25333
25334 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25335 struct prefix_bits prf;
25336 int i;
25337
25338 - p = (unsigned char *)ins_addr;
25339 + p = (unsigned char *)ktla_ktva(ins_addr);
25340 p += skip_prefix(p, &prf);
25341 p += get_opcode(p, &opcode);
25342
25343 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25344 struct prefix_bits prf;
25345 int i;
25346
25347 - p = (unsigned char *)ins_addr;
25348 + p = (unsigned char *)ktla_ktva(ins_addr);
25349 p += skip_prefix(p, &prf);
25350 p += get_opcode(p, &opcode);
25351 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25352 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25353 struct prefix_bits prf;
25354 int i;
25355
25356 - p = (unsigned char *)ins_addr;
25357 + p = (unsigned char *)ktla_ktva(ins_addr);
25358 p += skip_prefix(p, &prf);
25359 p += get_opcode(p, &opcode);
25360 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25361 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25362 index 8573b83..4f3ed7e 100644
25363 --- a/arch/x86/mm/pgtable.c
25364 +++ b/arch/x86/mm/pgtable.c
25365 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25366 list_del(&page->lru);
25367 }
25368
25369 -#define UNSHARED_PTRS_PER_PGD \
25370 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25371 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25372 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25373
25374 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25375 +{
25376 + unsigned int count = USER_PGD_PTRS;
25377
25378 + while (count--)
25379 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25380 +}
25381 +#endif
25382 +
25383 +#ifdef CONFIG_PAX_PER_CPU_PGD
25384 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25385 +{
25386 + unsigned int count = USER_PGD_PTRS;
25387 +
25388 + while (count--) {
25389 + pgd_t pgd;
25390 +
25391 +#ifdef CONFIG_X86_64
25392 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25393 +#else
25394 + pgd = *src++;
25395 +#endif
25396 +
25397 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25398 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25399 +#endif
25400 +
25401 + *dst++ = pgd;
25402 + }
25403 +
25404 +}
25405 +#endif
25406 +
25407 +#ifdef CONFIG_X86_64
25408 +#define pxd_t pud_t
25409 +#define pyd_t pgd_t
25410 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25411 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25412 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25413 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25414 +#define PYD_SIZE PGDIR_SIZE
25415 +#else
25416 +#define pxd_t pmd_t
25417 +#define pyd_t pud_t
25418 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25419 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25420 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25421 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25422 +#define PYD_SIZE PUD_SIZE
25423 +#endif
25424 +
25425 +#ifdef CONFIG_PAX_PER_CPU_PGD
25426 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25427 +static inline void pgd_dtor(pgd_t *pgd) {}
25428 +#else
25429 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25430 {
25431 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25432 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25433 pgd_list_del(pgd);
25434 spin_unlock(&pgd_lock);
25435 }
25436 +#endif
25437
25438 /*
25439 * List of all pgd's needed for non-PAE so it can invalidate entries
25440 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25441 * -- wli
25442 */
25443
25444 -#ifdef CONFIG_X86_PAE
25445 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25446 /*
25447 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25448 * updating the top-level pagetable entries to guarantee the
25449 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25450 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25451 * and initialize the kernel pmds here.
25452 */
25453 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25454 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25455
25456 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25457 {
25458 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25459 */
25460 flush_tlb_mm(mm);
25461 }
25462 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25463 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25464 #else /* !CONFIG_X86_PAE */
25465
25466 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25467 -#define PREALLOCATED_PMDS 0
25468 +#define PREALLOCATED_PXDS 0
25469
25470 #endif /* CONFIG_X86_PAE */
25471
25472 -static void free_pmds(pmd_t *pmds[])
25473 +static void free_pxds(pxd_t *pxds[])
25474 {
25475 int i;
25476
25477 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25478 - if (pmds[i])
25479 - free_page((unsigned long)pmds[i]);
25480 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25481 + if (pxds[i])
25482 + free_page((unsigned long)pxds[i]);
25483 }
25484
25485 -static int preallocate_pmds(pmd_t *pmds[])
25486 +static int preallocate_pxds(pxd_t *pxds[])
25487 {
25488 int i;
25489 bool failed = false;
25490
25491 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25492 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25493 - if (pmd == NULL)
25494 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25495 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25496 + if (pxd == NULL)
25497 failed = true;
25498 - pmds[i] = pmd;
25499 + pxds[i] = pxd;
25500 }
25501
25502 if (failed) {
25503 - free_pmds(pmds);
25504 + free_pxds(pxds);
25505 return -ENOMEM;
25506 }
25507
25508 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25509 * preallocate which never got a corresponding vma will need to be
25510 * freed manually.
25511 */
25512 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25513 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25514 {
25515 int i;
25516
25517 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25518 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25519 pgd_t pgd = pgdp[i];
25520
25521 if (pgd_val(pgd) != 0) {
25522 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25523 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25524
25525 - pgdp[i] = native_make_pgd(0);
25526 + set_pgd(pgdp + i, native_make_pgd(0));
25527
25528 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25529 - pmd_free(mm, pmd);
25530 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25531 + pxd_free(mm, pxd);
25532 }
25533 }
25534 }
25535
25536 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25537 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25538 {
25539 - pud_t *pud;
25540 + pyd_t *pyd;
25541 unsigned long addr;
25542 int i;
25543
25544 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25545 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25546 return;
25547
25548 - pud = pud_offset(pgd, 0);
25549 +#ifdef CONFIG_X86_64
25550 + pyd = pyd_offset(mm, 0L);
25551 +#else
25552 + pyd = pyd_offset(pgd, 0L);
25553 +#endif
25554
25555 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25556 - i++, pud++, addr += PUD_SIZE) {
25557 - pmd_t *pmd = pmds[i];
25558 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25559 + i++, pyd++, addr += PYD_SIZE) {
25560 + pxd_t *pxd = pxds[i];
25561
25562 if (i >= KERNEL_PGD_BOUNDARY)
25563 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25564 - sizeof(pmd_t) * PTRS_PER_PMD);
25565 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25566 + sizeof(pxd_t) * PTRS_PER_PMD);
25567
25568 - pud_populate(mm, pud, pmd);
25569 + pyd_populate(mm, pyd, pxd);
25570 }
25571 }
25572
25573 pgd_t *pgd_alloc(struct mm_struct *mm)
25574 {
25575 pgd_t *pgd;
25576 - pmd_t *pmds[PREALLOCATED_PMDS];
25577 + pxd_t *pxds[PREALLOCATED_PXDS];
25578
25579 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25580
25581 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25582
25583 mm->pgd = pgd;
25584
25585 - if (preallocate_pmds(pmds) != 0)
25586 + if (preallocate_pxds(pxds) != 0)
25587 goto out_free_pgd;
25588
25589 if (paravirt_pgd_alloc(mm) != 0)
25590 - goto out_free_pmds;
25591 + goto out_free_pxds;
25592
25593 /*
25594 * Make sure that pre-populating the pmds is atomic with
25595 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25596 spin_lock(&pgd_lock);
25597
25598 pgd_ctor(mm, pgd);
25599 - pgd_prepopulate_pmd(mm, pgd, pmds);
25600 + pgd_prepopulate_pxd(mm, pgd, pxds);
25601
25602 spin_unlock(&pgd_lock);
25603
25604 return pgd;
25605
25606 -out_free_pmds:
25607 - free_pmds(pmds);
25608 +out_free_pxds:
25609 + free_pxds(pxds);
25610 out_free_pgd:
25611 free_page((unsigned long)pgd);
25612 out:
25613 @@ -295,7 +356,7 @@ out:
25614
25615 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25616 {
25617 - pgd_mop_up_pmds(mm, pgd);
25618 + pgd_mop_up_pxds(mm, pgd);
25619 pgd_dtor(pgd);
25620 paravirt_pgd_free(mm, pgd);
25621 free_page((unsigned long)pgd);
25622 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25623 index a69bcb8..19068ab 100644
25624 --- a/arch/x86/mm/pgtable_32.c
25625 +++ b/arch/x86/mm/pgtable_32.c
25626 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25627 return;
25628 }
25629 pte = pte_offset_kernel(pmd, vaddr);
25630 +
25631 + pax_open_kernel();
25632 if (pte_val(pteval))
25633 set_pte_at(&init_mm, vaddr, pte, pteval);
25634 else
25635 pte_clear(&init_mm, vaddr, pte);
25636 + pax_close_kernel();
25637
25638 /*
25639 * It's enough to flush this one mapping.
25640 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25641 index 410531d..0f16030 100644
25642 --- a/arch/x86/mm/setup_nx.c
25643 +++ b/arch/x86/mm/setup_nx.c
25644 @@ -5,8 +5,10 @@
25645 #include <asm/pgtable.h>
25646 #include <asm/proto.h>
25647
25648 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25649 static int disable_nx __cpuinitdata;
25650
25651 +#ifndef CONFIG_PAX_PAGEEXEC
25652 /*
25653 * noexec = on|off
25654 *
25655 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25656 return 0;
25657 }
25658 early_param("noexec", noexec_setup);
25659 +#endif
25660 +
25661 +#endif
25662
25663 void __cpuinit x86_configure_nx(void)
25664 {
25665 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25666 if (cpu_has_nx && !disable_nx)
25667 __supported_pte_mask |= _PAGE_NX;
25668 else
25669 +#endif
25670 __supported_pte_mask &= ~_PAGE_NX;
25671 }
25672
25673 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25674 index 5e57e11..64874249 100644
25675 --- a/arch/x86/mm/tlb.c
25676 +++ b/arch/x86/mm/tlb.c
25677 @@ -66,7 +66,11 @@ void leave_mm(int cpu)
25678 BUG();
25679 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25680 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25681 +
25682 +#ifndef CONFIG_PAX_PER_CPU_PGD
25683 load_cr3(swapper_pg_dir);
25684 +#endif
25685 +
25686 }
25687 }
25688 EXPORT_SYMBOL_GPL(leave_mm);
25689 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25690 index 877b9a1..a8ecf42 100644
25691 --- a/arch/x86/net/bpf_jit.S
25692 +++ b/arch/x86/net/bpf_jit.S
25693 @@ -9,6 +9,7 @@
25694 */
25695 #include <linux/linkage.h>
25696 #include <asm/dwarf2.h>
25697 +#include <asm/alternative-asm.h>
25698
25699 /*
25700 * Calling convention :
25701 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25702 jle bpf_slow_path_word
25703 mov (SKBDATA,%rsi),%eax
25704 bswap %eax /* ntohl() */
25705 + pax_force_retaddr
25706 ret
25707
25708 sk_load_half:
25709 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25710 jle bpf_slow_path_half
25711 movzwl (SKBDATA,%rsi),%eax
25712 rol $8,%ax # ntohs()
25713 + pax_force_retaddr
25714 ret
25715
25716 sk_load_byte:
25717 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25718 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25719 jle bpf_slow_path_byte
25720 movzbl (SKBDATA,%rsi),%eax
25721 + pax_force_retaddr
25722 ret
25723
25724 /**
25725 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25726 movzbl (SKBDATA,%rsi),%ebx
25727 and $15,%bl
25728 shl $2,%bl
25729 + pax_force_retaddr
25730 ret
25731
25732 /* rsi contains offset and can be scratched */
25733 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25734 js bpf_error
25735 mov -12(%rbp),%eax
25736 bswap %eax
25737 + pax_force_retaddr
25738 ret
25739
25740 bpf_slow_path_half:
25741 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25742 mov -12(%rbp),%ax
25743 rol $8,%ax
25744 movzwl %ax,%eax
25745 + pax_force_retaddr
25746 ret
25747
25748 bpf_slow_path_byte:
25749 bpf_slow_path_common(1)
25750 js bpf_error
25751 movzbl -12(%rbp),%eax
25752 + pax_force_retaddr
25753 ret
25754
25755 bpf_slow_path_byte_msh:
25756 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25757 and $15,%al
25758 shl $2,%al
25759 xchg %eax,%ebx
25760 + pax_force_retaddr
25761 ret
25762
25763 #define sk_negative_common(SIZE) \
25764 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25765 sk_negative_common(4)
25766 mov (%rax), %eax
25767 bswap %eax
25768 + pax_force_retaddr
25769 ret
25770
25771 bpf_slow_path_half_neg:
25772 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25773 mov (%rax),%ax
25774 rol $8,%ax
25775 movzwl %ax,%eax
25776 + pax_force_retaddr
25777 ret
25778
25779 bpf_slow_path_byte_neg:
25780 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25781 .globl sk_load_byte_negative_offset
25782 sk_negative_common(1)
25783 movzbl (%rax), %eax
25784 + pax_force_retaddr
25785 ret
25786
25787 bpf_slow_path_byte_msh_neg:
25788 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25789 and $15,%al
25790 shl $2,%al
25791 xchg %eax,%ebx
25792 + pax_force_retaddr
25793 ret
25794
25795 bpf_error:
25796 @@ -197,4 +210,5 @@ bpf_error:
25797 xor %eax,%eax
25798 mov -8(%rbp),%rbx
25799 leaveq
25800 + pax_force_retaddr
25801 ret
25802 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25803 index 0597f95..a12c36e 100644
25804 --- a/arch/x86/net/bpf_jit_comp.c
25805 +++ b/arch/x86/net/bpf_jit_comp.c
25806 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25807 set_fs(old_fs);
25808 }
25809
25810 +struct bpf_jit_work {
25811 + struct work_struct work;
25812 + void *image;
25813 +};
25814 +
25815 #define CHOOSE_LOAD_FUNC(K, func) \
25816 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25817
25818 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25819 if (addrs == NULL)
25820 return;
25821
25822 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25823 + if (!fp->work)
25824 + goto out;
25825 +
25826 /* Before first pass, make a rough estimation of addrs[]
25827 * each bpf instruction is translated to less than 64 bytes
25828 */
25829 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25830 break;
25831 default:
25832 /* hmm, too complex filter, give up with jit compiler */
25833 - goto out;
25834 + goto error;
25835 }
25836 ilen = prog - temp;
25837 if (image) {
25838 if (unlikely(proglen + ilen > oldproglen)) {
25839 pr_err("bpb_jit_compile fatal error\n");
25840 - kfree(addrs);
25841 - module_free(NULL, image);
25842 - return;
25843 + module_free_exec(NULL, image);
25844 + goto error;
25845 }
25846 + pax_open_kernel();
25847 memcpy(image + proglen, temp, ilen);
25848 + pax_close_kernel();
25849 }
25850 proglen += ilen;
25851 addrs[i] = proglen;
25852 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25853 break;
25854 }
25855 if (proglen == oldproglen) {
25856 - image = module_alloc(max_t(unsigned int,
25857 - proglen,
25858 - sizeof(struct work_struct)));
25859 + image = module_alloc_exec(proglen);
25860 if (!image)
25861 - goto out;
25862 + goto error;
25863 }
25864 oldproglen = proglen;
25865 }
25866 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25867 bpf_flush_icache(image, image + proglen);
25868
25869 fp->bpf_func = (void *)image;
25870 - }
25871 + } else
25872 +error:
25873 + kfree(fp->work);
25874 +
25875 out:
25876 kfree(addrs);
25877 return;
25878 @@ -648,18 +659,20 @@ out:
25879
25880 static void jit_free_defer(struct work_struct *arg)
25881 {
25882 - module_free(NULL, arg);
25883 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25884 + kfree(arg);
25885 }
25886
25887 /* run from softirq, we must use a work_struct to call
25888 - * module_free() from process context
25889 + * module_free_exec() from process context
25890 */
25891 void bpf_jit_free(struct sk_filter *fp)
25892 {
25893 if (fp->bpf_func != sk_run_filter) {
25894 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
25895 + struct work_struct *work = &fp->work->work;
25896
25897 INIT_WORK(work, jit_free_defer);
25898 + fp->work->image = fp->bpf_func;
25899 schedule_work(work);
25900 }
25901 }
25902 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25903 index d6aa6e8..266395a 100644
25904 --- a/arch/x86/oprofile/backtrace.c
25905 +++ b/arch/x86/oprofile/backtrace.c
25906 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25907 struct stack_frame_ia32 *fp;
25908 unsigned long bytes;
25909
25910 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25911 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25912 if (bytes != sizeof(bufhead))
25913 return NULL;
25914
25915 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25916 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25917
25918 oprofile_add_trace(bufhead[0].return_address);
25919
25920 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25921 struct stack_frame bufhead[2];
25922 unsigned long bytes;
25923
25924 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25925 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25926 if (bytes != sizeof(bufhead))
25927 return NULL;
25928
25929 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25930 {
25931 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25932
25933 - if (!user_mode_vm(regs)) {
25934 + if (!user_mode(regs)) {
25935 unsigned long stack = kernel_stack_pointer(regs);
25936 if (depth)
25937 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25938 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25939 index 140942f..8a5cc55 100644
25940 --- a/arch/x86/pci/mrst.c
25941 +++ b/arch/x86/pci/mrst.c
25942 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
25943 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
25944 pci_mmcfg_late_init();
25945 pcibios_enable_irq = mrst_pci_irq_enable;
25946 - pci_root_ops = pci_mrst_ops;
25947 + pax_open_kernel();
25948 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25949 + pax_close_kernel();
25950 pci_soc_mode = 1;
25951 /* Continue with standard init */
25952 return 1;
25953 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25954 index da8fe05..7ee6704 100644
25955 --- a/arch/x86/pci/pcbios.c
25956 +++ b/arch/x86/pci/pcbios.c
25957 @@ -79,50 +79,93 @@ union bios32 {
25958 static struct {
25959 unsigned long address;
25960 unsigned short segment;
25961 -} bios32_indirect = { 0, __KERNEL_CS };
25962 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25963
25964 /*
25965 * Returns the entry point for the given service, NULL on error
25966 */
25967
25968 -static unsigned long bios32_service(unsigned long service)
25969 +static unsigned long __devinit bios32_service(unsigned long service)
25970 {
25971 unsigned char return_code; /* %al */
25972 unsigned long address; /* %ebx */
25973 unsigned long length; /* %ecx */
25974 unsigned long entry; /* %edx */
25975 unsigned long flags;
25976 + struct desc_struct d, *gdt;
25977
25978 local_irq_save(flags);
25979 - __asm__("lcall *(%%edi); cld"
25980 +
25981 + gdt = get_cpu_gdt_table(smp_processor_id());
25982 +
25983 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25984 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25985 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25986 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25987 +
25988 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25989 : "=a" (return_code),
25990 "=b" (address),
25991 "=c" (length),
25992 "=d" (entry)
25993 : "0" (service),
25994 "1" (0),
25995 - "D" (&bios32_indirect));
25996 + "D" (&bios32_indirect),
25997 + "r"(__PCIBIOS_DS)
25998 + : "memory");
25999 +
26000 + pax_open_kernel();
26001 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26002 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26003 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26004 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26005 + pax_close_kernel();
26006 +
26007 local_irq_restore(flags);
26008
26009 switch (return_code) {
26010 - case 0:
26011 - return address + entry;
26012 - case 0x80: /* Not present */
26013 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26014 - return 0;
26015 - default: /* Shouldn't happen */
26016 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26017 - service, return_code);
26018 + case 0: {
26019 + int cpu;
26020 + unsigned char flags;
26021 +
26022 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26023 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26024 + printk(KERN_WARNING "bios32_service: not valid\n");
26025 return 0;
26026 + }
26027 + address = address + PAGE_OFFSET;
26028 + length += 16UL; /* some BIOSs underreport this... */
26029 + flags = 4;
26030 + if (length >= 64*1024*1024) {
26031 + length >>= PAGE_SHIFT;
26032 + flags |= 8;
26033 + }
26034 +
26035 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26036 + gdt = get_cpu_gdt_table(cpu);
26037 + pack_descriptor(&d, address, length, 0x9b, flags);
26038 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26039 + pack_descriptor(&d, address, length, 0x93, flags);
26040 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26041 + }
26042 + return entry;
26043 + }
26044 + case 0x80: /* Not present */
26045 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26046 + return 0;
26047 + default: /* Shouldn't happen */
26048 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26049 + service, return_code);
26050 + return 0;
26051 }
26052 }
26053
26054 static struct {
26055 unsigned long address;
26056 unsigned short segment;
26057 -} pci_indirect = { 0, __KERNEL_CS };
26058 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26059
26060 -static int pci_bios_present;
26061 +static int pci_bios_present __read_only;
26062
26063 static int __devinit check_pcibios(void)
26064 {
26065 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26066 unsigned long flags, pcibios_entry;
26067
26068 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26069 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26070 + pci_indirect.address = pcibios_entry;
26071
26072 local_irq_save(flags);
26073 - __asm__(
26074 - "lcall *(%%edi); cld\n\t"
26075 + __asm__("movw %w6, %%ds\n\t"
26076 + "lcall *%%ss:(%%edi); cld\n\t"
26077 + "push %%ss\n\t"
26078 + "pop %%ds\n\t"
26079 "jc 1f\n\t"
26080 "xor %%ah, %%ah\n"
26081 "1:"
26082 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26083 "=b" (ebx),
26084 "=c" (ecx)
26085 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26086 - "D" (&pci_indirect)
26087 + "D" (&pci_indirect),
26088 + "r" (__PCIBIOS_DS)
26089 : "memory");
26090 local_irq_restore(flags);
26091
26092 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26093
26094 switch (len) {
26095 case 1:
26096 - __asm__("lcall *(%%esi); cld\n\t"
26097 + __asm__("movw %w6, %%ds\n\t"
26098 + "lcall *%%ss:(%%esi); cld\n\t"
26099 + "push %%ss\n\t"
26100 + "pop %%ds\n\t"
26101 "jc 1f\n\t"
26102 "xor %%ah, %%ah\n"
26103 "1:"
26104 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26105 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26106 "b" (bx),
26107 "D" ((long)reg),
26108 - "S" (&pci_indirect));
26109 + "S" (&pci_indirect),
26110 + "r" (__PCIBIOS_DS));
26111 /*
26112 * Zero-extend the result beyond 8 bits, do not trust the
26113 * BIOS having done it:
26114 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26115 *value &= 0xff;
26116 break;
26117 case 2:
26118 - __asm__("lcall *(%%esi); cld\n\t"
26119 + __asm__("movw %w6, %%ds\n\t"
26120 + "lcall *%%ss:(%%esi); cld\n\t"
26121 + "push %%ss\n\t"
26122 + "pop %%ds\n\t"
26123 "jc 1f\n\t"
26124 "xor %%ah, %%ah\n"
26125 "1:"
26126 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26127 : "1" (PCIBIOS_READ_CONFIG_WORD),
26128 "b" (bx),
26129 "D" ((long)reg),
26130 - "S" (&pci_indirect));
26131 + "S" (&pci_indirect),
26132 + "r" (__PCIBIOS_DS));
26133 /*
26134 * Zero-extend the result beyond 16 bits, do not trust the
26135 * BIOS having done it:
26136 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26137 *value &= 0xffff;
26138 break;
26139 case 4:
26140 - __asm__("lcall *(%%esi); cld\n\t"
26141 + __asm__("movw %w6, %%ds\n\t"
26142 + "lcall *%%ss:(%%esi); cld\n\t"
26143 + "push %%ss\n\t"
26144 + "pop %%ds\n\t"
26145 "jc 1f\n\t"
26146 "xor %%ah, %%ah\n"
26147 "1:"
26148 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26149 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26150 "b" (bx),
26151 "D" ((long)reg),
26152 - "S" (&pci_indirect));
26153 + "S" (&pci_indirect),
26154 + "r" (__PCIBIOS_DS));
26155 break;
26156 }
26157
26158 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26159
26160 switch (len) {
26161 case 1:
26162 - __asm__("lcall *(%%esi); cld\n\t"
26163 + __asm__("movw %w6, %%ds\n\t"
26164 + "lcall *%%ss:(%%esi); cld\n\t"
26165 + "push %%ss\n\t"
26166 + "pop %%ds\n\t"
26167 "jc 1f\n\t"
26168 "xor %%ah, %%ah\n"
26169 "1:"
26170 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26171 "c" (value),
26172 "b" (bx),
26173 "D" ((long)reg),
26174 - "S" (&pci_indirect));
26175 + "S" (&pci_indirect),
26176 + "r" (__PCIBIOS_DS));
26177 break;
26178 case 2:
26179 - __asm__("lcall *(%%esi); cld\n\t"
26180 + __asm__("movw %w6, %%ds\n\t"
26181 + "lcall *%%ss:(%%esi); cld\n\t"
26182 + "push %%ss\n\t"
26183 + "pop %%ds\n\t"
26184 "jc 1f\n\t"
26185 "xor %%ah, %%ah\n"
26186 "1:"
26187 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26188 "c" (value),
26189 "b" (bx),
26190 "D" ((long)reg),
26191 - "S" (&pci_indirect));
26192 + "S" (&pci_indirect),
26193 + "r" (__PCIBIOS_DS));
26194 break;
26195 case 4:
26196 - __asm__("lcall *(%%esi); cld\n\t"
26197 + __asm__("movw %w6, %%ds\n\t"
26198 + "lcall *%%ss:(%%esi); cld\n\t"
26199 + "push %%ss\n\t"
26200 + "pop %%ds\n\t"
26201 "jc 1f\n\t"
26202 "xor %%ah, %%ah\n"
26203 "1:"
26204 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26205 "c" (value),
26206 "b" (bx),
26207 "D" ((long)reg),
26208 - "S" (&pci_indirect));
26209 + "S" (&pci_indirect),
26210 + "r" (__PCIBIOS_DS));
26211 break;
26212 }
26213
26214 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26215
26216 DBG("PCI: Fetching IRQ routing table... ");
26217 __asm__("push %%es\n\t"
26218 + "movw %w8, %%ds\n\t"
26219 "push %%ds\n\t"
26220 "pop %%es\n\t"
26221 - "lcall *(%%esi); cld\n\t"
26222 + "lcall *%%ss:(%%esi); cld\n\t"
26223 "pop %%es\n\t"
26224 + "push %%ss\n\t"
26225 + "pop %%ds\n"
26226 "jc 1f\n\t"
26227 "xor %%ah, %%ah\n"
26228 "1:"
26229 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26230 "1" (0),
26231 "D" ((long) &opt),
26232 "S" (&pci_indirect),
26233 - "m" (opt)
26234 + "m" (opt),
26235 + "r" (__PCIBIOS_DS)
26236 : "memory");
26237 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26238 if (ret & 0xff00)
26239 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26240 {
26241 int ret;
26242
26243 - __asm__("lcall *(%%esi); cld\n\t"
26244 + __asm__("movw %w5, %%ds\n\t"
26245 + "lcall *%%ss:(%%esi); cld\n\t"
26246 + "push %%ss\n\t"
26247 + "pop %%ds\n"
26248 "jc 1f\n\t"
26249 "xor %%ah, %%ah\n"
26250 "1:"
26251 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26252 : "0" (PCIBIOS_SET_PCI_HW_INT),
26253 "b" ((dev->bus->number << 8) | dev->devfn),
26254 "c" ((irq << 8) | (pin + 10)),
26255 - "S" (&pci_indirect));
26256 + "S" (&pci_indirect),
26257 + "r" (__PCIBIOS_DS));
26258 return !(ret & 0xff00);
26259 }
26260 EXPORT_SYMBOL(pcibios_set_irq_routing);
26261 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26262 index 40e4469..1ab536e 100644
26263 --- a/arch/x86/platform/efi/efi_32.c
26264 +++ b/arch/x86/platform/efi/efi_32.c
26265 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26266 {
26267 struct desc_ptr gdt_descr;
26268
26269 +#ifdef CONFIG_PAX_KERNEXEC
26270 + struct desc_struct d;
26271 +#endif
26272 +
26273 local_irq_save(efi_rt_eflags);
26274
26275 load_cr3(initial_page_table);
26276 __flush_tlb_all();
26277
26278 +#ifdef CONFIG_PAX_KERNEXEC
26279 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26280 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26281 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26282 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26283 +#endif
26284 +
26285 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26286 gdt_descr.size = GDT_SIZE - 1;
26287 load_gdt(&gdt_descr);
26288 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26289 {
26290 struct desc_ptr gdt_descr;
26291
26292 +#ifdef CONFIG_PAX_KERNEXEC
26293 + struct desc_struct d;
26294 +
26295 + memset(&d, 0, sizeof d);
26296 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26297 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26298 +#endif
26299 +
26300 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26301 gdt_descr.size = GDT_SIZE - 1;
26302 load_gdt(&gdt_descr);
26303 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26304 index fbe66e6..eae5e38 100644
26305 --- a/arch/x86/platform/efi/efi_stub_32.S
26306 +++ b/arch/x86/platform/efi/efi_stub_32.S
26307 @@ -6,7 +6,9 @@
26308 */
26309
26310 #include <linux/linkage.h>
26311 +#include <linux/init.h>
26312 #include <asm/page_types.h>
26313 +#include <asm/segment.h>
26314
26315 /*
26316 * efi_call_phys(void *, ...) is a function with variable parameters.
26317 @@ -20,7 +22,7 @@
26318 * service functions will comply with gcc calling convention, too.
26319 */
26320
26321 -.text
26322 +__INIT
26323 ENTRY(efi_call_phys)
26324 /*
26325 * 0. The function can only be called in Linux kernel. So CS has been
26326 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26327 * The mapping of lower virtual memory has been created in prelog and
26328 * epilog.
26329 */
26330 - movl $1f, %edx
26331 - subl $__PAGE_OFFSET, %edx
26332 - jmp *%edx
26333 +#ifdef CONFIG_PAX_KERNEXEC
26334 + movl $(__KERNEXEC_EFI_DS), %edx
26335 + mov %edx, %ds
26336 + mov %edx, %es
26337 + mov %edx, %ss
26338 + addl $2f,(1f)
26339 + ljmp *(1f)
26340 +
26341 +__INITDATA
26342 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26343 +.previous
26344 +
26345 +2:
26346 + subl $2b,(1b)
26347 +#else
26348 + jmp 1f-__PAGE_OFFSET
26349 1:
26350 +#endif
26351
26352 /*
26353 * 2. Now on the top of stack is the return
26354 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26355 * parameter 2, ..., param n. To make things easy, we save the return
26356 * address of efi_call_phys in a global variable.
26357 */
26358 - popl %edx
26359 - movl %edx, saved_return_addr
26360 - /* get the function pointer into ECX*/
26361 - popl %ecx
26362 - movl %ecx, efi_rt_function_ptr
26363 - movl $2f, %edx
26364 - subl $__PAGE_OFFSET, %edx
26365 - pushl %edx
26366 + popl (saved_return_addr)
26367 + popl (efi_rt_function_ptr)
26368
26369 /*
26370 * 3. Clear PG bit in %CR0.
26371 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26372 /*
26373 * 5. Call the physical function.
26374 */
26375 - jmp *%ecx
26376 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26377
26378 -2:
26379 /*
26380 * 6. After EFI runtime service returns, control will return to
26381 * following instruction. We'd better readjust stack pointer first.
26382 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26383 movl %cr0, %edx
26384 orl $0x80000000, %edx
26385 movl %edx, %cr0
26386 - jmp 1f
26387 -1:
26388 +
26389 /*
26390 * 8. Now restore the virtual mode from flat mode by
26391 * adding EIP with PAGE_OFFSET.
26392 */
26393 - movl $1f, %edx
26394 - jmp *%edx
26395 +#ifdef CONFIG_PAX_KERNEXEC
26396 + movl $(__KERNEL_DS), %edx
26397 + mov %edx, %ds
26398 + mov %edx, %es
26399 + mov %edx, %ss
26400 + ljmp $(__KERNEL_CS),$1f
26401 +#else
26402 + jmp 1f+__PAGE_OFFSET
26403 +#endif
26404 1:
26405
26406 /*
26407 * 9. Balance the stack. And because EAX contain the return value,
26408 * we'd better not clobber it.
26409 */
26410 - leal efi_rt_function_ptr, %edx
26411 - movl (%edx), %ecx
26412 - pushl %ecx
26413 + pushl (efi_rt_function_ptr)
26414
26415 /*
26416 - * 10. Push the saved return address onto the stack and return.
26417 + * 10. Return to the saved return address.
26418 */
26419 - leal saved_return_addr, %edx
26420 - movl (%edx), %ecx
26421 - pushl %ecx
26422 - ret
26423 + jmpl *(saved_return_addr)
26424 ENDPROC(efi_call_phys)
26425 .previous
26426
26427 -.data
26428 +__INITDATA
26429 saved_return_addr:
26430 .long 0
26431 efi_rt_function_ptr:
26432 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26433 index 4c07cca..2c8427d 100644
26434 --- a/arch/x86/platform/efi/efi_stub_64.S
26435 +++ b/arch/x86/platform/efi/efi_stub_64.S
26436 @@ -7,6 +7,7 @@
26437 */
26438
26439 #include <linux/linkage.h>
26440 +#include <asm/alternative-asm.h>
26441
26442 #define SAVE_XMM \
26443 mov %rsp, %rax; \
26444 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26445 call *%rdi
26446 addq $32, %rsp
26447 RESTORE_XMM
26448 + pax_force_retaddr 0, 1
26449 ret
26450 ENDPROC(efi_call0)
26451
26452 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26453 call *%rdi
26454 addq $32, %rsp
26455 RESTORE_XMM
26456 + pax_force_retaddr 0, 1
26457 ret
26458 ENDPROC(efi_call1)
26459
26460 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26461 call *%rdi
26462 addq $32, %rsp
26463 RESTORE_XMM
26464 + pax_force_retaddr 0, 1
26465 ret
26466 ENDPROC(efi_call2)
26467
26468 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26469 call *%rdi
26470 addq $32, %rsp
26471 RESTORE_XMM
26472 + pax_force_retaddr 0, 1
26473 ret
26474 ENDPROC(efi_call3)
26475
26476 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26477 call *%rdi
26478 addq $32, %rsp
26479 RESTORE_XMM
26480 + pax_force_retaddr 0, 1
26481 ret
26482 ENDPROC(efi_call4)
26483
26484 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26485 call *%rdi
26486 addq $48, %rsp
26487 RESTORE_XMM
26488 + pax_force_retaddr 0, 1
26489 ret
26490 ENDPROC(efi_call5)
26491
26492 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26493 call *%rdi
26494 addq $48, %rsp
26495 RESTORE_XMM
26496 + pax_force_retaddr 0, 1
26497 ret
26498 ENDPROC(efi_call6)
26499 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26500 index fd41a92..9c33628 100644
26501 --- a/arch/x86/platform/mrst/mrst.c
26502 +++ b/arch/x86/platform/mrst/mrst.c
26503 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26504 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26505 int sfi_mrtc_num;
26506
26507 -static void mrst_power_off(void)
26508 +static __noreturn void mrst_power_off(void)
26509 {
26510 + BUG();
26511 }
26512
26513 -static void mrst_reboot(void)
26514 +static __noreturn void mrst_reboot(void)
26515 {
26516 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26517 + BUG();
26518 }
26519
26520 /* parse all the mtimer info to a static mtimer array */
26521 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26522 index 218cdb1..fd55c08 100644
26523 --- a/arch/x86/power/cpu.c
26524 +++ b/arch/x86/power/cpu.c
26525 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26526 static void fix_processor_context(void)
26527 {
26528 int cpu = smp_processor_id();
26529 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26530 + struct tss_struct *t = init_tss + cpu;
26531
26532 set_tss_desc(cpu, t); /*
26533 * This just modifies memory; should not be
26534 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26535 */
26536
26537 #ifdef CONFIG_X86_64
26538 + pax_open_kernel();
26539 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26540 + pax_close_kernel();
26541
26542 syscall_init(); /* This sets MSR_*STAR and related */
26543 #endif
26544 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26545 index cbca565..35ce1d7 100644
26546 --- a/arch/x86/realmode/init.c
26547 +++ b/arch/x86/realmode/init.c
26548 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26549 __va(real_mode_header->trampoline_header);
26550
26551 #ifdef CONFIG_X86_32
26552 - trampoline_header->start = __pa(startup_32_smp);
26553 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26554 +
26555 +#ifdef CONFIG_PAX_KERNEXEC
26556 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26557 +#endif
26558 +
26559 + trampoline_header->boot_cs = __BOOT_CS;
26560 trampoline_header->gdt_limit = __BOOT_DS + 7;
26561 trampoline_header->gdt_base = __pa(boot_gdt);
26562 #else
26563 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26564 index 5b84a2d..a004393 100644
26565 --- a/arch/x86/realmode/rm/Makefile
26566 +++ b/arch/x86/realmode/rm/Makefile
26567 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26568 $(call cc-option, -fno-unit-at-a-time)) \
26569 $(call cc-option, -fno-stack-protector) \
26570 $(call cc-option, -mpreferred-stack-boundary=2)
26571 +ifdef CONSTIFY_PLUGIN
26572 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26573 +endif
26574 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26575 GCOV_PROFILE := n
26576 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26577 index c1b2791..f9e31c7 100644
26578 --- a/arch/x86/realmode/rm/trampoline_32.S
26579 +++ b/arch/x86/realmode/rm/trampoline_32.S
26580 @@ -25,6 +25,12 @@
26581 #include <asm/page_types.h>
26582 #include "realmode.h"
26583
26584 +#ifdef CONFIG_PAX_KERNEXEC
26585 +#define ta(X) (X)
26586 +#else
26587 +#define ta(X) (pa_ ## X)
26588 +#endif
26589 +
26590 .text
26591 .code16
26592
26593 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26594
26595 cli # We should be safe anyway
26596
26597 - movl tr_start, %eax # where we need to go
26598 -
26599 movl $0xA5A5A5A5, trampoline_status
26600 # write marker for master knows we're running
26601
26602 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26603 movw $1, %dx # protected mode (PE) bit
26604 lmsw %dx # into protected mode
26605
26606 - ljmpl $__BOOT_CS, $pa_startup_32
26607 + ljmpl *(trampoline_header)
26608
26609 .section ".text32","ax"
26610 .code32
26611 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26612 .balign 8
26613 GLOBAL(trampoline_header)
26614 tr_start: .space 4
26615 - tr_gdt_pad: .space 2
26616 + tr_boot_cs: .space 2
26617 tr_gdt: .space 6
26618 END(trampoline_header)
26619
26620 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26621 index bb360dc..3e5945f 100644
26622 --- a/arch/x86/realmode/rm/trampoline_64.S
26623 +++ b/arch/x86/realmode/rm/trampoline_64.S
26624 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26625 wrmsr
26626
26627 # Enable paging and in turn activate Long Mode
26628 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26629 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26630 movl %eax, %cr0
26631
26632 /*
26633 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26634 index 5a1847d..deccb30 100644
26635 --- a/arch/x86/tools/relocs.c
26636 +++ b/arch/x86/tools/relocs.c
26637 @@ -12,10 +12,13 @@
26638 #include <regex.h>
26639 #include <tools/le_byteshift.h>
26640
26641 +#include "../../../include/generated/autoconf.h"
26642 +
26643 static void die(char *fmt, ...);
26644
26645 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26646 static Elf32_Ehdr ehdr;
26647 +static Elf32_Phdr *phdr;
26648 static unsigned long reloc_count, reloc_idx;
26649 static unsigned long *relocs;
26650 static unsigned long reloc16_count, reloc16_idx;
26651 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26652 }
26653 }
26654
26655 +static void read_phdrs(FILE *fp)
26656 +{
26657 + unsigned int i;
26658 +
26659 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26660 + if (!phdr) {
26661 + die("Unable to allocate %d program headers\n",
26662 + ehdr.e_phnum);
26663 + }
26664 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26665 + die("Seek to %d failed: %s\n",
26666 + ehdr.e_phoff, strerror(errno));
26667 + }
26668 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26669 + die("Cannot read ELF program headers: %s\n",
26670 + strerror(errno));
26671 + }
26672 + for(i = 0; i < ehdr.e_phnum; i++) {
26673 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26674 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26675 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26676 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26677 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26678 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26679 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26680 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26681 + }
26682 +
26683 +}
26684 +
26685 static void read_shdrs(FILE *fp)
26686 {
26687 - int i;
26688 + unsigned int i;
26689 Elf32_Shdr shdr;
26690
26691 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26692 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26693
26694 static void read_strtabs(FILE *fp)
26695 {
26696 - int i;
26697 + unsigned int i;
26698 for (i = 0; i < ehdr.e_shnum; i++) {
26699 struct section *sec = &secs[i];
26700 if (sec->shdr.sh_type != SHT_STRTAB) {
26701 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26702
26703 static void read_symtabs(FILE *fp)
26704 {
26705 - int i,j;
26706 + unsigned int i,j;
26707 for (i = 0; i < ehdr.e_shnum; i++) {
26708 struct section *sec = &secs[i];
26709 if (sec->shdr.sh_type != SHT_SYMTAB) {
26710 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26711 }
26712
26713
26714 -static void read_relocs(FILE *fp)
26715 +static void read_relocs(FILE *fp, int use_real_mode)
26716 {
26717 - int i,j;
26718 + unsigned int i,j;
26719 + uint32_t base;
26720 +
26721 for (i = 0; i < ehdr.e_shnum; i++) {
26722 struct section *sec = &secs[i];
26723 if (sec->shdr.sh_type != SHT_REL) {
26724 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26725 die("Cannot read symbol table: %s\n",
26726 strerror(errno));
26727 }
26728 + base = 0;
26729 +
26730 +#ifdef CONFIG_X86_32
26731 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26732 + if (phdr[j].p_type != PT_LOAD )
26733 + continue;
26734 + 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)
26735 + continue;
26736 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26737 + break;
26738 + }
26739 +#endif
26740 +
26741 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26742 Elf32_Rel *rel = &sec->reltab[j];
26743 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26744 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26745 rel->r_info = elf32_to_cpu(rel->r_info);
26746 }
26747 }
26748 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26749
26750 static void print_absolute_symbols(void)
26751 {
26752 - int i;
26753 + unsigned int i;
26754 printf("Absolute symbols\n");
26755 printf(" Num: Value Size Type Bind Visibility Name\n");
26756 for (i = 0; i < ehdr.e_shnum; i++) {
26757 struct section *sec = &secs[i];
26758 char *sym_strtab;
26759 - int j;
26760 + unsigned int j;
26761
26762 if (sec->shdr.sh_type != SHT_SYMTAB) {
26763 continue;
26764 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26765
26766 static void print_absolute_relocs(void)
26767 {
26768 - int i, printed = 0;
26769 + unsigned int i, printed = 0;
26770
26771 for (i = 0; i < ehdr.e_shnum; i++) {
26772 struct section *sec = &secs[i];
26773 struct section *sec_applies, *sec_symtab;
26774 char *sym_strtab;
26775 Elf32_Sym *sh_symtab;
26776 - int j;
26777 + unsigned int j;
26778 if (sec->shdr.sh_type != SHT_REL) {
26779 continue;
26780 }
26781 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26782 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26783 int use_real_mode)
26784 {
26785 - int i;
26786 + unsigned int i;
26787 /* Walk through the relocations */
26788 for (i = 0; i < ehdr.e_shnum; i++) {
26789 char *sym_strtab;
26790 Elf32_Sym *sh_symtab;
26791 struct section *sec_applies, *sec_symtab;
26792 - int j;
26793 + unsigned int j;
26794 struct section *sec = &secs[i];
26795
26796 if (sec->shdr.sh_type != SHT_REL) {
26797 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26798 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26799 r_type = ELF32_R_TYPE(rel->r_info);
26800
26801 + if (!use_real_mode) {
26802 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26803 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26804 + continue;
26805 +
26806 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26807 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26808 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26809 + continue;
26810 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26811 + continue;
26812 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26813 + continue;
26814 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26815 + continue;
26816 +#endif
26817 + }
26818 +
26819 shn_abs = sym->st_shndx == SHN_ABS;
26820
26821 switch (r_type) {
26822 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26823
26824 static void emit_relocs(int as_text, int use_real_mode)
26825 {
26826 - int i;
26827 + unsigned int i;
26828 /* Count how many relocations I have and allocate space for them. */
26829 reloc_count = 0;
26830 walk_relocs(count_reloc, use_real_mode);
26831 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
26832 fname, strerror(errno));
26833 }
26834 read_ehdr(fp);
26835 + read_phdrs(fp);
26836 read_shdrs(fp);
26837 read_strtabs(fp);
26838 read_symtabs(fp);
26839 - read_relocs(fp);
26840 + read_relocs(fp, use_real_mode);
26841 if (show_absolute_syms) {
26842 print_absolute_symbols();
26843 return 0;
26844 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26845 index fd14be1..e3c79c0 100644
26846 --- a/arch/x86/vdso/Makefile
26847 +++ b/arch/x86/vdso/Makefile
26848 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26849 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26850 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26851
26852 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26853 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26854 GCOV_PROFILE := n
26855
26856 #
26857 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26858 index 66e6d93..587f435 100644
26859 --- a/arch/x86/vdso/vdso32-setup.c
26860 +++ b/arch/x86/vdso/vdso32-setup.c
26861 @@ -25,6 +25,7 @@
26862 #include <asm/tlbflush.h>
26863 #include <asm/vdso.h>
26864 #include <asm/proto.h>
26865 +#include <asm/mman.h>
26866
26867 enum {
26868 VDSO_DISABLED = 0,
26869 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26870 void enable_sep_cpu(void)
26871 {
26872 int cpu = get_cpu();
26873 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26874 + struct tss_struct *tss = init_tss + cpu;
26875
26876 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26877 put_cpu();
26878 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26879 gate_vma.vm_start = FIXADDR_USER_START;
26880 gate_vma.vm_end = FIXADDR_USER_END;
26881 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26882 - gate_vma.vm_page_prot = __P101;
26883 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26884
26885 return 0;
26886 }
26887 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26888 if (compat)
26889 addr = VDSO_HIGH_BASE;
26890 else {
26891 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26892 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26893 if (IS_ERR_VALUE(addr)) {
26894 ret = addr;
26895 goto up_fail;
26896 }
26897 }
26898
26899 - current->mm->context.vdso = (void *)addr;
26900 + current->mm->context.vdso = addr;
26901
26902 if (compat_uses_vma || !compat) {
26903 /*
26904 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26905 }
26906
26907 current_thread_info()->sysenter_return =
26908 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26909 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26910
26911 up_fail:
26912 if (ret)
26913 - current->mm->context.vdso = NULL;
26914 + current->mm->context.vdso = 0;
26915
26916 up_write(&mm->mmap_sem);
26917
26918 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26919
26920 const char *arch_vma_name(struct vm_area_struct *vma)
26921 {
26922 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26923 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26924 return "[vdso]";
26925 +
26926 +#ifdef CONFIG_PAX_SEGMEXEC
26927 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26928 + return "[vdso]";
26929 +#endif
26930 +
26931 return NULL;
26932 }
26933
26934 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26935 * Check to see if the corresponding task was created in compat vdso
26936 * mode.
26937 */
26938 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26939 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26940 return &gate_vma;
26941 return NULL;
26942 }
26943 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26944 index 00aaf04..4a26505 100644
26945 --- a/arch/x86/vdso/vma.c
26946 +++ b/arch/x86/vdso/vma.c
26947 @@ -16,8 +16,6 @@
26948 #include <asm/vdso.h>
26949 #include <asm/page.h>
26950
26951 -unsigned int __read_mostly vdso_enabled = 1;
26952 -
26953 extern char vdso_start[], vdso_end[];
26954 extern unsigned short vdso_sync_cpuid;
26955
26956 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26957 * unaligned here as a result of stack start randomization.
26958 */
26959 addr = PAGE_ALIGN(addr);
26960 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26961
26962 return addr;
26963 }
26964 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
26965 unsigned size)
26966 {
26967 struct mm_struct *mm = current->mm;
26968 - unsigned long addr;
26969 + unsigned long addr = 0;
26970 int ret;
26971
26972 - if (!vdso_enabled)
26973 - return 0;
26974 -
26975 down_write(&mm->mmap_sem);
26976 +
26977 +#ifdef CONFIG_PAX_RANDMMAP
26978 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26979 +#endif
26980 +
26981 addr = vdso_addr(mm->start_stack, size);
26982 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26983 addr = get_unmapped_area(NULL, addr, size, 0, 0);
26984 if (IS_ERR_VALUE(addr)) {
26985 ret = addr;
26986 goto up_fail;
26987 }
26988
26989 - current->mm->context.vdso = (void *)addr;
26990 + mm->context.vdso = addr;
26991
26992 ret = install_special_mapping(mm, addr, size,
26993 VM_READ|VM_EXEC|
26994 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
26995 pages);
26996 - if (ret) {
26997 - current->mm->context.vdso = NULL;
26998 - goto up_fail;
26999 - }
27000 + if (ret)
27001 + mm->context.vdso = 0;
27002
27003 up_fail:
27004 up_write(&mm->mmap_sem);
27005 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27006 vdsox32_size);
27007 }
27008 #endif
27009 -
27010 -static __init int vdso_setup(char *s)
27011 -{
27012 - vdso_enabled = simple_strtoul(s, NULL, 0);
27013 - return 0;
27014 -}
27015 -__setup("vdso=", vdso_setup);
27016 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27017 index ff962d4..2bb5e83 100644
27018 --- a/arch/x86/xen/enlighten.c
27019 +++ b/arch/x86/xen/enlighten.c
27020 @@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27021
27022 struct shared_info xen_dummy_shared_info;
27023
27024 -void *xen_initial_gdt;
27025 -
27026 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27027 __read_mostly int xen_have_vector_callback;
27028 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27029 @@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27030 #endif
27031 };
27032
27033 -static void xen_reboot(int reason)
27034 +static __noreturn void xen_reboot(int reason)
27035 {
27036 struct sched_shutdown r = { .reason = reason };
27037
27038 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27039 - BUG();
27040 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27041 + BUG();
27042 }
27043
27044 -static void xen_restart(char *msg)
27045 +static __noreturn void xen_restart(char *msg)
27046 {
27047 xen_reboot(SHUTDOWN_reboot);
27048 }
27049
27050 -static void xen_emergency_restart(void)
27051 +static __noreturn void xen_emergency_restart(void)
27052 {
27053 xen_reboot(SHUTDOWN_reboot);
27054 }
27055
27056 -static void xen_machine_halt(void)
27057 +static __noreturn void xen_machine_halt(void)
27058 {
27059 xen_reboot(SHUTDOWN_poweroff);
27060 }
27061
27062 -static void xen_machine_power_off(void)
27063 +static __noreturn void xen_machine_power_off(void)
27064 {
27065 if (pm_power_off)
27066 pm_power_off();
27067 @@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27068 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27069
27070 /* Work out if we support NX */
27071 - x86_configure_nx();
27072 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27073 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27074 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27075 + unsigned l, h;
27076 +
27077 + __supported_pte_mask |= _PAGE_NX;
27078 + rdmsr(MSR_EFER, l, h);
27079 + l |= EFER_NX;
27080 + wrmsr(MSR_EFER, l, h);
27081 + }
27082 +#endif
27083
27084 xen_setup_features();
27085
27086 @@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27087
27088 machine_ops = xen_machine_ops;
27089
27090 - /*
27091 - * The only reliable way to retain the initial address of the
27092 - * percpu gdt_page is to remember it here, so we can go and
27093 - * mark it RW later, when the initial percpu area is freed.
27094 - */
27095 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27096 -
27097 xen_smp_init();
27098
27099 #ifdef CONFIG_ACPI_NUMA
27100 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27101 index 3a73785..0d30df2 100644
27102 --- a/arch/x86/xen/mmu.c
27103 +++ b/arch/x86/xen/mmu.c
27104 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27105 convert_pfn_mfn(init_level4_pgt);
27106 convert_pfn_mfn(level3_ident_pgt);
27107 convert_pfn_mfn(level3_kernel_pgt);
27108 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27109 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27110 + convert_pfn_mfn(level3_vmemmap_pgt);
27111
27112 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27113 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27114 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27115 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27116 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27117 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27118 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27119 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27120 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27121 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27122 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27123 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27124 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27125
27126 @@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27127 pv_mmu_ops.set_pud = xen_set_pud;
27128 #if PAGETABLE_LEVELS == 4
27129 pv_mmu_ops.set_pgd = xen_set_pgd;
27130 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27131 #endif
27132
27133 /* This will work as long as patching hasn't happened yet
27134 @@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27135 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27136 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27137 .set_pgd = xen_set_pgd_hyper,
27138 + .set_pgd_batched = xen_set_pgd_hyper,
27139
27140 .alloc_pud = xen_alloc_pmd_init,
27141 .release_pud = xen_release_pmd_init,
27142 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27143 index afb250d..627075f 100644
27144 --- a/arch/x86/xen/smp.c
27145 +++ b/arch/x86/xen/smp.c
27146 @@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27147 {
27148 BUG_ON(smp_processor_id() != 0);
27149 native_smp_prepare_boot_cpu();
27150 -
27151 - /* We've switched to the "real" per-cpu gdt, so make sure the
27152 - old memory can be recycled */
27153 - make_lowmem_page_readwrite(xen_initial_gdt);
27154 -
27155 xen_filter_cpu_maps();
27156 xen_setup_vcpu_info_placement();
27157 }
27158 @@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27159 gdt = get_cpu_gdt_table(cpu);
27160
27161 ctxt->flags = VGCF_IN_KERNEL;
27162 - ctxt->user_regs.ds = __USER_DS;
27163 - ctxt->user_regs.es = __USER_DS;
27164 + ctxt->user_regs.ds = __KERNEL_DS;
27165 + ctxt->user_regs.es = __KERNEL_DS;
27166 ctxt->user_regs.ss = __KERNEL_DS;
27167 #ifdef CONFIG_X86_32
27168 ctxt->user_regs.fs = __KERNEL_PERCPU;
27169 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27170 + savesegment(gs, ctxt->user_regs.gs);
27171 #else
27172 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27173 #endif
27174 @@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27175 int rc;
27176
27177 per_cpu(current_task, cpu) = idle;
27178 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27179 #ifdef CONFIG_X86_32
27180 irq_ctx_init(cpu);
27181 #else
27182 clear_tsk_thread_flag(idle, TIF_FORK);
27183 - per_cpu(kernel_stack, cpu) =
27184 - (unsigned long)task_stack_page(idle) -
27185 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27186 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27187 #endif
27188 xen_setup_runstate_info(cpu);
27189 xen_setup_timer(cpu);
27190 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27191 index f9643fc..602e8af 100644
27192 --- a/arch/x86/xen/xen-asm_32.S
27193 +++ b/arch/x86/xen/xen-asm_32.S
27194 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27195 ESP_OFFSET=4 # bytes pushed onto stack
27196
27197 /*
27198 - * Store vcpu_info pointer for easy access. Do it this way to
27199 - * avoid having to reload %fs
27200 + * Store vcpu_info pointer for easy access.
27201 */
27202 #ifdef CONFIG_SMP
27203 - GET_THREAD_INFO(%eax)
27204 - movl TI_cpu(%eax), %eax
27205 - movl __per_cpu_offset(,%eax,4), %eax
27206 - mov xen_vcpu(%eax), %eax
27207 + push %fs
27208 + mov $(__KERNEL_PERCPU), %eax
27209 + mov %eax, %fs
27210 + mov PER_CPU_VAR(xen_vcpu), %eax
27211 + pop %fs
27212 #else
27213 movl xen_vcpu, %eax
27214 #endif
27215 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27216 index aaa7291..3f77960 100644
27217 --- a/arch/x86/xen/xen-head.S
27218 +++ b/arch/x86/xen/xen-head.S
27219 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27220 #ifdef CONFIG_X86_32
27221 mov %esi,xen_start_info
27222 mov $init_thread_union+THREAD_SIZE,%esp
27223 +#ifdef CONFIG_SMP
27224 + movl $cpu_gdt_table,%edi
27225 + movl $__per_cpu_load,%eax
27226 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27227 + rorl $16,%eax
27228 + movb %al,__KERNEL_PERCPU + 4(%edi)
27229 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27230 + movl $__per_cpu_end - 1,%eax
27231 + subl $__per_cpu_start,%eax
27232 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27233 +#endif
27234 #else
27235 mov %rsi,xen_start_info
27236 mov $init_thread_union+THREAD_SIZE,%rsp
27237 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27238 index 202d4c1..99b072a 100644
27239 --- a/arch/x86/xen/xen-ops.h
27240 +++ b/arch/x86/xen/xen-ops.h
27241 @@ -10,8 +10,6 @@
27242 extern const char xen_hypervisor_callback[];
27243 extern const char xen_failsafe_callback[];
27244
27245 -extern void *xen_initial_gdt;
27246 -
27247 struct trap_info;
27248 void xen_copy_trap_info(struct trap_info *traps);
27249
27250 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27251 index 525bd3d..ef888b1 100644
27252 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27253 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27254 @@ -119,9 +119,9 @@
27255 ----------------------------------------------------------------------*/
27256
27257 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27258 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27259 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27260 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27261 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27262
27263 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27264 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27265 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27266 index 2f33760..835e50a 100644
27267 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27268 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27269 @@ -11,6 +11,7 @@
27270 #ifndef _XTENSA_CORE_H
27271 #define _XTENSA_CORE_H
27272
27273 +#include <linux/const.h>
27274
27275 /****************************************************************************
27276 Parameters Useful for Any Code, USER or PRIVILEGED
27277 @@ -112,9 +113,9 @@
27278 ----------------------------------------------------------------------*/
27279
27280 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27281 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27282 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27283 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27284 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27285
27286 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27287 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27288 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27289 index af00795..2bb8105 100644
27290 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27291 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27292 @@ -11,6 +11,7 @@
27293 #ifndef _XTENSA_CORE_CONFIGURATION_H
27294 #define _XTENSA_CORE_CONFIGURATION_H
27295
27296 +#include <linux/const.h>
27297
27298 /****************************************************************************
27299 Parameters Useful for Any Code, USER or PRIVILEGED
27300 @@ -118,9 +119,9 @@
27301 ----------------------------------------------------------------------*/
27302
27303 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27304 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27305 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27306 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27307 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27308
27309 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27310 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27311 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27312 index 58916af..9cb880b 100644
27313 --- a/block/blk-iopoll.c
27314 +++ b/block/blk-iopoll.c
27315 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27316 }
27317 EXPORT_SYMBOL(blk_iopoll_complete);
27318
27319 -static void blk_iopoll_softirq(struct softirq_action *h)
27320 +static void blk_iopoll_softirq(void)
27321 {
27322 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27323 int rearm = 0, budget = blk_iopoll_budget;
27324 diff --git a/block/blk-map.c b/block/blk-map.c
27325 index 623e1cd..ca1e109 100644
27326 --- a/block/blk-map.c
27327 +++ b/block/blk-map.c
27328 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27329 if (!len || !kbuf)
27330 return -EINVAL;
27331
27332 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27333 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27334 if (do_copy)
27335 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27336 else
27337 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27338 index 467c8de..4bddc6d 100644
27339 --- a/block/blk-softirq.c
27340 +++ b/block/blk-softirq.c
27341 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27342 * Softirq action handler - move entries to local list and loop over them
27343 * while passing them to the queue registered handler.
27344 */
27345 -static void blk_done_softirq(struct softirq_action *h)
27346 +static void blk_done_softirq(void)
27347 {
27348 struct list_head *cpu_list, local_list;
27349
27350 diff --git a/block/bsg.c b/block/bsg.c
27351 index ff64ae3..593560c 100644
27352 --- a/block/bsg.c
27353 +++ b/block/bsg.c
27354 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27355 struct sg_io_v4 *hdr, struct bsg_device *bd,
27356 fmode_t has_write_perm)
27357 {
27358 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27359 + unsigned char *cmdptr;
27360 +
27361 if (hdr->request_len > BLK_MAX_CDB) {
27362 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27363 if (!rq->cmd)
27364 return -ENOMEM;
27365 - }
27366 + cmdptr = rq->cmd;
27367 + } else
27368 + cmdptr = tmpcmd;
27369
27370 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27371 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27372 hdr->request_len))
27373 return -EFAULT;
27374
27375 + if (cmdptr != rq->cmd)
27376 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27377 +
27378 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27379 if (blk_verify_command(rq->cmd, has_write_perm))
27380 return -EPERM;
27381 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27382 index 7c668c8..db3521c 100644
27383 --- a/block/compat_ioctl.c
27384 +++ b/block/compat_ioctl.c
27385 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27386 err |= __get_user(f->spec1, &uf->spec1);
27387 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27388 err |= __get_user(name, &uf->name);
27389 - f->name = compat_ptr(name);
27390 + f->name = (void __force_kernel *)compat_ptr(name);
27391 if (err) {
27392 err = -EFAULT;
27393 goto out;
27394 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27395 index 6296b40..417c00f 100644
27396 --- a/block/partitions/efi.c
27397 +++ b/block/partitions/efi.c
27398 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27399 if (!gpt)
27400 return NULL;
27401
27402 + if (!le32_to_cpu(gpt->num_partition_entries))
27403 + return NULL;
27404 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27405 + if (!pte)
27406 + return NULL;
27407 +
27408 count = le32_to_cpu(gpt->num_partition_entries) *
27409 le32_to_cpu(gpt->sizeof_partition_entry);
27410 - if (!count)
27411 - return NULL;
27412 - pte = kzalloc(count, GFP_KERNEL);
27413 - if (!pte)
27414 - return NULL;
27415 -
27416 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27417 (u8 *) pte,
27418 count) < count) {
27419 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27420 index 9a87daa..fb17486 100644
27421 --- a/block/scsi_ioctl.c
27422 +++ b/block/scsi_ioctl.c
27423 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27424 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27425 struct sg_io_hdr *hdr, fmode_t mode)
27426 {
27427 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27428 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27429 + unsigned char *cmdptr;
27430 +
27431 + if (rq->cmd != rq->__cmd)
27432 + cmdptr = rq->cmd;
27433 + else
27434 + cmdptr = tmpcmd;
27435 +
27436 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27437 return -EFAULT;
27438 +
27439 + if (cmdptr != rq->cmd)
27440 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27441 +
27442 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27443 return -EPERM;
27444
27445 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27446 int err;
27447 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27448 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27449 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27450 + unsigned char *cmdptr;
27451
27452 if (!sic)
27453 return -EINVAL;
27454 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27455 */
27456 err = -EFAULT;
27457 rq->cmd_len = cmdlen;
27458 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27459 +
27460 + if (rq->cmd != rq->__cmd)
27461 + cmdptr = rq->cmd;
27462 + else
27463 + cmdptr = tmpcmd;
27464 +
27465 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27466 goto error;
27467
27468 + if (rq->cmd != cmdptr)
27469 + memcpy(rq->cmd, cmdptr, cmdlen);
27470 +
27471 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27472 goto error;
27473
27474 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27475 index 671d4d6..5f24030 100644
27476 --- a/crypto/cryptd.c
27477 +++ b/crypto/cryptd.c
27478 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27479
27480 struct cryptd_blkcipher_request_ctx {
27481 crypto_completion_t complete;
27482 -};
27483 +} __no_const;
27484
27485 struct cryptd_hash_ctx {
27486 struct crypto_shash *child;
27487 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27488
27489 struct cryptd_aead_request_ctx {
27490 crypto_completion_t complete;
27491 -};
27492 +} __no_const;
27493
27494 static void cryptd_queue_worker(struct work_struct *work);
27495
27496 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27497 index e6defd8..c26a225 100644
27498 --- a/drivers/acpi/apei/cper.c
27499 +++ b/drivers/acpi/apei/cper.c
27500 @@ -38,12 +38,12 @@
27501 */
27502 u64 cper_next_record_id(void)
27503 {
27504 - static atomic64_t seq;
27505 + static atomic64_unchecked_t seq;
27506
27507 - if (!atomic64_read(&seq))
27508 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27509 + if (!atomic64_read_unchecked(&seq))
27510 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27511
27512 - return atomic64_inc_return(&seq);
27513 + return atomic64_inc_return_unchecked(&seq);
27514 }
27515 EXPORT_SYMBOL_GPL(cper_next_record_id);
27516
27517 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27518 index 7586544..636a2f0 100644
27519 --- a/drivers/acpi/ec_sys.c
27520 +++ b/drivers/acpi/ec_sys.c
27521 @@ -12,6 +12,7 @@
27522 #include <linux/acpi.h>
27523 #include <linux/debugfs.h>
27524 #include <linux/module.h>
27525 +#include <linux/uaccess.h>
27526 #include "internal.h"
27527
27528 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27529 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27530 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27531 */
27532 unsigned int size = EC_SPACE_SIZE;
27533 - u8 *data = (u8 *) buf;
27534 + u8 data;
27535 loff_t init_off = *off;
27536 int err = 0;
27537
27538 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27539 size = count;
27540
27541 while (size) {
27542 - err = ec_read(*off, &data[*off - init_off]);
27543 + err = ec_read(*off, &data);
27544 if (err)
27545 return err;
27546 + if (put_user(data, &buf[*off - init_off]))
27547 + return -EFAULT;
27548 *off += 1;
27549 size--;
27550 }
27551 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27552
27553 unsigned int size = count;
27554 loff_t init_off = *off;
27555 - u8 *data = (u8 *) buf;
27556 int err = 0;
27557
27558 if (*off >= EC_SPACE_SIZE)
27559 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27560 }
27561
27562 while (size) {
27563 - u8 byte_write = data[*off - init_off];
27564 + u8 byte_write;
27565 + if (get_user(byte_write, &buf[*off - init_off]))
27566 + return -EFAULT;
27567 err = ec_write(*off, byte_write);
27568 if (err)
27569 return err;
27570 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27571 index 251c7b62..000462d 100644
27572 --- a/drivers/acpi/proc.c
27573 +++ b/drivers/acpi/proc.c
27574 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27575 size_t count, loff_t * ppos)
27576 {
27577 struct list_head *node, *next;
27578 - char strbuf[5];
27579 - char str[5] = "";
27580 - unsigned int len = count;
27581 + char strbuf[5] = {0};
27582
27583 - if (len > 4)
27584 - len = 4;
27585 - if (len < 0)
27586 + if (count > 4)
27587 + count = 4;
27588 + if (copy_from_user(strbuf, buffer, count))
27589 return -EFAULT;
27590 -
27591 - if (copy_from_user(strbuf, buffer, len))
27592 - return -EFAULT;
27593 - strbuf[len] = '\0';
27594 - sscanf(strbuf, "%s", str);
27595 + strbuf[count] = '\0';
27596
27597 mutex_lock(&acpi_device_lock);
27598 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27599 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27600 if (!dev->wakeup.flags.valid)
27601 continue;
27602
27603 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27604 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27605 if (device_can_wakeup(&dev->dev)) {
27606 bool enable = !device_may_wakeup(&dev->dev);
27607 device_set_wakeup_enable(&dev->dev, enable);
27608 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27609 index 0734086..3ad3e4c 100644
27610 --- a/drivers/acpi/processor_driver.c
27611 +++ b/drivers/acpi/processor_driver.c
27612 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27613 return 0;
27614 #endif
27615
27616 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27617 + BUG_ON(pr->id >= nr_cpu_ids);
27618
27619 /*
27620 * Buggy BIOS check
27621 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27622 index cece3a4..0845256 100644
27623 --- a/drivers/ata/libata-core.c
27624 +++ b/drivers/ata/libata-core.c
27625 @@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27626 struct ata_port *ap;
27627 unsigned int tag;
27628
27629 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27630 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27631 ap = qc->ap;
27632
27633 qc->flags = 0;
27634 @@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27635 struct ata_port *ap;
27636 struct ata_link *link;
27637
27638 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27639 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27640 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27641 ap = qc->ap;
27642 link = qc->dev->link;
27643 @@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27644 return;
27645
27646 spin_lock(&lock);
27647 + pax_open_kernel();
27648
27649 for (cur = ops->inherits; cur; cur = cur->inherits) {
27650 void **inherit = (void **)cur;
27651 @@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27652 if (IS_ERR(*pp))
27653 *pp = NULL;
27654
27655 - ops->inherits = NULL;
27656 + *(struct ata_port_operations **)&ops->inherits = NULL;
27657
27658 + pax_close_kernel();
27659 spin_unlock(&lock);
27660 }
27661
27662 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27663 index ac6a5be..c7176b1 100644
27664 --- a/drivers/ata/pata_arasan_cf.c
27665 +++ b/drivers/ata/pata_arasan_cf.c
27666 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27667 /* Handle platform specific quirks */
27668 if (pdata->quirk) {
27669 if (pdata->quirk & CF_BROKEN_PIO) {
27670 - ap->ops->set_piomode = NULL;
27671 + pax_open_kernel();
27672 + *(void **)&ap->ops->set_piomode = NULL;
27673 + pax_close_kernel();
27674 ap->pio_mask = 0;
27675 }
27676 if (pdata->quirk & CF_BROKEN_MWDMA)
27677 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27678 index f9b983a..887b9d8 100644
27679 --- a/drivers/atm/adummy.c
27680 +++ b/drivers/atm/adummy.c
27681 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27682 vcc->pop(vcc, skb);
27683 else
27684 dev_kfree_skb_any(skb);
27685 - atomic_inc(&vcc->stats->tx);
27686 + atomic_inc_unchecked(&vcc->stats->tx);
27687
27688 return 0;
27689 }
27690 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27691 index 89b30f3..7964211 100644
27692 --- a/drivers/atm/ambassador.c
27693 +++ b/drivers/atm/ambassador.c
27694 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27695 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27696
27697 // VC layer stats
27698 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27699 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27700
27701 // free the descriptor
27702 kfree (tx_descr);
27703 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27704 dump_skb ("<<<", vc, skb);
27705
27706 // VC layer stats
27707 - atomic_inc(&atm_vcc->stats->rx);
27708 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27709 __net_timestamp(skb);
27710 // end of our responsibility
27711 atm_vcc->push (atm_vcc, skb);
27712 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27713 } else {
27714 PRINTK (KERN_INFO, "dropped over-size frame");
27715 // should we count this?
27716 - atomic_inc(&atm_vcc->stats->rx_drop);
27717 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27718 }
27719
27720 } else {
27721 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27722 }
27723
27724 if (check_area (skb->data, skb->len)) {
27725 - atomic_inc(&atm_vcc->stats->tx_err);
27726 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27727 return -ENOMEM; // ?
27728 }
27729
27730 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27731 index b22d71c..d6e1049 100644
27732 --- a/drivers/atm/atmtcp.c
27733 +++ b/drivers/atm/atmtcp.c
27734 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27735 if (vcc->pop) vcc->pop(vcc,skb);
27736 else dev_kfree_skb(skb);
27737 if (dev_data) return 0;
27738 - atomic_inc(&vcc->stats->tx_err);
27739 + atomic_inc_unchecked(&vcc->stats->tx_err);
27740 return -ENOLINK;
27741 }
27742 size = skb->len+sizeof(struct atmtcp_hdr);
27743 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27744 if (!new_skb) {
27745 if (vcc->pop) vcc->pop(vcc,skb);
27746 else dev_kfree_skb(skb);
27747 - atomic_inc(&vcc->stats->tx_err);
27748 + atomic_inc_unchecked(&vcc->stats->tx_err);
27749 return -ENOBUFS;
27750 }
27751 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27752 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27753 if (vcc->pop) vcc->pop(vcc,skb);
27754 else dev_kfree_skb(skb);
27755 out_vcc->push(out_vcc,new_skb);
27756 - atomic_inc(&vcc->stats->tx);
27757 - atomic_inc(&out_vcc->stats->rx);
27758 + atomic_inc_unchecked(&vcc->stats->tx);
27759 + atomic_inc_unchecked(&out_vcc->stats->rx);
27760 return 0;
27761 }
27762
27763 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27764 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27765 read_unlock(&vcc_sklist_lock);
27766 if (!out_vcc) {
27767 - atomic_inc(&vcc->stats->tx_err);
27768 + atomic_inc_unchecked(&vcc->stats->tx_err);
27769 goto done;
27770 }
27771 skb_pull(skb,sizeof(struct atmtcp_hdr));
27772 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27773 __net_timestamp(new_skb);
27774 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27775 out_vcc->push(out_vcc,new_skb);
27776 - atomic_inc(&vcc->stats->tx);
27777 - atomic_inc(&out_vcc->stats->rx);
27778 + atomic_inc_unchecked(&vcc->stats->tx);
27779 + atomic_inc_unchecked(&out_vcc->stats->rx);
27780 done:
27781 if (vcc->pop) vcc->pop(vcc,skb);
27782 else dev_kfree_skb(skb);
27783 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27784 index 2059ee4..faf51c7 100644
27785 --- a/drivers/atm/eni.c
27786 +++ b/drivers/atm/eni.c
27787 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27788 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27789 vcc->dev->number);
27790 length = 0;
27791 - atomic_inc(&vcc->stats->rx_err);
27792 + atomic_inc_unchecked(&vcc->stats->rx_err);
27793 }
27794 else {
27795 length = ATM_CELL_SIZE-1; /* no HEC */
27796 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27797 size);
27798 }
27799 eff = length = 0;
27800 - atomic_inc(&vcc->stats->rx_err);
27801 + atomic_inc_unchecked(&vcc->stats->rx_err);
27802 }
27803 else {
27804 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27805 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27806 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27807 vcc->dev->number,vcc->vci,length,size << 2,descr);
27808 length = eff = 0;
27809 - atomic_inc(&vcc->stats->rx_err);
27810 + atomic_inc_unchecked(&vcc->stats->rx_err);
27811 }
27812 }
27813 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27814 @@ -767,7 +767,7 @@ rx_dequeued++;
27815 vcc->push(vcc,skb);
27816 pushed++;
27817 }
27818 - atomic_inc(&vcc->stats->rx);
27819 + atomic_inc_unchecked(&vcc->stats->rx);
27820 }
27821 wake_up(&eni_dev->rx_wait);
27822 }
27823 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27824 PCI_DMA_TODEVICE);
27825 if (vcc->pop) vcc->pop(vcc,skb);
27826 else dev_kfree_skb_irq(skb);
27827 - atomic_inc(&vcc->stats->tx);
27828 + atomic_inc_unchecked(&vcc->stats->tx);
27829 wake_up(&eni_dev->tx_wait);
27830 dma_complete++;
27831 }
27832 @@ -1567,7 +1567,7 @@ tx_complete++;
27833 /*--------------------------------- entries ---------------------------------*/
27834
27835
27836 -static const char *media_name[] __devinitdata = {
27837 +static const char *media_name[] __devinitconst = {
27838 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27839 "UTP", "05?", "06?", "07?", /* 4- 7 */
27840 "TAXI","09?", "10?", "11?", /* 8-11 */
27841 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27842 index 86fed1b..6dc4721 100644
27843 --- a/drivers/atm/firestream.c
27844 +++ b/drivers/atm/firestream.c
27845 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27846 }
27847 }
27848
27849 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27850 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27851
27852 fs_dprintk (FS_DEBUG_TXMEM, "i");
27853 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27854 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27855 #endif
27856 skb_put (skb, qe->p1 & 0xffff);
27857 ATM_SKB(skb)->vcc = atm_vcc;
27858 - atomic_inc(&atm_vcc->stats->rx);
27859 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27860 __net_timestamp(skb);
27861 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27862 atm_vcc->push (atm_vcc, skb);
27863 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27864 kfree (pe);
27865 }
27866 if (atm_vcc)
27867 - atomic_inc(&atm_vcc->stats->rx_drop);
27868 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27869 break;
27870 case 0x1f: /* Reassembly abort: no buffers. */
27871 /* Silently increment error counter. */
27872 if (atm_vcc)
27873 - atomic_inc(&atm_vcc->stats->rx_drop);
27874 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27875 break;
27876 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27877 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27878 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27879 index 361f5ae..7fc552d 100644
27880 --- a/drivers/atm/fore200e.c
27881 +++ b/drivers/atm/fore200e.c
27882 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27883 #endif
27884 /* check error condition */
27885 if (*entry->status & STATUS_ERROR)
27886 - atomic_inc(&vcc->stats->tx_err);
27887 + atomic_inc_unchecked(&vcc->stats->tx_err);
27888 else
27889 - atomic_inc(&vcc->stats->tx);
27890 + atomic_inc_unchecked(&vcc->stats->tx);
27891 }
27892 }
27893
27894 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27895 if (skb == NULL) {
27896 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27897
27898 - atomic_inc(&vcc->stats->rx_drop);
27899 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27900 return -ENOMEM;
27901 }
27902
27903 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27904
27905 dev_kfree_skb_any(skb);
27906
27907 - atomic_inc(&vcc->stats->rx_drop);
27908 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27909 return -ENOMEM;
27910 }
27911
27912 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27913
27914 vcc->push(vcc, skb);
27915 - atomic_inc(&vcc->stats->rx);
27916 + atomic_inc_unchecked(&vcc->stats->rx);
27917
27918 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27919
27920 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27921 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27922 fore200e->atm_dev->number,
27923 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27924 - atomic_inc(&vcc->stats->rx_err);
27925 + atomic_inc_unchecked(&vcc->stats->rx_err);
27926 }
27927 }
27928
27929 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27930 goto retry_here;
27931 }
27932
27933 - atomic_inc(&vcc->stats->tx_err);
27934 + atomic_inc_unchecked(&vcc->stats->tx_err);
27935
27936 fore200e->tx_sat++;
27937 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27938 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27939 index b182c2f..1c6fa8a 100644
27940 --- a/drivers/atm/he.c
27941 +++ b/drivers/atm/he.c
27942 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27943
27944 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27945 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27946 - atomic_inc(&vcc->stats->rx_drop);
27947 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27948 goto return_host_buffers;
27949 }
27950
27951 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27952 RBRQ_LEN_ERR(he_dev->rbrq_head)
27953 ? "LEN_ERR" : "",
27954 vcc->vpi, vcc->vci);
27955 - atomic_inc(&vcc->stats->rx_err);
27956 + atomic_inc_unchecked(&vcc->stats->rx_err);
27957 goto return_host_buffers;
27958 }
27959
27960 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27961 vcc->push(vcc, skb);
27962 spin_lock(&he_dev->global_lock);
27963
27964 - atomic_inc(&vcc->stats->rx);
27965 + atomic_inc_unchecked(&vcc->stats->rx);
27966
27967 return_host_buffers:
27968 ++pdus_assembled;
27969 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27970 tpd->vcc->pop(tpd->vcc, tpd->skb);
27971 else
27972 dev_kfree_skb_any(tpd->skb);
27973 - atomic_inc(&tpd->vcc->stats->tx_err);
27974 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27975 }
27976 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27977 return;
27978 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27979 vcc->pop(vcc, skb);
27980 else
27981 dev_kfree_skb_any(skb);
27982 - atomic_inc(&vcc->stats->tx_err);
27983 + atomic_inc_unchecked(&vcc->stats->tx_err);
27984 return -EINVAL;
27985 }
27986
27987 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27988 vcc->pop(vcc, skb);
27989 else
27990 dev_kfree_skb_any(skb);
27991 - atomic_inc(&vcc->stats->tx_err);
27992 + atomic_inc_unchecked(&vcc->stats->tx_err);
27993 return -EINVAL;
27994 }
27995 #endif
27996 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27997 vcc->pop(vcc, skb);
27998 else
27999 dev_kfree_skb_any(skb);
28000 - atomic_inc(&vcc->stats->tx_err);
28001 + atomic_inc_unchecked(&vcc->stats->tx_err);
28002 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28003 return -ENOMEM;
28004 }
28005 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28006 vcc->pop(vcc, skb);
28007 else
28008 dev_kfree_skb_any(skb);
28009 - atomic_inc(&vcc->stats->tx_err);
28010 + atomic_inc_unchecked(&vcc->stats->tx_err);
28011 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28012 return -ENOMEM;
28013 }
28014 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28015 __enqueue_tpd(he_dev, tpd, cid);
28016 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28017
28018 - atomic_inc(&vcc->stats->tx);
28019 + atomic_inc_unchecked(&vcc->stats->tx);
28020
28021 return 0;
28022 }
28023 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28024 index 7d01c2a..4e3ac01 100644
28025 --- a/drivers/atm/horizon.c
28026 +++ b/drivers/atm/horizon.c
28027 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28028 {
28029 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28030 // VC layer stats
28031 - atomic_inc(&vcc->stats->rx);
28032 + atomic_inc_unchecked(&vcc->stats->rx);
28033 __net_timestamp(skb);
28034 // end of our responsibility
28035 vcc->push (vcc, skb);
28036 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28037 dev->tx_iovec = NULL;
28038
28039 // VC layer stats
28040 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28041 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28042
28043 // free the skb
28044 hrz_kfree_skb (skb);
28045 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28046 index 8974bd2..b856f85 100644
28047 --- a/drivers/atm/idt77252.c
28048 +++ b/drivers/atm/idt77252.c
28049 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28050 else
28051 dev_kfree_skb(skb);
28052
28053 - atomic_inc(&vcc->stats->tx);
28054 + atomic_inc_unchecked(&vcc->stats->tx);
28055 }
28056
28057 atomic_dec(&scq->used);
28058 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28059 if ((sb = dev_alloc_skb(64)) == NULL) {
28060 printk("%s: Can't allocate buffers for aal0.\n",
28061 card->name);
28062 - atomic_add(i, &vcc->stats->rx_drop);
28063 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28064 break;
28065 }
28066 if (!atm_charge(vcc, sb->truesize)) {
28067 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28068 card->name);
28069 - atomic_add(i - 1, &vcc->stats->rx_drop);
28070 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28071 dev_kfree_skb(sb);
28072 break;
28073 }
28074 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28075 ATM_SKB(sb)->vcc = vcc;
28076 __net_timestamp(sb);
28077 vcc->push(vcc, sb);
28078 - atomic_inc(&vcc->stats->rx);
28079 + atomic_inc_unchecked(&vcc->stats->rx);
28080
28081 cell += ATM_CELL_PAYLOAD;
28082 }
28083 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28084 "(CDC: %08x)\n",
28085 card->name, len, rpp->len, readl(SAR_REG_CDC));
28086 recycle_rx_pool_skb(card, rpp);
28087 - atomic_inc(&vcc->stats->rx_err);
28088 + atomic_inc_unchecked(&vcc->stats->rx_err);
28089 return;
28090 }
28091 if (stat & SAR_RSQE_CRC) {
28092 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28093 recycle_rx_pool_skb(card, rpp);
28094 - atomic_inc(&vcc->stats->rx_err);
28095 + atomic_inc_unchecked(&vcc->stats->rx_err);
28096 return;
28097 }
28098 if (skb_queue_len(&rpp->queue) > 1) {
28099 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28100 RXPRINTK("%s: Can't alloc RX skb.\n",
28101 card->name);
28102 recycle_rx_pool_skb(card, rpp);
28103 - atomic_inc(&vcc->stats->rx_err);
28104 + atomic_inc_unchecked(&vcc->stats->rx_err);
28105 return;
28106 }
28107 if (!atm_charge(vcc, skb->truesize)) {
28108 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28109 __net_timestamp(skb);
28110
28111 vcc->push(vcc, skb);
28112 - atomic_inc(&vcc->stats->rx);
28113 + atomic_inc_unchecked(&vcc->stats->rx);
28114
28115 return;
28116 }
28117 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28118 __net_timestamp(skb);
28119
28120 vcc->push(vcc, skb);
28121 - atomic_inc(&vcc->stats->rx);
28122 + atomic_inc_unchecked(&vcc->stats->rx);
28123
28124 if (skb->truesize > SAR_FB_SIZE_3)
28125 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28126 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28127 if (vcc->qos.aal != ATM_AAL0) {
28128 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28129 card->name, vpi, vci);
28130 - atomic_inc(&vcc->stats->rx_drop);
28131 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28132 goto drop;
28133 }
28134
28135 if ((sb = dev_alloc_skb(64)) == NULL) {
28136 printk("%s: Can't allocate buffers for AAL0.\n",
28137 card->name);
28138 - atomic_inc(&vcc->stats->rx_err);
28139 + atomic_inc_unchecked(&vcc->stats->rx_err);
28140 goto drop;
28141 }
28142
28143 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28144 ATM_SKB(sb)->vcc = vcc;
28145 __net_timestamp(sb);
28146 vcc->push(vcc, sb);
28147 - atomic_inc(&vcc->stats->rx);
28148 + atomic_inc_unchecked(&vcc->stats->rx);
28149
28150 drop:
28151 skb_pull(queue, 64);
28152 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28153
28154 if (vc == NULL) {
28155 printk("%s: NULL connection in send().\n", card->name);
28156 - atomic_inc(&vcc->stats->tx_err);
28157 + atomic_inc_unchecked(&vcc->stats->tx_err);
28158 dev_kfree_skb(skb);
28159 return -EINVAL;
28160 }
28161 if (!test_bit(VCF_TX, &vc->flags)) {
28162 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28163 - atomic_inc(&vcc->stats->tx_err);
28164 + atomic_inc_unchecked(&vcc->stats->tx_err);
28165 dev_kfree_skb(skb);
28166 return -EINVAL;
28167 }
28168 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28169 break;
28170 default:
28171 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28172 - atomic_inc(&vcc->stats->tx_err);
28173 + atomic_inc_unchecked(&vcc->stats->tx_err);
28174 dev_kfree_skb(skb);
28175 return -EINVAL;
28176 }
28177
28178 if (skb_shinfo(skb)->nr_frags != 0) {
28179 printk("%s: No scatter-gather yet.\n", card->name);
28180 - atomic_inc(&vcc->stats->tx_err);
28181 + atomic_inc_unchecked(&vcc->stats->tx_err);
28182 dev_kfree_skb(skb);
28183 return -EINVAL;
28184 }
28185 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28186
28187 err = queue_skb(card, vc, skb, oam);
28188 if (err) {
28189 - atomic_inc(&vcc->stats->tx_err);
28190 + atomic_inc_unchecked(&vcc->stats->tx_err);
28191 dev_kfree_skb(skb);
28192 return err;
28193 }
28194 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28195 skb = dev_alloc_skb(64);
28196 if (!skb) {
28197 printk("%s: Out of memory in send_oam().\n", card->name);
28198 - atomic_inc(&vcc->stats->tx_err);
28199 + atomic_inc_unchecked(&vcc->stats->tx_err);
28200 return -ENOMEM;
28201 }
28202 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28203 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28204 index d438601..8b98495 100644
28205 --- a/drivers/atm/iphase.c
28206 +++ b/drivers/atm/iphase.c
28207 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28208 status = (u_short) (buf_desc_ptr->desc_mode);
28209 if (status & (RX_CER | RX_PTE | RX_OFL))
28210 {
28211 - atomic_inc(&vcc->stats->rx_err);
28212 + atomic_inc_unchecked(&vcc->stats->rx_err);
28213 IF_ERR(printk("IA: bad packet, dropping it");)
28214 if (status & RX_CER) {
28215 IF_ERR(printk(" cause: packet CRC error\n");)
28216 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28217 len = dma_addr - buf_addr;
28218 if (len > iadev->rx_buf_sz) {
28219 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28220 - atomic_inc(&vcc->stats->rx_err);
28221 + atomic_inc_unchecked(&vcc->stats->rx_err);
28222 goto out_free_desc;
28223 }
28224
28225 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28226 ia_vcc = INPH_IA_VCC(vcc);
28227 if (ia_vcc == NULL)
28228 {
28229 - atomic_inc(&vcc->stats->rx_err);
28230 + atomic_inc_unchecked(&vcc->stats->rx_err);
28231 atm_return(vcc, skb->truesize);
28232 dev_kfree_skb_any(skb);
28233 goto INCR_DLE;
28234 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28235 if ((length > iadev->rx_buf_sz) || (length >
28236 (skb->len - sizeof(struct cpcs_trailer))))
28237 {
28238 - atomic_inc(&vcc->stats->rx_err);
28239 + atomic_inc_unchecked(&vcc->stats->rx_err);
28240 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28241 length, skb->len);)
28242 atm_return(vcc, skb->truesize);
28243 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28244
28245 IF_RX(printk("rx_dle_intr: skb push");)
28246 vcc->push(vcc,skb);
28247 - atomic_inc(&vcc->stats->rx);
28248 + atomic_inc_unchecked(&vcc->stats->rx);
28249 iadev->rx_pkt_cnt++;
28250 }
28251 INCR_DLE:
28252 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28253 {
28254 struct k_sonet_stats *stats;
28255 stats = &PRIV(_ia_dev[board])->sonet_stats;
28256 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28257 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28258 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28259 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28260 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28261 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28262 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28263 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28264 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28265 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28266 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28267 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28268 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28269 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28270 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28271 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28272 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28273 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28274 }
28275 ia_cmds.status = 0;
28276 break;
28277 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28278 if ((desc == 0) || (desc > iadev->num_tx_desc))
28279 {
28280 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28281 - atomic_inc(&vcc->stats->tx);
28282 + atomic_inc_unchecked(&vcc->stats->tx);
28283 if (vcc->pop)
28284 vcc->pop(vcc, skb);
28285 else
28286 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28287 ATM_DESC(skb) = vcc->vci;
28288 skb_queue_tail(&iadev->tx_dma_q, skb);
28289
28290 - atomic_inc(&vcc->stats->tx);
28291 + atomic_inc_unchecked(&vcc->stats->tx);
28292 iadev->tx_pkt_cnt++;
28293 /* Increment transaction counter */
28294 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28295
28296 #if 0
28297 /* add flow control logic */
28298 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28299 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28300 if (iavcc->vc_desc_cnt > 10) {
28301 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28302 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28303 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28304 index 68c7588..7036683 100644
28305 --- a/drivers/atm/lanai.c
28306 +++ b/drivers/atm/lanai.c
28307 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28308 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28309 lanai_endtx(lanai, lvcc);
28310 lanai_free_skb(lvcc->tx.atmvcc, skb);
28311 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28312 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28313 }
28314
28315 /* Try to fill the buffer - don't call unless there is backlog */
28316 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28317 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28318 __net_timestamp(skb);
28319 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28320 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28321 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28322 out:
28323 lvcc->rx.buf.ptr = end;
28324 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28325 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28326 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28327 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28328 lanai->stats.service_rxnotaal5++;
28329 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28330 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28331 return 0;
28332 }
28333 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28334 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28335 int bytes;
28336 read_unlock(&vcc_sklist_lock);
28337 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28338 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28339 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28340 lvcc->stats.x.aal5.service_trash++;
28341 bytes = (SERVICE_GET_END(s) * 16) -
28342 (((unsigned long) lvcc->rx.buf.ptr) -
28343 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28344 }
28345 if (s & SERVICE_STREAM) {
28346 read_unlock(&vcc_sklist_lock);
28347 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28348 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28349 lvcc->stats.x.aal5.service_stream++;
28350 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28351 "PDU on VCI %d!\n", lanai->number, vci);
28352 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28353 return 0;
28354 }
28355 DPRINTK("got rx crc error on vci %d\n", vci);
28356 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28357 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28358 lvcc->stats.x.aal5.service_rxcrc++;
28359 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28360 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28361 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28362 index 1c70c45..300718d 100644
28363 --- a/drivers/atm/nicstar.c
28364 +++ b/drivers/atm/nicstar.c
28365 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28366 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28367 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28368 card->index);
28369 - atomic_inc(&vcc->stats->tx_err);
28370 + atomic_inc_unchecked(&vcc->stats->tx_err);
28371 dev_kfree_skb_any(skb);
28372 return -EINVAL;
28373 }
28374 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28375 if (!vc->tx) {
28376 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28377 card->index);
28378 - atomic_inc(&vcc->stats->tx_err);
28379 + atomic_inc_unchecked(&vcc->stats->tx_err);
28380 dev_kfree_skb_any(skb);
28381 return -EINVAL;
28382 }
28383 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28384 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28385 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28386 card->index);
28387 - atomic_inc(&vcc->stats->tx_err);
28388 + atomic_inc_unchecked(&vcc->stats->tx_err);
28389 dev_kfree_skb_any(skb);
28390 return -EINVAL;
28391 }
28392
28393 if (skb_shinfo(skb)->nr_frags != 0) {
28394 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28395 - atomic_inc(&vcc->stats->tx_err);
28396 + atomic_inc_unchecked(&vcc->stats->tx_err);
28397 dev_kfree_skb_any(skb);
28398 return -EINVAL;
28399 }
28400 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28401 }
28402
28403 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28404 - atomic_inc(&vcc->stats->tx_err);
28405 + atomic_inc_unchecked(&vcc->stats->tx_err);
28406 dev_kfree_skb_any(skb);
28407 return -EIO;
28408 }
28409 - atomic_inc(&vcc->stats->tx);
28410 + atomic_inc_unchecked(&vcc->stats->tx);
28411
28412 return 0;
28413 }
28414 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28415 printk
28416 ("nicstar%d: Can't allocate buffers for aal0.\n",
28417 card->index);
28418 - atomic_add(i, &vcc->stats->rx_drop);
28419 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28420 break;
28421 }
28422 if (!atm_charge(vcc, sb->truesize)) {
28423 RXPRINTK
28424 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28425 card->index);
28426 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28427 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28428 dev_kfree_skb_any(sb);
28429 break;
28430 }
28431 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28432 ATM_SKB(sb)->vcc = vcc;
28433 __net_timestamp(sb);
28434 vcc->push(vcc, sb);
28435 - atomic_inc(&vcc->stats->rx);
28436 + atomic_inc_unchecked(&vcc->stats->rx);
28437 cell += ATM_CELL_PAYLOAD;
28438 }
28439
28440 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28441 if (iovb == NULL) {
28442 printk("nicstar%d: Out of iovec buffers.\n",
28443 card->index);
28444 - atomic_inc(&vcc->stats->rx_drop);
28445 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28446 recycle_rx_buf(card, skb);
28447 return;
28448 }
28449 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28450 small or large buffer itself. */
28451 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28452 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28453 - atomic_inc(&vcc->stats->rx_err);
28454 + atomic_inc_unchecked(&vcc->stats->rx_err);
28455 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28456 NS_MAX_IOVECS);
28457 NS_PRV_IOVCNT(iovb) = 0;
28458 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28459 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28460 card->index);
28461 which_list(card, skb);
28462 - atomic_inc(&vcc->stats->rx_err);
28463 + atomic_inc_unchecked(&vcc->stats->rx_err);
28464 recycle_rx_buf(card, skb);
28465 vc->rx_iov = NULL;
28466 recycle_iov_buf(card, iovb);
28467 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28468 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28469 card->index);
28470 which_list(card, skb);
28471 - atomic_inc(&vcc->stats->rx_err);
28472 + atomic_inc_unchecked(&vcc->stats->rx_err);
28473 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28474 NS_PRV_IOVCNT(iovb));
28475 vc->rx_iov = NULL;
28476 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28477 printk(" - PDU size mismatch.\n");
28478 else
28479 printk(".\n");
28480 - atomic_inc(&vcc->stats->rx_err);
28481 + atomic_inc_unchecked(&vcc->stats->rx_err);
28482 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28483 NS_PRV_IOVCNT(iovb));
28484 vc->rx_iov = NULL;
28485 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28486 /* skb points to a small buffer */
28487 if (!atm_charge(vcc, skb->truesize)) {
28488 push_rxbufs(card, skb);
28489 - atomic_inc(&vcc->stats->rx_drop);
28490 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28491 } else {
28492 skb_put(skb, len);
28493 dequeue_sm_buf(card, skb);
28494 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28495 ATM_SKB(skb)->vcc = vcc;
28496 __net_timestamp(skb);
28497 vcc->push(vcc, skb);
28498 - atomic_inc(&vcc->stats->rx);
28499 + atomic_inc_unchecked(&vcc->stats->rx);
28500 }
28501 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28502 struct sk_buff *sb;
28503 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28504 if (len <= NS_SMBUFSIZE) {
28505 if (!atm_charge(vcc, sb->truesize)) {
28506 push_rxbufs(card, sb);
28507 - atomic_inc(&vcc->stats->rx_drop);
28508 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28509 } else {
28510 skb_put(sb, len);
28511 dequeue_sm_buf(card, sb);
28512 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28513 ATM_SKB(sb)->vcc = vcc;
28514 __net_timestamp(sb);
28515 vcc->push(vcc, sb);
28516 - atomic_inc(&vcc->stats->rx);
28517 + atomic_inc_unchecked(&vcc->stats->rx);
28518 }
28519
28520 push_rxbufs(card, skb);
28521 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28522
28523 if (!atm_charge(vcc, skb->truesize)) {
28524 push_rxbufs(card, skb);
28525 - atomic_inc(&vcc->stats->rx_drop);
28526 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28527 } else {
28528 dequeue_lg_buf(card, skb);
28529 #ifdef NS_USE_DESTRUCTORS
28530 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28531 ATM_SKB(skb)->vcc = vcc;
28532 __net_timestamp(skb);
28533 vcc->push(vcc, skb);
28534 - atomic_inc(&vcc->stats->rx);
28535 + atomic_inc_unchecked(&vcc->stats->rx);
28536 }
28537
28538 push_rxbufs(card, sb);
28539 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28540 printk
28541 ("nicstar%d: Out of huge buffers.\n",
28542 card->index);
28543 - atomic_inc(&vcc->stats->rx_drop);
28544 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28545 recycle_iovec_rx_bufs(card,
28546 (struct iovec *)
28547 iovb->data,
28548 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28549 card->hbpool.count++;
28550 } else
28551 dev_kfree_skb_any(hb);
28552 - atomic_inc(&vcc->stats->rx_drop);
28553 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28554 } else {
28555 /* Copy the small buffer to the huge buffer */
28556 sb = (struct sk_buff *)iov->iov_base;
28557 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28558 #endif /* NS_USE_DESTRUCTORS */
28559 __net_timestamp(hb);
28560 vcc->push(vcc, hb);
28561 - atomic_inc(&vcc->stats->rx);
28562 + atomic_inc_unchecked(&vcc->stats->rx);
28563 }
28564 }
28565
28566 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28567 index 9851093..adb2b1e 100644
28568 --- a/drivers/atm/solos-pci.c
28569 +++ b/drivers/atm/solos-pci.c
28570 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28571 }
28572 atm_charge(vcc, skb->truesize);
28573 vcc->push(vcc, skb);
28574 - atomic_inc(&vcc->stats->rx);
28575 + atomic_inc_unchecked(&vcc->stats->rx);
28576 break;
28577
28578 case PKT_STATUS:
28579 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28580 vcc = SKB_CB(oldskb)->vcc;
28581
28582 if (vcc) {
28583 - atomic_inc(&vcc->stats->tx);
28584 + atomic_inc_unchecked(&vcc->stats->tx);
28585 solos_pop(vcc, oldskb);
28586 } else
28587 dev_kfree_skb_irq(oldskb);
28588 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28589 index 0215934..ce9f5b1 100644
28590 --- a/drivers/atm/suni.c
28591 +++ b/drivers/atm/suni.c
28592 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28593
28594
28595 #define ADD_LIMITED(s,v) \
28596 - atomic_add((v),&stats->s); \
28597 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28598 + atomic_add_unchecked((v),&stats->s); \
28599 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28600
28601
28602 static void suni_hz(unsigned long from_timer)
28603 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28604 index 5120a96..e2572bd 100644
28605 --- a/drivers/atm/uPD98402.c
28606 +++ b/drivers/atm/uPD98402.c
28607 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28608 struct sonet_stats tmp;
28609 int error = 0;
28610
28611 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28612 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28613 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28614 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28615 if (zero && !error) {
28616 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28617
28618
28619 #define ADD_LIMITED(s,v) \
28620 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28621 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28622 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28623 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28624 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28625 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28626
28627
28628 static void stat_event(struct atm_dev *dev)
28629 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28630 if (reason & uPD98402_INT_PFM) stat_event(dev);
28631 if (reason & uPD98402_INT_PCO) {
28632 (void) GET(PCOCR); /* clear interrupt cause */
28633 - atomic_add(GET(HECCT),
28634 + atomic_add_unchecked(GET(HECCT),
28635 &PRIV(dev)->sonet_stats.uncorr_hcs);
28636 }
28637 if ((reason & uPD98402_INT_RFO) &&
28638 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28639 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28640 uPD98402_INT_LOS),PIMR); /* enable them */
28641 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28642 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28643 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28644 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28645 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28646 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28647 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28648 return 0;
28649 }
28650
28651 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28652 index abe4e20..83c4727 100644
28653 --- a/drivers/atm/zatm.c
28654 +++ b/drivers/atm/zatm.c
28655 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28656 }
28657 if (!size) {
28658 dev_kfree_skb_irq(skb);
28659 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28660 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28661 continue;
28662 }
28663 if (!atm_charge(vcc,skb->truesize)) {
28664 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28665 skb->len = size;
28666 ATM_SKB(skb)->vcc = vcc;
28667 vcc->push(vcc,skb);
28668 - atomic_inc(&vcc->stats->rx);
28669 + atomic_inc_unchecked(&vcc->stats->rx);
28670 }
28671 zout(pos & 0xffff,MTA(mbx));
28672 #if 0 /* probably a stupid idea */
28673 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28674 skb_queue_head(&zatm_vcc->backlog,skb);
28675 break;
28676 }
28677 - atomic_inc(&vcc->stats->tx);
28678 + atomic_inc_unchecked(&vcc->stats->tx);
28679 wake_up(&zatm_vcc->tx_wait);
28680 }
28681
28682 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28683 index 765c3a2..771ace6 100644
28684 --- a/drivers/base/devtmpfs.c
28685 +++ b/drivers/base/devtmpfs.c
28686 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28687 if (!thread)
28688 return 0;
28689
28690 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28691 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28692 if (err)
28693 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28694 else
28695 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28696 index cbb463b..babe2cf 100644
28697 --- a/drivers/base/power/wakeup.c
28698 +++ b/drivers/base/power/wakeup.c
28699 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28700 * They need to be modified together atomically, so it's better to use one
28701 * atomic variable to hold them both.
28702 */
28703 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28704 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28705
28706 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28707 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28708
28709 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28710 {
28711 - unsigned int comb = atomic_read(&combined_event_count);
28712 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28713
28714 *cnt = (comb >> IN_PROGRESS_BITS);
28715 *inpr = comb & MAX_IN_PROGRESS;
28716 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28717 ws->start_prevent_time = ws->last_time;
28718
28719 /* Increment the counter of events in progress. */
28720 - cec = atomic_inc_return(&combined_event_count);
28721 + cec = atomic_inc_return_unchecked(&combined_event_count);
28722
28723 trace_wakeup_source_activate(ws->name, cec);
28724 }
28725 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28726 * Increment the counter of registered wakeup events and decrement the
28727 * couter of wakeup events in progress simultaneously.
28728 */
28729 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28730 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28731 trace_wakeup_source_deactivate(ws->name, cec);
28732
28733 split_counters(&cnt, &inpr);
28734 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28735 index b0f553b..77b928b 100644
28736 --- a/drivers/block/cciss.c
28737 +++ b/drivers/block/cciss.c
28738 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28739 int err;
28740 u32 cp;
28741
28742 + memset(&arg64, 0, sizeof(arg64));
28743 +
28744 err = 0;
28745 err |=
28746 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28747 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28748 while (!list_empty(&h->reqQ)) {
28749 c = list_entry(h->reqQ.next, CommandList_struct, list);
28750 /* can't do anything if fifo is full */
28751 - if ((h->access.fifo_full(h))) {
28752 + if ((h->access->fifo_full(h))) {
28753 dev_warn(&h->pdev->dev, "fifo full\n");
28754 break;
28755 }
28756 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28757 h->Qdepth--;
28758
28759 /* Tell the controller execute command */
28760 - h->access.submit_command(h, c);
28761 + h->access->submit_command(h, c);
28762
28763 /* Put job onto the completed Q */
28764 addQ(&h->cmpQ, c);
28765 @@ -3443,17 +3445,17 @@ startio:
28766
28767 static inline unsigned long get_next_completion(ctlr_info_t *h)
28768 {
28769 - return h->access.command_completed(h);
28770 + return h->access->command_completed(h);
28771 }
28772
28773 static inline int interrupt_pending(ctlr_info_t *h)
28774 {
28775 - return h->access.intr_pending(h);
28776 + return h->access->intr_pending(h);
28777 }
28778
28779 static inline long interrupt_not_for_us(ctlr_info_t *h)
28780 {
28781 - return ((h->access.intr_pending(h) == 0) ||
28782 + return ((h->access->intr_pending(h) == 0) ||
28783 (h->interrupts_enabled == 0));
28784 }
28785
28786 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28787 u32 a;
28788
28789 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28790 - return h->access.command_completed(h);
28791 + return h->access->command_completed(h);
28792
28793 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28794 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28795 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28796 trans_support & CFGTBL_Trans_use_short_tags);
28797
28798 /* Change the access methods to the performant access methods */
28799 - h->access = SA5_performant_access;
28800 + h->access = &SA5_performant_access;
28801 h->transMethod = CFGTBL_Trans_Performant;
28802
28803 return;
28804 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28805 if (prod_index < 0)
28806 return -ENODEV;
28807 h->product_name = products[prod_index].product_name;
28808 - h->access = *(products[prod_index].access);
28809 + h->access = products[prod_index].access;
28810
28811 if (cciss_board_disabled(h)) {
28812 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28813 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28814 }
28815
28816 /* make sure the board interrupts are off */
28817 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28818 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28819 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28820 if (rc)
28821 goto clean2;
28822 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28823 * fake ones to scoop up any residual completions.
28824 */
28825 spin_lock_irqsave(&h->lock, flags);
28826 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28827 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28828 spin_unlock_irqrestore(&h->lock, flags);
28829 free_irq(h->intr[h->intr_mode], h);
28830 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28831 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28832 dev_info(&h->pdev->dev, "Board READY.\n");
28833 dev_info(&h->pdev->dev,
28834 "Waiting for stale completions to drain.\n");
28835 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28836 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28837 msleep(10000);
28838 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28839 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28840
28841 rc = controller_reset_failed(h->cfgtable);
28842 if (rc)
28843 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28844 cciss_scsi_setup(h);
28845
28846 /* Turn the interrupts on so we can service requests */
28847 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28848 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28849
28850 /* Get the firmware version */
28851 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28852 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28853 kfree(flush_buf);
28854 if (return_code != IO_OK)
28855 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28856 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28857 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28858 free_irq(h->intr[h->intr_mode], h);
28859 }
28860
28861 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28862 index 7fda30e..eb5dfe0 100644
28863 --- a/drivers/block/cciss.h
28864 +++ b/drivers/block/cciss.h
28865 @@ -101,7 +101,7 @@ struct ctlr_info
28866 /* information about each logical volume */
28867 drive_info_struct *drv[CISS_MAX_LUN];
28868
28869 - struct access_method access;
28870 + struct access_method *access;
28871
28872 /* queue and queue Info */
28873 struct list_head reqQ;
28874 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28875 index 9125bbe..eede5c8 100644
28876 --- a/drivers/block/cpqarray.c
28877 +++ b/drivers/block/cpqarray.c
28878 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28879 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28880 goto Enomem4;
28881 }
28882 - hba[i]->access.set_intr_mask(hba[i], 0);
28883 + hba[i]->access->set_intr_mask(hba[i], 0);
28884 if (request_irq(hba[i]->intr, do_ida_intr,
28885 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28886 {
28887 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28888 add_timer(&hba[i]->timer);
28889
28890 /* Enable IRQ now that spinlock and rate limit timer are set up */
28891 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28892 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28893
28894 for(j=0; j<NWD; j++) {
28895 struct gendisk *disk = ida_gendisk[i][j];
28896 @@ -694,7 +694,7 @@ DBGINFO(
28897 for(i=0; i<NR_PRODUCTS; i++) {
28898 if (board_id == products[i].board_id) {
28899 c->product_name = products[i].product_name;
28900 - c->access = *(products[i].access);
28901 + c->access = products[i].access;
28902 break;
28903 }
28904 }
28905 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28906 hba[ctlr]->intr = intr;
28907 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28908 hba[ctlr]->product_name = products[j].product_name;
28909 - hba[ctlr]->access = *(products[j].access);
28910 + hba[ctlr]->access = products[j].access;
28911 hba[ctlr]->ctlr = ctlr;
28912 hba[ctlr]->board_id = board_id;
28913 hba[ctlr]->pci_dev = NULL; /* not PCI */
28914 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28915
28916 while((c = h->reqQ) != NULL) {
28917 /* Can't do anything if we're busy */
28918 - if (h->access.fifo_full(h) == 0)
28919 + if (h->access->fifo_full(h) == 0)
28920 return;
28921
28922 /* Get the first entry from the request Q */
28923 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28924 h->Qdepth--;
28925
28926 /* Tell the controller to do our bidding */
28927 - h->access.submit_command(h, c);
28928 + h->access->submit_command(h, c);
28929
28930 /* Get onto the completion Q */
28931 addQ(&h->cmpQ, c);
28932 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28933 unsigned long flags;
28934 __u32 a,a1;
28935
28936 - istat = h->access.intr_pending(h);
28937 + istat = h->access->intr_pending(h);
28938 /* Is this interrupt for us? */
28939 if (istat == 0)
28940 return IRQ_NONE;
28941 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28942 */
28943 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28944 if (istat & FIFO_NOT_EMPTY) {
28945 - while((a = h->access.command_completed(h))) {
28946 + while((a = h->access->command_completed(h))) {
28947 a1 = a; a &= ~3;
28948 if ((c = h->cmpQ) == NULL)
28949 {
28950 @@ -1449,11 +1449,11 @@ static int sendcmd(
28951 /*
28952 * Disable interrupt
28953 */
28954 - info_p->access.set_intr_mask(info_p, 0);
28955 + info_p->access->set_intr_mask(info_p, 0);
28956 /* Make sure there is room in the command FIFO */
28957 /* Actually it should be completely empty at this time. */
28958 for (i = 200000; i > 0; i--) {
28959 - temp = info_p->access.fifo_full(info_p);
28960 + temp = info_p->access->fifo_full(info_p);
28961 if (temp != 0) {
28962 break;
28963 }
28964 @@ -1466,7 +1466,7 @@ DBG(
28965 /*
28966 * Send the cmd
28967 */
28968 - info_p->access.submit_command(info_p, c);
28969 + info_p->access->submit_command(info_p, c);
28970 complete = pollcomplete(ctlr);
28971
28972 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28973 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28974 * we check the new geometry. Then turn interrupts back on when
28975 * we're done.
28976 */
28977 - host->access.set_intr_mask(host, 0);
28978 + host->access->set_intr_mask(host, 0);
28979 getgeometry(ctlr);
28980 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28981 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28982
28983 for(i=0; i<NWD; i++) {
28984 struct gendisk *disk = ida_gendisk[ctlr][i];
28985 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28986 /* Wait (up to 2 seconds) for a command to complete */
28987
28988 for (i = 200000; i > 0; i--) {
28989 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
28990 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
28991 if (done == 0) {
28992 udelay(10); /* a short fixed delay */
28993 } else
28994 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28995 index be73e9d..7fbf140 100644
28996 --- a/drivers/block/cpqarray.h
28997 +++ b/drivers/block/cpqarray.h
28998 @@ -99,7 +99,7 @@ struct ctlr_info {
28999 drv_info_t drv[NWD];
29000 struct proc_dir_entry *proc;
29001
29002 - struct access_method access;
29003 + struct access_method *access;
29004
29005 cmdlist_t *reqQ;
29006 cmdlist_t *cmpQ;
29007 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29008 index 02f013a..afeba24 100644
29009 --- a/drivers/block/drbd/drbd_int.h
29010 +++ b/drivers/block/drbd/drbd_int.h
29011 @@ -735,7 +735,7 @@ struct drbd_request;
29012 struct drbd_epoch {
29013 struct list_head list;
29014 unsigned int barrier_nr;
29015 - atomic_t epoch_size; /* increased on every request added. */
29016 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29017 atomic_t active; /* increased on every req. added, and dec on every finished. */
29018 unsigned long flags;
29019 };
29020 @@ -1110,7 +1110,7 @@ struct drbd_conf {
29021 void *int_dig_in;
29022 void *int_dig_vv;
29023 wait_queue_head_t seq_wait;
29024 - atomic_t packet_seq;
29025 + atomic_unchecked_t packet_seq;
29026 unsigned int peer_seq;
29027 spinlock_t peer_seq_lock;
29028 unsigned int minor;
29029 @@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29030
29031 static inline void drbd_tcp_cork(struct socket *sock)
29032 {
29033 - int __user val = 1;
29034 + int val = 1;
29035 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29036 - (char __user *)&val, sizeof(val));
29037 + (char __force_user *)&val, sizeof(val));
29038 }
29039
29040 static inline void drbd_tcp_uncork(struct socket *sock)
29041 {
29042 - int __user val = 0;
29043 + int val = 0;
29044 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29045 - (char __user *)&val, sizeof(val));
29046 + (char __force_user *)&val, sizeof(val));
29047 }
29048
29049 static inline void drbd_tcp_nodelay(struct socket *sock)
29050 {
29051 - int __user val = 1;
29052 + int val = 1;
29053 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29054 - (char __user *)&val, sizeof(val));
29055 + (char __force_user *)&val, sizeof(val));
29056 }
29057
29058 static inline void drbd_tcp_quickack(struct socket *sock)
29059 {
29060 - int __user val = 2;
29061 + int val = 2;
29062 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29063 - (char __user *)&val, sizeof(val));
29064 + (char __force_user *)&val, sizeof(val));
29065 }
29066
29067 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29068 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29069 index 920ede2..cb827ba 100644
29070 --- a/drivers/block/drbd/drbd_main.c
29071 +++ b/drivers/block/drbd/drbd_main.c
29072 @@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29073 p.sector = sector;
29074 p.block_id = block_id;
29075 p.blksize = blksize;
29076 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29077 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29078
29079 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29080 return false;
29081 @@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29082
29083 p.sector = cpu_to_be64(req->sector);
29084 p.block_id = (unsigned long)req;
29085 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29086 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29087
29088 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29089
29090 @@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29091 atomic_set(&mdev->unacked_cnt, 0);
29092 atomic_set(&mdev->local_cnt, 0);
29093 atomic_set(&mdev->net_cnt, 0);
29094 - atomic_set(&mdev->packet_seq, 0);
29095 + atomic_set_unchecked(&mdev->packet_seq, 0);
29096 atomic_set(&mdev->pp_in_use, 0);
29097 atomic_set(&mdev->pp_in_use_by_net, 0);
29098 atomic_set(&mdev->rs_sect_in, 0);
29099 @@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29100 mdev->receiver.t_state);
29101
29102 /* no need to lock it, I'm the only thread alive */
29103 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29104 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29105 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29106 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29107 mdev->al_writ_cnt =
29108 mdev->bm_writ_cnt =
29109 mdev->read_cnt =
29110 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29111 index 6d4de6a..7b7ad4b 100644
29112 --- a/drivers/block/drbd/drbd_nl.c
29113 +++ b/drivers/block/drbd/drbd_nl.c
29114 @@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29115 module_put(THIS_MODULE);
29116 }
29117
29118 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29119 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29120
29121 static unsigned short *
29122 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29123 @@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29124 cn_reply->id.idx = CN_IDX_DRBD;
29125 cn_reply->id.val = CN_VAL_DRBD;
29126
29127 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29128 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29129 cn_reply->ack = 0; /* not used here. */
29130 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29131 (int)((char *)tl - (char *)reply->tag_list);
29132 @@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29133 cn_reply->id.idx = CN_IDX_DRBD;
29134 cn_reply->id.val = CN_VAL_DRBD;
29135
29136 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29137 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29138 cn_reply->ack = 0; /* not used here. */
29139 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29140 (int)((char *)tl - (char *)reply->tag_list);
29141 @@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29142 cn_reply->id.idx = CN_IDX_DRBD;
29143 cn_reply->id.val = CN_VAL_DRBD;
29144
29145 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29146 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29147 cn_reply->ack = 0; // not used here.
29148 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29149 (int)((char*)tl - (char*)reply->tag_list);
29150 @@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29151 cn_reply->id.idx = CN_IDX_DRBD;
29152 cn_reply->id.val = CN_VAL_DRBD;
29153
29154 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29155 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29156 cn_reply->ack = 0; /* not used here. */
29157 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29158 (int)((char *)tl - (char *)reply->tag_list);
29159 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29160 index ea4836e..272d72a 100644
29161 --- a/drivers/block/drbd/drbd_receiver.c
29162 +++ b/drivers/block/drbd/drbd_receiver.c
29163 @@ -893,7 +893,7 @@ retry:
29164 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29165 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29166
29167 - atomic_set(&mdev->packet_seq, 0);
29168 + atomic_set_unchecked(&mdev->packet_seq, 0);
29169 mdev->peer_seq = 0;
29170
29171 if (drbd_send_protocol(mdev) == -1)
29172 @@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29173 do {
29174 next_epoch = NULL;
29175
29176 - epoch_size = atomic_read(&epoch->epoch_size);
29177 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29178
29179 switch (ev & ~EV_CLEANUP) {
29180 case EV_PUT:
29181 @@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29182 rv = FE_DESTROYED;
29183 } else {
29184 epoch->flags = 0;
29185 - atomic_set(&epoch->epoch_size, 0);
29186 + atomic_set_unchecked(&epoch->epoch_size, 0);
29187 /* atomic_set(&epoch->active, 0); is already zero */
29188 if (rv == FE_STILL_LIVE)
29189 rv = FE_RECYCLED;
29190 @@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29191 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29192 drbd_flush(mdev);
29193
29194 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29195 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29196 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29197 if (epoch)
29198 break;
29199 }
29200
29201 epoch = mdev->current_epoch;
29202 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29203 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29204
29205 D_ASSERT(atomic_read(&epoch->active) == 0);
29206 D_ASSERT(epoch->flags == 0);
29207 @@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29208 }
29209
29210 epoch->flags = 0;
29211 - atomic_set(&epoch->epoch_size, 0);
29212 + atomic_set_unchecked(&epoch->epoch_size, 0);
29213 atomic_set(&epoch->active, 0);
29214
29215 spin_lock(&mdev->epoch_lock);
29216 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29217 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29218 list_add(&epoch->list, &mdev->current_epoch->list);
29219 mdev->current_epoch = epoch;
29220 mdev->epochs++;
29221 @@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29222 spin_unlock(&mdev->peer_seq_lock);
29223
29224 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29225 - atomic_inc(&mdev->current_epoch->epoch_size);
29226 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29227 return drbd_drain_block(mdev, data_size);
29228 }
29229
29230 @@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29231
29232 spin_lock(&mdev->epoch_lock);
29233 e->epoch = mdev->current_epoch;
29234 - atomic_inc(&e->epoch->epoch_size);
29235 + atomic_inc_unchecked(&e->epoch->epoch_size);
29236 atomic_inc(&e->epoch->active);
29237 spin_unlock(&mdev->epoch_lock);
29238
29239 @@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29240 D_ASSERT(list_empty(&mdev->done_ee));
29241
29242 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29243 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29244 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29245 D_ASSERT(list_empty(&mdev->current_epoch->list));
29246 }
29247
29248 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29249 index 3bba655..6151b66 100644
29250 --- a/drivers/block/loop.c
29251 +++ b/drivers/block/loop.c
29252 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29253 mm_segment_t old_fs = get_fs();
29254
29255 set_fs(get_ds());
29256 - bw = file->f_op->write(file, buf, len, &pos);
29257 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29258 set_fs(old_fs);
29259 if (likely(bw == len))
29260 return 0;
29261 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29262 index ea6f632..eafb192 100644
29263 --- a/drivers/char/Kconfig
29264 +++ b/drivers/char/Kconfig
29265 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29266
29267 config DEVKMEM
29268 bool "/dev/kmem virtual device support"
29269 - default y
29270 + default n
29271 + depends on !GRKERNSEC_KMEM
29272 help
29273 Say Y here if you want to support the /dev/kmem device. The
29274 /dev/kmem device is rarely used, but can be used for certain
29275 @@ -581,6 +582,7 @@ config DEVPORT
29276 bool
29277 depends on !M68K
29278 depends on ISA || PCI
29279 + depends on !GRKERNSEC_KMEM
29280 default y
29281
29282 source "drivers/s390/char/Kconfig"
29283 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29284 index 2e04433..22afc64 100644
29285 --- a/drivers/char/agp/frontend.c
29286 +++ b/drivers/char/agp/frontend.c
29287 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29288 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29289 return -EFAULT;
29290
29291 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29292 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29293 return -EFAULT;
29294
29295 client = agp_find_client_by_pid(reserve.pid);
29296 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29297 index 21cb980..f15107c 100644
29298 --- a/drivers/char/genrtc.c
29299 +++ b/drivers/char/genrtc.c
29300 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29301 switch (cmd) {
29302
29303 case RTC_PLL_GET:
29304 + memset(&pll, 0, sizeof(pll));
29305 if (get_rtc_pll(&pll))
29306 return -EINVAL;
29307 else
29308 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29309 index dfd7876..c0b0885 100644
29310 --- a/drivers/char/hpet.c
29311 +++ b/drivers/char/hpet.c
29312 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29313 }
29314
29315 static int
29316 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29317 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29318 struct hpet_info *info)
29319 {
29320 struct hpet_timer __iomem *timer;
29321 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29322 index 2c29942..604c5ba 100644
29323 --- a/drivers/char/ipmi/ipmi_msghandler.c
29324 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29325 @@ -420,7 +420,7 @@ struct ipmi_smi {
29326 struct proc_dir_entry *proc_dir;
29327 char proc_dir_name[10];
29328
29329 - atomic_t stats[IPMI_NUM_STATS];
29330 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29331
29332 /*
29333 * run_to_completion duplicate of smb_info, smi_info
29334 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29335
29336
29337 #define ipmi_inc_stat(intf, stat) \
29338 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29339 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29340 #define ipmi_get_stat(intf, stat) \
29341 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29342 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29343
29344 static int is_lan_addr(struct ipmi_addr *addr)
29345 {
29346 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29347 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29348 init_waitqueue_head(&intf->waitq);
29349 for (i = 0; i < IPMI_NUM_STATS; i++)
29350 - atomic_set(&intf->stats[i], 0);
29351 + atomic_set_unchecked(&intf->stats[i], 0);
29352
29353 intf->proc_dir = NULL;
29354
29355 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29356 index 1e638ff..a869ef5 100644
29357 --- a/drivers/char/ipmi/ipmi_si_intf.c
29358 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29359 @@ -275,7 +275,7 @@ struct smi_info {
29360 unsigned char slave_addr;
29361
29362 /* Counters and things for the proc filesystem. */
29363 - atomic_t stats[SI_NUM_STATS];
29364 + atomic_unchecked_t stats[SI_NUM_STATS];
29365
29366 struct task_struct *thread;
29367
29368 @@ -284,9 +284,9 @@ struct smi_info {
29369 };
29370
29371 #define smi_inc_stat(smi, stat) \
29372 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29373 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29374 #define smi_get_stat(smi, stat) \
29375 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29376 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29377
29378 #define SI_MAX_PARMS 4
29379
29380 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29381 atomic_set(&new_smi->req_events, 0);
29382 new_smi->run_to_completion = 0;
29383 for (i = 0; i < SI_NUM_STATS; i++)
29384 - atomic_set(&new_smi->stats[i], 0);
29385 + atomic_set_unchecked(&new_smi->stats[i], 0);
29386
29387 new_smi->interrupt_disabled = 1;
29388 atomic_set(&new_smi->stop_operation, 0);
29389 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29390 index 47ff7e4..0c7d340 100644
29391 --- a/drivers/char/mbcs.c
29392 +++ b/drivers/char/mbcs.c
29393 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29394 return 0;
29395 }
29396
29397 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29398 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29399 {
29400 .part_num = MBCS_PART_NUM,
29401 .mfg_num = MBCS_MFG_NUM,
29402 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29403 index 67c3371..ba8429d 100644
29404 --- a/drivers/char/mem.c
29405 +++ b/drivers/char/mem.c
29406 @@ -18,6 +18,7 @@
29407 #include <linux/raw.h>
29408 #include <linux/tty.h>
29409 #include <linux/capability.h>
29410 +#include <linux/security.h>
29411 #include <linux/ptrace.h>
29412 #include <linux/device.h>
29413 #include <linux/highmem.h>
29414 @@ -35,6 +36,10 @@
29415 # include <linux/efi.h>
29416 #endif
29417
29418 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29419 +extern const struct file_operations grsec_fops;
29420 +#endif
29421 +
29422 static inline unsigned long size_inside_page(unsigned long start,
29423 unsigned long size)
29424 {
29425 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29426
29427 while (cursor < to) {
29428 if (!devmem_is_allowed(pfn)) {
29429 +#ifdef CONFIG_GRKERNSEC_KMEM
29430 + gr_handle_mem_readwrite(from, to);
29431 +#else
29432 printk(KERN_INFO
29433 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29434 current->comm, from, to);
29435 +#endif
29436 return 0;
29437 }
29438 cursor += PAGE_SIZE;
29439 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29440 }
29441 return 1;
29442 }
29443 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29444 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29445 +{
29446 + return 0;
29447 +}
29448 #else
29449 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29450 {
29451 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29452
29453 while (count > 0) {
29454 unsigned long remaining;
29455 + char *temp;
29456
29457 sz = size_inside_page(p, count);
29458
29459 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29460 if (!ptr)
29461 return -EFAULT;
29462
29463 - remaining = copy_to_user(buf, ptr, sz);
29464 +#ifdef CONFIG_PAX_USERCOPY
29465 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29466 + if (!temp) {
29467 + unxlate_dev_mem_ptr(p, ptr);
29468 + return -ENOMEM;
29469 + }
29470 + memcpy(temp, ptr, sz);
29471 +#else
29472 + temp = ptr;
29473 +#endif
29474 +
29475 + remaining = copy_to_user(buf, temp, sz);
29476 +
29477 +#ifdef CONFIG_PAX_USERCOPY
29478 + kfree(temp);
29479 +#endif
29480 +
29481 unxlate_dev_mem_ptr(p, ptr);
29482 if (remaining)
29483 return -EFAULT;
29484 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29485 size_t count, loff_t *ppos)
29486 {
29487 unsigned long p = *ppos;
29488 - ssize_t low_count, read, sz;
29489 + ssize_t low_count, read, sz, err = 0;
29490 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29491 - int err = 0;
29492
29493 read = 0;
29494 if (p < (unsigned long) high_memory) {
29495 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29496 }
29497 #endif
29498 while (low_count > 0) {
29499 + char *temp;
29500 +
29501 sz = size_inside_page(p, low_count);
29502
29503 /*
29504 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29505 */
29506 kbuf = xlate_dev_kmem_ptr((char *)p);
29507
29508 - if (copy_to_user(buf, kbuf, sz))
29509 +#ifdef CONFIG_PAX_USERCOPY
29510 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29511 + if (!temp)
29512 + return -ENOMEM;
29513 + memcpy(temp, kbuf, sz);
29514 +#else
29515 + temp = kbuf;
29516 +#endif
29517 +
29518 + err = copy_to_user(buf, temp, sz);
29519 +
29520 +#ifdef CONFIG_PAX_USERCOPY
29521 + kfree(temp);
29522 +#endif
29523 +
29524 + if (err)
29525 return -EFAULT;
29526 buf += sz;
29527 p += sz;
29528 @@ -831,6 +878,9 @@ static const struct memdev {
29529 #ifdef CONFIG_CRASH_DUMP
29530 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29531 #endif
29532 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29533 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29534 +#endif
29535 };
29536
29537 static int memory_open(struct inode *inode, struct file *filp)
29538 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29539 index 9df78e2..01ba9ae 100644
29540 --- a/drivers/char/nvram.c
29541 +++ b/drivers/char/nvram.c
29542 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29543
29544 spin_unlock_irq(&rtc_lock);
29545
29546 - if (copy_to_user(buf, contents, tmp - contents))
29547 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29548 return -EFAULT;
29549
29550 *ppos = i;
29551 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29552 index 0a484b4..f48ccd1 100644
29553 --- a/drivers/char/pcmcia/synclink_cs.c
29554 +++ b/drivers/char/pcmcia/synclink_cs.c
29555 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29556
29557 if (debug_level >= DEBUG_LEVEL_INFO)
29558 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29559 - __FILE__,__LINE__, info->device_name, port->count);
29560 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29561
29562 - WARN_ON(!port->count);
29563 + WARN_ON(!atomic_read(&port->count));
29564
29565 if (tty_port_close_start(port, tty, filp) == 0)
29566 goto cleanup;
29567 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29568 cleanup:
29569 if (debug_level >= DEBUG_LEVEL_INFO)
29570 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29571 - tty->driver->name, port->count);
29572 + tty->driver->name, atomic_read(&port->count));
29573 }
29574
29575 /* Wait until the transmitter is empty.
29576 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29577
29578 if (debug_level >= DEBUG_LEVEL_INFO)
29579 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29580 - __FILE__,__LINE__,tty->driver->name, port->count);
29581 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29582
29583 /* If port is closing, signal caller to try again */
29584 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29585 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29586 goto cleanup;
29587 }
29588 spin_lock(&port->lock);
29589 - port->count++;
29590 + atomic_inc(&port->count);
29591 spin_unlock(&port->lock);
29592 spin_unlock_irqrestore(&info->netlock, flags);
29593
29594 - if (port->count == 1) {
29595 + if (atomic_read(&port->count) == 1) {
29596 /* 1st open on this device, init hardware */
29597 retval = startup(info, tty);
29598 if (retval < 0)
29599 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29600 unsigned short new_crctype;
29601
29602 /* return error if TTY interface open */
29603 - if (info->port.count)
29604 + if (atomic_read(&info->port.count))
29605 return -EBUSY;
29606
29607 switch (encoding)
29608 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29609
29610 /* arbitrate between network and tty opens */
29611 spin_lock_irqsave(&info->netlock, flags);
29612 - if (info->port.count != 0 || info->netcount != 0) {
29613 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29614 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29615 spin_unlock_irqrestore(&info->netlock, flags);
29616 return -EBUSY;
29617 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29618 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29619
29620 /* return error if TTY interface open */
29621 - if (info->port.count)
29622 + if (atomic_read(&info->port.count))
29623 return -EBUSY;
29624
29625 if (cmd != SIOCWANDEV)
29626 diff --git a/drivers/char/random.c b/drivers/char/random.c
29627 index 4ec04a7..9918387 100644
29628 --- a/drivers/char/random.c
29629 +++ b/drivers/char/random.c
29630 @@ -261,8 +261,13 @@
29631 /*
29632 * Configuration information
29633 */
29634 +#ifdef CONFIG_GRKERNSEC_RANDNET
29635 +#define INPUT_POOL_WORDS 512
29636 +#define OUTPUT_POOL_WORDS 128
29637 +#else
29638 #define INPUT_POOL_WORDS 128
29639 #define OUTPUT_POOL_WORDS 32
29640 +#endif
29641 #define SEC_XFER_SIZE 512
29642 #define EXTRACT_SIZE 10
29643
29644 @@ -300,10 +305,17 @@ static struct poolinfo {
29645 int poolwords;
29646 int tap1, tap2, tap3, tap4, tap5;
29647 } poolinfo_table[] = {
29648 +#ifdef CONFIG_GRKERNSEC_RANDNET
29649 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29650 + { 512, 411, 308, 208, 104, 1 },
29651 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29652 + { 128, 103, 76, 51, 25, 1 },
29653 +#else
29654 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29655 { 128, 103, 76, 51, 25, 1 },
29656 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29657 { 32, 26, 20, 14, 7, 1 },
29658 +#endif
29659 #if 0
29660 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29661 { 2048, 1638, 1231, 819, 411, 1 },
29662 @@ -726,6 +738,17 @@ void add_disk_randomness(struct gendisk *disk)
29663 }
29664 #endif
29665
29666 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29667 +u64 latent_entropy;
29668 +
29669 +__init void transfer_latent_entropy(void)
29670 +{
29671 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy));
29672 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy));
29673 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29674 +}
29675 +#endif
29676 +
29677 /*********************************************************************
29678 *
29679 * Entropy extraction routines
29680 @@ -913,7 +936,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29681
29682 extract_buf(r, tmp);
29683 i = min_t(int, nbytes, EXTRACT_SIZE);
29684 - if (copy_to_user(buf, tmp, i)) {
29685 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29686 ret = -EFAULT;
29687 break;
29688 }
29689 @@ -1238,7 +1261,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29690 #include <linux/sysctl.h>
29691
29692 static int min_read_thresh = 8, min_write_thresh;
29693 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29694 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29695 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29696 static char sysctl_bootid[16];
29697
29698 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29699 index 45713f0..8286d21 100644
29700 --- a/drivers/char/sonypi.c
29701 +++ b/drivers/char/sonypi.c
29702 @@ -54,6 +54,7 @@
29703
29704 #include <asm/uaccess.h>
29705 #include <asm/io.h>
29706 +#include <asm/local.h>
29707
29708 #include <linux/sonypi.h>
29709
29710 @@ -490,7 +491,7 @@ static struct sonypi_device {
29711 spinlock_t fifo_lock;
29712 wait_queue_head_t fifo_proc_list;
29713 struct fasync_struct *fifo_async;
29714 - int open_count;
29715 + local_t open_count;
29716 int model;
29717 struct input_dev *input_jog_dev;
29718 struct input_dev *input_key_dev;
29719 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29720 static int sonypi_misc_release(struct inode *inode, struct file *file)
29721 {
29722 mutex_lock(&sonypi_device.lock);
29723 - sonypi_device.open_count--;
29724 + local_dec(&sonypi_device.open_count);
29725 mutex_unlock(&sonypi_device.lock);
29726 return 0;
29727 }
29728 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29729 {
29730 mutex_lock(&sonypi_device.lock);
29731 /* Flush input queue on first open */
29732 - if (!sonypi_device.open_count)
29733 + if (!local_read(&sonypi_device.open_count))
29734 kfifo_reset(&sonypi_device.fifo);
29735 - sonypi_device.open_count++;
29736 + local_inc(&sonypi_device.open_count);
29737 mutex_unlock(&sonypi_device.lock);
29738
29739 return 0;
29740 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29741 index ad7c732..5aa8054 100644
29742 --- a/drivers/char/tpm/tpm.c
29743 +++ b/drivers/char/tpm/tpm.c
29744 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29745 chip->vendor.req_complete_val)
29746 goto out_recv;
29747
29748 - if ((status == chip->vendor.req_canceled)) {
29749 + if (status == chip->vendor.req_canceled) {
29750 dev_err(chip->dev, "Operation Canceled\n");
29751 rc = -ECANCELED;
29752 goto out;
29753 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29754 index 0636520..169c1d0 100644
29755 --- a/drivers/char/tpm/tpm_bios.c
29756 +++ b/drivers/char/tpm/tpm_bios.c
29757 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29758 event = addr;
29759
29760 if ((event->event_type == 0 && event->event_size == 0) ||
29761 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29762 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29763 return NULL;
29764
29765 return addr;
29766 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29767 return NULL;
29768
29769 if ((event->event_type == 0 && event->event_size == 0) ||
29770 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29771 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29772 return NULL;
29773
29774 (*pos)++;
29775 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29776 int i;
29777
29778 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29779 - seq_putc(m, data[i]);
29780 + if (!seq_putc(m, data[i]))
29781 + return -EFAULT;
29782
29783 return 0;
29784 }
29785 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29786 log->bios_event_log_end = log->bios_event_log + len;
29787
29788 virt = acpi_os_map_memory(start, len);
29789 + if (!virt) {
29790 + kfree(log->bios_event_log);
29791 + log->bios_event_log = NULL;
29792 + return -EFAULT;
29793 + }
29794
29795 - memcpy(log->bios_event_log, virt, len);
29796 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29797
29798 acpi_os_unmap_memory(virt, len);
29799 return 0;
29800 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29801 index cdf2f54..e55c197 100644
29802 --- a/drivers/char/virtio_console.c
29803 +++ b/drivers/char/virtio_console.c
29804 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29805 if (to_user) {
29806 ssize_t ret;
29807
29808 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29809 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29810 if (ret)
29811 return -EFAULT;
29812 } else {
29813 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29814 if (!port_has_data(port) && !port->host_connected)
29815 return 0;
29816
29817 - return fill_readbuf(port, ubuf, count, true);
29818 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29819 }
29820
29821 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29822 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29823 index 97f5064..202b6e6 100644
29824 --- a/drivers/edac/edac_pci_sysfs.c
29825 +++ b/drivers/edac/edac_pci_sysfs.c
29826 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29827 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29828 static int edac_pci_poll_msec = 1000; /* one second workq period */
29829
29830 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29831 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29832 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29833 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29834
29835 static struct kobject *edac_pci_top_main_kobj;
29836 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29837 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29838 edac_printk(KERN_CRIT, EDAC_PCI,
29839 "Signaled System Error on %s\n",
29840 pci_name(dev));
29841 - atomic_inc(&pci_nonparity_count);
29842 + atomic_inc_unchecked(&pci_nonparity_count);
29843 }
29844
29845 if (status & (PCI_STATUS_PARITY)) {
29846 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29847 "Master Data Parity Error on %s\n",
29848 pci_name(dev));
29849
29850 - atomic_inc(&pci_parity_count);
29851 + atomic_inc_unchecked(&pci_parity_count);
29852 }
29853
29854 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29855 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29856 "Detected Parity Error on %s\n",
29857 pci_name(dev));
29858
29859 - atomic_inc(&pci_parity_count);
29860 + atomic_inc_unchecked(&pci_parity_count);
29861 }
29862 }
29863
29864 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29865 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29866 "Signaled System Error on %s\n",
29867 pci_name(dev));
29868 - atomic_inc(&pci_nonparity_count);
29869 + atomic_inc_unchecked(&pci_nonparity_count);
29870 }
29871
29872 if (status & (PCI_STATUS_PARITY)) {
29873 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29874 "Master Data Parity Error on "
29875 "%s\n", pci_name(dev));
29876
29877 - atomic_inc(&pci_parity_count);
29878 + atomic_inc_unchecked(&pci_parity_count);
29879 }
29880
29881 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29882 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29883 "Detected Parity Error on %s\n",
29884 pci_name(dev));
29885
29886 - atomic_inc(&pci_parity_count);
29887 + atomic_inc_unchecked(&pci_parity_count);
29888 }
29889 }
29890 }
29891 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29892 if (!check_pci_errors)
29893 return;
29894
29895 - before_count = atomic_read(&pci_parity_count);
29896 + before_count = atomic_read_unchecked(&pci_parity_count);
29897
29898 /* scan all PCI devices looking for a Parity Error on devices and
29899 * bridges.
29900 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29901 /* Only if operator has selected panic on PCI Error */
29902 if (edac_pci_get_panic_on_pe()) {
29903 /* If the count is different 'after' from 'before' */
29904 - if (before_count != atomic_read(&pci_parity_count))
29905 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29906 panic("EDAC: PCI Parity Error");
29907 }
29908 }
29909 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29910 index 8c87a5e..a19cbd7 100644
29911 --- a/drivers/edac/mce_amd.h
29912 +++ b/drivers/edac/mce_amd.h
29913 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29914 struct amd_decoder_ops {
29915 bool (*dc_mce)(u16, u8);
29916 bool (*ic_mce)(u16, u8);
29917 -};
29918 +} __no_const;
29919
29920 void amd_report_gart_errors(bool);
29921 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29922 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29923 index 57ea7f4..789e3c3 100644
29924 --- a/drivers/firewire/core-card.c
29925 +++ b/drivers/firewire/core-card.c
29926 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
29927
29928 void fw_core_remove_card(struct fw_card *card)
29929 {
29930 - struct fw_card_driver dummy_driver = dummy_driver_template;
29931 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29932
29933 card->driver->update_phy_reg(card, 4,
29934 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29935 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29936 index 2783f69..9f4b0cc 100644
29937 --- a/drivers/firewire/core-cdev.c
29938 +++ b/drivers/firewire/core-cdev.c
29939 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
29940 int ret;
29941
29942 if ((request->channels == 0 && request->bandwidth == 0) ||
29943 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29944 - request->bandwidth < 0)
29945 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29946 return -EINVAL;
29947
29948 r = kmalloc(sizeof(*r), GFP_KERNEL);
29949 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29950 index 780708d..ad60a66 100644
29951 --- a/drivers/firewire/core-transaction.c
29952 +++ b/drivers/firewire/core-transaction.c
29953 @@ -37,6 +37,7 @@
29954 #include <linux/timer.h>
29955 #include <linux/types.h>
29956 #include <linux/workqueue.h>
29957 +#include <linux/sched.h>
29958
29959 #include <asm/byteorder.h>
29960
29961 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29962 index 515a42c..5ecf3ba 100644
29963 --- a/drivers/firewire/core.h
29964 +++ b/drivers/firewire/core.h
29965 @@ -111,6 +111,7 @@ struct fw_card_driver {
29966
29967 int (*stop_iso)(struct fw_iso_context *ctx);
29968 };
29969 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29970
29971 void fw_card_initialize(struct fw_card *card,
29972 const struct fw_card_driver *driver, struct device *device);
29973 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29974 index 153980b..4b4d046 100644
29975 --- a/drivers/firmware/dmi_scan.c
29976 +++ b/drivers/firmware/dmi_scan.c
29977 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29978 }
29979 }
29980 else {
29981 - /*
29982 - * no iounmap() for that ioremap(); it would be a no-op, but
29983 - * it's so early in setup that sucker gets confused into doing
29984 - * what it shouldn't if we actually call it.
29985 - */
29986 p = dmi_ioremap(0xF0000, 0x10000);
29987 if (p == NULL)
29988 goto error;
29989 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29990 if (buf == NULL)
29991 return -1;
29992
29993 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29994 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29995
29996 iounmap(buf);
29997 return 0;
29998 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29999 index 82d5c20..44a7177 100644
30000 --- a/drivers/gpio/gpio-vr41xx.c
30001 +++ b/drivers/gpio/gpio-vr41xx.c
30002 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30003 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30004 maskl, pendl, maskh, pendh);
30005
30006 - atomic_inc(&irq_err_count);
30007 + atomic_inc_unchecked(&irq_err_count);
30008
30009 return -EINVAL;
30010 }
30011 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30012 index 3252e70..b5314ace 100644
30013 --- a/drivers/gpu/drm/drm_crtc_helper.c
30014 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30015 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30016 struct drm_crtc *tmp;
30017 int crtc_mask = 1;
30018
30019 - WARN(!crtc, "checking null crtc?\n");
30020 + BUG_ON(!crtc);
30021
30022 dev = crtc->dev;
30023
30024 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30025 index 8a9d079..606cdd5 100644
30026 --- a/drivers/gpu/drm/drm_drv.c
30027 +++ b/drivers/gpu/drm/drm_drv.c
30028 @@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30029 /**
30030 * Copy and IOCTL return string to user space
30031 */
30032 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30033 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30034 {
30035 int len;
30036
30037 @@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30038 return -ENODEV;
30039
30040 atomic_inc(&dev->ioctl_count);
30041 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30042 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30043 ++file_priv->ioctl_count;
30044
30045 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30046 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30047 index 123de28..43a0897 100644
30048 --- a/drivers/gpu/drm/drm_fops.c
30049 +++ b/drivers/gpu/drm/drm_fops.c
30050 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30051 }
30052
30053 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30054 - atomic_set(&dev->counts[i], 0);
30055 + atomic_set_unchecked(&dev->counts[i], 0);
30056
30057 dev->sigdata.lock = NULL;
30058
30059 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30060
30061 retcode = drm_open_helper(inode, filp, dev);
30062 if (!retcode) {
30063 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30064 - if (!dev->open_count++)
30065 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30066 + if (local_inc_return(&dev->open_count) == 1)
30067 retcode = drm_setup(dev);
30068 }
30069 if (!retcode) {
30070 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30071
30072 mutex_lock(&drm_global_mutex);
30073
30074 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30075 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30076
30077 if (dev->driver->preclose)
30078 dev->driver->preclose(dev, file_priv);
30079 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30080 * Begin inline drm_release
30081 */
30082
30083 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30084 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30085 task_pid_nr(current),
30086 (long)old_encode_dev(file_priv->minor->device),
30087 - dev->open_count);
30088 + local_read(&dev->open_count));
30089
30090 /* Release any auth tokens that might point to this file_priv,
30091 (do that under the drm_global_mutex) */
30092 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30093 * End inline drm_release
30094 */
30095
30096 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30097 - if (!--dev->open_count) {
30098 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30099 + if (local_dec_and_test(&dev->open_count)) {
30100 if (atomic_read(&dev->ioctl_count)) {
30101 DRM_ERROR("Device busy: %d\n",
30102 atomic_read(&dev->ioctl_count));
30103 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30104 index c87dc96..326055d 100644
30105 --- a/drivers/gpu/drm/drm_global.c
30106 +++ b/drivers/gpu/drm/drm_global.c
30107 @@ -36,7 +36,7 @@
30108 struct drm_global_item {
30109 struct mutex mutex;
30110 void *object;
30111 - int refcount;
30112 + atomic_t refcount;
30113 };
30114
30115 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30116 @@ -49,7 +49,7 @@ void drm_global_init(void)
30117 struct drm_global_item *item = &glob[i];
30118 mutex_init(&item->mutex);
30119 item->object = NULL;
30120 - item->refcount = 0;
30121 + atomic_set(&item->refcount, 0);
30122 }
30123 }
30124
30125 @@ -59,7 +59,7 @@ void drm_global_release(void)
30126 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30127 struct drm_global_item *item = &glob[i];
30128 BUG_ON(item->object != NULL);
30129 - BUG_ON(item->refcount != 0);
30130 + BUG_ON(atomic_read(&item->refcount) != 0);
30131 }
30132 }
30133
30134 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30135 void *object;
30136
30137 mutex_lock(&item->mutex);
30138 - if (item->refcount == 0) {
30139 + if (atomic_read(&item->refcount) == 0) {
30140 item->object = kzalloc(ref->size, GFP_KERNEL);
30141 if (unlikely(item->object == NULL)) {
30142 ret = -ENOMEM;
30143 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30144 goto out_err;
30145
30146 }
30147 - ++item->refcount;
30148 + atomic_inc(&item->refcount);
30149 ref->object = item->object;
30150 object = item->object;
30151 mutex_unlock(&item->mutex);
30152 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30153 struct drm_global_item *item = &glob[ref->global_type];
30154
30155 mutex_lock(&item->mutex);
30156 - BUG_ON(item->refcount == 0);
30157 + BUG_ON(atomic_read(&item->refcount) == 0);
30158 BUG_ON(ref->object != item->object);
30159 - if (--item->refcount == 0) {
30160 + if (atomic_dec_and_test(&item->refcount)) {
30161 ref->release(ref);
30162 item->object = NULL;
30163 }
30164 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30165 index ab1162d..42587b2 100644
30166 --- a/drivers/gpu/drm/drm_info.c
30167 +++ b/drivers/gpu/drm/drm_info.c
30168 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30169 struct drm_local_map *map;
30170 struct drm_map_list *r_list;
30171
30172 - /* Hardcoded from _DRM_FRAME_BUFFER,
30173 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30174 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30175 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30176 + static const char * const types[] = {
30177 + [_DRM_FRAME_BUFFER] = "FB",
30178 + [_DRM_REGISTERS] = "REG",
30179 + [_DRM_SHM] = "SHM",
30180 + [_DRM_AGP] = "AGP",
30181 + [_DRM_SCATTER_GATHER] = "SG",
30182 + [_DRM_CONSISTENT] = "PCI",
30183 + [_DRM_GEM] = "GEM" };
30184 const char *type;
30185 int i;
30186
30187 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30188 map = r_list->map;
30189 if (!map)
30190 continue;
30191 - if (map->type < 0 || map->type > 5)
30192 + if (map->type >= ARRAY_SIZE(types))
30193 type = "??";
30194 else
30195 type = types[map->type];
30196 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30197 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30198 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30199 vma->vm_flags & VM_IO ? 'i' : '-',
30200 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30201 + 0);
30202 +#else
30203 vma->vm_pgoff);
30204 +#endif
30205
30206 #if defined(__i386__)
30207 pgprot = pgprot_val(vma->vm_page_prot);
30208 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30209 index 637fcc3..e890b33 100644
30210 --- a/drivers/gpu/drm/drm_ioc32.c
30211 +++ b/drivers/gpu/drm/drm_ioc32.c
30212 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30213 request = compat_alloc_user_space(nbytes);
30214 if (!access_ok(VERIFY_WRITE, request, nbytes))
30215 return -EFAULT;
30216 - list = (struct drm_buf_desc *) (request + 1);
30217 + list = (struct drm_buf_desc __user *) (request + 1);
30218
30219 if (__put_user(count, &request->count)
30220 || __put_user(list, &request->list))
30221 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30222 request = compat_alloc_user_space(nbytes);
30223 if (!access_ok(VERIFY_WRITE, request, nbytes))
30224 return -EFAULT;
30225 - list = (struct drm_buf_pub *) (request + 1);
30226 + list = (struct drm_buf_pub __user *) (request + 1);
30227
30228 if (__put_user(count, &request->count)
30229 || __put_user(list, &request->list))
30230 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30231 index 64a62c6..ceab35e 100644
30232 --- a/drivers/gpu/drm/drm_ioctl.c
30233 +++ b/drivers/gpu/drm/drm_ioctl.c
30234 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30235 stats->data[i].value =
30236 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30237 else
30238 - stats->data[i].value = atomic_read(&dev->counts[i]);
30239 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30240 stats->data[i].type = dev->types[i];
30241 }
30242
30243 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30244 index 5211520..c744d85 100644
30245 --- a/drivers/gpu/drm/drm_lock.c
30246 +++ b/drivers/gpu/drm/drm_lock.c
30247 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30248 if (drm_lock_take(&master->lock, lock->context)) {
30249 master->lock.file_priv = file_priv;
30250 master->lock.lock_time = jiffies;
30251 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30252 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30253 break; /* Got lock */
30254 }
30255
30256 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30257 return -EINVAL;
30258 }
30259
30260 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30261 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30262
30263 if (drm_lock_free(&master->lock, lock->context)) {
30264 /* FIXME: Should really bail out here. */
30265 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30266 index 21bcd4a..8e074e0 100644
30267 --- a/drivers/gpu/drm/drm_stub.c
30268 +++ b/drivers/gpu/drm/drm_stub.c
30269 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30270
30271 drm_device_set_unplugged(dev);
30272
30273 - if (dev->open_count == 0) {
30274 + if (local_read(&dev->open_count) == 0) {
30275 drm_put_dev(dev);
30276 }
30277 mutex_unlock(&drm_global_mutex);
30278 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30279 index fa94391..ed26ec8 100644
30280 --- a/drivers/gpu/drm/i810/i810_dma.c
30281 +++ b/drivers/gpu/drm/i810/i810_dma.c
30282 @@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30283 dma->buflist[vertex->idx],
30284 vertex->discard, vertex->used);
30285
30286 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30287 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30288 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30289 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30290 sarea_priv->last_enqueue = dev_priv->counter - 1;
30291 sarea_priv->last_dispatch = (int)hw_status[5];
30292
30293 @@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30294 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30295 mc->last_render);
30296
30297 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30298 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30299 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30300 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30301 sarea_priv->last_enqueue = dev_priv->counter - 1;
30302 sarea_priv->last_dispatch = (int)hw_status[5];
30303
30304 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30305 index c9339f4..f5e1b9d 100644
30306 --- a/drivers/gpu/drm/i810/i810_drv.h
30307 +++ b/drivers/gpu/drm/i810/i810_drv.h
30308 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30309 int page_flipping;
30310
30311 wait_queue_head_t irq_queue;
30312 - atomic_t irq_received;
30313 - atomic_t irq_emitted;
30314 + atomic_unchecked_t irq_received;
30315 + atomic_unchecked_t irq_emitted;
30316
30317 int front_offset;
30318 } drm_i810_private_t;
30319 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30320 index 5363e9c..59360d1 100644
30321 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30322 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30323 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30324 I915_READ(GTIMR));
30325 }
30326 seq_printf(m, "Interrupts received: %d\n",
30327 - atomic_read(&dev_priv->irq_received));
30328 + atomic_read_unchecked(&dev_priv->irq_received));
30329 for (i = 0; i < I915_NUM_RINGS; i++) {
30330 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30331 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30332 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30333 index 36822b9..b725e1b 100644
30334 --- a/drivers/gpu/drm/i915/i915_dma.c
30335 +++ b/drivers/gpu/drm/i915/i915_dma.c
30336 @@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30337 bool can_switch;
30338
30339 spin_lock(&dev->count_lock);
30340 - can_switch = (dev->open_count == 0);
30341 + can_switch = (local_read(&dev->open_count) == 0);
30342 spin_unlock(&dev->count_lock);
30343 return can_switch;
30344 }
30345 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30346 index b0b676a..d107105 100644
30347 --- a/drivers/gpu/drm/i915/i915_drv.h
30348 +++ b/drivers/gpu/drm/i915/i915_drv.h
30349 @@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30350 /* render clock increase/decrease */
30351 /* display clock increase/decrease */
30352 /* pll clock increase/decrease */
30353 -};
30354 +} __no_const;
30355
30356 struct intel_device_info {
30357 u8 gen;
30358 @@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30359 int current_page;
30360 int page_flipping;
30361
30362 - atomic_t irq_received;
30363 + atomic_unchecked_t irq_received;
30364
30365 /* protects the irq masks */
30366 spinlock_t irq_lock;
30367 @@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30368 * will be page flipped away on the next vblank. When it
30369 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30370 */
30371 - atomic_t pending_flip;
30372 + atomic_unchecked_t pending_flip;
30373 };
30374
30375 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30376 @@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30377 struct drm_i915_private *dev_priv, unsigned port);
30378 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30379 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30380 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30381 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30382 {
30383 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30384 }
30385 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30386 index 974a9f1..b3ebd45 100644
30387 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30388 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30389 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30390 i915_gem_clflush_object(obj);
30391
30392 if (obj->base.pending_write_domain)
30393 - cd->flips |= atomic_read(&obj->pending_flip);
30394 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30395
30396 /* The actual obj->write_domain will be updated with
30397 * pending_write_domain after we emit the accumulated flush for all
30398 @@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30399
30400 static int
30401 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30402 - int count)
30403 + unsigned int count)
30404 {
30405 - int i;
30406 + unsigned int i;
30407
30408 for (i = 0; i < count; i++) {
30409 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30410 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30411 index ed3224c..6618589 100644
30412 --- a/drivers/gpu/drm/i915/i915_irq.c
30413 +++ b/drivers/gpu/drm/i915/i915_irq.c
30414 @@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30415 int vblank = 0;
30416 bool blc_event;
30417
30418 - atomic_inc(&dev_priv->irq_received);
30419 + atomic_inc_unchecked(&dev_priv->irq_received);
30420
30421 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30422 PIPE_VBLANK_INTERRUPT_STATUS;
30423 @@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30424 irqreturn_t ret = IRQ_NONE;
30425 int i;
30426
30427 - atomic_inc(&dev_priv->irq_received);
30428 + atomic_inc_unchecked(&dev_priv->irq_received);
30429
30430 /* disable master interrupt before clearing iir */
30431 de_ier = I915_READ(DEIER);
30432 @@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30433 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30434 u32 hotplug_mask;
30435
30436 - atomic_inc(&dev_priv->irq_received);
30437 + atomic_inc_unchecked(&dev_priv->irq_received);
30438
30439 /* disable master interrupt before clearing iir */
30440 de_ier = I915_READ(DEIER);
30441 @@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30442 {
30443 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30444
30445 - atomic_set(&dev_priv->irq_received, 0);
30446 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30447
30448
30449 I915_WRITE(HWSTAM, 0xeffe);
30450 @@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30451 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30452 int pipe;
30453
30454 - atomic_set(&dev_priv->irq_received, 0);
30455 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30456
30457 /* VLV magic */
30458 I915_WRITE(VLV_IMR, 0);
30459 @@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30460 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30461 int pipe;
30462
30463 - atomic_set(&dev_priv->irq_received, 0);
30464 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30465
30466 for_each_pipe(pipe)
30467 I915_WRITE(PIPESTAT(pipe), 0);
30468 @@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30469 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30470 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30471
30472 - atomic_inc(&dev_priv->irq_received);
30473 + atomic_inc_unchecked(&dev_priv->irq_received);
30474
30475 iir = I915_READ16(IIR);
30476 if (iir == 0)
30477 @@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30478 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30479 int pipe;
30480
30481 - atomic_set(&dev_priv->irq_received, 0);
30482 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30483
30484 if (I915_HAS_HOTPLUG(dev)) {
30485 I915_WRITE(PORT_HOTPLUG_EN, 0);
30486 @@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30487 };
30488 int pipe, ret = IRQ_NONE;
30489
30490 - atomic_inc(&dev_priv->irq_received);
30491 + atomic_inc_unchecked(&dev_priv->irq_received);
30492
30493 iir = I915_READ(IIR);
30494 do {
30495 @@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30496 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30497 int pipe;
30498
30499 - atomic_set(&dev_priv->irq_received, 0);
30500 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30501
30502 if (I915_HAS_HOTPLUG(dev)) {
30503 I915_WRITE(PORT_HOTPLUG_EN, 0);
30504 @@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30505 int irq_received;
30506 int ret = IRQ_NONE, pipe;
30507
30508 - atomic_inc(&dev_priv->irq_received);
30509 + atomic_inc_unchecked(&dev_priv->irq_received);
30510
30511 iir = I915_READ(IIR);
30512
30513 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30514 index a8538ac..4868a05 100644
30515 --- a/drivers/gpu/drm/i915/intel_display.c
30516 +++ b/drivers/gpu/drm/i915/intel_display.c
30517 @@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30518
30519 wait_event(dev_priv->pending_flip_queue,
30520 atomic_read(&dev_priv->mm.wedged) ||
30521 - atomic_read(&obj->pending_flip) == 0);
30522 + atomic_read_unchecked(&obj->pending_flip) == 0);
30523
30524 /* Big Hammer, we also need to ensure that any pending
30525 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30526 @@ -5925,9 +5925,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30527
30528 obj = work->old_fb_obj;
30529
30530 - atomic_clear_mask(1 << intel_crtc->plane,
30531 - &obj->pending_flip.counter);
30532 - if (atomic_read(&obj->pending_flip) == 0)
30533 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30534 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30535 wake_up(&dev_priv->pending_flip_queue);
30536
30537 schedule_work(&work->work);
30538 @@ -6264,7 +6263,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30539 /* Block clients from rendering to the new back buffer until
30540 * the flip occurs and the object is no longer visible.
30541 */
30542 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30543 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30544
30545 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30546 if (ret)
30547 @@ -6279,7 +6278,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30548 return 0;
30549
30550 cleanup_pending:
30551 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30552 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30553 drm_gem_object_unreference(&work->old_fb_obj->base);
30554 drm_gem_object_unreference(&obj->base);
30555 mutex_unlock(&dev->struct_mutex);
30556 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30557 index 54558a0..2d97005 100644
30558 --- a/drivers/gpu/drm/mga/mga_drv.h
30559 +++ b/drivers/gpu/drm/mga/mga_drv.h
30560 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30561 u32 clear_cmd;
30562 u32 maccess;
30563
30564 - atomic_t vbl_received; /**< Number of vblanks received. */
30565 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30566 wait_queue_head_t fence_queue;
30567 - atomic_t last_fence_retired;
30568 + atomic_unchecked_t last_fence_retired;
30569 u32 next_fence_to_post;
30570
30571 unsigned int fb_cpp;
30572 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30573 index 2581202..f230a8d9 100644
30574 --- a/drivers/gpu/drm/mga/mga_irq.c
30575 +++ b/drivers/gpu/drm/mga/mga_irq.c
30576 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30577 if (crtc != 0)
30578 return 0;
30579
30580 - return atomic_read(&dev_priv->vbl_received);
30581 + return atomic_read_unchecked(&dev_priv->vbl_received);
30582 }
30583
30584
30585 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30586 /* VBLANK interrupt */
30587 if (status & MGA_VLINEPEN) {
30588 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30589 - atomic_inc(&dev_priv->vbl_received);
30590 + atomic_inc_unchecked(&dev_priv->vbl_received);
30591 drm_handle_vblank(dev, 0);
30592 handled = 1;
30593 }
30594 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30595 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30596 MGA_WRITE(MGA_PRIMEND, prim_end);
30597
30598 - atomic_inc(&dev_priv->last_fence_retired);
30599 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30600 DRM_WAKEUP(&dev_priv->fence_queue);
30601 handled = 1;
30602 }
30603 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30604 * using fences.
30605 */
30606 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30607 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30608 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30609 - *sequence) <= (1 << 23)));
30610
30611 *sequence = cur_fence;
30612 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30613 index 2f11e16..191267e 100644
30614 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30615 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30616 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30617 struct bit_table {
30618 const char id;
30619 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30620 -};
30621 +} __no_const;
30622
30623 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30624
30625 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30626 index 8613cb2..ea038e7 100644
30627 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30628 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30629 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30630 u32 handle, u16 class);
30631 void (*set_tile_region)(struct drm_device *dev, int i);
30632 void (*tlb_flush)(struct drm_device *, int engine);
30633 -};
30634 +} __no_const;
30635
30636 struct nouveau_instmem_engine {
30637 void *priv;
30638 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30639 struct nouveau_mc_engine {
30640 int (*init)(struct drm_device *dev);
30641 void (*takedown)(struct drm_device *dev);
30642 -};
30643 +} __no_const;
30644
30645 struct nouveau_timer_engine {
30646 int (*init)(struct drm_device *dev);
30647 void (*takedown)(struct drm_device *dev);
30648 uint64_t (*read)(struct drm_device *dev);
30649 -};
30650 +} __no_const;
30651
30652 struct nouveau_fb_engine {
30653 int num_tiles;
30654 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30655 void (*put)(struct drm_device *, struct nouveau_mem **);
30656
30657 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30658 -};
30659 +} __no_const;
30660
30661 struct nouveau_engine {
30662 struct nouveau_instmem_engine instmem;
30663 @@ -695,7 +695,7 @@ struct drm_nouveau_private {
30664 struct drm_global_reference mem_global_ref;
30665 struct ttm_bo_global_ref bo_global_ref;
30666 struct ttm_bo_device bdev;
30667 - atomic_t validate_sequence;
30668 + atomic_unchecked_t validate_sequence;
30669 int (*move)(struct nouveau_channel *,
30670 struct ttm_buffer_object *,
30671 struct ttm_mem_reg *, struct ttm_mem_reg *);
30672 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30673 index 30f5423..abca136 100644
30674 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30675 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30676 @@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30677 int trycnt = 0;
30678 int ret, i;
30679
30680 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30681 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30682 retry:
30683 if (++trycnt > 100000) {
30684 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30685 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30686 index 19706f0..f257368 100644
30687 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30688 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30689 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30690 bool can_switch;
30691
30692 spin_lock(&dev->count_lock);
30693 - can_switch = (dev->open_count == 0);
30694 + can_switch = (local_read(&dev->open_count) == 0);
30695 spin_unlock(&dev->count_lock);
30696 return can_switch;
30697 }
30698 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30699 index a9514ea..369d511 100644
30700 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30701 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30702 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30703 }
30704
30705 if (nv_encoder->dcb->type == OUTPUT_DP) {
30706 - struct dp_train_func func = {
30707 + static struct dp_train_func func = {
30708 .link_set = nv50_sor_dp_link_set,
30709 .train_set = nv50_sor_dp_train_set,
30710 .train_adj = nv50_sor_dp_train_adj
30711 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30712 index c486d3c..3a7d6f4 100644
30713 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30714 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30715 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30716 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30717
30718 if (nv_encoder->dcb->type == OUTPUT_DP) {
30719 - struct dp_train_func func = {
30720 + static struct dp_train_func func = {
30721 .link_set = nvd0_sor_dp_link_set,
30722 .train_set = nvd0_sor_dp_train_set,
30723 .train_adj = nvd0_sor_dp_train_adj
30724 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30725 index bcac90b..53bfc76 100644
30726 --- a/drivers/gpu/drm/r128/r128_cce.c
30727 +++ b/drivers/gpu/drm/r128/r128_cce.c
30728 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30729
30730 /* GH: Simple idle check.
30731 */
30732 - atomic_set(&dev_priv->idle_count, 0);
30733 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30734
30735 /* We don't support anything other than bus-mastering ring mode,
30736 * but the ring can be in either AGP or PCI space for the ring
30737 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30738 index 930c71b..499aded 100644
30739 --- a/drivers/gpu/drm/r128/r128_drv.h
30740 +++ b/drivers/gpu/drm/r128/r128_drv.h
30741 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30742 int is_pci;
30743 unsigned long cce_buffers_offset;
30744
30745 - atomic_t idle_count;
30746 + atomic_unchecked_t idle_count;
30747
30748 int page_flipping;
30749 int current_page;
30750 u32 crtc_offset;
30751 u32 crtc_offset_cntl;
30752
30753 - atomic_t vbl_received;
30754 + atomic_unchecked_t vbl_received;
30755
30756 u32 color_fmt;
30757 unsigned int front_offset;
30758 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30759 index 429d5a0..7e899ed 100644
30760 --- a/drivers/gpu/drm/r128/r128_irq.c
30761 +++ b/drivers/gpu/drm/r128/r128_irq.c
30762 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30763 if (crtc != 0)
30764 return 0;
30765
30766 - return atomic_read(&dev_priv->vbl_received);
30767 + return atomic_read_unchecked(&dev_priv->vbl_received);
30768 }
30769
30770 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30771 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30772 /* VBLANK interrupt */
30773 if (status & R128_CRTC_VBLANK_INT) {
30774 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30775 - atomic_inc(&dev_priv->vbl_received);
30776 + atomic_inc_unchecked(&dev_priv->vbl_received);
30777 drm_handle_vblank(dev, 0);
30778 return IRQ_HANDLED;
30779 }
30780 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30781 index a9e33ce..09edd4b 100644
30782 --- a/drivers/gpu/drm/r128/r128_state.c
30783 +++ b/drivers/gpu/drm/r128/r128_state.c
30784 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30785
30786 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30787 {
30788 - if (atomic_read(&dev_priv->idle_count) == 0)
30789 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30790 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30791 else
30792 - atomic_set(&dev_priv->idle_count, 0);
30793 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30794 }
30795
30796 #endif
30797 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30798 index 5a82b6b..9e69c73 100644
30799 --- a/drivers/gpu/drm/radeon/mkregtable.c
30800 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30801 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30802 regex_t mask_rex;
30803 regmatch_t match[4];
30804 char buf[1024];
30805 - size_t end;
30806 + long end;
30807 int len;
30808 int done = 0;
30809 int r;
30810 unsigned o;
30811 struct offset *offset;
30812 char last_reg_s[10];
30813 - int last_reg;
30814 + unsigned long last_reg;
30815
30816 if (regcomp
30817 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30818 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30819 index fefcca5..20a5b90 100644
30820 --- a/drivers/gpu/drm/radeon/radeon.h
30821 +++ b/drivers/gpu/drm/radeon/radeon.h
30822 @@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30823 int x2, int y2);
30824 void (*draw_auto)(struct radeon_device *rdev);
30825 void (*set_default_state)(struct radeon_device *rdev);
30826 -};
30827 +} __no_const;
30828
30829 struct r600_blit {
30830 struct radeon_bo *shader_obj;
30831 @@ -1244,7 +1244,7 @@ struct radeon_asic {
30832 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30833 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30834 } pflip;
30835 -};
30836 +} __no_const;
30837
30838 /*
30839 * Asic structures
30840 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30841 index 066c98b..96ab858 100644
30842 --- a/drivers/gpu/drm/radeon/radeon_device.c
30843 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30844 @@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30845 bool can_switch;
30846
30847 spin_lock(&dev->count_lock);
30848 - can_switch = (dev->open_count == 0);
30849 + can_switch = (local_read(&dev->open_count) == 0);
30850 spin_unlock(&dev->count_lock);
30851 return can_switch;
30852 }
30853 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30854 index a1b59ca..86f2d44 100644
30855 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30856 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30857 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30858
30859 /* SW interrupt */
30860 wait_queue_head_t swi_queue;
30861 - atomic_t swi_emitted;
30862 + atomic_unchecked_t swi_emitted;
30863 int vblank_crtc;
30864 uint32_t irq_enable_reg;
30865 uint32_t r500_disp_irq_reg;
30866 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30867 index 48b7cea..342236f 100644
30868 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30869 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30870 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30871 request = compat_alloc_user_space(sizeof(*request));
30872 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30873 || __put_user(req32.param, &request->param)
30874 - || __put_user((void __user *)(unsigned long)req32.value,
30875 + || __put_user((unsigned long)req32.value,
30876 &request->value))
30877 return -EFAULT;
30878
30879 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30880 index 00da384..32f972d 100644
30881 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30882 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30883 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30884 unsigned int ret;
30885 RING_LOCALS;
30886
30887 - atomic_inc(&dev_priv->swi_emitted);
30888 - ret = atomic_read(&dev_priv->swi_emitted);
30889 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30890 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30891
30892 BEGIN_RING(4);
30893 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30894 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30895 drm_radeon_private_t *dev_priv =
30896 (drm_radeon_private_t *) dev->dev_private;
30897
30898 - atomic_set(&dev_priv->swi_emitted, 0);
30899 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30900 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30901
30902 dev->max_vblank_count = 0x001fffff;
30903 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30904 index e8422ae..d22d4a8 100644
30905 --- a/drivers/gpu/drm/radeon/radeon_state.c
30906 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30907 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30908 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30909 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30910
30911 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30912 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30913 sarea_priv->nbox * sizeof(depth_boxes[0])))
30914 return -EFAULT;
30915
30916 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30917 {
30918 drm_radeon_private_t *dev_priv = dev->dev_private;
30919 drm_radeon_getparam_t *param = data;
30920 - int value;
30921 + int value = 0;
30922
30923 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30924
30925 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30926 index c94a225..5795d34 100644
30927 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30928 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30929 @@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30930 }
30931 if (unlikely(ttm_vm_ops == NULL)) {
30932 ttm_vm_ops = vma->vm_ops;
30933 - radeon_ttm_vm_ops = *ttm_vm_ops;
30934 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30935 + pax_open_kernel();
30936 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30937 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30938 + pax_close_kernel();
30939 }
30940 vma->vm_ops = &radeon_ttm_vm_ops;
30941 return 0;
30942 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30943 index 159b6a4..fa82487 100644
30944 --- a/drivers/gpu/drm/radeon/rs690.c
30945 +++ b/drivers/gpu/drm/radeon/rs690.c
30946 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30947 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30948 rdev->pm.sideport_bandwidth.full)
30949 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30950 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30951 + read_delay_latency.full = dfixed_const(800 * 1000);
30952 read_delay_latency.full = dfixed_div(read_delay_latency,
30953 rdev->pm.igp_sideport_mclk);
30954 + a.full = dfixed_const(370);
30955 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30956 } else {
30957 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30958 rdev->pm.k8_bandwidth.full)
30959 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30960 index ebc6fac..a8313ed 100644
30961 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30962 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30963 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30964 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30965 struct shrink_control *sc)
30966 {
30967 - static atomic_t start_pool = ATOMIC_INIT(0);
30968 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30969 unsigned i;
30970 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30971 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30972 struct ttm_page_pool *pool;
30973 int shrink_pages = sc->nr_to_scan;
30974
30975 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30976 index 88edacc..1e5412b 100644
30977 --- a/drivers/gpu/drm/via/via_drv.h
30978 +++ b/drivers/gpu/drm/via/via_drv.h
30979 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30980 typedef uint32_t maskarray_t[5];
30981
30982 typedef struct drm_via_irq {
30983 - atomic_t irq_received;
30984 + atomic_unchecked_t irq_received;
30985 uint32_t pending_mask;
30986 uint32_t enable_mask;
30987 wait_queue_head_t irq_queue;
30988 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
30989 struct timeval last_vblank;
30990 int last_vblank_valid;
30991 unsigned usec_per_vblank;
30992 - atomic_t vbl_received;
30993 + atomic_unchecked_t vbl_received;
30994 drm_via_state_t hc_state;
30995 char pci_buf[VIA_PCI_BUF_SIZE];
30996 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30997 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30998 index d391f48..10c8ca3 100644
30999 --- a/drivers/gpu/drm/via/via_irq.c
31000 +++ b/drivers/gpu/drm/via/via_irq.c
31001 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31002 if (crtc != 0)
31003 return 0;
31004
31005 - return atomic_read(&dev_priv->vbl_received);
31006 + return atomic_read_unchecked(&dev_priv->vbl_received);
31007 }
31008
31009 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31010 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31011
31012 status = VIA_READ(VIA_REG_INTERRUPT);
31013 if (status & VIA_IRQ_VBLANK_PENDING) {
31014 - atomic_inc(&dev_priv->vbl_received);
31015 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31016 + atomic_inc_unchecked(&dev_priv->vbl_received);
31017 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31018 do_gettimeofday(&cur_vblank);
31019 if (dev_priv->last_vblank_valid) {
31020 dev_priv->usec_per_vblank =
31021 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31022 dev_priv->last_vblank = cur_vblank;
31023 dev_priv->last_vblank_valid = 1;
31024 }
31025 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31026 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31027 DRM_DEBUG("US per vblank is: %u\n",
31028 dev_priv->usec_per_vblank);
31029 }
31030 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31031
31032 for (i = 0; i < dev_priv->num_irqs; ++i) {
31033 if (status & cur_irq->pending_mask) {
31034 - atomic_inc(&cur_irq->irq_received);
31035 + atomic_inc_unchecked(&cur_irq->irq_received);
31036 DRM_WAKEUP(&cur_irq->irq_queue);
31037 handled = 1;
31038 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31039 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31040 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31041 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31042 masks[irq][4]));
31043 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31044 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31045 } else {
31046 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31047 (((cur_irq_sequence =
31048 - atomic_read(&cur_irq->irq_received)) -
31049 + atomic_read_unchecked(&cur_irq->irq_received)) -
31050 *sequence) <= (1 << 23)));
31051 }
31052 *sequence = cur_irq_sequence;
31053 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31054 }
31055
31056 for (i = 0; i < dev_priv->num_irqs; ++i) {
31057 - atomic_set(&cur_irq->irq_received, 0);
31058 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31059 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31060 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31061 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31062 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31063 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31064 case VIA_IRQ_RELATIVE:
31065 irqwait->request.sequence +=
31066 - atomic_read(&cur_irq->irq_received);
31067 + atomic_read_unchecked(&cur_irq->irq_received);
31068 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31069 case VIA_IRQ_ABSOLUTE:
31070 break;
31071 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31072 index d0f2c07..9ebd9c3 100644
31073 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31074 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31075 @@ -263,7 +263,7 @@ struct vmw_private {
31076 * Fencing and IRQs.
31077 */
31078
31079 - atomic_t marker_seq;
31080 + atomic_unchecked_t marker_seq;
31081 wait_queue_head_t fence_queue;
31082 wait_queue_head_t fifo_queue;
31083 int fence_queue_waiters; /* Protected by hw_mutex */
31084 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31085 index a0c2f12..68ae6cb 100644
31086 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31087 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31088 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31089 (unsigned int) min,
31090 (unsigned int) fifo->capabilities);
31091
31092 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31093 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31094 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31095 vmw_marker_queue_init(&fifo->marker_queue);
31096 return vmw_fifo_send_fence(dev_priv, &dummy);
31097 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31098 if (reserveable)
31099 iowrite32(bytes, fifo_mem +
31100 SVGA_FIFO_RESERVED);
31101 - return fifo_mem + (next_cmd >> 2);
31102 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31103 } else {
31104 need_bounce = true;
31105 }
31106 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31107
31108 fm = vmw_fifo_reserve(dev_priv, bytes);
31109 if (unlikely(fm == NULL)) {
31110 - *seqno = atomic_read(&dev_priv->marker_seq);
31111 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31112 ret = -ENOMEM;
31113 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31114 false, 3*HZ);
31115 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31116 }
31117
31118 do {
31119 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31120 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31121 } while (*seqno == 0);
31122
31123 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31124 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31125 index cabc95f..14b3d77 100644
31126 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31127 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31128 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31129 * emitted. Then the fence is stale and signaled.
31130 */
31131
31132 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31133 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31134 > VMW_FENCE_WRAP);
31135
31136 return ret;
31137 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31138
31139 if (fifo_idle)
31140 down_read(&fifo_state->rwsem);
31141 - signal_seq = atomic_read(&dev_priv->marker_seq);
31142 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31143 ret = 0;
31144
31145 for (;;) {
31146 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31147 index 8a8725c..afed796 100644
31148 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31149 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31150 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31151 while (!vmw_lag_lt(queue, us)) {
31152 spin_lock(&queue->lock);
31153 if (list_empty(&queue->head))
31154 - seqno = atomic_read(&dev_priv->marker_seq);
31155 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31156 else {
31157 marker = list_first_entry(&queue->head,
31158 struct vmw_marker, head);
31159 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31160 index 4c87276..9ecc3c7 100644
31161 --- a/drivers/hid/hid-core.c
31162 +++ b/drivers/hid/hid-core.c
31163 @@ -2151,7 +2151,7 @@ static bool hid_ignore(struct hid_device *hdev)
31164
31165 int hid_add_device(struct hid_device *hdev)
31166 {
31167 - static atomic_t id = ATOMIC_INIT(0);
31168 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31169 int ret;
31170
31171 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31172 @@ -2186,7 +2186,7 @@ int hid_add_device(struct hid_device *hdev)
31173 /* XXX hack, any other cleaner solution after the driver core
31174 * is converted to allow more than 20 bytes as the device name? */
31175 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31176 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31177 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31178
31179 hid_debug_register(hdev, dev_name(&hdev->dev));
31180 ret = device_add(&hdev->dev);
31181 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31182 index eec3291..8ed706b 100644
31183 --- a/drivers/hid/hid-wiimote-debug.c
31184 +++ b/drivers/hid/hid-wiimote-debug.c
31185 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31186 else if (size == 0)
31187 return -EIO;
31188
31189 - if (copy_to_user(u, buf, size))
31190 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31191 return -EFAULT;
31192
31193 *off += size;
31194 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31195 index 14599e2..711c965 100644
31196 --- a/drivers/hid/usbhid/hiddev.c
31197 +++ b/drivers/hid/usbhid/hiddev.c
31198 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31199 break;
31200
31201 case HIDIOCAPPLICATION:
31202 - if (arg < 0 || arg >= hid->maxapplication)
31203 + if (arg >= hid->maxapplication)
31204 break;
31205
31206 for (i = 0; i < hid->maxcollection; i++)
31207 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31208 index 4065374..10ed7dc 100644
31209 --- a/drivers/hv/channel.c
31210 +++ b/drivers/hv/channel.c
31211 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31212 int ret = 0;
31213 int t;
31214
31215 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31216 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31217 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31218 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31219
31220 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31221 if (ret)
31222 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31223 index 86f8885..ab9cb2b 100644
31224 --- a/drivers/hv/hv.c
31225 +++ b/drivers/hv/hv.c
31226 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31227 u64 output_address = (output) ? virt_to_phys(output) : 0;
31228 u32 output_address_hi = output_address >> 32;
31229 u32 output_address_lo = output_address & 0xFFFFFFFF;
31230 - void *hypercall_page = hv_context.hypercall_page;
31231 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31232
31233 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31234 "=a"(hv_status_lo) : "d" (control_hi),
31235 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31236 index b9426a6..677ce34 100644
31237 --- a/drivers/hv/hyperv_vmbus.h
31238 +++ b/drivers/hv/hyperv_vmbus.h
31239 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31240 struct vmbus_connection {
31241 enum vmbus_connect_state conn_state;
31242
31243 - atomic_t next_gpadl_handle;
31244 + atomic_unchecked_t next_gpadl_handle;
31245
31246 /*
31247 * Represents channel interrupts. Each bit position represents a
31248 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31249 index a220e57..428f54d 100644
31250 --- a/drivers/hv/vmbus_drv.c
31251 +++ b/drivers/hv/vmbus_drv.c
31252 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31253 {
31254 int ret = 0;
31255
31256 - static atomic_t device_num = ATOMIC_INIT(0);
31257 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31258
31259 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31260 - atomic_inc_return(&device_num));
31261 + atomic_inc_return_unchecked(&device_num));
31262
31263 child_device_obj->device.bus = &hv_bus;
31264 child_device_obj->device.parent = &hv_acpi_dev->dev;
31265 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31266 index 34ad5a2..e2b0ae8 100644
31267 --- a/drivers/hwmon/acpi_power_meter.c
31268 +++ b/drivers/hwmon/acpi_power_meter.c
31269 @@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31270 return res;
31271
31272 temp /= 1000;
31273 - if (temp < 0)
31274 - return -EINVAL;
31275
31276 mutex_lock(&resource->lock);
31277 resource->trip[attr->index - 7] = temp;
31278 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31279 index 8b011d0..3de24a1 100644
31280 --- a/drivers/hwmon/sht15.c
31281 +++ b/drivers/hwmon/sht15.c
31282 @@ -166,7 +166,7 @@ struct sht15_data {
31283 int supply_uV;
31284 bool supply_uV_valid;
31285 struct work_struct update_supply_work;
31286 - atomic_t interrupt_handled;
31287 + atomic_unchecked_t interrupt_handled;
31288 };
31289
31290 /**
31291 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31292 return ret;
31293
31294 gpio_direction_input(data->pdata->gpio_data);
31295 - atomic_set(&data->interrupt_handled, 0);
31296 + atomic_set_unchecked(&data->interrupt_handled, 0);
31297
31298 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31299 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31300 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31301 /* Only relevant if the interrupt hasn't occurred. */
31302 - if (!atomic_read(&data->interrupt_handled))
31303 + if (!atomic_read_unchecked(&data->interrupt_handled))
31304 schedule_work(&data->read_work);
31305 }
31306 ret = wait_event_timeout(data->wait_queue,
31307 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31308
31309 /* First disable the interrupt */
31310 disable_irq_nosync(irq);
31311 - atomic_inc(&data->interrupt_handled);
31312 + atomic_inc_unchecked(&data->interrupt_handled);
31313 /* Then schedule a reading work struct */
31314 if (data->state != SHT15_READING_NOTHING)
31315 schedule_work(&data->read_work);
31316 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31317 * If not, then start the interrupt again - care here as could
31318 * have gone low in meantime so verify it hasn't!
31319 */
31320 - atomic_set(&data->interrupt_handled, 0);
31321 + atomic_set_unchecked(&data->interrupt_handled, 0);
31322 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31323 /* If still not occurred or another handler was scheduled */
31324 if (gpio_get_value(data->pdata->gpio_data)
31325 - || atomic_read(&data->interrupt_handled))
31326 + || atomic_read_unchecked(&data->interrupt_handled))
31327 return;
31328 }
31329
31330 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31331 index 378fcb5..5e91fa8 100644
31332 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31333 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31334 @@ -43,7 +43,7 @@
31335 extern struct i2c_adapter amd756_smbus;
31336
31337 static struct i2c_adapter *s4882_adapter;
31338 -static struct i2c_algorithm *s4882_algo;
31339 +static i2c_algorithm_no_const *s4882_algo;
31340
31341 /* Wrapper access functions for multiplexed SMBus */
31342 static DEFINE_MUTEX(amd756_lock);
31343 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31344 index 29015eb..af2d8e9 100644
31345 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31346 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31347 @@ -41,7 +41,7 @@
31348 extern struct i2c_adapter *nforce2_smbus;
31349
31350 static struct i2c_adapter *s4985_adapter;
31351 -static struct i2c_algorithm *s4985_algo;
31352 +static i2c_algorithm_no_const *s4985_algo;
31353
31354 /* Wrapper access functions for multiplexed SMBus */
31355 static DEFINE_MUTEX(nforce2_lock);
31356 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31357 index 1038c38..eb92f51 100644
31358 --- a/drivers/i2c/i2c-mux.c
31359 +++ b/drivers/i2c/i2c-mux.c
31360 @@ -30,7 +30,7 @@
31361 /* multiplexer per channel data */
31362 struct i2c_mux_priv {
31363 struct i2c_adapter adap;
31364 - struct i2c_algorithm algo;
31365 + i2c_algorithm_no_const algo;
31366
31367 struct i2c_adapter *parent;
31368 void *mux_priv; /* the mux chip/device */
31369 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31370 index 57d00ca..0145194 100644
31371 --- a/drivers/ide/aec62xx.c
31372 +++ b/drivers/ide/aec62xx.c
31373 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31374 .cable_detect = atp86x_cable_detect,
31375 };
31376
31377 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31378 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31379 { /* 0: AEC6210 */
31380 .name = DRV_NAME,
31381 .init_chipset = init_chipset_aec62xx,
31382 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31383 index 2c8016a..911a27c 100644
31384 --- a/drivers/ide/alim15x3.c
31385 +++ b/drivers/ide/alim15x3.c
31386 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31387 .dma_sff_read_status = ide_dma_sff_read_status,
31388 };
31389
31390 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31391 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31392 .name = DRV_NAME,
31393 .init_chipset = init_chipset_ali15x3,
31394 .init_hwif = init_hwif_ali15x3,
31395 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31396 index 3747b25..56fc995 100644
31397 --- a/drivers/ide/amd74xx.c
31398 +++ b/drivers/ide/amd74xx.c
31399 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31400 .udma_mask = udma, \
31401 }
31402
31403 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31404 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31405 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31406 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31407 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31408 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31409 index 15f0ead..cb43480 100644
31410 --- a/drivers/ide/atiixp.c
31411 +++ b/drivers/ide/atiixp.c
31412 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31413 .cable_detect = atiixp_cable_detect,
31414 };
31415
31416 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31417 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31418 { /* 0: IXP200/300/400/700 */
31419 .name = DRV_NAME,
31420 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31421 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31422 index 5f80312..d1fc438 100644
31423 --- a/drivers/ide/cmd64x.c
31424 +++ b/drivers/ide/cmd64x.c
31425 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31426 .dma_sff_read_status = ide_dma_sff_read_status,
31427 };
31428
31429 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31430 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31431 { /* 0: CMD643 */
31432 .name = DRV_NAME,
31433 .init_chipset = init_chipset_cmd64x,
31434 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31435 index 2c1e5f7..1444762 100644
31436 --- a/drivers/ide/cs5520.c
31437 +++ b/drivers/ide/cs5520.c
31438 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31439 .set_dma_mode = cs5520_set_dma_mode,
31440 };
31441
31442 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31443 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31444 .name = DRV_NAME,
31445 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31446 .port_ops = &cs5520_port_ops,
31447 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31448 index 4dc4eb9..49b40ad 100644
31449 --- a/drivers/ide/cs5530.c
31450 +++ b/drivers/ide/cs5530.c
31451 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31452 .udma_filter = cs5530_udma_filter,
31453 };
31454
31455 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31456 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31457 .name = DRV_NAME,
31458 .init_chipset = init_chipset_cs5530,
31459 .init_hwif = init_hwif_cs5530,
31460 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31461 index 5059faf..18d4c85 100644
31462 --- a/drivers/ide/cs5535.c
31463 +++ b/drivers/ide/cs5535.c
31464 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31465 .cable_detect = cs5535_cable_detect,
31466 };
31467
31468 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31469 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31470 .name = DRV_NAME,
31471 .port_ops = &cs5535_port_ops,
31472 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31473 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31474 index 847553f..3ffb49d 100644
31475 --- a/drivers/ide/cy82c693.c
31476 +++ b/drivers/ide/cy82c693.c
31477 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31478 .set_dma_mode = cy82c693_set_dma_mode,
31479 };
31480
31481 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31482 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31483 .name = DRV_NAME,
31484 .init_iops = init_iops_cy82c693,
31485 .port_ops = &cy82c693_port_ops,
31486 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31487 index 58c51cd..4aec3b8 100644
31488 --- a/drivers/ide/hpt366.c
31489 +++ b/drivers/ide/hpt366.c
31490 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31491 }
31492 };
31493
31494 -static const struct hpt_info hpt36x __devinitdata = {
31495 +static const struct hpt_info hpt36x __devinitconst = {
31496 .chip_name = "HPT36x",
31497 .chip_type = HPT36x,
31498 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31499 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31500 .timings = &hpt36x_timings
31501 };
31502
31503 -static const struct hpt_info hpt370 __devinitdata = {
31504 +static const struct hpt_info hpt370 __devinitconst = {
31505 .chip_name = "HPT370",
31506 .chip_type = HPT370,
31507 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31508 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31509 .timings = &hpt37x_timings
31510 };
31511
31512 -static const struct hpt_info hpt370a __devinitdata = {
31513 +static const struct hpt_info hpt370a __devinitconst = {
31514 .chip_name = "HPT370A",
31515 .chip_type = HPT370A,
31516 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31517 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31518 .timings = &hpt37x_timings
31519 };
31520
31521 -static const struct hpt_info hpt374 __devinitdata = {
31522 +static const struct hpt_info hpt374 __devinitconst = {
31523 .chip_name = "HPT374",
31524 .chip_type = HPT374,
31525 .udma_mask = ATA_UDMA5,
31526 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31527 .timings = &hpt37x_timings
31528 };
31529
31530 -static const struct hpt_info hpt372 __devinitdata = {
31531 +static const struct hpt_info hpt372 __devinitconst = {
31532 .chip_name = "HPT372",
31533 .chip_type = HPT372,
31534 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31535 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31536 .timings = &hpt37x_timings
31537 };
31538
31539 -static const struct hpt_info hpt372a __devinitdata = {
31540 +static const struct hpt_info hpt372a __devinitconst = {
31541 .chip_name = "HPT372A",
31542 .chip_type = HPT372A,
31543 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31544 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31545 .timings = &hpt37x_timings
31546 };
31547
31548 -static const struct hpt_info hpt302 __devinitdata = {
31549 +static const struct hpt_info hpt302 __devinitconst = {
31550 .chip_name = "HPT302",
31551 .chip_type = HPT302,
31552 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31553 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31554 .timings = &hpt37x_timings
31555 };
31556
31557 -static const struct hpt_info hpt371 __devinitdata = {
31558 +static const struct hpt_info hpt371 __devinitconst = {
31559 .chip_name = "HPT371",
31560 .chip_type = HPT371,
31561 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31562 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31563 .timings = &hpt37x_timings
31564 };
31565
31566 -static const struct hpt_info hpt372n __devinitdata = {
31567 +static const struct hpt_info hpt372n __devinitconst = {
31568 .chip_name = "HPT372N",
31569 .chip_type = HPT372N,
31570 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31571 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31572 .timings = &hpt37x_timings
31573 };
31574
31575 -static const struct hpt_info hpt302n __devinitdata = {
31576 +static const struct hpt_info hpt302n __devinitconst = {
31577 .chip_name = "HPT302N",
31578 .chip_type = HPT302N,
31579 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31580 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31581 .timings = &hpt37x_timings
31582 };
31583
31584 -static const struct hpt_info hpt371n __devinitdata = {
31585 +static const struct hpt_info hpt371n __devinitconst = {
31586 .chip_name = "HPT371N",
31587 .chip_type = HPT371N,
31588 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31589 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31590 .dma_sff_read_status = ide_dma_sff_read_status,
31591 };
31592
31593 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31594 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31595 { /* 0: HPT36x */
31596 .name = DRV_NAME,
31597 .init_chipset = init_chipset_hpt366,
31598 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31599 index 8126824..55a2798 100644
31600 --- a/drivers/ide/ide-cd.c
31601 +++ b/drivers/ide/ide-cd.c
31602 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31603 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31604 if ((unsigned long)buf & alignment
31605 || blk_rq_bytes(rq) & q->dma_pad_mask
31606 - || object_is_on_stack(buf))
31607 + || object_starts_on_stack(buf))
31608 drive->dma = 0;
31609 }
31610 }
31611 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31612 index 7f56b73..dab5b67 100644
31613 --- a/drivers/ide/ide-pci-generic.c
31614 +++ b/drivers/ide/ide-pci-generic.c
31615 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31616 .udma_mask = ATA_UDMA6, \
31617 }
31618
31619 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31620 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31621 /* 0: Unknown */
31622 DECLARE_GENERIC_PCI_DEV(0),
31623
31624 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31625 index 560e66d..d5dd180 100644
31626 --- a/drivers/ide/it8172.c
31627 +++ b/drivers/ide/it8172.c
31628 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31629 .set_dma_mode = it8172_set_dma_mode,
31630 };
31631
31632 -static const struct ide_port_info it8172_port_info __devinitdata = {
31633 +static const struct ide_port_info it8172_port_info __devinitconst = {
31634 .name = DRV_NAME,
31635 .port_ops = &it8172_port_ops,
31636 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31637 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31638 index 46816ba..1847aeb 100644
31639 --- a/drivers/ide/it8213.c
31640 +++ b/drivers/ide/it8213.c
31641 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31642 .cable_detect = it8213_cable_detect,
31643 };
31644
31645 -static const struct ide_port_info it8213_chipset __devinitdata = {
31646 +static const struct ide_port_info it8213_chipset __devinitconst = {
31647 .name = DRV_NAME,
31648 .enablebits = { {0x41, 0x80, 0x80} },
31649 .port_ops = &it8213_port_ops,
31650 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31651 index 2e3169f..c5611db 100644
31652 --- a/drivers/ide/it821x.c
31653 +++ b/drivers/ide/it821x.c
31654 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31655 .cable_detect = it821x_cable_detect,
31656 };
31657
31658 -static const struct ide_port_info it821x_chipset __devinitdata = {
31659 +static const struct ide_port_info it821x_chipset __devinitconst = {
31660 .name = DRV_NAME,
31661 .init_chipset = init_chipset_it821x,
31662 .init_hwif = init_hwif_it821x,
31663 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31664 index 74c2c4a..efddd7d 100644
31665 --- a/drivers/ide/jmicron.c
31666 +++ b/drivers/ide/jmicron.c
31667 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31668 .cable_detect = jmicron_cable_detect,
31669 };
31670
31671 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31672 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31673 .name = DRV_NAME,
31674 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31675 .port_ops = &jmicron_port_ops,
31676 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31677 index 95327a2..73f78d8 100644
31678 --- a/drivers/ide/ns87415.c
31679 +++ b/drivers/ide/ns87415.c
31680 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31681 .dma_sff_read_status = superio_dma_sff_read_status,
31682 };
31683
31684 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31685 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31686 .name = DRV_NAME,
31687 .init_hwif = init_hwif_ns87415,
31688 .tp_ops = &ns87415_tp_ops,
31689 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31690 index 1a53a4c..39edc66 100644
31691 --- a/drivers/ide/opti621.c
31692 +++ b/drivers/ide/opti621.c
31693 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31694 .set_pio_mode = opti621_set_pio_mode,
31695 };
31696
31697 -static const struct ide_port_info opti621_chipset __devinitdata = {
31698 +static const struct ide_port_info opti621_chipset __devinitconst = {
31699 .name = DRV_NAME,
31700 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31701 .port_ops = &opti621_port_ops,
31702 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31703 index 9546fe2..2e5ceb6 100644
31704 --- a/drivers/ide/pdc202xx_new.c
31705 +++ b/drivers/ide/pdc202xx_new.c
31706 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31707 .udma_mask = udma, \
31708 }
31709
31710 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31711 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31712 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31713 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31714 };
31715 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31716 index 3a35ec6..5634510 100644
31717 --- a/drivers/ide/pdc202xx_old.c
31718 +++ b/drivers/ide/pdc202xx_old.c
31719 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31720 .max_sectors = sectors, \
31721 }
31722
31723 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31724 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31725 { /* 0: PDC20246 */
31726 .name = DRV_NAME,
31727 .init_chipset = init_chipset_pdc202xx,
31728 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31729 index 1892e81..fe0fd60 100644
31730 --- a/drivers/ide/piix.c
31731 +++ b/drivers/ide/piix.c
31732 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31733 .udma_mask = udma, \
31734 }
31735
31736 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31737 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31738 /* 0: MPIIX */
31739 { /*
31740 * MPIIX actually has only a single IDE channel mapped to
31741 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31742 index a6414a8..c04173e 100644
31743 --- a/drivers/ide/rz1000.c
31744 +++ b/drivers/ide/rz1000.c
31745 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31746 }
31747 }
31748
31749 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31750 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31751 .name = DRV_NAME,
31752 .host_flags = IDE_HFLAG_NO_DMA,
31753 };
31754 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31755 index 356b9b5..d4758eb 100644
31756 --- a/drivers/ide/sc1200.c
31757 +++ b/drivers/ide/sc1200.c
31758 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31759 .dma_sff_read_status = ide_dma_sff_read_status,
31760 };
31761
31762 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31763 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31764 .name = DRV_NAME,
31765 .port_ops = &sc1200_port_ops,
31766 .dma_ops = &sc1200_dma_ops,
31767 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31768 index b7f5b0c..9701038 100644
31769 --- a/drivers/ide/scc_pata.c
31770 +++ b/drivers/ide/scc_pata.c
31771 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31772 .dma_sff_read_status = scc_dma_sff_read_status,
31773 };
31774
31775 -static const struct ide_port_info scc_chipset __devinitdata = {
31776 +static const struct ide_port_info scc_chipset __devinitconst = {
31777 .name = "sccIDE",
31778 .init_iops = init_iops_scc,
31779 .init_dma = scc_init_dma,
31780 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31781 index 35fb8da..24d72ef 100644
31782 --- a/drivers/ide/serverworks.c
31783 +++ b/drivers/ide/serverworks.c
31784 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31785 .cable_detect = svwks_cable_detect,
31786 };
31787
31788 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31789 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31790 { /* 0: OSB4 */
31791 .name = DRV_NAME,
31792 .init_chipset = init_chipset_svwks,
31793 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31794 index ddeda44..46f7e30 100644
31795 --- a/drivers/ide/siimage.c
31796 +++ b/drivers/ide/siimage.c
31797 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31798 .udma_mask = ATA_UDMA6, \
31799 }
31800
31801 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31802 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31803 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31804 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31805 };
31806 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31807 index 4a00225..09e61b4 100644
31808 --- a/drivers/ide/sis5513.c
31809 +++ b/drivers/ide/sis5513.c
31810 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31811 .cable_detect = sis_cable_detect,
31812 };
31813
31814 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31815 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31816 .name = DRV_NAME,
31817 .init_chipset = init_chipset_sis5513,
31818 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31819 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31820 index f21dc2a..d051cd2 100644
31821 --- a/drivers/ide/sl82c105.c
31822 +++ b/drivers/ide/sl82c105.c
31823 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31824 .dma_sff_read_status = ide_dma_sff_read_status,
31825 };
31826
31827 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31828 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31829 .name = DRV_NAME,
31830 .init_chipset = init_chipset_sl82c105,
31831 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31832 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31833 index 864ffe0..863a5e9 100644
31834 --- a/drivers/ide/slc90e66.c
31835 +++ b/drivers/ide/slc90e66.c
31836 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31837 .cable_detect = slc90e66_cable_detect,
31838 };
31839
31840 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31841 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31842 .name = DRV_NAME,
31843 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31844 .port_ops = &slc90e66_port_ops,
31845 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31846 index 4799d5c..1794678 100644
31847 --- a/drivers/ide/tc86c001.c
31848 +++ b/drivers/ide/tc86c001.c
31849 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31850 .dma_sff_read_status = ide_dma_sff_read_status,
31851 };
31852
31853 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31854 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31855 .name = DRV_NAME,
31856 .init_hwif = init_hwif_tc86c001,
31857 .port_ops = &tc86c001_port_ops,
31858 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31859 index 281c914..55ce1b8 100644
31860 --- a/drivers/ide/triflex.c
31861 +++ b/drivers/ide/triflex.c
31862 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31863 .set_dma_mode = triflex_set_mode,
31864 };
31865
31866 -static const struct ide_port_info triflex_device __devinitdata = {
31867 +static const struct ide_port_info triflex_device __devinitconst = {
31868 .name = DRV_NAME,
31869 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31870 .port_ops = &triflex_port_ops,
31871 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31872 index 4b42ca0..e494a98 100644
31873 --- a/drivers/ide/trm290.c
31874 +++ b/drivers/ide/trm290.c
31875 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31876 .dma_check = trm290_dma_check,
31877 };
31878
31879 -static const struct ide_port_info trm290_chipset __devinitdata = {
31880 +static const struct ide_port_info trm290_chipset __devinitconst = {
31881 .name = DRV_NAME,
31882 .init_hwif = init_hwif_trm290,
31883 .tp_ops = &trm290_tp_ops,
31884 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31885 index f46f49c..eb77678 100644
31886 --- a/drivers/ide/via82cxxx.c
31887 +++ b/drivers/ide/via82cxxx.c
31888 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31889 .cable_detect = via82cxxx_cable_detect,
31890 };
31891
31892 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31893 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31894 .name = DRV_NAME,
31895 .init_chipset = init_chipset_via82cxxx,
31896 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31897 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31898 index 73d4531..c90cd2d 100644
31899 --- a/drivers/ieee802154/fakehard.c
31900 +++ b/drivers/ieee802154/fakehard.c
31901 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31902 phy->transmit_power = 0xbf;
31903
31904 dev->netdev_ops = &fake_ops;
31905 - dev->ml_priv = &fake_mlme;
31906 + dev->ml_priv = (void *)&fake_mlme;
31907
31908 priv = netdev_priv(dev);
31909 priv->phy = phy;
31910 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31911 index c889aae..6cf5aa7 100644
31912 --- a/drivers/infiniband/core/cm.c
31913 +++ b/drivers/infiniband/core/cm.c
31914 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31915
31916 struct cm_counter_group {
31917 struct kobject obj;
31918 - atomic_long_t counter[CM_ATTR_COUNT];
31919 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31920 };
31921
31922 struct cm_counter_attribute {
31923 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31924 struct ib_mad_send_buf *msg = NULL;
31925 int ret;
31926
31927 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31928 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31929 counter[CM_REQ_COUNTER]);
31930
31931 /* Quick state check to discard duplicate REQs. */
31932 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31933 if (!cm_id_priv)
31934 return;
31935
31936 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31937 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31938 counter[CM_REP_COUNTER]);
31939 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31940 if (ret)
31941 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31942 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31943 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31944 spin_unlock_irq(&cm_id_priv->lock);
31945 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31946 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31947 counter[CM_RTU_COUNTER]);
31948 goto out;
31949 }
31950 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31951 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31952 dreq_msg->local_comm_id);
31953 if (!cm_id_priv) {
31954 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31955 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31956 counter[CM_DREQ_COUNTER]);
31957 cm_issue_drep(work->port, work->mad_recv_wc);
31958 return -EINVAL;
31959 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31960 case IB_CM_MRA_REP_RCVD:
31961 break;
31962 case IB_CM_TIMEWAIT:
31963 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31964 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31965 counter[CM_DREQ_COUNTER]);
31966 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31967 goto unlock;
31968 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31969 cm_free_msg(msg);
31970 goto deref;
31971 case IB_CM_DREQ_RCVD:
31972 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31973 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31974 counter[CM_DREQ_COUNTER]);
31975 goto unlock;
31976 default:
31977 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31978 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31979 cm_id_priv->msg, timeout)) {
31980 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31981 - atomic_long_inc(&work->port->
31982 + atomic_long_inc_unchecked(&work->port->
31983 counter_group[CM_RECV_DUPLICATES].
31984 counter[CM_MRA_COUNTER]);
31985 goto out;
31986 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31987 break;
31988 case IB_CM_MRA_REQ_RCVD:
31989 case IB_CM_MRA_REP_RCVD:
31990 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31991 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31992 counter[CM_MRA_COUNTER]);
31993 /* fall through */
31994 default:
31995 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31996 case IB_CM_LAP_IDLE:
31997 break;
31998 case IB_CM_MRA_LAP_SENT:
31999 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32000 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32001 counter[CM_LAP_COUNTER]);
32002 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32003 goto unlock;
32004 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32005 cm_free_msg(msg);
32006 goto deref;
32007 case IB_CM_LAP_RCVD:
32008 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32009 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32010 counter[CM_LAP_COUNTER]);
32011 goto unlock;
32012 default:
32013 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32014 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32015 if (cur_cm_id_priv) {
32016 spin_unlock_irq(&cm.lock);
32017 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32018 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32019 counter[CM_SIDR_REQ_COUNTER]);
32020 goto out; /* Duplicate message. */
32021 }
32022 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32023 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32024 msg->retries = 1;
32025
32026 - atomic_long_add(1 + msg->retries,
32027 + atomic_long_add_unchecked(1 + msg->retries,
32028 &port->counter_group[CM_XMIT].counter[attr_index]);
32029 if (msg->retries)
32030 - atomic_long_add(msg->retries,
32031 + atomic_long_add_unchecked(msg->retries,
32032 &port->counter_group[CM_XMIT_RETRIES].
32033 counter[attr_index]);
32034
32035 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32036 }
32037
32038 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32039 - atomic_long_inc(&port->counter_group[CM_RECV].
32040 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32041 counter[attr_id - CM_ATTR_ID_OFFSET]);
32042
32043 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32044 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32045 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32046
32047 return sprintf(buf, "%ld\n",
32048 - atomic_long_read(&group->counter[cm_attr->index]));
32049 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32050 }
32051
32052 static const struct sysfs_ops cm_counter_ops = {
32053 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32054 index 176c8f9..2627b62 100644
32055 --- a/drivers/infiniband/core/fmr_pool.c
32056 +++ b/drivers/infiniband/core/fmr_pool.c
32057 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32058
32059 struct task_struct *thread;
32060
32061 - atomic_t req_ser;
32062 - atomic_t flush_ser;
32063 + atomic_unchecked_t req_ser;
32064 + atomic_unchecked_t flush_ser;
32065
32066 wait_queue_head_t force_wait;
32067 };
32068 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32069 struct ib_fmr_pool *pool = pool_ptr;
32070
32071 do {
32072 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32073 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32074 ib_fmr_batch_release(pool);
32075
32076 - atomic_inc(&pool->flush_ser);
32077 + atomic_inc_unchecked(&pool->flush_ser);
32078 wake_up_interruptible(&pool->force_wait);
32079
32080 if (pool->flush_function)
32081 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32082 }
32083
32084 set_current_state(TASK_INTERRUPTIBLE);
32085 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32086 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32087 !kthread_should_stop())
32088 schedule();
32089 __set_current_state(TASK_RUNNING);
32090 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32091 pool->dirty_watermark = params->dirty_watermark;
32092 pool->dirty_len = 0;
32093 spin_lock_init(&pool->pool_lock);
32094 - atomic_set(&pool->req_ser, 0);
32095 - atomic_set(&pool->flush_ser, 0);
32096 + atomic_set_unchecked(&pool->req_ser, 0);
32097 + atomic_set_unchecked(&pool->flush_ser, 0);
32098 init_waitqueue_head(&pool->force_wait);
32099
32100 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32101 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32102 }
32103 spin_unlock_irq(&pool->pool_lock);
32104
32105 - serial = atomic_inc_return(&pool->req_ser);
32106 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32107 wake_up_process(pool->thread);
32108
32109 if (wait_event_interruptible(pool->force_wait,
32110 - atomic_read(&pool->flush_ser) - serial >= 0))
32111 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32112 return -EINTR;
32113
32114 return 0;
32115 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32116 } else {
32117 list_add_tail(&fmr->list, &pool->dirty_list);
32118 if (++pool->dirty_len >= pool->dirty_watermark) {
32119 - atomic_inc(&pool->req_ser);
32120 + atomic_inc_unchecked(&pool->req_ser);
32121 wake_up_process(pool->thread);
32122 }
32123 }
32124 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32125 index 57e07c6..56d09d4 100644
32126 --- a/drivers/infiniband/hw/cxgb4/mem.c
32127 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32128 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32129 int err;
32130 struct fw_ri_tpte tpt;
32131 u32 stag_idx;
32132 - static atomic_t key;
32133 + static atomic_unchecked_t key;
32134
32135 if (c4iw_fatal_error(rdev))
32136 return -EIO;
32137 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32138 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32139 rdev->stats.stag.max = rdev->stats.stag.cur;
32140 mutex_unlock(&rdev->stats.lock);
32141 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32142 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32143 }
32144 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32145 __func__, stag_state, type, pdid, stag_idx);
32146 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32147 index 79b3dbc..96e5fcc 100644
32148 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32149 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32150 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32151 struct ib_atomic_eth *ateth;
32152 struct ipath_ack_entry *e;
32153 u64 vaddr;
32154 - atomic64_t *maddr;
32155 + atomic64_unchecked_t *maddr;
32156 u64 sdata;
32157 u32 rkey;
32158 u8 next;
32159 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32160 IB_ACCESS_REMOTE_ATOMIC)))
32161 goto nack_acc_unlck;
32162 /* Perform atomic OP and save result. */
32163 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32164 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32165 sdata = be64_to_cpu(ateth->swap_data);
32166 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32167 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32168 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32169 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32170 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32171 be64_to_cpu(ateth->compare_data),
32172 sdata);
32173 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32174 index 1f95bba..9530f87 100644
32175 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32176 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32177 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32178 unsigned long flags;
32179 struct ib_wc wc;
32180 u64 sdata;
32181 - atomic64_t *maddr;
32182 + atomic64_unchecked_t *maddr;
32183 enum ib_wc_status send_status;
32184
32185 /*
32186 @@ -382,11 +382,11 @@ again:
32187 IB_ACCESS_REMOTE_ATOMIC)))
32188 goto acc_err;
32189 /* Perform atomic OP and save result. */
32190 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32191 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32192 sdata = wqe->wr.wr.atomic.compare_add;
32193 *(u64 *) sqp->s_sge.sge.vaddr =
32194 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32195 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32196 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32197 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32198 sdata, wqe->wr.wr.atomic.swap);
32199 goto send_comp;
32200 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32201 index 7140199..da60063 100644
32202 --- a/drivers/infiniband/hw/nes/nes.c
32203 +++ b/drivers/infiniband/hw/nes/nes.c
32204 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32205 LIST_HEAD(nes_adapter_list);
32206 static LIST_HEAD(nes_dev_list);
32207
32208 -atomic_t qps_destroyed;
32209 +atomic_unchecked_t qps_destroyed;
32210
32211 static unsigned int ee_flsh_adapter;
32212 static unsigned int sysfs_nonidx_addr;
32213 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32214 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32215 struct nes_adapter *nesadapter = nesdev->nesadapter;
32216
32217 - atomic_inc(&qps_destroyed);
32218 + atomic_inc_unchecked(&qps_destroyed);
32219
32220 /* Free the control structures */
32221
32222 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32223 index c438e46..ca30356 100644
32224 --- a/drivers/infiniband/hw/nes/nes.h
32225 +++ b/drivers/infiniband/hw/nes/nes.h
32226 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32227 extern unsigned int wqm_quanta;
32228 extern struct list_head nes_adapter_list;
32229
32230 -extern atomic_t cm_connects;
32231 -extern atomic_t cm_accepts;
32232 -extern atomic_t cm_disconnects;
32233 -extern atomic_t cm_closes;
32234 -extern atomic_t cm_connecteds;
32235 -extern atomic_t cm_connect_reqs;
32236 -extern atomic_t cm_rejects;
32237 -extern atomic_t mod_qp_timouts;
32238 -extern atomic_t qps_created;
32239 -extern atomic_t qps_destroyed;
32240 -extern atomic_t sw_qps_destroyed;
32241 +extern atomic_unchecked_t cm_connects;
32242 +extern atomic_unchecked_t cm_accepts;
32243 +extern atomic_unchecked_t cm_disconnects;
32244 +extern atomic_unchecked_t cm_closes;
32245 +extern atomic_unchecked_t cm_connecteds;
32246 +extern atomic_unchecked_t cm_connect_reqs;
32247 +extern atomic_unchecked_t cm_rejects;
32248 +extern atomic_unchecked_t mod_qp_timouts;
32249 +extern atomic_unchecked_t qps_created;
32250 +extern atomic_unchecked_t qps_destroyed;
32251 +extern atomic_unchecked_t sw_qps_destroyed;
32252 extern u32 mh_detected;
32253 extern u32 mh_pauses_sent;
32254 extern u32 cm_packets_sent;
32255 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32256 extern u32 cm_packets_received;
32257 extern u32 cm_packets_dropped;
32258 extern u32 cm_packets_retrans;
32259 -extern atomic_t cm_listens_created;
32260 -extern atomic_t cm_listens_destroyed;
32261 +extern atomic_unchecked_t cm_listens_created;
32262 +extern atomic_unchecked_t cm_listens_destroyed;
32263 extern u32 cm_backlog_drops;
32264 -extern atomic_t cm_loopbacks;
32265 -extern atomic_t cm_nodes_created;
32266 -extern atomic_t cm_nodes_destroyed;
32267 -extern atomic_t cm_accel_dropped_pkts;
32268 -extern atomic_t cm_resets_recvd;
32269 -extern atomic_t pau_qps_created;
32270 -extern atomic_t pau_qps_destroyed;
32271 +extern atomic_unchecked_t cm_loopbacks;
32272 +extern atomic_unchecked_t cm_nodes_created;
32273 +extern atomic_unchecked_t cm_nodes_destroyed;
32274 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32275 +extern atomic_unchecked_t cm_resets_recvd;
32276 +extern atomic_unchecked_t pau_qps_created;
32277 +extern atomic_unchecked_t pau_qps_destroyed;
32278
32279 extern u32 int_mod_timer_init;
32280 extern u32 int_mod_cq_depth_256;
32281 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32282 index 020e95c..fbb3450 100644
32283 --- a/drivers/infiniband/hw/nes/nes_cm.c
32284 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32285 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32286 u32 cm_packets_retrans;
32287 u32 cm_packets_created;
32288 u32 cm_packets_received;
32289 -atomic_t cm_listens_created;
32290 -atomic_t cm_listens_destroyed;
32291 +atomic_unchecked_t cm_listens_created;
32292 +atomic_unchecked_t cm_listens_destroyed;
32293 u32 cm_backlog_drops;
32294 -atomic_t cm_loopbacks;
32295 -atomic_t cm_nodes_created;
32296 -atomic_t cm_nodes_destroyed;
32297 -atomic_t cm_accel_dropped_pkts;
32298 -atomic_t cm_resets_recvd;
32299 +atomic_unchecked_t cm_loopbacks;
32300 +atomic_unchecked_t cm_nodes_created;
32301 +atomic_unchecked_t cm_nodes_destroyed;
32302 +atomic_unchecked_t cm_accel_dropped_pkts;
32303 +atomic_unchecked_t cm_resets_recvd;
32304
32305 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32306 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32307 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32308
32309 static struct nes_cm_core *g_cm_core;
32310
32311 -atomic_t cm_connects;
32312 -atomic_t cm_accepts;
32313 -atomic_t cm_disconnects;
32314 -atomic_t cm_closes;
32315 -atomic_t cm_connecteds;
32316 -atomic_t cm_connect_reqs;
32317 -atomic_t cm_rejects;
32318 +atomic_unchecked_t cm_connects;
32319 +atomic_unchecked_t cm_accepts;
32320 +atomic_unchecked_t cm_disconnects;
32321 +atomic_unchecked_t cm_closes;
32322 +atomic_unchecked_t cm_connecteds;
32323 +atomic_unchecked_t cm_connect_reqs;
32324 +atomic_unchecked_t cm_rejects;
32325
32326 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32327 {
32328 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32329 kfree(listener);
32330 listener = NULL;
32331 ret = 0;
32332 - atomic_inc(&cm_listens_destroyed);
32333 + atomic_inc_unchecked(&cm_listens_destroyed);
32334 } else {
32335 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32336 }
32337 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32338 cm_node->rem_mac);
32339
32340 add_hte_node(cm_core, cm_node);
32341 - atomic_inc(&cm_nodes_created);
32342 + atomic_inc_unchecked(&cm_nodes_created);
32343
32344 return cm_node;
32345 }
32346 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32347 }
32348
32349 atomic_dec(&cm_core->node_cnt);
32350 - atomic_inc(&cm_nodes_destroyed);
32351 + atomic_inc_unchecked(&cm_nodes_destroyed);
32352 nesqp = cm_node->nesqp;
32353 if (nesqp) {
32354 nesqp->cm_node = NULL;
32355 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32356
32357 static void drop_packet(struct sk_buff *skb)
32358 {
32359 - atomic_inc(&cm_accel_dropped_pkts);
32360 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32361 dev_kfree_skb_any(skb);
32362 }
32363
32364 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32365 {
32366
32367 int reset = 0; /* whether to send reset in case of err.. */
32368 - atomic_inc(&cm_resets_recvd);
32369 + atomic_inc_unchecked(&cm_resets_recvd);
32370 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32371 " refcnt=%d\n", cm_node, cm_node->state,
32372 atomic_read(&cm_node->ref_count));
32373 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32374 rem_ref_cm_node(cm_node->cm_core, cm_node);
32375 return NULL;
32376 }
32377 - atomic_inc(&cm_loopbacks);
32378 + atomic_inc_unchecked(&cm_loopbacks);
32379 loopbackremotenode->loopbackpartner = cm_node;
32380 loopbackremotenode->tcp_cntxt.rcv_wscale =
32381 NES_CM_DEFAULT_RCV_WND_SCALE;
32382 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32383 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32384 else {
32385 rem_ref_cm_node(cm_core, cm_node);
32386 - atomic_inc(&cm_accel_dropped_pkts);
32387 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32388 dev_kfree_skb_any(skb);
32389 }
32390 break;
32391 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32392
32393 if ((cm_id) && (cm_id->event_handler)) {
32394 if (issue_disconn) {
32395 - atomic_inc(&cm_disconnects);
32396 + atomic_inc_unchecked(&cm_disconnects);
32397 cm_event.event = IW_CM_EVENT_DISCONNECT;
32398 cm_event.status = disconn_status;
32399 cm_event.local_addr = cm_id->local_addr;
32400 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32401 }
32402
32403 if (issue_close) {
32404 - atomic_inc(&cm_closes);
32405 + atomic_inc_unchecked(&cm_closes);
32406 nes_disconnect(nesqp, 1);
32407
32408 cm_id->provider_data = nesqp;
32409 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32410
32411 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32412 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32413 - atomic_inc(&cm_accepts);
32414 + atomic_inc_unchecked(&cm_accepts);
32415
32416 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32417 netdev_refcnt_read(nesvnic->netdev));
32418 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32419 struct nes_cm_core *cm_core;
32420 u8 *start_buff;
32421
32422 - atomic_inc(&cm_rejects);
32423 + atomic_inc_unchecked(&cm_rejects);
32424 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32425 loopback = cm_node->loopbackpartner;
32426 cm_core = cm_node->cm_core;
32427 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32428 ntohl(cm_id->local_addr.sin_addr.s_addr),
32429 ntohs(cm_id->local_addr.sin_port));
32430
32431 - atomic_inc(&cm_connects);
32432 + atomic_inc_unchecked(&cm_connects);
32433 nesqp->active_conn = 1;
32434
32435 /* cache the cm_id in the qp */
32436 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32437 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32438 return err;
32439 }
32440 - atomic_inc(&cm_listens_created);
32441 + atomic_inc_unchecked(&cm_listens_created);
32442 }
32443
32444 cm_id->add_ref(cm_id);
32445 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32446
32447 if (nesqp->destroyed)
32448 return;
32449 - atomic_inc(&cm_connecteds);
32450 + atomic_inc_unchecked(&cm_connecteds);
32451 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32452 " local port 0x%04X. jiffies = %lu.\n",
32453 nesqp->hwqp.qp_id,
32454 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32455
32456 cm_id->add_ref(cm_id);
32457 ret = cm_id->event_handler(cm_id, &cm_event);
32458 - atomic_inc(&cm_closes);
32459 + atomic_inc_unchecked(&cm_closes);
32460 cm_event.event = IW_CM_EVENT_CLOSE;
32461 cm_event.status = 0;
32462 cm_event.provider_data = cm_id->provider_data;
32463 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32464 return;
32465 cm_id = cm_node->cm_id;
32466
32467 - atomic_inc(&cm_connect_reqs);
32468 + atomic_inc_unchecked(&cm_connect_reqs);
32469 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32470 cm_node, cm_id, jiffies);
32471
32472 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32473 return;
32474 cm_id = cm_node->cm_id;
32475
32476 - atomic_inc(&cm_connect_reqs);
32477 + atomic_inc_unchecked(&cm_connect_reqs);
32478 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32479 cm_node, cm_id, jiffies);
32480
32481 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32482 index 3ba7be3..c81f6ff 100644
32483 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32484 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32485 @@ -40,8 +40,8 @@
32486 #include "nes.h"
32487 #include "nes_mgt.h"
32488
32489 -atomic_t pau_qps_created;
32490 -atomic_t pau_qps_destroyed;
32491 +atomic_unchecked_t pau_qps_created;
32492 +atomic_unchecked_t pau_qps_destroyed;
32493
32494 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32495 {
32496 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32497 {
32498 struct sk_buff *skb;
32499 unsigned long flags;
32500 - atomic_inc(&pau_qps_destroyed);
32501 + atomic_inc_unchecked(&pau_qps_destroyed);
32502
32503 /* Free packets that have not yet been forwarded */
32504 /* Lock is acquired by skb_dequeue when removing the skb */
32505 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32506 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32507 skb_queue_head_init(&nesqp->pau_list);
32508 spin_lock_init(&nesqp->pau_lock);
32509 - atomic_inc(&pau_qps_created);
32510 + atomic_inc_unchecked(&pau_qps_created);
32511 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32512 }
32513
32514 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32515 index f3a3ecf..57d311d 100644
32516 --- a/drivers/infiniband/hw/nes/nes_nic.c
32517 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32518 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32519 target_stat_values[++index] = mh_detected;
32520 target_stat_values[++index] = mh_pauses_sent;
32521 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32522 - target_stat_values[++index] = atomic_read(&cm_connects);
32523 - target_stat_values[++index] = atomic_read(&cm_accepts);
32524 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32525 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32526 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32527 - target_stat_values[++index] = atomic_read(&cm_rejects);
32528 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32529 - target_stat_values[++index] = atomic_read(&qps_created);
32530 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32531 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32532 - target_stat_values[++index] = atomic_read(&cm_closes);
32533 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32534 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32535 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32536 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32537 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32538 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32539 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32540 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32541 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32542 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32543 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32544 target_stat_values[++index] = cm_packets_sent;
32545 target_stat_values[++index] = cm_packets_bounced;
32546 target_stat_values[++index] = cm_packets_created;
32547 target_stat_values[++index] = cm_packets_received;
32548 target_stat_values[++index] = cm_packets_dropped;
32549 target_stat_values[++index] = cm_packets_retrans;
32550 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32551 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32552 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32553 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32554 target_stat_values[++index] = cm_backlog_drops;
32555 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32556 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32557 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32558 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32559 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32560 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32561 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32562 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32563 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32564 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32565 target_stat_values[++index] = nesadapter->free_4kpbl;
32566 target_stat_values[++index] = nesadapter->free_256pbl;
32567 target_stat_values[++index] = int_mod_timer_init;
32568 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32569 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32570 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32571 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32572 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32573 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32574 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32575 }
32576
32577 /**
32578 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32579 index 8b8812d..a5e1133 100644
32580 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32581 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32582 @@ -46,9 +46,9 @@
32583
32584 #include <rdma/ib_umem.h>
32585
32586 -atomic_t mod_qp_timouts;
32587 -atomic_t qps_created;
32588 -atomic_t sw_qps_destroyed;
32589 +atomic_unchecked_t mod_qp_timouts;
32590 +atomic_unchecked_t qps_created;
32591 +atomic_unchecked_t sw_qps_destroyed;
32592
32593 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32594
32595 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32596 if (init_attr->create_flags)
32597 return ERR_PTR(-EINVAL);
32598
32599 - atomic_inc(&qps_created);
32600 + atomic_inc_unchecked(&qps_created);
32601 switch (init_attr->qp_type) {
32602 case IB_QPT_RC:
32603 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32604 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32605 struct iw_cm_event cm_event;
32606 int ret = 0;
32607
32608 - atomic_inc(&sw_qps_destroyed);
32609 + atomic_inc_unchecked(&sw_qps_destroyed);
32610 nesqp->destroyed = 1;
32611
32612 /* Blow away the connection if it exists. */
32613 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32614 index 7e62f41..4c2b8e2 100644
32615 --- a/drivers/infiniband/hw/qib/qib.h
32616 +++ b/drivers/infiniband/hw/qib/qib.h
32617 @@ -51,6 +51,7 @@
32618 #include <linux/completion.h>
32619 #include <linux/kref.h>
32620 #include <linux/sched.h>
32621 +#include <linux/slab.h>
32622
32623 #include "qib_common.h"
32624 #include "qib_verbs.h"
32625 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32626 index da739d9..da1c7f4 100644
32627 --- a/drivers/input/gameport/gameport.c
32628 +++ b/drivers/input/gameport/gameport.c
32629 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32630 */
32631 static void gameport_init_port(struct gameport *gameport)
32632 {
32633 - static atomic_t gameport_no = ATOMIC_INIT(0);
32634 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32635
32636 __module_get(THIS_MODULE);
32637
32638 mutex_init(&gameport->drv_mutex);
32639 device_initialize(&gameport->dev);
32640 dev_set_name(&gameport->dev, "gameport%lu",
32641 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32642 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32643 gameport->dev.bus = &gameport_bus;
32644 gameport->dev.release = gameport_release_port;
32645 if (gameport->parent)
32646 diff --git a/drivers/input/input.c b/drivers/input/input.c
32647 index 8921c61..f5cd63d 100644
32648 --- a/drivers/input/input.c
32649 +++ b/drivers/input/input.c
32650 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32651 */
32652 int input_register_device(struct input_dev *dev)
32653 {
32654 - static atomic_t input_no = ATOMIC_INIT(0);
32655 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32656 struct input_handler *handler;
32657 const char *path;
32658 int error;
32659 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32660 dev->setkeycode = input_default_setkeycode;
32661
32662 dev_set_name(&dev->dev, "input%ld",
32663 - (unsigned long) atomic_inc_return(&input_no) - 1);
32664 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32665
32666 error = device_add(&dev->dev);
32667 if (error)
32668 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32669 index 04c69af..5f92d00 100644
32670 --- a/drivers/input/joystick/sidewinder.c
32671 +++ b/drivers/input/joystick/sidewinder.c
32672 @@ -30,6 +30,7 @@
32673 #include <linux/kernel.h>
32674 #include <linux/module.h>
32675 #include <linux/slab.h>
32676 +#include <linux/sched.h>
32677 #include <linux/init.h>
32678 #include <linux/input.h>
32679 #include <linux/gameport.h>
32680 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32681 index 83811e4..0822b90 100644
32682 --- a/drivers/input/joystick/xpad.c
32683 +++ b/drivers/input/joystick/xpad.c
32684 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32685
32686 static int xpad_led_probe(struct usb_xpad *xpad)
32687 {
32688 - static atomic_t led_seq = ATOMIC_INIT(0);
32689 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32690 long led_no;
32691 struct xpad_led *led;
32692 struct led_classdev *led_cdev;
32693 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32694 if (!led)
32695 return -ENOMEM;
32696
32697 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32698 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32699
32700 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32701 led->xpad = xpad;
32702 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32703 index 0110b5a..d3ad144 100644
32704 --- a/drivers/input/mousedev.c
32705 +++ b/drivers/input/mousedev.c
32706 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32707
32708 spin_unlock_irq(&client->packet_lock);
32709
32710 - if (copy_to_user(buffer, data, count))
32711 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32712 return -EFAULT;
32713
32714 return count;
32715 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32716 index d0f7533..fb8215b 100644
32717 --- a/drivers/input/serio/serio.c
32718 +++ b/drivers/input/serio/serio.c
32719 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32720 */
32721 static void serio_init_port(struct serio *serio)
32722 {
32723 - static atomic_t serio_no = ATOMIC_INIT(0);
32724 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32725
32726 __module_get(THIS_MODULE);
32727
32728 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32729 mutex_init(&serio->drv_mutex);
32730 device_initialize(&serio->dev);
32731 dev_set_name(&serio->dev, "serio%ld",
32732 - (long)atomic_inc_return(&serio_no) - 1);
32733 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32734 serio->dev.bus = &serio_bus;
32735 serio->dev.release = serio_release_port;
32736 serio->dev.groups = serio_device_attr_groups;
32737 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32738 index 38c4bd8..58965d9 100644
32739 --- a/drivers/isdn/capi/capi.c
32740 +++ b/drivers/isdn/capi/capi.c
32741 @@ -83,8 +83,8 @@ struct capiminor {
32742
32743 struct capi20_appl *ap;
32744 u32 ncci;
32745 - atomic_t datahandle;
32746 - atomic_t msgid;
32747 + atomic_unchecked_t datahandle;
32748 + atomic_unchecked_t msgid;
32749
32750 struct tty_port port;
32751 int ttyinstop;
32752 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32753 capimsg_setu16(s, 2, mp->ap->applid);
32754 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32755 capimsg_setu8 (s, 5, CAPI_RESP);
32756 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32757 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32758 capimsg_setu32(s, 8, mp->ncci);
32759 capimsg_setu16(s, 12, datahandle);
32760 }
32761 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32762 mp->outbytes -= len;
32763 spin_unlock_bh(&mp->outlock);
32764
32765 - datahandle = atomic_inc_return(&mp->datahandle);
32766 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32767 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32768 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32769 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32770 capimsg_setu16(skb->data, 2, mp->ap->applid);
32771 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32772 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32773 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32774 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32775 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32776 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32777 capimsg_setu16(skb->data, 16, len); /* Data length */
32778 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32779 index a6d9fd2..afdb8a3 100644
32780 --- a/drivers/isdn/gigaset/interface.c
32781 +++ b/drivers/isdn/gigaset/interface.c
32782 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32783 }
32784 tty->driver_data = cs;
32785
32786 - ++cs->port.count;
32787 + atomic_inc(&cs->port.count);
32788
32789 - if (cs->port.count == 1) {
32790 + if (atomic_read(&cs->port.count) == 1) {
32791 tty_port_tty_set(&cs->port, tty);
32792 tty->low_latency = 1;
32793 }
32794 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32795
32796 if (!cs->connected)
32797 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32798 - else if (!cs->port.count)
32799 + else if (!atomic_read(&cs->port.count))
32800 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32801 - else if (!--cs->port.count)
32802 + else if (!atomic_dec_return(&cs->port.count))
32803 tty_port_tty_set(&cs->port, NULL);
32804
32805 mutex_unlock(&cs->mutex);
32806 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32807 index 821f7ac..28d4030 100644
32808 --- a/drivers/isdn/hardware/avm/b1.c
32809 +++ b/drivers/isdn/hardware/avm/b1.c
32810 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32811 }
32812 if (left) {
32813 if (t4file->user) {
32814 - if (copy_from_user(buf, dp, left))
32815 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32816 return -EFAULT;
32817 } else {
32818 memcpy(buf, dp, left);
32819 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32820 }
32821 if (left) {
32822 if (config->user) {
32823 - if (copy_from_user(buf, dp, left))
32824 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32825 return -EFAULT;
32826 } else {
32827 memcpy(buf, dp, left);
32828 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32829 index dd6b53a..19d9ee6 100644
32830 --- a/drivers/isdn/hardware/eicon/divasync.h
32831 +++ b/drivers/isdn/hardware/eicon/divasync.h
32832 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32833 } diva_didd_add_adapter_t;
32834 typedef struct _diva_didd_remove_adapter {
32835 IDI_CALL p_request;
32836 -} diva_didd_remove_adapter_t;
32837 +} __no_const diva_didd_remove_adapter_t;
32838 typedef struct _diva_didd_read_adapter_array {
32839 void *buffer;
32840 dword length;
32841 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32842 index d303e65..28bcb7b 100644
32843 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32844 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32845 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32846 typedef struct _diva_os_idi_adapter_interface {
32847 diva_init_card_proc_t cleanup_adapter_proc;
32848 diva_cmd_card_proc_t cmd_proc;
32849 -} diva_os_idi_adapter_interface_t;
32850 +} __no_const diva_os_idi_adapter_interface_t;
32851
32852 typedef struct _diva_os_xdi_adapter {
32853 struct list_head link;
32854 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32855 index 7bc5067..fd36232 100644
32856 --- a/drivers/isdn/i4l/isdn_tty.c
32857 +++ b/drivers/isdn/i4l/isdn_tty.c
32858 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32859 port = &info->port;
32860 #ifdef ISDN_DEBUG_MODEM_OPEN
32861 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32862 - port->count);
32863 + atomic_read(&port->count))
32864 #endif
32865 - port->count++;
32866 + atomic_inc(&port->count);
32867 tty->driver_data = info;
32868 port->tty = tty;
32869 tty->port = port;
32870 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32871 #endif
32872 return;
32873 }
32874 - if ((tty->count == 1) && (port->count != 1)) {
32875 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32876 /*
32877 * Uh, oh. tty->count is 1, which means that the tty
32878 * structure will be freed. Info->count should always
32879 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32880 * serial port won't be shutdown.
32881 */
32882 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32883 - "info->count is %d\n", port->count);
32884 - port->count = 1;
32885 + "info->count is %d\n", atomic_read(&port->count));
32886 + atomic_set(&port->count, 1);
32887 }
32888 - if (--port->count < 0) {
32889 + if (atomic_dec_return(&port->count) < 0) {
32890 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32891 - info->line, port->count);
32892 - port->count = 0;
32893 + info->line, atomic_read(&port->count));
32894 + atomic_set(&port->count, 0);
32895 }
32896 - if (port->count) {
32897 + if (atomic_read(&port->count)) {
32898 #ifdef ISDN_DEBUG_MODEM_OPEN
32899 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32900 #endif
32901 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32902 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32903 return;
32904 isdn_tty_shutdown(info);
32905 - port->count = 0;
32906 + atomic_set(&port->count, 0);
32907 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32908 port->tty = NULL;
32909 wake_up_interruptible(&port->open_wait);
32910 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32911 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32912 modem_info *info = &dev->mdm.info[i];
32913
32914 - if (info->port.count == 0)
32915 + if (atomic_read(&info->port.count) == 0)
32916 continue;
32917 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32918 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32919 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32920 index e74df7c..03a03ba 100644
32921 --- a/drivers/isdn/icn/icn.c
32922 +++ b/drivers/isdn/icn/icn.c
32923 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32924 if (count > len)
32925 count = len;
32926 if (user) {
32927 - if (copy_from_user(msg, buf, count))
32928 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32929 return -EFAULT;
32930 } else
32931 memcpy(msg, buf, count);
32932 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32933 index b5fdcb7..5b6c59f 100644
32934 --- a/drivers/lguest/core.c
32935 +++ b/drivers/lguest/core.c
32936 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32937 * it's worked so far. The end address needs +1 because __get_vm_area
32938 * allocates an extra guard page, so we need space for that.
32939 */
32940 +
32941 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32942 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32943 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32944 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32945 +#else
32946 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32947 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32948 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32949 +#endif
32950 +
32951 if (!switcher_vma) {
32952 err = -ENOMEM;
32953 printk("lguest: could not map switcher pages high\n");
32954 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32955 * Now the Switcher is mapped at the right address, we can't fail!
32956 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32957 */
32958 - memcpy(switcher_vma->addr, start_switcher_text,
32959 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32960 end_switcher_text - start_switcher_text);
32961
32962 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32963 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32964 index 39809035..ce25c5e 100644
32965 --- a/drivers/lguest/x86/core.c
32966 +++ b/drivers/lguest/x86/core.c
32967 @@ -59,7 +59,7 @@ static struct {
32968 /* Offset from where switcher.S was compiled to where we've copied it */
32969 static unsigned long switcher_offset(void)
32970 {
32971 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32972 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32973 }
32974
32975 /* This cpu's struct lguest_pages. */
32976 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32977 * These copies are pretty cheap, so we do them unconditionally: */
32978 /* Save the current Host top-level page directory.
32979 */
32980 +
32981 +#ifdef CONFIG_PAX_PER_CPU_PGD
32982 + pages->state.host_cr3 = read_cr3();
32983 +#else
32984 pages->state.host_cr3 = __pa(current->mm->pgd);
32985 +#endif
32986 +
32987 /*
32988 * Set up the Guest's page tables to see this CPU's pages (and no
32989 * other CPU's pages).
32990 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32991 * compiled-in switcher code and the high-mapped copy we just made.
32992 */
32993 for (i = 0; i < IDT_ENTRIES; i++)
32994 - default_idt_entries[i] += switcher_offset();
32995 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32996
32997 /*
32998 * Set up the Switcher's per-cpu areas.
32999 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33000 * it will be undisturbed when we switch. To change %cs and jump we
33001 * need this structure to feed to Intel's "lcall" instruction.
33002 */
33003 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33004 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33005 lguest_entry.segment = LGUEST_CS;
33006
33007 /*
33008 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33009 index 40634b0..4f5855e 100644
33010 --- a/drivers/lguest/x86/switcher_32.S
33011 +++ b/drivers/lguest/x86/switcher_32.S
33012 @@ -87,6 +87,7 @@
33013 #include <asm/page.h>
33014 #include <asm/segment.h>
33015 #include <asm/lguest.h>
33016 +#include <asm/processor-flags.h>
33017
33018 // We mark the start of the code to copy
33019 // It's placed in .text tho it's never run here
33020 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33021 // Changes type when we load it: damn Intel!
33022 // For after we switch over our page tables
33023 // That entry will be read-only: we'd crash.
33024 +
33025 +#ifdef CONFIG_PAX_KERNEXEC
33026 + mov %cr0, %edx
33027 + xor $X86_CR0_WP, %edx
33028 + mov %edx, %cr0
33029 +#endif
33030 +
33031 movl $(GDT_ENTRY_TSS*8), %edx
33032 ltr %dx
33033
33034 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33035 // Let's clear it again for our return.
33036 // The GDT descriptor of the Host
33037 // Points to the table after two "size" bytes
33038 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33039 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33040 // Clear "used" from type field (byte 5, bit 2)
33041 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33042 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33043 +
33044 +#ifdef CONFIG_PAX_KERNEXEC
33045 + mov %cr0, %eax
33046 + xor $X86_CR0_WP, %eax
33047 + mov %eax, %cr0
33048 +#endif
33049
33050 // Once our page table's switched, the Guest is live!
33051 // The Host fades as we run this final step.
33052 @@ -295,13 +309,12 @@ deliver_to_host:
33053 // I consulted gcc, and it gave
33054 // These instructions, which I gladly credit:
33055 leal (%edx,%ebx,8), %eax
33056 - movzwl (%eax),%edx
33057 - movl 4(%eax), %eax
33058 - xorw %ax, %ax
33059 - orl %eax, %edx
33060 + movl 4(%eax), %edx
33061 + movw (%eax), %dx
33062 // Now the address of the handler's in %edx
33063 // We call it now: its "iret" drops us home.
33064 - jmp *%edx
33065 + ljmp $__KERNEL_CS, $1f
33066 +1: jmp *%edx
33067
33068 // Every interrupt can come to us here
33069 // But we must truly tell each apart.
33070 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33071 index 20e5c2c..9e849a9 100644
33072 --- a/drivers/macintosh/macio_asic.c
33073 +++ b/drivers/macintosh/macio_asic.c
33074 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33075 * MacIO is matched against any Apple ID, it's probe() function
33076 * will then decide wether it applies or not
33077 */
33078 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33079 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33080 .vendor = PCI_VENDOR_ID_APPLE,
33081 .device = PCI_ANY_ID,
33082 .subvendor = PCI_ANY_ID,
33083 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33084 index 15dbe03..743fc65 100644
33085 --- a/drivers/md/bitmap.c
33086 +++ b/drivers/md/bitmap.c
33087 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33088 chunk_kb ? "KB" : "B");
33089 if (bitmap->storage.file) {
33090 seq_printf(seq, ", file: ");
33091 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33092 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33093 }
33094
33095 seq_printf(seq, "\n");
33096 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33097 index a1a3e6d..1918bfc 100644
33098 --- a/drivers/md/dm-ioctl.c
33099 +++ b/drivers/md/dm-ioctl.c
33100 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33101 cmd == DM_LIST_VERSIONS_CMD)
33102 return 0;
33103
33104 - if ((cmd == DM_DEV_CREATE_CMD)) {
33105 + if (cmd == DM_DEV_CREATE_CMD) {
33106 if (!*param->name) {
33107 DMWARN("name not supplied when creating device");
33108 return -EINVAL;
33109 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33110 index b58b7a3..8018b19 100644
33111 --- a/drivers/md/dm-raid1.c
33112 +++ b/drivers/md/dm-raid1.c
33113 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33114
33115 struct mirror {
33116 struct mirror_set *ms;
33117 - atomic_t error_count;
33118 + atomic_unchecked_t error_count;
33119 unsigned long error_type;
33120 struct dm_dev *dev;
33121 sector_t offset;
33122 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33123 struct mirror *m;
33124
33125 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33126 - if (!atomic_read(&m->error_count))
33127 + if (!atomic_read_unchecked(&m->error_count))
33128 return m;
33129
33130 return NULL;
33131 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33132 * simple way to tell if a device has encountered
33133 * errors.
33134 */
33135 - atomic_inc(&m->error_count);
33136 + atomic_inc_unchecked(&m->error_count);
33137
33138 if (test_and_set_bit(error_type, &m->error_type))
33139 return;
33140 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33141 struct mirror *m = get_default_mirror(ms);
33142
33143 do {
33144 - if (likely(!atomic_read(&m->error_count)))
33145 + if (likely(!atomic_read_unchecked(&m->error_count)))
33146 return m;
33147
33148 if (m-- == ms->mirror)
33149 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33150 {
33151 struct mirror *default_mirror = get_default_mirror(m->ms);
33152
33153 - return !atomic_read(&default_mirror->error_count);
33154 + return !atomic_read_unchecked(&default_mirror->error_count);
33155 }
33156
33157 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33158 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33159 */
33160 if (likely(region_in_sync(ms, region, 1)))
33161 m = choose_mirror(ms, bio->bi_sector);
33162 - else if (m && atomic_read(&m->error_count))
33163 + else if (m && atomic_read_unchecked(&m->error_count))
33164 m = NULL;
33165
33166 if (likely(m))
33167 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33168 }
33169
33170 ms->mirror[mirror].ms = ms;
33171 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33172 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33173 ms->mirror[mirror].error_type = 0;
33174 ms->mirror[mirror].offset = offset;
33175
33176 @@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33177 */
33178 static char device_status_char(struct mirror *m)
33179 {
33180 - if (!atomic_read(&(m->error_count)))
33181 + if (!atomic_read_unchecked(&(m->error_count)))
33182 return 'A';
33183
33184 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33185 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33186 index 35c94ff..20d4c17 100644
33187 --- a/drivers/md/dm-stripe.c
33188 +++ b/drivers/md/dm-stripe.c
33189 @@ -20,7 +20,7 @@ struct stripe {
33190 struct dm_dev *dev;
33191 sector_t physical_start;
33192
33193 - atomic_t error_count;
33194 + atomic_unchecked_t error_count;
33195 };
33196
33197 struct stripe_c {
33198 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33199 kfree(sc);
33200 return r;
33201 }
33202 - atomic_set(&(sc->stripe[i].error_count), 0);
33203 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33204 }
33205
33206 ti->private = sc;
33207 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33208 DMEMIT("%d ", sc->stripes);
33209 for (i = 0; i < sc->stripes; i++) {
33210 DMEMIT("%s ", sc->stripe[i].dev->name);
33211 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33212 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33213 'D' : 'A';
33214 }
33215 buffer[i] = '\0';
33216 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33217 */
33218 for (i = 0; i < sc->stripes; i++)
33219 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33220 - atomic_inc(&(sc->stripe[i].error_count));
33221 - if (atomic_read(&(sc->stripe[i].error_count)) <
33222 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33223 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33224 DM_IO_ERROR_THRESHOLD)
33225 schedule_work(&sc->trigger_event);
33226 }
33227 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33228 index 2e227fb..44ead1f 100644
33229 --- a/drivers/md/dm-table.c
33230 +++ b/drivers/md/dm-table.c
33231 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33232 if (!dev_size)
33233 return 0;
33234
33235 - if ((start >= dev_size) || (start + len > dev_size)) {
33236 + if ((start >= dev_size) || (len > dev_size - start)) {
33237 DMWARN("%s: %s too small for target: "
33238 "start=%llu, len=%llu, dev_size=%llu",
33239 dm_device_name(ti->table->md), bdevname(bdev, b),
33240 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33241 index 3e2907f..c28851a 100644
33242 --- a/drivers/md/dm-thin-metadata.c
33243 +++ b/drivers/md/dm-thin-metadata.c
33244 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33245
33246 pmd->info.tm = tm;
33247 pmd->info.levels = 2;
33248 - pmd->info.value_type.context = pmd->data_sm;
33249 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33250 pmd->info.value_type.size = sizeof(__le64);
33251 pmd->info.value_type.inc = data_block_inc;
33252 pmd->info.value_type.dec = data_block_dec;
33253 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33254
33255 pmd->bl_info.tm = tm;
33256 pmd->bl_info.levels = 1;
33257 - pmd->bl_info.value_type.context = pmd->data_sm;
33258 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33259 pmd->bl_info.value_type.size = sizeof(__le64);
33260 pmd->bl_info.value_type.inc = data_block_inc;
33261 pmd->bl_info.value_type.dec = data_block_dec;
33262 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33263 index e24143c..ce2f21a1 100644
33264 --- a/drivers/md/dm.c
33265 +++ b/drivers/md/dm.c
33266 @@ -176,9 +176,9 @@ struct mapped_device {
33267 /*
33268 * Event handling.
33269 */
33270 - atomic_t event_nr;
33271 + atomic_unchecked_t event_nr;
33272 wait_queue_head_t eventq;
33273 - atomic_t uevent_seq;
33274 + atomic_unchecked_t uevent_seq;
33275 struct list_head uevent_list;
33276 spinlock_t uevent_lock; /* Protect access to uevent_list */
33277
33278 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33279 rwlock_init(&md->map_lock);
33280 atomic_set(&md->holders, 1);
33281 atomic_set(&md->open_count, 0);
33282 - atomic_set(&md->event_nr, 0);
33283 - atomic_set(&md->uevent_seq, 0);
33284 + atomic_set_unchecked(&md->event_nr, 0);
33285 + atomic_set_unchecked(&md->uevent_seq, 0);
33286 INIT_LIST_HEAD(&md->uevent_list);
33287 spin_lock_init(&md->uevent_lock);
33288
33289 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33290
33291 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33292
33293 - atomic_inc(&md->event_nr);
33294 + atomic_inc_unchecked(&md->event_nr);
33295 wake_up(&md->eventq);
33296 }
33297
33298 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33299
33300 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33301 {
33302 - return atomic_add_return(1, &md->uevent_seq);
33303 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33304 }
33305
33306 uint32_t dm_get_event_nr(struct mapped_device *md)
33307 {
33308 - return atomic_read(&md->event_nr);
33309 + return atomic_read_unchecked(&md->event_nr);
33310 }
33311
33312 int dm_wait_event(struct mapped_device *md, int event_nr)
33313 {
33314 return wait_event_interruptible(md->eventq,
33315 - (event_nr != atomic_read(&md->event_nr)));
33316 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33317 }
33318
33319 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33320 diff --git a/drivers/md/md.c b/drivers/md/md.c
33321 index d5ab449..7e9ed7b 100644
33322 --- a/drivers/md/md.c
33323 +++ b/drivers/md/md.c
33324 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33325 * start build, activate spare
33326 */
33327 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33328 -static atomic_t md_event_count;
33329 +static atomic_unchecked_t md_event_count;
33330 void md_new_event(struct mddev *mddev)
33331 {
33332 - atomic_inc(&md_event_count);
33333 + atomic_inc_unchecked(&md_event_count);
33334 wake_up(&md_event_waiters);
33335 }
33336 EXPORT_SYMBOL_GPL(md_new_event);
33337 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33338 */
33339 static void md_new_event_inintr(struct mddev *mddev)
33340 {
33341 - atomic_inc(&md_event_count);
33342 + atomic_inc_unchecked(&md_event_count);
33343 wake_up(&md_event_waiters);
33344 }
33345
33346 @@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33347 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33348 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33349 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33350 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33351 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33352
33353 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33354 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33355 @@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33356 else
33357 sb->resync_offset = cpu_to_le64(0);
33358
33359 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33360 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33361
33362 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33363 sb->size = cpu_to_le64(mddev->dev_sectors);
33364 @@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33365 static ssize_t
33366 errors_show(struct md_rdev *rdev, char *page)
33367 {
33368 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33369 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33370 }
33371
33372 static ssize_t
33373 @@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33374 char *e;
33375 unsigned long n = simple_strtoul(buf, &e, 10);
33376 if (*buf && (*e == 0 || *e == '\n')) {
33377 - atomic_set(&rdev->corrected_errors, n);
33378 + atomic_set_unchecked(&rdev->corrected_errors, n);
33379 return len;
33380 }
33381 return -EINVAL;
33382 @@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33383 rdev->sb_loaded = 0;
33384 rdev->bb_page = NULL;
33385 atomic_set(&rdev->nr_pending, 0);
33386 - atomic_set(&rdev->read_errors, 0);
33387 - atomic_set(&rdev->corrected_errors, 0);
33388 + atomic_set_unchecked(&rdev->read_errors, 0);
33389 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33390
33391 INIT_LIST_HEAD(&rdev->same_set);
33392 init_waitqueue_head(&rdev->blocked_wait);
33393 @@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33394
33395 spin_unlock(&pers_lock);
33396 seq_printf(seq, "\n");
33397 - seq->poll_event = atomic_read(&md_event_count);
33398 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33399 return 0;
33400 }
33401 if (v == (void*)2) {
33402 @@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33403 return error;
33404
33405 seq = file->private_data;
33406 - seq->poll_event = atomic_read(&md_event_count);
33407 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33408 return error;
33409 }
33410
33411 @@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33412 /* always allow read */
33413 mask = POLLIN | POLLRDNORM;
33414
33415 - if (seq->poll_event != atomic_read(&md_event_count))
33416 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33417 mask |= POLLERR | POLLPRI;
33418 return mask;
33419 }
33420 @@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33421 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33422 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33423 (int)part_stat_read(&disk->part0, sectors[1]) -
33424 - atomic_read(&disk->sync_io);
33425 + atomic_read_unchecked(&disk->sync_io);
33426 /* sync IO will cause sync_io to increase before the disk_stats
33427 * as sync_io is counted when a request starts, and
33428 * disk_stats is counted when it completes.
33429 diff --git a/drivers/md/md.h b/drivers/md/md.h
33430 index 7b4a3c3..994ad4f 100644
33431 --- a/drivers/md/md.h
33432 +++ b/drivers/md/md.h
33433 @@ -94,13 +94,13 @@ struct md_rdev {
33434 * only maintained for arrays that
33435 * support hot removal
33436 */
33437 - atomic_t read_errors; /* number of consecutive read errors that
33438 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33439 * we have tried to ignore.
33440 */
33441 struct timespec last_read_error; /* monotonic time since our
33442 * last read error
33443 */
33444 - atomic_t corrected_errors; /* number of corrected read errors,
33445 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33446 * for reporting to userspace and storing
33447 * in superblock.
33448 */
33449 @@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33450
33451 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33452 {
33453 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33454 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33455 }
33456
33457 struct md_personality
33458 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33459 index fc90c11..c8cd9a9 100644
33460 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33461 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33462 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33463 /*----------------------------------------------------------------*/
33464
33465 struct sm_checker {
33466 - struct dm_space_map sm;
33467 + dm_space_map_no_const sm;
33468
33469 struct count_array old_counts;
33470 struct count_array counts;
33471 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33472 index 3d0ed53..35dc592 100644
33473 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33474 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33475 @@ -23,7 +23,7 @@
33476 * Space map interface.
33477 */
33478 struct sm_disk {
33479 - struct dm_space_map sm;
33480 + dm_space_map_no_const sm;
33481
33482 struct ll_disk ll;
33483 struct ll_disk old_ll;
33484 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33485 index e89ae5e..062e4c2 100644
33486 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33487 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33488 @@ -43,7 +43,7 @@ struct block_op {
33489 };
33490
33491 struct sm_metadata {
33492 - struct dm_space_map sm;
33493 + dm_space_map_no_const sm;
33494
33495 struct ll_disk ll;
33496 struct ll_disk old_ll;
33497 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33498 index 1cbfc6b..56e1dbb 100644
33499 --- a/drivers/md/persistent-data/dm-space-map.h
33500 +++ b/drivers/md/persistent-data/dm-space-map.h
33501 @@ -60,6 +60,7 @@ struct dm_space_map {
33502 int (*root_size)(struct dm_space_map *sm, size_t *result);
33503 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33504 };
33505 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33506
33507 /*----------------------------------------------------------------*/
33508
33509 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33510 index cacd008..2823610 100644
33511 --- a/drivers/md/raid1.c
33512 +++ b/drivers/md/raid1.c
33513 @@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33514 if (r1_sync_page_io(rdev, sect, s,
33515 bio->bi_io_vec[idx].bv_page,
33516 READ) != 0)
33517 - atomic_add(s, &rdev->corrected_errors);
33518 + atomic_add_unchecked(s, &rdev->corrected_errors);
33519 }
33520 sectors -= s;
33521 sect += s;
33522 @@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33523 test_bit(In_sync, &rdev->flags)) {
33524 if (r1_sync_page_io(rdev, sect, s,
33525 conf->tmppage, READ)) {
33526 - atomic_add(s, &rdev->corrected_errors);
33527 + atomic_add_unchecked(s, &rdev->corrected_errors);
33528 printk(KERN_INFO
33529 "md/raid1:%s: read error corrected "
33530 "(%d sectors at %llu on %s)\n",
33531 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33532 index 8da6282..8ec7103 100644
33533 --- a/drivers/md/raid10.c
33534 +++ b/drivers/md/raid10.c
33535 @@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33536 /* The write handler will notice the lack of
33537 * R10BIO_Uptodate and record any errors etc
33538 */
33539 - atomic_add(r10_bio->sectors,
33540 + atomic_add_unchecked(r10_bio->sectors,
33541 &conf->mirrors[d].rdev->corrected_errors);
33542
33543 /* for reconstruct, we always reschedule after a read.
33544 @@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33545 {
33546 struct timespec cur_time_mon;
33547 unsigned long hours_since_last;
33548 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33549 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33550
33551 ktime_get_ts(&cur_time_mon);
33552
33553 @@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33554 * overflowing the shift of read_errors by hours_since_last.
33555 */
33556 if (hours_since_last >= 8 * sizeof(read_errors))
33557 - atomic_set(&rdev->read_errors, 0);
33558 + atomic_set_unchecked(&rdev->read_errors, 0);
33559 else
33560 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33561 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33562 }
33563
33564 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33565 @@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33566 return;
33567
33568 check_decay_read_errors(mddev, rdev);
33569 - atomic_inc(&rdev->read_errors);
33570 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33571 + atomic_inc_unchecked(&rdev->read_errors);
33572 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33573 char b[BDEVNAME_SIZE];
33574 bdevname(rdev->bdev, b);
33575
33576 @@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33577 "md/raid10:%s: %s: Raid device exceeded "
33578 "read_error threshold [cur %d:max %d]\n",
33579 mdname(mddev), b,
33580 - atomic_read(&rdev->read_errors), max_read_errors);
33581 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33582 printk(KERN_NOTICE
33583 "md/raid10:%s: %s: Failing raid device\n",
33584 mdname(mddev), b);
33585 @@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33586 sect +
33587 choose_data_offset(r10_bio, rdev)),
33588 bdevname(rdev->bdev, b));
33589 - atomic_add(s, &rdev->corrected_errors);
33590 + atomic_add_unchecked(s, &rdev->corrected_errors);
33591 }
33592
33593 rdev_dec_pending(rdev, mddev);
33594 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33595 index 04348d7..62a4b9b 100644
33596 --- a/drivers/md/raid5.c
33597 +++ b/drivers/md/raid5.c
33598 @@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33599 mdname(conf->mddev), STRIPE_SECTORS,
33600 (unsigned long long)s,
33601 bdevname(rdev->bdev, b));
33602 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33603 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33604 clear_bit(R5_ReadError, &sh->dev[i].flags);
33605 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33606 }
33607 - if (atomic_read(&rdev->read_errors))
33608 - atomic_set(&rdev->read_errors, 0);
33609 + if (atomic_read_unchecked(&rdev->read_errors))
33610 + atomic_set_unchecked(&rdev->read_errors, 0);
33611 } else {
33612 const char *bdn = bdevname(rdev->bdev, b);
33613 int retry = 0;
33614 int set_bad = 0;
33615
33616 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33617 - atomic_inc(&rdev->read_errors);
33618 + atomic_inc_unchecked(&rdev->read_errors);
33619 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33620 printk_ratelimited(
33621 KERN_WARNING
33622 @@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33623 mdname(conf->mddev),
33624 (unsigned long long)s,
33625 bdn);
33626 - } else if (atomic_read(&rdev->read_errors)
33627 + } else if (atomic_read_unchecked(&rdev->read_errors)
33628 > conf->max_nr_stripes)
33629 printk(KERN_WARNING
33630 "md/raid:%s: Too many read errors, failing device %s.\n",
33631 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33632 index 131b938..8572ed1 100644
33633 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33634 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33635 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33636 .subvendor = _subvend, .subdevice = _subdev, \
33637 .driver_data = (unsigned long)&_driverdata }
33638
33639 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33640 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33641 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33642 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33643 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33644 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33645 index fa7188a..04a045e 100644
33646 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33647 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33648 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33649 union {
33650 dmx_ts_cb ts;
33651 dmx_section_cb sec;
33652 - } cb;
33653 + } __no_const cb;
33654
33655 struct dvb_demux *demux;
33656 void *priv;
33657 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33658 index 39eab73..60033e7 100644
33659 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33660 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33661 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33662 const struct dvb_device *template, void *priv, int type)
33663 {
33664 struct dvb_device *dvbdev;
33665 - struct file_operations *dvbdevfops;
33666 + file_operations_no_const *dvbdevfops;
33667 struct device *clsdev;
33668 int minor;
33669 int id;
33670 diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33671 index 4008b9c..ce714f5 100644
33672 --- a/drivers/media/dvb/dvb-usb/az6007.c
33673 +++ b/drivers/media/dvb/dvb-usb/az6007.c
33674 @@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33675 int ret;
33676
33677 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33678 - memcpy(mac, st->data, sizeof(mac));
33679 + memcpy(mac, st->data, 6);
33680
33681 if (ret > 0)
33682 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33683 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33684 index 3940bb0..fb3952a 100644
33685 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33686 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33687 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33688
33689 struct dib0700_adapter_state {
33690 int (*set_param_save) (struct dvb_frontend *);
33691 -};
33692 +} __no_const;
33693
33694 static int dib7070_set_param_override(struct dvb_frontend *fe)
33695 {
33696 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33697 index 9382895..ac8093c 100644
33698 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33699 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33700 @@ -95,7 +95,7 @@ struct su3000_state {
33701
33702 struct s6x0_state {
33703 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33704 -};
33705 +} __no_const;
33706
33707 /* debug */
33708 static int dvb_usb_dw2102_debug;
33709 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33710 index 404f63a..4796533 100644
33711 --- a/drivers/media/dvb/frontends/dib3000.h
33712 +++ b/drivers/media/dvb/frontends/dib3000.h
33713 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33714 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33715 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33716 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33717 -};
33718 +} __no_const;
33719
33720 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33721 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33722 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33723 index 7539a5d..06531a6 100644
33724 --- a/drivers/media/dvb/ngene/ngene-cards.c
33725 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33726 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33727
33728 /****************************************************************************/
33729
33730 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33731 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33732 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33733 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33734 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33735 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33736 index 16a089f..1661b11 100644
33737 --- a/drivers/media/radio/radio-cadet.c
33738 +++ b/drivers/media/radio/radio-cadet.c
33739 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33740 unsigned char readbuf[RDS_BUFFER];
33741 int i = 0;
33742
33743 + if (count > RDS_BUFFER)
33744 + return -EFAULT;
33745 mutex_lock(&dev->lock);
33746 if (dev->rdsstat == 0) {
33747 dev->rdsstat = 1;
33748 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33749 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33750 mutex_unlock(&dev->lock);
33751
33752 - if (copy_to_user(data, readbuf, i))
33753 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33754 return -EFAULT;
33755 return i;
33756 }
33757 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33758 index 9cde353..8c6a1c3 100644
33759 --- a/drivers/media/video/au0828/au0828.h
33760 +++ b/drivers/media/video/au0828/au0828.h
33761 @@ -191,7 +191,7 @@ struct au0828_dev {
33762
33763 /* I2C */
33764 struct i2c_adapter i2c_adap;
33765 - struct i2c_algorithm i2c_algo;
33766 + i2c_algorithm_no_const i2c_algo;
33767 struct i2c_client i2c_client;
33768 u32 i2c_rc;
33769
33770 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33771 index 04bf662..e0ac026 100644
33772 --- a/drivers/media/video/cx88/cx88-alsa.c
33773 +++ b/drivers/media/video/cx88/cx88-alsa.c
33774 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33775 * Only boards with eeprom and byte 1 at eeprom=1 have it
33776 */
33777
33778 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33779 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33780 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33781 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33782 {0, }
33783 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33784 index 88cf9d9..bbc4b2c 100644
33785 --- a/drivers/media/video/omap/omap_vout.c
33786 +++ b/drivers/media/video/omap/omap_vout.c
33787 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33788 OMAP_VIDEO2,
33789 };
33790
33791 -static struct videobuf_queue_ops video_vbq_ops;
33792 /* Variables configurable through module params*/
33793 static u32 video1_numbuffers = 3;
33794 static u32 video2_numbuffers = 3;
33795 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33796 {
33797 struct videobuf_queue *q;
33798 struct omap_vout_device *vout = NULL;
33799 + static struct videobuf_queue_ops video_vbq_ops = {
33800 + .buf_setup = omap_vout_buffer_setup,
33801 + .buf_prepare = omap_vout_buffer_prepare,
33802 + .buf_release = omap_vout_buffer_release,
33803 + .buf_queue = omap_vout_buffer_queue,
33804 + };
33805
33806 vout = video_drvdata(file);
33807 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33808 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33809 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33810
33811 q = &vout->vbq;
33812 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33813 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33814 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33815 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33816 spin_lock_init(&vout->vbq_lock);
33817
33818 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33819 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33820 index 036952f..80d356d 100644
33821 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33822 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33823 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33824
33825 /* I2C stuff */
33826 struct i2c_adapter i2c_adap;
33827 - struct i2c_algorithm i2c_algo;
33828 + i2c_algorithm_no_const i2c_algo;
33829 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33830 int i2c_cx25840_hack_state;
33831 int i2c_linked;
33832 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33833 index 02194c0..091733b 100644
33834 --- a/drivers/media/video/timblogiw.c
33835 +++ b/drivers/media/video/timblogiw.c
33836 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33837
33838 /* Platform device functions */
33839
33840 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33841 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33842 .vidioc_querycap = timblogiw_querycap,
33843 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33844 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33845 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33846 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33847 };
33848
33849 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33850 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33851 .owner = THIS_MODULE,
33852 .open = timblogiw_open,
33853 .release = timblogiw_close,
33854 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33855 index d99db56..a16b959 100644
33856 --- a/drivers/message/fusion/mptbase.c
33857 +++ b/drivers/message/fusion/mptbase.c
33858 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33859 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33860 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33861
33862 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33863 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33864 +#else
33865 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33866 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33867 +#endif
33868 +
33869 /*
33870 * Rounding UP to nearest 4-kB boundary here...
33871 */
33872 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33873 index 551262e..7551198 100644
33874 --- a/drivers/message/fusion/mptsas.c
33875 +++ b/drivers/message/fusion/mptsas.c
33876 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33877 return 0;
33878 }
33879
33880 +static inline void
33881 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33882 +{
33883 + if (phy_info->port_details) {
33884 + phy_info->port_details->rphy = rphy;
33885 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33886 + ioc->name, rphy));
33887 + }
33888 +
33889 + if (rphy) {
33890 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33891 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33892 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33893 + ioc->name, rphy, rphy->dev.release));
33894 + }
33895 +}
33896 +
33897 /* no mutex */
33898 static void
33899 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33900 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33901 return NULL;
33902 }
33903
33904 -static inline void
33905 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33906 -{
33907 - if (phy_info->port_details) {
33908 - phy_info->port_details->rphy = rphy;
33909 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33910 - ioc->name, rphy));
33911 - }
33912 -
33913 - if (rphy) {
33914 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33915 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33916 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33917 - ioc->name, rphy, rphy->dev.release));
33918 - }
33919 -}
33920 -
33921 static inline struct sas_port *
33922 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33923 {
33924 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33925 index 0c3ced7..1fe34ec 100644
33926 --- a/drivers/message/fusion/mptscsih.c
33927 +++ b/drivers/message/fusion/mptscsih.c
33928 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33929
33930 h = shost_priv(SChost);
33931
33932 - if (h) {
33933 - if (h->info_kbuf == NULL)
33934 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33935 - return h->info_kbuf;
33936 - h->info_kbuf[0] = '\0';
33937 + if (!h)
33938 + return NULL;
33939
33940 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33941 - h->info_kbuf[size-1] = '\0';
33942 - }
33943 + if (h->info_kbuf == NULL)
33944 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33945 + return h->info_kbuf;
33946 + h->info_kbuf[0] = '\0';
33947 +
33948 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33949 + h->info_kbuf[size-1] = '\0';
33950
33951 return h->info_kbuf;
33952 }
33953 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33954 index 506c36f..b137580 100644
33955 --- a/drivers/message/i2o/i2o_proc.c
33956 +++ b/drivers/message/i2o/i2o_proc.c
33957 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33958 "Array Controller Device"
33959 };
33960
33961 -static char *chtostr(u8 * chars, int n)
33962 -{
33963 - char tmp[256];
33964 - tmp[0] = 0;
33965 - return strncat(tmp, (char *)chars, n);
33966 -}
33967 -
33968 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33969 char *group)
33970 {
33971 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33972
33973 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33974 seq_printf(seq, "%-#8x", ddm_table.module_id);
33975 - seq_printf(seq, "%-29s",
33976 - chtostr(ddm_table.module_name_version, 28));
33977 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33978 seq_printf(seq, "%9d ", ddm_table.data_size);
33979 seq_printf(seq, "%8d", ddm_table.code_size);
33980
33981 @@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33982
33983 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33984 seq_printf(seq, "%-#8x", dst->module_id);
33985 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33986 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33987 + seq_printf(seq, "%-.28s", dst->module_name_version);
33988 + seq_printf(seq, "%-.8s", dst->date);
33989 seq_printf(seq, "%8d ", dst->module_size);
33990 seq_printf(seq, "%8d ", dst->mpb_size);
33991 seq_printf(seq, "0x%04x", dst->module_flags);
33992 @@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33993 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33994 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33995 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33996 - seq_printf(seq, "Vendor info : %s\n",
33997 - chtostr((u8 *) (work32 + 2), 16));
33998 - seq_printf(seq, "Product info : %s\n",
33999 - chtostr((u8 *) (work32 + 6), 16));
34000 - seq_printf(seq, "Description : %s\n",
34001 - chtostr((u8 *) (work32 + 10), 16));
34002 - seq_printf(seq, "Product rev. : %s\n",
34003 - chtostr((u8 *) (work32 + 14), 8));
34004 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34005 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34006 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34007 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34008
34009 seq_printf(seq, "Serial number : ");
34010 print_serial_number(seq, (u8 *) (work32 + 16),
34011 @@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34012 }
34013
34014 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34015 - seq_printf(seq, "Module name : %s\n",
34016 - chtostr(result.module_name, 24));
34017 - seq_printf(seq, "Module revision : %s\n",
34018 - chtostr(result.module_rev, 8));
34019 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34020 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34021
34022 seq_printf(seq, "Serial number : ");
34023 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34024 @@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34025 return 0;
34026 }
34027
34028 - seq_printf(seq, "Device name : %s\n",
34029 - chtostr(result.device_name, 64));
34030 - seq_printf(seq, "Service name : %s\n",
34031 - chtostr(result.service_name, 64));
34032 - seq_printf(seq, "Physical name : %s\n",
34033 - chtostr(result.physical_location, 64));
34034 - seq_printf(seq, "Instance number : %s\n",
34035 - chtostr(result.instance_number, 4));
34036 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34037 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34038 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34039 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34040
34041 return 0;
34042 }
34043 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34044 index a8c08f3..155fe3d 100644
34045 --- a/drivers/message/i2o/iop.c
34046 +++ b/drivers/message/i2o/iop.c
34047 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34048
34049 spin_lock_irqsave(&c->context_list_lock, flags);
34050
34051 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34052 - atomic_inc(&c->context_list_counter);
34053 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34054 + atomic_inc_unchecked(&c->context_list_counter);
34055
34056 - entry->context = atomic_read(&c->context_list_counter);
34057 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34058
34059 list_add(&entry->list, &c->context_list);
34060
34061 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34062
34063 #if BITS_PER_LONG == 64
34064 spin_lock_init(&c->context_list_lock);
34065 - atomic_set(&c->context_list_counter, 0);
34066 + atomic_set_unchecked(&c->context_list_counter, 0);
34067 INIT_LIST_HEAD(&c->context_list);
34068 #endif
34069
34070 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34071 index 7ce65f4..e66e9bc 100644
34072 --- a/drivers/mfd/abx500-core.c
34073 +++ b/drivers/mfd/abx500-core.c
34074 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34075
34076 struct abx500_device_entry {
34077 struct list_head list;
34078 - struct abx500_ops ops;
34079 + abx500_ops_no_const ops;
34080 struct device *dev;
34081 };
34082
34083 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34084 index 2ea9998..51dabee 100644
34085 --- a/drivers/mfd/janz-cmodio.c
34086 +++ b/drivers/mfd/janz-cmodio.c
34087 @@ -13,6 +13,7 @@
34088
34089 #include <linux/kernel.h>
34090 #include <linux/module.h>
34091 +#include <linux/slab.h>
34092 #include <linux/init.h>
34093 #include <linux/pci.h>
34094 #include <linux/interrupt.h>
34095 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34096 index a981e2a..5ca0c8b 100644
34097 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34098 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34099 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34100 * the lid is closed. This leads to interrupts as soon as a little move
34101 * is done.
34102 */
34103 - atomic_inc(&lis3->count);
34104 + atomic_inc_unchecked(&lis3->count);
34105
34106 wake_up_interruptible(&lis3->misc_wait);
34107 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34108 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34109 if (lis3->pm_dev)
34110 pm_runtime_get_sync(lis3->pm_dev);
34111
34112 - atomic_set(&lis3->count, 0);
34113 + atomic_set_unchecked(&lis3->count, 0);
34114 return 0;
34115 }
34116
34117 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34118 add_wait_queue(&lis3->misc_wait, &wait);
34119 while (true) {
34120 set_current_state(TASK_INTERRUPTIBLE);
34121 - data = atomic_xchg(&lis3->count, 0);
34122 + data = atomic_xchg_unchecked(&lis3->count, 0);
34123 if (data)
34124 break;
34125
34126 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34127 struct lis3lv02d, miscdev);
34128
34129 poll_wait(file, &lis3->misc_wait, wait);
34130 - if (atomic_read(&lis3->count))
34131 + if (atomic_read_unchecked(&lis3->count))
34132 return POLLIN | POLLRDNORM;
34133 return 0;
34134 }
34135 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34136 index 2b1482a..5d33616 100644
34137 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34138 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34139 @@ -266,7 +266,7 @@ struct lis3lv02d {
34140 struct input_polled_dev *idev; /* input device */
34141 struct platform_device *pdev; /* platform device */
34142 struct regulator_bulk_data regulators[2];
34143 - atomic_t count; /* interrupt count after last read */
34144 + atomic_unchecked_t count; /* interrupt count after last read */
34145 union axis_conversion ac; /* hw -> logical axis */
34146 int mapped_btns[3];
34147
34148 diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34149 index 28adefe..08aad69 100644
34150 --- a/drivers/misc/lkdtm.c
34151 +++ b/drivers/misc/lkdtm.c
34152 @@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34153 int i, n, out;
34154
34155 buf = (char *)__get_free_page(GFP_KERNEL);
34156 + if (buf == NULL)
34157 + return -ENOMEM;
34158
34159 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34160 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34161 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34162 index 2f30bad..c4c13d0 100644
34163 --- a/drivers/misc/sgi-gru/gruhandles.c
34164 +++ b/drivers/misc/sgi-gru/gruhandles.c
34165 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34166 unsigned long nsec;
34167
34168 nsec = CLKS2NSEC(clks);
34169 - atomic_long_inc(&mcs_op_statistics[op].count);
34170 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34171 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34172 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34173 if (mcs_op_statistics[op].max < nsec)
34174 mcs_op_statistics[op].max = nsec;
34175 }
34176 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34177 index 950dbe9..eeef0f8 100644
34178 --- a/drivers/misc/sgi-gru/gruprocfs.c
34179 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34180 @@ -32,9 +32,9 @@
34181
34182 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34183
34184 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34185 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34186 {
34187 - unsigned long val = atomic_long_read(v);
34188 + unsigned long val = atomic_long_read_unchecked(v);
34189
34190 seq_printf(s, "%16lu %s\n", val, id);
34191 }
34192 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34193
34194 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34195 for (op = 0; op < mcsop_last; op++) {
34196 - count = atomic_long_read(&mcs_op_statistics[op].count);
34197 - total = atomic_long_read(&mcs_op_statistics[op].total);
34198 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34199 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34200 max = mcs_op_statistics[op].max;
34201 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34202 count ? total / count : 0, max);
34203 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34204 index 5c3ce24..4915ccb 100644
34205 --- a/drivers/misc/sgi-gru/grutables.h
34206 +++ b/drivers/misc/sgi-gru/grutables.h
34207 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34208 * GRU statistics.
34209 */
34210 struct gru_stats_s {
34211 - atomic_long_t vdata_alloc;
34212 - atomic_long_t vdata_free;
34213 - atomic_long_t gts_alloc;
34214 - atomic_long_t gts_free;
34215 - atomic_long_t gms_alloc;
34216 - atomic_long_t gms_free;
34217 - atomic_long_t gts_double_allocate;
34218 - atomic_long_t assign_context;
34219 - atomic_long_t assign_context_failed;
34220 - atomic_long_t free_context;
34221 - atomic_long_t load_user_context;
34222 - atomic_long_t load_kernel_context;
34223 - atomic_long_t lock_kernel_context;
34224 - atomic_long_t unlock_kernel_context;
34225 - atomic_long_t steal_user_context;
34226 - atomic_long_t steal_kernel_context;
34227 - atomic_long_t steal_context_failed;
34228 - atomic_long_t nopfn;
34229 - atomic_long_t asid_new;
34230 - atomic_long_t asid_next;
34231 - atomic_long_t asid_wrap;
34232 - atomic_long_t asid_reuse;
34233 - atomic_long_t intr;
34234 - atomic_long_t intr_cbr;
34235 - atomic_long_t intr_tfh;
34236 - atomic_long_t intr_spurious;
34237 - atomic_long_t intr_mm_lock_failed;
34238 - atomic_long_t call_os;
34239 - atomic_long_t call_os_wait_queue;
34240 - atomic_long_t user_flush_tlb;
34241 - atomic_long_t user_unload_context;
34242 - atomic_long_t user_exception;
34243 - atomic_long_t set_context_option;
34244 - atomic_long_t check_context_retarget_intr;
34245 - atomic_long_t check_context_unload;
34246 - atomic_long_t tlb_dropin;
34247 - atomic_long_t tlb_preload_page;
34248 - atomic_long_t tlb_dropin_fail_no_asid;
34249 - atomic_long_t tlb_dropin_fail_upm;
34250 - atomic_long_t tlb_dropin_fail_invalid;
34251 - atomic_long_t tlb_dropin_fail_range_active;
34252 - atomic_long_t tlb_dropin_fail_idle;
34253 - atomic_long_t tlb_dropin_fail_fmm;
34254 - atomic_long_t tlb_dropin_fail_no_exception;
34255 - atomic_long_t tfh_stale_on_fault;
34256 - atomic_long_t mmu_invalidate_range;
34257 - atomic_long_t mmu_invalidate_page;
34258 - atomic_long_t flush_tlb;
34259 - atomic_long_t flush_tlb_gru;
34260 - atomic_long_t flush_tlb_gru_tgh;
34261 - atomic_long_t flush_tlb_gru_zero_asid;
34262 + atomic_long_unchecked_t vdata_alloc;
34263 + atomic_long_unchecked_t vdata_free;
34264 + atomic_long_unchecked_t gts_alloc;
34265 + atomic_long_unchecked_t gts_free;
34266 + atomic_long_unchecked_t gms_alloc;
34267 + atomic_long_unchecked_t gms_free;
34268 + atomic_long_unchecked_t gts_double_allocate;
34269 + atomic_long_unchecked_t assign_context;
34270 + atomic_long_unchecked_t assign_context_failed;
34271 + atomic_long_unchecked_t free_context;
34272 + atomic_long_unchecked_t load_user_context;
34273 + atomic_long_unchecked_t load_kernel_context;
34274 + atomic_long_unchecked_t lock_kernel_context;
34275 + atomic_long_unchecked_t unlock_kernel_context;
34276 + atomic_long_unchecked_t steal_user_context;
34277 + atomic_long_unchecked_t steal_kernel_context;
34278 + atomic_long_unchecked_t steal_context_failed;
34279 + atomic_long_unchecked_t nopfn;
34280 + atomic_long_unchecked_t asid_new;
34281 + atomic_long_unchecked_t asid_next;
34282 + atomic_long_unchecked_t asid_wrap;
34283 + atomic_long_unchecked_t asid_reuse;
34284 + atomic_long_unchecked_t intr;
34285 + atomic_long_unchecked_t intr_cbr;
34286 + atomic_long_unchecked_t intr_tfh;
34287 + atomic_long_unchecked_t intr_spurious;
34288 + atomic_long_unchecked_t intr_mm_lock_failed;
34289 + atomic_long_unchecked_t call_os;
34290 + atomic_long_unchecked_t call_os_wait_queue;
34291 + atomic_long_unchecked_t user_flush_tlb;
34292 + atomic_long_unchecked_t user_unload_context;
34293 + atomic_long_unchecked_t user_exception;
34294 + atomic_long_unchecked_t set_context_option;
34295 + atomic_long_unchecked_t check_context_retarget_intr;
34296 + atomic_long_unchecked_t check_context_unload;
34297 + atomic_long_unchecked_t tlb_dropin;
34298 + atomic_long_unchecked_t tlb_preload_page;
34299 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34300 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34301 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34302 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34303 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34304 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34305 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34306 + atomic_long_unchecked_t tfh_stale_on_fault;
34307 + atomic_long_unchecked_t mmu_invalidate_range;
34308 + atomic_long_unchecked_t mmu_invalidate_page;
34309 + atomic_long_unchecked_t flush_tlb;
34310 + atomic_long_unchecked_t flush_tlb_gru;
34311 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34312 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34313
34314 - atomic_long_t copy_gpa;
34315 - atomic_long_t read_gpa;
34316 + atomic_long_unchecked_t copy_gpa;
34317 + atomic_long_unchecked_t read_gpa;
34318
34319 - atomic_long_t mesq_receive;
34320 - atomic_long_t mesq_receive_none;
34321 - atomic_long_t mesq_send;
34322 - atomic_long_t mesq_send_failed;
34323 - atomic_long_t mesq_noop;
34324 - atomic_long_t mesq_send_unexpected_error;
34325 - atomic_long_t mesq_send_lb_overflow;
34326 - atomic_long_t mesq_send_qlimit_reached;
34327 - atomic_long_t mesq_send_amo_nacked;
34328 - atomic_long_t mesq_send_put_nacked;
34329 - atomic_long_t mesq_page_overflow;
34330 - atomic_long_t mesq_qf_locked;
34331 - atomic_long_t mesq_qf_noop_not_full;
34332 - atomic_long_t mesq_qf_switch_head_failed;
34333 - atomic_long_t mesq_qf_unexpected_error;
34334 - atomic_long_t mesq_noop_unexpected_error;
34335 - atomic_long_t mesq_noop_lb_overflow;
34336 - atomic_long_t mesq_noop_qlimit_reached;
34337 - atomic_long_t mesq_noop_amo_nacked;
34338 - atomic_long_t mesq_noop_put_nacked;
34339 - atomic_long_t mesq_noop_page_overflow;
34340 + atomic_long_unchecked_t mesq_receive;
34341 + atomic_long_unchecked_t mesq_receive_none;
34342 + atomic_long_unchecked_t mesq_send;
34343 + atomic_long_unchecked_t mesq_send_failed;
34344 + atomic_long_unchecked_t mesq_noop;
34345 + atomic_long_unchecked_t mesq_send_unexpected_error;
34346 + atomic_long_unchecked_t mesq_send_lb_overflow;
34347 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34348 + atomic_long_unchecked_t mesq_send_amo_nacked;
34349 + atomic_long_unchecked_t mesq_send_put_nacked;
34350 + atomic_long_unchecked_t mesq_page_overflow;
34351 + atomic_long_unchecked_t mesq_qf_locked;
34352 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34353 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34354 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34355 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34356 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34357 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34358 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34359 + atomic_long_unchecked_t mesq_noop_put_nacked;
34360 + atomic_long_unchecked_t mesq_noop_page_overflow;
34361
34362 };
34363
34364 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34365 tghop_invalidate, mcsop_last};
34366
34367 struct mcs_op_statistic {
34368 - atomic_long_t count;
34369 - atomic_long_t total;
34370 + atomic_long_unchecked_t count;
34371 + atomic_long_unchecked_t total;
34372 unsigned long max;
34373 };
34374
34375 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34376
34377 #define STAT(id) do { \
34378 if (gru_options & OPT_STATS) \
34379 - atomic_long_inc(&gru_stats.id); \
34380 + atomic_long_inc_unchecked(&gru_stats.id); \
34381 } while (0)
34382
34383 #ifdef CONFIG_SGI_GRU_DEBUG
34384 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34385 index c862cd4..0d176fe 100644
34386 --- a/drivers/misc/sgi-xp/xp.h
34387 +++ b/drivers/misc/sgi-xp/xp.h
34388 @@ -288,7 +288,7 @@ struct xpc_interface {
34389 xpc_notify_func, void *);
34390 void (*received) (short, int, void *);
34391 enum xp_retval (*partid_to_nasids) (short, void *);
34392 -};
34393 +} __no_const;
34394
34395 extern struct xpc_interface xpc_interface;
34396
34397 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34398 index b94d5f7..7f494c5 100644
34399 --- a/drivers/misc/sgi-xp/xpc.h
34400 +++ b/drivers/misc/sgi-xp/xpc.h
34401 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34402 void (*received_payload) (struct xpc_channel *, void *);
34403 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34404 };
34405 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34406
34407 /* struct xpc_partition act_state values (for XPC HB) */
34408
34409 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34410 /* found in xpc_main.c */
34411 extern struct device *xpc_part;
34412 extern struct device *xpc_chan;
34413 -extern struct xpc_arch_operations xpc_arch_ops;
34414 +extern xpc_arch_operations_no_const xpc_arch_ops;
34415 extern int xpc_disengage_timelimit;
34416 extern int xpc_disengage_timedout;
34417 extern int xpc_activate_IRQ_rcvd;
34418 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34419 index 8d082b4..aa749ae 100644
34420 --- a/drivers/misc/sgi-xp/xpc_main.c
34421 +++ b/drivers/misc/sgi-xp/xpc_main.c
34422 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34423 .notifier_call = xpc_system_die,
34424 };
34425
34426 -struct xpc_arch_operations xpc_arch_ops;
34427 +xpc_arch_operations_no_const xpc_arch_ops;
34428
34429 /*
34430 * Timer function to enforce the timelimit on the partition disengage.
34431 diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34432 index 2b62232..acfaeeb 100644
34433 --- a/drivers/misc/ti-st/st_core.c
34434 +++ b/drivers/misc/ti-st/st_core.c
34435 @@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34436 st_gdata->rx_skb = alloc_skb(
34437 st_gdata->list[type]->max_frame_size,
34438 GFP_ATOMIC);
34439 + if (st_gdata->rx_skb == NULL) {
34440 + pr_err("out of memory: dropping\n");
34441 + goto done;
34442 + }
34443 +
34444 skb_reserve(st_gdata->rx_skb,
34445 st_gdata->list[type]->reserve);
34446 /* next 2 required for BT only */
34447 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34448 index 69ef0be..f3ef91e 100644
34449 --- a/drivers/mmc/host/sdhci-pci.c
34450 +++ b/drivers/mmc/host/sdhci-pci.c
34451 @@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34452 .probe = via_probe,
34453 };
34454
34455 -static const struct pci_device_id pci_ids[] __devinitdata = {
34456 +static const struct pci_device_id pci_ids[] __devinitconst = {
34457 {
34458 .vendor = PCI_VENDOR_ID_RICOH,
34459 .device = PCI_DEVICE_ID_RICOH_R5C822,
34460 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34461 index a4eb8b5..8c0628f 100644
34462 --- a/drivers/mtd/devices/doc2000.c
34463 +++ b/drivers/mtd/devices/doc2000.c
34464 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34465
34466 /* The ECC will not be calculated correctly if less than 512 is written */
34467 /* DBB-
34468 - if (len != 0x200 && eccbuf)
34469 + if (len != 0x200)
34470 printk(KERN_WARNING
34471 "ECC needs a full sector write (adr: %lx size %lx)\n",
34472 (long) to, (long) len);
34473 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34474 index 0650aaf..7718762 100644
34475 --- a/drivers/mtd/nand/denali.c
34476 +++ b/drivers/mtd/nand/denali.c
34477 @@ -26,6 +26,7 @@
34478 #include <linux/pci.h>
34479 #include <linux/mtd/mtd.h>
34480 #include <linux/module.h>
34481 +#include <linux/slab.h>
34482
34483 #include "denali.h"
34484
34485 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34486 index 51b9d6a..52af9a7 100644
34487 --- a/drivers/mtd/nftlmount.c
34488 +++ b/drivers/mtd/nftlmount.c
34489 @@ -24,6 +24,7 @@
34490 #include <asm/errno.h>
34491 #include <linux/delay.h>
34492 #include <linux/slab.h>
34493 +#include <linux/sched.h>
34494 #include <linux/mtd/mtd.h>
34495 #include <linux/mtd/nand.h>
34496 #include <linux/mtd/nftl.h>
34497 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34498 index 6762dc4..9956862 100644
34499 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34500 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34501 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34502 */
34503
34504 #define ATL2_PARAM(X, desc) \
34505 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34506 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34507 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34508 MODULE_PARM_DESC(X, desc);
34509 #else
34510 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34511 index efd80bd..21fcff0 100644
34512 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34513 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34514 @@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34515
34516 int (*wait_comp)(struct bnx2x *bp,
34517 struct bnx2x_rx_mode_ramrod_params *p);
34518 -};
34519 +} __no_const;
34520
34521 /********************** Set multicast group ***********************************/
34522
34523 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34524 index 93865f8..5448741 100644
34525 --- a/drivers/net/ethernet/broadcom/tg3.h
34526 +++ b/drivers/net/ethernet/broadcom/tg3.h
34527 @@ -140,6 +140,7 @@
34528 #define CHIPREV_ID_5750_A0 0x4000
34529 #define CHIPREV_ID_5750_A1 0x4001
34530 #define CHIPREV_ID_5750_A3 0x4003
34531 +#define CHIPREV_ID_5750_C1 0x4201
34532 #define CHIPREV_ID_5750_C2 0x4202
34533 #define CHIPREV_ID_5752_A0_HW 0x5000
34534 #define CHIPREV_ID_5752_A0 0x6000
34535 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34536 index c4e8643..0979484 100644
34537 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34538 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34539 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34540 */
34541 struct l2t_skb_cb {
34542 arp_failure_handler_func arp_failure_handler;
34543 -};
34544 +} __no_const;
34545
34546 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34547
34548 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34549 index d3cd489..0fd52dd 100644
34550 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34551 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34552 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34553 for (i=0; i<ETH_ALEN; i++) {
34554 tmp.addr[i] = dev->dev_addr[i];
34555 }
34556 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34557 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34558 break;
34559
34560 case DE4X5_SET_HWADDR: /* Set the hardware address */
34561 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34562 spin_lock_irqsave(&lp->lock, flags);
34563 memcpy(&statbuf, &lp->pktStats, ioc->len);
34564 spin_unlock_irqrestore(&lp->lock, flags);
34565 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34566 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34567 return -EFAULT;
34568 break;
34569 }
34570 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34571 index ed7d1dc..d426748 100644
34572 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34573 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34574 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34575 {NULL}};
34576
34577
34578 -static const char *block_name[] __devinitdata = {
34579 +static const char *block_name[] __devinitconst = {
34580 "21140 non-MII",
34581 "21140 MII PHY",
34582 "21142 Serial PHY",
34583 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34584 index 75d45f8..3d9c55b 100644
34585 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34586 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34587 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34588 struct uli_phy_ops {
34589 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34590 u16 (*read)(struct uli526x_board_info *, u8, u8);
34591 - } phy;
34592 + } __no_const phy;
34593 struct net_device *next_dev; /* next device */
34594 struct pci_dev *pdev; /* PCI device */
34595 spinlock_t lock;
34596 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34597 index 4d1ffca..7c1ec4d 100644
34598 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34599 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34600 @@ -236,7 +236,7 @@ struct pci_id_info {
34601 int drv_flags; /* Driver use, intended as capability flags. */
34602 };
34603
34604 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34605 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34606 { /* Sometime a Level-One switch card. */
34607 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34608 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34609 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34610 index d7bb52a..3b83588 100644
34611 --- a/drivers/net/ethernet/dlink/sundance.c
34612 +++ b/drivers/net/ethernet/dlink/sundance.c
34613 @@ -218,7 +218,7 @@ enum {
34614 struct pci_id_info {
34615 const char *name;
34616 };
34617 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34618 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34619 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34620 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34621 {"D-Link DFE-580TX 4 port Server Adapter"},
34622 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34623 index 501dfa9..aa9ec11 100644
34624 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34625 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34626 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34627
34628 if (wrapped)
34629 newacc += 65536;
34630 - ACCESS_ONCE(*acc) = newacc;
34631 + ACCESS_ONCE_RW(*acc) = newacc;
34632 }
34633
34634 void be_parse_stats(struct be_adapter *adapter)
34635 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34636 index 16b0704..d2c07d7 100644
34637 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34638 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34639 @@ -31,6 +31,8 @@
34640 #include <linux/netdevice.h>
34641 #include <linux/phy.h>
34642 #include <linux/platform_device.h>
34643 +#include <linux/interrupt.h>
34644 +#include <linux/irqreturn.h>
34645 #include <net/ip.h>
34646
34647 #include "ftgmac100.h"
34648 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34649 index 829b109..4ae5f6a 100644
34650 --- a/drivers/net/ethernet/faraday/ftmac100.c
34651 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34652 @@ -31,6 +31,8 @@
34653 #include <linux/module.h>
34654 #include <linux/netdevice.h>
34655 #include <linux/platform_device.h>
34656 +#include <linux/interrupt.h>
34657 +#include <linux/irqreturn.h>
34658
34659 #include "ftmac100.h"
34660
34661 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34662 index 9d71c9c..0e4a0ac 100644
34663 --- a/drivers/net/ethernet/fealnx.c
34664 +++ b/drivers/net/ethernet/fealnx.c
34665 @@ -150,7 +150,7 @@ struct chip_info {
34666 int flags;
34667 };
34668
34669 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34670 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34671 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34672 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34673 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34674 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34675 index 6e6fffb..588f361 100644
34676 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34677 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34678 @@ -181,7 +181,7 @@ struct e1000_info;
34679 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34680 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34681 E1000_TXDCTL_COUNT_DESC | \
34682 - (5 << 16) | /* wthresh must be +1 more than desired */\
34683 + (1 << 16) | /* wthresh must be +1 more than desired */\
34684 (1 << 8) | /* hthresh */ \
34685 0x1f) /* pthresh */
34686
34687 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34688 index ed5b409..ec37828 100644
34689 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34690 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34691 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34692 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34693 s32 (*read_mac_addr)(struct e1000_hw *);
34694 };
34695 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34696
34697 /*
34698 * When to use various PHY register access functions:
34699 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34700 void (*power_up)(struct e1000_hw *);
34701 void (*power_down)(struct e1000_hw *);
34702 };
34703 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34704
34705 /* Function pointers for the NVM. */
34706 struct e1000_nvm_operations {
34707 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34708 s32 (*validate)(struct e1000_hw *);
34709 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34710 };
34711 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34712
34713 struct e1000_mac_info {
34714 - struct e1000_mac_operations ops;
34715 + e1000_mac_operations_no_const ops;
34716 u8 addr[ETH_ALEN];
34717 u8 perm_addr[ETH_ALEN];
34718
34719 @@ -892,7 +895,7 @@ struct e1000_mac_info {
34720 };
34721
34722 struct e1000_phy_info {
34723 - struct e1000_phy_operations ops;
34724 + e1000_phy_operations_no_const ops;
34725
34726 enum e1000_phy_type type;
34727
34728 @@ -926,7 +929,7 @@ struct e1000_phy_info {
34729 };
34730
34731 struct e1000_nvm_info {
34732 - struct e1000_nvm_operations ops;
34733 + e1000_nvm_operations_no_const ops;
34734
34735 enum e1000_nvm_type type;
34736 enum e1000_nvm_override override;
34737 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34738 index c2a51dc..c2bd262 100644
34739 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34740 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34741 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34742 void (*release_swfw_sync)(struct e1000_hw *, u16);
34743
34744 };
34745 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34746
34747 struct e1000_phy_operations {
34748 s32 (*acquire)(struct e1000_hw *);
34749 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34750 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34751 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34752 };
34753 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34754
34755 struct e1000_nvm_operations {
34756 s32 (*acquire)(struct e1000_hw *);
34757 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34758 s32 (*validate)(struct e1000_hw *);
34759 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34760 };
34761 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34762
34763 struct e1000_info {
34764 s32 (*get_invariants)(struct e1000_hw *);
34765 @@ -364,7 +367,7 @@ struct e1000_info {
34766 extern const struct e1000_info e1000_82575_info;
34767
34768 struct e1000_mac_info {
34769 - struct e1000_mac_operations ops;
34770 + e1000_mac_operations_no_const ops;
34771
34772 u8 addr[6];
34773 u8 perm_addr[6];
34774 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34775 };
34776
34777 struct e1000_phy_info {
34778 - struct e1000_phy_operations ops;
34779 + e1000_phy_operations_no_const ops;
34780
34781 enum e1000_phy_type type;
34782
34783 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34784 };
34785
34786 struct e1000_nvm_info {
34787 - struct e1000_nvm_operations ops;
34788 + e1000_nvm_operations_no_const ops;
34789 enum e1000_nvm_type type;
34790 enum e1000_nvm_override override;
34791
34792 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34793 s32 (*check_for_ack)(struct e1000_hw *, u16);
34794 s32 (*check_for_rst)(struct e1000_hw *, u16);
34795 };
34796 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34797
34798 struct e1000_mbx_stats {
34799 u32 msgs_tx;
34800 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34801 };
34802
34803 struct e1000_mbx_info {
34804 - struct e1000_mbx_operations ops;
34805 + e1000_mbx_operations_no_const ops;
34806 struct e1000_mbx_stats stats;
34807 u32 timeout;
34808 u32 usec_delay;
34809 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34810 index 57db3c6..aa825fc 100644
34811 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34812 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34813 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34814 s32 (*read_mac_addr)(struct e1000_hw *);
34815 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34816 };
34817 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34818
34819 struct e1000_mac_info {
34820 - struct e1000_mac_operations ops;
34821 + e1000_mac_operations_no_const ops;
34822 u8 addr[6];
34823 u8 perm_addr[6];
34824
34825 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34826 s32 (*check_for_ack)(struct e1000_hw *);
34827 s32 (*check_for_rst)(struct e1000_hw *);
34828 };
34829 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34830
34831 struct e1000_mbx_stats {
34832 u32 msgs_tx;
34833 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34834 };
34835
34836 struct e1000_mbx_info {
34837 - struct e1000_mbx_operations ops;
34838 + e1000_mbx_operations_no_const ops;
34839 struct e1000_mbx_stats stats;
34840 u32 timeout;
34841 u32 usec_delay;
34842 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34843 index dcebd12..c1fe8be 100644
34844 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34845 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34846 @@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34847 /* store the new cycle speed */
34848 adapter->cycle_speed = cycle_speed;
34849
34850 - ACCESS_ONCE(adapter->base_incval) = incval;
34851 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
34852 smp_mb();
34853
34854 /* grab the ptp lock */
34855 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34856 index 204848d..d8aeaec 100644
34857 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34858 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34859 @@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34860 s32 (*update_checksum)(struct ixgbe_hw *);
34861 u16 (*calc_checksum)(struct ixgbe_hw *);
34862 };
34863 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34864
34865 struct ixgbe_mac_operations {
34866 s32 (*init_hw)(struct ixgbe_hw *);
34867 @@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34868 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34869 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34870 };
34871 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34872
34873 struct ixgbe_phy_operations {
34874 s32 (*identify)(struct ixgbe_hw *);
34875 @@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34876 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34877 s32 (*check_overtemp)(struct ixgbe_hw *);
34878 };
34879 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34880
34881 struct ixgbe_eeprom_info {
34882 - struct ixgbe_eeprom_operations ops;
34883 + ixgbe_eeprom_operations_no_const ops;
34884 enum ixgbe_eeprom_type type;
34885 u32 semaphore_delay;
34886 u16 word_size;
34887 @@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34888
34889 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34890 struct ixgbe_mac_info {
34891 - struct ixgbe_mac_operations ops;
34892 + ixgbe_mac_operations_no_const ops;
34893 enum ixgbe_mac_type type;
34894 u8 addr[ETH_ALEN];
34895 u8 perm_addr[ETH_ALEN];
34896 @@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34897 };
34898
34899 struct ixgbe_phy_info {
34900 - struct ixgbe_phy_operations ops;
34901 + ixgbe_phy_operations_no_const ops;
34902 struct mdio_if_info mdio;
34903 enum ixgbe_phy_type type;
34904 u32 id;
34905 @@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34906 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34907 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34908 };
34909 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34910
34911 struct ixgbe_mbx_stats {
34912 u32 msgs_tx;
34913 @@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34914 };
34915
34916 struct ixgbe_mbx_info {
34917 - struct ixgbe_mbx_operations ops;
34918 + ixgbe_mbx_operations_no_const ops;
34919 struct ixgbe_mbx_stats stats;
34920 u32 timeout;
34921 u32 usec_delay;
34922 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34923 index 25c951d..cc7cf33 100644
34924 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34925 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34926 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34927 s32 (*clear_vfta)(struct ixgbe_hw *);
34928 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34929 };
34930 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34931
34932 enum ixgbe_mac_type {
34933 ixgbe_mac_unknown = 0,
34934 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34935 };
34936
34937 struct ixgbe_mac_info {
34938 - struct ixgbe_mac_operations ops;
34939 + ixgbe_mac_operations_no_const ops;
34940 u8 addr[6];
34941 u8 perm_addr[6];
34942
34943 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34944 s32 (*check_for_ack)(struct ixgbe_hw *);
34945 s32 (*check_for_rst)(struct ixgbe_hw *);
34946 };
34947 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34948
34949 struct ixgbe_mbx_stats {
34950 u32 msgs_tx;
34951 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34952 };
34953
34954 struct ixgbe_mbx_info {
34955 - struct ixgbe_mbx_operations ops;
34956 + ixgbe_mbx_operations_no_const ops;
34957 struct ixgbe_mbx_stats stats;
34958 u32 timeout;
34959 u32 udelay;
34960 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34961 index a0313de..e83a572 100644
34962 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34963 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34964 @@ -41,6 +41,7 @@
34965 #include <linux/slab.h>
34966 #include <linux/io-mapping.h>
34967 #include <linux/delay.h>
34968 +#include <linux/sched.h>
34969
34970 #include <linux/mlx4/device.h>
34971 #include <linux/mlx4/doorbell.h>
34972 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34973 index 5046a64..71ca936 100644
34974 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34975 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34976 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34977 void (*link_down)(struct __vxge_hw_device *devh);
34978 void (*crit_err)(struct __vxge_hw_device *devh,
34979 enum vxge_hw_event type, u64 ext_data);
34980 -};
34981 +} __no_const;
34982
34983 /*
34984 * struct __vxge_hw_blockpool_entry - Block private data structure
34985 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34986 index 4a518a3..936b334 100644
34987 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34988 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34989 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34990 struct vxge_hw_mempool_dma *dma_object,
34991 u32 index,
34992 u32 is_last);
34993 -};
34994 +} __no_const;
34995
34996 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34997 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34998 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34999 index d7a04e0..76d0431 100644
35000 --- a/drivers/net/ethernet/realtek/r8169.c
35001 +++ b/drivers/net/ethernet/realtek/r8169.c
35002 @@ -723,22 +723,22 @@ struct rtl8169_private {
35003 struct mdio_ops {
35004 void (*write)(void __iomem *, int, int);
35005 int (*read)(void __iomem *, int);
35006 - } mdio_ops;
35007 + } __no_const mdio_ops;
35008
35009 struct pll_power_ops {
35010 void (*down)(struct rtl8169_private *);
35011 void (*up)(struct rtl8169_private *);
35012 - } pll_power_ops;
35013 + } __no_const pll_power_ops;
35014
35015 struct jumbo_ops {
35016 void (*enable)(struct rtl8169_private *);
35017 void (*disable)(struct rtl8169_private *);
35018 - } jumbo_ops;
35019 + } __no_const jumbo_ops;
35020
35021 struct csi_ops {
35022 void (*write)(void __iomem *, int, int);
35023 u32 (*read)(void __iomem *, int);
35024 - } csi_ops;
35025 + } __no_const csi_ops;
35026
35027 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35028 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35029 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35030 index 4613591..d816601 100644
35031 --- a/drivers/net/ethernet/sis/sis190.c
35032 +++ b/drivers/net/ethernet/sis/sis190.c
35033 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35034 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35035 struct net_device *dev)
35036 {
35037 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35038 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35039 struct sis190_private *tp = netdev_priv(dev);
35040 struct pci_dev *isa_bridge;
35041 u8 reg, tmp8;
35042 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35043 index c07cfe9..81cbf7e 100644
35044 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35045 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35046 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35047
35048 writel(value, ioaddr + MMC_CNTRL);
35049
35050 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35051 - MMC_CNTRL, value);
35052 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35053 +// MMC_CNTRL, value);
35054 }
35055
35056 /* To mask all all interrupts.*/
35057 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35058 index 2857ab0..9a1f9b0 100644
35059 --- a/drivers/net/hyperv/hyperv_net.h
35060 +++ b/drivers/net/hyperv/hyperv_net.h
35061 @@ -99,7 +99,7 @@ struct rndis_device {
35062
35063 enum rndis_device_state state;
35064 bool link_state;
35065 - atomic_t new_req_id;
35066 + atomic_unchecked_t new_req_id;
35067
35068 spinlock_t request_lock;
35069 struct list_head req_list;
35070 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35071 index 981ebb1..b34959b 100644
35072 --- a/drivers/net/hyperv/rndis_filter.c
35073 +++ b/drivers/net/hyperv/rndis_filter.c
35074 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35075 * template
35076 */
35077 set = &rndis_msg->msg.set_req;
35078 - set->req_id = atomic_inc_return(&dev->new_req_id);
35079 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35080
35081 /* Add to the request list */
35082 spin_lock_irqsave(&dev->request_lock, flags);
35083 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35084
35085 /* Setup the rndis set */
35086 halt = &request->request_msg.msg.halt_req;
35087 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35088 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35089
35090 /* Ignore return since this msg is optional. */
35091 rndis_filter_send_request(dev, request);
35092 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35093 index 5c05572..389610b 100644
35094 --- a/drivers/net/ppp/ppp_generic.c
35095 +++ b/drivers/net/ppp/ppp_generic.c
35096 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35097 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35098 struct ppp_stats stats;
35099 struct ppp_comp_stats cstats;
35100 - char *vers;
35101
35102 switch (cmd) {
35103 case SIOCGPPPSTATS:
35104 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35105 break;
35106
35107 case SIOCGPPPVER:
35108 - vers = PPP_VERSION;
35109 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35110 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35111 break;
35112 err = 0;
35113 break;
35114 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35115 index 62f30b4..ff99dfd 100644
35116 --- a/drivers/net/usb/hso.c
35117 +++ b/drivers/net/usb/hso.c
35118 @@ -71,7 +71,7 @@
35119 #include <asm/byteorder.h>
35120 #include <linux/serial_core.h>
35121 #include <linux/serial.h>
35122 -
35123 +#include <asm/local.h>
35124
35125 #define MOD_AUTHOR "Option Wireless"
35126 #define MOD_DESCRIPTION "USB High Speed Option driver"
35127 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35128 struct urb *urb;
35129
35130 urb = serial->rx_urb[0];
35131 - if (serial->port.count > 0) {
35132 + if (atomic_read(&serial->port.count) > 0) {
35133 count = put_rxbuf_data(urb, serial);
35134 if (count == -1)
35135 return;
35136 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35137 DUMP1(urb->transfer_buffer, urb->actual_length);
35138
35139 /* Anyone listening? */
35140 - if (serial->port.count == 0)
35141 + if (atomic_read(&serial->port.count) == 0)
35142 return;
35143
35144 if (status == 0) {
35145 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35146 tty_port_tty_set(&serial->port, tty);
35147
35148 /* check for port already opened, if not set the termios */
35149 - serial->port.count++;
35150 - if (serial->port.count == 1) {
35151 + if (atomic_inc_return(&serial->port.count) == 1) {
35152 serial->rx_state = RX_IDLE;
35153 /* Force default termio settings */
35154 _hso_serial_set_termios(tty, NULL);
35155 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35156 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35157 if (result) {
35158 hso_stop_serial_device(serial->parent);
35159 - serial->port.count--;
35160 + atomic_dec(&serial->port.count);
35161 kref_put(&serial->parent->ref, hso_serial_ref_free);
35162 }
35163 } else {
35164 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35165
35166 /* reset the rts and dtr */
35167 /* do the actual close */
35168 - serial->port.count--;
35169 + atomic_dec(&serial->port.count);
35170
35171 - if (serial->port.count <= 0) {
35172 - serial->port.count = 0;
35173 + if (atomic_read(&serial->port.count) <= 0) {
35174 + atomic_set(&serial->port.count, 0);
35175 tty_port_tty_set(&serial->port, NULL);
35176 if (!usb_gone)
35177 hso_stop_serial_device(serial->parent);
35178 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35179
35180 /* the actual setup */
35181 spin_lock_irqsave(&serial->serial_lock, flags);
35182 - if (serial->port.count)
35183 + if (atomic_read(&serial->port.count))
35184 _hso_serial_set_termios(tty, old);
35185 else
35186 tty->termios = old;
35187 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35188 D1("Pending read interrupt on port %d\n", i);
35189 spin_lock(&serial->serial_lock);
35190 if (serial->rx_state == RX_IDLE &&
35191 - serial->port.count > 0) {
35192 + atomic_read(&serial->port.count) > 0) {
35193 /* Setup and send a ctrl req read on
35194 * port i */
35195 if (!serial->rx_urb_filled[0]) {
35196 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35197 /* Start all serial ports */
35198 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35199 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35200 - if (dev2ser(serial_table[i])->port.count) {
35201 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35202 result =
35203 hso_start_serial_device(serial_table[i], GFP_NOIO);
35204 hso_kick_transmit(dev2ser(serial_table[i]));
35205 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35206 index 420d69b..74f90a2 100644
35207 --- a/drivers/net/wireless/ath/ath.h
35208 +++ b/drivers/net/wireless/ath/ath.h
35209 @@ -119,6 +119,7 @@ struct ath_ops {
35210 void (*write_flush) (void *);
35211 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35212 };
35213 +typedef struct ath_ops __no_const ath_ops_no_const;
35214
35215 struct ath_common;
35216 struct ath_bus_ops;
35217 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35218 index 8d78253..bebbb68 100644
35219 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35220 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35221 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35222 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35223 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35224
35225 - ACCESS_ONCE(ads->ds_link) = i->link;
35226 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35227 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35228 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35229
35230 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35231 ctl6 = SM(i->keytype, AR_EncrType);
35232 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35233
35234 if ((i->is_first || i->is_last) &&
35235 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35236 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35237 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35238 | set11nTries(i->rates, 1)
35239 | set11nTries(i->rates, 2)
35240 | set11nTries(i->rates, 3)
35241 | (i->dur_update ? AR_DurUpdateEna : 0)
35242 | SM(0, AR_BurstDur);
35243
35244 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35245 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35246 | set11nRate(i->rates, 1)
35247 | set11nRate(i->rates, 2)
35248 | set11nRate(i->rates, 3);
35249 } else {
35250 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35251 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35252 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35253 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35254 }
35255
35256 if (!i->is_first) {
35257 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35258 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35259 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35260 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35261 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35262 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35263 return;
35264 }
35265
35266 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35267 break;
35268 }
35269
35270 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35271 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35272 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35273 | SM(i->txpower, AR_XmitPower)
35274 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35275 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35276 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35277 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35278
35279 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35280 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35281 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35282 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35283
35284 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35285 return;
35286
35287 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35288 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35289 | set11nPktDurRTSCTS(i->rates, 1);
35290
35291 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35292 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35293 | set11nPktDurRTSCTS(i->rates, 3);
35294
35295 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35296 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35297 | set11nRateFlags(i->rates, 1)
35298 | set11nRateFlags(i->rates, 2)
35299 | set11nRateFlags(i->rates, 3)
35300 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35301 index d9e0824..1a874e7 100644
35302 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35303 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35304 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35305 (i->qcu << AR_TxQcuNum_S) | desc_len;
35306
35307 checksum += val;
35308 - ACCESS_ONCE(ads->info) = val;
35309 + ACCESS_ONCE_RW(ads->info) = val;
35310
35311 checksum += i->link;
35312 - ACCESS_ONCE(ads->link) = i->link;
35313 + ACCESS_ONCE_RW(ads->link) = i->link;
35314
35315 checksum += i->buf_addr[0];
35316 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35317 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35318 checksum += i->buf_addr[1];
35319 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35320 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35321 checksum += i->buf_addr[2];
35322 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35323 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35324 checksum += i->buf_addr[3];
35325 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35326 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35327
35328 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35329 - ACCESS_ONCE(ads->ctl3) = val;
35330 + ACCESS_ONCE_RW(ads->ctl3) = val;
35331 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35332 - ACCESS_ONCE(ads->ctl5) = val;
35333 + ACCESS_ONCE_RW(ads->ctl5) = val;
35334 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35335 - ACCESS_ONCE(ads->ctl7) = val;
35336 + ACCESS_ONCE_RW(ads->ctl7) = val;
35337 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35338 - ACCESS_ONCE(ads->ctl9) = val;
35339 + ACCESS_ONCE_RW(ads->ctl9) = val;
35340
35341 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35342 - ACCESS_ONCE(ads->ctl10) = checksum;
35343 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35344
35345 if (i->is_first || i->is_last) {
35346 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35347 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35348 | set11nTries(i->rates, 1)
35349 | set11nTries(i->rates, 2)
35350 | set11nTries(i->rates, 3)
35351 | (i->dur_update ? AR_DurUpdateEna : 0)
35352 | SM(0, AR_BurstDur);
35353
35354 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35355 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35356 | set11nRate(i->rates, 1)
35357 | set11nRate(i->rates, 2)
35358 | set11nRate(i->rates, 3);
35359 } else {
35360 - ACCESS_ONCE(ads->ctl13) = 0;
35361 - ACCESS_ONCE(ads->ctl14) = 0;
35362 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35363 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35364 }
35365
35366 ads->ctl20 = 0;
35367 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35368
35369 ctl17 = SM(i->keytype, AR_EncrType);
35370 if (!i->is_first) {
35371 - ACCESS_ONCE(ads->ctl11) = 0;
35372 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35373 - ACCESS_ONCE(ads->ctl15) = 0;
35374 - ACCESS_ONCE(ads->ctl16) = 0;
35375 - ACCESS_ONCE(ads->ctl17) = ctl17;
35376 - ACCESS_ONCE(ads->ctl18) = 0;
35377 - ACCESS_ONCE(ads->ctl19) = 0;
35378 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35379 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35380 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35381 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35382 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35383 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35384 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35385 return;
35386 }
35387
35388 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35389 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35390 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35391 | SM(i->txpower, AR_XmitPower)
35392 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35393 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35394 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35395 ctl12 |= SM(val, AR_PAPRDChainMask);
35396
35397 - ACCESS_ONCE(ads->ctl12) = ctl12;
35398 - ACCESS_ONCE(ads->ctl17) = ctl17;
35399 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35400 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35401
35402 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35403 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35404 | set11nPktDurRTSCTS(i->rates, 1);
35405
35406 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35407 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35408 | set11nPktDurRTSCTS(i->rates, 3);
35409
35410 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35411 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35412 | set11nRateFlags(i->rates, 1)
35413 | set11nRateFlags(i->rates, 2)
35414 | set11nRateFlags(i->rates, 3)
35415 | SM(i->rtscts_rate, AR_RTSCTSRate);
35416
35417 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35418 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35419 }
35420
35421 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35422 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35423 index b620c55..a76cd49 100644
35424 --- a/drivers/net/wireless/ath/ath9k/hw.h
35425 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35426 @@ -609,7 +609,7 @@ struct ath_hw_private_ops {
35427
35428 /* ANI */
35429 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35430 -};
35431 +} __no_const;
35432
35433 /**
35434 * struct ath_hw_ops - callbacks used by hardware code and driver code
35435 @@ -639,7 +639,7 @@ struct ath_hw_ops {
35436 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35437 struct ath_hw_antcomb_conf *antconf);
35438
35439 -};
35440 +} __no_const;
35441
35442 struct ath_nf_limits {
35443 s16 max;
35444 @@ -659,7 +659,7 @@ enum ath_cal_list {
35445 #define AH_FASTCC 0x4
35446
35447 struct ath_hw {
35448 - struct ath_ops reg_ops;
35449 + ath_ops_no_const reg_ops;
35450
35451 struct ieee80211_hw *hw;
35452 struct ath_common common;
35453 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35454 index af00e2c..ab04d34 100644
35455 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35456 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35457 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35458 void (*carrsuppr)(struct brcms_phy *);
35459 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35460 void (*detach)(struct brcms_phy *);
35461 -};
35462 +} __no_const;
35463
35464 struct brcms_phy {
35465 struct brcms_phy_pub pubpi_ro;
35466 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35467 index faec404..a5277f1 100644
35468 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35469 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35470 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35471 */
35472 if (il3945_mod_params.disable_hw_scan) {
35473 D_INFO("Disabling hw_scan\n");
35474 - il3945_mac_ops.hw_scan = NULL;
35475 + pax_open_kernel();
35476 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35477 + pax_close_kernel();
35478 }
35479
35480 D_INFO("*** LOAD DRIVER ***\n");
35481 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35482 index a0b7cfd..20b49f7 100644
35483 --- a/drivers/net/wireless/mac80211_hwsim.c
35484 +++ b/drivers/net/wireless/mac80211_hwsim.c
35485 @@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35486 return -EINVAL;
35487
35488 if (fake_hw_scan) {
35489 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35490 - mac80211_hwsim_ops.sw_scan_start = NULL;
35491 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35492 + pax_open_kernel();
35493 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35494 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35495 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35496 + pax_close_kernel();
35497 }
35498
35499 spin_lock_init(&hwsim_radio_lock);
35500 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35501 index bd3b0bf..f9db92a 100644
35502 --- a/drivers/net/wireless/mwifiex/main.h
35503 +++ b/drivers/net/wireless/mwifiex/main.h
35504 @@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35505 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35506 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35507 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35508 -};
35509 +} __no_const;
35510
35511 struct mwifiex_adapter {
35512 u8 iface_type;
35513 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35514 index dfcd02a..a42a59d 100644
35515 --- a/drivers/net/wireless/rndis_wlan.c
35516 +++ b/drivers/net/wireless/rndis_wlan.c
35517 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35518
35519 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35520
35521 - if (rts_threshold < 0 || rts_threshold > 2347)
35522 + if (rts_threshold > 2347)
35523 rts_threshold = 2347;
35524
35525 tmp = cpu_to_le32(rts_threshold);
35526 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35527 index 8f75402..eed109d 100644
35528 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35529 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35530 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35531 * for hardware which doesn't support hardware
35532 * sequence counting.
35533 */
35534 - atomic_t seqno;
35535 + atomic_unchecked_t seqno;
35536 };
35537
35538 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35539 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35540 index 2fd8301..9767e8c 100644
35541 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35542 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35543 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35544 * sequence counter given by mac80211.
35545 */
35546 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35547 - seqno = atomic_add_return(0x10, &intf->seqno);
35548 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35549 else
35550 - seqno = atomic_read(&intf->seqno);
35551 + seqno = atomic_read_unchecked(&intf->seqno);
35552
35553 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35554 hdr->seq_ctrl |= cpu_to_le16(seqno);
35555 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35556 index 9d8f581..0f6589e 100644
35557 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35558 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35559 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35560 void (*reset)(struct wl1251 *wl);
35561 void (*enable_irq)(struct wl1251 *wl);
35562 void (*disable_irq)(struct wl1251 *wl);
35563 -};
35564 +} __no_const;
35565
35566 struct wl1251 {
35567 struct ieee80211_hw *hw;
35568 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35569 index 0b3f0b5..62f68bd 100644
35570 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35571 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35572 @@ -61,7 +61,7 @@ struct wlcore_ops {
35573 struct wl12xx_vif *wlvif);
35574 s8 (*get_pg_ver)(struct wl1271 *wl);
35575 void (*get_mac)(struct wl1271 *wl);
35576 -};
35577 +} __no_const;
35578
35579 enum wlcore_partitions {
35580 PART_DOWN,
35581 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35582 index f34b5b2..b5abb9f 100644
35583 --- a/drivers/oprofile/buffer_sync.c
35584 +++ b/drivers/oprofile/buffer_sync.c
35585 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35586 if (cookie == NO_COOKIE)
35587 offset = pc;
35588 if (cookie == INVALID_COOKIE) {
35589 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35590 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35591 offset = pc;
35592 }
35593 if (cookie != last_cookie) {
35594 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35595 /* add userspace sample */
35596
35597 if (!mm) {
35598 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35599 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35600 return 0;
35601 }
35602
35603 cookie = lookup_dcookie(mm, s->eip, &offset);
35604
35605 if (cookie == INVALID_COOKIE) {
35606 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35607 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35608 return 0;
35609 }
35610
35611 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35612 /* ignore backtraces if failed to add a sample */
35613 if (state == sb_bt_start) {
35614 state = sb_bt_ignore;
35615 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35616 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35617 }
35618 }
35619 release_mm(mm);
35620 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35621 index c0cc4e7..44d4e54 100644
35622 --- a/drivers/oprofile/event_buffer.c
35623 +++ b/drivers/oprofile/event_buffer.c
35624 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35625 }
35626
35627 if (buffer_pos == buffer_size) {
35628 - atomic_inc(&oprofile_stats.event_lost_overflow);
35629 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35630 return;
35631 }
35632
35633 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35634 index ed2c3ec..deda85a 100644
35635 --- a/drivers/oprofile/oprof.c
35636 +++ b/drivers/oprofile/oprof.c
35637 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35638 if (oprofile_ops.switch_events())
35639 return;
35640
35641 - atomic_inc(&oprofile_stats.multiplex_counter);
35642 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35643 start_switch_worker();
35644 }
35645
35646 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35647 index 917d28e..d62d981 100644
35648 --- a/drivers/oprofile/oprofile_stats.c
35649 +++ b/drivers/oprofile/oprofile_stats.c
35650 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35651 cpu_buf->sample_invalid_eip = 0;
35652 }
35653
35654 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35655 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35656 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35657 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35658 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35659 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35660 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35661 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35662 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35663 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35664 }
35665
35666
35667 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35668 index 38b6fc0..b5cbfce 100644
35669 --- a/drivers/oprofile/oprofile_stats.h
35670 +++ b/drivers/oprofile/oprofile_stats.h
35671 @@ -13,11 +13,11 @@
35672 #include <linux/atomic.h>
35673
35674 struct oprofile_stat_struct {
35675 - atomic_t sample_lost_no_mm;
35676 - atomic_t sample_lost_no_mapping;
35677 - atomic_t bt_lost_no_mapping;
35678 - atomic_t event_lost_overflow;
35679 - atomic_t multiplex_counter;
35680 + atomic_unchecked_t sample_lost_no_mm;
35681 + atomic_unchecked_t sample_lost_no_mapping;
35682 + atomic_unchecked_t bt_lost_no_mapping;
35683 + atomic_unchecked_t event_lost_overflow;
35684 + atomic_unchecked_t multiplex_counter;
35685 };
35686
35687 extern struct oprofile_stat_struct oprofile_stats;
35688 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35689 index 849357c..b83c1e0 100644
35690 --- a/drivers/oprofile/oprofilefs.c
35691 +++ b/drivers/oprofile/oprofilefs.c
35692 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35693
35694
35695 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35696 - char const *name, atomic_t *val)
35697 + char const *name, atomic_unchecked_t *val)
35698 {
35699 return __oprofilefs_create_file(sb, root, name,
35700 &atomic_ro_fops, 0444, val);
35701 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35702 index 3f56bc0..707d642 100644
35703 --- a/drivers/parport/procfs.c
35704 +++ b/drivers/parport/procfs.c
35705 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35706
35707 *ppos += len;
35708
35709 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35710 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35711 }
35712
35713 #ifdef CONFIG_PARPORT_1284
35714 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35715
35716 *ppos += len;
35717
35718 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35719 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35720 }
35721 #endif /* IEEE1284.3 support. */
35722
35723 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35724 index 9fff878..ad0ad53 100644
35725 --- a/drivers/pci/hotplug/cpci_hotplug.h
35726 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35727 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35728 int (*hardware_test) (struct slot* slot, u32 value);
35729 u8 (*get_power) (struct slot* slot);
35730 int (*set_power) (struct slot* slot, int value);
35731 -};
35732 +} __no_const;
35733
35734 struct cpci_hp_controller {
35735 unsigned int irq;
35736 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35737 index 76ba8a1..20ca857 100644
35738 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35739 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35740 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35741
35742 void compaq_nvram_init (void __iomem *rom_start)
35743 {
35744 +
35745 +#ifndef CONFIG_PAX_KERNEXEC
35746 if (rom_start) {
35747 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35748 }
35749 +#endif
35750 +
35751 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35752
35753 /* initialize our int15 lock */
35754 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35755 index b500840..d7159d3 100644
35756 --- a/drivers/pci/pcie/aspm.c
35757 +++ b/drivers/pci/pcie/aspm.c
35758 @@ -27,9 +27,9 @@
35759 #define MODULE_PARAM_PREFIX "pcie_aspm."
35760
35761 /* Note: those are not register definitions */
35762 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35763 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35764 -#define ASPM_STATE_L1 (4) /* L1 state */
35765 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35766 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35767 +#define ASPM_STATE_L1 (4U) /* L1 state */
35768 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35769 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35770
35771 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35772 index 658ac97..05e1b90 100644
35773 --- a/drivers/pci/probe.c
35774 +++ b/drivers/pci/probe.c
35775 @@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35776 u16 orig_cmd;
35777 struct pci_bus_region region;
35778
35779 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35780 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35781
35782 if (!dev->mmio_always_on) {
35783 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35784 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35785 index 27911b5..5b6db88 100644
35786 --- a/drivers/pci/proc.c
35787 +++ b/drivers/pci/proc.c
35788 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35789 static int __init pci_proc_init(void)
35790 {
35791 struct pci_dev *dev = NULL;
35792 +
35793 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35794 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35795 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35796 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35797 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35798 +#endif
35799 +#else
35800 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35801 +#endif
35802 proc_create("devices", 0, proc_bus_pci_dir,
35803 &proc_bus_pci_dev_operations);
35804 proc_initialized = 1;
35805 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35806 index 8b5610d..a4c22bb 100644
35807 --- a/drivers/platform/x86/thinkpad_acpi.c
35808 +++ b/drivers/platform/x86/thinkpad_acpi.c
35809 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35810 return 0;
35811 }
35812
35813 -void static hotkey_mask_warn_incomplete_mask(void)
35814 +static void hotkey_mask_warn_incomplete_mask(void)
35815 {
35816 /* log only what the user can fix... */
35817 const u32 wantedmask = hotkey_driver_mask &
35818 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35819 }
35820 }
35821
35822 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35823 - struct tp_nvram_state *newn,
35824 - const u32 event_mask)
35825 -{
35826 -
35827 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35828 do { \
35829 if ((event_mask & (1 << __scancode)) && \
35830 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35831 tpacpi_hotkey_send_key(__scancode); \
35832 } while (0)
35833
35834 - void issue_volchange(const unsigned int oldvol,
35835 - const unsigned int newvol)
35836 - {
35837 - unsigned int i = oldvol;
35838 +static void issue_volchange(const unsigned int oldvol,
35839 + const unsigned int newvol,
35840 + const u32 event_mask)
35841 +{
35842 + unsigned int i = oldvol;
35843
35844 - while (i > newvol) {
35845 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35846 - i--;
35847 - }
35848 - while (i < newvol) {
35849 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35850 - i++;
35851 - }
35852 + while (i > newvol) {
35853 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35854 + i--;
35855 }
35856 + while (i < newvol) {
35857 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35858 + i++;
35859 + }
35860 +}
35861
35862 - void issue_brightnesschange(const unsigned int oldbrt,
35863 - const unsigned int newbrt)
35864 - {
35865 - unsigned int i = oldbrt;
35866 +static void issue_brightnesschange(const unsigned int oldbrt,
35867 + const unsigned int newbrt,
35868 + const u32 event_mask)
35869 +{
35870 + unsigned int i = oldbrt;
35871
35872 - while (i > newbrt) {
35873 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35874 - i--;
35875 - }
35876 - while (i < newbrt) {
35877 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35878 - i++;
35879 - }
35880 + while (i > newbrt) {
35881 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35882 + i--;
35883 + }
35884 + while (i < newbrt) {
35885 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35886 + i++;
35887 }
35888 +}
35889
35890 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35891 + struct tp_nvram_state *newn,
35892 + const u32 event_mask)
35893 +{
35894 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35895 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35896 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35897 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35898 oldn->volume_level != newn->volume_level) {
35899 /* recently muted, or repeated mute keypress, or
35900 * multiple presses ending in mute */
35901 - issue_volchange(oldn->volume_level, newn->volume_level);
35902 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35903 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35904 }
35905 } else {
35906 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35907 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35908 }
35909 if (oldn->volume_level != newn->volume_level) {
35910 - issue_volchange(oldn->volume_level, newn->volume_level);
35911 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35912 } else if (oldn->volume_toggle != newn->volume_toggle) {
35913 /* repeated vol up/down keypress at end of scale ? */
35914 if (newn->volume_level == 0)
35915 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35916 /* handle brightness */
35917 if (oldn->brightness_level != newn->brightness_level) {
35918 issue_brightnesschange(oldn->brightness_level,
35919 - newn->brightness_level);
35920 + newn->brightness_level,
35921 + event_mask);
35922 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35923 /* repeated key presses that didn't change state */
35924 if (newn->brightness_level == 0)
35925 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35926 && !tp_features.bright_unkfw)
35927 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35928 }
35929 +}
35930
35931 #undef TPACPI_COMPARE_KEY
35932 #undef TPACPI_MAY_SEND_KEY
35933 -}
35934
35935 /*
35936 * Polling driver
35937 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35938 index 769d265..a3a05ca 100644
35939 --- a/drivers/pnp/pnpbios/bioscalls.c
35940 +++ b/drivers/pnp/pnpbios/bioscalls.c
35941 @@ -58,7 +58,7 @@ do { \
35942 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35943 } while(0)
35944
35945 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35946 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35947 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35948
35949 /*
35950 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35951
35952 cpu = get_cpu();
35953 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35954 +
35955 + pax_open_kernel();
35956 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35957 + pax_close_kernel();
35958
35959 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35960 spin_lock_irqsave(&pnp_bios_lock, flags);
35961 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35962 :"memory");
35963 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35964
35965 + pax_open_kernel();
35966 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35967 + pax_close_kernel();
35968 +
35969 put_cpu();
35970
35971 /* If we get here and this is set then the PnP BIOS faulted on us. */
35972 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35973 return status;
35974 }
35975
35976 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
35977 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35978 {
35979 int i;
35980
35981 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35982 pnp_bios_callpoint.offset = header->fields.pm16offset;
35983 pnp_bios_callpoint.segment = PNP_CS16;
35984
35985 + pax_open_kernel();
35986 +
35987 for_each_possible_cpu(i) {
35988 struct desc_struct *gdt = get_cpu_gdt_table(i);
35989 if (!gdt)
35990 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35991 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35992 (unsigned long)__va(header->fields.pm16dseg));
35993 }
35994 +
35995 + pax_close_kernel();
35996 }
35997 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35998 index b0ecacb..7c9da2e 100644
35999 --- a/drivers/pnp/resource.c
36000 +++ b/drivers/pnp/resource.c
36001 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36002 return 1;
36003
36004 /* check if the resource is valid */
36005 - if (*irq < 0 || *irq > 15)
36006 + if (*irq > 15)
36007 return 0;
36008
36009 /* check if the resource is reserved */
36010 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36011 return 1;
36012
36013 /* check if the resource is valid */
36014 - if (*dma < 0 || *dma == 4 || *dma > 7)
36015 + if (*dma == 4 || *dma > 7)
36016 return 0;
36017
36018 /* check if the resource is reserved */
36019 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36020 index f5d6d37..739f6a9 100644
36021 --- a/drivers/power/bq27x00_battery.c
36022 +++ b/drivers/power/bq27x00_battery.c
36023 @@ -72,7 +72,7 @@
36024 struct bq27x00_device_info;
36025 struct bq27x00_access_methods {
36026 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36027 -};
36028 +} __no_const;
36029
36030 enum bq27x00_chip { BQ27000, BQ27500 };
36031
36032 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36033 index 8d53174..04c65de 100644
36034 --- a/drivers/regulator/max8660.c
36035 +++ b/drivers/regulator/max8660.c
36036 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36037 max8660->shadow_regs[MAX8660_OVER1] = 5;
36038 } else {
36039 /* Otherwise devices can be toggled via software */
36040 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36041 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36042 + pax_open_kernel();
36043 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36044 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36045 + pax_close_kernel();
36046 }
36047
36048 /*
36049 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36050 index 970a233..ee1f241 100644
36051 --- a/drivers/regulator/mc13892-regulator.c
36052 +++ b/drivers/regulator/mc13892-regulator.c
36053 @@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36054 }
36055 mc13xxx_unlock(mc13892);
36056
36057 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36058 + pax_open_kernel();
36059 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36060 = mc13892_vcam_set_mode;
36061 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36062 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36063 = mc13892_vcam_get_mode;
36064 + pax_close_kernel();
36065
36066 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36067 ARRAY_SIZE(mc13892_regulators));
36068 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36069 index cace6d3..f623fda 100644
36070 --- a/drivers/rtc/rtc-dev.c
36071 +++ b/drivers/rtc/rtc-dev.c
36072 @@ -14,6 +14,7 @@
36073 #include <linux/module.h>
36074 #include <linux/rtc.h>
36075 #include <linux/sched.h>
36076 +#include <linux/grsecurity.h>
36077 #include "rtc-core.h"
36078
36079 static dev_t rtc_devt;
36080 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36081 if (copy_from_user(&tm, uarg, sizeof(tm)))
36082 return -EFAULT;
36083
36084 + gr_log_timechange();
36085 +
36086 return rtc_set_time(rtc, &tm);
36087
36088 case RTC_PIE_ON:
36089 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36090 index 3fcf627..f334910 100644
36091 --- a/drivers/scsi/aacraid/aacraid.h
36092 +++ b/drivers/scsi/aacraid/aacraid.h
36093 @@ -492,7 +492,7 @@ struct adapter_ops
36094 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36095 /* Administrative operations */
36096 int (*adapter_comm)(struct aac_dev * dev, int comm);
36097 -};
36098 +} __no_const;
36099
36100 /*
36101 * Define which interrupt handler needs to be installed
36102 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36103 index 0d279c44..3d25a97 100644
36104 --- a/drivers/scsi/aacraid/linit.c
36105 +++ b/drivers/scsi/aacraid/linit.c
36106 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36107 #elif defined(__devinitconst)
36108 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36109 #else
36110 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36111 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36112 #endif
36113 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36114 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36115 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36116 index ff80552..1c4120c 100644
36117 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36118 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36119 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36120 .lldd_ata_set_dmamode = asd_set_dmamode,
36121 };
36122
36123 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36124 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36125 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36126 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36127 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36128 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36129 index 4ad7e36..d004679 100644
36130 --- a/drivers/scsi/bfa/bfa.h
36131 +++ b/drivers/scsi/bfa/bfa.h
36132 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36133 u32 *end);
36134 int cpe_vec_q0;
36135 int rme_vec_q0;
36136 -};
36137 +} __no_const;
36138 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36139
36140 struct bfa_faa_cbfn_s {
36141 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36142 index f0f80e2..8ec946b 100644
36143 --- a/drivers/scsi/bfa/bfa_fcpim.c
36144 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36145 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36146
36147 bfa_iotag_attach(fcp);
36148
36149 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36150 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36151 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36152 (fcp->num_itns * sizeof(struct bfa_itn_s));
36153 memset(fcp->itn_arr, 0,
36154 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36155 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36156 {
36157 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36158 - struct bfa_itn_s *itn;
36159 + bfa_itn_s_no_const *itn;
36160
36161 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36162 itn->isr = isr;
36163 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36164 index 36f26da..38a34a8 100644
36165 --- a/drivers/scsi/bfa/bfa_fcpim.h
36166 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36167 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36168 struct bfa_itn_s {
36169 bfa_isr_func_t isr;
36170 };
36171 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36172
36173 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36174 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36175 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36176 struct list_head iotag_tio_free_q; /* free IO resources */
36177 struct list_head iotag_unused_q; /* unused IO resources*/
36178 struct bfa_iotag_s *iotag_arr;
36179 - struct bfa_itn_s *itn_arr;
36180 + bfa_itn_s_no_const *itn_arr;
36181 int num_ioim_reqs;
36182 int num_fwtio_reqs;
36183 int num_itns;
36184 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36185 index 1a99d4b..e85d64b 100644
36186 --- a/drivers/scsi/bfa/bfa_ioc.h
36187 +++ b/drivers/scsi/bfa/bfa_ioc.h
36188 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36189 bfa_ioc_disable_cbfn_t disable_cbfn;
36190 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36191 bfa_ioc_reset_cbfn_t reset_cbfn;
36192 -};
36193 +} __no_const;
36194
36195 /*
36196 * IOC event notification mechanism.
36197 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36198 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36199 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36200 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36201 -};
36202 +} __no_const;
36203
36204 /*
36205 * Queue element to wait for room in request queue. FIFO order is
36206 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36207 index a3a056a..b9bbc2f 100644
36208 --- a/drivers/scsi/hosts.c
36209 +++ b/drivers/scsi/hosts.c
36210 @@ -42,7 +42,7 @@
36211 #include "scsi_logging.h"
36212
36213
36214 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36215 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36216
36217
36218 static void scsi_host_cls_release(struct device *dev)
36219 @@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36220 * subtract one because we increment first then return, but we need to
36221 * know what the next host number was before increment
36222 */
36223 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36224 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36225 shost->dma_channel = 0xff;
36226
36227 /* These three are default values which can be overridden */
36228 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36229 index 796482b..d08435c 100644
36230 --- a/drivers/scsi/hpsa.c
36231 +++ b/drivers/scsi/hpsa.c
36232 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36233 unsigned long flags;
36234
36235 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36236 - return h->access.command_completed(h, q);
36237 + return h->access->command_completed(h, q);
36238
36239 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36240 a = rq->head[rq->current_entry];
36241 @@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36242 while (!list_empty(&h->reqQ)) {
36243 c = list_entry(h->reqQ.next, struct CommandList, list);
36244 /* can't do anything if fifo is full */
36245 - if ((h->access.fifo_full(h))) {
36246 + if ((h->access->fifo_full(h))) {
36247 dev_warn(&h->pdev->dev, "fifo full\n");
36248 break;
36249 }
36250 @@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36251
36252 /* Tell the controller execute command */
36253 spin_unlock_irqrestore(&h->lock, flags);
36254 - h->access.submit_command(h, c);
36255 + h->access->submit_command(h, c);
36256 spin_lock_irqsave(&h->lock, flags);
36257 }
36258 spin_unlock_irqrestore(&h->lock, flags);
36259 @@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36260
36261 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36262 {
36263 - return h->access.command_completed(h, q);
36264 + return h->access->command_completed(h, q);
36265 }
36266
36267 static inline bool interrupt_pending(struct ctlr_info *h)
36268 {
36269 - return h->access.intr_pending(h);
36270 + return h->access->intr_pending(h);
36271 }
36272
36273 static inline long interrupt_not_for_us(struct ctlr_info *h)
36274 {
36275 - return (h->access.intr_pending(h) == 0) ||
36276 + return (h->access->intr_pending(h) == 0) ||
36277 (h->interrupts_enabled == 0);
36278 }
36279
36280 @@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36281 if (prod_index < 0)
36282 return -ENODEV;
36283 h->product_name = products[prod_index].product_name;
36284 - h->access = *(products[prod_index].access);
36285 + h->access = products[prod_index].access;
36286
36287 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36288 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36289 @@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36290
36291 assert_spin_locked(&lockup_detector_lock);
36292 remove_ctlr_from_lockup_detector_list(h);
36293 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36294 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36295 spin_lock_irqsave(&h->lock, flags);
36296 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36297 spin_unlock_irqrestore(&h->lock, flags);
36298 @@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36299 }
36300
36301 /* make sure the board interrupts are off */
36302 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36303 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36304
36305 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36306 goto clean2;
36307 @@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36308 * fake ones to scoop up any residual completions.
36309 */
36310 spin_lock_irqsave(&h->lock, flags);
36311 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36312 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36313 spin_unlock_irqrestore(&h->lock, flags);
36314 free_irqs(h);
36315 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36316 @@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36317 dev_info(&h->pdev->dev, "Board READY.\n");
36318 dev_info(&h->pdev->dev,
36319 "Waiting for stale completions to drain.\n");
36320 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36321 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36322 msleep(10000);
36323 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36324 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36325
36326 rc = controller_reset_failed(h->cfgtable);
36327 if (rc)
36328 @@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36329 }
36330
36331 /* Turn the interrupts on so we can service requests */
36332 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36333 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36334
36335 hpsa_hba_inquiry(h);
36336 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36337 @@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36338 * To write all data in the battery backed cache to disks
36339 */
36340 hpsa_flush_cache(h);
36341 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36342 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36343 hpsa_free_irqs_and_disable_msix(h);
36344 }
36345
36346 @@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36347 return;
36348 }
36349 /* Change the access methods to the performant access methods */
36350 - h->access = SA5_performant_access;
36351 + h->access = &SA5_performant_access;
36352 h->transMethod = CFGTBL_Trans_Performant;
36353 }
36354
36355 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36356 index 9816479..c5d4e97 100644
36357 --- a/drivers/scsi/hpsa.h
36358 +++ b/drivers/scsi/hpsa.h
36359 @@ -79,7 +79,7 @@ struct ctlr_info {
36360 unsigned int msix_vector;
36361 unsigned int msi_vector;
36362 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36363 - struct access_method access;
36364 + struct access_method *access;
36365
36366 /* queue and queue Info */
36367 struct list_head reqQ;
36368 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36369 index f2df059..a3a9930 100644
36370 --- a/drivers/scsi/ips.h
36371 +++ b/drivers/scsi/ips.h
36372 @@ -1027,7 +1027,7 @@ typedef struct {
36373 int (*intr)(struct ips_ha *);
36374 void (*enableint)(struct ips_ha *);
36375 uint32_t (*statupd)(struct ips_ha *);
36376 -} ips_hw_func_t;
36377 +} __no_const ips_hw_func_t;
36378
36379 typedef struct ips_ha {
36380 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36381 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36382 index aceffad..c35c08d 100644
36383 --- a/drivers/scsi/libfc/fc_exch.c
36384 +++ b/drivers/scsi/libfc/fc_exch.c
36385 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36386 * all together if not used XXX
36387 */
36388 struct {
36389 - atomic_t no_free_exch;
36390 - atomic_t no_free_exch_xid;
36391 - atomic_t xid_not_found;
36392 - atomic_t xid_busy;
36393 - atomic_t seq_not_found;
36394 - atomic_t non_bls_resp;
36395 + atomic_unchecked_t no_free_exch;
36396 + atomic_unchecked_t no_free_exch_xid;
36397 + atomic_unchecked_t xid_not_found;
36398 + atomic_unchecked_t xid_busy;
36399 + atomic_unchecked_t seq_not_found;
36400 + atomic_unchecked_t non_bls_resp;
36401 } stats;
36402 };
36403
36404 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36405 /* allocate memory for exchange */
36406 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36407 if (!ep) {
36408 - atomic_inc(&mp->stats.no_free_exch);
36409 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36410 goto out;
36411 }
36412 memset(ep, 0, sizeof(*ep));
36413 @@ -780,7 +780,7 @@ out:
36414 return ep;
36415 err:
36416 spin_unlock_bh(&pool->lock);
36417 - atomic_inc(&mp->stats.no_free_exch_xid);
36418 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36419 mempool_free(ep, mp->ep_pool);
36420 return NULL;
36421 }
36422 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36423 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36424 ep = fc_exch_find(mp, xid);
36425 if (!ep) {
36426 - atomic_inc(&mp->stats.xid_not_found);
36427 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36428 reject = FC_RJT_OX_ID;
36429 goto out;
36430 }
36431 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36432 ep = fc_exch_find(mp, xid);
36433 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36434 if (ep) {
36435 - atomic_inc(&mp->stats.xid_busy);
36436 + atomic_inc_unchecked(&mp->stats.xid_busy);
36437 reject = FC_RJT_RX_ID;
36438 goto rel;
36439 }
36440 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36441 }
36442 xid = ep->xid; /* get our XID */
36443 } else if (!ep) {
36444 - atomic_inc(&mp->stats.xid_not_found);
36445 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36446 reject = FC_RJT_RX_ID; /* XID not found */
36447 goto out;
36448 }
36449 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36450 } else {
36451 sp = &ep->seq;
36452 if (sp->id != fh->fh_seq_id) {
36453 - atomic_inc(&mp->stats.seq_not_found);
36454 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36455 if (f_ctl & FC_FC_END_SEQ) {
36456 /*
36457 * Update sequence_id based on incoming last
36458 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36459
36460 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36461 if (!ep) {
36462 - atomic_inc(&mp->stats.xid_not_found);
36463 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36464 goto out;
36465 }
36466 if (ep->esb_stat & ESB_ST_COMPLETE) {
36467 - atomic_inc(&mp->stats.xid_not_found);
36468 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36469 goto rel;
36470 }
36471 if (ep->rxid == FC_XID_UNKNOWN)
36472 ep->rxid = ntohs(fh->fh_rx_id);
36473 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36474 - atomic_inc(&mp->stats.xid_not_found);
36475 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36476 goto rel;
36477 }
36478 if (ep->did != ntoh24(fh->fh_s_id) &&
36479 ep->did != FC_FID_FLOGI) {
36480 - atomic_inc(&mp->stats.xid_not_found);
36481 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36482 goto rel;
36483 }
36484 sof = fr_sof(fp);
36485 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36486 sp->ssb_stat |= SSB_ST_RESP;
36487 sp->id = fh->fh_seq_id;
36488 } else if (sp->id != fh->fh_seq_id) {
36489 - atomic_inc(&mp->stats.seq_not_found);
36490 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36491 goto rel;
36492 }
36493
36494 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36495 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36496
36497 if (!sp)
36498 - atomic_inc(&mp->stats.xid_not_found);
36499 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36500 else
36501 - atomic_inc(&mp->stats.non_bls_resp);
36502 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36503
36504 fc_frame_free(fp);
36505 }
36506 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36507 index d109cc3..09f4e7d 100644
36508 --- a/drivers/scsi/libsas/sas_ata.c
36509 +++ b/drivers/scsi/libsas/sas_ata.c
36510 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36511 .postreset = ata_std_postreset,
36512 .error_handler = ata_std_error_handler,
36513 .post_internal_cmd = sas_ata_post_internal,
36514 - .qc_defer = ata_std_qc_defer,
36515 + .qc_defer = ata_std_qc_defer,
36516 .qc_prep = ata_noop_qc_prep,
36517 .qc_issue = sas_ata_qc_issue,
36518 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36519 diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36520 index fe5d396..e93d526 100644
36521 --- a/drivers/scsi/lpfc/Makefile
36522 +++ b/drivers/scsi/lpfc/Makefile
36523 @@ -22,7 +22,7 @@
36524 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36525 ccflags-$(GCOV) += -O0
36526
36527 -ccflags-y += -Werror
36528 +#ccflags-y += -Werror
36529
36530 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36531
36532 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36533 index e5da6da..c888d48 100644
36534 --- a/drivers/scsi/lpfc/lpfc.h
36535 +++ b/drivers/scsi/lpfc/lpfc.h
36536 @@ -416,7 +416,7 @@ struct lpfc_vport {
36537 struct dentry *debug_nodelist;
36538 struct dentry *vport_debugfs_root;
36539 struct lpfc_debugfs_trc *disc_trc;
36540 - atomic_t disc_trc_cnt;
36541 + atomic_unchecked_t disc_trc_cnt;
36542 #endif
36543 uint8_t stat_data_enabled;
36544 uint8_t stat_data_blocked;
36545 @@ -830,8 +830,8 @@ struct lpfc_hba {
36546 struct timer_list fabric_block_timer;
36547 unsigned long bit_flags;
36548 #define FABRIC_COMANDS_BLOCKED 0
36549 - atomic_t num_rsrc_err;
36550 - atomic_t num_cmd_success;
36551 + atomic_unchecked_t num_rsrc_err;
36552 + atomic_unchecked_t num_cmd_success;
36553 unsigned long last_rsrc_error_time;
36554 unsigned long last_ramp_down_time;
36555 unsigned long last_ramp_up_time;
36556 @@ -867,7 +867,7 @@ struct lpfc_hba {
36557
36558 struct dentry *debug_slow_ring_trc;
36559 struct lpfc_debugfs_trc *slow_ring_trc;
36560 - atomic_t slow_ring_trc_cnt;
36561 + atomic_unchecked_t slow_ring_trc_cnt;
36562 /* iDiag debugfs sub-directory */
36563 struct dentry *idiag_root;
36564 struct dentry *idiag_pci_cfg;
36565 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36566 index 3217d63..c417981 100644
36567 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36568 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36569 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36570
36571 #include <linux/debugfs.h>
36572
36573 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36574 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36575 static unsigned long lpfc_debugfs_start_time = 0L;
36576
36577 /* iDiag */
36578 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36579 lpfc_debugfs_enable = 0;
36580
36581 len = 0;
36582 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36583 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36584 (lpfc_debugfs_max_disc_trc - 1);
36585 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36586 dtp = vport->disc_trc + i;
36587 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36588 lpfc_debugfs_enable = 0;
36589
36590 len = 0;
36591 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36592 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36593 (lpfc_debugfs_max_slow_ring_trc - 1);
36594 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36595 dtp = phba->slow_ring_trc + i;
36596 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36597 !vport || !vport->disc_trc)
36598 return;
36599
36600 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36601 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36602 (lpfc_debugfs_max_disc_trc - 1);
36603 dtp = vport->disc_trc + index;
36604 dtp->fmt = fmt;
36605 dtp->data1 = data1;
36606 dtp->data2 = data2;
36607 dtp->data3 = data3;
36608 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36609 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36610 dtp->jif = jiffies;
36611 #endif
36612 return;
36613 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36614 !phba || !phba->slow_ring_trc)
36615 return;
36616
36617 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36618 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36619 (lpfc_debugfs_max_slow_ring_trc - 1);
36620 dtp = phba->slow_ring_trc + index;
36621 dtp->fmt = fmt;
36622 dtp->data1 = data1;
36623 dtp->data2 = data2;
36624 dtp->data3 = data3;
36625 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36626 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36627 dtp->jif = jiffies;
36628 #endif
36629 return;
36630 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36631 "slow_ring buffer\n");
36632 goto debug_failed;
36633 }
36634 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36635 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36636 memset(phba->slow_ring_trc, 0,
36637 (sizeof(struct lpfc_debugfs_trc) *
36638 lpfc_debugfs_max_slow_ring_trc));
36639 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36640 "buffer\n");
36641 goto debug_failed;
36642 }
36643 - atomic_set(&vport->disc_trc_cnt, 0);
36644 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36645
36646 snprintf(name, sizeof(name), "discovery_trace");
36647 vport->debug_disc_trc =
36648 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36649 index 411ed48..967f553 100644
36650 --- a/drivers/scsi/lpfc/lpfc_init.c
36651 +++ b/drivers/scsi/lpfc/lpfc_init.c
36652 @@ -10341,8 +10341,10 @@ lpfc_init(void)
36653 "misc_register returned with status %d", error);
36654
36655 if (lpfc_enable_npiv) {
36656 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36657 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36658 + pax_open_kernel();
36659 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36660 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36661 + pax_close_kernel();
36662 }
36663 lpfc_transport_template =
36664 fc_attach_transport(&lpfc_transport_functions);
36665 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36666 index 66e0906..1620281 100644
36667 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36668 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36669 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36670 uint32_t evt_posted;
36671
36672 spin_lock_irqsave(&phba->hbalock, flags);
36673 - atomic_inc(&phba->num_rsrc_err);
36674 + atomic_inc_unchecked(&phba->num_rsrc_err);
36675 phba->last_rsrc_error_time = jiffies;
36676
36677 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36678 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36679 unsigned long flags;
36680 struct lpfc_hba *phba = vport->phba;
36681 uint32_t evt_posted;
36682 - atomic_inc(&phba->num_cmd_success);
36683 + atomic_inc_unchecked(&phba->num_cmd_success);
36684
36685 if (vport->cfg_lun_queue_depth <= queue_depth)
36686 return;
36687 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36688 unsigned long num_rsrc_err, num_cmd_success;
36689 int i;
36690
36691 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36692 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36693 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36694 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36695
36696 /*
36697 * The error and success command counters are global per
36698 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36699 }
36700 }
36701 lpfc_destroy_vport_work_array(phba, vports);
36702 - atomic_set(&phba->num_rsrc_err, 0);
36703 - atomic_set(&phba->num_cmd_success, 0);
36704 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36705 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36706 }
36707
36708 /**
36709 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36710 }
36711 }
36712 lpfc_destroy_vport_work_array(phba, vports);
36713 - atomic_set(&phba->num_rsrc_err, 0);
36714 - atomic_set(&phba->num_cmd_success, 0);
36715 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36716 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36717 }
36718
36719 /**
36720 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36721 index ea8a0b4..812a124 100644
36722 --- a/drivers/scsi/pmcraid.c
36723 +++ b/drivers/scsi/pmcraid.c
36724 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36725 res->scsi_dev = scsi_dev;
36726 scsi_dev->hostdata = res;
36727 res->change_detected = 0;
36728 - atomic_set(&res->read_failures, 0);
36729 - atomic_set(&res->write_failures, 0);
36730 + atomic_set_unchecked(&res->read_failures, 0);
36731 + atomic_set_unchecked(&res->write_failures, 0);
36732 rc = 0;
36733 }
36734 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36735 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36736
36737 /* If this was a SCSI read/write command keep count of errors */
36738 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36739 - atomic_inc(&res->read_failures);
36740 + atomic_inc_unchecked(&res->read_failures);
36741 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36742 - atomic_inc(&res->write_failures);
36743 + atomic_inc_unchecked(&res->write_failures);
36744
36745 if (!RES_IS_GSCSI(res->cfg_entry) &&
36746 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36747 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36748 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36749 * hrrq_id assigned here in queuecommand
36750 */
36751 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36752 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36753 pinstance->num_hrrq;
36754 cmd->cmd_done = pmcraid_io_done;
36755
36756 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36757 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36758 * hrrq_id assigned here in queuecommand
36759 */
36760 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36761 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36762 pinstance->num_hrrq;
36763
36764 if (request_size) {
36765 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36766
36767 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36768 /* add resources only after host is added into system */
36769 - if (!atomic_read(&pinstance->expose_resources))
36770 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36771 return;
36772
36773 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36774 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36775 init_waitqueue_head(&pinstance->reset_wait_q);
36776
36777 atomic_set(&pinstance->outstanding_cmds, 0);
36778 - atomic_set(&pinstance->last_message_id, 0);
36779 - atomic_set(&pinstance->expose_resources, 0);
36780 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36781 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36782
36783 INIT_LIST_HEAD(&pinstance->free_res_q);
36784 INIT_LIST_HEAD(&pinstance->used_res_q);
36785 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36786 /* Schedule worker thread to handle CCN and take care of adding and
36787 * removing devices to OS
36788 */
36789 - atomic_set(&pinstance->expose_resources, 1);
36790 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36791 schedule_work(&pinstance->worker_q);
36792 return rc;
36793
36794 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36795 index e1d150f..6c6df44 100644
36796 --- a/drivers/scsi/pmcraid.h
36797 +++ b/drivers/scsi/pmcraid.h
36798 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36799 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36800
36801 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36802 - atomic_t last_message_id;
36803 + atomic_unchecked_t last_message_id;
36804
36805 /* configuration table */
36806 struct pmcraid_config_table *cfg_table;
36807 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36808 atomic_t outstanding_cmds;
36809
36810 /* should add/delete resources to mid-layer now ?*/
36811 - atomic_t expose_resources;
36812 + atomic_unchecked_t expose_resources;
36813
36814
36815
36816 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36817 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36818 };
36819 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36820 - atomic_t read_failures; /* count of failed READ commands */
36821 - atomic_t write_failures; /* count of failed WRITE commands */
36822 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36823 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36824
36825 /* To indicate add/delete/modify during CCN */
36826 u8 change_detected;
36827 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36828 index 5ab9530..2dd80f7 100644
36829 --- a/drivers/scsi/qla2xxx/qla_attr.c
36830 +++ b/drivers/scsi/qla2xxx/qla_attr.c
36831 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36832 return 0;
36833 }
36834
36835 -struct fc_function_template qla2xxx_transport_functions = {
36836 +fc_function_template_no_const qla2xxx_transport_functions = {
36837
36838 .show_host_node_name = 1,
36839 .show_host_port_name = 1,
36840 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36841 .bsg_timeout = qla24xx_bsg_timeout,
36842 };
36843
36844 -struct fc_function_template qla2xxx_transport_vport_functions = {
36845 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
36846
36847 .show_host_node_name = 1,
36848 .show_host_port_name = 1,
36849 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36850 index 39007f5..7fafc64 100644
36851 --- a/drivers/scsi/qla2xxx/qla_def.h
36852 +++ b/drivers/scsi/qla2xxx/qla_def.h
36853 @@ -2284,7 +2284,7 @@ struct isp_operations {
36854 int (*start_scsi) (srb_t *);
36855 int (*abort_isp) (struct scsi_qla_host *);
36856 int (*iospace_config)(struct qla_hw_data*);
36857 -};
36858 +} __no_const;
36859
36860 /* MSI-X Support *************************************************************/
36861
36862 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36863 index 9eacd2d..d79629c 100644
36864 --- a/drivers/scsi/qla2xxx/qla_gbl.h
36865 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
36866 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36867 struct device_attribute;
36868 extern struct device_attribute *qla2x00_host_attrs[];
36869 struct fc_function_template;
36870 -extern struct fc_function_template qla2xxx_transport_functions;
36871 -extern struct fc_function_template qla2xxx_transport_vport_functions;
36872 +extern fc_function_template_no_const qla2xxx_transport_functions;
36873 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36874 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36875 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36876 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36877 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36878 index 96a5616..eeb185a 100644
36879 --- a/drivers/scsi/qla4xxx/ql4_def.h
36880 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36881 @@ -268,7 +268,7 @@ struct ddb_entry {
36882 * (4000 only) */
36883 atomic_t relogin_timer; /* Max Time to wait for
36884 * relogin to complete */
36885 - atomic_t relogin_retry_count; /* Num of times relogin has been
36886 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36887 * retried */
36888 uint32_t default_time2wait; /* Default Min time between
36889 * relogins (+aens) */
36890 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36891 index cd15678..f7e6846 100644
36892 --- a/drivers/scsi/qla4xxx/ql4_os.c
36893 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36894 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36895 */
36896 if (!iscsi_is_session_online(cls_sess)) {
36897 /* Reset retry relogin timer */
36898 - atomic_inc(&ddb_entry->relogin_retry_count);
36899 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36900 DEBUG2(ql4_printk(KERN_INFO, ha,
36901 "%s: index[%d] relogin timed out-retrying"
36902 " relogin (%d), retry (%d)\n", __func__,
36903 ddb_entry->fw_ddb_index,
36904 - atomic_read(&ddb_entry->relogin_retry_count),
36905 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36906 ddb_entry->default_time2wait + 4));
36907 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36908 atomic_set(&ddb_entry->retry_relogin_timer,
36909 @@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36910
36911 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36912 atomic_set(&ddb_entry->relogin_timer, 0);
36913 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36914 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36915 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36916 ddb_entry->default_relogin_timeout =
36917 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36918 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36919 index bbbc9c9..ce22f77 100644
36920 --- a/drivers/scsi/scsi.c
36921 +++ b/drivers/scsi/scsi.c
36922 @@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36923 unsigned long timeout;
36924 int rtn = 0;
36925
36926 - atomic_inc(&cmd->device->iorequest_cnt);
36927 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36928
36929 /* check if the device is still usable */
36930 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36931 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36932 index 6dfb978..ddc470e 100644
36933 --- a/drivers/scsi/scsi_lib.c
36934 +++ b/drivers/scsi/scsi_lib.c
36935 @@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36936 shost = sdev->host;
36937 scsi_init_cmd_errh(cmd);
36938 cmd->result = DID_NO_CONNECT << 16;
36939 - atomic_inc(&cmd->device->iorequest_cnt);
36940 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36941
36942 /*
36943 * SCSI request completion path will do scsi_device_unbusy(),
36944 @@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36945
36946 INIT_LIST_HEAD(&cmd->eh_entry);
36947
36948 - atomic_inc(&cmd->device->iodone_cnt);
36949 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36950 if (cmd->result)
36951 - atomic_inc(&cmd->device->ioerr_cnt);
36952 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36953
36954 disposition = scsi_decide_disposition(cmd);
36955 if (disposition != SUCCESS &&
36956 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36957 index 04c2a27..9d8bd66 100644
36958 --- a/drivers/scsi/scsi_sysfs.c
36959 +++ b/drivers/scsi/scsi_sysfs.c
36960 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36961 char *buf) \
36962 { \
36963 struct scsi_device *sdev = to_scsi_device(dev); \
36964 - unsigned long long count = atomic_read(&sdev->field); \
36965 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36966 return snprintf(buf, 20, "0x%llx\n", count); \
36967 } \
36968 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36969 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36970 index 84a1fdf..693b0d6 100644
36971 --- a/drivers/scsi/scsi_tgt_lib.c
36972 +++ b/drivers/scsi/scsi_tgt_lib.c
36973 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36974 int err;
36975
36976 dprintk("%lx %u\n", uaddr, len);
36977 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36978 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36979 if (err) {
36980 /*
36981 * TODO: need to fixup sg_tablesize, max_segment_size,
36982 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36983 index 5797604..289a5b5 100644
36984 --- a/drivers/scsi/scsi_transport_fc.c
36985 +++ b/drivers/scsi/scsi_transport_fc.c
36986 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36987 * Netlink Infrastructure
36988 */
36989
36990 -static atomic_t fc_event_seq;
36991 +static atomic_unchecked_t fc_event_seq;
36992
36993 /**
36994 * fc_get_event_number - Obtain the next sequential FC event number
36995 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36996 u32
36997 fc_get_event_number(void)
36998 {
36999 - return atomic_add_return(1, &fc_event_seq);
37000 + return atomic_add_return_unchecked(1, &fc_event_seq);
37001 }
37002 EXPORT_SYMBOL(fc_get_event_number);
37003
37004 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37005 {
37006 int error;
37007
37008 - atomic_set(&fc_event_seq, 0);
37009 + atomic_set_unchecked(&fc_event_seq, 0);
37010
37011 error = transport_class_register(&fc_host_class);
37012 if (error)
37013 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37014 char *cp;
37015
37016 *val = simple_strtoul(buf, &cp, 0);
37017 - if ((*cp && (*cp != '\n')) || (*val < 0))
37018 + if (*cp && (*cp != '\n'))
37019 return -EINVAL;
37020 /*
37021 * Check for overflow; dev_loss_tmo is u32
37022 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37023 index 1cf640e..78e9014 100644
37024 --- a/drivers/scsi/scsi_transport_iscsi.c
37025 +++ b/drivers/scsi/scsi_transport_iscsi.c
37026 @@ -79,7 +79,7 @@ struct iscsi_internal {
37027 struct transport_container session_cont;
37028 };
37029
37030 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37031 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37032 static struct workqueue_struct *iscsi_eh_timer_workq;
37033
37034 static DEFINE_IDA(iscsi_sess_ida);
37035 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37036 int err;
37037
37038 ihost = shost->shost_data;
37039 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37040 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37041
37042 if (target_id == ISCSI_MAX_TARGET) {
37043 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37044 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37045 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37046 ISCSI_TRANSPORT_VERSION);
37047
37048 - atomic_set(&iscsi_session_nr, 0);
37049 + atomic_set_unchecked(&iscsi_session_nr, 0);
37050
37051 err = class_register(&iscsi_transport_class);
37052 if (err)
37053 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37054 index 21a045e..ec89e03 100644
37055 --- a/drivers/scsi/scsi_transport_srp.c
37056 +++ b/drivers/scsi/scsi_transport_srp.c
37057 @@ -33,7 +33,7 @@
37058 #include "scsi_transport_srp_internal.h"
37059
37060 struct srp_host_attrs {
37061 - atomic_t next_port_id;
37062 + atomic_unchecked_t next_port_id;
37063 };
37064 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37065
37066 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37067 struct Scsi_Host *shost = dev_to_shost(dev);
37068 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37069
37070 - atomic_set(&srp_host->next_port_id, 0);
37071 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37072 return 0;
37073 }
37074
37075 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37076 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37077 rport->roles = ids->roles;
37078
37079 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37080 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37081 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37082
37083 transport_setup_device(&rport->dev);
37084 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37085 index 9c5c5f2..8414557 100644
37086 --- a/drivers/scsi/sg.c
37087 +++ b/drivers/scsi/sg.c
37088 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37089 sdp->disk->disk_name,
37090 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37091 NULL,
37092 - (char *)arg);
37093 + (char __user *)arg);
37094 case BLKTRACESTART:
37095 return blk_trace_startstop(sdp->device->request_queue, 1);
37096 case BLKTRACESTOP:
37097 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37098 index 1041cb8..4a946fa 100644
37099 --- a/drivers/spi/spi.c
37100 +++ b/drivers/spi/spi.c
37101 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37102 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37103
37104 /* portable code must never pass more than 32 bytes */
37105 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37106 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37107
37108 static u8 *buf;
37109
37110 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37111 index 34afc16..ffe44dd 100644
37112 --- a/drivers/staging/octeon/ethernet-rx.c
37113 +++ b/drivers/staging/octeon/ethernet-rx.c
37114 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37115 /* Increment RX stats for virtual ports */
37116 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37117 #ifdef CONFIG_64BIT
37118 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37119 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37120 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37121 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37122 #else
37123 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37124 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37125 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37126 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37127 #endif
37128 }
37129 netif_receive_skb(skb);
37130 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37131 dev->name);
37132 */
37133 #ifdef CONFIG_64BIT
37134 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37135 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37136 #else
37137 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37138 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37139 #endif
37140 dev_kfree_skb_irq(skb);
37141 }
37142 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37143 index 18f7a79..cc3bc24 100644
37144 --- a/drivers/staging/octeon/ethernet.c
37145 +++ b/drivers/staging/octeon/ethernet.c
37146 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37147 * since the RX tasklet also increments it.
37148 */
37149 #ifdef CONFIG_64BIT
37150 - atomic64_add(rx_status.dropped_packets,
37151 - (atomic64_t *)&priv->stats.rx_dropped);
37152 + atomic64_add_unchecked(rx_status.dropped_packets,
37153 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37154 #else
37155 - atomic_add(rx_status.dropped_packets,
37156 - (atomic_t *)&priv->stats.rx_dropped);
37157 + atomic_add_unchecked(rx_status.dropped_packets,
37158 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37159 #endif
37160 }
37161
37162 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37163 index dc23395..cf7e9b1 100644
37164 --- a/drivers/staging/rtl8712/rtl871x_io.h
37165 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37166 @@ -108,7 +108,7 @@ struct _io_ops {
37167 u8 *pmem);
37168 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37169 u8 *pmem);
37170 -};
37171 +} __no_const;
37172
37173 struct io_req {
37174 struct list_head list;
37175 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37176 index c7b5e8b..783d6cb 100644
37177 --- a/drivers/staging/sbe-2t3e3/netdev.c
37178 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37179 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37180 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37181
37182 if (rlen)
37183 - if (copy_to_user(data, &resp, rlen))
37184 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37185 return -EFAULT;
37186
37187 return 0;
37188 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37189 index 42cdafe..2769103 100644
37190 --- a/drivers/staging/speakup/speakup_soft.c
37191 +++ b/drivers/staging/speakup/speakup_soft.c
37192 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37193 break;
37194 } else if (!initialized) {
37195 if (*init) {
37196 - ch = *init;
37197 init++;
37198 } else {
37199 initialized = 1;
37200 }
37201 + ch = *init;
37202 } else {
37203 ch = synth_buffer_getc();
37204 }
37205 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37206 index 5d89c0f..9261317 100644
37207 --- a/drivers/staging/usbip/usbip_common.h
37208 +++ b/drivers/staging/usbip/usbip_common.h
37209 @@ -289,7 +289,7 @@ struct usbip_device {
37210 void (*shutdown)(struct usbip_device *);
37211 void (*reset)(struct usbip_device *);
37212 void (*unusable)(struct usbip_device *);
37213 - } eh_ops;
37214 + } __no_const eh_ops;
37215 };
37216
37217 #define kthread_get_run(threadfn, data, namefmt, ...) \
37218 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37219 index 88b3298..3783eee 100644
37220 --- a/drivers/staging/usbip/vhci.h
37221 +++ b/drivers/staging/usbip/vhci.h
37222 @@ -88,7 +88,7 @@ struct vhci_hcd {
37223 unsigned resuming:1;
37224 unsigned long re_timeout;
37225
37226 - atomic_t seqnum;
37227 + atomic_unchecked_t seqnum;
37228
37229 /*
37230 * NOTE:
37231 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37232 index f708cba..2de6d72 100644
37233 --- a/drivers/staging/usbip/vhci_hcd.c
37234 +++ b/drivers/staging/usbip/vhci_hcd.c
37235 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37236 return;
37237 }
37238
37239 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37240 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37241 if (priv->seqnum == 0xffff)
37242 dev_info(&urb->dev->dev, "seqnum max\n");
37243
37244 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37245 return -ENOMEM;
37246 }
37247
37248 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37249 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37250 if (unlink->seqnum == 0xffff)
37251 pr_info("seqnum max\n");
37252
37253 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37254 vdev->rhport = rhport;
37255 }
37256
37257 - atomic_set(&vhci->seqnum, 0);
37258 + atomic_set_unchecked(&vhci->seqnum, 0);
37259 spin_lock_init(&vhci->lock);
37260
37261 hcd->power_budget = 0; /* no limit */
37262 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37263 index f0eaf04..5a82e06 100644
37264 --- a/drivers/staging/usbip/vhci_rx.c
37265 +++ b/drivers/staging/usbip/vhci_rx.c
37266 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37267 if (!urb) {
37268 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37269 pr_info("max seqnum %d\n",
37270 - atomic_read(&the_controller->seqnum));
37271 + atomic_read_unchecked(&the_controller->seqnum));
37272 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37273 return;
37274 }
37275 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37276 index 7735027..30eed13 100644
37277 --- a/drivers/staging/vt6655/hostap.c
37278 +++ b/drivers/staging/vt6655/hostap.c
37279 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37280 *
37281 */
37282
37283 +static net_device_ops_no_const apdev_netdev_ops;
37284 +
37285 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37286 {
37287 PSDevice apdev_priv;
37288 struct net_device *dev = pDevice->dev;
37289 int ret;
37290 - const struct net_device_ops apdev_netdev_ops = {
37291 - .ndo_start_xmit = pDevice->tx_80211,
37292 - };
37293
37294 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37295
37296 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37297 *apdev_priv = *pDevice;
37298 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37299
37300 + /* only half broken now */
37301 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37302 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37303
37304 pDevice->apdev->type = ARPHRD_IEEE80211;
37305 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37306 index 51b5adf..098e320 100644
37307 --- a/drivers/staging/vt6656/hostap.c
37308 +++ b/drivers/staging/vt6656/hostap.c
37309 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37310 *
37311 */
37312
37313 +static net_device_ops_no_const apdev_netdev_ops;
37314 +
37315 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37316 {
37317 PSDevice apdev_priv;
37318 struct net_device *dev = pDevice->dev;
37319 int ret;
37320 - const struct net_device_ops apdev_netdev_ops = {
37321 - .ndo_start_xmit = pDevice->tx_80211,
37322 - };
37323
37324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37325
37326 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37327 *apdev_priv = *pDevice;
37328 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37329
37330 + /* only half broken now */
37331 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37332 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37333
37334 pDevice->apdev->type = ARPHRD_IEEE80211;
37335 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37336 index 7843dfd..3db105f 100644
37337 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37338 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37339 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37340
37341 struct usbctlx_completor {
37342 int (*complete) (struct usbctlx_completor *);
37343 -};
37344 +} __no_const;
37345
37346 static int
37347 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37348 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37349 index 1ca66ea..76f1343 100644
37350 --- a/drivers/staging/zcache/tmem.c
37351 +++ b/drivers/staging/zcache/tmem.c
37352 @@ -39,7 +39,7 @@
37353 * A tmem host implementation must use this function to register callbacks
37354 * for memory allocation.
37355 */
37356 -static struct tmem_hostops tmem_hostops;
37357 +static tmem_hostops_no_const tmem_hostops;
37358
37359 static void tmem_objnode_tree_init(void);
37360
37361 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37362 * A tmem host implementation must use this function to register
37363 * callbacks for a page-accessible memory (PAM) implementation
37364 */
37365 -static struct tmem_pamops tmem_pamops;
37366 +static tmem_pamops_no_const tmem_pamops;
37367
37368 void tmem_register_pamops(struct tmem_pamops *m)
37369 {
37370 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37371 index 0d4aa82..f7832d4 100644
37372 --- a/drivers/staging/zcache/tmem.h
37373 +++ b/drivers/staging/zcache/tmem.h
37374 @@ -180,6 +180,7 @@ struct tmem_pamops {
37375 void (*new_obj)(struct tmem_obj *);
37376 int (*replace_in_obj)(void *, struct tmem_obj *);
37377 };
37378 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37379 extern void tmem_register_pamops(struct tmem_pamops *m);
37380
37381 /* memory allocation methods provided by the host implementation */
37382 @@ -189,6 +190,7 @@ struct tmem_hostops {
37383 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37384 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37385 };
37386 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37387 extern void tmem_register_hostops(struct tmem_hostops *m);
37388
37389 /* core tmem accessor functions */
37390 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37391 index 634d0f3..efff61f 100644
37392 --- a/drivers/target/target_core_transport.c
37393 +++ b/drivers/target/target_core_transport.c
37394 @@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37395 spin_lock_init(&dev->se_port_lock);
37396 spin_lock_init(&dev->se_tmr_lock);
37397 spin_lock_init(&dev->qf_cmd_lock);
37398 - atomic_set(&dev->dev_ordered_id, 0);
37399 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37400
37401 se_dev_set_default_attribs(dev, dev_limits);
37402
37403 @@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37404 * Used to determine when ORDERED commands should go from
37405 * Dormant to Active status.
37406 */
37407 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37408 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37409 smp_mb__after_atomic_inc();
37410 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37411 cmd->se_ordered_id, cmd->sam_task_attr,
37412 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37413 index e61cabd..7617d26 100644
37414 --- a/drivers/tty/cyclades.c
37415 +++ b/drivers/tty/cyclades.c
37416 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37417 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37418 info->port.count);
37419 #endif
37420 - info->port.count++;
37421 + atomic_inc(&info->port.count);
37422 #ifdef CY_DEBUG_COUNT
37423 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37424 - current->pid, info->port.count);
37425 + current->pid, atomic_read(&info->port.count));
37426 #endif
37427
37428 /*
37429 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37430 for (j = 0; j < cy_card[i].nports; j++) {
37431 info = &cy_card[i].ports[j];
37432
37433 - if (info->port.count) {
37434 + if (atomic_read(&info->port.count)) {
37435 /* XXX is the ldisc num worth this? */
37436 struct tty_struct *tty;
37437 struct tty_ldisc *ld;
37438 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37439 index 2d691eb..be02ebd 100644
37440 --- a/drivers/tty/hvc/hvc_console.c
37441 +++ b/drivers/tty/hvc/hvc_console.c
37442 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37443
37444 spin_lock_irqsave(&hp->port.lock, flags);
37445 /* Check and then increment for fast path open. */
37446 - if (hp->port.count++ > 0) {
37447 + if (atomic_inc_return(&hp->port.count) > 1) {
37448 spin_unlock_irqrestore(&hp->port.lock, flags);
37449 hvc_kick();
37450 return 0;
37451 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37452
37453 spin_lock_irqsave(&hp->port.lock, flags);
37454
37455 - if (--hp->port.count == 0) {
37456 + if (atomic_dec_return(&hp->port.count) == 0) {
37457 spin_unlock_irqrestore(&hp->port.lock, flags);
37458 /* We are done with the tty pointer now. */
37459 tty_port_tty_set(&hp->port, NULL);
37460 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37461 */
37462 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37463 } else {
37464 - if (hp->port.count < 0)
37465 + if (atomic_read(&hp->port.count) < 0)
37466 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37467 - hp->vtermno, hp->port.count);
37468 + hp->vtermno, atomic_read(&hp->port.count));
37469 spin_unlock_irqrestore(&hp->port.lock, flags);
37470 }
37471
37472 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37473 * open->hangup case this can be called after the final close so prevent
37474 * that from happening for now.
37475 */
37476 - if (hp->port.count <= 0) {
37477 + if (atomic_read(&hp->port.count) <= 0) {
37478 spin_unlock_irqrestore(&hp->port.lock, flags);
37479 return;
37480 }
37481
37482 - temp_open_count = hp->port.count;
37483 - hp->port.count = 0;
37484 + temp_open_count = atomic_read(&hp->port.count);
37485 + atomic_set(&hp->port.count, 0);
37486 spin_unlock_irqrestore(&hp->port.lock, flags);
37487 tty_port_tty_set(&hp->port, NULL);
37488
37489 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37490 return -EPIPE;
37491
37492 /* FIXME what's this (unprotected) check for? */
37493 - if (hp->port.count <= 0)
37494 + if (atomic_read(&hp->port.count) <= 0)
37495 return -EIO;
37496
37497 spin_lock_irqsave(&hp->lock, flags);
37498 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37499 index d56788c..12d8f85 100644
37500 --- a/drivers/tty/hvc/hvcs.c
37501 +++ b/drivers/tty/hvc/hvcs.c
37502 @@ -83,6 +83,7 @@
37503 #include <asm/hvcserver.h>
37504 #include <asm/uaccess.h>
37505 #include <asm/vio.h>
37506 +#include <asm/local.h>
37507
37508 /*
37509 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37510 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37511
37512 spin_lock_irqsave(&hvcsd->lock, flags);
37513
37514 - if (hvcsd->port.count > 0) {
37515 + if (atomic_read(&hvcsd->port.count) > 0) {
37516 spin_unlock_irqrestore(&hvcsd->lock, flags);
37517 printk(KERN_INFO "HVCS: vterm state unchanged. "
37518 "The hvcs device node is still in use.\n");
37519 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37520 if ((retval = hvcs_partner_connect(hvcsd)))
37521 goto error_release;
37522
37523 - hvcsd->port.count = 1;
37524 + atomic_set(&hvcsd->port.count, 1);
37525 hvcsd->port.tty = tty;
37526 tty->driver_data = hvcsd;
37527
37528 @@ -1168,7 +1169,7 @@ fast_open:
37529
37530 spin_lock_irqsave(&hvcsd->lock, flags);
37531 tty_port_get(&hvcsd->port);
37532 - hvcsd->port.count++;
37533 + atomic_inc(&hvcsd->port.count);
37534 hvcsd->todo_mask |= HVCS_SCHED_READ;
37535 spin_unlock_irqrestore(&hvcsd->lock, flags);
37536
37537 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37538 hvcsd = tty->driver_data;
37539
37540 spin_lock_irqsave(&hvcsd->lock, flags);
37541 - if (--hvcsd->port.count == 0) {
37542 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37543
37544 vio_disable_interrupts(hvcsd->vdev);
37545
37546 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37547 free_irq(irq, hvcsd);
37548 tty_port_put(&hvcsd->port);
37549 return;
37550 - } else if (hvcsd->port.count < 0) {
37551 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37552 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37553 " is missmanaged.\n",
37554 - hvcsd->vdev->unit_address, hvcsd->port.count);
37555 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37556 }
37557
37558 spin_unlock_irqrestore(&hvcsd->lock, flags);
37559 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37560
37561 spin_lock_irqsave(&hvcsd->lock, flags);
37562 /* Preserve this so that we know how many kref refs to put */
37563 - temp_open_count = hvcsd->port.count;
37564 + temp_open_count = atomic_read(&hvcsd->port.count);
37565
37566 /*
37567 * Don't kref put inside the spinlock because the destruction
37568 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37569 tty->driver_data = NULL;
37570 hvcsd->port.tty = NULL;
37571
37572 - hvcsd->port.count = 0;
37573 + atomic_set(&hvcsd->port.count, 0);
37574
37575 /* This will drop any buffered data on the floor which is OK in a hangup
37576 * scenario. */
37577 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37578 * the middle of a write operation? This is a crummy place to do this
37579 * but we want to keep it all in the spinlock.
37580 */
37581 - if (hvcsd->port.count <= 0) {
37582 + if (atomic_read(&hvcsd->port.count) <= 0) {
37583 spin_unlock_irqrestore(&hvcsd->lock, flags);
37584 return -ENODEV;
37585 }
37586 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37587 {
37588 struct hvcs_struct *hvcsd = tty->driver_data;
37589
37590 - if (!hvcsd || hvcsd->port.count <= 0)
37591 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37592 return 0;
37593
37594 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37595 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37596 index f8b5fa0..4ba9f89 100644
37597 --- a/drivers/tty/ipwireless/tty.c
37598 +++ b/drivers/tty/ipwireless/tty.c
37599 @@ -29,6 +29,7 @@
37600 #include <linux/tty_driver.h>
37601 #include <linux/tty_flip.h>
37602 #include <linux/uaccess.h>
37603 +#include <asm/local.h>
37604
37605 #include "tty.h"
37606 #include "network.h"
37607 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37608 mutex_unlock(&tty->ipw_tty_mutex);
37609 return -ENODEV;
37610 }
37611 - if (tty->port.count == 0)
37612 + if (atomic_read(&tty->port.count) == 0)
37613 tty->tx_bytes_queued = 0;
37614
37615 - tty->port.count++;
37616 + atomic_inc(&tty->port.count);
37617
37618 tty->port.tty = linux_tty;
37619 linux_tty->driver_data = tty;
37620 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37621
37622 static void do_ipw_close(struct ipw_tty *tty)
37623 {
37624 - tty->port.count--;
37625 -
37626 - if (tty->port.count == 0) {
37627 + if (atomic_dec_return(&tty->port.count) == 0) {
37628 struct tty_struct *linux_tty = tty->port.tty;
37629
37630 if (linux_tty != NULL) {
37631 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37632 return;
37633
37634 mutex_lock(&tty->ipw_tty_mutex);
37635 - if (tty->port.count == 0) {
37636 + if (atomic_read(&tty->port.count) == 0) {
37637 mutex_unlock(&tty->ipw_tty_mutex);
37638 return;
37639 }
37640 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37641 return;
37642 }
37643
37644 - if (!tty->port.count) {
37645 + if (!atomic_read(&tty->port.count)) {
37646 mutex_unlock(&tty->ipw_tty_mutex);
37647 return;
37648 }
37649 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37650 return -ENODEV;
37651
37652 mutex_lock(&tty->ipw_tty_mutex);
37653 - if (!tty->port.count) {
37654 + if (!atomic_read(&tty->port.count)) {
37655 mutex_unlock(&tty->ipw_tty_mutex);
37656 return -EINVAL;
37657 }
37658 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37659 if (!tty)
37660 return -ENODEV;
37661
37662 - if (!tty->port.count)
37663 + if (!atomic_read(&tty->port.count))
37664 return -EINVAL;
37665
37666 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37667 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37668 if (!tty)
37669 return 0;
37670
37671 - if (!tty->port.count)
37672 + if (!atomic_read(&tty->port.count))
37673 return 0;
37674
37675 return tty->tx_bytes_queued;
37676 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37677 if (!tty)
37678 return -ENODEV;
37679
37680 - if (!tty->port.count)
37681 + if (!atomic_read(&tty->port.count))
37682 return -EINVAL;
37683
37684 return get_control_lines(tty);
37685 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37686 if (!tty)
37687 return -ENODEV;
37688
37689 - if (!tty->port.count)
37690 + if (!atomic_read(&tty->port.count))
37691 return -EINVAL;
37692
37693 return set_control_lines(tty, set, clear);
37694 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37695 if (!tty)
37696 return -ENODEV;
37697
37698 - if (!tty->port.count)
37699 + if (!atomic_read(&tty->port.count))
37700 return -EINVAL;
37701
37702 /* FIXME: Exactly how is the tty object locked here .. */
37703 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37704 * are gone */
37705 mutex_lock(&ttyj->ipw_tty_mutex);
37706 }
37707 - while (ttyj->port.count)
37708 + while (atomic_read(&ttyj->port.count))
37709 do_ipw_close(ttyj);
37710 ipwireless_disassociate_network_ttys(network,
37711 ttyj->channel_idx);
37712 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37713 index 324467d..504cc25 100644
37714 --- a/drivers/tty/moxa.c
37715 +++ b/drivers/tty/moxa.c
37716 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37717 }
37718
37719 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37720 - ch->port.count++;
37721 + atomic_inc(&ch->port.count);
37722 tty->driver_data = ch;
37723 tty_port_tty_set(&ch->port, tty);
37724 mutex_lock(&ch->port.mutex);
37725 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37726 index c43b683..4dab83e 100644
37727 --- a/drivers/tty/n_gsm.c
37728 +++ b/drivers/tty/n_gsm.c
37729 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37730 kref_init(&dlci->ref);
37731 mutex_init(&dlci->mutex);
37732 dlci->fifo = &dlci->_fifo;
37733 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37734 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37735 kfree(dlci);
37736 return NULL;
37737 }
37738 @@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37739 if (dlci == NULL)
37740 return -ENOMEM;
37741 port = &dlci->port;
37742 - port->count++;
37743 + atomic_inc(&port->count);
37744 tty->driver_data = dlci;
37745 dlci_get(dlci);
37746 dlci_get(dlci->gsm->dlci[0]);
37747 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37748 index ee1c268..0e97caf 100644
37749 --- a/drivers/tty/n_tty.c
37750 +++ b/drivers/tty/n_tty.c
37751 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37752 {
37753 *ops = tty_ldisc_N_TTY;
37754 ops->owner = NULL;
37755 - ops->refcount = ops->flags = 0;
37756 + atomic_set(&ops->refcount, 0);
37757 + ops->flags = 0;
37758 }
37759 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37760 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37761 index 5505ffc..7affff9 100644
37762 --- a/drivers/tty/pty.c
37763 +++ b/drivers/tty/pty.c
37764 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37765 panic("Couldn't register Unix98 pts driver");
37766
37767 /* Now create the /dev/ptmx special device */
37768 + pax_open_kernel();
37769 tty_default_fops(&ptmx_fops);
37770 - ptmx_fops.open = ptmx_open;
37771 + *(void **)&ptmx_fops.open = ptmx_open;
37772 + pax_close_kernel();
37773
37774 cdev_init(&ptmx_cdev, &ptmx_fops);
37775 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37776 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37777 index 777d5f9..56d67ca 100644
37778 --- a/drivers/tty/rocket.c
37779 +++ b/drivers/tty/rocket.c
37780 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37781 tty->driver_data = info;
37782 tty_port_tty_set(port, tty);
37783
37784 - if (port->count++ == 0) {
37785 + if (atomic_inc_return(&port->count) == 1) {
37786 atomic_inc(&rp_num_ports_open);
37787
37788 #ifdef ROCKET_DEBUG_OPEN
37789 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37790 #endif
37791 }
37792 #ifdef ROCKET_DEBUG_OPEN
37793 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37794 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37795 #endif
37796
37797 /*
37798 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37799 spin_unlock_irqrestore(&info->port.lock, flags);
37800 return;
37801 }
37802 - if (info->port.count)
37803 + if (atomic_read(&info->port.count))
37804 atomic_dec(&rp_num_ports_open);
37805 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37806 spin_unlock_irqrestore(&info->port.lock, flags);
37807 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37808 index 2b42a01..32a2ed3 100644
37809 --- a/drivers/tty/serial/kgdboc.c
37810 +++ b/drivers/tty/serial/kgdboc.c
37811 @@ -24,8 +24,9 @@
37812 #define MAX_CONFIG_LEN 40
37813
37814 static struct kgdb_io kgdboc_io_ops;
37815 +static struct kgdb_io kgdboc_io_ops_console;
37816
37817 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37818 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37819 static int configured = -1;
37820
37821 static char config[MAX_CONFIG_LEN];
37822 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37823 kgdboc_unregister_kbd();
37824 if (configured == 1)
37825 kgdb_unregister_io_module(&kgdboc_io_ops);
37826 + else if (configured == 2)
37827 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37828 }
37829
37830 static int configure_kgdboc(void)
37831 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37832 int err;
37833 char *cptr = config;
37834 struct console *cons;
37835 + int is_console = 0;
37836
37837 err = kgdboc_option_setup(config);
37838 if (err || !strlen(config) || isspace(config[0]))
37839 goto noconfig;
37840
37841 err = -ENODEV;
37842 - kgdboc_io_ops.is_console = 0;
37843 kgdb_tty_driver = NULL;
37844
37845 kgdboc_use_kms = 0;
37846 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37847 int idx;
37848 if (cons->device && cons->device(cons, &idx) == p &&
37849 idx == tty_line) {
37850 - kgdboc_io_ops.is_console = 1;
37851 + is_console = 1;
37852 break;
37853 }
37854 cons = cons->next;
37855 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37856 kgdb_tty_line = tty_line;
37857
37858 do_register:
37859 - err = kgdb_register_io_module(&kgdboc_io_ops);
37860 + if (is_console) {
37861 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37862 + configured = 2;
37863 + } else {
37864 + err = kgdb_register_io_module(&kgdboc_io_ops);
37865 + configured = 1;
37866 + }
37867 if (err)
37868 goto noconfig;
37869
37870 - configured = 1;
37871 -
37872 return 0;
37873
37874 noconfig:
37875 @@ -213,7 +220,7 @@ noconfig:
37876 static int __init init_kgdboc(void)
37877 {
37878 /* Already configured? */
37879 - if (configured == 1)
37880 + if (configured >= 1)
37881 return 0;
37882
37883 return configure_kgdboc();
37884 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37885 if (config[len - 1] == '\n')
37886 config[len - 1] = '\0';
37887
37888 - if (configured == 1)
37889 + if (configured >= 1)
37890 cleanup_kgdboc();
37891
37892 /* Go and configure with the new params. */
37893 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37894 .post_exception = kgdboc_post_exp_handler,
37895 };
37896
37897 +static struct kgdb_io kgdboc_io_ops_console = {
37898 + .name = "kgdboc",
37899 + .read_char = kgdboc_get_char,
37900 + .write_char = kgdboc_put_char,
37901 + .pre_exception = kgdboc_pre_exp_handler,
37902 + .post_exception = kgdboc_post_exp_handler,
37903 + .is_console = 1
37904 +};
37905 +
37906 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37907 /* This is only available if kgdboc is a built in for early debugging */
37908 static int __init kgdboc_early_init(char *opt)
37909 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37910 index 246b823..9e0db76 100644
37911 --- a/drivers/tty/serial/serial_core.c
37912 +++ b/drivers/tty/serial/serial_core.c
37913 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37914 uart_flush_buffer(tty);
37915 uart_shutdown(tty, state);
37916 spin_lock_irqsave(&port->lock, flags);
37917 - port->count = 0;
37918 + atomic_set(&port->count, 0);
37919 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37920 spin_unlock_irqrestore(&port->lock, flags);
37921 tty_port_tty_set(port, NULL);
37922 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37923 goto end;
37924 }
37925
37926 - port->count++;
37927 + atomic_inc(&port->count);
37928 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
37929 retval = -ENXIO;
37930 goto err_dec_count;
37931 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37932 /*
37933 * Make sure the device is in D0 state.
37934 */
37935 - if (port->count == 1)
37936 + if (atomic_read(&port->count) == 1)
37937 uart_change_pm(state, 0);
37938
37939 /*
37940 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37941 end:
37942 return retval;
37943 err_dec_count:
37944 - port->count--;
37945 + atomic_inc(&port->count);
37946 mutex_unlock(&port->mutex);
37947 goto end;
37948 }
37949 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
37950 index 593d40a..bdc61f3 100644
37951 --- a/drivers/tty/synclink.c
37952 +++ b/drivers/tty/synclink.c
37953 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37954
37955 if (debug_level >= DEBUG_LEVEL_INFO)
37956 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
37957 - __FILE__,__LINE__, info->device_name, info->port.count);
37958 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
37959
37960 if (tty_port_close_start(&info->port, tty, filp) == 0)
37961 goto cleanup;
37962 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37963 cleanup:
37964 if (debug_level >= DEBUG_LEVEL_INFO)
37965 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
37966 - tty->driver->name, info->port.count);
37967 + tty->driver->name, atomic_read(&info->port.count));
37968
37969 } /* end of mgsl_close() */
37970
37971 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
37972
37973 mgsl_flush_buffer(tty);
37974 shutdown(info);
37975 -
37976 - info->port.count = 0;
37977 +
37978 + atomic_set(&info->port.count, 0);
37979 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
37980 info->port.tty = NULL;
37981
37982 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37983
37984 if (debug_level >= DEBUG_LEVEL_INFO)
37985 printk("%s(%d):block_til_ready before block on %s count=%d\n",
37986 - __FILE__,__LINE__, tty->driver->name, port->count );
37987 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37988
37989 spin_lock_irqsave(&info->irq_spinlock, flags);
37990 if (!tty_hung_up_p(filp)) {
37991 extra_count = true;
37992 - port->count--;
37993 + atomic_dec(&port->count);
37994 }
37995 spin_unlock_irqrestore(&info->irq_spinlock, flags);
37996 port->blocked_open++;
37997 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37998
37999 if (debug_level >= DEBUG_LEVEL_INFO)
38000 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38001 - __FILE__,__LINE__, tty->driver->name, port->count );
38002 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38003
38004 tty_unlock();
38005 schedule();
38006 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38007
38008 /* FIXME: Racy on hangup during close wait */
38009 if (extra_count)
38010 - port->count++;
38011 + atomic_inc(&port->count);
38012 port->blocked_open--;
38013
38014 if (debug_level >= DEBUG_LEVEL_INFO)
38015 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38016 - __FILE__,__LINE__, tty->driver->name, port->count );
38017 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38018
38019 if (!retval)
38020 port->flags |= ASYNC_NORMAL_ACTIVE;
38021 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38022
38023 if (debug_level >= DEBUG_LEVEL_INFO)
38024 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38025 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38026 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38027
38028 /* If port is closing, signal caller to try again */
38029 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38030 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38031 spin_unlock_irqrestore(&info->netlock, flags);
38032 goto cleanup;
38033 }
38034 - info->port.count++;
38035 + atomic_inc(&info->port.count);
38036 spin_unlock_irqrestore(&info->netlock, flags);
38037
38038 - if (info->port.count == 1) {
38039 + if (atomic_read(&info->port.count) == 1) {
38040 /* 1st open on this device, init hardware */
38041 retval = startup(info);
38042 if (retval < 0)
38043 @@ -3444,8 +3444,8 @@ cleanup:
38044 if (retval) {
38045 if (tty->count == 1)
38046 info->port.tty = NULL; /* tty layer will release tty struct */
38047 - if(info->port.count)
38048 - info->port.count--;
38049 + if (atomic_read(&info->port.count))
38050 + atomic_dec(&info->port.count);
38051 }
38052
38053 return retval;
38054 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38055 unsigned short new_crctype;
38056
38057 /* return error if TTY interface open */
38058 - if (info->port.count)
38059 + if (atomic_read(&info->port.count))
38060 return -EBUSY;
38061
38062 switch (encoding)
38063 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38064
38065 /* arbitrate between network and tty opens */
38066 spin_lock_irqsave(&info->netlock, flags);
38067 - if (info->port.count != 0 || info->netcount != 0) {
38068 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38069 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38070 spin_unlock_irqrestore(&info->netlock, flags);
38071 return -EBUSY;
38072 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38073 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38074
38075 /* return error if TTY interface open */
38076 - if (info->port.count)
38077 + if (atomic_read(&info->port.count))
38078 return -EBUSY;
38079
38080 if (cmd != SIOCWANDEV)
38081 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38082 index aa1debf..9297a16 100644
38083 --- a/drivers/tty/synclink_gt.c
38084 +++ b/drivers/tty/synclink_gt.c
38085 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38086 tty->driver_data = info;
38087 info->port.tty = tty;
38088
38089 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38090 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38091
38092 /* If port is closing, signal caller to try again */
38093 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38094 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38095 mutex_unlock(&info->port.mutex);
38096 goto cleanup;
38097 }
38098 - info->port.count++;
38099 + atomic_inc(&info->port.count);
38100 spin_unlock_irqrestore(&info->netlock, flags);
38101
38102 - if (info->port.count == 1) {
38103 + if (atomic_read(&info->port.count) == 1) {
38104 /* 1st open on this device, init hardware */
38105 retval = startup(info);
38106 if (retval < 0) {
38107 @@ -716,8 +716,8 @@ cleanup:
38108 if (retval) {
38109 if (tty->count == 1)
38110 info->port.tty = NULL; /* tty layer will release tty struct */
38111 - if(info->port.count)
38112 - info->port.count--;
38113 + if(atomic_read(&info->port.count))
38114 + atomic_dec(&info->port.count);
38115 }
38116
38117 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38118 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38119
38120 if (sanity_check(info, tty->name, "close"))
38121 return;
38122 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38123 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38124
38125 if (tty_port_close_start(&info->port, tty, filp) == 0)
38126 goto cleanup;
38127 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38128 tty_port_close_end(&info->port, tty);
38129 info->port.tty = NULL;
38130 cleanup:
38131 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38132 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38133 }
38134
38135 static void hangup(struct tty_struct *tty)
38136 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38137 shutdown(info);
38138
38139 spin_lock_irqsave(&info->port.lock, flags);
38140 - info->port.count = 0;
38141 + atomic_set(&info->port.count, 0);
38142 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38143 info->port.tty = NULL;
38144 spin_unlock_irqrestore(&info->port.lock, flags);
38145 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38146 unsigned short new_crctype;
38147
38148 /* return error if TTY interface open */
38149 - if (info->port.count)
38150 + if (atomic_read(&info->port.count))
38151 return -EBUSY;
38152
38153 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38154 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38155
38156 /* arbitrate between network and tty opens */
38157 spin_lock_irqsave(&info->netlock, flags);
38158 - if (info->port.count != 0 || info->netcount != 0) {
38159 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38160 DBGINFO(("%s hdlc_open busy\n", dev->name));
38161 spin_unlock_irqrestore(&info->netlock, flags);
38162 return -EBUSY;
38163 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38164 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38165
38166 /* return error if TTY interface open */
38167 - if (info->port.count)
38168 + if (atomic_read(&info->port.count))
38169 return -EBUSY;
38170
38171 if (cmd != SIOCWANDEV)
38172 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38173 if (port == NULL)
38174 continue;
38175 spin_lock(&port->lock);
38176 - if ((port->port.count || port->netcount) &&
38177 + if ((atomic_read(&port->port.count) || port->netcount) &&
38178 port->pending_bh && !port->bh_running &&
38179 !port->bh_requested) {
38180 DBGISR(("%s bh queued\n", port->device_name));
38181 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38182 spin_lock_irqsave(&info->lock, flags);
38183 if (!tty_hung_up_p(filp)) {
38184 extra_count = true;
38185 - port->count--;
38186 + atomic_dec(&port->count);
38187 }
38188 spin_unlock_irqrestore(&info->lock, flags);
38189 port->blocked_open++;
38190 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38191 remove_wait_queue(&port->open_wait, &wait);
38192
38193 if (extra_count)
38194 - port->count++;
38195 + atomic_inc(&port->count);
38196 port->blocked_open--;
38197
38198 if (!retval)
38199 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38200 index a3dddc1..8905ab2 100644
38201 --- a/drivers/tty/synclinkmp.c
38202 +++ b/drivers/tty/synclinkmp.c
38203 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38204
38205 if (debug_level >= DEBUG_LEVEL_INFO)
38206 printk("%s(%d):%s open(), old ref count = %d\n",
38207 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38208 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38209
38210 /* If port is closing, signal caller to try again */
38211 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38212 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38213 spin_unlock_irqrestore(&info->netlock, flags);
38214 goto cleanup;
38215 }
38216 - info->port.count++;
38217 + atomic_inc(&info->port.count);
38218 spin_unlock_irqrestore(&info->netlock, flags);
38219
38220 - if (info->port.count == 1) {
38221 + if (atomic_read(&info->port.count) == 1) {
38222 /* 1st open on this device, init hardware */
38223 retval = startup(info);
38224 if (retval < 0)
38225 @@ -788,8 +788,8 @@ cleanup:
38226 if (retval) {
38227 if (tty->count == 1)
38228 info->port.tty = NULL; /* tty layer will release tty struct */
38229 - if(info->port.count)
38230 - info->port.count--;
38231 + if(atomic_read(&info->port.count))
38232 + atomic_dec(&info->port.count);
38233 }
38234
38235 return retval;
38236 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38237
38238 if (debug_level >= DEBUG_LEVEL_INFO)
38239 printk("%s(%d):%s close() entry, count=%d\n",
38240 - __FILE__,__LINE__, info->device_name, info->port.count);
38241 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38242
38243 if (tty_port_close_start(&info->port, tty, filp) == 0)
38244 goto cleanup;
38245 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38246 cleanup:
38247 if (debug_level >= DEBUG_LEVEL_INFO)
38248 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38249 - tty->driver->name, info->port.count);
38250 + tty->driver->name, atomic_read(&info->port.count));
38251 }
38252
38253 /* Called by tty_hangup() when a hangup is signaled.
38254 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38255 shutdown(info);
38256
38257 spin_lock_irqsave(&info->port.lock, flags);
38258 - info->port.count = 0;
38259 + atomic_set(&info->port.count, 0);
38260 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38261 info->port.tty = NULL;
38262 spin_unlock_irqrestore(&info->port.lock, flags);
38263 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38264 unsigned short new_crctype;
38265
38266 /* return error if TTY interface open */
38267 - if (info->port.count)
38268 + if (atomic_read(&info->port.count))
38269 return -EBUSY;
38270
38271 switch (encoding)
38272 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38273
38274 /* arbitrate between network and tty opens */
38275 spin_lock_irqsave(&info->netlock, flags);
38276 - if (info->port.count != 0 || info->netcount != 0) {
38277 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38278 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38279 spin_unlock_irqrestore(&info->netlock, flags);
38280 return -EBUSY;
38281 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38282 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38283
38284 /* return error if TTY interface open */
38285 - if (info->port.count)
38286 + if (atomic_read(&info->port.count))
38287 return -EBUSY;
38288
38289 if (cmd != SIOCWANDEV)
38290 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38291 * do not request bottom half processing if the
38292 * device is not open in a normal mode.
38293 */
38294 - if ( port && (port->port.count || port->netcount) &&
38295 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38296 port->pending_bh && !port->bh_running &&
38297 !port->bh_requested ) {
38298 if ( debug_level >= DEBUG_LEVEL_ISR )
38299 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38300
38301 if (debug_level >= DEBUG_LEVEL_INFO)
38302 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38303 - __FILE__,__LINE__, tty->driver->name, port->count );
38304 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38305
38306 spin_lock_irqsave(&info->lock, flags);
38307 if (!tty_hung_up_p(filp)) {
38308 extra_count = true;
38309 - port->count--;
38310 + atomic_dec(&port->count);
38311 }
38312 spin_unlock_irqrestore(&info->lock, flags);
38313 port->blocked_open++;
38314 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38315
38316 if (debug_level >= DEBUG_LEVEL_INFO)
38317 printk("%s(%d):%s block_til_ready() count=%d\n",
38318 - __FILE__,__LINE__, tty->driver->name, port->count );
38319 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38320
38321 tty_unlock();
38322 schedule();
38323 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38324 remove_wait_queue(&port->open_wait, &wait);
38325
38326 if (extra_count)
38327 - port->count++;
38328 + atomic_inc(&port->count);
38329 port->blocked_open--;
38330
38331 if (debug_level >= DEBUG_LEVEL_INFO)
38332 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38333 - __FILE__,__LINE__, tty->driver->name, port->count );
38334 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38335
38336 if (!retval)
38337 port->flags |= ASYNC_NORMAL_ACTIVE;
38338 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38339 index 05728894..b9d44c6 100644
38340 --- a/drivers/tty/sysrq.c
38341 +++ b/drivers/tty/sysrq.c
38342 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38343 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38344 size_t count, loff_t *ppos)
38345 {
38346 - if (count) {
38347 + if (count && capable(CAP_SYS_ADMIN)) {
38348 char c;
38349
38350 if (get_user(c, buf))
38351 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38352 index b425c79..08a3f06 100644
38353 --- a/drivers/tty/tty_io.c
38354 +++ b/drivers/tty/tty_io.c
38355 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38356
38357 void tty_default_fops(struct file_operations *fops)
38358 {
38359 - *fops = tty_fops;
38360 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38361 }
38362
38363 /*
38364 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38365 index 9911eb6..5abe0e1 100644
38366 --- a/drivers/tty/tty_ldisc.c
38367 +++ b/drivers/tty/tty_ldisc.c
38368 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38369 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38370 struct tty_ldisc_ops *ldo = ld->ops;
38371
38372 - ldo->refcount--;
38373 + atomic_dec(&ldo->refcount);
38374 module_put(ldo->owner);
38375 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38376
38377 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38378 spin_lock_irqsave(&tty_ldisc_lock, flags);
38379 tty_ldiscs[disc] = new_ldisc;
38380 new_ldisc->num = disc;
38381 - new_ldisc->refcount = 0;
38382 + atomic_set(&new_ldisc->refcount, 0);
38383 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38384
38385 return ret;
38386 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38387 return -EINVAL;
38388
38389 spin_lock_irqsave(&tty_ldisc_lock, flags);
38390 - if (tty_ldiscs[disc]->refcount)
38391 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38392 ret = -EBUSY;
38393 else
38394 tty_ldiscs[disc] = NULL;
38395 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38396 if (ldops) {
38397 ret = ERR_PTR(-EAGAIN);
38398 if (try_module_get(ldops->owner)) {
38399 - ldops->refcount++;
38400 + atomic_inc(&ldops->refcount);
38401 ret = ldops;
38402 }
38403 }
38404 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38405 unsigned long flags;
38406
38407 spin_lock_irqsave(&tty_ldisc_lock, flags);
38408 - ldops->refcount--;
38409 + atomic_dec(&ldops->refcount);
38410 module_put(ldops->owner);
38411 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38412 }
38413 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38414 index bf6e238..d401c04 100644
38415 --- a/drivers/tty/tty_port.c
38416 +++ b/drivers/tty/tty_port.c
38417 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38418 unsigned long flags;
38419
38420 spin_lock_irqsave(&port->lock, flags);
38421 - port->count = 0;
38422 + atomic_set(&port->count, 0);
38423 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38424 if (port->tty) {
38425 set_bit(TTY_IO_ERROR, &port->tty->flags);
38426 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38427 /* The port lock protects the port counts */
38428 spin_lock_irqsave(&port->lock, flags);
38429 if (!tty_hung_up_p(filp))
38430 - port->count--;
38431 + atomic_dec(&port->count);
38432 port->blocked_open++;
38433 spin_unlock_irqrestore(&port->lock, flags);
38434
38435 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38436 we must not mess that up further */
38437 spin_lock_irqsave(&port->lock, flags);
38438 if (!tty_hung_up_p(filp))
38439 - port->count++;
38440 + atomic_inc(&port->count);
38441 port->blocked_open--;
38442 if (retval == 0)
38443 port->flags |= ASYNC_NORMAL_ACTIVE;
38444 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38445 return 0;
38446 }
38447
38448 - if (tty->count == 1 && port->count != 1) {
38449 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38450 printk(KERN_WARNING
38451 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38452 - port->count);
38453 - port->count = 1;
38454 + atomic_read(&port->count));
38455 + atomic_set(&port->count, 1);
38456 }
38457 - if (--port->count < 0) {
38458 + if (atomic_dec_return(&port->count) < 0) {
38459 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38460 - port->count);
38461 - port->count = 0;
38462 + atomic_read(&port->count));
38463 + atomic_set(&port->count, 0);
38464 }
38465
38466 - if (port->count) {
38467 + if (atomic_read(&port->count)) {
38468 spin_unlock_irqrestore(&port->lock, flags);
38469 if (port->ops->drop)
38470 port->ops->drop(port);
38471 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38472 {
38473 spin_lock_irq(&port->lock);
38474 if (!tty_hung_up_p(filp))
38475 - ++port->count;
38476 + atomic_inc(&port->count);
38477 spin_unlock_irq(&port->lock);
38478 tty_port_tty_set(port, tty);
38479
38480 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38481 index 48cc6f2..85584dd 100644
38482 --- a/drivers/tty/vt/keyboard.c
38483 +++ b/drivers/tty/vt/keyboard.c
38484 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38485 kbd->kbdmode == VC_OFF) &&
38486 value != KVAL(K_SAK))
38487 return; /* SAK is allowed even in raw mode */
38488 +
38489 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38490 + {
38491 + void *func = fn_handler[value];
38492 + if (func == fn_show_state || func == fn_show_ptregs ||
38493 + func == fn_show_mem)
38494 + return;
38495 + }
38496 +#endif
38497 +
38498 fn_handler[value](vc);
38499 }
38500
38501 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38502 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38503 return -EFAULT;
38504
38505 - if (!capable(CAP_SYS_TTY_CONFIG))
38506 - perm = 0;
38507 -
38508 switch (cmd) {
38509 case KDGKBENT:
38510 /* Ensure another thread doesn't free it under us */
38511 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38512 spin_unlock_irqrestore(&kbd_event_lock, flags);
38513 return put_user(val, &user_kbe->kb_value);
38514 case KDSKBENT:
38515 + if (!capable(CAP_SYS_TTY_CONFIG))
38516 + perm = 0;
38517 +
38518 if (!perm)
38519 return -EPERM;
38520 if (!i && v == K_NOSUCHMAP) {
38521 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38522 int i, j, k;
38523 int ret;
38524
38525 - if (!capable(CAP_SYS_TTY_CONFIG))
38526 - perm = 0;
38527 -
38528 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38529 if (!kbs) {
38530 ret = -ENOMEM;
38531 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38532 kfree(kbs);
38533 return ((p && *p) ? -EOVERFLOW : 0);
38534 case KDSKBSENT:
38535 + if (!capable(CAP_SYS_TTY_CONFIG))
38536 + perm = 0;
38537 +
38538 if (!perm) {
38539 ret = -EPERM;
38540 goto reterr;
38541 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38542 index a783d53..cb30d94 100644
38543 --- a/drivers/uio/uio.c
38544 +++ b/drivers/uio/uio.c
38545 @@ -25,6 +25,7 @@
38546 #include <linux/kobject.h>
38547 #include <linux/cdev.h>
38548 #include <linux/uio_driver.h>
38549 +#include <asm/local.h>
38550
38551 #define UIO_MAX_DEVICES (1U << MINORBITS)
38552
38553 @@ -32,10 +33,10 @@ struct uio_device {
38554 struct module *owner;
38555 struct device *dev;
38556 int minor;
38557 - atomic_t event;
38558 + atomic_unchecked_t event;
38559 struct fasync_struct *async_queue;
38560 wait_queue_head_t wait;
38561 - int vma_count;
38562 + local_t vma_count;
38563 struct uio_info *info;
38564 struct kobject *map_dir;
38565 struct kobject *portio_dir;
38566 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38567 struct device_attribute *attr, char *buf)
38568 {
38569 struct uio_device *idev = dev_get_drvdata(dev);
38570 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38571 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38572 }
38573
38574 static struct device_attribute uio_class_attributes[] = {
38575 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38576 {
38577 struct uio_device *idev = info->uio_dev;
38578
38579 - atomic_inc(&idev->event);
38580 + atomic_inc_unchecked(&idev->event);
38581 wake_up_interruptible(&idev->wait);
38582 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38583 }
38584 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38585 }
38586
38587 listener->dev = idev;
38588 - listener->event_count = atomic_read(&idev->event);
38589 + listener->event_count = atomic_read_unchecked(&idev->event);
38590 filep->private_data = listener;
38591
38592 if (idev->info->open) {
38593 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38594 return -EIO;
38595
38596 poll_wait(filep, &idev->wait, wait);
38597 - if (listener->event_count != atomic_read(&idev->event))
38598 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38599 return POLLIN | POLLRDNORM;
38600 return 0;
38601 }
38602 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38603 do {
38604 set_current_state(TASK_INTERRUPTIBLE);
38605
38606 - event_count = atomic_read(&idev->event);
38607 + event_count = atomic_read_unchecked(&idev->event);
38608 if (event_count != listener->event_count) {
38609 if (copy_to_user(buf, &event_count, count))
38610 retval = -EFAULT;
38611 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38612 static void uio_vma_open(struct vm_area_struct *vma)
38613 {
38614 struct uio_device *idev = vma->vm_private_data;
38615 - idev->vma_count++;
38616 + local_inc(&idev->vma_count);
38617 }
38618
38619 static void uio_vma_close(struct vm_area_struct *vma)
38620 {
38621 struct uio_device *idev = vma->vm_private_data;
38622 - idev->vma_count--;
38623 + local_dec(&idev->vma_count);
38624 }
38625
38626 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38627 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38628 idev->owner = owner;
38629 idev->info = info;
38630 init_waitqueue_head(&idev->wait);
38631 - atomic_set(&idev->event, 0);
38632 + atomic_set_unchecked(&idev->event, 0);
38633
38634 ret = uio_get_minor(idev);
38635 if (ret)
38636 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38637 index b7eb86a..36d28af 100644
38638 --- a/drivers/usb/atm/cxacru.c
38639 +++ b/drivers/usb/atm/cxacru.c
38640 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38641 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38642 if (ret < 2)
38643 return -EINVAL;
38644 - if (index < 0 || index > 0x7f)
38645 + if (index > 0x7f)
38646 return -EINVAL;
38647 pos += tmp;
38648
38649 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38650 index ee62b35..b663594 100644
38651 --- a/drivers/usb/atm/usbatm.c
38652 +++ b/drivers/usb/atm/usbatm.c
38653 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38654 if (printk_ratelimit())
38655 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38656 __func__, vpi, vci);
38657 - atomic_inc(&vcc->stats->rx_err);
38658 + atomic_inc_unchecked(&vcc->stats->rx_err);
38659 return;
38660 }
38661
38662 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38663 if (length > ATM_MAX_AAL5_PDU) {
38664 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38665 __func__, length, vcc);
38666 - atomic_inc(&vcc->stats->rx_err);
38667 + atomic_inc_unchecked(&vcc->stats->rx_err);
38668 goto out;
38669 }
38670
38671 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38672 if (sarb->len < pdu_length) {
38673 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38674 __func__, pdu_length, sarb->len, vcc);
38675 - atomic_inc(&vcc->stats->rx_err);
38676 + atomic_inc_unchecked(&vcc->stats->rx_err);
38677 goto out;
38678 }
38679
38680 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38681 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38682 __func__, vcc);
38683 - atomic_inc(&vcc->stats->rx_err);
38684 + atomic_inc_unchecked(&vcc->stats->rx_err);
38685 goto out;
38686 }
38687
38688 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38689 if (printk_ratelimit())
38690 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38691 __func__, length);
38692 - atomic_inc(&vcc->stats->rx_drop);
38693 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38694 goto out;
38695 }
38696
38697 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38698
38699 vcc->push(vcc, skb);
38700
38701 - atomic_inc(&vcc->stats->rx);
38702 + atomic_inc_unchecked(&vcc->stats->rx);
38703 out:
38704 skb_trim(sarb, 0);
38705 }
38706 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38707 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38708
38709 usbatm_pop(vcc, skb);
38710 - atomic_inc(&vcc->stats->tx);
38711 + atomic_inc_unchecked(&vcc->stats->tx);
38712
38713 skb = skb_dequeue(&instance->sndqueue);
38714 }
38715 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38716 if (!left--)
38717 return sprintf(page,
38718 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38719 - atomic_read(&atm_dev->stats.aal5.tx),
38720 - atomic_read(&atm_dev->stats.aal5.tx_err),
38721 - atomic_read(&atm_dev->stats.aal5.rx),
38722 - atomic_read(&atm_dev->stats.aal5.rx_err),
38723 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38724 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38725 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38726 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38727 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38728 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38729
38730 if (!left--) {
38731 if (instance->disconnected)
38732 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38733 index d956965..4179a77 100644
38734 --- a/drivers/usb/core/devices.c
38735 +++ b/drivers/usb/core/devices.c
38736 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38737 * time it gets called.
38738 */
38739 static struct device_connect_event {
38740 - atomic_t count;
38741 + atomic_unchecked_t count;
38742 wait_queue_head_t wait;
38743 } device_event = {
38744 .count = ATOMIC_INIT(1),
38745 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38746
38747 void usbfs_conn_disc_event(void)
38748 {
38749 - atomic_add(2, &device_event.count);
38750 + atomic_add_unchecked(2, &device_event.count);
38751 wake_up(&device_event.wait);
38752 }
38753
38754 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38755
38756 poll_wait(file, &device_event.wait, wait);
38757
38758 - event_count = atomic_read(&device_event.count);
38759 + event_count = atomic_read_unchecked(&device_event.count);
38760 if (file->f_version != event_count) {
38761 file->f_version = event_count;
38762 return POLLIN | POLLRDNORM;
38763 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38764 index 1fc8f12..20647c1 100644
38765 --- a/drivers/usb/early/ehci-dbgp.c
38766 +++ b/drivers/usb/early/ehci-dbgp.c
38767 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38768
38769 #ifdef CONFIG_KGDB
38770 static struct kgdb_io kgdbdbgp_io_ops;
38771 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38772 +static struct kgdb_io kgdbdbgp_io_ops_console;
38773 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38774 #else
38775 #define dbgp_kgdb_mode (0)
38776 #endif
38777 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38778 .write_char = kgdbdbgp_write_char,
38779 };
38780
38781 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38782 + .name = "kgdbdbgp",
38783 + .read_char = kgdbdbgp_read_char,
38784 + .write_char = kgdbdbgp_write_char,
38785 + .is_console = 1
38786 +};
38787 +
38788 static int kgdbdbgp_wait_time;
38789
38790 static int __init kgdbdbgp_parse_config(char *str)
38791 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38792 ptr++;
38793 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38794 }
38795 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38796 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38797 + if (early_dbgp_console.index != -1)
38798 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38799 + else
38800 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38801
38802 return 0;
38803 }
38804 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38805 index 5b3f5ff..6e00893 100644
38806 --- a/drivers/usb/gadget/u_serial.c
38807 +++ b/drivers/usb/gadget/u_serial.c
38808 @@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38809 spin_lock_irq(&port->port_lock);
38810
38811 /* already open? Great. */
38812 - if (port->port.count) {
38813 + if (atomic_read(&port->port.count)) {
38814 status = 0;
38815 - port->port.count++;
38816 + atomic_inc(&port->port.count);
38817
38818 /* currently opening/closing? wait ... */
38819 } else if (port->openclose) {
38820 @@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38821 tty->driver_data = port;
38822 port->port.tty = tty;
38823
38824 - port->port.count = 1;
38825 + atomic_set(&port->port.count, 1);
38826 port->openclose = false;
38827
38828 /* if connected, start the I/O stream */
38829 @@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38830
38831 spin_lock_irq(&port->port_lock);
38832
38833 - if (port->port.count != 1) {
38834 - if (port->port.count == 0)
38835 + if (atomic_read(&port->port.count) != 1) {
38836 + if (atomic_read(&port->port.count) == 0)
38837 WARN_ON(1);
38838 else
38839 - --port->port.count;
38840 + atomic_dec(&port->port.count);
38841 goto exit;
38842 }
38843
38844 @@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38845 * and sleep if necessary
38846 */
38847 port->openclose = true;
38848 - port->port.count = 0;
38849 + atomic_set(&port->port.count, 0);
38850
38851 gser = port->port_usb;
38852 if (gser && gser->disconnect)
38853 @@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38854 int cond;
38855
38856 spin_lock_irq(&port->port_lock);
38857 - cond = (port->port.count == 0) && !port->openclose;
38858 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38859 spin_unlock_irq(&port->port_lock);
38860 return cond;
38861 }
38862 @@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38863 /* if it's already open, start I/O ... and notify the serial
38864 * protocol about open/close status (connect/disconnect).
38865 */
38866 - if (port->port.count) {
38867 + if (atomic_read(&port->port.count)) {
38868 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38869 gs_start_io(port);
38870 if (gser->connect)
38871 @@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38872
38873 port->port_usb = NULL;
38874 gser->ioport = NULL;
38875 - if (port->port.count > 0 || port->openclose) {
38876 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
38877 wake_up_interruptible(&port->drain_wait);
38878 if (port->port.tty)
38879 tty_hangup(port->port.tty);
38880 @@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38881
38882 /* finally, free any unused/unusable I/O buffers */
38883 spin_lock_irqsave(&port->port_lock, flags);
38884 - if (port->port.count == 0 && !port->openclose)
38885 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
38886 gs_buf_free(&port->port_write_buf);
38887 gs_free_requests(gser->out, &port->read_pool, NULL);
38888 gs_free_requests(gser->out, &port->read_queue, NULL);
38889 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38890 index b9cca6d..75c75df 100644
38891 --- a/drivers/usb/serial/console.c
38892 +++ b/drivers/usb/serial/console.c
38893 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38894
38895 info->port = port;
38896
38897 - ++port->port.count;
38898 + atomic_inc(&port->port.count);
38899 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38900 if (serial->type->set_termios) {
38901 /*
38902 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38903 }
38904 /* Now that any required fake tty operations are completed restore
38905 * the tty port count */
38906 - --port->port.count;
38907 + atomic_dec(&port->port.count);
38908 /* The console is special in terms of closing the device so
38909 * indicate this port is now acting as a system console. */
38910 port->port.console = 1;
38911 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38912 free_tty:
38913 kfree(tty);
38914 reset_open_count:
38915 - port->port.count = 0;
38916 + atomic_set(&port->port.count, 0);
38917 usb_autopm_put_interface(serial->interface);
38918 error_get_interface:
38919 usb_serial_put(serial);
38920 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38921 index d6bea3e..60b250e 100644
38922 --- a/drivers/usb/wusbcore/wa-hc.h
38923 +++ b/drivers/usb/wusbcore/wa-hc.h
38924 @@ -192,7 +192,7 @@ struct wahc {
38925 struct list_head xfer_delayed_list;
38926 spinlock_t xfer_list_lock;
38927 struct work_struct xfer_work;
38928 - atomic_t xfer_id_count;
38929 + atomic_unchecked_t xfer_id_count;
38930 };
38931
38932
38933 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38934 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38935 spin_lock_init(&wa->xfer_list_lock);
38936 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38937 - atomic_set(&wa->xfer_id_count, 1);
38938 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38939 }
38940
38941 /**
38942 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38943 index 57c01ab..8a05959 100644
38944 --- a/drivers/usb/wusbcore/wa-xfer.c
38945 +++ b/drivers/usb/wusbcore/wa-xfer.c
38946 @@ -296,7 +296,7 @@ out:
38947 */
38948 static void wa_xfer_id_init(struct wa_xfer *xfer)
38949 {
38950 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38951 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38952 }
38953
38954 /*
38955 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38956 index 112156f..eb81154 100644
38957 --- a/drivers/vhost/vhost.c
38958 +++ b/drivers/vhost/vhost.c
38959 @@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38960 return 0;
38961 }
38962
38963 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38964 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38965 {
38966 struct file *eventfp, *filep = NULL,
38967 *pollstart = NULL, *pollstop = NULL;
38968 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38969 index b0b2ac3..89a4399 100644
38970 --- a/drivers/video/aty/aty128fb.c
38971 +++ b/drivers/video/aty/aty128fb.c
38972 @@ -148,7 +148,7 @@ enum {
38973 };
38974
38975 /* Must match above enum */
38976 -static const char *r128_family[] __devinitdata = {
38977 +static const char *r128_family[] __devinitconst = {
38978 "AGP",
38979 "PCI",
38980 "PRO AGP",
38981 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38982 index 5c3960d..15cf8fc 100644
38983 --- a/drivers/video/fbcmap.c
38984 +++ b/drivers/video/fbcmap.c
38985 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38986 rc = -ENODEV;
38987 goto out;
38988 }
38989 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38990 - !info->fbops->fb_setcmap)) {
38991 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38992 rc = -EINVAL;
38993 goto out1;
38994 }
38995 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38996 index 0dff12a..2ef47b3 100644
38997 --- a/drivers/video/fbmem.c
38998 +++ b/drivers/video/fbmem.c
38999 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39000 image->dx += image->width + 8;
39001 }
39002 } else if (rotate == FB_ROTATE_UD) {
39003 - for (x = 0; x < num && image->dx >= 0; x++) {
39004 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39005 info->fbops->fb_imageblit(info, image);
39006 image->dx -= image->width + 8;
39007 }
39008 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39009 image->dy += image->height + 8;
39010 }
39011 } else if (rotate == FB_ROTATE_CCW) {
39012 - for (x = 0; x < num && image->dy >= 0; x++) {
39013 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39014 info->fbops->fb_imageblit(info, image);
39015 image->dy -= image->height + 8;
39016 }
39017 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39018 return -EFAULT;
39019 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39020 return -EINVAL;
39021 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39022 + if (con2fb.framebuffer >= FB_MAX)
39023 return -EINVAL;
39024 if (!registered_fb[con2fb.framebuffer])
39025 request_module("fb%d", con2fb.framebuffer);
39026 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39027 index 5a5d092..265c5ed 100644
39028 --- a/drivers/video/geode/gx1fb_core.c
39029 +++ b/drivers/video/geode/gx1fb_core.c
39030 @@ -29,7 +29,7 @@ static int crt_option = 1;
39031 static char panel_option[32] = "";
39032
39033 /* Modes relevant to the GX1 (taken from modedb.c) */
39034 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39035 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39036 /* 640x480-60 VESA */
39037 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39038 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39039 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39040 index 0fad23f..0e9afa4 100644
39041 --- a/drivers/video/gxt4500.c
39042 +++ b/drivers/video/gxt4500.c
39043 @@ -156,7 +156,7 @@ struct gxt4500_par {
39044 static char *mode_option;
39045
39046 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39047 -static const struct fb_videomode defaultmode __devinitdata = {
39048 +static const struct fb_videomode defaultmode __devinitconst = {
39049 .refresh = 60,
39050 .xres = 1280,
39051 .yres = 1024,
39052 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39053 return 0;
39054 }
39055
39056 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39057 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39058 .id = "IBM GXT4500P",
39059 .type = FB_TYPE_PACKED_PIXELS,
39060 .visual = FB_VISUAL_PSEUDOCOLOR,
39061 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39062 index 7672d2e..b56437f 100644
39063 --- a/drivers/video/i810/i810_accel.c
39064 +++ b/drivers/video/i810/i810_accel.c
39065 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39066 }
39067 }
39068 printk("ringbuffer lockup!!!\n");
39069 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39070 i810_report_error(mmio);
39071 par->dev_flags |= LOCKUP;
39072 info->pixmap.scan_align = 1;
39073 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39074 index b83f361..2b05a91 100644
39075 --- a/drivers/video/i810/i810_main.c
39076 +++ b/drivers/video/i810/i810_main.c
39077 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39078 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39079
39080 /* PCI */
39081 -static const char *i810_pci_list[] __devinitdata = {
39082 +static const char *i810_pci_list[] __devinitconst = {
39083 "Intel(R) 810 Framebuffer Device" ,
39084 "Intel(R) 810-DC100 Framebuffer Device" ,
39085 "Intel(R) 810E Framebuffer Device" ,
39086 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39087 index de36693..3c63fc2 100644
39088 --- a/drivers/video/jz4740_fb.c
39089 +++ b/drivers/video/jz4740_fb.c
39090 @@ -136,7 +136,7 @@ struct jzfb {
39091 uint32_t pseudo_palette[16];
39092 };
39093
39094 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39095 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39096 .id = "JZ4740 FB",
39097 .type = FB_TYPE_PACKED_PIXELS,
39098 .visual = FB_VISUAL_TRUECOLOR,
39099 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39100 index 3c14e43..eafa544 100644
39101 --- a/drivers/video/logo/logo_linux_clut224.ppm
39102 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39103 @@ -1,1604 +1,1123 @@
39104 P3
39105 -# Standard 224-color Linux logo
39106 80 80
39107 255
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 0 0 0 0 0 0
39110 - 0 0 0 0 0 0 0 0 0 0 0 0
39111 - 0 0 0 0 0 0 0 0 0 0 0 0
39112 - 0 0 0 0 0 0 0 0 0 0 0 0
39113 - 0 0 0 0 0 0 0 0 0 0 0 0
39114 - 0 0 0 0 0 0 0 0 0 0 0 0
39115 - 0 0 0 0 0 0 0 0 0 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 0 0 0
39117 - 6 6 6 6 6 6 10 10 10 10 10 10
39118 - 10 10 10 6 6 6 6 6 6 6 6 6
39119 - 0 0 0 0 0 0 0 0 0 0 0 0
39120 - 0 0 0 0 0 0 0 0 0 0 0 0
39121 - 0 0 0 0 0 0 0 0 0 0 0 0
39122 - 0 0 0 0 0 0 0 0 0 0 0 0
39123 - 0 0 0 0 0 0 0 0 0 0 0 0
39124 - 0 0 0 0 0 0 0 0 0 0 0 0
39125 - 0 0 0 0 0 0 0 0 0 0 0 0
39126 - 0 0 0 0 0 0 0 0 0 0 0 0
39127 - 0 0 0 0 0 0 0 0 0 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 0 0 0
39130 - 0 0 0 0 0 0 0 0 0 0 0 0
39131 - 0 0 0 0 0 0 0 0 0 0 0 0
39132 - 0 0 0 0 0 0 0 0 0 0 0 0
39133 - 0 0 0 0 0 0 0 0 0 0 0 0
39134 - 0 0 0 0 0 0 0 0 0 0 0 0
39135 - 0 0 0 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 6 6 6 10 10 10 14 14 14
39137 - 22 22 22 26 26 26 30 30 30 34 34 34
39138 - 30 30 30 30 30 30 26 26 26 18 18 18
39139 - 14 14 14 10 10 10 6 6 6 0 0 0
39140 - 0 0 0 0 0 0 0 0 0 0 0 0
39141 - 0 0 0 0 0 0 0 0 0 0 0 0
39142 - 0 0 0 0 0 0 0 0 0 0 0 0
39143 - 0 0 0 0 0 0 0 0 0 0 0 0
39144 - 0 0 0 0 0 0 0 0 0 0 0 0
39145 - 0 0 0 0 0 0 0 0 0 0 0 0
39146 - 0 0 0 0 0 0 0 0 0 0 0 0
39147 - 0 0 0 0 0 0 0 0 0 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 0 0 0 0 0 1 0 0 1 0 0 0
39150 - 0 0 0 0 0 0 0 0 0 0 0 0
39151 - 0 0 0 0 0 0 0 0 0 0 0 0
39152 - 0 0 0 0 0 0 0 0 0 0 0 0
39153 - 0 0 0 0 0 0 0 0 0 0 0 0
39154 - 0 0 0 0 0 0 0 0 0 0 0 0
39155 - 0 0 0 0 0 0 0 0 0 0 0 0
39156 - 6 6 6 14 14 14 26 26 26 42 42 42
39157 - 54 54 54 66 66 66 78 78 78 78 78 78
39158 - 78 78 78 74 74 74 66 66 66 54 54 54
39159 - 42 42 42 26 26 26 18 18 18 10 10 10
39160 - 6 6 6 0 0 0 0 0 0 0 0 0
39161 - 0 0 0 0 0 0 0 0 0 0 0 0
39162 - 0 0 0 0 0 0 0 0 0 0 0 0
39163 - 0 0 0 0 0 0 0 0 0 0 0 0
39164 - 0 0 0 0 0 0 0 0 0 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 1 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 0 0 0
39175 - 0 0 0 0 0 0 0 0 0 10 10 10
39176 - 22 22 22 42 42 42 66 66 66 86 86 86
39177 - 66 66 66 38 38 38 38 38 38 22 22 22
39178 - 26 26 26 34 34 34 54 54 54 66 66 66
39179 - 86 86 86 70 70 70 46 46 46 26 26 26
39180 - 14 14 14 6 6 6 0 0 0 0 0 0
39181 - 0 0 0 0 0 0 0 0 0 0 0 0
39182 - 0 0 0 0 0 0 0 0 0 0 0 0
39183 - 0 0 0 0 0 0 0 0 0 0 0 0
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 1 0 0 1 0 0 1 0 0 0
39190 - 0 0 0 0 0 0 0 0 0 0 0 0
39191 - 0 0 0 0 0 0 0 0 0 0 0 0
39192 - 0 0 0 0 0 0 0 0 0 0 0 0
39193 - 0 0 0 0 0 0 0 0 0 0 0 0
39194 - 0 0 0 0 0 0 0 0 0 0 0 0
39195 - 0 0 0 0 0 0 10 10 10 26 26 26
39196 - 50 50 50 82 82 82 58 58 58 6 6 6
39197 - 2 2 6 2 2 6 2 2 6 2 2 6
39198 - 2 2 6 2 2 6 2 2 6 2 2 6
39199 - 6 6 6 54 54 54 86 86 86 66 66 66
39200 - 38 38 38 18 18 18 6 6 6 0 0 0
39201 - 0 0 0 0 0 0 0 0 0 0 0 0
39202 - 0 0 0 0 0 0 0 0 0 0 0 0
39203 - 0 0 0 0 0 0 0 0 0 0 0 0
39204 - 0 0 0 0 0 0 0 0 0 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39214 - 0 0 0 0 0 0 0 0 0 0 0 0
39215 - 0 0 0 6 6 6 22 22 22 50 50 50
39216 - 78 78 78 34 34 34 2 2 6 2 2 6
39217 - 2 2 6 2 2 6 2 2 6 2 2 6
39218 - 2 2 6 2 2 6 2 2 6 2 2 6
39219 - 2 2 6 2 2 6 6 6 6 70 70 70
39220 - 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 0 0 0
39234 - 0 0 0 0 0 0 0 0 0 0 0 0
39235 - 6 6 6 18 18 18 42 42 42 82 82 82
39236 - 26 26 26 2 2 6 2 2 6 2 2 6
39237 - 2 2 6 2 2 6 2 2 6 2 2 6
39238 - 2 2 6 2 2 6 2 2 6 14 14 14
39239 - 46 46 46 34 34 34 6 6 6 2 2 6
39240 - 42 42 42 78 78 78 42 42 42 18 18 18
39241 - 6 6 6 0 0 0 0 0 0 0 0 0
39242 - 0 0 0 0 0 0 0 0 0 0 0 0
39243 - 0 0 0 0 0 0 0 0 0 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 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 1 0 0 0 0 0 1 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 0 0 0
39254 - 0 0 0 0 0 0 0 0 0 0 0 0
39255 - 10 10 10 30 30 30 66 66 66 58 58 58
39256 - 2 2 6 2 2 6 2 2 6 2 2 6
39257 - 2 2 6 2 2 6 2 2 6 2 2 6
39258 - 2 2 6 2 2 6 2 2 6 26 26 26
39259 - 86 86 86 101 101 101 46 46 46 10 10 10
39260 - 2 2 6 58 58 58 70 70 70 34 34 34
39261 - 10 10 10 0 0 0 0 0 0 0 0 0
39262 - 0 0 0 0 0 0 0 0 0 0 0 0
39263 - 0 0 0 0 0 0 0 0 0 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 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 1 0 0 1 0 0 1 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 0 0 0
39272 - 0 0 0 0 0 0 0 0 0 0 0 0
39273 - 0 0 0 0 0 0 0 0 0 0 0 0
39274 - 0 0 0 0 0 0 0 0 0 0 0 0
39275 - 14 14 14 42 42 42 86 86 86 10 10 10
39276 - 2 2 6 2 2 6 2 2 6 2 2 6
39277 - 2 2 6 2 2 6 2 2 6 2 2 6
39278 - 2 2 6 2 2 6 2 2 6 30 30 30
39279 - 94 94 94 94 94 94 58 58 58 26 26 26
39280 - 2 2 6 6 6 6 78 78 78 54 54 54
39281 - 22 22 22 6 6 6 0 0 0 0 0 0
39282 - 0 0 0 0 0 0 0 0 0 0 0 0
39283 - 0 0 0 0 0 0 0 0 0 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 0 0 0
39293 - 0 0 0 0 0 0 0 0 0 0 0 0
39294 - 0 0 0 0 0 0 0 0 0 6 6 6
39295 - 22 22 22 62 62 62 62 62 62 2 2 6
39296 - 2 2 6 2 2 6 2 2 6 2 2 6
39297 - 2 2 6 2 2 6 2 2 6 2 2 6
39298 - 2 2 6 2 2 6 2 2 6 26 26 26
39299 - 54 54 54 38 38 38 18 18 18 10 10 10
39300 - 2 2 6 2 2 6 34 34 34 82 82 82
39301 - 38 38 38 14 14 14 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 1 0 0 1 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 0 0 0 0 0 0 0 0 0
39312 - 0 0 0 0 0 0 0 0 0 0 0 0
39313 - 0 0 0 0 0 0 0 0 0 0 0 0
39314 - 0 0 0 0 0 0 0 0 0 6 6 6
39315 - 30 30 30 78 78 78 30 30 30 2 2 6
39316 - 2 2 6 2 2 6 2 2 6 2 2 6
39317 - 2 2 6 2 2 6 2 2 6 2 2 6
39318 - 2 2 6 2 2 6 2 2 6 10 10 10
39319 - 10 10 10 2 2 6 2 2 6 2 2 6
39320 - 2 2 6 2 2 6 2 2 6 78 78 78
39321 - 50 50 50 18 18 18 6 6 6 0 0 0
39322 - 0 0 0 0 0 0 0 0 0 0 0 0
39323 - 0 0 0 0 0 0 0 0 0 0 0 0
39324 - 0 0 0 0 0 0 0 0 0 0 0 0
39325 - 0 0 0 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 1 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 0 0 0 0 0 0 0 0 0
39333 - 0 0 0 0 0 0 0 0 0 0 0 0
39334 - 0 0 0 0 0 0 0 0 0 10 10 10
39335 - 38 38 38 86 86 86 14 14 14 2 2 6
39336 - 2 2 6 2 2 6 2 2 6 2 2 6
39337 - 2 2 6 2 2 6 2 2 6 2 2 6
39338 - 2 2 6 2 2 6 2 2 6 2 2 6
39339 - 2 2 6 2 2 6 2 2 6 2 2 6
39340 - 2 2 6 2 2 6 2 2 6 54 54 54
39341 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 1 0 0 1 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 0 0 0 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 0 0 0 0 0 0 0 0 0
39354 - 0 0 0 0 0 0 0 0 0 14 14 14
39355 - 42 42 42 82 82 82 2 2 6 2 2 6
39356 - 2 2 6 6 6 6 10 10 10 2 2 6
39357 - 2 2 6 2 2 6 2 2 6 2 2 6
39358 - 2 2 6 2 2 6 2 2 6 6 6 6
39359 - 14 14 14 10 10 10 2 2 6 2 2 6
39360 - 2 2 6 2 2 6 2 2 6 18 18 18
39361 - 82 82 82 34 34 34 10 10 10 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 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 1 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 0 0 0
39374 - 0 0 0 0 0 0 0 0 0 14 14 14
39375 - 46 46 46 86 86 86 2 2 6 2 2 6
39376 - 6 6 6 6 6 6 22 22 22 34 34 34
39377 - 6 6 6 2 2 6 2 2 6 2 2 6
39378 - 2 2 6 2 2 6 18 18 18 34 34 34
39379 - 10 10 10 50 50 50 22 22 22 2 2 6
39380 - 2 2 6 2 2 6 2 2 6 10 10 10
39381 - 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 0 0 0
39391 - 0 0 0 0 0 0 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 0 0 0 0 0 0
39394 - 0 0 0 0 0 0 0 0 0 14 14 14
39395 - 46 46 46 86 86 86 2 2 6 2 2 6
39396 - 38 38 38 116 116 116 94 94 94 22 22 22
39397 - 22 22 22 2 2 6 2 2 6 2 2 6
39398 - 14 14 14 86 86 86 138 138 138 162 162 162
39399 -154 154 154 38 38 38 26 26 26 6 6 6
39400 - 2 2 6 2 2 6 2 2 6 2 2 6
39401 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 0 0 0 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 - 0 0 0 0 0 0 0 0 0 0 0 0
39410 - 0 0 0 0 0 0 0 0 0 0 0 0
39411 - 0 0 0 0 0 0 0 0 0 0 0 0
39412 - 0 0 0 0 0 0 0 0 0 0 0 0
39413 - 0 0 0 0 0 0 0 0 0 0 0 0
39414 - 0 0 0 0 0 0 0 0 0 14 14 14
39415 - 46 46 46 86 86 86 2 2 6 14 14 14
39416 -134 134 134 198 198 198 195 195 195 116 116 116
39417 - 10 10 10 2 2 6 2 2 6 6 6 6
39418 -101 98 89 187 187 187 210 210 210 218 218 218
39419 -214 214 214 134 134 134 14 14 14 6 6 6
39420 - 2 2 6 2 2 6 2 2 6 2 2 6
39421 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 0 0 0
39427 - 0 0 0 0 0 0 0 0 0 0 0 0
39428 - 0 0 0 0 0 0 0 0 1 0 0 0
39429 - 0 0 1 0 0 1 0 0 1 0 0 0
39430 - 0 0 0 0 0 0 0 0 0 0 0 0
39431 - 0 0 0 0 0 0 0 0 0 0 0 0
39432 - 0 0 0 0 0 0 0 0 0 0 0 0
39433 - 0 0 0 0 0 0 0 0 0 0 0 0
39434 - 0 0 0 0 0 0 0 0 0 14 14 14
39435 - 46 46 46 86 86 86 2 2 6 54 54 54
39436 -218 218 218 195 195 195 226 226 226 246 246 246
39437 - 58 58 58 2 2 6 2 2 6 30 30 30
39438 -210 210 210 253 253 253 174 174 174 123 123 123
39439 -221 221 221 234 234 234 74 74 74 2 2 6
39440 - 2 2 6 2 2 6 2 2 6 2 2 6
39441 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 0 0 0
39447 - 0 0 0 0 0 0 0 0 0 0 0 0
39448 - 0 0 0 0 0 0 0 0 0 0 0 0
39449 - 0 0 0 0 0 0 0 0 0 0 0 0
39450 - 0 0 0 0 0 0 0 0 0 0 0 0
39451 - 0 0 0 0 0 0 0 0 0 0 0 0
39452 - 0 0 0 0 0 0 0 0 0 0 0 0
39453 - 0 0 0 0 0 0 0 0 0 0 0 0
39454 - 0 0 0 0 0 0 0 0 0 14 14 14
39455 - 46 46 46 82 82 82 2 2 6 106 106 106
39456 -170 170 170 26 26 26 86 86 86 226 226 226
39457 -123 123 123 10 10 10 14 14 14 46 46 46
39458 -231 231 231 190 190 190 6 6 6 70 70 70
39459 - 90 90 90 238 238 238 158 158 158 2 2 6
39460 - 2 2 6 2 2 6 2 2 6 2 2 6
39461 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
39466 - 0 0 0 0 0 0 0 0 0 0 0 0
39467 - 0 0 0 0 0 0 0 0 0 0 0 0
39468 - 0 0 0 0 0 0 0 0 1 0 0 0
39469 - 0 0 1 0 0 1 0 0 1 0 0 0
39470 - 0 0 0 0 0 0 0 0 0 0 0 0
39471 - 0 0 0 0 0 0 0 0 0 0 0 0
39472 - 0 0 0 0 0 0 0 0 0 0 0 0
39473 - 0 0 0 0 0 0 0 0 0 0 0 0
39474 - 0 0 0 0 0 0 0 0 0 14 14 14
39475 - 42 42 42 86 86 86 6 6 6 116 116 116
39476 -106 106 106 6 6 6 70 70 70 149 149 149
39477 -128 128 128 18 18 18 38 38 38 54 54 54
39478 -221 221 221 106 106 106 2 2 6 14 14 14
39479 - 46 46 46 190 190 190 198 198 198 2 2 6
39480 - 2 2 6 2 2 6 2 2 6 2 2 6
39481 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 0 0 0
39488 - 0 0 0 0 0 0 0 0 1 0 0 0
39489 - 0 0 1 0 0 0 0 0 1 0 0 0
39490 - 0 0 0 0 0 0 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 0 0 0
39492 - 0 0 0 0 0 0 0 0 0 0 0 0
39493 - 0 0 0 0 0 0 0 0 0 0 0 0
39494 - 0 0 0 0 0 0 0 0 0 14 14 14
39495 - 42 42 42 94 94 94 14 14 14 101 101 101
39496 -128 128 128 2 2 6 18 18 18 116 116 116
39497 -118 98 46 121 92 8 121 92 8 98 78 10
39498 -162 162 162 106 106 106 2 2 6 2 2 6
39499 - 2 2 6 195 195 195 195 195 195 6 6 6
39500 - 2 2 6 2 2 6 2 2 6 2 2 6
39501 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
39509 - 0 0 1 0 0 0 0 0 1 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 0 0 0
39514 - 0 0 0 0 0 0 0 0 0 10 10 10
39515 - 38 38 38 90 90 90 14 14 14 58 58 58
39516 -210 210 210 26 26 26 54 38 6 154 114 10
39517 -226 170 11 236 186 11 225 175 15 184 144 12
39518 -215 174 15 175 146 61 37 26 9 2 2 6
39519 - 70 70 70 246 246 246 138 138 138 2 2 6
39520 - 2 2 6 2 2 6 2 2 6 2 2 6
39521 - 70 70 70 66 66 66 26 26 26 6 6 6
39522 - 0 0 0 0 0 0 0 0 0 0 0 0
39523 - 0 0 0 0 0 0 0 0 0 0 0 0
39524 - 0 0 0 0 0 0 0 0 0 0 0 0
39525 - 0 0 0 0 0 0 0 0 0 0 0 0
39526 - 0 0 0 0 0 0 0 0 0 0 0 0
39527 - 0 0 0 0 0 0 0 0 0 0 0 0
39528 - 0 0 0 0 0 0 0 0 0 0 0 0
39529 - 0 0 0 0 0 0 0 0 0 0 0 0
39530 - 0 0 0 0 0 0 0 0 0 0 0 0
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 0 0 0
39534 - 0 0 0 0 0 0 0 0 0 10 10 10
39535 - 38 38 38 86 86 86 14 14 14 10 10 10
39536 -195 195 195 188 164 115 192 133 9 225 175 15
39537 -239 182 13 234 190 10 232 195 16 232 200 30
39538 -245 207 45 241 208 19 232 195 16 184 144 12
39539 -218 194 134 211 206 186 42 42 42 2 2 6
39540 - 2 2 6 2 2 6 2 2 6 2 2 6
39541 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 10 10 10
39555 - 34 34 34 86 86 86 14 14 14 2 2 6
39556 -121 87 25 192 133 9 219 162 10 239 182 13
39557 -236 186 11 232 195 16 241 208 19 244 214 54
39558 -246 218 60 246 218 38 246 215 20 241 208 19
39559 -241 208 19 226 184 13 121 87 25 2 2 6
39560 - 2 2 6 2 2 6 2 2 6 2 2 6
39561 - 50 50 50 82 82 82 34 34 34 10 10 10
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 0 0 0 0 0 0 10 10 10
39575 - 34 34 34 82 82 82 30 30 30 61 42 6
39576 -180 123 7 206 145 10 230 174 11 239 182 13
39577 -234 190 10 238 202 15 241 208 19 246 218 74
39578 -246 218 38 246 215 20 246 215 20 246 215 20
39579 -226 184 13 215 174 15 184 144 12 6 6 6
39580 - 2 2 6 2 2 6 2 2 6 2 2 6
39581 - 26 26 26 94 94 94 42 42 42 14 14 14
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 0 0 0 10 10 10
39595 - 30 30 30 78 78 78 50 50 50 104 69 6
39596 -192 133 9 216 158 10 236 178 12 236 186 11
39597 -232 195 16 241 208 19 244 214 54 245 215 43
39598 -246 215 20 246 215 20 241 208 19 198 155 10
39599 -200 144 11 216 158 10 156 118 10 2 2 6
39600 - 2 2 6 2 2 6 2 2 6 2 2 6
39601 - 6 6 6 90 90 90 54 54 54 18 18 18
39602 - 6 6 6 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 0 0 0 10 10 10
39615 - 30 30 30 78 78 78 46 46 46 22 22 22
39616 -137 92 6 210 162 10 239 182 13 238 190 10
39617 -238 202 15 241 208 19 246 215 20 246 215 20
39618 -241 208 19 203 166 17 185 133 11 210 150 10
39619 -216 158 10 210 150 10 102 78 10 2 2 6
39620 - 6 6 6 54 54 54 14 14 14 2 2 6
39621 - 2 2 6 62 62 62 74 74 74 30 30 30
39622 - 10 10 10 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 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 10 10 10
39635 - 34 34 34 78 78 78 50 50 50 6 6 6
39636 - 94 70 30 139 102 15 190 146 13 226 184 13
39637 -232 200 30 232 195 16 215 174 15 190 146 13
39638 -168 122 10 192 133 9 210 150 10 213 154 11
39639 -202 150 34 182 157 106 101 98 89 2 2 6
39640 - 2 2 6 78 78 78 116 116 116 58 58 58
39641 - 2 2 6 22 22 22 90 90 90 46 46 46
39642 - 18 18 18 6 6 6 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 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 10 10 10
39655 - 38 38 38 86 86 86 50 50 50 6 6 6
39656 -128 128 128 174 154 114 156 107 11 168 122 10
39657 -198 155 10 184 144 12 197 138 11 200 144 11
39658 -206 145 10 206 145 10 197 138 11 188 164 115
39659 -195 195 195 198 198 198 174 174 174 14 14 14
39660 - 2 2 6 22 22 22 116 116 116 116 116 116
39661 - 22 22 22 2 2 6 74 74 74 70 70 70
39662 - 30 30 30 10 10 10 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 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 0 6 6 6 18 18 18
39675 - 50 50 50 101 101 101 26 26 26 10 10 10
39676 -138 138 138 190 190 190 174 154 114 156 107 11
39677 -197 138 11 200 144 11 197 138 11 192 133 9
39678 -180 123 7 190 142 34 190 178 144 187 187 187
39679 -202 202 202 221 221 221 214 214 214 66 66 66
39680 - 2 2 6 2 2 6 50 50 50 62 62 62
39681 - 6 6 6 2 2 6 10 10 10 90 90 90
39682 - 50 50 50 18 18 18 6 6 6 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 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 10 10 10 34 34 34
39695 - 74 74 74 74 74 74 2 2 6 6 6 6
39696 -144 144 144 198 198 198 190 190 190 178 166 146
39697 -154 121 60 156 107 11 156 107 11 168 124 44
39698 -174 154 114 187 187 187 190 190 190 210 210 210
39699 -246 246 246 253 253 253 253 253 253 182 182 182
39700 - 6 6 6 2 2 6 2 2 6 2 2 6
39701 - 2 2 6 2 2 6 2 2 6 62 62 62
39702 - 74 74 74 34 34 34 14 14 14 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 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 10 10 10 22 22 22 54 54 54
39715 - 94 94 94 18 18 18 2 2 6 46 46 46
39716 -234 234 234 221 221 221 190 190 190 190 190 190
39717 -190 190 190 187 187 187 187 187 187 190 190 190
39718 -190 190 190 195 195 195 214 214 214 242 242 242
39719 -253 253 253 253 253 253 253 253 253 253 253 253
39720 - 82 82 82 2 2 6 2 2 6 2 2 6
39721 - 2 2 6 2 2 6 2 2 6 14 14 14
39722 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 6 6 6 18 18 18 46 46 46 90 90 90
39735 - 46 46 46 18 18 18 6 6 6 182 182 182
39736 -253 253 253 246 246 246 206 206 206 190 190 190
39737 -190 190 190 190 190 190 190 190 190 190 190 190
39738 -206 206 206 231 231 231 250 250 250 253 253 253
39739 -253 253 253 253 253 253 253 253 253 253 253 253
39740 -202 202 202 14 14 14 2 2 6 2 2 6
39741 - 2 2 6 2 2 6 2 2 6 2 2 6
39742 - 42 42 42 86 86 86 42 42 42 18 18 18
39743 - 6 6 6 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 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 6 6 6
39754 - 14 14 14 38 38 38 74 74 74 66 66 66
39755 - 2 2 6 6 6 6 90 90 90 250 250 250
39756 -253 253 253 253 253 253 238 238 238 198 198 198
39757 -190 190 190 190 190 190 195 195 195 221 221 221
39758 -246 246 246 253 253 253 253 253 253 253 253 253
39759 -253 253 253 253 253 253 253 253 253 253 253 253
39760 -253 253 253 82 82 82 2 2 6 2 2 6
39761 - 2 2 6 2 2 6 2 2 6 2 2 6
39762 - 2 2 6 78 78 78 70 70 70 34 34 34
39763 - 14 14 14 6 6 6 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 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 14 14 14
39774 - 34 34 34 66 66 66 78 78 78 6 6 6
39775 - 2 2 6 18 18 18 218 218 218 253 253 253
39776 -253 253 253 253 253 253 253 253 253 246 246 246
39777 -226 226 226 231 231 231 246 246 246 253 253 253
39778 -253 253 253 253 253 253 253 253 253 253 253 253
39779 -253 253 253 253 253 253 253 253 253 253 253 253
39780 -253 253 253 178 178 178 2 2 6 2 2 6
39781 - 2 2 6 2 2 6 2 2 6 2 2 6
39782 - 2 2 6 18 18 18 90 90 90 62 62 62
39783 - 30 30 30 10 10 10 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 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 10 10 10 26 26 26
39794 - 58 58 58 90 90 90 18 18 18 2 2 6
39795 - 2 2 6 110 110 110 253 253 253 253 253 253
39796 -253 253 253 253 253 253 253 253 253 253 253 253
39797 -250 250 250 253 253 253 253 253 253 253 253 253
39798 -253 253 253 253 253 253 253 253 253 253 253 253
39799 -253 253 253 253 253 253 253 253 253 253 253 253
39800 -253 253 253 231 231 231 18 18 18 2 2 6
39801 - 2 2 6 2 2 6 2 2 6 2 2 6
39802 - 2 2 6 2 2 6 18 18 18 94 94 94
39803 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 6 6 6 22 22 22 50 50 50
39814 - 90 90 90 26 26 26 2 2 6 2 2 6
39815 - 14 14 14 195 195 195 250 250 250 253 253 253
39816 -253 253 253 253 253 253 253 253 253 253 253 253
39817 -253 253 253 253 253 253 253 253 253 253 253 253
39818 -253 253 253 253 253 253 253 253 253 253 253 253
39819 -253 253 253 253 253 253 253 253 253 253 253 253
39820 -250 250 250 242 242 242 54 54 54 2 2 6
39821 - 2 2 6 2 2 6 2 2 6 2 2 6
39822 - 2 2 6 2 2 6 2 2 6 38 38 38
39823 - 86 86 86 50 50 50 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 6 6 6 14 14 14 38 38 38 82 82 82
39834 - 34 34 34 2 2 6 2 2 6 2 2 6
39835 - 42 42 42 195 195 195 246 246 246 253 253 253
39836 -253 253 253 253 253 253 253 253 253 250 250 250
39837 -242 242 242 242 242 242 250 250 250 253 253 253
39838 -253 253 253 253 253 253 253 253 253 253 253 253
39839 -253 253 253 250 250 250 246 246 246 238 238 238
39840 -226 226 226 231 231 231 101 101 101 6 6 6
39841 - 2 2 6 2 2 6 2 2 6 2 2 6
39842 - 2 2 6 2 2 6 2 2 6 2 2 6
39843 - 38 38 38 82 82 82 42 42 42 14 14 14
39844 - 6 6 6 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 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 10 10 10 26 26 26 62 62 62 66 66 66
39854 - 2 2 6 2 2 6 2 2 6 6 6 6
39855 - 70 70 70 170 170 170 206 206 206 234 234 234
39856 -246 246 246 250 250 250 250 250 250 238 238 238
39857 -226 226 226 231 231 231 238 238 238 250 250 250
39858 -250 250 250 250 250 250 246 246 246 231 231 231
39859 -214 214 214 206 206 206 202 202 202 202 202 202
39860 -198 198 198 202 202 202 182 182 182 18 18 18
39861 - 2 2 6 2 2 6 2 2 6 2 2 6
39862 - 2 2 6 2 2 6 2 2 6 2 2 6
39863 - 2 2 6 62 62 62 66 66 66 30 30 30
39864 - 10 10 10 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 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 14 14 14 42 42 42 82 82 82 18 18 18
39874 - 2 2 6 2 2 6 2 2 6 10 10 10
39875 - 94 94 94 182 182 182 218 218 218 242 242 242
39876 -250 250 250 253 253 253 253 253 253 250 250 250
39877 -234 234 234 253 253 253 253 253 253 253 253 253
39878 -253 253 253 253 253 253 253 253 253 246 246 246
39879 -238 238 238 226 226 226 210 210 210 202 202 202
39880 -195 195 195 195 195 195 210 210 210 158 158 158
39881 - 6 6 6 14 14 14 50 50 50 14 14 14
39882 - 2 2 6 2 2 6 2 2 6 2 2 6
39883 - 2 2 6 6 6 6 86 86 86 46 46 46
39884 - 18 18 18 6 6 6 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 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 6 6 6
39893 - 22 22 22 54 54 54 70 70 70 2 2 6
39894 - 2 2 6 10 10 10 2 2 6 22 22 22
39895 -166 166 166 231 231 231 250 250 250 253 253 253
39896 -253 253 253 253 253 253 253 253 253 250 250 250
39897 -242 242 242 253 253 253 253 253 253 253 253 253
39898 -253 253 253 253 253 253 253 253 253 253 253 253
39899 -253 253 253 253 253 253 253 253 253 246 246 246
39900 -231 231 231 206 206 206 198 198 198 226 226 226
39901 - 94 94 94 2 2 6 6 6 6 38 38 38
39902 - 30 30 30 2 2 6 2 2 6 2 2 6
39903 - 2 2 6 2 2 6 62 62 62 66 66 66
39904 - 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 10 10 10
39913 - 30 30 30 74 74 74 50 50 50 2 2 6
39914 - 26 26 26 26 26 26 2 2 6 106 106 106
39915 -238 238 238 253 253 253 253 253 253 253 253 253
39916 -253 253 253 253 253 253 253 253 253 253 253 253
39917 -253 253 253 253 253 253 253 253 253 253 253 253
39918 -253 253 253 253 253 253 253 253 253 253 253 253
39919 -253 253 253 253 253 253 253 253 253 253 253 253
39920 -253 253 253 246 246 246 218 218 218 202 202 202
39921 -210 210 210 14 14 14 2 2 6 2 2 6
39922 - 30 30 30 22 22 22 2 2 6 2 2 6
39923 - 2 2 6 2 2 6 18 18 18 86 86 86
39924 - 42 42 42 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 14 14 14
39933 - 42 42 42 90 90 90 22 22 22 2 2 6
39934 - 42 42 42 2 2 6 18 18 18 218 218 218
39935 -253 253 253 253 253 253 253 253 253 253 253 253
39936 -253 253 253 253 253 253 253 253 253 253 253 253
39937 -253 253 253 253 253 253 253 253 253 253 253 253
39938 -253 253 253 253 253 253 253 253 253 253 253 253
39939 -253 253 253 253 253 253 253 253 253 253 253 253
39940 -253 253 253 253 253 253 250 250 250 221 221 221
39941 -218 218 218 101 101 101 2 2 6 14 14 14
39942 - 18 18 18 38 38 38 10 10 10 2 2 6
39943 - 2 2 6 2 2 6 2 2 6 78 78 78
39944 - 58 58 58 22 22 22 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 6 6 6 18 18 18
39953 - 54 54 54 82 82 82 2 2 6 26 26 26
39954 - 22 22 22 2 2 6 123 123 123 253 253 253
39955 -253 253 253 253 253 253 253 253 253 253 253 253
39956 -253 253 253 253 253 253 253 253 253 253 253 253
39957 -253 253 253 253 253 253 253 253 253 253 253 253
39958 -253 253 253 253 253 253 253 253 253 253 253 253
39959 -253 253 253 253 253 253 253 253 253 253 253 253
39960 -253 253 253 253 253 253 253 253 253 250 250 250
39961 -238 238 238 198 198 198 6 6 6 38 38 38
39962 - 58 58 58 26 26 26 38 38 38 2 2 6
39963 - 2 2 6 2 2 6 2 2 6 46 46 46
39964 - 78 78 78 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 10 10 10 30 30 30
39973 - 74 74 74 58 58 58 2 2 6 42 42 42
39974 - 2 2 6 22 22 22 231 231 231 253 253 253
39975 -253 253 253 253 253 253 253 253 253 253 253 253
39976 -253 253 253 253 253 253 253 253 253 250 250 250
39977 -253 253 253 253 253 253 253 253 253 253 253 253
39978 -253 253 253 253 253 253 253 253 253 253 253 253
39979 -253 253 253 253 253 253 253 253 253 253 253 253
39980 -253 253 253 253 253 253 253 253 253 253 253 253
39981 -253 253 253 246 246 246 46 46 46 38 38 38
39982 - 42 42 42 14 14 14 38 38 38 14 14 14
39983 - 2 2 6 2 2 6 2 2 6 6 6 6
39984 - 86 86 86 46 46 46 14 14 14 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 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 6 6 6 14 14 14 42 42 42
39993 - 90 90 90 18 18 18 18 18 18 26 26 26
39994 - 2 2 6 116 116 116 253 253 253 253 253 253
39995 -253 253 253 253 253 253 253 253 253 253 253 253
39996 -253 253 253 253 253 253 250 250 250 238 238 238
39997 -253 253 253 253 253 253 253 253 253 253 253 253
39998 -253 253 253 253 253 253 253 253 253 253 253 253
39999 -253 253 253 253 253 253 253 253 253 253 253 253
40000 -253 253 253 253 253 253 253 253 253 253 253 253
40001 -253 253 253 253 253 253 94 94 94 6 6 6
40002 - 2 2 6 2 2 6 10 10 10 34 34 34
40003 - 2 2 6 2 2 6 2 2 6 2 2 6
40004 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 10 10 10 26 26 26 66 66 66
40013 - 82 82 82 2 2 6 38 38 38 6 6 6
40014 - 14 14 14 210 210 210 253 253 253 253 253 253
40015 -253 253 253 253 253 253 253 253 253 253 253 253
40016 -253 253 253 253 253 253 246 246 246 242 242 242
40017 -253 253 253 253 253 253 253 253 253 253 253 253
40018 -253 253 253 253 253 253 253 253 253 253 253 253
40019 -253 253 253 253 253 253 253 253 253 253 253 253
40020 -253 253 253 253 253 253 253 253 253 253 253 253
40021 -253 253 253 253 253 253 144 144 144 2 2 6
40022 - 2 2 6 2 2 6 2 2 6 46 46 46
40023 - 2 2 6 2 2 6 2 2 6 2 2 6
40024 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 6 6 6 14 14 14 42 42 42 90 90 90
40033 - 26 26 26 6 6 6 42 42 42 2 2 6
40034 - 74 74 74 250 250 250 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 242 242 242 242 242 242
40037 -253 253 253 253 253 253 253 253 253 253 253 253
40038 -253 253 253 253 253 253 253 253 253 253 253 253
40039 -253 253 253 253 253 253 253 253 253 253 253 253
40040 -253 253 253 253 253 253 253 253 253 253 253 253
40041 -253 253 253 253 253 253 182 182 182 2 2 6
40042 - 2 2 6 2 2 6 2 2 6 46 46 46
40043 - 2 2 6 2 2 6 2 2 6 2 2 6
40044 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 10 10 10 26 26 26 66 66 66 82 82 82
40053 - 2 2 6 22 22 22 18 18 18 2 2 6
40054 -149 149 149 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 234 234 234 242 242 242
40057 -253 253 253 253 253 253 253 253 253 253 253 253
40058 -253 253 253 253 253 253 253 253 253 253 253 253
40059 -253 253 253 253 253 253 253 253 253 253 253 253
40060 -253 253 253 253 253 253 253 253 253 253 253 253
40061 -253 253 253 253 253 253 206 206 206 2 2 6
40062 - 2 2 6 2 2 6 2 2 6 38 38 38
40063 - 2 2 6 2 2 6 2 2 6 2 2 6
40064 - 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 6 6 6
40072 - 18 18 18 46 46 46 86 86 86 18 18 18
40073 - 2 2 6 34 34 34 10 10 10 6 6 6
40074 -210 210 210 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 234 234 234 242 242 242
40077 -253 253 253 253 253 253 253 253 253 253 253 253
40078 -253 253 253 253 253 253 253 253 253 253 253 253
40079 -253 253 253 253 253 253 253 253 253 253 253 253
40080 -253 253 253 253 253 253 253 253 253 253 253 253
40081 -253 253 253 253 253 253 221 221 221 6 6 6
40082 - 2 2 6 2 2 6 6 6 6 30 30 30
40083 - 2 2 6 2 2 6 2 2 6 2 2 6
40084 - 2 2 6 82 82 82 54 54 54 18 18 18
40085 - 6 6 6 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 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 10 10 10
40092 - 26 26 26 66 66 66 62 62 62 2 2 6
40093 - 2 2 6 38 38 38 10 10 10 26 26 26
40094 -238 238 238 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 231 231 231 238 238 238
40097 -253 253 253 253 253 253 253 253 253 253 253 253
40098 -253 253 253 253 253 253 253 253 253 253 253 253
40099 -253 253 253 253 253 253 253 253 253 253 253 253
40100 -253 253 253 253 253 253 253 253 253 253 253 253
40101 -253 253 253 253 253 253 231 231 231 6 6 6
40102 - 2 2 6 2 2 6 10 10 10 30 30 30
40103 - 2 2 6 2 2 6 2 2 6 2 2 6
40104 - 2 2 6 66 66 66 58 58 58 22 22 22
40105 - 6 6 6 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 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 10 10 10
40112 - 38 38 38 78 78 78 6 6 6 2 2 6
40113 - 2 2 6 46 46 46 14 14 14 42 42 42
40114 -246 246 246 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 231 231 231 242 242 242
40117 -253 253 253 253 253 253 253 253 253 253 253 253
40118 -253 253 253 253 253 253 253 253 253 253 253 253
40119 -253 253 253 253 253 253 253 253 253 253 253 253
40120 -253 253 253 253 253 253 253 253 253 253 253 253
40121 -253 253 253 253 253 253 234 234 234 10 10 10
40122 - 2 2 6 2 2 6 22 22 22 14 14 14
40123 - 2 2 6 2 2 6 2 2 6 2 2 6
40124 - 2 2 6 66 66 66 62 62 62 22 22 22
40125 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 6 6 6 18 18 18
40132 - 50 50 50 74 74 74 2 2 6 2 2 6
40133 - 14 14 14 70 70 70 34 34 34 62 62 62
40134 -250 250 250 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 231 231 231 246 246 246
40137 -253 253 253 253 253 253 253 253 253 253 253 253
40138 -253 253 253 253 253 253 253 253 253 253 253 253
40139 -253 253 253 253 253 253 253 253 253 253 253 253
40140 -253 253 253 253 253 253 253 253 253 253 253 253
40141 -253 253 253 253 253 253 234 234 234 14 14 14
40142 - 2 2 6 2 2 6 30 30 30 2 2 6
40143 - 2 2 6 2 2 6 2 2 6 2 2 6
40144 - 2 2 6 66 66 66 62 62 62 22 22 22
40145 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 6 6 6 18 18 18
40152 - 54 54 54 62 62 62 2 2 6 2 2 6
40153 - 2 2 6 30 30 30 46 46 46 70 70 70
40154 -250 250 250 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 231 231 231 246 246 246
40157 -253 253 253 253 253 253 253 253 253 253 253 253
40158 -253 253 253 253 253 253 253 253 253 253 253 253
40159 -253 253 253 253 253 253 253 253 253 253 253 253
40160 -253 253 253 253 253 253 253 253 253 253 253 253
40161 -253 253 253 253 253 253 226 226 226 10 10 10
40162 - 2 2 6 6 6 6 30 30 30 2 2 6
40163 - 2 2 6 2 2 6 2 2 6 2 2 6
40164 - 2 2 6 66 66 66 58 58 58 22 22 22
40165 - 6 6 6 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 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 6 6 6 22 22 22
40172 - 58 58 58 62 62 62 2 2 6 2 2 6
40173 - 2 2 6 2 2 6 30 30 30 78 78 78
40174 -250 250 250 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 231 231 231 246 246 246
40177 -253 253 253 253 253 253 253 253 253 253 253 253
40178 -253 253 253 253 253 253 253 253 253 253 253 253
40179 -253 253 253 253 253 253 253 253 253 253 253 253
40180 -253 253 253 253 253 253 253 253 253 253 253 253
40181 -253 253 253 253 253 253 206 206 206 2 2 6
40182 - 22 22 22 34 34 34 18 14 6 22 22 22
40183 - 26 26 26 18 18 18 6 6 6 2 2 6
40184 - 2 2 6 82 82 82 54 54 54 18 18 18
40185 - 6 6 6 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 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 6 6 6 26 26 26
40192 - 62 62 62 106 106 106 74 54 14 185 133 11
40193 -210 162 10 121 92 8 6 6 6 62 62 62
40194 -238 238 238 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 231 231 231 246 246 246
40197 -253 253 253 253 253 253 253 253 253 253 253 253
40198 -253 253 253 253 253 253 253 253 253 253 253 253
40199 -253 253 253 253 253 253 253 253 253 253 253 253
40200 -253 253 253 253 253 253 253 253 253 253 253 253
40201 -253 253 253 253 253 253 158 158 158 18 18 18
40202 - 14 14 14 2 2 6 2 2 6 2 2 6
40203 - 6 6 6 18 18 18 66 66 66 38 38 38
40204 - 6 6 6 94 94 94 50 50 50 18 18 18
40205 - 6 6 6 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 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 6 6 6
40211 - 10 10 10 10 10 10 18 18 18 38 38 38
40212 - 78 78 78 142 134 106 216 158 10 242 186 14
40213 -246 190 14 246 190 14 156 118 10 10 10 10
40214 - 90 90 90 238 238 238 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 231 231 231 250 250 250
40217 -253 253 253 253 253 253 253 253 253 253 253 253
40218 -253 253 253 253 253 253 253 253 253 253 253 253
40219 -253 253 253 253 253 253 253 253 253 253 253 253
40220 -253 253 253 253 253 253 253 253 253 246 230 190
40221 -238 204 91 238 204 91 181 142 44 37 26 9
40222 - 2 2 6 2 2 6 2 2 6 2 2 6
40223 - 2 2 6 2 2 6 38 38 38 46 46 46
40224 - 26 26 26 106 106 106 54 54 54 18 18 18
40225 - 6 6 6 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 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 6 6 6 14 14 14 22 22 22
40231 - 30 30 30 38 38 38 50 50 50 70 70 70
40232 -106 106 106 190 142 34 226 170 11 242 186 14
40233 -246 190 14 246 190 14 246 190 14 154 114 10
40234 - 6 6 6 74 74 74 226 226 226 253 253 253
40235 -253 253 253 253 253 253 253 253 253 253 253 253
40236 -253 253 253 253 253 253 231 231 231 250 250 250
40237 -253 253 253 253 253 253 253 253 253 253 253 253
40238 -253 253 253 253 253 253 253 253 253 253 253 253
40239 -253 253 253 253 253 253 253 253 253 253 253 253
40240 -253 253 253 253 253 253 253 253 253 228 184 62
40241 -241 196 14 241 208 19 232 195 16 38 30 10
40242 - 2 2 6 2 2 6 2 2 6 2 2 6
40243 - 2 2 6 6 6 6 30 30 30 26 26 26
40244 -203 166 17 154 142 90 66 66 66 26 26 26
40245 - 6 6 6 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 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 6 6 6 18 18 18 38 38 38 58 58 58
40251 - 78 78 78 86 86 86 101 101 101 123 123 123
40252 -175 146 61 210 150 10 234 174 13 246 186 14
40253 -246 190 14 246 190 14 246 190 14 238 190 10
40254 -102 78 10 2 2 6 46 46 46 198 198 198
40255 -253 253 253 253 253 253 253 253 253 253 253 253
40256 -253 253 253 253 253 253 234 234 234 242 242 242
40257 -253 253 253 253 253 253 253 253 253 253 253 253
40258 -253 253 253 253 253 253 253 253 253 253 253 253
40259 -253 253 253 253 253 253 253 253 253 253 253 253
40260 -253 253 253 253 253 253 253 253 253 224 178 62
40261 -242 186 14 241 196 14 210 166 10 22 18 6
40262 - 2 2 6 2 2 6 2 2 6 2 2 6
40263 - 2 2 6 2 2 6 6 6 6 121 92 8
40264 -238 202 15 232 195 16 82 82 82 34 34 34
40265 - 10 10 10 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 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 14 14 14 38 38 38 70 70 70 154 122 46
40271 -190 142 34 200 144 11 197 138 11 197 138 11
40272 -213 154 11 226 170 11 242 186 14 246 190 14
40273 -246 190 14 246 190 14 246 190 14 246 190 14
40274 -225 175 15 46 32 6 2 2 6 22 22 22
40275 -158 158 158 250 250 250 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 253 253 253 253 253 253
40278 -253 253 253 253 253 253 253 253 253 253 253 253
40279 -253 253 253 253 253 253 253 253 253 253 253 253
40280 -253 253 253 250 250 250 242 242 242 224 178 62
40281 -239 182 13 236 186 11 213 154 11 46 32 6
40282 - 2 2 6 2 2 6 2 2 6 2 2 6
40283 - 2 2 6 2 2 6 61 42 6 225 175 15
40284 -238 190 10 236 186 11 112 100 78 42 42 42
40285 - 14 14 14 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 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 6 6 6
40290 - 22 22 22 54 54 54 154 122 46 213 154 11
40291 -226 170 11 230 174 11 226 170 11 226 170 11
40292 -236 178 12 242 186 14 246 190 14 246 190 14
40293 -246 190 14 246 190 14 246 190 14 246 190 14
40294 -241 196 14 184 144 12 10 10 10 2 2 6
40295 - 6 6 6 116 116 116 242 242 242 253 253 253
40296 -253 253 253 253 253 253 253 253 253 253 253 253
40297 -253 253 253 253 253 253 253 253 253 253 253 253
40298 -253 253 253 253 253 253 253 253 253 253 253 253
40299 -253 253 253 253 253 253 253 253 253 253 253 253
40300 -253 253 253 231 231 231 198 198 198 214 170 54
40301 -236 178 12 236 178 12 210 150 10 137 92 6
40302 - 18 14 6 2 2 6 2 2 6 2 2 6
40303 - 6 6 6 70 47 6 200 144 11 236 178 12
40304 -239 182 13 239 182 13 124 112 88 58 58 58
40305 - 22 22 22 6 6 6 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 10 10 10
40310 - 30 30 30 70 70 70 180 133 36 226 170 11
40311 -239 182 13 242 186 14 242 186 14 246 186 14
40312 -246 190 14 246 190 14 246 190 14 246 190 14
40313 -246 190 14 246 190 14 246 190 14 246 190 14
40314 -246 190 14 232 195 16 98 70 6 2 2 6
40315 - 2 2 6 2 2 6 66 66 66 221 221 221
40316 -253 253 253 253 253 253 253 253 253 253 253 253
40317 -253 253 253 253 253 253 253 253 253 253 253 253
40318 -253 253 253 253 253 253 253 253 253 253 253 253
40319 -253 253 253 253 253 253 253 253 253 253 253 253
40320 -253 253 253 206 206 206 198 198 198 214 166 58
40321 -230 174 11 230 174 11 216 158 10 192 133 9
40322 -163 110 8 116 81 8 102 78 10 116 81 8
40323 -167 114 7 197 138 11 226 170 11 239 182 13
40324 -242 186 14 242 186 14 162 146 94 78 78 78
40325 - 34 34 34 14 14 14 6 6 6 0 0 0
40326 - 0 0 0 0 0 0 0 0 0 0 0 0
40327 - 0 0 0 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 6 6 6
40330 - 30 30 30 78 78 78 190 142 34 226 170 11
40331 -239 182 13 246 190 14 246 190 14 246 190 14
40332 -246 190 14 246 190 14 246 190 14 246 190 14
40333 -246 190 14 246 190 14 246 190 14 246 190 14
40334 -246 190 14 241 196 14 203 166 17 22 18 6
40335 - 2 2 6 2 2 6 2 2 6 38 38 38
40336 -218 218 218 253 253 253 253 253 253 253 253 253
40337 -253 253 253 253 253 253 253 253 253 253 253 253
40338 -253 253 253 253 253 253 253 253 253 253 253 253
40339 -253 253 253 253 253 253 253 253 253 253 253 253
40340 -250 250 250 206 206 206 198 198 198 202 162 69
40341 -226 170 11 236 178 12 224 166 10 210 150 10
40342 -200 144 11 197 138 11 192 133 9 197 138 11
40343 -210 150 10 226 170 11 242 186 14 246 190 14
40344 -246 190 14 246 186 14 225 175 15 124 112 88
40345 - 62 62 62 30 30 30 14 14 14 6 6 6
40346 - 0 0 0 0 0 0 0 0 0 0 0 0
40347 - 0 0 0 0 0 0 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 10 10 10
40350 - 30 30 30 78 78 78 174 135 50 224 166 10
40351 -239 182 13 246 190 14 246 190 14 246 190 14
40352 -246 190 14 246 190 14 246 190 14 246 190 14
40353 -246 190 14 246 190 14 246 190 14 246 190 14
40354 -246 190 14 246 190 14 241 196 14 139 102 15
40355 - 2 2 6 2 2 6 2 2 6 2 2 6
40356 - 78 78 78 250 250 250 253 253 253 253 253 253
40357 -253 253 253 253 253 253 253 253 253 253 253 253
40358 -253 253 253 253 253 253 253 253 253 253 253 253
40359 -253 253 253 253 253 253 253 253 253 253 253 253
40360 -250 250 250 214 214 214 198 198 198 190 150 46
40361 -219 162 10 236 178 12 234 174 13 224 166 10
40362 -216 158 10 213 154 11 213 154 11 216 158 10
40363 -226 170 11 239 182 13 246 190 14 246 190 14
40364 -246 190 14 246 190 14 242 186 14 206 162 42
40365 -101 101 101 58 58 58 30 30 30 14 14 14
40366 - 6 6 6 0 0 0 0 0 0 0 0 0
40367 - 0 0 0 0 0 0 0 0 0 0 0 0
40368 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 10 10 10
40370 - 30 30 30 74 74 74 174 135 50 216 158 10
40371 -236 178 12 246 190 14 246 190 14 246 190 14
40372 -246 190 14 246 190 14 246 190 14 246 190 14
40373 -246 190 14 246 190 14 246 190 14 246 190 14
40374 -246 190 14 246 190 14 241 196 14 226 184 13
40375 - 61 42 6 2 2 6 2 2 6 2 2 6
40376 - 22 22 22 238 238 238 253 253 253 253 253 253
40377 -253 253 253 253 253 253 253 253 253 253 253 253
40378 -253 253 253 253 253 253 253 253 253 253 253 253
40379 -253 253 253 253 253 253 253 253 253 253 253 253
40380 -253 253 253 226 226 226 187 187 187 180 133 36
40381 -216 158 10 236 178 12 239 182 13 236 178 12
40382 -230 174 11 226 170 11 226 170 11 230 174 11
40383 -236 178 12 242 186 14 246 190 14 246 190 14
40384 -246 190 14 246 190 14 246 186 14 239 182 13
40385 -206 162 42 106 106 106 66 66 66 34 34 34
40386 - 14 14 14 6 6 6 0 0 0 0 0 0
40387 - 0 0 0 0 0 0 0 0 0 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 6 6 6
40390 - 26 26 26 70 70 70 163 133 67 213 154 11
40391 -236 178 12 246 190 14 246 190 14 246 190 14
40392 -246 190 14 246 190 14 246 190 14 246 190 14
40393 -246 190 14 246 190 14 246 190 14 246 190 14
40394 -246 190 14 246 190 14 246 190 14 241 196 14
40395 -190 146 13 18 14 6 2 2 6 2 2 6
40396 - 46 46 46 246 246 246 253 253 253 253 253 253
40397 -253 253 253 253 253 253 253 253 253 253 253 253
40398 -253 253 253 253 253 253 253 253 253 253 253 253
40399 -253 253 253 253 253 253 253 253 253 253 253 253
40400 -253 253 253 221 221 221 86 86 86 156 107 11
40401 -216 158 10 236 178 12 242 186 14 246 186 14
40402 -242 186 14 239 182 13 239 182 13 242 186 14
40403 -242 186 14 246 186 14 246 190 14 246 190 14
40404 -246 190 14 246 190 14 246 190 14 246 190 14
40405 -242 186 14 225 175 15 142 122 72 66 66 66
40406 - 30 30 30 10 10 10 0 0 0 0 0 0
40407 - 0 0 0 0 0 0 0 0 0 0 0 0
40408 - 0 0 0 0 0 0 0 0 0 0 0 0
40409 - 0 0 0 0 0 0 0 0 0 6 6 6
40410 - 26 26 26 70 70 70 163 133 67 210 150 10
40411 -236 178 12 246 190 14 246 190 14 246 190 14
40412 -246 190 14 246 190 14 246 190 14 246 190 14
40413 -246 190 14 246 190 14 246 190 14 246 190 14
40414 -246 190 14 246 190 14 246 190 14 246 190 14
40415 -232 195 16 121 92 8 34 34 34 106 106 106
40416 -221 221 221 253 253 253 253 253 253 253 253 253
40417 -253 253 253 253 253 253 253 253 253 253 253 253
40418 -253 253 253 253 253 253 253 253 253 253 253 253
40419 -253 253 253 253 253 253 253 253 253 253 253 253
40420 -242 242 242 82 82 82 18 14 6 163 110 8
40421 -216 158 10 236 178 12 242 186 14 246 190 14
40422 -246 190 14 246 190 14 246 190 14 246 190 14
40423 -246 190 14 246 190 14 246 190 14 246 190 14
40424 -246 190 14 246 190 14 246 190 14 246 190 14
40425 -246 190 14 246 190 14 242 186 14 163 133 67
40426 - 46 46 46 18 18 18 6 6 6 0 0 0
40427 - 0 0 0 0 0 0 0 0 0 0 0 0
40428 - 0 0 0 0 0 0 0 0 0 0 0 0
40429 - 0 0 0 0 0 0 0 0 0 10 10 10
40430 - 30 30 30 78 78 78 163 133 67 210 150 10
40431 -236 178 12 246 186 14 246 190 14 246 190 14
40432 -246 190 14 246 190 14 246 190 14 246 190 14
40433 -246 190 14 246 190 14 246 190 14 246 190 14
40434 -246 190 14 246 190 14 246 190 14 246 190 14
40435 -241 196 14 215 174 15 190 178 144 253 253 253
40436 -253 253 253 253 253 253 253 253 253 253 253 253
40437 -253 253 253 253 253 253 253 253 253 253 253 253
40438 -253 253 253 253 253 253 253 253 253 253 253 253
40439 -253 253 253 253 253 253 253 253 253 218 218 218
40440 - 58 58 58 2 2 6 22 18 6 167 114 7
40441 -216 158 10 236 178 12 246 186 14 246 190 14
40442 -246 190 14 246 190 14 246 190 14 246 190 14
40443 -246 190 14 246 190 14 246 190 14 246 190 14
40444 -246 190 14 246 190 14 246 190 14 246 190 14
40445 -246 190 14 246 186 14 242 186 14 190 150 46
40446 - 54 54 54 22 22 22 6 6 6 0 0 0
40447 - 0 0 0 0 0 0 0 0 0 0 0 0
40448 - 0 0 0 0 0 0 0 0 0 0 0 0
40449 - 0 0 0 0 0 0 0 0 0 14 14 14
40450 - 38 38 38 86 86 86 180 133 36 213 154 11
40451 -236 178 12 246 186 14 246 190 14 246 190 14
40452 -246 190 14 246 190 14 246 190 14 246 190 14
40453 -246 190 14 246 190 14 246 190 14 246 190 14
40454 -246 190 14 246 190 14 246 190 14 246 190 14
40455 -246 190 14 232 195 16 190 146 13 214 214 214
40456 -253 253 253 253 253 253 253 253 253 253 253 253
40457 -253 253 253 253 253 253 253 253 253 253 253 253
40458 -253 253 253 253 253 253 253 253 253 253 253 253
40459 -253 253 253 250 250 250 170 170 170 26 26 26
40460 - 2 2 6 2 2 6 37 26 9 163 110 8
40461 -219 162 10 239 182 13 246 186 14 246 190 14
40462 -246 190 14 246 190 14 246 190 14 246 190 14
40463 -246 190 14 246 190 14 246 190 14 246 190 14
40464 -246 190 14 246 190 14 246 190 14 246 190 14
40465 -246 186 14 236 178 12 224 166 10 142 122 72
40466 - 46 46 46 18 18 18 6 6 6 0 0 0
40467 - 0 0 0 0 0 0 0 0 0 0 0 0
40468 - 0 0 0 0 0 0 0 0 0 0 0 0
40469 - 0 0 0 0 0 0 6 6 6 18 18 18
40470 - 50 50 50 109 106 95 192 133 9 224 166 10
40471 -242 186 14 246 190 14 246 190 14 246 190 14
40472 -246 190 14 246 190 14 246 190 14 246 190 14
40473 -246 190 14 246 190 14 246 190 14 246 190 14
40474 -246 190 14 246 190 14 246 190 14 246 190 14
40475 -242 186 14 226 184 13 210 162 10 142 110 46
40476 -226 226 226 253 253 253 253 253 253 253 253 253
40477 -253 253 253 253 253 253 253 253 253 253 253 253
40478 -253 253 253 253 253 253 253 253 253 253 253 253
40479 -198 198 198 66 66 66 2 2 6 2 2 6
40480 - 2 2 6 2 2 6 50 34 6 156 107 11
40481 -219 162 10 239 182 13 246 186 14 246 190 14
40482 -246 190 14 246 190 14 246 190 14 246 190 14
40483 -246 190 14 246 190 14 246 190 14 246 190 14
40484 -246 190 14 246 190 14 246 190 14 242 186 14
40485 -234 174 13 213 154 11 154 122 46 66 66 66
40486 - 30 30 30 10 10 10 0 0 0 0 0 0
40487 - 0 0 0 0 0 0 0 0 0 0 0 0
40488 - 0 0 0 0 0 0 0 0 0 0 0 0
40489 - 0 0 0 0 0 0 6 6 6 22 22 22
40490 - 58 58 58 154 121 60 206 145 10 234 174 13
40491 -242 186 14 246 186 14 246 190 14 246 190 14
40492 -246 190 14 246 190 14 246 190 14 246 190 14
40493 -246 190 14 246 190 14 246 190 14 246 190 14
40494 -246 190 14 246 190 14 246 190 14 246 190 14
40495 -246 186 14 236 178 12 210 162 10 163 110 8
40496 - 61 42 6 138 138 138 218 218 218 250 250 250
40497 -253 253 253 253 253 253 253 253 253 250 250 250
40498 -242 242 242 210 210 210 144 144 144 66 66 66
40499 - 6 6 6 2 2 6 2 2 6 2 2 6
40500 - 2 2 6 2 2 6 61 42 6 163 110 8
40501 -216 158 10 236 178 12 246 190 14 246 190 14
40502 -246 190 14 246 190 14 246 190 14 246 190 14
40503 -246 190 14 246 190 14 246 190 14 246 190 14
40504 -246 190 14 239 182 13 230 174 11 216 158 10
40505 -190 142 34 124 112 88 70 70 70 38 38 38
40506 - 18 18 18 6 6 6 0 0 0 0 0 0
40507 - 0 0 0 0 0 0 0 0 0 0 0 0
40508 - 0 0 0 0 0 0 0 0 0 0 0 0
40509 - 0 0 0 0 0 0 6 6 6 22 22 22
40510 - 62 62 62 168 124 44 206 145 10 224 166 10
40511 -236 178 12 239 182 13 242 186 14 242 186 14
40512 -246 186 14 246 190 14 246 190 14 246 190 14
40513 -246 190 14 246 190 14 246 190 14 246 190 14
40514 -246 190 14 246 190 14 246 190 14 246 190 14
40515 -246 190 14 236 178 12 216 158 10 175 118 6
40516 - 80 54 7 2 2 6 6 6 6 30 30 30
40517 - 54 54 54 62 62 62 50 50 50 38 38 38
40518 - 14 14 14 2 2 6 2 2 6 2 2 6
40519 - 2 2 6 2 2 6 2 2 6 2 2 6
40520 - 2 2 6 6 6 6 80 54 7 167 114 7
40521 -213 154 11 236 178 12 246 190 14 246 190 14
40522 -246 190 14 246 190 14 246 190 14 246 190 14
40523 -246 190 14 242 186 14 239 182 13 239 182 13
40524 -230 174 11 210 150 10 174 135 50 124 112 88
40525 - 82 82 82 54 54 54 34 34 34 18 18 18
40526 - 6 6 6 0 0 0 0 0 0 0 0 0
40527 - 0 0 0 0 0 0 0 0 0 0 0 0
40528 - 0 0 0 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 6 6 6 18 18 18
40530 - 50 50 50 158 118 36 192 133 9 200 144 11
40531 -216 158 10 219 162 10 224 166 10 226 170 11
40532 -230 174 11 236 178 12 239 182 13 239 182 13
40533 -242 186 14 246 186 14 246 190 14 246 190 14
40534 -246 190 14 246 190 14 246 190 14 246 190 14
40535 -246 186 14 230 174 11 210 150 10 163 110 8
40536 -104 69 6 10 10 10 2 2 6 2 2 6
40537 - 2 2 6 2 2 6 2 2 6 2 2 6
40538 - 2 2 6 2 2 6 2 2 6 2 2 6
40539 - 2 2 6 2 2 6 2 2 6 2 2 6
40540 - 2 2 6 6 6 6 91 60 6 167 114 7
40541 -206 145 10 230 174 11 242 186 14 246 190 14
40542 -246 190 14 246 190 14 246 186 14 242 186 14
40543 -239 182 13 230 174 11 224 166 10 213 154 11
40544 -180 133 36 124 112 88 86 86 86 58 58 58
40545 - 38 38 38 22 22 22 10 10 10 6 6 6
40546 - 0 0 0 0 0 0 0 0 0 0 0 0
40547 - 0 0 0 0 0 0 0 0 0 0 0 0
40548 - 0 0 0 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 14 14 14
40550 - 34 34 34 70 70 70 138 110 50 158 118 36
40551 -167 114 7 180 123 7 192 133 9 197 138 11
40552 -200 144 11 206 145 10 213 154 11 219 162 10
40553 -224 166 10 230 174 11 239 182 13 242 186 14
40554 -246 186 14 246 186 14 246 186 14 246 186 14
40555 -239 182 13 216 158 10 185 133 11 152 99 6
40556 -104 69 6 18 14 6 2 2 6 2 2 6
40557 - 2 2 6 2 2 6 2 2 6 2 2 6
40558 - 2 2 6 2 2 6 2 2 6 2 2 6
40559 - 2 2 6 2 2 6 2 2 6 2 2 6
40560 - 2 2 6 6 6 6 80 54 7 152 99 6
40561 -192 133 9 219 162 10 236 178 12 239 182 13
40562 -246 186 14 242 186 14 239 182 13 236 178 12
40563 -224 166 10 206 145 10 192 133 9 154 121 60
40564 - 94 94 94 62 62 62 42 42 42 22 22 22
40565 - 14 14 14 6 6 6 0 0 0 0 0 0
40566 - 0 0 0 0 0 0 0 0 0 0 0 0
40567 - 0 0 0 0 0 0 0 0 0 0 0 0
40568 - 0 0 0 0 0 0 0 0 0 0 0 0
40569 - 0 0 0 0 0 0 0 0 0 6 6 6
40570 - 18 18 18 34 34 34 58 58 58 78 78 78
40571 -101 98 89 124 112 88 142 110 46 156 107 11
40572 -163 110 8 167 114 7 175 118 6 180 123 7
40573 -185 133 11 197 138 11 210 150 10 219 162 10
40574 -226 170 11 236 178 12 236 178 12 234 174 13
40575 -219 162 10 197 138 11 163 110 8 130 83 6
40576 - 91 60 6 10 10 10 2 2 6 2 2 6
40577 - 18 18 18 38 38 38 38 38 38 38 38 38
40578 - 38 38 38 38 38 38 38 38 38 38 38 38
40579 - 38 38 38 38 38 38 26 26 26 2 2 6
40580 - 2 2 6 6 6 6 70 47 6 137 92 6
40581 -175 118 6 200 144 11 219 162 10 230 174 11
40582 -234 174 13 230 174 11 219 162 10 210 150 10
40583 -192 133 9 163 110 8 124 112 88 82 82 82
40584 - 50 50 50 30 30 30 14 14 14 6 6 6
40585 - 0 0 0 0 0 0 0 0 0 0 0 0
40586 - 0 0 0 0 0 0 0 0 0 0 0 0
40587 - 0 0 0 0 0 0 0 0 0 0 0 0
40588 - 0 0 0 0 0 0 0 0 0 0 0 0
40589 - 0 0 0 0 0 0 0 0 0 0 0 0
40590 - 6 6 6 14 14 14 22 22 22 34 34 34
40591 - 42 42 42 58 58 58 74 74 74 86 86 86
40592 -101 98 89 122 102 70 130 98 46 121 87 25
40593 -137 92 6 152 99 6 163 110 8 180 123 7
40594 -185 133 11 197 138 11 206 145 10 200 144 11
40595 -180 123 7 156 107 11 130 83 6 104 69 6
40596 - 50 34 6 54 54 54 110 110 110 101 98 89
40597 - 86 86 86 82 82 82 78 78 78 78 78 78
40598 - 78 78 78 78 78 78 78 78 78 78 78 78
40599 - 78 78 78 82 82 82 86 86 86 94 94 94
40600 -106 106 106 101 101 101 86 66 34 124 80 6
40601 -156 107 11 180 123 7 192 133 9 200 144 11
40602 -206 145 10 200 144 11 192 133 9 175 118 6
40603 -139 102 15 109 106 95 70 70 70 42 42 42
40604 - 22 22 22 10 10 10 0 0 0 0 0 0
40605 - 0 0 0 0 0 0 0 0 0 0 0 0
40606 - 0 0 0 0 0 0 0 0 0 0 0 0
40607 - 0 0 0 0 0 0 0 0 0 0 0 0
40608 - 0 0 0 0 0 0 0 0 0 0 0 0
40609 - 0 0 0 0 0 0 0 0 0 0 0 0
40610 - 0 0 0 0 0 0 6 6 6 10 10 10
40611 - 14 14 14 22 22 22 30 30 30 38 38 38
40612 - 50 50 50 62 62 62 74 74 74 90 90 90
40613 -101 98 89 112 100 78 121 87 25 124 80 6
40614 -137 92 6 152 99 6 152 99 6 152 99 6
40615 -138 86 6 124 80 6 98 70 6 86 66 30
40616 -101 98 89 82 82 82 58 58 58 46 46 46
40617 - 38 38 38 34 34 34 34 34 34 34 34 34
40618 - 34 34 34 34 34 34 34 34 34 34 34 34
40619 - 34 34 34 34 34 34 38 38 38 42 42 42
40620 - 54 54 54 82 82 82 94 86 76 91 60 6
40621 -134 86 6 156 107 11 167 114 7 175 118 6
40622 -175 118 6 167 114 7 152 99 6 121 87 25
40623 -101 98 89 62 62 62 34 34 34 18 18 18
40624 - 6 6 6 0 0 0 0 0 0 0 0 0
40625 - 0 0 0 0 0 0 0 0 0 0 0 0
40626 - 0 0 0 0 0 0 0 0 0 0 0 0
40627 - 0 0 0 0 0 0 0 0 0 0 0 0
40628 - 0 0 0 0 0 0 0 0 0 0 0 0
40629 - 0 0 0 0 0 0 0 0 0 0 0 0
40630 - 0 0 0 0 0 0 0 0 0 0 0 0
40631 - 0 0 0 6 6 6 6 6 6 10 10 10
40632 - 18 18 18 22 22 22 30 30 30 42 42 42
40633 - 50 50 50 66 66 66 86 86 86 101 98 89
40634 -106 86 58 98 70 6 104 69 6 104 69 6
40635 -104 69 6 91 60 6 82 62 34 90 90 90
40636 - 62 62 62 38 38 38 22 22 22 14 14 14
40637 - 10 10 10 10 10 10 10 10 10 10 10 10
40638 - 10 10 10 10 10 10 6 6 6 10 10 10
40639 - 10 10 10 10 10 10 10 10 10 14 14 14
40640 - 22 22 22 42 42 42 70 70 70 89 81 66
40641 - 80 54 7 104 69 6 124 80 6 137 92 6
40642 -134 86 6 116 81 8 100 82 52 86 86 86
40643 - 58 58 58 30 30 30 14 14 14 6 6 6
40644 - 0 0 0 0 0 0 0 0 0 0 0 0
40645 - 0 0 0 0 0 0 0 0 0 0 0 0
40646 - 0 0 0 0 0 0 0 0 0 0 0 0
40647 - 0 0 0 0 0 0 0 0 0 0 0 0
40648 - 0 0 0 0 0 0 0 0 0 0 0 0
40649 - 0 0 0 0 0 0 0 0 0 0 0 0
40650 - 0 0 0 0 0 0 0 0 0 0 0 0
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 6 6 6 10 10 10 14 14 14
40653 - 18 18 18 26 26 26 38 38 38 54 54 54
40654 - 70 70 70 86 86 86 94 86 76 89 81 66
40655 - 89 81 66 86 86 86 74 74 74 50 50 50
40656 - 30 30 30 14 14 14 6 6 6 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 6 6 6 18 18 18 34 34 34 58 58 58
40661 - 82 82 82 89 81 66 89 81 66 89 81 66
40662 - 94 86 66 94 86 76 74 74 74 50 50 50
40663 - 26 26 26 14 14 14 6 6 6 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 0 0 0
40666 - 0 0 0 0 0 0 0 0 0 0 0 0
40667 - 0 0 0 0 0 0 0 0 0 0 0 0
40668 - 0 0 0 0 0 0 0 0 0 0 0 0
40669 - 0 0 0 0 0 0 0 0 0 0 0 0
40670 - 0 0 0 0 0 0 0 0 0 0 0 0
40671 - 0 0 0 0 0 0 0 0 0 0 0 0
40672 - 0 0 0 0 0 0 0 0 0 0 0 0
40673 - 6 6 6 6 6 6 14 14 14 18 18 18
40674 - 30 30 30 38 38 38 46 46 46 54 54 54
40675 - 50 50 50 42 42 42 30 30 30 18 18 18
40676 - 10 10 10 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 6 6 6 14 14 14 26 26 26
40681 - 38 38 38 50 50 50 58 58 58 58 58 58
40682 - 54 54 54 42 42 42 30 30 30 18 18 18
40683 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40687 - 0 0 0 0 0 0 0 0 0 0 0 0
40688 - 0 0 0 0 0 0 0 0 0 0 0 0
40689 - 0 0 0 0 0 0 0 0 0 0 0 0
40690 - 0 0 0 0 0 0 0 0 0 0 0 0
40691 - 0 0 0 0 0 0 0 0 0 0 0 0
40692 - 0 0 0 0 0 0 0 0 0 0 0 0
40693 - 0 0 0 0 0 0 0 0 0 6 6 6
40694 - 6 6 6 10 10 10 14 14 14 18 18 18
40695 - 18 18 18 14 14 14 10 10 10 6 6 6
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 6 6 6
40701 - 14 14 14 18 18 18 22 22 22 22 22 22
40702 - 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0 0 0 0
40707 - 0 0 0 0 0 0 0 0 0 0 0 0
40708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40721 +4 4 4 4 4 4
40722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40735 +4 4 4 4 4 4
40736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40749 +4 4 4 4 4 4
40750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40763 +4 4 4 4 4 4
40764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40777 +4 4 4 4 4 4
40778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40791 +4 4 4 4 4 4
40792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40796 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40797 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40801 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40802 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40803 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
40811 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40812 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
40816 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40817 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40818 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40819 +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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40825 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40826 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
40830 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40831 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40832 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40833 +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 5 5 5 5 5 5 2 2 2 0 0 0
40838 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40839 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40840 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
40843 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40844 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40845 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40846 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40847 +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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40852 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40853 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40854 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40855 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40856 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40857 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40858 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40859 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40860 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40861 +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 5 5 5
40865 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40866 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40867 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40868 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40869 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40870 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40871 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40872 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40873 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40874 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40875 +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 5 5 5 3 3 3
40879 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40880 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40881 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40882 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40883 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40884 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40885 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40886 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40887 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40888 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40889 +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 2 2 2 0 0 0 4 0 0
40893 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40894 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40895 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40896 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40897 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40898 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40899 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40900 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40901 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40902 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40903 +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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40907 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40908 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40909 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40910 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40911 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40912 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40913 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40914 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40915 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40916 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40917 +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 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40921 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40922 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40923 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40924 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40925 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40926 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40927 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40928 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40929 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40930 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40931 +4 4 4 4 4 4
40932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40934 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40935 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40936 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40937 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40938 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40939 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40940 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40941 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40942 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40943 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40944 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40945 +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 3 3 3 0 0 0 1 0 0 4 0 0
40948 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40949 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40950 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40951 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40952 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40953 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40954 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40955 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40956 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40957 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40958 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40959 +0 0 0 4 4 4
40960 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40961 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40962 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40963 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40964 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40965 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40966 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40967 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40968 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40969 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40970 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40971 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40972 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40973 +2 0 0 0 0 0
40974 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40975 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40976 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40977 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40978 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40979 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40980 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40981 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40982 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40983 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40984 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40985 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40986 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40987 +37 38 37 0 0 0
40988 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40989 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40990 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40991 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40992 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40993 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40994 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40995 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40996 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40997 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40998 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40999 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41000 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41001 +85 115 134 4 0 0
41002 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41003 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41004 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41005 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41006 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41007 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41008 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41009 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41010 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41011 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41012 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41013 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41014 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41015 +60 73 81 4 0 0
41016 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41017 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41018 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41019 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41020 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41021 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41022 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41023 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41024 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41025 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41026 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41027 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41028 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41029 +16 19 21 4 0 0
41030 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41031 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41032 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41033 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41034 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41035 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41036 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41037 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41038 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41039 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41040 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41041 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41042 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41043 +4 0 0 4 3 3
41044 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41045 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41046 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41048 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41049 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41050 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41051 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41052 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41053 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41054 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41055 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41056 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41057 +3 2 2 4 4 4
41058 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41059 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41060 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41061 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41062 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41063 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41064 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41065 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41066 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41067 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41068 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41069 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41070 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41071 +4 4 4 4 4 4
41072 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41073 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41074 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41075 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41076 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41077 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41078 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41079 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41080 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41081 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41082 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41083 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41084 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41085 +4 4 4 4 4 4
41086 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41087 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41088 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41089 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41090 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41091 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41092 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41093 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41094 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41095 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41096 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41097 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41098 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41099 +5 5 5 5 5 5
41100 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41101 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41102 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41103 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41104 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41105 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41106 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41107 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41108 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41109 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41110 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41111 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41112 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41113 +5 5 5 4 4 4
41114 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41115 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41116 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41117 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41118 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41119 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41120 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41121 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41122 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41123 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41124 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41125 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41127 +4 4 4 4 4 4
41128 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41129 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41130 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41131 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41132 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41133 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41134 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41135 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41136 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41137 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41138 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41139 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141 +4 4 4 4 4 4
41142 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41143 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41144 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41145 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41146 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41147 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41148 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41149 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41150 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41151 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41152 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155 +4 4 4 4 4 4
41156 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41157 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41158 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41159 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41160 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41161 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41162 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41163 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41164 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41165 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41166 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169 +4 4 4 4 4 4
41170 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41171 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41172 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41173 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41174 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41175 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41176 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41177 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41178 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41179 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41180 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183 +4 4 4 4 4 4
41184 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41185 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41186 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41187 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41188 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41189 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41190 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41191 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41192 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41193 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41194 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197 +4 4 4 4 4 4
41198 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41199 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41200 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41201 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41202 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41203 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41204 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41205 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41206 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41207 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41208 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211 +4 4 4 4 4 4
41212 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41213 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41214 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41215 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41216 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41217 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41218 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41219 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41220 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41221 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41222 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225 +4 4 4 4 4 4
41226 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41227 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41228 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41229 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41230 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41231 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41232 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41233 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41234 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41235 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41236 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4
41240 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41241 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41242 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41243 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41244 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41245 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41246 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41247 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41248 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41249 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41250 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253 +4 4 4 4 4 4
41254 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41255 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41256 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41257 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41258 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41259 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41260 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41261 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41262 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41263 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41264 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267 +4 4 4 4 4 4
41268 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41269 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41270 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41271 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41272 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41273 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41274 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41275 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41276 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41277 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41278 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281 +4 4 4 4 4 4
41282 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41283 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41284 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41285 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41286 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41287 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41288 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41289 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41290 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41291 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41292 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295 +4 4 4 4 4 4
41296 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41297 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41298 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41299 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41300 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41301 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41302 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41303 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41304 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41305 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41306 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309 +4 4 4 4 4 4
41310 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41311 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41312 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41313 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41314 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41315 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41316 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41317 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41318 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41319 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41320 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323 +4 4 4 4 4 4
41324 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41325 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41326 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41327 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41328 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41329 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41330 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41331 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41332 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41333 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41334 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4
41338 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41339 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41340 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41341 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41342 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41343 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41344 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41345 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41346 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41347 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41348 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4
41352 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41353 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41354 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41355 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41356 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41357 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41358 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41359 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41360 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41361 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41362 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4
41366 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41367 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41368 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41369 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41370 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41371 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41372 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41373 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41374 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41375 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41376 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4
41380 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41381 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41382 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41383 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41384 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41385 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41386 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41387 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41388 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41389 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41390 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4
41394 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41395 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41396 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41397 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41398 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41399 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41400 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41401 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41402 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41403 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41404 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4
41408 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41409 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41410 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41411 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41412 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41413 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41414 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41415 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41416 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41417 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41418 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41421 +4 4 4 4 4 4
41422 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41423 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41424 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41425 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41426 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41427 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41428 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41429 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41430 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41431 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41432 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4
41436 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41437 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41438 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41439 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41440 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41441 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41442 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41443 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41444 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41445 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41446 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449 +4 4 4 4 4 4
41450 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41451 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41452 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41453 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41454 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41455 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41456 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41457 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41458 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41459 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41460 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463 +4 4 4 4 4 4
41464 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41465 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41466 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41467 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41468 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41469 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41470 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41471 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41472 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41473 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41474 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477 +4 4 4 4 4 4
41478 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41479 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41480 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41481 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41482 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41483 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41484 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41485 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41486 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41487 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41488 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41491 +4 4 4 4 4 4
41492 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41493 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41494 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41495 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41496 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41497 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41498 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41499 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41500 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41501 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41502 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41505 +4 4 4 4 4 4
41506 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41507 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41508 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41509 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41510 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41511 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41512 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41513 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41514 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41515 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41516 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519 +4 4 4 4 4 4
41520 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41521 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41522 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41523 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41524 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41525 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41526 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41527 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41528 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41529 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41533 +4 4 4 4 4 4
41534 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41535 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41536 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41537 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41538 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41539 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41540 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41541 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41542 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41543 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
41546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41547 +4 4 4 4 4 4
41548 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41549 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41550 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41551 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41552 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41553 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41554 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41555 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41556 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41557 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561 +4 4 4 4 4 4
41562 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41563 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41564 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41565 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41566 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41567 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41568 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41569 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41570 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41571 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41575 +4 4 4 4 4 4
41576 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41577 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41578 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41579 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41580 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41581 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41582 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41583 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41584 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
41588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41589 +4 4 4 4 4 4
41590 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41591 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41592 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41593 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41594 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41595 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41596 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41597 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41598 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
41602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41603 +4 4 4 4 4 4
41604 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41605 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41606 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41607 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41608 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41609 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41610 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41611 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41612 +4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
41616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41617 +4 4 4 4 4 4
41618 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41619 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41620 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41621 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41622 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41623 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41624 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41625 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
41630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41631 +4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41633 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41634 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41635 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41636 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41637 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41638 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41639 +6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
41644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41645 +4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41647 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41648 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41649 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41650 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41651 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41652 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41653 +4 0 0 4 3 3 6 6 6 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659 +4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41662 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41663 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41664 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41665 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41666 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41667 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673 +4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41676 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41677 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41678 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41679 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41680 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41681 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41687 +4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41691 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41692 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41693 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41694 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41695 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41701 +4 4 4 4 4 4
41702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41705 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41706 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41707 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41708 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
41714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41715 +4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41720 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41721 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41722 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41729 +4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41734 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41735 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41736 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41743 +4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41748 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41749 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41750 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41757 +4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41762 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41763 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41764 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771 +4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41776 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41777 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41778 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
41784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785 +4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41790 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41791 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41792 +5 5 5 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 4 4 4 4 4 4 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
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41804 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41805 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41818 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41819 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
41828 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41829 index 8af6414..658c030 100644
41830 --- a/drivers/video/udlfb.c
41831 +++ b/drivers/video/udlfb.c
41832 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41833 dlfb_urb_completion(urb);
41834
41835 error:
41836 - atomic_add(bytes_sent, &dev->bytes_sent);
41837 - atomic_add(bytes_identical, &dev->bytes_identical);
41838 - atomic_add(width*height*2, &dev->bytes_rendered);
41839 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41840 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41841 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41842 end_cycles = get_cycles();
41843 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41844 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41845 >> 10)), /* Kcycles */
41846 &dev->cpu_kcycles_used);
41847
41848 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41849 dlfb_urb_completion(urb);
41850
41851 error:
41852 - atomic_add(bytes_sent, &dev->bytes_sent);
41853 - atomic_add(bytes_identical, &dev->bytes_identical);
41854 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41855 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41856 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41857 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41858 end_cycles = get_cycles();
41859 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41860 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41861 >> 10)), /* Kcycles */
41862 &dev->cpu_kcycles_used);
41863 }
41864 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41865 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41866 struct dlfb_data *dev = fb_info->par;
41867 return snprintf(buf, PAGE_SIZE, "%u\n",
41868 - atomic_read(&dev->bytes_rendered));
41869 + atomic_read_unchecked(&dev->bytes_rendered));
41870 }
41871
41872 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41873 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41874 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41875 struct dlfb_data *dev = fb_info->par;
41876 return snprintf(buf, PAGE_SIZE, "%u\n",
41877 - atomic_read(&dev->bytes_identical));
41878 + atomic_read_unchecked(&dev->bytes_identical));
41879 }
41880
41881 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41882 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41883 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41884 struct dlfb_data *dev = fb_info->par;
41885 return snprintf(buf, PAGE_SIZE, "%u\n",
41886 - atomic_read(&dev->bytes_sent));
41887 + atomic_read_unchecked(&dev->bytes_sent));
41888 }
41889
41890 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41891 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41892 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41893 struct dlfb_data *dev = fb_info->par;
41894 return snprintf(buf, PAGE_SIZE, "%u\n",
41895 - atomic_read(&dev->cpu_kcycles_used));
41896 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41897 }
41898
41899 static ssize_t edid_show(
41900 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41901 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41902 struct dlfb_data *dev = fb_info->par;
41903
41904 - atomic_set(&dev->bytes_rendered, 0);
41905 - atomic_set(&dev->bytes_identical, 0);
41906 - atomic_set(&dev->bytes_sent, 0);
41907 - atomic_set(&dev->cpu_kcycles_used, 0);
41908 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41909 + atomic_set_unchecked(&dev->bytes_identical, 0);
41910 + atomic_set_unchecked(&dev->bytes_sent, 0);
41911 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41912
41913 return count;
41914 }
41915 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41916 index b0e2a42..e2df3ad 100644
41917 --- a/drivers/video/uvesafb.c
41918 +++ b/drivers/video/uvesafb.c
41919 @@ -19,6 +19,7 @@
41920 #include <linux/io.h>
41921 #include <linux/mutex.h>
41922 #include <linux/slab.h>
41923 +#include <linux/moduleloader.h>
41924 #include <video/edid.h>
41925 #include <video/uvesafb.h>
41926 #ifdef CONFIG_X86
41927 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41928 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41929 par->pmi_setpal = par->ypan = 0;
41930 } else {
41931 +
41932 +#ifdef CONFIG_PAX_KERNEXEC
41933 +#ifdef CONFIG_MODULES
41934 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41935 +#endif
41936 + if (!par->pmi_code) {
41937 + par->pmi_setpal = par->ypan = 0;
41938 + return 0;
41939 + }
41940 +#endif
41941 +
41942 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41943 + task->t.regs.edi);
41944 +
41945 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41946 + pax_open_kernel();
41947 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41948 + pax_close_kernel();
41949 +
41950 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41951 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41952 +#else
41953 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41954 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41955 +#endif
41956 +
41957 printk(KERN_INFO "uvesafb: protected mode interface info at "
41958 "%04x:%04x\n",
41959 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41960 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41961 par->ypan = ypan;
41962
41963 if (par->pmi_setpal || par->ypan) {
41964 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41965 if (__supported_pte_mask & _PAGE_NX) {
41966 par->pmi_setpal = par->ypan = 0;
41967 printk(KERN_WARNING "uvesafb: NX protection is actively."
41968 "We have better not to use the PMI.\n");
41969 - } else {
41970 + } else
41971 +#endif
41972 uvesafb_vbe_getpmi(task, par);
41973 - }
41974 }
41975 #else
41976 /* The protected mode interface is not available on non-x86. */
41977 @@ -1836,6 +1860,11 @@ out:
41978 if (par->vbe_modes)
41979 kfree(par->vbe_modes);
41980
41981 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41982 + if (par->pmi_code)
41983 + module_free_exec(NULL, par->pmi_code);
41984 +#endif
41985 +
41986 framebuffer_release(info);
41987 return err;
41988 }
41989 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41990 kfree(par->vbe_state_orig);
41991 if (par->vbe_state_saved)
41992 kfree(par->vbe_state_saved);
41993 +
41994 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41995 + if (par->pmi_code)
41996 + module_free_exec(NULL, par->pmi_code);
41997 +#endif
41998 +
41999 }
42000
42001 framebuffer_release(info);
42002 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42003 index 501b340..86bd4cf 100644
42004 --- a/drivers/video/vesafb.c
42005 +++ b/drivers/video/vesafb.c
42006 @@ -9,6 +9,7 @@
42007 */
42008
42009 #include <linux/module.h>
42010 +#include <linux/moduleloader.h>
42011 #include <linux/kernel.h>
42012 #include <linux/errno.h>
42013 #include <linux/string.h>
42014 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42015 static int vram_total __initdata; /* Set total amount of memory */
42016 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42017 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42018 -static void (*pmi_start)(void) __read_mostly;
42019 -static void (*pmi_pal) (void) __read_mostly;
42020 +static void (*pmi_start)(void) __read_only;
42021 +static void (*pmi_pal) (void) __read_only;
42022 static int depth __read_mostly;
42023 static int vga_compat __read_mostly;
42024 /* --------------------------------------------------------------------- */
42025 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42026 unsigned int size_vmode;
42027 unsigned int size_remap;
42028 unsigned int size_total;
42029 + void *pmi_code = NULL;
42030
42031 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42032 return -ENODEV;
42033 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42034 size_remap = size_total;
42035 vesafb_fix.smem_len = size_remap;
42036
42037 -#ifndef __i386__
42038 - screen_info.vesapm_seg = 0;
42039 -#endif
42040 -
42041 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42042 printk(KERN_WARNING
42043 "vesafb: cannot reserve video memory at 0x%lx\n",
42044 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42045 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42046 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42047
42048 +#ifdef __i386__
42049 +
42050 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42051 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42052 + if (!pmi_code)
42053 +#elif !defined(CONFIG_PAX_KERNEXEC)
42054 + if (0)
42055 +#endif
42056 +
42057 +#endif
42058 + screen_info.vesapm_seg = 0;
42059 +
42060 if (screen_info.vesapm_seg) {
42061 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42062 - screen_info.vesapm_seg,screen_info.vesapm_off);
42063 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42064 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42065 }
42066
42067 if (screen_info.vesapm_seg < 0xc000)
42068 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42069
42070 if (ypan || pmi_setpal) {
42071 unsigned short *pmi_base;
42072 +
42073 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42074 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42075 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42076 +
42077 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42078 + pax_open_kernel();
42079 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42080 +#else
42081 + pmi_code = pmi_base;
42082 +#endif
42083 +
42084 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42085 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42086 +
42087 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42088 + pmi_start = ktva_ktla(pmi_start);
42089 + pmi_pal = ktva_ktla(pmi_pal);
42090 + pax_close_kernel();
42091 +#endif
42092 +
42093 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42094 if (pmi_base[3]) {
42095 printk(KERN_INFO "vesafb: pmi: ports = ");
42096 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42097 info->node, info->fix.id);
42098 return 0;
42099 err:
42100 +
42101 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42102 + module_free_exec(NULL, pmi_code);
42103 +#endif
42104 +
42105 if (info->screen_base)
42106 iounmap(info->screen_base);
42107 framebuffer_release(info);
42108 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42109 index 88714ae..16c2e11 100644
42110 --- a/drivers/video/via/via_clock.h
42111 +++ b/drivers/video/via/via_clock.h
42112 @@ -56,7 +56,7 @@ struct via_clock {
42113
42114 void (*set_engine_pll_state)(u8 state);
42115 void (*set_engine_pll)(struct via_pll_config config);
42116 -};
42117 +} __no_const;
42118
42119
42120 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42121 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42122 index e56c934..fc22f4b 100644
42123 --- a/drivers/xen/xen-pciback/conf_space.h
42124 +++ b/drivers/xen/xen-pciback/conf_space.h
42125 @@ -44,15 +44,15 @@ struct config_field {
42126 struct {
42127 conf_dword_write write;
42128 conf_dword_read read;
42129 - } dw;
42130 + } __no_const dw;
42131 struct {
42132 conf_word_write write;
42133 conf_word_read read;
42134 - } w;
42135 + } __no_const w;
42136 struct {
42137 conf_byte_write write;
42138 conf_byte_read read;
42139 - } b;
42140 + } __no_const b;
42141 } u;
42142 struct list_head list;
42143 };
42144 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42145 index 57ccb75..f6d05f8 100644
42146 --- a/fs/9p/vfs_inode.c
42147 +++ b/fs/9p/vfs_inode.c
42148 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42149 void
42150 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42151 {
42152 - char *s = nd_get_link(nd);
42153 + const char *s = nd_get_link(nd);
42154
42155 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42156 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42157 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42158 index 0225742..1cd4732 100644
42159 --- a/fs/Kconfig.binfmt
42160 +++ b/fs/Kconfig.binfmt
42161 @@ -89,7 +89,7 @@ config HAVE_AOUT
42162
42163 config BINFMT_AOUT
42164 tristate "Kernel support for a.out and ECOFF binaries"
42165 - depends on HAVE_AOUT
42166 + depends on HAVE_AOUT && BROKEN
42167 ---help---
42168 A.out (Assembler.OUTput) is a set of formats for libraries and
42169 executables used in the earliest versions of UNIX. Linux used
42170 diff --git a/fs/aio.c b/fs/aio.c
42171 index 55c4c76..11aee6f 100644
42172 --- a/fs/aio.c
42173 +++ b/fs/aio.c
42174 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42175 size += sizeof(struct io_event) * nr_events;
42176 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42177
42178 - if (nr_pages < 0)
42179 + if (nr_pages <= 0)
42180 return -EINVAL;
42181
42182 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42183 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42184 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42185 {
42186 ssize_t ret;
42187 + struct iovec iovstack;
42188
42189 #ifdef CONFIG_COMPAT
42190 if (compat)
42191 ret = compat_rw_copy_check_uvector(type,
42192 (struct compat_iovec __user *)kiocb->ki_buf,
42193 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42194 + kiocb->ki_nbytes, 1, &iovstack,
42195 &kiocb->ki_iovec);
42196 else
42197 #endif
42198 ret = rw_copy_check_uvector(type,
42199 (struct iovec __user *)kiocb->ki_buf,
42200 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42201 + kiocb->ki_nbytes, 1, &iovstack,
42202 &kiocb->ki_iovec);
42203 if (ret < 0)
42204 goto out;
42205 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42206 if (ret < 0)
42207 goto out;
42208
42209 + if (kiocb->ki_iovec == &iovstack) {
42210 + kiocb->ki_inline_vec = iovstack;
42211 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42212 + }
42213 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42214 kiocb->ki_cur_seg = 0;
42215 /* ki_nbytes/left now reflect bytes instead of segs */
42216 diff --git a/fs/attr.c b/fs/attr.c
42217 index 0da9095..1386693 100644
42218 --- a/fs/attr.c
42219 +++ b/fs/attr.c
42220 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42221 unsigned long limit;
42222
42223 limit = rlimit(RLIMIT_FSIZE);
42224 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42225 if (limit != RLIM_INFINITY && offset > limit)
42226 goto out_sig;
42227 if (offset > inode->i_sb->s_maxbytes)
42228 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42229 index da8876d..9f3e6d8 100644
42230 --- a/fs/autofs4/waitq.c
42231 +++ b/fs/autofs4/waitq.c
42232 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42233 {
42234 unsigned long sigpipe, flags;
42235 mm_segment_t fs;
42236 - const char *data = (const char *)addr;
42237 + const char __user *data = (const char __force_user *)addr;
42238 ssize_t wr = 0;
42239
42240 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42241 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42242 index e18da23..affc30e 100644
42243 --- a/fs/befs/linuxvfs.c
42244 +++ b/fs/befs/linuxvfs.c
42245 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42246 {
42247 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42248 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42249 - char *link = nd_get_link(nd);
42250 + const char *link = nd_get_link(nd);
42251 if (!IS_ERR(link))
42252 kfree(link);
42253 }
42254 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42255 index d146e18..12d1bd1 100644
42256 --- a/fs/binfmt_aout.c
42257 +++ b/fs/binfmt_aout.c
42258 @@ -16,6 +16,7 @@
42259 #include <linux/string.h>
42260 #include <linux/fs.h>
42261 #include <linux/file.h>
42262 +#include <linux/security.h>
42263 #include <linux/stat.h>
42264 #include <linux/fcntl.h>
42265 #include <linux/ptrace.h>
42266 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42267 #endif
42268 # define START_STACK(u) ((void __user *)u.start_stack)
42269
42270 + memset(&dump, 0, sizeof(dump));
42271 +
42272 fs = get_fs();
42273 set_fs(KERNEL_DS);
42274 has_dumped = 1;
42275 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42276
42277 /* If the size of the dump file exceeds the rlimit, then see what would happen
42278 if we wrote the stack, but not the data area. */
42279 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42280 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42281 dump.u_dsize = 0;
42282
42283 /* Make sure we have enough room to write the stack and data areas. */
42284 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42285 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42286 dump.u_ssize = 0;
42287
42288 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42289 rlim = rlimit(RLIMIT_DATA);
42290 if (rlim >= RLIM_INFINITY)
42291 rlim = ~0;
42292 +
42293 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42294 if (ex.a_data + ex.a_bss > rlim)
42295 return -ENOMEM;
42296
42297 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42298
42299 install_exec_creds(bprm);
42300
42301 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42302 + current->mm->pax_flags = 0UL;
42303 +#endif
42304 +
42305 +#ifdef CONFIG_PAX_PAGEEXEC
42306 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42307 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42308 +
42309 +#ifdef CONFIG_PAX_EMUTRAMP
42310 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42311 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42312 +#endif
42313 +
42314 +#ifdef CONFIG_PAX_MPROTECT
42315 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42316 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42317 +#endif
42318 +
42319 + }
42320 +#endif
42321 +
42322 if (N_MAGIC(ex) == OMAGIC) {
42323 unsigned long text_addr, map_size;
42324 loff_t pos;
42325 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42326 }
42327
42328 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42329 - PROT_READ | PROT_WRITE | PROT_EXEC,
42330 + PROT_READ | PROT_WRITE,
42331 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42332 fd_offset + ex.a_text);
42333 if (error != N_DATADDR(ex)) {
42334 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42335 index 1b52956..271266e 100644
42336 --- a/fs/binfmt_elf.c
42337 +++ b/fs/binfmt_elf.c
42338 @@ -32,6 +32,7 @@
42339 #include <linux/elf.h>
42340 #include <linux/utsname.h>
42341 #include <linux/coredump.h>
42342 +#include <linux/xattr.h>
42343 #include <asm/uaccess.h>
42344 #include <asm/param.h>
42345 #include <asm/page.h>
42346 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42347 #define elf_core_dump NULL
42348 #endif
42349
42350 +#ifdef CONFIG_PAX_MPROTECT
42351 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42352 +#endif
42353 +
42354 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42355 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42356 #else
42357 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42358 .load_binary = load_elf_binary,
42359 .load_shlib = load_elf_library,
42360 .core_dump = elf_core_dump,
42361 +
42362 +#ifdef CONFIG_PAX_MPROTECT
42363 + .handle_mprotect= elf_handle_mprotect,
42364 +#endif
42365 +
42366 .min_coredump = ELF_EXEC_PAGESIZE,
42367 };
42368
42369 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42370
42371 static int set_brk(unsigned long start, unsigned long end)
42372 {
42373 + unsigned long e = end;
42374 +
42375 start = ELF_PAGEALIGN(start);
42376 end = ELF_PAGEALIGN(end);
42377 if (end > start) {
42378 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42379 if (BAD_ADDR(addr))
42380 return addr;
42381 }
42382 - current->mm->start_brk = current->mm->brk = end;
42383 + current->mm->start_brk = current->mm->brk = e;
42384 return 0;
42385 }
42386
42387 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42388 elf_addr_t __user *u_rand_bytes;
42389 const char *k_platform = ELF_PLATFORM;
42390 const char *k_base_platform = ELF_BASE_PLATFORM;
42391 - unsigned char k_rand_bytes[16];
42392 + u32 k_rand_bytes[4];
42393 int items;
42394 elf_addr_t *elf_info;
42395 int ei_index = 0;
42396 const struct cred *cred = current_cred();
42397 struct vm_area_struct *vma;
42398 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42399
42400 /*
42401 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42402 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42403 * Generate 16 random bytes for userspace PRNG seeding.
42404 */
42405 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42406 - u_rand_bytes = (elf_addr_t __user *)
42407 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42408 + srandom32(k_rand_bytes[0] ^ random32());
42409 + srandom32(k_rand_bytes[1] ^ random32());
42410 + srandom32(k_rand_bytes[2] ^ random32());
42411 + srandom32(k_rand_bytes[3] ^ random32());
42412 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42413 + u_rand_bytes = (elf_addr_t __user *) p;
42414 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42415 return -EFAULT;
42416
42417 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42418 return -EFAULT;
42419 current->mm->env_end = p;
42420
42421 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42422 +
42423 /* Put the elf_info on the stack in the right place. */
42424 sp = (elf_addr_t __user *)envp + 1;
42425 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42426 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42427 return -EFAULT;
42428 return 0;
42429 }
42430 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42431 {
42432 struct elf_phdr *elf_phdata;
42433 struct elf_phdr *eppnt;
42434 - unsigned long load_addr = 0;
42435 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42436 int load_addr_set = 0;
42437 unsigned long last_bss = 0, elf_bss = 0;
42438 - unsigned long error = ~0UL;
42439 + unsigned long error = -EINVAL;
42440 unsigned long total_size;
42441 int retval, i, size;
42442
42443 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42444 goto out_close;
42445 }
42446
42447 +#ifdef CONFIG_PAX_SEGMEXEC
42448 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42449 + pax_task_size = SEGMEXEC_TASK_SIZE;
42450 +#endif
42451 +
42452 eppnt = elf_phdata;
42453 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42454 if (eppnt->p_type == PT_LOAD) {
42455 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42456 k = load_addr + eppnt->p_vaddr;
42457 if (BAD_ADDR(k) ||
42458 eppnt->p_filesz > eppnt->p_memsz ||
42459 - eppnt->p_memsz > TASK_SIZE ||
42460 - TASK_SIZE - eppnt->p_memsz < k) {
42461 + eppnt->p_memsz > pax_task_size ||
42462 + pax_task_size - eppnt->p_memsz < k) {
42463 error = -ENOMEM;
42464 goto out_close;
42465 }
42466 @@ -523,6 +547,311 @@ out:
42467 return error;
42468 }
42469
42470 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42471 +#ifdef CONFIG_PAX_SOFTMODE
42472 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42473 +{
42474 + unsigned long pax_flags = 0UL;
42475 +
42476 +#ifdef CONFIG_PAX_PAGEEXEC
42477 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42478 + pax_flags |= MF_PAX_PAGEEXEC;
42479 +#endif
42480 +
42481 +#ifdef CONFIG_PAX_SEGMEXEC
42482 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42483 + pax_flags |= MF_PAX_SEGMEXEC;
42484 +#endif
42485 +
42486 +#ifdef CONFIG_PAX_EMUTRAMP
42487 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42488 + pax_flags |= MF_PAX_EMUTRAMP;
42489 +#endif
42490 +
42491 +#ifdef CONFIG_PAX_MPROTECT
42492 + if (elf_phdata->p_flags & PF_MPROTECT)
42493 + pax_flags |= MF_PAX_MPROTECT;
42494 +#endif
42495 +
42496 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42497 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42498 + pax_flags |= MF_PAX_RANDMMAP;
42499 +#endif
42500 +
42501 + return pax_flags;
42502 +}
42503 +#endif
42504 +
42505 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42506 +{
42507 + unsigned long pax_flags = 0UL;
42508 +
42509 +#ifdef CONFIG_PAX_PAGEEXEC
42510 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42511 + pax_flags |= MF_PAX_PAGEEXEC;
42512 +#endif
42513 +
42514 +#ifdef CONFIG_PAX_SEGMEXEC
42515 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42516 + pax_flags |= MF_PAX_SEGMEXEC;
42517 +#endif
42518 +
42519 +#ifdef CONFIG_PAX_EMUTRAMP
42520 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42521 + pax_flags |= MF_PAX_EMUTRAMP;
42522 +#endif
42523 +
42524 +#ifdef CONFIG_PAX_MPROTECT
42525 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42526 + pax_flags |= MF_PAX_MPROTECT;
42527 +#endif
42528 +
42529 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42530 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42531 + pax_flags |= MF_PAX_RANDMMAP;
42532 +#endif
42533 +
42534 + return pax_flags;
42535 +}
42536 +#endif
42537 +
42538 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42539 +#ifdef CONFIG_PAX_SOFTMODE
42540 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42541 +{
42542 + unsigned long pax_flags = 0UL;
42543 +
42544 +#ifdef CONFIG_PAX_PAGEEXEC
42545 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42546 + pax_flags |= MF_PAX_PAGEEXEC;
42547 +#endif
42548 +
42549 +#ifdef CONFIG_PAX_SEGMEXEC
42550 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42551 + pax_flags |= MF_PAX_SEGMEXEC;
42552 +#endif
42553 +
42554 +#ifdef CONFIG_PAX_EMUTRAMP
42555 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42556 + pax_flags |= MF_PAX_EMUTRAMP;
42557 +#endif
42558 +
42559 +#ifdef CONFIG_PAX_MPROTECT
42560 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42561 + pax_flags |= MF_PAX_MPROTECT;
42562 +#endif
42563 +
42564 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42565 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42566 + pax_flags |= MF_PAX_RANDMMAP;
42567 +#endif
42568 +
42569 + return pax_flags;
42570 +}
42571 +#endif
42572 +
42573 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42574 +{
42575 + unsigned long pax_flags = 0UL;
42576 +
42577 +#ifdef CONFIG_PAX_PAGEEXEC
42578 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42579 + pax_flags |= MF_PAX_PAGEEXEC;
42580 +#endif
42581 +
42582 +#ifdef CONFIG_PAX_SEGMEXEC
42583 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42584 + pax_flags |= MF_PAX_SEGMEXEC;
42585 +#endif
42586 +
42587 +#ifdef CONFIG_PAX_EMUTRAMP
42588 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42589 + pax_flags |= MF_PAX_EMUTRAMP;
42590 +#endif
42591 +
42592 +#ifdef CONFIG_PAX_MPROTECT
42593 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42594 + pax_flags |= MF_PAX_MPROTECT;
42595 +#endif
42596 +
42597 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42598 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42599 + pax_flags |= MF_PAX_RANDMMAP;
42600 +#endif
42601 +
42602 + return pax_flags;
42603 +}
42604 +#endif
42605 +
42606 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42607 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42608 +{
42609 + unsigned long pax_flags = 0UL;
42610 +
42611 +#ifdef CONFIG_PAX_EI_PAX
42612 +
42613 +#ifdef CONFIG_PAX_PAGEEXEC
42614 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42615 + pax_flags |= MF_PAX_PAGEEXEC;
42616 +#endif
42617 +
42618 +#ifdef CONFIG_PAX_SEGMEXEC
42619 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42620 + pax_flags |= MF_PAX_SEGMEXEC;
42621 +#endif
42622 +
42623 +#ifdef CONFIG_PAX_EMUTRAMP
42624 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42625 + pax_flags |= MF_PAX_EMUTRAMP;
42626 +#endif
42627 +
42628 +#ifdef CONFIG_PAX_MPROTECT
42629 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42630 + pax_flags |= MF_PAX_MPROTECT;
42631 +#endif
42632 +
42633 +#ifdef CONFIG_PAX_ASLR
42634 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42635 + pax_flags |= MF_PAX_RANDMMAP;
42636 +#endif
42637 +
42638 +#else
42639 +
42640 +#ifdef CONFIG_PAX_PAGEEXEC
42641 + pax_flags |= MF_PAX_PAGEEXEC;
42642 +#endif
42643 +
42644 +#ifdef CONFIG_PAX_SEGMEXEC
42645 + pax_flags |= MF_PAX_SEGMEXEC;
42646 +#endif
42647 +
42648 +#ifdef CONFIG_PAX_MPROTECT
42649 + pax_flags |= MF_PAX_MPROTECT;
42650 +#endif
42651 +
42652 +#ifdef CONFIG_PAX_RANDMMAP
42653 + if (randomize_va_space)
42654 + pax_flags |= MF_PAX_RANDMMAP;
42655 +#endif
42656 +
42657 +#endif
42658 +
42659 + return pax_flags;
42660 +}
42661 +
42662 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42663 +{
42664 +
42665 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42666 + unsigned long i;
42667 +
42668 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42669 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42670 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42671 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42672 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42673 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42674 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42675 + return ~0UL;
42676 +
42677 +#ifdef CONFIG_PAX_SOFTMODE
42678 + if (pax_softmode)
42679 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42680 + else
42681 +#endif
42682 +
42683 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42684 + break;
42685 + }
42686 +#endif
42687 +
42688 + return ~0UL;
42689 +}
42690 +
42691 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42692 +{
42693 +
42694 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42695 + ssize_t xattr_size, i;
42696 + unsigned char xattr_value[5];
42697 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42698 +
42699 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42700 + if (xattr_size <= 0)
42701 + return ~0UL;
42702 +
42703 + for (i = 0; i < xattr_size; i++)
42704 + switch (xattr_value[i]) {
42705 + default:
42706 + return ~0UL;
42707 +
42708 +#define parse_flag(option1, option2, flag) \
42709 + case option1: \
42710 + pax_flags_hardmode |= MF_PAX_##flag; \
42711 + break; \
42712 + case option2: \
42713 + pax_flags_softmode |= MF_PAX_##flag; \
42714 + break;
42715 +
42716 + parse_flag('p', 'P', PAGEEXEC);
42717 + parse_flag('e', 'E', EMUTRAMP);
42718 + parse_flag('m', 'M', MPROTECT);
42719 + parse_flag('r', 'R', RANDMMAP);
42720 + parse_flag('s', 'S', SEGMEXEC);
42721 +
42722 +#undef parse_flag
42723 + }
42724 +
42725 + if (pax_flags_hardmode & pax_flags_softmode)
42726 + return ~0UL;
42727 +
42728 +#ifdef CONFIG_PAX_SOFTMODE
42729 + if (pax_softmode)
42730 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42731 + else
42732 +#endif
42733 +
42734 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42735 +#else
42736 + return ~0UL;
42737 +#endif
42738 +
42739 +}
42740 +
42741 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42742 +{
42743 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42744 +
42745 + pax_flags = pax_parse_ei_pax(elf_ex);
42746 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42747 + xattr_pax_flags = pax_parse_xattr_pax(file);
42748 +
42749 + if (pt_pax_flags == ~0UL)
42750 + pt_pax_flags = xattr_pax_flags;
42751 + else if (xattr_pax_flags == ~0UL)
42752 + xattr_pax_flags = pt_pax_flags;
42753 + if (pt_pax_flags != xattr_pax_flags)
42754 + return -EINVAL;
42755 + if (pt_pax_flags != ~0UL)
42756 + pax_flags = pt_pax_flags;
42757 +
42758 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42759 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42760 + if ((__supported_pte_mask & _PAGE_NX))
42761 + pax_flags &= ~MF_PAX_SEGMEXEC;
42762 + else
42763 + pax_flags &= ~MF_PAX_PAGEEXEC;
42764 + }
42765 +#endif
42766 +
42767 + if (0 > pax_check_flags(&pax_flags))
42768 + return -EINVAL;
42769 +
42770 + current->mm->pax_flags = pax_flags;
42771 + return 0;
42772 +}
42773 +#endif
42774 +
42775 /*
42776 * These are the functions used to load ELF style executables and shared
42777 * libraries. There is no binary dependent code anywhere else.
42778 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42779 {
42780 unsigned int random_variable = 0;
42781
42782 +#ifdef CONFIG_PAX_RANDUSTACK
42783 + if (randomize_va_space)
42784 + return stack_top - current->mm->delta_stack;
42785 +#endif
42786 +
42787 if ((current->flags & PF_RANDOMIZE) &&
42788 !(current->personality & ADDR_NO_RANDOMIZE)) {
42789 random_variable = get_random_int() & STACK_RND_MASK;
42790 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42791 unsigned long load_addr = 0, load_bias = 0;
42792 int load_addr_set = 0;
42793 char * elf_interpreter = NULL;
42794 - unsigned long error;
42795 + unsigned long error = 0;
42796 struct elf_phdr *elf_ppnt, *elf_phdata;
42797 unsigned long elf_bss, elf_brk;
42798 int retval, i;
42799 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42800 unsigned long start_code, end_code, start_data, end_data;
42801 unsigned long reloc_func_desc __maybe_unused = 0;
42802 int executable_stack = EXSTACK_DEFAULT;
42803 - unsigned long def_flags = 0;
42804 struct {
42805 struct elfhdr elf_ex;
42806 struct elfhdr interp_elf_ex;
42807 } *loc;
42808 + unsigned long pax_task_size = TASK_SIZE;
42809
42810 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42811 if (!loc) {
42812 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42813 goto out_free_dentry;
42814
42815 /* OK, This is the point of no return */
42816 - current->mm->def_flags = def_flags;
42817 +
42818 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42819 + current->mm->pax_flags = 0UL;
42820 +#endif
42821 +
42822 +#ifdef CONFIG_PAX_DLRESOLVE
42823 + current->mm->call_dl_resolve = 0UL;
42824 +#endif
42825 +
42826 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42827 + current->mm->call_syscall = 0UL;
42828 +#endif
42829 +
42830 +#ifdef CONFIG_PAX_ASLR
42831 + current->mm->delta_mmap = 0UL;
42832 + current->mm->delta_stack = 0UL;
42833 +#endif
42834 +
42835 + current->mm->def_flags = 0;
42836 +
42837 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42838 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42839 + send_sig(SIGKILL, current, 0);
42840 + goto out_free_dentry;
42841 + }
42842 +#endif
42843 +
42844 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42845 + pax_set_initial_flags(bprm);
42846 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42847 + if (pax_set_initial_flags_func)
42848 + (pax_set_initial_flags_func)(bprm);
42849 +#endif
42850 +
42851 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42852 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42853 + current->mm->context.user_cs_limit = PAGE_SIZE;
42854 + current->mm->def_flags |= VM_PAGEEXEC;
42855 + }
42856 +#endif
42857 +
42858 +#ifdef CONFIG_PAX_SEGMEXEC
42859 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42860 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42861 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42862 + pax_task_size = SEGMEXEC_TASK_SIZE;
42863 + current->mm->def_flags |= VM_NOHUGEPAGE;
42864 + }
42865 +#endif
42866 +
42867 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42868 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42869 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42870 + put_cpu();
42871 + }
42872 +#endif
42873
42874 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42875 may depend on the personality. */
42876 SET_PERSONALITY(loc->elf_ex);
42877 +
42878 +#ifdef CONFIG_PAX_ASLR
42879 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42880 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42881 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42882 + }
42883 +#endif
42884 +
42885 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42886 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42887 + executable_stack = EXSTACK_DISABLE_X;
42888 + current->personality &= ~READ_IMPLIES_EXEC;
42889 + } else
42890 +#endif
42891 +
42892 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42893 current->personality |= READ_IMPLIES_EXEC;
42894
42895 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42896 #else
42897 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42898 #endif
42899 +
42900 +#ifdef CONFIG_PAX_RANDMMAP
42901 + /* PaX: randomize base address at the default exe base if requested */
42902 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42903 +#ifdef CONFIG_SPARC64
42904 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42905 +#else
42906 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42907 +#endif
42908 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42909 + elf_flags |= MAP_FIXED;
42910 + }
42911 +#endif
42912 +
42913 }
42914
42915 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42916 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42917 * allowed task size. Note that p_filesz must always be
42918 * <= p_memsz so it is only necessary to check p_memsz.
42919 */
42920 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42921 - elf_ppnt->p_memsz > TASK_SIZE ||
42922 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42923 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42924 + elf_ppnt->p_memsz > pax_task_size ||
42925 + pax_task_size - elf_ppnt->p_memsz < k) {
42926 /* set_brk can never work. Avoid overflows. */
42927 send_sig(SIGKILL, current, 0);
42928 retval = -EINVAL;
42929 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42930 goto out_free_dentry;
42931 }
42932 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42933 - send_sig(SIGSEGV, current, 0);
42934 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42935 - goto out_free_dentry;
42936 + /*
42937 + * This bss-zeroing can fail if the ELF
42938 + * file specifies odd protections. So
42939 + * we don't check the return value
42940 + */
42941 }
42942
42943 +#ifdef CONFIG_PAX_RANDMMAP
42944 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42945 + unsigned long start, size;
42946 +
42947 + start = ELF_PAGEALIGN(elf_brk);
42948 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42949 + down_read(&current->mm->mmap_sem);
42950 + retval = -ENOMEM;
42951 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42952 + unsigned long prot = PROT_NONE;
42953 +
42954 + up_read(&current->mm->mmap_sem);
42955 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42956 +// if (current->personality & ADDR_NO_RANDOMIZE)
42957 +// prot = PROT_READ;
42958 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42959 + retval = IS_ERR_VALUE(start) ? start : 0;
42960 + } else
42961 + up_read(&current->mm->mmap_sem);
42962 + if (retval == 0)
42963 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42964 + if (retval < 0) {
42965 + send_sig(SIGKILL, current, 0);
42966 + goto out_free_dentry;
42967 + }
42968 + }
42969 +#endif
42970 +
42971 if (elf_interpreter) {
42972 unsigned long uninitialized_var(interp_map_addr);
42973
42974 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42975 * Decide what to dump of a segment, part, all or none.
42976 */
42977 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42978 - unsigned long mm_flags)
42979 + unsigned long mm_flags, long signr)
42980 {
42981 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42982
42983 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42984 if (vma->vm_file == NULL)
42985 return 0;
42986
42987 - if (FILTER(MAPPED_PRIVATE))
42988 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42989 goto whole;
42990
42991 /*
42992 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42993 {
42994 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42995 int i = 0;
42996 - do
42997 + do {
42998 i += 2;
42999 - while (auxv[i - 2] != AT_NULL);
43000 + } while (auxv[i - 2] != AT_NULL);
43001 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43002 }
43003
43004 @@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43005 }
43006
43007 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43008 - unsigned long mm_flags)
43009 + struct coredump_params *cprm)
43010 {
43011 struct vm_area_struct *vma;
43012 size_t size = 0;
43013
43014 for (vma = first_vma(current, gate_vma); vma != NULL;
43015 vma = next_vma(vma, gate_vma))
43016 - size += vma_dump_size(vma, mm_flags);
43017 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43018 return size;
43019 }
43020
43021 @@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43022
43023 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43024
43025 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43026 + offset += elf_core_vma_data_size(gate_vma, cprm);
43027 offset += elf_core_extra_data_size();
43028 e_shoff = offset;
43029
43030 @@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43031 offset = dataoff;
43032
43033 size += sizeof(*elf);
43034 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43035 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43036 goto end_coredump;
43037
43038 size += sizeof(*phdr4note);
43039 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43040 if (size > cprm->limit
43041 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43042 goto end_coredump;
43043 @@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43044 phdr.p_offset = offset;
43045 phdr.p_vaddr = vma->vm_start;
43046 phdr.p_paddr = 0;
43047 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43048 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43049 phdr.p_memsz = vma->vm_end - vma->vm_start;
43050 offset += phdr.p_filesz;
43051 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43052 @@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43053 phdr.p_align = ELF_EXEC_PAGESIZE;
43054
43055 size += sizeof(phdr);
43056 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43057 if (size > cprm->limit
43058 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43059 goto end_coredump;
43060 @@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43061 unsigned long addr;
43062 unsigned long end;
43063
43064 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43065 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43066
43067 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43068 struct page *page;
43069 @@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43070 page = get_dump_page(addr);
43071 if (page) {
43072 void *kaddr = kmap(page);
43073 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43074 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43075 !dump_write(cprm->file, kaddr,
43076 PAGE_SIZE);
43077 @@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43078
43079 if (e_phnum == PN_XNUM) {
43080 size += sizeof(*shdr4extnum);
43081 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43082 if (size > cprm->limit
43083 || !dump_write(cprm->file, shdr4extnum,
43084 sizeof(*shdr4extnum)))
43085 @@ -2103,6 +2556,97 @@ out:
43086
43087 #endif /* CONFIG_ELF_CORE */
43088
43089 +#ifdef CONFIG_PAX_MPROTECT
43090 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43091 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43092 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43093 + *
43094 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43095 + * basis because we want to allow the common case and not the special ones.
43096 + */
43097 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43098 +{
43099 + struct elfhdr elf_h;
43100 + struct elf_phdr elf_p;
43101 + unsigned long i;
43102 + unsigned long oldflags;
43103 + bool is_textrel_rw, is_textrel_rx, is_relro;
43104 +
43105 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43106 + return;
43107 +
43108 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43109 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43110 +
43111 +#ifdef CONFIG_PAX_ELFRELOCS
43112 + /* possible TEXTREL */
43113 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43114 + 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);
43115 +#else
43116 + is_textrel_rw = false;
43117 + is_textrel_rx = false;
43118 +#endif
43119 +
43120 + /* possible RELRO */
43121 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43122 +
43123 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43124 + return;
43125 +
43126 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43127 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43128 +
43129 +#ifdef CONFIG_PAX_ETEXECRELOCS
43130 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43131 +#else
43132 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43133 +#endif
43134 +
43135 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43136 + !elf_check_arch(&elf_h) ||
43137 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43138 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43139 + return;
43140 +
43141 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43142 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43143 + return;
43144 + switch (elf_p.p_type) {
43145 + case PT_DYNAMIC:
43146 + if (!is_textrel_rw && !is_textrel_rx)
43147 + continue;
43148 + i = 0UL;
43149 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43150 + elf_dyn dyn;
43151 +
43152 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43153 + return;
43154 + if (dyn.d_tag == DT_NULL)
43155 + return;
43156 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43157 + gr_log_textrel(vma);
43158 + if (is_textrel_rw)
43159 + vma->vm_flags |= VM_MAYWRITE;
43160 + else
43161 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43162 + vma->vm_flags &= ~VM_MAYWRITE;
43163 + return;
43164 + }
43165 + i++;
43166 + }
43167 + return;
43168 +
43169 + case PT_GNU_RELRO:
43170 + if (!is_relro)
43171 + continue;
43172 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43173 + vma->vm_flags &= ~VM_MAYWRITE;
43174 + return;
43175 + }
43176 + }
43177 +}
43178 +#endif
43179 +
43180 static int __init init_elf_binfmt(void)
43181 {
43182 register_binfmt(&elf_format);
43183 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43184 index 178cb70..8972997 100644
43185 --- a/fs/binfmt_flat.c
43186 +++ b/fs/binfmt_flat.c
43187 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43188 realdatastart = (unsigned long) -ENOMEM;
43189 printk("Unable to allocate RAM for process data, errno %d\n",
43190 (int)-realdatastart);
43191 + down_write(&current->mm->mmap_sem);
43192 vm_munmap(textpos, text_len);
43193 + up_write(&current->mm->mmap_sem);
43194 ret = realdatastart;
43195 goto err;
43196 }
43197 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43198 }
43199 if (IS_ERR_VALUE(result)) {
43200 printk("Unable to read data+bss, errno %d\n", (int)-result);
43201 + down_write(&current->mm->mmap_sem);
43202 vm_munmap(textpos, text_len);
43203 vm_munmap(realdatastart, len);
43204 + up_write(&current->mm->mmap_sem);
43205 ret = result;
43206 goto err;
43207 }
43208 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43209 }
43210 if (IS_ERR_VALUE(result)) {
43211 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43212 + down_write(&current->mm->mmap_sem);
43213 vm_munmap(textpos, text_len + data_len + extra +
43214 MAX_SHARED_LIBS * sizeof(unsigned long));
43215 + up_write(&current->mm->mmap_sem);
43216 ret = result;
43217 goto err;
43218 }
43219 diff --git a/fs/bio.c b/fs/bio.c
43220 index 73922ab..16642dd 100644
43221 --- a/fs/bio.c
43222 +++ b/fs/bio.c
43223 @@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43224 /*
43225 * Overflow, abort
43226 */
43227 - if (end < start)
43228 + if (end < start || end - start > INT_MAX - nr_pages)
43229 return ERR_PTR(-EINVAL);
43230
43231 nr_pages += end - start;
43232 @@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43233 /*
43234 * Overflow, abort
43235 */
43236 - if (end < start)
43237 + if (end < start || end - start > INT_MAX - nr_pages)
43238 return ERR_PTR(-EINVAL);
43239
43240 nr_pages += end - start;
43241 @@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43242 const int read = bio_data_dir(bio) == READ;
43243 struct bio_map_data *bmd = bio->bi_private;
43244 int i;
43245 - char *p = bmd->sgvecs[0].iov_base;
43246 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43247
43248 __bio_for_each_segment(bvec, bio, i, 0) {
43249 char *addr = page_address(bvec->bv_page);
43250 diff --git a/fs/block_dev.c b/fs/block_dev.c
43251 index c2bbe1f..9dfbc23 100644
43252 --- a/fs/block_dev.c
43253 +++ b/fs/block_dev.c
43254 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43255 else if (bdev->bd_contains == bdev)
43256 return true; /* is a whole device which isn't held */
43257
43258 - else if (whole->bd_holder == bd_may_claim)
43259 + else if (whole->bd_holder == (void *)bd_may_claim)
43260 return true; /* is a partition of a device that is being partitioned */
43261 else if (whole->bd_holder != NULL)
43262 return false; /* is a partition of a held device */
43263 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43264 index da6e936..1598dd0 100644
43265 --- a/fs/btrfs/check-integrity.c
43266 +++ b/fs/btrfs/check-integrity.c
43267 @@ -155,7 +155,7 @@ struct btrfsic_block {
43268 union {
43269 bio_end_io_t *bio;
43270 bh_end_io_t *bh;
43271 - } orig_bio_bh_end_io;
43272 + } __no_const orig_bio_bh_end_io;
43273 int submit_bio_bh_rw;
43274 u64 flush_gen; /* only valid if !never_written */
43275 };
43276 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43277 index 8206b39..06d5654 100644
43278 --- a/fs/btrfs/ctree.c
43279 +++ b/fs/btrfs/ctree.c
43280 @@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43281 free_extent_buffer(buf);
43282 add_root_to_dirty_list(root);
43283 } else {
43284 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43285 - parent_start = parent->start;
43286 - else
43287 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43288 + if (parent)
43289 + parent_start = parent->start;
43290 + else
43291 + parent_start = 0;
43292 + } else
43293 parent_start = 0;
43294
43295 WARN_ON(trans->transid != btrfs_header_generation(parent));
43296 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43297 index a7d1921..a32dba2 100644
43298 --- a/fs/btrfs/inode.c
43299 +++ b/fs/btrfs/inode.c
43300 @@ -7111,7 +7111,7 @@ fail:
43301 return -ENOMEM;
43302 }
43303
43304 -static int btrfs_getattr(struct vfsmount *mnt,
43305 +int btrfs_getattr(struct vfsmount *mnt,
43306 struct dentry *dentry, struct kstat *stat)
43307 {
43308 struct inode *inode = dentry->d_inode;
43309 @@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43310 return 0;
43311 }
43312
43313 +EXPORT_SYMBOL(btrfs_getattr);
43314 +
43315 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43316 +{
43317 + return BTRFS_I(inode)->root->anon_dev;
43318 +}
43319 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43320 +
43321 /*
43322 * If a file is moved, it will inherit the cow and compression flags of the new
43323 * directory.
43324 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43325 index 0e92e57..8b560de 100644
43326 --- a/fs/btrfs/ioctl.c
43327 +++ b/fs/btrfs/ioctl.c
43328 @@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43329 for (i = 0; i < num_types; i++) {
43330 struct btrfs_space_info *tmp;
43331
43332 + /* Don't copy in more than we allocated */
43333 if (!slot_count)
43334 break;
43335
43336 + slot_count--;
43337 +
43338 info = NULL;
43339 rcu_read_lock();
43340 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43341 @@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43342 memcpy(dest, &space, sizeof(space));
43343 dest++;
43344 space_args.total_spaces++;
43345 - slot_count--;
43346 }
43347 - if (!slot_count)
43348 - break;
43349 }
43350 up_read(&info->groups_sem);
43351 }
43352 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43353 index 646ee21..f020f87 100644
43354 --- a/fs/btrfs/relocation.c
43355 +++ b/fs/btrfs/relocation.c
43356 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43357 }
43358 spin_unlock(&rc->reloc_root_tree.lock);
43359
43360 - BUG_ON((struct btrfs_root *)node->data != root);
43361 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43362
43363 if (!del) {
43364 spin_lock(&rc->reloc_root_tree.lock);
43365 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43366 index 622f469..e8d2d55 100644
43367 --- a/fs/cachefiles/bind.c
43368 +++ b/fs/cachefiles/bind.c
43369 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43370 args);
43371
43372 /* start by checking things over */
43373 - ASSERT(cache->fstop_percent >= 0 &&
43374 - cache->fstop_percent < cache->fcull_percent &&
43375 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43376 cache->fcull_percent < cache->frun_percent &&
43377 cache->frun_percent < 100);
43378
43379 - ASSERT(cache->bstop_percent >= 0 &&
43380 - cache->bstop_percent < cache->bcull_percent &&
43381 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43382 cache->bcull_percent < cache->brun_percent &&
43383 cache->brun_percent < 100);
43384
43385 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43386 index 0a1467b..6a53245 100644
43387 --- a/fs/cachefiles/daemon.c
43388 +++ b/fs/cachefiles/daemon.c
43389 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43390 if (n > buflen)
43391 return -EMSGSIZE;
43392
43393 - if (copy_to_user(_buffer, buffer, n) != 0)
43394 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43395 return -EFAULT;
43396
43397 return n;
43398 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43399 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43400 return -EIO;
43401
43402 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43403 + if (datalen > PAGE_SIZE - 1)
43404 return -EOPNOTSUPP;
43405
43406 /* drag the command string into the kernel so we can parse it */
43407 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43408 if (args[0] != '%' || args[1] != '\0')
43409 return -EINVAL;
43410
43411 - if (fstop < 0 || fstop >= cache->fcull_percent)
43412 + if (fstop >= cache->fcull_percent)
43413 return cachefiles_daemon_range_error(cache, args);
43414
43415 cache->fstop_percent = fstop;
43416 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43417 if (args[0] != '%' || args[1] != '\0')
43418 return -EINVAL;
43419
43420 - if (bstop < 0 || bstop >= cache->bcull_percent)
43421 + if (bstop >= cache->bcull_percent)
43422 return cachefiles_daemon_range_error(cache, args);
43423
43424 cache->bstop_percent = bstop;
43425 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43426 index bd6bc1b..b627b53 100644
43427 --- a/fs/cachefiles/internal.h
43428 +++ b/fs/cachefiles/internal.h
43429 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43430 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43431 struct rb_root active_nodes; /* active nodes (can't be culled) */
43432 rwlock_t active_lock; /* lock for active_nodes */
43433 - atomic_t gravecounter; /* graveyard uniquifier */
43434 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43435 unsigned frun_percent; /* when to stop culling (% files) */
43436 unsigned fcull_percent; /* when to start culling (% files) */
43437 unsigned fstop_percent; /* when to stop allocating (% files) */
43438 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43439 * proc.c
43440 */
43441 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43442 -extern atomic_t cachefiles_lookup_histogram[HZ];
43443 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43444 -extern atomic_t cachefiles_create_histogram[HZ];
43445 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43446 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43447 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43448
43449 extern int __init cachefiles_proc_init(void);
43450 extern void cachefiles_proc_cleanup(void);
43451 static inline
43452 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43453 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43454 {
43455 unsigned long jif = jiffies - start_jif;
43456 if (jif >= HZ)
43457 jif = HZ - 1;
43458 - atomic_inc(&histogram[jif]);
43459 + atomic_inc_unchecked(&histogram[jif]);
43460 }
43461
43462 #else
43463 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43464 index 7f0771d..87d4f36 100644
43465 --- a/fs/cachefiles/namei.c
43466 +++ b/fs/cachefiles/namei.c
43467 @@ -318,7 +318,7 @@ try_again:
43468 /* first step is to make up a grave dentry in the graveyard */
43469 sprintf(nbuffer, "%08x%08x",
43470 (uint32_t) get_seconds(),
43471 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43472 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43473
43474 /* do the multiway lock magic */
43475 trap = lock_rename(cache->graveyard, dir);
43476 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43477 index eccd339..4c1d995 100644
43478 --- a/fs/cachefiles/proc.c
43479 +++ b/fs/cachefiles/proc.c
43480 @@ -14,9 +14,9 @@
43481 #include <linux/seq_file.h>
43482 #include "internal.h"
43483
43484 -atomic_t cachefiles_lookup_histogram[HZ];
43485 -atomic_t cachefiles_mkdir_histogram[HZ];
43486 -atomic_t cachefiles_create_histogram[HZ];
43487 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43488 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43489 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43490
43491 /*
43492 * display the latency histogram
43493 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43494 return 0;
43495 default:
43496 index = (unsigned long) v - 3;
43497 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43498 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43499 - z = atomic_read(&cachefiles_create_histogram[index]);
43500 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43501 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43502 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43503 if (x == 0 && y == 0 && z == 0)
43504 return 0;
43505
43506 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43507 index 0e3c092..818480e 100644
43508 --- a/fs/cachefiles/rdwr.c
43509 +++ b/fs/cachefiles/rdwr.c
43510 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43511 old_fs = get_fs();
43512 set_fs(KERNEL_DS);
43513 ret = file->f_op->write(
43514 - file, (const void __user *) data, len, &pos);
43515 + file, (const void __force_user *) data, len, &pos);
43516 set_fs(old_fs);
43517 kunmap(page);
43518 if (ret != len)
43519 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43520 index 3e8094b..cb3ff3d 100644
43521 --- a/fs/ceph/dir.c
43522 +++ b/fs/ceph/dir.c
43523 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43524 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43525 struct ceph_mds_client *mdsc = fsc->mdsc;
43526 unsigned frag = fpos_frag(filp->f_pos);
43527 - int off = fpos_off(filp->f_pos);
43528 + unsigned int off = fpos_off(filp->f_pos);
43529 int err;
43530 u32 ftype;
43531 struct ceph_mds_reply_info_parsed *rinfo;
43532 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43533 if (nd &&
43534 (nd->flags & LOOKUP_OPEN) &&
43535 !(nd->intent.open.flags & O_CREAT)) {
43536 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43537 + int mode = nd->intent.open.create_mode & ~current_umask();
43538 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43539 }
43540
43541 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43542 index e814052..28dcdf7 100644
43543 --- a/fs/cifs/cifs_debug.c
43544 +++ b/fs/cifs/cifs_debug.c
43545 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43546
43547 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43548 #ifdef CONFIG_CIFS_STATS2
43549 - atomic_set(&totBufAllocCount, 0);
43550 - atomic_set(&totSmBufAllocCount, 0);
43551 + atomic_set_unchecked(&totBufAllocCount, 0);
43552 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43553 #endif /* CONFIG_CIFS_STATS2 */
43554 spin_lock(&cifs_tcp_ses_lock);
43555 list_for_each(tmp1, &cifs_tcp_ses_list) {
43556 @@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43557 tcon = list_entry(tmp3,
43558 struct cifs_tcon,
43559 tcon_list);
43560 - atomic_set(&tcon->num_smbs_sent, 0);
43561 - atomic_set(&tcon->num_writes, 0);
43562 - atomic_set(&tcon->num_reads, 0);
43563 - atomic_set(&tcon->num_oplock_brks, 0);
43564 - atomic_set(&tcon->num_opens, 0);
43565 - atomic_set(&tcon->num_posixopens, 0);
43566 - atomic_set(&tcon->num_posixmkdirs, 0);
43567 - atomic_set(&tcon->num_closes, 0);
43568 - atomic_set(&tcon->num_deletes, 0);
43569 - atomic_set(&tcon->num_mkdirs, 0);
43570 - atomic_set(&tcon->num_rmdirs, 0);
43571 - atomic_set(&tcon->num_renames, 0);
43572 - atomic_set(&tcon->num_t2renames, 0);
43573 - atomic_set(&tcon->num_ffirst, 0);
43574 - atomic_set(&tcon->num_fnext, 0);
43575 - atomic_set(&tcon->num_fclose, 0);
43576 - atomic_set(&tcon->num_hardlinks, 0);
43577 - atomic_set(&tcon->num_symlinks, 0);
43578 - atomic_set(&tcon->num_locks, 0);
43579 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43580 + atomic_set_unchecked(&tcon->num_writes, 0);
43581 + atomic_set_unchecked(&tcon->num_reads, 0);
43582 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43583 + atomic_set_unchecked(&tcon->num_opens, 0);
43584 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43585 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43586 + atomic_set_unchecked(&tcon->num_closes, 0);
43587 + atomic_set_unchecked(&tcon->num_deletes, 0);
43588 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43589 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43590 + atomic_set_unchecked(&tcon->num_renames, 0);
43591 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43592 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43593 + atomic_set_unchecked(&tcon->num_fnext, 0);
43594 + atomic_set_unchecked(&tcon->num_fclose, 0);
43595 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43596 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43597 + atomic_set_unchecked(&tcon->num_locks, 0);
43598 }
43599 }
43600 }
43601 @@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43602 smBufAllocCount.counter, cifs_min_small);
43603 #ifdef CONFIG_CIFS_STATS2
43604 seq_printf(m, "Total Large %d Small %d Allocations\n",
43605 - atomic_read(&totBufAllocCount),
43606 - atomic_read(&totSmBufAllocCount));
43607 + atomic_read_unchecked(&totBufAllocCount),
43608 + atomic_read_unchecked(&totSmBufAllocCount));
43609 #endif /* CONFIG_CIFS_STATS2 */
43610
43611 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43612 @@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43613 if (tcon->need_reconnect)
43614 seq_puts(m, "\tDISCONNECTED ");
43615 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43616 - atomic_read(&tcon->num_smbs_sent),
43617 - atomic_read(&tcon->num_oplock_brks));
43618 + atomic_read_unchecked(&tcon->num_smbs_sent),
43619 + atomic_read_unchecked(&tcon->num_oplock_brks));
43620 seq_printf(m, "\nReads: %d Bytes: %lld",
43621 - atomic_read(&tcon->num_reads),
43622 + atomic_read_unchecked(&tcon->num_reads),
43623 (long long)(tcon->bytes_read));
43624 seq_printf(m, "\nWrites: %d Bytes: %lld",
43625 - atomic_read(&tcon->num_writes),
43626 + atomic_read_unchecked(&tcon->num_writes),
43627 (long long)(tcon->bytes_written));
43628 seq_printf(m, "\nFlushes: %d",
43629 - atomic_read(&tcon->num_flushes));
43630 + atomic_read_unchecked(&tcon->num_flushes));
43631 seq_printf(m, "\nLocks: %d HardLinks: %d "
43632 "Symlinks: %d",
43633 - atomic_read(&tcon->num_locks),
43634 - atomic_read(&tcon->num_hardlinks),
43635 - atomic_read(&tcon->num_symlinks));
43636 + atomic_read_unchecked(&tcon->num_locks),
43637 + atomic_read_unchecked(&tcon->num_hardlinks),
43638 + atomic_read_unchecked(&tcon->num_symlinks));
43639 seq_printf(m, "\nOpens: %d Closes: %d "
43640 "Deletes: %d",
43641 - atomic_read(&tcon->num_opens),
43642 - atomic_read(&tcon->num_closes),
43643 - atomic_read(&tcon->num_deletes));
43644 + atomic_read_unchecked(&tcon->num_opens),
43645 + atomic_read_unchecked(&tcon->num_closes),
43646 + atomic_read_unchecked(&tcon->num_deletes));
43647 seq_printf(m, "\nPosix Opens: %d "
43648 "Posix Mkdirs: %d",
43649 - atomic_read(&tcon->num_posixopens),
43650 - atomic_read(&tcon->num_posixmkdirs));
43651 + atomic_read_unchecked(&tcon->num_posixopens),
43652 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43653 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43654 - atomic_read(&tcon->num_mkdirs),
43655 - atomic_read(&tcon->num_rmdirs));
43656 + atomic_read_unchecked(&tcon->num_mkdirs),
43657 + atomic_read_unchecked(&tcon->num_rmdirs));
43658 seq_printf(m, "\nRenames: %d T2 Renames %d",
43659 - atomic_read(&tcon->num_renames),
43660 - atomic_read(&tcon->num_t2renames));
43661 + atomic_read_unchecked(&tcon->num_renames),
43662 + atomic_read_unchecked(&tcon->num_t2renames));
43663 seq_printf(m, "\nFindFirst: %d FNext %d "
43664 "FClose %d",
43665 - atomic_read(&tcon->num_ffirst),
43666 - atomic_read(&tcon->num_fnext),
43667 - atomic_read(&tcon->num_fclose));
43668 + atomic_read_unchecked(&tcon->num_ffirst),
43669 + atomic_read_unchecked(&tcon->num_fnext),
43670 + atomic_read_unchecked(&tcon->num_fclose));
43671 }
43672 }
43673 }
43674 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43675 index 8b6e344..303a662 100644
43676 --- a/fs/cifs/cifsfs.c
43677 +++ b/fs/cifs/cifsfs.c
43678 @@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43679 cifs_req_cachep = kmem_cache_create("cifs_request",
43680 CIFSMaxBufSize +
43681 MAX_CIFS_HDR_SIZE, 0,
43682 - SLAB_HWCACHE_ALIGN, NULL);
43683 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43684 if (cifs_req_cachep == NULL)
43685 return -ENOMEM;
43686
43687 @@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43688 efficient to alloc 1 per page off the slab compared to 17K (5page)
43689 alloc of large cifs buffers even when page debugging is on */
43690 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43691 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43692 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43693 NULL);
43694 if (cifs_sm_req_cachep == NULL) {
43695 mempool_destroy(cifs_req_poolp);
43696 @@ -1106,8 +1106,8 @@ init_cifs(void)
43697 atomic_set(&bufAllocCount, 0);
43698 atomic_set(&smBufAllocCount, 0);
43699 #ifdef CONFIG_CIFS_STATS2
43700 - atomic_set(&totBufAllocCount, 0);
43701 - atomic_set(&totSmBufAllocCount, 0);
43702 + atomic_set_unchecked(&totBufAllocCount, 0);
43703 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43704 #endif /* CONFIG_CIFS_STATS2 */
43705
43706 atomic_set(&midCount, 0);
43707 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43708 index 6df0cbe..eb7ecbb 100644
43709 --- a/fs/cifs/cifsglob.h
43710 +++ b/fs/cifs/cifsglob.h
43711 @@ -491,28 +491,28 @@ struct cifs_tcon {
43712 __u16 Flags; /* optional support bits */
43713 enum statusEnum tidStatus;
43714 #ifdef CONFIG_CIFS_STATS
43715 - atomic_t num_smbs_sent;
43716 - atomic_t num_writes;
43717 - atomic_t num_reads;
43718 - atomic_t num_flushes;
43719 - atomic_t num_oplock_brks;
43720 - atomic_t num_opens;
43721 - atomic_t num_closes;
43722 - atomic_t num_deletes;
43723 - atomic_t num_mkdirs;
43724 - atomic_t num_posixopens;
43725 - atomic_t num_posixmkdirs;
43726 - atomic_t num_rmdirs;
43727 - atomic_t num_renames;
43728 - atomic_t num_t2renames;
43729 - atomic_t num_ffirst;
43730 - atomic_t num_fnext;
43731 - atomic_t num_fclose;
43732 - atomic_t num_hardlinks;
43733 - atomic_t num_symlinks;
43734 - atomic_t num_locks;
43735 - atomic_t num_acl_get;
43736 - atomic_t num_acl_set;
43737 + atomic_unchecked_t num_smbs_sent;
43738 + atomic_unchecked_t num_writes;
43739 + atomic_unchecked_t num_reads;
43740 + atomic_unchecked_t num_flushes;
43741 + atomic_unchecked_t num_oplock_brks;
43742 + atomic_unchecked_t num_opens;
43743 + atomic_unchecked_t num_closes;
43744 + atomic_unchecked_t num_deletes;
43745 + atomic_unchecked_t num_mkdirs;
43746 + atomic_unchecked_t num_posixopens;
43747 + atomic_unchecked_t num_posixmkdirs;
43748 + atomic_unchecked_t num_rmdirs;
43749 + atomic_unchecked_t num_renames;
43750 + atomic_unchecked_t num_t2renames;
43751 + atomic_unchecked_t num_ffirst;
43752 + atomic_unchecked_t num_fnext;
43753 + atomic_unchecked_t num_fclose;
43754 + atomic_unchecked_t num_hardlinks;
43755 + atomic_unchecked_t num_symlinks;
43756 + atomic_unchecked_t num_locks;
43757 + atomic_unchecked_t num_acl_get;
43758 + atomic_unchecked_t num_acl_set;
43759 #ifdef CONFIG_CIFS_STATS2
43760 unsigned long long time_writes;
43761 unsigned long long time_reads;
43762 @@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43763 }
43764
43765 #ifdef CONFIG_CIFS_STATS
43766 -#define cifs_stats_inc atomic_inc
43767 +#define cifs_stats_inc atomic_inc_unchecked
43768
43769 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43770 unsigned int bytes)
43771 @@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43772 /* Various Debug counters */
43773 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43774 #ifdef CONFIG_CIFS_STATS2
43775 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43776 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43777 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43778 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43779 #endif
43780 GLOBAL_EXTERN atomic_t smBufAllocCount;
43781 GLOBAL_EXTERN atomic_t midCount;
43782 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43783 index 6b0e064..94e6c3c 100644
43784 --- a/fs/cifs/link.c
43785 +++ b/fs/cifs/link.c
43786 @@ -600,7 +600,7 @@ symlink_exit:
43787
43788 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43789 {
43790 - char *p = nd_get_link(nd);
43791 + const char *p = nd_get_link(nd);
43792 if (!IS_ERR(p))
43793 kfree(p);
43794 }
43795 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43796 index 557506a..2fd3816 100644
43797 --- a/fs/cifs/misc.c
43798 +++ b/fs/cifs/misc.c
43799 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43800 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43801 atomic_inc(&bufAllocCount);
43802 #ifdef CONFIG_CIFS_STATS2
43803 - atomic_inc(&totBufAllocCount);
43804 + atomic_inc_unchecked(&totBufAllocCount);
43805 #endif /* CONFIG_CIFS_STATS2 */
43806 }
43807
43808 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43809 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43810 atomic_inc(&smBufAllocCount);
43811 #ifdef CONFIG_CIFS_STATS2
43812 - atomic_inc(&totSmBufAllocCount);
43813 + atomic_inc_unchecked(&totSmBufAllocCount);
43814 #endif /* CONFIG_CIFS_STATS2 */
43815
43816 }
43817 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43818 index 6901578..d402eb5 100644
43819 --- a/fs/coda/cache.c
43820 +++ b/fs/coda/cache.c
43821 @@ -24,7 +24,7 @@
43822 #include "coda_linux.h"
43823 #include "coda_cache.h"
43824
43825 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43826 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43827
43828 /* replace or extend an acl cache hit */
43829 void coda_cache_enter(struct inode *inode, int mask)
43830 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43831 struct coda_inode_info *cii = ITOC(inode);
43832
43833 spin_lock(&cii->c_lock);
43834 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43835 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43836 if (cii->c_uid != current_fsuid()) {
43837 cii->c_uid = current_fsuid();
43838 cii->c_cached_perm = mask;
43839 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43840 {
43841 struct coda_inode_info *cii = ITOC(inode);
43842 spin_lock(&cii->c_lock);
43843 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43844 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43845 spin_unlock(&cii->c_lock);
43846 }
43847
43848 /* remove all acl caches */
43849 void coda_cache_clear_all(struct super_block *sb)
43850 {
43851 - atomic_inc(&permission_epoch);
43852 + atomic_inc_unchecked(&permission_epoch);
43853 }
43854
43855
43856 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43857 spin_lock(&cii->c_lock);
43858 hit = (mask & cii->c_cached_perm) == mask &&
43859 cii->c_uid == current_fsuid() &&
43860 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43861 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43862 spin_unlock(&cii->c_lock);
43863
43864 return hit;
43865 diff --git a/fs/compat.c b/fs/compat.c
43866 index 6161255..512b1a1 100644
43867 --- a/fs/compat.c
43868 +++ b/fs/compat.c
43869 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43870
43871 set_fs(KERNEL_DS);
43872 /* The __user pointer cast is valid because of the set_fs() */
43873 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43874 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43875 set_fs(oldfs);
43876 /* truncating is ok because it's a user address */
43877 if (!ret)
43878 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43879 goto out;
43880
43881 ret = -EINVAL;
43882 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43883 + if (nr_segs > UIO_MAXIOV)
43884 goto out;
43885 if (nr_segs > fast_segs) {
43886 ret = -ENOMEM;
43887 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43888
43889 struct compat_readdir_callback {
43890 struct compat_old_linux_dirent __user *dirent;
43891 + struct file * file;
43892 int result;
43893 };
43894
43895 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43896 buf->result = -EOVERFLOW;
43897 return -EOVERFLOW;
43898 }
43899 +
43900 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43901 + return 0;
43902 +
43903 buf->result++;
43904 dirent = buf->dirent;
43905 if (!access_ok(VERIFY_WRITE, dirent,
43906 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43907
43908 buf.result = 0;
43909 buf.dirent = dirent;
43910 + buf.file = file;
43911
43912 error = vfs_readdir(file, compat_fillonedir, &buf);
43913 if (buf.result)
43914 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
43915 struct compat_getdents_callback {
43916 struct compat_linux_dirent __user *current_dir;
43917 struct compat_linux_dirent __user *previous;
43918 + struct file * file;
43919 int count;
43920 int error;
43921 };
43922 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43923 buf->error = -EOVERFLOW;
43924 return -EOVERFLOW;
43925 }
43926 +
43927 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43928 + return 0;
43929 +
43930 dirent = buf->previous;
43931 if (dirent) {
43932 if (__put_user(offset, &dirent->d_off))
43933 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43934 buf.previous = NULL;
43935 buf.count = count;
43936 buf.error = 0;
43937 + buf.file = file;
43938
43939 error = vfs_readdir(file, compat_filldir, &buf);
43940 if (error >= 0)
43941 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43942 struct compat_getdents_callback64 {
43943 struct linux_dirent64 __user *current_dir;
43944 struct linux_dirent64 __user *previous;
43945 + struct file * file;
43946 int count;
43947 int error;
43948 };
43949 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43950 buf->error = -EINVAL; /* only used if we fail.. */
43951 if (reclen > buf->count)
43952 return -EINVAL;
43953 +
43954 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43955 + return 0;
43956 +
43957 dirent = buf->previous;
43958
43959 if (dirent) {
43960 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43961 buf.previous = NULL;
43962 buf.count = count;
43963 buf.error = 0;
43964 + buf.file = file;
43965
43966 error = vfs_readdir(file, compat_filldir64, &buf);
43967 if (error >= 0)
43968 error = buf.error;
43969 lastdirent = buf.previous;
43970 if (lastdirent) {
43971 - typeof(lastdirent->d_off) d_off = file->f_pos;
43972 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43973 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43974 error = -EFAULT;
43975 else
43976 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43977 index 112e45a..b59845b 100644
43978 --- a/fs/compat_binfmt_elf.c
43979 +++ b/fs/compat_binfmt_elf.c
43980 @@ -30,11 +30,13 @@
43981 #undef elf_phdr
43982 #undef elf_shdr
43983 #undef elf_note
43984 +#undef elf_dyn
43985 #undef elf_addr_t
43986 #define elfhdr elf32_hdr
43987 #define elf_phdr elf32_phdr
43988 #define elf_shdr elf32_shdr
43989 #define elf_note elf32_note
43990 +#define elf_dyn Elf32_Dyn
43991 #define elf_addr_t Elf32_Addr
43992
43993 /*
43994 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43995 index debdfe0..75d31d4 100644
43996 --- a/fs/compat_ioctl.c
43997 +++ b/fs/compat_ioctl.c
43998 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43999
44000 err = get_user(palp, &up->palette);
44001 err |= get_user(length, &up->length);
44002 + if (err)
44003 + return -EFAULT;
44004
44005 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44006 err = put_user(compat_ptr(palp), &up_native->palette);
44007 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44008 return -EFAULT;
44009 if (__get_user(udata, &ss32->iomem_base))
44010 return -EFAULT;
44011 - ss.iomem_base = compat_ptr(udata);
44012 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44013 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44014 __get_user(ss.port_high, &ss32->port_high))
44015 return -EFAULT;
44016 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44017 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44018 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44019 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44020 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44021 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44022 return -EFAULT;
44023
44024 return ioctl_preallocate(file, p);
44025 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44026 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44027 {
44028 unsigned int a, b;
44029 - a = *(unsigned int *)p;
44030 - b = *(unsigned int *)q;
44031 + a = *(const unsigned int *)p;
44032 + b = *(const unsigned int *)q;
44033 if (a > b)
44034 return 1;
44035 if (a < b)
44036 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44037 index 7e6c52d..94bc756 100644
44038 --- a/fs/configfs/dir.c
44039 +++ b/fs/configfs/dir.c
44040 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44041 }
44042 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44043 struct configfs_dirent *next;
44044 - const char * name;
44045 + const unsigned char * name;
44046 + char d_name[sizeof(next->s_dentry->d_iname)];
44047 int len;
44048 struct inode *inode = NULL;
44049
44050 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44051 continue;
44052
44053 name = configfs_get_name(next);
44054 - len = strlen(name);
44055 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44056 + len = next->s_dentry->d_name.len;
44057 + memcpy(d_name, name, len);
44058 + name = d_name;
44059 + } else
44060 + len = strlen(name);
44061
44062 /*
44063 * We'll have a dentry and an inode for
44064 diff --git a/fs/dcache.c b/fs/dcache.c
44065 index 4046904..5e31505 100644
44066 --- a/fs/dcache.c
44067 +++ b/fs/dcache.c
44068 @@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44069 mempages -= reserve;
44070
44071 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44072 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44073 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44074
44075 dcache_init();
44076 inode_init();
44077 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44078 index b80bc84..0d46d1a 100644
44079 --- a/fs/debugfs/inode.c
44080 +++ b/fs/debugfs/inode.c
44081 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44082 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44083 {
44084 return debugfs_create_file(name,
44085 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44086 + S_IFDIR | S_IRWXU,
44087 +#else
44088 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44089 +#endif
44090 parent, NULL, NULL);
44091 }
44092 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44093 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44094 index a07441a..046fc0d 100644
44095 --- a/fs/ecryptfs/inode.c
44096 +++ b/fs/ecryptfs/inode.c
44097 @@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44098 old_fs = get_fs();
44099 set_fs(get_ds());
44100 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44101 - (char __user *)lower_buf,
44102 + (char __force_user *)lower_buf,
44103 PATH_MAX);
44104 set_fs(old_fs);
44105 if (rc < 0)
44106 @@ -703,7 +703,7 @@ out:
44107 static void
44108 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44109 {
44110 - char *buf = nd_get_link(nd);
44111 + const char *buf = nd_get_link(nd);
44112 if (!IS_ERR(buf)) {
44113 /* Free the char* */
44114 kfree(buf);
44115 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44116 index c0038f6..47ab347 100644
44117 --- a/fs/ecryptfs/miscdev.c
44118 +++ b/fs/ecryptfs/miscdev.c
44119 @@ -355,7 +355,7 @@ check_list:
44120 goto out_unlock_msg_ctx;
44121 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44122 if (msg_ctx->msg) {
44123 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44124 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44125 goto out_unlock_msg_ctx;
44126 i += packet_length_size;
44127 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44128 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44129 index b2a34a1..162fa69 100644
44130 --- a/fs/ecryptfs/read_write.c
44131 +++ b/fs/ecryptfs/read_write.c
44132 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44133 return -EIO;
44134 fs_save = get_fs();
44135 set_fs(get_ds());
44136 - rc = vfs_write(lower_file, data, size, &offset);
44137 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44138 set_fs(fs_save);
44139 mark_inode_dirty_sync(ecryptfs_inode);
44140 return rc;
44141 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44142 return -EIO;
44143 fs_save = get_fs();
44144 set_fs(get_ds());
44145 - rc = vfs_read(lower_file, data, size, &offset);
44146 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44147 set_fs(fs_save);
44148 return rc;
44149 }
44150 diff --git a/fs/exec.c b/fs/exec.c
44151 index da27b91..5a05624 100644
44152 --- a/fs/exec.c
44153 +++ b/fs/exec.c
44154 @@ -55,6 +55,15 @@
44155 #include <linux/pipe_fs_i.h>
44156 #include <linux/oom.h>
44157 #include <linux/compat.h>
44158 +#include <linux/random.h>
44159 +#include <linux/seq_file.h>
44160 +
44161 +#ifdef CONFIG_PAX_REFCOUNT
44162 +#include <linux/kallsyms.h>
44163 +#include <linux/kdebug.h>
44164 +#endif
44165 +
44166 +#include <trace/events/fs.h>
44167
44168 #include <asm/uaccess.h>
44169 #include <asm/mmu_context.h>
44170 @@ -66,6 +75,18 @@
44171
44172 #include <trace/events/sched.h>
44173
44174 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44175 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44176 +{
44177 + 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");
44178 +}
44179 +#endif
44180 +
44181 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44182 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44183 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44184 +#endif
44185 +
44186 int core_uses_pid;
44187 char core_pattern[CORENAME_MAX_SIZE] = "core";
44188 unsigned int core_pipe_limit;
44189 @@ -75,7 +96,7 @@ struct core_name {
44190 char *corename;
44191 int used, size;
44192 };
44193 -static atomic_t call_count = ATOMIC_INIT(1);
44194 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44195
44196 /* The maximal length of core_pattern is also specified in sysctl.c */
44197
44198 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44199 int write)
44200 {
44201 struct page *page;
44202 - int ret;
44203
44204 -#ifdef CONFIG_STACK_GROWSUP
44205 - if (write) {
44206 - ret = expand_downwards(bprm->vma, pos);
44207 - if (ret < 0)
44208 - return NULL;
44209 - }
44210 -#endif
44211 - ret = get_user_pages(current, bprm->mm, pos,
44212 - 1, write, 1, &page, NULL);
44213 - if (ret <= 0)
44214 + if (0 > expand_downwards(bprm->vma, pos))
44215 + return NULL;
44216 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44217 return NULL;
44218
44219 if (write) {
44220 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44221 if (size <= ARG_MAX)
44222 return page;
44223
44224 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44225 + // only allow 512KB for argv+env on suid/sgid binaries
44226 + // to prevent easy ASLR exhaustion
44227 + if (((bprm->cred->euid != current_euid()) ||
44228 + (bprm->cred->egid != current_egid())) &&
44229 + (size > (512 * 1024))) {
44230 + put_page(page);
44231 + return NULL;
44232 + }
44233 +#endif
44234 +
44235 /*
44236 * Limit to 1/4-th the stack size for the argv+env strings.
44237 * This ensures that:
44238 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44239 vma->vm_end = STACK_TOP_MAX;
44240 vma->vm_start = vma->vm_end - PAGE_SIZE;
44241 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44242 +
44243 +#ifdef CONFIG_PAX_SEGMEXEC
44244 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44245 +#endif
44246 +
44247 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44248 INIT_LIST_HEAD(&vma->anon_vma_chain);
44249
44250 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44251 mm->stack_vm = mm->total_vm = 1;
44252 up_write(&mm->mmap_sem);
44253 bprm->p = vma->vm_end - sizeof(void *);
44254 +
44255 +#ifdef CONFIG_PAX_RANDUSTACK
44256 + if (randomize_va_space)
44257 + bprm->p ^= random32() & ~PAGE_MASK;
44258 +#endif
44259 +
44260 return 0;
44261 err:
44262 up_write(&mm->mmap_sem);
44263 @@ -395,19 +430,7 @@ err:
44264 return err;
44265 }
44266
44267 -struct user_arg_ptr {
44268 -#ifdef CONFIG_COMPAT
44269 - bool is_compat;
44270 -#endif
44271 - union {
44272 - const char __user *const __user *native;
44273 -#ifdef CONFIG_COMPAT
44274 - compat_uptr_t __user *compat;
44275 -#endif
44276 - } ptr;
44277 -};
44278 -
44279 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44280 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44281 {
44282 const char __user *native;
44283
44284 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44285 compat_uptr_t compat;
44286
44287 if (get_user(compat, argv.ptr.compat + nr))
44288 - return ERR_PTR(-EFAULT);
44289 + return (const char __force_user *)ERR_PTR(-EFAULT);
44290
44291 return compat_ptr(compat);
44292 }
44293 #endif
44294
44295 if (get_user(native, argv.ptr.native + nr))
44296 - return ERR_PTR(-EFAULT);
44297 + return (const char __force_user *)ERR_PTR(-EFAULT);
44298
44299 return native;
44300 }
44301 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44302 if (!p)
44303 break;
44304
44305 - if (IS_ERR(p))
44306 + if (IS_ERR((const char __force_kernel *)p))
44307 return -EFAULT;
44308
44309 if (i++ >= max)
44310 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44311
44312 ret = -EFAULT;
44313 str = get_user_arg_ptr(argv, argc);
44314 - if (IS_ERR(str))
44315 + if (IS_ERR((const char __force_kernel *)str))
44316 goto out;
44317
44318 len = strnlen_user(str, MAX_ARG_STRLEN);
44319 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44320 int r;
44321 mm_segment_t oldfs = get_fs();
44322 struct user_arg_ptr argv = {
44323 - .ptr.native = (const char __user *const __user *)__argv,
44324 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44325 };
44326
44327 set_fs(KERNEL_DS);
44328 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44329 unsigned long new_end = old_end - shift;
44330 struct mmu_gather tlb;
44331
44332 - BUG_ON(new_start > new_end);
44333 + if (new_start >= new_end || new_start < mmap_min_addr)
44334 + return -ENOMEM;
44335
44336 /*
44337 * ensure there are no vmas between where we want to go
44338 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44339 if (vma != find_vma(mm, new_start))
44340 return -EFAULT;
44341
44342 +#ifdef CONFIG_PAX_SEGMEXEC
44343 + BUG_ON(pax_find_mirror_vma(vma));
44344 +#endif
44345 +
44346 /*
44347 * cover the whole range: [new_start, old_end)
44348 */
44349 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44350 stack_top = arch_align_stack(stack_top);
44351 stack_top = PAGE_ALIGN(stack_top);
44352
44353 - if (unlikely(stack_top < mmap_min_addr) ||
44354 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44355 - return -ENOMEM;
44356 -
44357 stack_shift = vma->vm_end - stack_top;
44358
44359 bprm->p -= stack_shift;
44360 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44361 bprm->exec -= stack_shift;
44362
44363 down_write(&mm->mmap_sem);
44364 +
44365 + /* Move stack pages down in memory. */
44366 + if (stack_shift) {
44367 + ret = shift_arg_pages(vma, stack_shift);
44368 + if (ret)
44369 + goto out_unlock;
44370 + }
44371 +
44372 vm_flags = VM_STACK_FLAGS;
44373
44374 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44375 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44376 + vm_flags &= ~VM_EXEC;
44377 +
44378 +#ifdef CONFIG_PAX_MPROTECT
44379 + if (mm->pax_flags & MF_PAX_MPROTECT)
44380 + vm_flags &= ~VM_MAYEXEC;
44381 +#endif
44382 +
44383 + }
44384 +#endif
44385 +
44386 /*
44387 * Adjust stack execute permissions; explicitly enable for
44388 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44389 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44390 goto out_unlock;
44391 BUG_ON(prev != vma);
44392
44393 - /* Move stack pages down in memory. */
44394 - if (stack_shift) {
44395 - ret = shift_arg_pages(vma, stack_shift);
44396 - if (ret)
44397 - goto out_unlock;
44398 - }
44399 -
44400 /* mprotect_fixup is overkill to remove the temporary stack flags */
44401 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44402
44403 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44404
44405 fsnotify_open(file);
44406
44407 + trace_open_exec(name);
44408 +
44409 err = deny_write_access(file);
44410 if (err)
44411 goto exit;
44412 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44413 old_fs = get_fs();
44414 set_fs(get_ds());
44415 /* The cast to a user pointer is valid due to the set_fs() */
44416 - result = vfs_read(file, (void __user *)addr, count, &pos);
44417 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44418 set_fs(old_fs);
44419 return result;
44420 }
44421 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44422 }
44423 rcu_read_unlock();
44424
44425 - if (p->fs->users > n_fs) {
44426 + if (atomic_read(&p->fs->users) > n_fs) {
44427 bprm->unsafe |= LSM_UNSAFE_SHARE;
44428 } else {
44429 res = -EAGAIN;
44430 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44431
44432 EXPORT_SYMBOL(search_binary_handler);
44433
44434 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44435 +static DEFINE_PER_CPU(u64, exec_counter);
44436 +static int __init init_exec_counters(void)
44437 +{
44438 + unsigned int cpu;
44439 +
44440 + for_each_possible_cpu(cpu) {
44441 + per_cpu(exec_counter, cpu) = (u64)cpu;
44442 + }
44443 +
44444 + return 0;
44445 +}
44446 +early_initcall(init_exec_counters);
44447 +static inline void increment_exec_counter(void)
44448 +{
44449 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44450 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44451 +}
44452 +#else
44453 +static inline void increment_exec_counter(void) {}
44454 +#endif
44455 +
44456 /*
44457 * sys_execve() executes a new program.
44458 */
44459 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44460 struct user_arg_ptr envp,
44461 struct pt_regs *regs)
44462 {
44463 +#ifdef CONFIG_GRKERNSEC
44464 + struct file *old_exec_file;
44465 + struct acl_subject_label *old_acl;
44466 + struct rlimit old_rlim[RLIM_NLIMITS];
44467 +#endif
44468 struct linux_binprm *bprm;
44469 struct file *file;
44470 struct files_struct *displaced;
44471 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44472 int retval;
44473 const struct cred *cred = current_cred();
44474
44475 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44476 +
44477 /*
44478 * We move the actual failure in case of RLIMIT_NPROC excess from
44479 * set*uid() to execve() because too many poorly written programs
44480 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44481 if (IS_ERR(file))
44482 goto out_unmark;
44483
44484 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44485 + retval = -EPERM;
44486 + goto out_file;
44487 + }
44488 +
44489 sched_exec();
44490
44491 bprm->file = file;
44492 bprm->filename = filename;
44493 bprm->interp = filename;
44494
44495 + if (gr_process_user_ban()) {
44496 + retval = -EPERM;
44497 + goto out_file;
44498 + }
44499 +
44500 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44501 + retval = -EACCES;
44502 + goto out_file;
44503 + }
44504 +
44505 retval = bprm_mm_init(bprm);
44506 if (retval)
44507 goto out_file;
44508 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44509 if (retval < 0)
44510 goto out;
44511
44512 +#ifdef CONFIG_GRKERNSEC
44513 + old_acl = current->acl;
44514 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44515 + old_exec_file = current->exec_file;
44516 + get_file(file);
44517 + current->exec_file = file;
44518 +#endif
44519 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44520 + /* limit suid stack to 8MB
44521 + we saved the old limits above and will restore them if this exec fails
44522 + */
44523 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44524 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44525 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44526 +#endif
44527 +
44528 + if (!gr_tpe_allow(file)) {
44529 + retval = -EACCES;
44530 + goto out_fail;
44531 + }
44532 +
44533 + if (gr_check_crash_exec(file)) {
44534 + retval = -EACCES;
44535 + goto out_fail;
44536 + }
44537 +
44538 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44539 + bprm->unsafe);
44540 + if (retval < 0)
44541 + goto out_fail;
44542 +
44543 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44544 if (retval < 0)
44545 - goto out;
44546 + goto out_fail;
44547
44548 bprm->exec = bprm->p;
44549 retval = copy_strings(bprm->envc, envp, bprm);
44550 if (retval < 0)
44551 - goto out;
44552 + goto out_fail;
44553
44554 retval = copy_strings(bprm->argc, argv, bprm);
44555 if (retval < 0)
44556 - goto out;
44557 + goto out_fail;
44558 +
44559 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44560 +
44561 + gr_handle_exec_args(bprm, argv);
44562
44563 retval = search_binary_handler(bprm,regs);
44564 if (retval < 0)
44565 - goto out;
44566 + goto out_fail;
44567 +#ifdef CONFIG_GRKERNSEC
44568 + if (old_exec_file)
44569 + fput(old_exec_file);
44570 +#endif
44571
44572 /* execve succeeded */
44573 +
44574 + increment_exec_counter();
44575 current->fs->in_exec = 0;
44576 current->in_execve = 0;
44577 acct_update_integrals(current);
44578 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44579 put_files_struct(displaced);
44580 return retval;
44581
44582 +out_fail:
44583 +#ifdef CONFIG_GRKERNSEC
44584 + current->acl = old_acl;
44585 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44586 + fput(current->exec_file);
44587 + current->exec_file = old_exec_file;
44588 +#endif
44589 +
44590 out:
44591 if (bprm->mm) {
44592 acct_arg_size(bprm, 0);
44593 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44594 {
44595 char *old_corename = cn->corename;
44596
44597 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44598 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44599 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44600
44601 if (!cn->corename) {
44602 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44603 int pid_in_pattern = 0;
44604 int err = 0;
44605
44606 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44607 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44608 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44609 cn->used = 0;
44610
44611 @@ -1830,6 +1962,250 @@ out:
44612 return ispipe;
44613 }
44614
44615 +int pax_check_flags(unsigned long *flags)
44616 +{
44617 + int retval = 0;
44618 +
44619 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44620 + if (*flags & MF_PAX_SEGMEXEC)
44621 + {
44622 + *flags &= ~MF_PAX_SEGMEXEC;
44623 + retval = -EINVAL;
44624 + }
44625 +#endif
44626 +
44627 + if ((*flags & MF_PAX_PAGEEXEC)
44628 +
44629 +#ifdef CONFIG_PAX_PAGEEXEC
44630 + && (*flags & MF_PAX_SEGMEXEC)
44631 +#endif
44632 +
44633 + )
44634 + {
44635 + *flags &= ~MF_PAX_PAGEEXEC;
44636 + retval = -EINVAL;
44637 + }
44638 +
44639 + if ((*flags & MF_PAX_MPROTECT)
44640 +
44641 +#ifdef CONFIG_PAX_MPROTECT
44642 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44643 +#endif
44644 +
44645 + )
44646 + {
44647 + *flags &= ~MF_PAX_MPROTECT;
44648 + retval = -EINVAL;
44649 + }
44650 +
44651 + if ((*flags & MF_PAX_EMUTRAMP)
44652 +
44653 +#ifdef CONFIG_PAX_EMUTRAMP
44654 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44655 +#endif
44656 +
44657 + )
44658 + {
44659 + *flags &= ~MF_PAX_EMUTRAMP;
44660 + retval = -EINVAL;
44661 + }
44662 +
44663 + return retval;
44664 +}
44665 +
44666 +EXPORT_SYMBOL(pax_check_flags);
44667 +
44668 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44669 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44670 +{
44671 + struct task_struct *tsk = current;
44672 + struct mm_struct *mm = current->mm;
44673 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44674 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44675 + char *path_exec = NULL;
44676 + char *path_fault = NULL;
44677 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44678 +
44679 + if (buffer_exec && buffer_fault) {
44680 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44681 +
44682 + down_read(&mm->mmap_sem);
44683 + vma = mm->mmap;
44684 + while (vma && (!vma_exec || !vma_fault)) {
44685 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44686 + vma_exec = vma;
44687 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44688 + vma_fault = vma;
44689 + vma = vma->vm_next;
44690 + }
44691 + if (vma_exec) {
44692 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44693 + if (IS_ERR(path_exec))
44694 + path_exec = "<path too long>";
44695 + else {
44696 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44697 + if (path_exec) {
44698 + *path_exec = 0;
44699 + path_exec = buffer_exec;
44700 + } else
44701 + path_exec = "<path too long>";
44702 + }
44703 + }
44704 + if (vma_fault) {
44705 + start = vma_fault->vm_start;
44706 + end = vma_fault->vm_end;
44707 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44708 + if (vma_fault->vm_file) {
44709 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44710 + if (IS_ERR(path_fault))
44711 + path_fault = "<path too long>";
44712 + else {
44713 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44714 + if (path_fault) {
44715 + *path_fault = 0;
44716 + path_fault = buffer_fault;
44717 + } else
44718 + path_fault = "<path too long>";
44719 + }
44720 + } else
44721 + path_fault = "<anonymous mapping>";
44722 + }
44723 + up_read(&mm->mmap_sem);
44724 + }
44725 + if (tsk->signal->curr_ip)
44726 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44727 + else
44728 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44729 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44730 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44731 + task_uid(tsk), task_euid(tsk), pc, sp);
44732 + free_page((unsigned long)buffer_exec);
44733 + free_page((unsigned long)buffer_fault);
44734 + pax_report_insns(regs, pc, sp);
44735 + do_coredump(SIGKILL, SIGKILL, regs);
44736 +}
44737 +#endif
44738 +
44739 +#ifdef CONFIG_PAX_REFCOUNT
44740 +void pax_report_refcount_overflow(struct pt_regs *regs)
44741 +{
44742 + if (current->signal->curr_ip)
44743 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44744 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44745 + else
44746 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44747 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44748 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44749 + show_regs(regs);
44750 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44751 +}
44752 +#endif
44753 +
44754 +#ifdef CONFIG_PAX_USERCOPY
44755 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44756 +static noinline int check_stack_object(const void *obj, unsigned long len)
44757 +{
44758 + const void * const stack = task_stack_page(current);
44759 + const void * const stackend = stack + THREAD_SIZE;
44760 +
44761 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44762 + const void *frame = NULL;
44763 + const void *oldframe;
44764 +#endif
44765 +
44766 + if (obj + len < obj)
44767 + return -1;
44768 +
44769 + if (obj + len <= stack || stackend <= obj)
44770 + return 0;
44771 +
44772 + if (obj < stack || stackend < obj + len)
44773 + return -1;
44774 +
44775 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44776 + oldframe = __builtin_frame_address(1);
44777 + if (oldframe)
44778 + frame = __builtin_frame_address(2);
44779 + /*
44780 + low ----------------------------------------------> high
44781 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44782 + ^----------------^
44783 + allow copies only within here
44784 + */
44785 + while (stack <= frame && frame < stackend) {
44786 + /* if obj + len extends past the last frame, this
44787 + check won't pass and the next frame will be 0,
44788 + causing us to bail out and correctly report
44789 + the copy as invalid
44790 + */
44791 + if (obj + len <= frame)
44792 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44793 + oldframe = frame;
44794 + frame = *(const void * const *)frame;
44795 + }
44796 + return -1;
44797 +#else
44798 + return 1;
44799 +#endif
44800 +}
44801 +
44802 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44803 +{
44804 + if (current->signal->curr_ip)
44805 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44806 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44807 + else
44808 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44809 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44810 + dump_stack();
44811 + gr_handle_kernel_exploit();
44812 + do_group_exit(SIGKILL);
44813 +}
44814 +#endif
44815 +
44816 +void check_object_size(const void *ptr, unsigned long n, bool to)
44817 +{
44818 +
44819 +#ifdef CONFIG_PAX_USERCOPY
44820 + const char *type;
44821 +
44822 + if (!n)
44823 + return;
44824 +
44825 + type = check_heap_object(ptr, n, to);
44826 + if (!type) {
44827 + if (check_stack_object(ptr, n) != -1)
44828 + return;
44829 + type = "<process stack>";
44830 + }
44831 +
44832 + pax_report_usercopy(ptr, n, to, type);
44833 +#endif
44834 +
44835 +}
44836 +EXPORT_SYMBOL(check_object_size);
44837 +
44838 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44839 +void pax_track_stack(void)
44840 +{
44841 + unsigned long sp = (unsigned long)&sp;
44842 + if (sp < current_thread_info()->lowest_stack &&
44843 + sp > (unsigned long)task_stack_page(current))
44844 + current_thread_info()->lowest_stack = sp;
44845 +}
44846 +EXPORT_SYMBOL(pax_track_stack);
44847 +#endif
44848 +
44849 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44850 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44851 +{
44852 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44853 + dump_stack();
44854 + do_group_exit(SIGKILL);
44855 +}
44856 +EXPORT_SYMBOL(report_size_overflow);
44857 +#endif
44858 +
44859 static int zap_process(struct task_struct *start, int exit_code)
44860 {
44861 struct task_struct *t;
44862 @@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
44863 void set_dumpable(struct mm_struct *mm, int value)
44864 {
44865 switch (value) {
44866 - case 0:
44867 + case SUID_DUMPABLE_DISABLED:
44868 clear_bit(MMF_DUMPABLE, &mm->flags);
44869 smp_wmb();
44870 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44871 break;
44872 - case 1:
44873 + case SUID_DUMPABLE_ENABLED:
44874 set_bit(MMF_DUMPABLE, &mm->flags);
44875 smp_wmb();
44876 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44877 break;
44878 - case 2:
44879 + case SUID_DUMPABLE_SAFE:
44880 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44881 smp_wmb();
44882 set_bit(MMF_DUMPABLE, &mm->flags);
44883 @@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
44884 int ret;
44885
44886 ret = mm_flags & MMF_DUMPABLE_MASK;
44887 - return (ret >= 2) ? 2 : ret;
44888 + return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44889 }
44890
44891 int get_dumpable(struct mm_struct *mm)
44892 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
44893 pipe = file->f_path.dentry->d_inode->i_pipe;
44894
44895 pipe_lock(pipe);
44896 - pipe->readers++;
44897 - pipe->writers--;
44898 + atomic_inc(&pipe->readers);
44899 + atomic_dec(&pipe->writers);
44900
44901 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44902 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44903 wake_up_interruptible_sync(&pipe->wait);
44904 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44905 pipe_wait(pipe);
44906 }
44907
44908 - pipe->readers--;
44909 - pipe->writers++;
44910 + atomic_dec(&pipe->readers);
44911 + atomic_inc(&pipe->writers);
44912 pipe_unlock(pipe);
44913
44914 }
44915 @@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44916 int retval = 0;
44917 int flag = 0;
44918 int ispipe;
44919 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44920 + bool need_nonrelative = false;
44921 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44922 struct coredump_params cprm = {
44923 .signr = signr,
44924 .regs = regs,
44925 @@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44926
44927 audit_core_dumps(signr);
44928
44929 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44930 + gr_handle_brute_attach(current, cprm.mm_flags);
44931 +
44932 binfmt = mm->binfmt;
44933 if (!binfmt || !binfmt->core_dump)
44934 goto fail;
44935 @@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44936 if (!cred)
44937 goto fail;
44938 /*
44939 - * We cannot trust fsuid as being the "true" uid of the
44940 - * process nor do we know its entire history. We only know it
44941 - * was tainted so we dump it as root in mode 2.
44942 + * We cannot trust fsuid as being the "true" uid of the process
44943 + * nor do we know its entire history. We only know it was tainted
44944 + * so we dump it as root in mode 2, and only into a controlled
44945 + * environment (pipe handler or fully qualified path).
44946 */
44947 - if (__get_dumpable(cprm.mm_flags) == 2) {
44948 + if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
44949 /* Setuid core dump mode */
44950 flag = O_EXCL; /* Stop rewrite attacks */
44951 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
44952 + need_nonrelative = true;
44953 }
44954
44955 retval = coredump_wait(exit_code, &core_state);
44956 @@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44957 }
44958 cprm.limit = RLIM_INFINITY;
44959
44960 - dump_count = atomic_inc_return(&core_dump_count);
44961 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44962 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44963 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44964 task_tgid_vnr(current), current->comm);
44965 @@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44966 } else {
44967 struct inode *inode;
44968
44969 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44970 +
44971 if (cprm.limit < binfmt->min_coredump)
44972 goto fail_unlock;
44973
44974 + if (need_nonrelative && cn.corename[0] != '/') {
44975 + printk(KERN_WARNING "Pid %d(%s) can only dump core "\
44976 + "to fully qualified path!\n",
44977 + task_tgid_vnr(current), current->comm);
44978 + printk(KERN_WARNING "Skipping core dump\n");
44979 + goto fail_unlock;
44980 + }
44981 +
44982 cprm.file = filp_open(cn.corename,
44983 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
44984 0600);
44985 @@ -2263,7 +2655,7 @@ close_fail:
44986 filp_close(cprm.file, NULL);
44987 fail_dropcount:
44988 if (ispipe)
44989 - atomic_dec(&core_dump_count);
44990 + atomic_dec_unchecked(&core_dump_count);
44991 fail_unlock:
44992 kfree(cn.corename);
44993 fail_corename:
44994 @@ -2282,7 +2674,7 @@ fail:
44995 */
44996 int dump_write(struct file *file, const void *addr, int nr)
44997 {
44998 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44999 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45000 }
45001 EXPORT_SYMBOL(dump_write);
45002
45003 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45004 index 1c36139..cf6b350 100644
45005 --- a/fs/ext2/balloc.c
45006 +++ b/fs/ext2/balloc.c
45007 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45008
45009 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45010 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45011 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45012 + if (free_blocks < root_blocks + 1 &&
45013 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45014 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45015 - !in_group_p (sbi->s_resgid))) {
45016 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45017 return 0;
45018 }
45019 return 1;
45020 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45021 index 25cd608..9ed5294 100644
45022 --- a/fs/ext3/balloc.c
45023 +++ b/fs/ext3/balloc.c
45024 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45025
45026 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45027 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45028 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45029 + if (free_blocks < root_blocks + 1 &&
45030 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45031 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45032 - !in_group_p (sbi->s_resgid))) {
45033 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45034 return 0;
45035 }
45036 return 1;
45037 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45038 index cee7812..0e8e65c 100644
45039 --- a/fs/ext4/balloc.c
45040 +++ b/fs/ext4/balloc.c
45041 @@ -488,8 +488,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45042 /* Hm, nope. Are (enough) root reserved clusters available? */
45043 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45044 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45045 - capable(CAP_SYS_RESOURCE) ||
45046 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45047 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45048 + capable_nolog(CAP_SYS_RESOURCE)) {
45049
45050 if (free_clusters >= (nclusters + dirty_clusters))
45051 return 1;
45052 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45053 index cfc4e01..2f3fd3c 100644
45054 --- a/fs/ext4/ext4.h
45055 +++ b/fs/ext4/ext4.h
45056 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
45057 unsigned long s_mb_last_start;
45058
45059 /* stats for buddy allocator */
45060 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45061 - atomic_t s_bal_success; /* we found long enough chunks */
45062 - atomic_t s_bal_allocated; /* in blocks */
45063 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45064 - atomic_t s_bal_goals; /* goal hits */
45065 - atomic_t s_bal_breaks; /* too long searches */
45066 - atomic_t s_bal_2orders; /* 2^order hits */
45067 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45068 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45069 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45070 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45071 + atomic_unchecked_t s_bal_goals; /* goal hits */
45072 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45073 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45074 spinlock_t s_bal_lock;
45075 unsigned long s_mb_buddies_generated;
45076 unsigned long long s_mb_generation_time;
45077 - atomic_t s_mb_lost_chunks;
45078 - atomic_t s_mb_preallocated;
45079 - atomic_t s_mb_discarded;
45080 + atomic_unchecked_t s_mb_lost_chunks;
45081 + atomic_unchecked_t s_mb_preallocated;
45082 + atomic_unchecked_t s_mb_discarded;
45083 atomic_t s_lock_busy;
45084
45085 /* locality groups */
45086 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45087 index 1cd6994..5799d45 100644
45088 --- a/fs/ext4/mballoc.c
45089 +++ b/fs/ext4/mballoc.c
45090 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45091 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45092
45093 if (EXT4_SB(sb)->s_mb_stats)
45094 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45095 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45096
45097 break;
45098 }
45099 @@ -2041,7 +2041,7 @@ repeat:
45100 ac->ac_status = AC_STATUS_CONTINUE;
45101 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45102 cr = 3;
45103 - atomic_inc(&sbi->s_mb_lost_chunks);
45104 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45105 goto repeat;
45106 }
45107 }
45108 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45109 if (sbi->s_mb_stats) {
45110 ext4_msg(sb, KERN_INFO,
45111 "mballoc: %u blocks %u reqs (%u success)",
45112 - atomic_read(&sbi->s_bal_allocated),
45113 - atomic_read(&sbi->s_bal_reqs),
45114 - atomic_read(&sbi->s_bal_success));
45115 + atomic_read_unchecked(&sbi->s_bal_allocated),
45116 + atomic_read_unchecked(&sbi->s_bal_reqs),
45117 + atomic_read_unchecked(&sbi->s_bal_success));
45118 ext4_msg(sb, KERN_INFO,
45119 "mballoc: %u extents scanned, %u goal hits, "
45120 "%u 2^N hits, %u breaks, %u lost",
45121 - atomic_read(&sbi->s_bal_ex_scanned),
45122 - atomic_read(&sbi->s_bal_goals),
45123 - atomic_read(&sbi->s_bal_2orders),
45124 - atomic_read(&sbi->s_bal_breaks),
45125 - atomic_read(&sbi->s_mb_lost_chunks));
45126 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45127 + atomic_read_unchecked(&sbi->s_bal_goals),
45128 + atomic_read_unchecked(&sbi->s_bal_2orders),
45129 + atomic_read_unchecked(&sbi->s_bal_breaks),
45130 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45131 ext4_msg(sb, KERN_INFO,
45132 "mballoc: %lu generated and it took %Lu",
45133 sbi->s_mb_buddies_generated,
45134 sbi->s_mb_generation_time);
45135 ext4_msg(sb, KERN_INFO,
45136 "mballoc: %u preallocated, %u discarded",
45137 - atomic_read(&sbi->s_mb_preallocated),
45138 - atomic_read(&sbi->s_mb_discarded));
45139 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45140 + atomic_read_unchecked(&sbi->s_mb_discarded));
45141 }
45142
45143 free_percpu(sbi->s_locality_groups);
45144 @@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45145 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45146
45147 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45148 - atomic_inc(&sbi->s_bal_reqs);
45149 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45150 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45151 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45152 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45153 - atomic_inc(&sbi->s_bal_success);
45154 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45155 + atomic_inc_unchecked(&sbi->s_bal_success);
45156 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45157 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45158 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45159 - atomic_inc(&sbi->s_bal_goals);
45160 + atomic_inc_unchecked(&sbi->s_bal_goals);
45161 if (ac->ac_found > sbi->s_mb_max_to_scan)
45162 - atomic_inc(&sbi->s_bal_breaks);
45163 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45164 }
45165
45166 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45167 @@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45168 trace_ext4_mb_new_inode_pa(ac, pa);
45169
45170 ext4_mb_use_inode_pa(ac, pa);
45171 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45172 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45173
45174 ei = EXT4_I(ac->ac_inode);
45175 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45176 @@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45177 trace_ext4_mb_new_group_pa(ac, pa);
45178
45179 ext4_mb_use_group_pa(ac, pa);
45180 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45181 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45182
45183 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45184 lg = ac->ac_lg;
45185 @@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45186 * from the bitmap and continue.
45187 */
45188 }
45189 - atomic_add(free, &sbi->s_mb_discarded);
45190 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45191
45192 return err;
45193 }
45194 @@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45195 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45196 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45197 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45198 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45199 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45200 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45201
45202 return 0;
45203 diff --git a/fs/fcntl.c b/fs/fcntl.c
45204 index 81b70e6..d9ae6cf 100644
45205 --- a/fs/fcntl.c
45206 +++ b/fs/fcntl.c
45207 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45208 if (err)
45209 return err;
45210
45211 + if (gr_handle_chroot_fowner(pid, type))
45212 + return -ENOENT;
45213 + if (gr_check_protected_task_fowner(pid, type))
45214 + return -EACCES;
45215 +
45216 f_modown(filp, pid, type, force);
45217 return 0;
45218 }
45219 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45220
45221 static int f_setown_ex(struct file *filp, unsigned long arg)
45222 {
45223 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45224 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45225 struct f_owner_ex owner;
45226 struct pid *pid;
45227 int type;
45228 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45229
45230 static int f_getown_ex(struct file *filp, unsigned long arg)
45231 {
45232 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45233 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45234 struct f_owner_ex owner;
45235 int ret = 0;
45236
45237 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45238 switch (cmd) {
45239 case F_DUPFD:
45240 case F_DUPFD_CLOEXEC:
45241 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45242 if (arg >= rlimit(RLIMIT_NOFILE))
45243 break;
45244 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45245 diff --git a/fs/fifo.c b/fs/fifo.c
45246 index cf6f434..3d7942c 100644
45247 --- a/fs/fifo.c
45248 +++ b/fs/fifo.c
45249 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45250 */
45251 filp->f_op = &read_pipefifo_fops;
45252 pipe->r_counter++;
45253 - if (pipe->readers++ == 0)
45254 + if (atomic_inc_return(&pipe->readers) == 1)
45255 wake_up_partner(inode);
45256
45257 - if (!pipe->writers) {
45258 + if (!atomic_read(&pipe->writers)) {
45259 if ((filp->f_flags & O_NONBLOCK)) {
45260 /* suppress POLLHUP until we have
45261 * seen a writer */
45262 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45263 * errno=ENXIO when there is no process reading the FIFO.
45264 */
45265 ret = -ENXIO;
45266 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45267 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45268 goto err;
45269
45270 filp->f_op = &write_pipefifo_fops;
45271 pipe->w_counter++;
45272 - if (!pipe->writers++)
45273 + if (atomic_inc_return(&pipe->writers) == 1)
45274 wake_up_partner(inode);
45275
45276 - if (!pipe->readers) {
45277 + if (!atomic_read(&pipe->readers)) {
45278 if (wait_for_partner(inode, &pipe->r_counter))
45279 goto err_wr;
45280 }
45281 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45282 */
45283 filp->f_op = &rdwr_pipefifo_fops;
45284
45285 - pipe->readers++;
45286 - pipe->writers++;
45287 + atomic_inc(&pipe->readers);
45288 + atomic_inc(&pipe->writers);
45289 pipe->r_counter++;
45290 pipe->w_counter++;
45291 - if (pipe->readers == 1 || pipe->writers == 1)
45292 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45293 wake_up_partner(inode);
45294 break;
45295
45296 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45297 return 0;
45298
45299 err_rd:
45300 - if (!--pipe->readers)
45301 + if (atomic_dec_and_test(&pipe->readers))
45302 wake_up_interruptible(&pipe->wait);
45303 ret = -ERESTARTSYS;
45304 goto err;
45305
45306 err_wr:
45307 - if (!--pipe->writers)
45308 + if (atomic_dec_and_test(&pipe->writers))
45309 wake_up_interruptible(&pipe->wait);
45310 ret = -ERESTARTSYS;
45311 goto err;
45312
45313 err:
45314 - if (!pipe->readers && !pipe->writers)
45315 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45316 free_pipe_info(inode);
45317
45318 err_nocleanup:
45319 diff --git a/fs/file.c b/fs/file.c
45320 index ba3f605..fade102 100644
45321 --- a/fs/file.c
45322 +++ b/fs/file.c
45323 @@ -15,6 +15,7 @@
45324 #include <linux/slab.h>
45325 #include <linux/vmalloc.h>
45326 #include <linux/file.h>
45327 +#include <linux/security.h>
45328 #include <linux/fdtable.h>
45329 #include <linux/bitops.h>
45330 #include <linux/interrupt.h>
45331 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45332 * N.B. For clone tasks sharing a files structure, this test
45333 * will limit the total number of files that can be opened.
45334 */
45335 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45336 if (nr >= rlimit(RLIMIT_NOFILE))
45337 return -EMFILE;
45338
45339 diff --git a/fs/filesystems.c b/fs/filesystems.c
45340 index 96f2428..f5eeb8e 100644
45341 --- a/fs/filesystems.c
45342 +++ b/fs/filesystems.c
45343 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45344 int len = dot ? dot - name : strlen(name);
45345
45346 fs = __get_fs_type(name, len);
45347 +
45348 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45349 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45350 +#else
45351 if (!fs && (request_module("%.*s", len, name) == 0))
45352 +#endif
45353 fs = __get_fs_type(name, len);
45354
45355 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45356 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45357 index e159e68..e7d2a6f 100644
45358 --- a/fs/fs_struct.c
45359 +++ b/fs/fs_struct.c
45360 @@ -4,6 +4,7 @@
45361 #include <linux/path.h>
45362 #include <linux/slab.h>
45363 #include <linux/fs_struct.h>
45364 +#include <linux/grsecurity.h>
45365 #include "internal.h"
45366
45367 static inline void path_get_longterm(struct path *path)
45368 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45369 write_seqcount_begin(&fs->seq);
45370 old_root = fs->root;
45371 fs->root = *path;
45372 + gr_set_chroot_entries(current, path);
45373 write_seqcount_end(&fs->seq);
45374 spin_unlock(&fs->lock);
45375 if (old_root.dentry)
45376 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45377 return 1;
45378 }
45379
45380 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45381 +{
45382 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45383 + return 0;
45384 + *p = *new;
45385 +
45386 + gr_set_chroot_entries(task, new);
45387 +
45388 + return 1;
45389 +}
45390 +
45391 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45392 {
45393 struct task_struct *g, *p;
45394 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45395 int hits = 0;
45396 spin_lock(&fs->lock);
45397 write_seqcount_begin(&fs->seq);
45398 - hits += replace_path(&fs->root, old_root, new_root);
45399 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45400 hits += replace_path(&fs->pwd, old_root, new_root);
45401 write_seqcount_end(&fs->seq);
45402 while (hits--) {
45403 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45404 task_lock(tsk);
45405 spin_lock(&fs->lock);
45406 tsk->fs = NULL;
45407 - kill = !--fs->users;
45408 + gr_clear_chroot_entries(tsk);
45409 + kill = !atomic_dec_return(&fs->users);
45410 spin_unlock(&fs->lock);
45411 task_unlock(tsk);
45412 if (kill)
45413 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45414 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45415 /* We don't need to lock fs - think why ;-) */
45416 if (fs) {
45417 - fs->users = 1;
45418 + atomic_set(&fs->users, 1);
45419 fs->in_exec = 0;
45420 spin_lock_init(&fs->lock);
45421 seqcount_init(&fs->seq);
45422 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45423 spin_lock(&old->lock);
45424 fs->root = old->root;
45425 path_get_longterm(&fs->root);
45426 + /* instead of calling gr_set_chroot_entries here,
45427 + we call it from every caller of this function
45428 + */
45429 fs->pwd = old->pwd;
45430 path_get_longterm(&fs->pwd);
45431 spin_unlock(&old->lock);
45432 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45433
45434 task_lock(current);
45435 spin_lock(&fs->lock);
45436 - kill = !--fs->users;
45437 + kill = !atomic_dec_return(&fs->users);
45438 current->fs = new_fs;
45439 + gr_set_chroot_entries(current, &new_fs->root);
45440 spin_unlock(&fs->lock);
45441 task_unlock(current);
45442
45443 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45444
45445 int current_umask(void)
45446 {
45447 - return current->fs->umask;
45448 + return current->fs->umask | gr_acl_umask();
45449 }
45450 EXPORT_SYMBOL(current_umask);
45451
45452 /* to be mentioned only in INIT_TASK */
45453 struct fs_struct init_fs = {
45454 - .users = 1,
45455 + .users = ATOMIC_INIT(1),
45456 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45457 .seq = SEQCNT_ZERO,
45458 .umask = 0022,
45459 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45460 task_lock(current);
45461
45462 spin_lock(&init_fs.lock);
45463 - init_fs.users++;
45464 + atomic_inc(&init_fs.users);
45465 spin_unlock(&init_fs.lock);
45466
45467 spin_lock(&fs->lock);
45468 current->fs = &init_fs;
45469 - kill = !--fs->users;
45470 + gr_set_chroot_entries(current, &current->fs->root);
45471 + kill = !atomic_dec_return(&fs->users);
45472 spin_unlock(&fs->lock);
45473
45474 task_unlock(current);
45475 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45476 index 9905350..02eaec4 100644
45477 --- a/fs/fscache/cookie.c
45478 +++ b/fs/fscache/cookie.c
45479 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45480 parent ? (char *) parent->def->name : "<no-parent>",
45481 def->name, netfs_data);
45482
45483 - fscache_stat(&fscache_n_acquires);
45484 + fscache_stat_unchecked(&fscache_n_acquires);
45485
45486 /* if there's no parent cookie, then we don't create one here either */
45487 if (!parent) {
45488 - fscache_stat(&fscache_n_acquires_null);
45489 + fscache_stat_unchecked(&fscache_n_acquires_null);
45490 _leave(" [no parent]");
45491 return NULL;
45492 }
45493 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45494 /* allocate and initialise a cookie */
45495 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45496 if (!cookie) {
45497 - fscache_stat(&fscache_n_acquires_oom);
45498 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45499 _leave(" [ENOMEM]");
45500 return NULL;
45501 }
45502 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45503
45504 switch (cookie->def->type) {
45505 case FSCACHE_COOKIE_TYPE_INDEX:
45506 - fscache_stat(&fscache_n_cookie_index);
45507 + fscache_stat_unchecked(&fscache_n_cookie_index);
45508 break;
45509 case FSCACHE_COOKIE_TYPE_DATAFILE:
45510 - fscache_stat(&fscache_n_cookie_data);
45511 + fscache_stat_unchecked(&fscache_n_cookie_data);
45512 break;
45513 default:
45514 - fscache_stat(&fscache_n_cookie_special);
45515 + fscache_stat_unchecked(&fscache_n_cookie_special);
45516 break;
45517 }
45518
45519 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45520 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45521 atomic_dec(&parent->n_children);
45522 __fscache_cookie_put(cookie);
45523 - fscache_stat(&fscache_n_acquires_nobufs);
45524 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45525 _leave(" = NULL");
45526 return NULL;
45527 }
45528 }
45529
45530 - fscache_stat(&fscache_n_acquires_ok);
45531 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45532 _leave(" = %p", cookie);
45533 return cookie;
45534 }
45535 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45536 cache = fscache_select_cache_for_object(cookie->parent);
45537 if (!cache) {
45538 up_read(&fscache_addremove_sem);
45539 - fscache_stat(&fscache_n_acquires_no_cache);
45540 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45541 _leave(" = -ENOMEDIUM [no cache]");
45542 return -ENOMEDIUM;
45543 }
45544 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45545 object = cache->ops->alloc_object(cache, cookie);
45546 fscache_stat_d(&fscache_n_cop_alloc_object);
45547 if (IS_ERR(object)) {
45548 - fscache_stat(&fscache_n_object_no_alloc);
45549 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45550 ret = PTR_ERR(object);
45551 goto error;
45552 }
45553
45554 - fscache_stat(&fscache_n_object_alloc);
45555 + fscache_stat_unchecked(&fscache_n_object_alloc);
45556
45557 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45558
45559 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45560 struct fscache_object *object;
45561 struct hlist_node *_p;
45562
45563 - fscache_stat(&fscache_n_updates);
45564 + fscache_stat_unchecked(&fscache_n_updates);
45565
45566 if (!cookie) {
45567 - fscache_stat(&fscache_n_updates_null);
45568 + fscache_stat_unchecked(&fscache_n_updates_null);
45569 _leave(" [no cookie]");
45570 return;
45571 }
45572 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45573 struct fscache_object *object;
45574 unsigned long event;
45575
45576 - fscache_stat(&fscache_n_relinquishes);
45577 + fscache_stat_unchecked(&fscache_n_relinquishes);
45578 if (retire)
45579 - fscache_stat(&fscache_n_relinquishes_retire);
45580 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45581
45582 if (!cookie) {
45583 - fscache_stat(&fscache_n_relinquishes_null);
45584 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45585 _leave(" [no cookie]");
45586 return;
45587 }
45588 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45589
45590 /* wait for the cookie to finish being instantiated (or to fail) */
45591 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45592 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45593 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45594 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45595 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45596 }
45597 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45598 index f6aad48..88dcf26 100644
45599 --- a/fs/fscache/internal.h
45600 +++ b/fs/fscache/internal.h
45601 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45602 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45603 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45604
45605 -extern atomic_t fscache_n_op_pend;
45606 -extern atomic_t fscache_n_op_run;
45607 -extern atomic_t fscache_n_op_enqueue;
45608 -extern atomic_t fscache_n_op_deferred_release;
45609 -extern atomic_t fscache_n_op_release;
45610 -extern atomic_t fscache_n_op_gc;
45611 -extern atomic_t fscache_n_op_cancelled;
45612 -extern atomic_t fscache_n_op_rejected;
45613 +extern atomic_unchecked_t fscache_n_op_pend;
45614 +extern atomic_unchecked_t fscache_n_op_run;
45615 +extern atomic_unchecked_t fscache_n_op_enqueue;
45616 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45617 +extern atomic_unchecked_t fscache_n_op_release;
45618 +extern atomic_unchecked_t fscache_n_op_gc;
45619 +extern atomic_unchecked_t fscache_n_op_cancelled;
45620 +extern atomic_unchecked_t fscache_n_op_rejected;
45621
45622 -extern atomic_t fscache_n_attr_changed;
45623 -extern atomic_t fscache_n_attr_changed_ok;
45624 -extern atomic_t fscache_n_attr_changed_nobufs;
45625 -extern atomic_t fscache_n_attr_changed_nomem;
45626 -extern atomic_t fscache_n_attr_changed_calls;
45627 +extern atomic_unchecked_t fscache_n_attr_changed;
45628 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45629 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45630 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45631 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45632
45633 -extern atomic_t fscache_n_allocs;
45634 -extern atomic_t fscache_n_allocs_ok;
45635 -extern atomic_t fscache_n_allocs_wait;
45636 -extern atomic_t fscache_n_allocs_nobufs;
45637 -extern atomic_t fscache_n_allocs_intr;
45638 -extern atomic_t fscache_n_allocs_object_dead;
45639 -extern atomic_t fscache_n_alloc_ops;
45640 -extern atomic_t fscache_n_alloc_op_waits;
45641 +extern atomic_unchecked_t fscache_n_allocs;
45642 +extern atomic_unchecked_t fscache_n_allocs_ok;
45643 +extern atomic_unchecked_t fscache_n_allocs_wait;
45644 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45645 +extern atomic_unchecked_t fscache_n_allocs_intr;
45646 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45647 +extern atomic_unchecked_t fscache_n_alloc_ops;
45648 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45649
45650 -extern atomic_t fscache_n_retrievals;
45651 -extern atomic_t fscache_n_retrievals_ok;
45652 -extern atomic_t fscache_n_retrievals_wait;
45653 -extern atomic_t fscache_n_retrievals_nodata;
45654 -extern atomic_t fscache_n_retrievals_nobufs;
45655 -extern atomic_t fscache_n_retrievals_intr;
45656 -extern atomic_t fscache_n_retrievals_nomem;
45657 -extern atomic_t fscache_n_retrievals_object_dead;
45658 -extern atomic_t fscache_n_retrieval_ops;
45659 -extern atomic_t fscache_n_retrieval_op_waits;
45660 +extern atomic_unchecked_t fscache_n_retrievals;
45661 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45662 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45663 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45664 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45665 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45666 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45667 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45668 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45669 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45670
45671 -extern atomic_t fscache_n_stores;
45672 -extern atomic_t fscache_n_stores_ok;
45673 -extern atomic_t fscache_n_stores_again;
45674 -extern atomic_t fscache_n_stores_nobufs;
45675 -extern atomic_t fscache_n_stores_oom;
45676 -extern atomic_t fscache_n_store_ops;
45677 -extern atomic_t fscache_n_store_calls;
45678 -extern atomic_t fscache_n_store_pages;
45679 -extern atomic_t fscache_n_store_radix_deletes;
45680 -extern atomic_t fscache_n_store_pages_over_limit;
45681 +extern atomic_unchecked_t fscache_n_stores;
45682 +extern atomic_unchecked_t fscache_n_stores_ok;
45683 +extern atomic_unchecked_t fscache_n_stores_again;
45684 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45685 +extern atomic_unchecked_t fscache_n_stores_oom;
45686 +extern atomic_unchecked_t fscache_n_store_ops;
45687 +extern atomic_unchecked_t fscache_n_store_calls;
45688 +extern atomic_unchecked_t fscache_n_store_pages;
45689 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45690 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45691
45692 -extern atomic_t fscache_n_store_vmscan_not_storing;
45693 -extern atomic_t fscache_n_store_vmscan_gone;
45694 -extern atomic_t fscache_n_store_vmscan_busy;
45695 -extern atomic_t fscache_n_store_vmscan_cancelled;
45696 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45697 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45698 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45699 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45700
45701 -extern atomic_t fscache_n_marks;
45702 -extern atomic_t fscache_n_uncaches;
45703 +extern atomic_unchecked_t fscache_n_marks;
45704 +extern atomic_unchecked_t fscache_n_uncaches;
45705
45706 -extern atomic_t fscache_n_acquires;
45707 -extern atomic_t fscache_n_acquires_null;
45708 -extern atomic_t fscache_n_acquires_no_cache;
45709 -extern atomic_t fscache_n_acquires_ok;
45710 -extern atomic_t fscache_n_acquires_nobufs;
45711 -extern atomic_t fscache_n_acquires_oom;
45712 +extern atomic_unchecked_t fscache_n_acquires;
45713 +extern atomic_unchecked_t fscache_n_acquires_null;
45714 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45715 +extern atomic_unchecked_t fscache_n_acquires_ok;
45716 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45717 +extern atomic_unchecked_t fscache_n_acquires_oom;
45718
45719 -extern atomic_t fscache_n_updates;
45720 -extern atomic_t fscache_n_updates_null;
45721 -extern atomic_t fscache_n_updates_run;
45722 +extern atomic_unchecked_t fscache_n_updates;
45723 +extern atomic_unchecked_t fscache_n_updates_null;
45724 +extern atomic_unchecked_t fscache_n_updates_run;
45725
45726 -extern atomic_t fscache_n_relinquishes;
45727 -extern atomic_t fscache_n_relinquishes_null;
45728 -extern atomic_t fscache_n_relinquishes_waitcrt;
45729 -extern atomic_t fscache_n_relinquishes_retire;
45730 +extern atomic_unchecked_t fscache_n_relinquishes;
45731 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45732 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45733 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45734
45735 -extern atomic_t fscache_n_cookie_index;
45736 -extern atomic_t fscache_n_cookie_data;
45737 -extern atomic_t fscache_n_cookie_special;
45738 +extern atomic_unchecked_t fscache_n_cookie_index;
45739 +extern atomic_unchecked_t fscache_n_cookie_data;
45740 +extern atomic_unchecked_t fscache_n_cookie_special;
45741
45742 -extern atomic_t fscache_n_object_alloc;
45743 -extern atomic_t fscache_n_object_no_alloc;
45744 -extern atomic_t fscache_n_object_lookups;
45745 -extern atomic_t fscache_n_object_lookups_negative;
45746 -extern atomic_t fscache_n_object_lookups_positive;
45747 -extern atomic_t fscache_n_object_lookups_timed_out;
45748 -extern atomic_t fscache_n_object_created;
45749 -extern atomic_t fscache_n_object_avail;
45750 -extern atomic_t fscache_n_object_dead;
45751 +extern atomic_unchecked_t fscache_n_object_alloc;
45752 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45753 +extern atomic_unchecked_t fscache_n_object_lookups;
45754 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45755 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45756 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45757 +extern atomic_unchecked_t fscache_n_object_created;
45758 +extern atomic_unchecked_t fscache_n_object_avail;
45759 +extern atomic_unchecked_t fscache_n_object_dead;
45760
45761 -extern atomic_t fscache_n_checkaux_none;
45762 -extern atomic_t fscache_n_checkaux_okay;
45763 -extern atomic_t fscache_n_checkaux_update;
45764 -extern atomic_t fscache_n_checkaux_obsolete;
45765 +extern atomic_unchecked_t fscache_n_checkaux_none;
45766 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45767 +extern atomic_unchecked_t fscache_n_checkaux_update;
45768 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45769
45770 extern atomic_t fscache_n_cop_alloc_object;
45771 extern atomic_t fscache_n_cop_lookup_object;
45772 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45773 atomic_inc(stat);
45774 }
45775
45776 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45777 +{
45778 + atomic_inc_unchecked(stat);
45779 +}
45780 +
45781 static inline void fscache_stat_d(atomic_t *stat)
45782 {
45783 atomic_dec(stat);
45784 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45785
45786 #define __fscache_stat(stat) (NULL)
45787 #define fscache_stat(stat) do {} while (0)
45788 +#define fscache_stat_unchecked(stat) do {} while (0)
45789 #define fscache_stat_d(stat) do {} while (0)
45790 #endif
45791
45792 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45793 index b6b897c..0ffff9c 100644
45794 --- a/fs/fscache/object.c
45795 +++ b/fs/fscache/object.c
45796 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45797 /* update the object metadata on disk */
45798 case FSCACHE_OBJECT_UPDATING:
45799 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45800 - fscache_stat(&fscache_n_updates_run);
45801 + fscache_stat_unchecked(&fscache_n_updates_run);
45802 fscache_stat(&fscache_n_cop_update_object);
45803 object->cache->ops->update_object(object);
45804 fscache_stat_d(&fscache_n_cop_update_object);
45805 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45806 spin_lock(&object->lock);
45807 object->state = FSCACHE_OBJECT_DEAD;
45808 spin_unlock(&object->lock);
45809 - fscache_stat(&fscache_n_object_dead);
45810 + fscache_stat_unchecked(&fscache_n_object_dead);
45811 goto terminal_transit;
45812
45813 /* handle the parent cache of this object being withdrawn from
45814 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45815 spin_lock(&object->lock);
45816 object->state = FSCACHE_OBJECT_DEAD;
45817 spin_unlock(&object->lock);
45818 - fscache_stat(&fscache_n_object_dead);
45819 + fscache_stat_unchecked(&fscache_n_object_dead);
45820 goto terminal_transit;
45821
45822 /* complain about the object being woken up once it is
45823 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45824 parent->cookie->def->name, cookie->def->name,
45825 object->cache->tag->name);
45826
45827 - fscache_stat(&fscache_n_object_lookups);
45828 + fscache_stat_unchecked(&fscache_n_object_lookups);
45829 fscache_stat(&fscache_n_cop_lookup_object);
45830 ret = object->cache->ops->lookup_object(object);
45831 fscache_stat_d(&fscache_n_cop_lookup_object);
45832 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45833 if (ret == -ETIMEDOUT) {
45834 /* probably stuck behind another object, so move this one to
45835 * the back of the queue */
45836 - fscache_stat(&fscache_n_object_lookups_timed_out);
45837 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45838 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45839 }
45840
45841 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45842
45843 spin_lock(&object->lock);
45844 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45845 - fscache_stat(&fscache_n_object_lookups_negative);
45846 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45847
45848 /* transit here to allow write requests to begin stacking up
45849 * and read requests to begin returning ENODATA */
45850 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45851 * result, in which case there may be data available */
45852 spin_lock(&object->lock);
45853 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45854 - fscache_stat(&fscache_n_object_lookups_positive);
45855 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45856
45857 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45858
45859 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45860 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45861 } else {
45862 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45863 - fscache_stat(&fscache_n_object_created);
45864 + fscache_stat_unchecked(&fscache_n_object_created);
45865
45866 object->state = FSCACHE_OBJECT_AVAILABLE;
45867 spin_unlock(&object->lock);
45868 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45869 fscache_enqueue_dependents(object);
45870
45871 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45872 - fscache_stat(&fscache_n_object_avail);
45873 + fscache_stat_unchecked(&fscache_n_object_avail);
45874
45875 _leave("");
45876 }
45877 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45878 enum fscache_checkaux result;
45879
45880 if (!object->cookie->def->check_aux) {
45881 - fscache_stat(&fscache_n_checkaux_none);
45882 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45883 return FSCACHE_CHECKAUX_OKAY;
45884 }
45885
45886 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45887 switch (result) {
45888 /* entry okay as is */
45889 case FSCACHE_CHECKAUX_OKAY:
45890 - fscache_stat(&fscache_n_checkaux_okay);
45891 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45892 break;
45893
45894 /* entry requires update */
45895 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45896 - fscache_stat(&fscache_n_checkaux_update);
45897 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45898 break;
45899
45900 /* entry requires deletion */
45901 case FSCACHE_CHECKAUX_OBSOLETE:
45902 - fscache_stat(&fscache_n_checkaux_obsolete);
45903 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45904 break;
45905
45906 default:
45907 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45908 index 30afdfa..2256596 100644
45909 --- a/fs/fscache/operation.c
45910 +++ b/fs/fscache/operation.c
45911 @@ -17,7 +17,7 @@
45912 #include <linux/slab.h>
45913 #include "internal.h"
45914
45915 -atomic_t fscache_op_debug_id;
45916 +atomic_unchecked_t fscache_op_debug_id;
45917 EXPORT_SYMBOL(fscache_op_debug_id);
45918
45919 /**
45920 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45921 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45922 ASSERTCMP(atomic_read(&op->usage), >, 0);
45923
45924 - fscache_stat(&fscache_n_op_enqueue);
45925 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45926 switch (op->flags & FSCACHE_OP_TYPE) {
45927 case FSCACHE_OP_ASYNC:
45928 _debug("queue async");
45929 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45930 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45931 if (op->processor)
45932 fscache_enqueue_operation(op);
45933 - fscache_stat(&fscache_n_op_run);
45934 + fscache_stat_unchecked(&fscache_n_op_run);
45935 }
45936
45937 /*
45938 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45939 if (object->n_ops > 1) {
45940 atomic_inc(&op->usage);
45941 list_add_tail(&op->pend_link, &object->pending_ops);
45942 - fscache_stat(&fscache_n_op_pend);
45943 + fscache_stat_unchecked(&fscache_n_op_pend);
45944 } else if (!list_empty(&object->pending_ops)) {
45945 atomic_inc(&op->usage);
45946 list_add_tail(&op->pend_link, &object->pending_ops);
45947 - fscache_stat(&fscache_n_op_pend);
45948 + fscache_stat_unchecked(&fscache_n_op_pend);
45949 fscache_start_operations(object);
45950 } else {
45951 ASSERTCMP(object->n_in_progress, ==, 0);
45952 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45953 object->n_exclusive++; /* reads and writes must wait */
45954 atomic_inc(&op->usage);
45955 list_add_tail(&op->pend_link, &object->pending_ops);
45956 - fscache_stat(&fscache_n_op_pend);
45957 + fscache_stat_unchecked(&fscache_n_op_pend);
45958 ret = 0;
45959 } else {
45960 /* not allowed to submit ops in any other state */
45961 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45962 if (object->n_exclusive > 0) {
45963 atomic_inc(&op->usage);
45964 list_add_tail(&op->pend_link, &object->pending_ops);
45965 - fscache_stat(&fscache_n_op_pend);
45966 + fscache_stat_unchecked(&fscache_n_op_pend);
45967 } else if (!list_empty(&object->pending_ops)) {
45968 atomic_inc(&op->usage);
45969 list_add_tail(&op->pend_link, &object->pending_ops);
45970 - fscache_stat(&fscache_n_op_pend);
45971 + fscache_stat_unchecked(&fscache_n_op_pend);
45972 fscache_start_operations(object);
45973 } else {
45974 ASSERTCMP(object->n_exclusive, ==, 0);
45975 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45976 object->n_ops++;
45977 atomic_inc(&op->usage);
45978 list_add_tail(&op->pend_link, &object->pending_ops);
45979 - fscache_stat(&fscache_n_op_pend);
45980 + fscache_stat_unchecked(&fscache_n_op_pend);
45981 ret = 0;
45982 } else if (object->state == FSCACHE_OBJECT_DYING ||
45983 object->state == FSCACHE_OBJECT_LC_DYING ||
45984 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45985 - fscache_stat(&fscache_n_op_rejected);
45986 + fscache_stat_unchecked(&fscache_n_op_rejected);
45987 ret = -ENOBUFS;
45988 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45989 fscache_report_unexpected_submission(object, op, ostate);
45990 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45991
45992 ret = -EBUSY;
45993 if (!list_empty(&op->pend_link)) {
45994 - fscache_stat(&fscache_n_op_cancelled);
45995 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45996 list_del_init(&op->pend_link);
45997 object->n_ops--;
45998 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45999 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46000 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46001 BUG();
46002
46003 - fscache_stat(&fscache_n_op_release);
46004 + fscache_stat_unchecked(&fscache_n_op_release);
46005
46006 if (op->release) {
46007 op->release(op);
46008 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46009 * lock, and defer it otherwise */
46010 if (!spin_trylock(&object->lock)) {
46011 _debug("defer put");
46012 - fscache_stat(&fscache_n_op_deferred_release);
46013 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46014
46015 cache = object->cache;
46016 spin_lock(&cache->op_gc_list_lock);
46017 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46018
46019 _debug("GC DEFERRED REL OBJ%x OP%x",
46020 object->debug_id, op->debug_id);
46021 - fscache_stat(&fscache_n_op_gc);
46022 + fscache_stat_unchecked(&fscache_n_op_gc);
46023
46024 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46025
46026 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46027 index 3f7a59b..cf196cc 100644
46028 --- a/fs/fscache/page.c
46029 +++ b/fs/fscache/page.c
46030 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46031 val = radix_tree_lookup(&cookie->stores, page->index);
46032 if (!val) {
46033 rcu_read_unlock();
46034 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46035 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46036 __fscache_uncache_page(cookie, page);
46037 return true;
46038 }
46039 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46040 spin_unlock(&cookie->stores_lock);
46041
46042 if (xpage) {
46043 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46044 - fscache_stat(&fscache_n_store_radix_deletes);
46045 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46046 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46047 ASSERTCMP(xpage, ==, page);
46048 } else {
46049 - fscache_stat(&fscache_n_store_vmscan_gone);
46050 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46051 }
46052
46053 wake_up_bit(&cookie->flags, 0);
46054 @@ -107,7 +107,7 @@ page_busy:
46055 /* we might want to wait here, but that could deadlock the allocator as
46056 * the work threads writing to the cache may all end up sleeping
46057 * on memory allocation */
46058 - fscache_stat(&fscache_n_store_vmscan_busy);
46059 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46060 return false;
46061 }
46062 EXPORT_SYMBOL(__fscache_maybe_release_page);
46063 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46064 FSCACHE_COOKIE_STORING_TAG);
46065 if (!radix_tree_tag_get(&cookie->stores, page->index,
46066 FSCACHE_COOKIE_PENDING_TAG)) {
46067 - fscache_stat(&fscache_n_store_radix_deletes);
46068 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46069 xpage = radix_tree_delete(&cookie->stores, page->index);
46070 }
46071 spin_unlock(&cookie->stores_lock);
46072 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46073
46074 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46075
46076 - fscache_stat(&fscache_n_attr_changed_calls);
46077 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46078
46079 if (fscache_object_is_active(object)) {
46080 fscache_stat(&fscache_n_cop_attr_changed);
46081 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46082
46083 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46084
46085 - fscache_stat(&fscache_n_attr_changed);
46086 + fscache_stat_unchecked(&fscache_n_attr_changed);
46087
46088 op = kzalloc(sizeof(*op), GFP_KERNEL);
46089 if (!op) {
46090 - fscache_stat(&fscache_n_attr_changed_nomem);
46091 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46092 _leave(" = -ENOMEM");
46093 return -ENOMEM;
46094 }
46095 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46096 if (fscache_submit_exclusive_op(object, op) < 0)
46097 goto nobufs;
46098 spin_unlock(&cookie->lock);
46099 - fscache_stat(&fscache_n_attr_changed_ok);
46100 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46101 fscache_put_operation(op);
46102 _leave(" = 0");
46103 return 0;
46104 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46105 nobufs:
46106 spin_unlock(&cookie->lock);
46107 kfree(op);
46108 - fscache_stat(&fscache_n_attr_changed_nobufs);
46109 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46110 _leave(" = %d", -ENOBUFS);
46111 return -ENOBUFS;
46112 }
46113 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46114 /* allocate a retrieval operation and attempt to submit it */
46115 op = kzalloc(sizeof(*op), GFP_NOIO);
46116 if (!op) {
46117 - fscache_stat(&fscache_n_retrievals_nomem);
46118 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46119 return NULL;
46120 }
46121
46122 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46123 return 0;
46124 }
46125
46126 - fscache_stat(&fscache_n_retrievals_wait);
46127 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46128
46129 jif = jiffies;
46130 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46131 fscache_wait_bit_interruptible,
46132 TASK_INTERRUPTIBLE) != 0) {
46133 - fscache_stat(&fscache_n_retrievals_intr);
46134 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46135 _leave(" = -ERESTARTSYS");
46136 return -ERESTARTSYS;
46137 }
46138 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46139 */
46140 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46141 struct fscache_retrieval *op,
46142 - atomic_t *stat_op_waits,
46143 - atomic_t *stat_object_dead)
46144 + atomic_unchecked_t *stat_op_waits,
46145 + atomic_unchecked_t *stat_object_dead)
46146 {
46147 int ret;
46148
46149 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46150 goto check_if_dead;
46151
46152 _debug(">>> WT");
46153 - fscache_stat(stat_op_waits);
46154 + fscache_stat_unchecked(stat_op_waits);
46155 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46156 fscache_wait_bit_interruptible,
46157 TASK_INTERRUPTIBLE) < 0) {
46158 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46159
46160 check_if_dead:
46161 if (unlikely(fscache_object_is_dead(object))) {
46162 - fscache_stat(stat_object_dead);
46163 + fscache_stat_unchecked(stat_object_dead);
46164 return -ENOBUFS;
46165 }
46166 return 0;
46167 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46168
46169 _enter("%p,%p,,,", cookie, page);
46170
46171 - fscache_stat(&fscache_n_retrievals);
46172 + fscache_stat_unchecked(&fscache_n_retrievals);
46173
46174 if (hlist_empty(&cookie->backing_objects))
46175 goto nobufs;
46176 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46177 goto nobufs_unlock;
46178 spin_unlock(&cookie->lock);
46179
46180 - fscache_stat(&fscache_n_retrieval_ops);
46181 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46182
46183 /* pin the netfs read context in case we need to do the actual netfs
46184 * read because we've encountered a cache read failure */
46185 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46186
46187 error:
46188 if (ret == -ENOMEM)
46189 - fscache_stat(&fscache_n_retrievals_nomem);
46190 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46191 else if (ret == -ERESTARTSYS)
46192 - fscache_stat(&fscache_n_retrievals_intr);
46193 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46194 else if (ret == -ENODATA)
46195 - fscache_stat(&fscache_n_retrievals_nodata);
46196 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46197 else if (ret < 0)
46198 - fscache_stat(&fscache_n_retrievals_nobufs);
46199 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46200 else
46201 - fscache_stat(&fscache_n_retrievals_ok);
46202 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46203
46204 fscache_put_retrieval(op);
46205 _leave(" = %d", ret);
46206 @@ -429,7 +429,7 @@ nobufs_unlock:
46207 spin_unlock(&cookie->lock);
46208 kfree(op);
46209 nobufs:
46210 - fscache_stat(&fscache_n_retrievals_nobufs);
46211 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46212 _leave(" = -ENOBUFS");
46213 return -ENOBUFS;
46214 }
46215 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46216
46217 _enter("%p,,%d,,,", cookie, *nr_pages);
46218
46219 - fscache_stat(&fscache_n_retrievals);
46220 + fscache_stat_unchecked(&fscache_n_retrievals);
46221
46222 if (hlist_empty(&cookie->backing_objects))
46223 goto nobufs;
46224 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46225 goto nobufs_unlock;
46226 spin_unlock(&cookie->lock);
46227
46228 - fscache_stat(&fscache_n_retrieval_ops);
46229 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46230
46231 /* pin the netfs read context in case we need to do the actual netfs
46232 * read because we've encountered a cache read failure */
46233 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46234
46235 error:
46236 if (ret == -ENOMEM)
46237 - fscache_stat(&fscache_n_retrievals_nomem);
46238 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46239 else if (ret == -ERESTARTSYS)
46240 - fscache_stat(&fscache_n_retrievals_intr);
46241 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46242 else if (ret == -ENODATA)
46243 - fscache_stat(&fscache_n_retrievals_nodata);
46244 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46245 else if (ret < 0)
46246 - fscache_stat(&fscache_n_retrievals_nobufs);
46247 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46248 else
46249 - fscache_stat(&fscache_n_retrievals_ok);
46250 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46251
46252 fscache_put_retrieval(op);
46253 _leave(" = %d", ret);
46254 @@ -545,7 +545,7 @@ nobufs_unlock:
46255 spin_unlock(&cookie->lock);
46256 kfree(op);
46257 nobufs:
46258 - fscache_stat(&fscache_n_retrievals_nobufs);
46259 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46260 _leave(" = -ENOBUFS");
46261 return -ENOBUFS;
46262 }
46263 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46264
46265 _enter("%p,%p,,,", cookie, page);
46266
46267 - fscache_stat(&fscache_n_allocs);
46268 + fscache_stat_unchecked(&fscache_n_allocs);
46269
46270 if (hlist_empty(&cookie->backing_objects))
46271 goto nobufs;
46272 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46273 goto nobufs_unlock;
46274 spin_unlock(&cookie->lock);
46275
46276 - fscache_stat(&fscache_n_alloc_ops);
46277 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46278
46279 ret = fscache_wait_for_retrieval_activation(
46280 object, op,
46281 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46282
46283 error:
46284 if (ret == -ERESTARTSYS)
46285 - fscache_stat(&fscache_n_allocs_intr);
46286 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46287 else if (ret < 0)
46288 - fscache_stat(&fscache_n_allocs_nobufs);
46289 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46290 else
46291 - fscache_stat(&fscache_n_allocs_ok);
46292 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46293
46294 fscache_put_retrieval(op);
46295 _leave(" = %d", ret);
46296 @@ -625,7 +625,7 @@ nobufs_unlock:
46297 spin_unlock(&cookie->lock);
46298 kfree(op);
46299 nobufs:
46300 - fscache_stat(&fscache_n_allocs_nobufs);
46301 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46302 _leave(" = -ENOBUFS");
46303 return -ENOBUFS;
46304 }
46305 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46306
46307 spin_lock(&cookie->stores_lock);
46308
46309 - fscache_stat(&fscache_n_store_calls);
46310 + fscache_stat_unchecked(&fscache_n_store_calls);
46311
46312 /* find a page to store */
46313 page = NULL;
46314 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46315 page = results[0];
46316 _debug("gang %d [%lx]", n, page->index);
46317 if (page->index > op->store_limit) {
46318 - fscache_stat(&fscache_n_store_pages_over_limit);
46319 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46320 goto superseded;
46321 }
46322
46323 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46324 spin_unlock(&cookie->stores_lock);
46325 spin_unlock(&object->lock);
46326
46327 - fscache_stat(&fscache_n_store_pages);
46328 + fscache_stat_unchecked(&fscache_n_store_pages);
46329 fscache_stat(&fscache_n_cop_write_page);
46330 ret = object->cache->ops->write_page(op, page);
46331 fscache_stat_d(&fscache_n_cop_write_page);
46332 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46333 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46334 ASSERT(PageFsCache(page));
46335
46336 - fscache_stat(&fscache_n_stores);
46337 + fscache_stat_unchecked(&fscache_n_stores);
46338
46339 op = kzalloc(sizeof(*op), GFP_NOIO);
46340 if (!op)
46341 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46342 spin_unlock(&cookie->stores_lock);
46343 spin_unlock(&object->lock);
46344
46345 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46346 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46347 op->store_limit = object->store_limit;
46348
46349 if (fscache_submit_op(object, &op->op) < 0)
46350 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46351
46352 spin_unlock(&cookie->lock);
46353 radix_tree_preload_end();
46354 - fscache_stat(&fscache_n_store_ops);
46355 - fscache_stat(&fscache_n_stores_ok);
46356 + fscache_stat_unchecked(&fscache_n_store_ops);
46357 + fscache_stat_unchecked(&fscache_n_stores_ok);
46358
46359 /* the work queue now carries its own ref on the object */
46360 fscache_put_operation(&op->op);
46361 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46362 return 0;
46363
46364 already_queued:
46365 - fscache_stat(&fscache_n_stores_again);
46366 + fscache_stat_unchecked(&fscache_n_stores_again);
46367 already_pending:
46368 spin_unlock(&cookie->stores_lock);
46369 spin_unlock(&object->lock);
46370 spin_unlock(&cookie->lock);
46371 radix_tree_preload_end();
46372 kfree(op);
46373 - fscache_stat(&fscache_n_stores_ok);
46374 + fscache_stat_unchecked(&fscache_n_stores_ok);
46375 _leave(" = 0");
46376 return 0;
46377
46378 @@ -851,14 +851,14 @@ nobufs:
46379 spin_unlock(&cookie->lock);
46380 radix_tree_preload_end();
46381 kfree(op);
46382 - fscache_stat(&fscache_n_stores_nobufs);
46383 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46384 _leave(" = -ENOBUFS");
46385 return -ENOBUFS;
46386
46387 nomem_free:
46388 kfree(op);
46389 nomem:
46390 - fscache_stat(&fscache_n_stores_oom);
46391 + fscache_stat_unchecked(&fscache_n_stores_oom);
46392 _leave(" = -ENOMEM");
46393 return -ENOMEM;
46394 }
46395 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46396 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46397 ASSERTCMP(page, !=, NULL);
46398
46399 - fscache_stat(&fscache_n_uncaches);
46400 + fscache_stat_unchecked(&fscache_n_uncaches);
46401
46402 /* cache withdrawal may beat us to it */
46403 if (!PageFsCache(page))
46404 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46405 unsigned long loop;
46406
46407 #ifdef CONFIG_FSCACHE_STATS
46408 - atomic_add(pagevec->nr, &fscache_n_marks);
46409 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46410 #endif
46411
46412 for (loop = 0; loop < pagevec->nr; loop++) {
46413 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46414 index 4765190..2a067f2 100644
46415 --- a/fs/fscache/stats.c
46416 +++ b/fs/fscache/stats.c
46417 @@ -18,95 +18,95 @@
46418 /*
46419 * operation counters
46420 */
46421 -atomic_t fscache_n_op_pend;
46422 -atomic_t fscache_n_op_run;
46423 -atomic_t fscache_n_op_enqueue;
46424 -atomic_t fscache_n_op_requeue;
46425 -atomic_t fscache_n_op_deferred_release;
46426 -atomic_t fscache_n_op_release;
46427 -atomic_t fscache_n_op_gc;
46428 -atomic_t fscache_n_op_cancelled;
46429 -atomic_t fscache_n_op_rejected;
46430 +atomic_unchecked_t fscache_n_op_pend;
46431 +atomic_unchecked_t fscache_n_op_run;
46432 +atomic_unchecked_t fscache_n_op_enqueue;
46433 +atomic_unchecked_t fscache_n_op_requeue;
46434 +atomic_unchecked_t fscache_n_op_deferred_release;
46435 +atomic_unchecked_t fscache_n_op_release;
46436 +atomic_unchecked_t fscache_n_op_gc;
46437 +atomic_unchecked_t fscache_n_op_cancelled;
46438 +atomic_unchecked_t fscache_n_op_rejected;
46439
46440 -atomic_t fscache_n_attr_changed;
46441 -atomic_t fscache_n_attr_changed_ok;
46442 -atomic_t fscache_n_attr_changed_nobufs;
46443 -atomic_t fscache_n_attr_changed_nomem;
46444 -atomic_t fscache_n_attr_changed_calls;
46445 +atomic_unchecked_t fscache_n_attr_changed;
46446 +atomic_unchecked_t fscache_n_attr_changed_ok;
46447 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46448 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46449 +atomic_unchecked_t fscache_n_attr_changed_calls;
46450
46451 -atomic_t fscache_n_allocs;
46452 -atomic_t fscache_n_allocs_ok;
46453 -atomic_t fscache_n_allocs_wait;
46454 -atomic_t fscache_n_allocs_nobufs;
46455 -atomic_t fscache_n_allocs_intr;
46456 -atomic_t fscache_n_allocs_object_dead;
46457 -atomic_t fscache_n_alloc_ops;
46458 -atomic_t fscache_n_alloc_op_waits;
46459 +atomic_unchecked_t fscache_n_allocs;
46460 +atomic_unchecked_t fscache_n_allocs_ok;
46461 +atomic_unchecked_t fscache_n_allocs_wait;
46462 +atomic_unchecked_t fscache_n_allocs_nobufs;
46463 +atomic_unchecked_t fscache_n_allocs_intr;
46464 +atomic_unchecked_t fscache_n_allocs_object_dead;
46465 +atomic_unchecked_t fscache_n_alloc_ops;
46466 +atomic_unchecked_t fscache_n_alloc_op_waits;
46467
46468 -atomic_t fscache_n_retrievals;
46469 -atomic_t fscache_n_retrievals_ok;
46470 -atomic_t fscache_n_retrievals_wait;
46471 -atomic_t fscache_n_retrievals_nodata;
46472 -atomic_t fscache_n_retrievals_nobufs;
46473 -atomic_t fscache_n_retrievals_intr;
46474 -atomic_t fscache_n_retrievals_nomem;
46475 -atomic_t fscache_n_retrievals_object_dead;
46476 -atomic_t fscache_n_retrieval_ops;
46477 -atomic_t fscache_n_retrieval_op_waits;
46478 +atomic_unchecked_t fscache_n_retrievals;
46479 +atomic_unchecked_t fscache_n_retrievals_ok;
46480 +atomic_unchecked_t fscache_n_retrievals_wait;
46481 +atomic_unchecked_t fscache_n_retrievals_nodata;
46482 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46483 +atomic_unchecked_t fscache_n_retrievals_intr;
46484 +atomic_unchecked_t fscache_n_retrievals_nomem;
46485 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46486 +atomic_unchecked_t fscache_n_retrieval_ops;
46487 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46488
46489 -atomic_t fscache_n_stores;
46490 -atomic_t fscache_n_stores_ok;
46491 -atomic_t fscache_n_stores_again;
46492 -atomic_t fscache_n_stores_nobufs;
46493 -atomic_t fscache_n_stores_oom;
46494 -atomic_t fscache_n_store_ops;
46495 -atomic_t fscache_n_store_calls;
46496 -atomic_t fscache_n_store_pages;
46497 -atomic_t fscache_n_store_radix_deletes;
46498 -atomic_t fscache_n_store_pages_over_limit;
46499 +atomic_unchecked_t fscache_n_stores;
46500 +atomic_unchecked_t fscache_n_stores_ok;
46501 +atomic_unchecked_t fscache_n_stores_again;
46502 +atomic_unchecked_t fscache_n_stores_nobufs;
46503 +atomic_unchecked_t fscache_n_stores_oom;
46504 +atomic_unchecked_t fscache_n_store_ops;
46505 +atomic_unchecked_t fscache_n_store_calls;
46506 +atomic_unchecked_t fscache_n_store_pages;
46507 +atomic_unchecked_t fscache_n_store_radix_deletes;
46508 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46509
46510 -atomic_t fscache_n_store_vmscan_not_storing;
46511 -atomic_t fscache_n_store_vmscan_gone;
46512 -atomic_t fscache_n_store_vmscan_busy;
46513 -atomic_t fscache_n_store_vmscan_cancelled;
46514 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46515 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46516 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46517 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46518
46519 -atomic_t fscache_n_marks;
46520 -atomic_t fscache_n_uncaches;
46521 +atomic_unchecked_t fscache_n_marks;
46522 +atomic_unchecked_t fscache_n_uncaches;
46523
46524 -atomic_t fscache_n_acquires;
46525 -atomic_t fscache_n_acquires_null;
46526 -atomic_t fscache_n_acquires_no_cache;
46527 -atomic_t fscache_n_acquires_ok;
46528 -atomic_t fscache_n_acquires_nobufs;
46529 -atomic_t fscache_n_acquires_oom;
46530 +atomic_unchecked_t fscache_n_acquires;
46531 +atomic_unchecked_t fscache_n_acquires_null;
46532 +atomic_unchecked_t fscache_n_acquires_no_cache;
46533 +atomic_unchecked_t fscache_n_acquires_ok;
46534 +atomic_unchecked_t fscache_n_acquires_nobufs;
46535 +atomic_unchecked_t fscache_n_acquires_oom;
46536
46537 -atomic_t fscache_n_updates;
46538 -atomic_t fscache_n_updates_null;
46539 -atomic_t fscache_n_updates_run;
46540 +atomic_unchecked_t fscache_n_updates;
46541 +atomic_unchecked_t fscache_n_updates_null;
46542 +atomic_unchecked_t fscache_n_updates_run;
46543
46544 -atomic_t fscache_n_relinquishes;
46545 -atomic_t fscache_n_relinquishes_null;
46546 -atomic_t fscache_n_relinquishes_waitcrt;
46547 -atomic_t fscache_n_relinquishes_retire;
46548 +atomic_unchecked_t fscache_n_relinquishes;
46549 +atomic_unchecked_t fscache_n_relinquishes_null;
46550 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46551 +atomic_unchecked_t fscache_n_relinquishes_retire;
46552
46553 -atomic_t fscache_n_cookie_index;
46554 -atomic_t fscache_n_cookie_data;
46555 -atomic_t fscache_n_cookie_special;
46556 +atomic_unchecked_t fscache_n_cookie_index;
46557 +atomic_unchecked_t fscache_n_cookie_data;
46558 +atomic_unchecked_t fscache_n_cookie_special;
46559
46560 -atomic_t fscache_n_object_alloc;
46561 -atomic_t fscache_n_object_no_alloc;
46562 -atomic_t fscache_n_object_lookups;
46563 -atomic_t fscache_n_object_lookups_negative;
46564 -atomic_t fscache_n_object_lookups_positive;
46565 -atomic_t fscache_n_object_lookups_timed_out;
46566 -atomic_t fscache_n_object_created;
46567 -atomic_t fscache_n_object_avail;
46568 -atomic_t fscache_n_object_dead;
46569 +atomic_unchecked_t fscache_n_object_alloc;
46570 +atomic_unchecked_t fscache_n_object_no_alloc;
46571 +atomic_unchecked_t fscache_n_object_lookups;
46572 +atomic_unchecked_t fscache_n_object_lookups_negative;
46573 +atomic_unchecked_t fscache_n_object_lookups_positive;
46574 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46575 +atomic_unchecked_t fscache_n_object_created;
46576 +atomic_unchecked_t fscache_n_object_avail;
46577 +atomic_unchecked_t fscache_n_object_dead;
46578
46579 -atomic_t fscache_n_checkaux_none;
46580 -atomic_t fscache_n_checkaux_okay;
46581 -atomic_t fscache_n_checkaux_update;
46582 -atomic_t fscache_n_checkaux_obsolete;
46583 +atomic_unchecked_t fscache_n_checkaux_none;
46584 +atomic_unchecked_t fscache_n_checkaux_okay;
46585 +atomic_unchecked_t fscache_n_checkaux_update;
46586 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46587
46588 atomic_t fscache_n_cop_alloc_object;
46589 atomic_t fscache_n_cop_lookup_object;
46590 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46591 seq_puts(m, "FS-Cache statistics\n");
46592
46593 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46594 - atomic_read(&fscache_n_cookie_index),
46595 - atomic_read(&fscache_n_cookie_data),
46596 - atomic_read(&fscache_n_cookie_special));
46597 + atomic_read_unchecked(&fscache_n_cookie_index),
46598 + atomic_read_unchecked(&fscache_n_cookie_data),
46599 + atomic_read_unchecked(&fscache_n_cookie_special));
46600
46601 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46602 - atomic_read(&fscache_n_object_alloc),
46603 - atomic_read(&fscache_n_object_no_alloc),
46604 - atomic_read(&fscache_n_object_avail),
46605 - atomic_read(&fscache_n_object_dead));
46606 + atomic_read_unchecked(&fscache_n_object_alloc),
46607 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46608 + atomic_read_unchecked(&fscache_n_object_avail),
46609 + atomic_read_unchecked(&fscache_n_object_dead));
46610 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46611 - atomic_read(&fscache_n_checkaux_none),
46612 - atomic_read(&fscache_n_checkaux_okay),
46613 - atomic_read(&fscache_n_checkaux_update),
46614 - atomic_read(&fscache_n_checkaux_obsolete));
46615 + atomic_read_unchecked(&fscache_n_checkaux_none),
46616 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46617 + atomic_read_unchecked(&fscache_n_checkaux_update),
46618 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46619
46620 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46621 - atomic_read(&fscache_n_marks),
46622 - atomic_read(&fscache_n_uncaches));
46623 + atomic_read_unchecked(&fscache_n_marks),
46624 + atomic_read_unchecked(&fscache_n_uncaches));
46625
46626 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46627 " oom=%u\n",
46628 - atomic_read(&fscache_n_acquires),
46629 - atomic_read(&fscache_n_acquires_null),
46630 - atomic_read(&fscache_n_acquires_no_cache),
46631 - atomic_read(&fscache_n_acquires_ok),
46632 - atomic_read(&fscache_n_acquires_nobufs),
46633 - atomic_read(&fscache_n_acquires_oom));
46634 + atomic_read_unchecked(&fscache_n_acquires),
46635 + atomic_read_unchecked(&fscache_n_acquires_null),
46636 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46637 + atomic_read_unchecked(&fscache_n_acquires_ok),
46638 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46639 + atomic_read_unchecked(&fscache_n_acquires_oom));
46640
46641 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46642 - atomic_read(&fscache_n_object_lookups),
46643 - atomic_read(&fscache_n_object_lookups_negative),
46644 - atomic_read(&fscache_n_object_lookups_positive),
46645 - atomic_read(&fscache_n_object_created),
46646 - atomic_read(&fscache_n_object_lookups_timed_out));
46647 + atomic_read_unchecked(&fscache_n_object_lookups),
46648 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46649 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46650 + atomic_read_unchecked(&fscache_n_object_created),
46651 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46652
46653 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46654 - atomic_read(&fscache_n_updates),
46655 - atomic_read(&fscache_n_updates_null),
46656 - atomic_read(&fscache_n_updates_run));
46657 + atomic_read_unchecked(&fscache_n_updates),
46658 + atomic_read_unchecked(&fscache_n_updates_null),
46659 + atomic_read_unchecked(&fscache_n_updates_run));
46660
46661 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46662 - atomic_read(&fscache_n_relinquishes),
46663 - atomic_read(&fscache_n_relinquishes_null),
46664 - atomic_read(&fscache_n_relinquishes_waitcrt),
46665 - atomic_read(&fscache_n_relinquishes_retire));
46666 + atomic_read_unchecked(&fscache_n_relinquishes),
46667 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46668 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46669 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46670
46671 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46672 - atomic_read(&fscache_n_attr_changed),
46673 - atomic_read(&fscache_n_attr_changed_ok),
46674 - atomic_read(&fscache_n_attr_changed_nobufs),
46675 - atomic_read(&fscache_n_attr_changed_nomem),
46676 - atomic_read(&fscache_n_attr_changed_calls));
46677 + atomic_read_unchecked(&fscache_n_attr_changed),
46678 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46679 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46680 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46681 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46682
46683 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46684 - atomic_read(&fscache_n_allocs),
46685 - atomic_read(&fscache_n_allocs_ok),
46686 - atomic_read(&fscache_n_allocs_wait),
46687 - atomic_read(&fscache_n_allocs_nobufs),
46688 - atomic_read(&fscache_n_allocs_intr));
46689 + atomic_read_unchecked(&fscache_n_allocs),
46690 + atomic_read_unchecked(&fscache_n_allocs_ok),
46691 + atomic_read_unchecked(&fscache_n_allocs_wait),
46692 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46693 + atomic_read_unchecked(&fscache_n_allocs_intr));
46694 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46695 - atomic_read(&fscache_n_alloc_ops),
46696 - atomic_read(&fscache_n_alloc_op_waits),
46697 - atomic_read(&fscache_n_allocs_object_dead));
46698 + atomic_read_unchecked(&fscache_n_alloc_ops),
46699 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46700 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46701
46702 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46703 " int=%u oom=%u\n",
46704 - atomic_read(&fscache_n_retrievals),
46705 - atomic_read(&fscache_n_retrievals_ok),
46706 - atomic_read(&fscache_n_retrievals_wait),
46707 - atomic_read(&fscache_n_retrievals_nodata),
46708 - atomic_read(&fscache_n_retrievals_nobufs),
46709 - atomic_read(&fscache_n_retrievals_intr),
46710 - atomic_read(&fscache_n_retrievals_nomem));
46711 + atomic_read_unchecked(&fscache_n_retrievals),
46712 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46713 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46714 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46715 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46716 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46717 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46718 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46719 - atomic_read(&fscache_n_retrieval_ops),
46720 - atomic_read(&fscache_n_retrieval_op_waits),
46721 - atomic_read(&fscache_n_retrievals_object_dead));
46722 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46723 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46724 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46725
46726 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46727 - atomic_read(&fscache_n_stores),
46728 - atomic_read(&fscache_n_stores_ok),
46729 - atomic_read(&fscache_n_stores_again),
46730 - atomic_read(&fscache_n_stores_nobufs),
46731 - atomic_read(&fscache_n_stores_oom));
46732 + atomic_read_unchecked(&fscache_n_stores),
46733 + atomic_read_unchecked(&fscache_n_stores_ok),
46734 + atomic_read_unchecked(&fscache_n_stores_again),
46735 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46736 + atomic_read_unchecked(&fscache_n_stores_oom));
46737 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46738 - atomic_read(&fscache_n_store_ops),
46739 - atomic_read(&fscache_n_store_calls),
46740 - atomic_read(&fscache_n_store_pages),
46741 - atomic_read(&fscache_n_store_radix_deletes),
46742 - atomic_read(&fscache_n_store_pages_over_limit));
46743 + atomic_read_unchecked(&fscache_n_store_ops),
46744 + atomic_read_unchecked(&fscache_n_store_calls),
46745 + atomic_read_unchecked(&fscache_n_store_pages),
46746 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46747 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46748
46749 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46750 - atomic_read(&fscache_n_store_vmscan_not_storing),
46751 - atomic_read(&fscache_n_store_vmscan_gone),
46752 - atomic_read(&fscache_n_store_vmscan_busy),
46753 - atomic_read(&fscache_n_store_vmscan_cancelled));
46754 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46755 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46756 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46757 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46758
46759 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46760 - atomic_read(&fscache_n_op_pend),
46761 - atomic_read(&fscache_n_op_run),
46762 - atomic_read(&fscache_n_op_enqueue),
46763 - atomic_read(&fscache_n_op_cancelled),
46764 - atomic_read(&fscache_n_op_rejected));
46765 + atomic_read_unchecked(&fscache_n_op_pend),
46766 + atomic_read_unchecked(&fscache_n_op_run),
46767 + atomic_read_unchecked(&fscache_n_op_enqueue),
46768 + atomic_read_unchecked(&fscache_n_op_cancelled),
46769 + atomic_read_unchecked(&fscache_n_op_rejected));
46770 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46771 - atomic_read(&fscache_n_op_deferred_release),
46772 - atomic_read(&fscache_n_op_release),
46773 - atomic_read(&fscache_n_op_gc));
46774 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46775 + atomic_read_unchecked(&fscache_n_op_release),
46776 + atomic_read_unchecked(&fscache_n_op_gc));
46777
46778 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46779 atomic_read(&fscache_n_cop_alloc_object),
46780 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46781 index 3426521..3b75162 100644
46782 --- a/fs/fuse/cuse.c
46783 +++ b/fs/fuse/cuse.c
46784 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46785 INIT_LIST_HEAD(&cuse_conntbl[i]);
46786
46787 /* inherit and extend fuse_dev_operations */
46788 - cuse_channel_fops = fuse_dev_operations;
46789 - cuse_channel_fops.owner = THIS_MODULE;
46790 - cuse_channel_fops.open = cuse_channel_open;
46791 - cuse_channel_fops.release = cuse_channel_release;
46792 + pax_open_kernel();
46793 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46794 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46795 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46796 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46797 + pax_close_kernel();
46798
46799 cuse_class = class_create(THIS_MODULE, "cuse");
46800 if (IS_ERR(cuse_class))
46801 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46802 index 7df2b5e..5804aa7 100644
46803 --- a/fs/fuse/dev.c
46804 +++ b/fs/fuse/dev.c
46805 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46806 ret = 0;
46807 pipe_lock(pipe);
46808
46809 - if (!pipe->readers) {
46810 + if (!atomic_read(&pipe->readers)) {
46811 send_sig(SIGPIPE, current, 0);
46812 if (!ret)
46813 ret = -EPIPE;
46814 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46815 index 334e0b1..fc571e8 100644
46816 --- a/fs/fuse/dir.c
46817 +++ b/fs/fuse/dir.c
46818 @@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46819 return link;
46820 }
46821
46822 -static void free_link(char *link)
46823 +static void free_link(const char *link)
46824 {
46825 if (!IS_ERR(link))
46826 free_page((unsigned long) link);
46827 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46828 index a9ba244..d9df391 100644
46829 --- a/fs/gfs2/inode.c
46830 +++ b/fs/gfs2/inode.c
46831 @@ -1496,7 +1496,7 @@ out:
46832
46833 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46834 {
46835 - char *s = nd_get_link(nd);
46836 + const char *s = nd_get_link(nd);
46837 if (!IS_ERR(s))
46838 kfree(s);
46839 }
46840 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46841 index cc9281b..58996fb 100644
46842 --- a/fs/hugetlbfs/inode.c
46843 +++ b/fs/hugetlbfs/inode.c
46844 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46845 .kill_sb = kill_litter_super,
46846 };
46847
46848 -static struct vfsmount *hugetlbfs_vfsmount;
46849 +struct vfsmount *hugetlbfs_vfsmount;
46850
46851 static int can_do_hugetlb_shm(void)
46852 {
46853 diff --git a/fs/inode.c b/fs/inode.c
46854 index c99163b..a11ad40 100644
46855 --- a/fs/inode.c
46856 +++ b/fs/inode.c
46857 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
46858
46859 #ifdef CONFIG_SMP
46860 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46861 - static atomic_t shared_last_ino;
46862 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46863 + static atomic_unchecked_t shared_last_ino;
46864 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46865
46866 res = next - LAST_INO_BATCH;
46867 }
46868 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46869 index 4a6cf28..d3a29d3 100644
46870 --- a/fs/jffs2/erase.c
46871 +++ b/fs/jffs2/erase.c
46872 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46873 struct jffs2_unknown_node marker = {
46874 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46875 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46876 - .totlen = cpu_to_je32(c->cleanmarker_size)
46877 + .totlen = cpu_to_je32(c->cleanmarker_size),
46878 + .hdr_crc = cpu_to_je32(0)
46879 };
46880
46881 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46882 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46883 index 6f4529d..bf12806 100644
46884 --- a/fs/jffs2/wbuf.c
46885 +++ b/fs/jffs2/wbuf.c
46886 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46887 {
46888 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46889 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46890 - .totlen = constant_cpu_to_je32(8)
46891 + .totlen = constant_cpu_to_je32(8),
46892 + .hdr_crc = constant_cpu_to_je32(0)
46893 };
46894
46895 /*
46896 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46897 index 4a82950..bcaa0cb 100644
46898 --- a/fs/jfs/super.c
46899 +++ b/fs/jfs/super.c
46900 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46901
46902 jfs_inode_cachep =
46903 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46904 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46905 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46906 init_once);
46907 if (jfs_inode_cachep == NULL)
46908 return -ENOMEM;
46909 diff --git a/fs/libfs.c b/fs/libfs.c
46910 index f86ec27..4734776 100644
46911 --- a/fs/libfs.c
46912 +++ b/fs/libfs.c
46913 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46914
46915 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46916 struct dentry *next;
46917 + char d_name[sizeof(next->d_iname)];
46918 + const unsigned char *name;
46919 +
46920 next = list_entry(p, struct dentry, d_u.d_child);
46921 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46922 if (!simple_positive(next)) {
46923 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46924
46925 spin_unlock(&next->d_lock);
46926 spin_unlock(&dentry->d_lock);
46927 - if (filldir(dirent, next->d_name.name,
46928 + name = next->d_name.name;
46929 + if (name == next->d_iname) {
46930 + memcpy(d_name, name, next->d_name.len);
46931 + name = d_name;
46932 + }
46933 + if (filldir(dirent, name,
46934 next->d_name.len, filp->f_pos,
46935 next->d_inode->i_ino,
46936 dt_type(next->d_inode)) < 0)
46937 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46938 index 8392cb8..80d6193 100644
46939 --- a/fs/lockd/clntproc.c
46940 +++ b/fs/lockd/clntproc.c
46941 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46942 /*
46943 * Cookie counter for NLM requests
46944 */
46945 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46946 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46947
46948 void nlmclnt_next_cookie(struct nlm_cookie *c)
46949 {
46950 - u32 cookie = atomic_inc_return(&nlm_cookie);
46951 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46952
46953 memcpy(c->data, &cookie, 4);
46954 c->len=4;
46955 diff --git a/fs/locks.c b/fs/locks.c
46956 index fce6238..34e929c 100644
46957 --- a/fs/locks.c
46958 +++ b/fs/locks.c
46959 @@ -308,7 +308,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
46960 return 0;
46961 }
46962
46963 -static int assign_type(struct file_lock *fl, int type)
46964 +static int assign_type(struct file_lock *fl, long type)
46965 {
46966 switch (type) {
46967 case F_RDLCK:
46968 @@ -445,7 +445,7 @@ static const struct lock_manager_operations lease_manager_ops = {
46969 /*
46970 * Initialize a lease, use the default lock manager operations
46971 */
46972 -static int lease_init(struct file *filp, int type, struct file_lock *fl)
46973 +static int lease_init(struct file *filp, long type, struct file_lock *fl)
46974 {
46975 if (assign_type(fl, type) != 0)
46976 return -EINVAL;
46977 @@ -463,7 +463,7 @@ static int lease_init(struct file *filp, int type, struct file_lock *fl)
46978 }
46979
46980 /* Allocate a file_lock initialised to this type of lease */
46981 -static struct file_lock *lease_alloc(struct file *filp, int type)
46982 +static struct file_lock *lease_alloc(struct file *filp, long type)
46983 {
46984 struct file_lock *fl = locks_alloc_lock();
46985 int error = -ENOMEM;
46986 @@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
46987 return;
46988
46989 if (filp->f_op && filp->f_op->flock) {
46990 - struct file_lock fl = {
46991 + struct file_lock flock = {
46992 .fl_pid = current->tgid,
46993 .fl_file = filp,
46994 .fl_flags = FL_FLOCK,
46995 .fl_type = F_UNLCK,
46996 .fl_end = OFFSET_MAX,
46997 };
46998 - filp->f_op->flock(filp, F_SETLKW, &fl);
46999 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47000 - fl.fl_ops->fl_release_private(&fl);
47001 + filp->f_op->flock(filp, F_SETLKW, &flock);
47002 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47003 + flock.fl_ops->fl_release_private(&flock);
47004 }
47005
47006 lock_flocks();
47007 diff --git a/fs/namei.c b/fs/namei.c
47008 index 7d69419..1487852 100644
47009 --- a/fs/namei.c
47010 +++ b/fs/namei.c
47011 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47012 if (ret != -EACCES)
47013 return ret;
47014
47015 +#ifdef CONFIG_GRKERNSEC
47016 + /* we'll block if we have to log due to a denied capability use */
47017 + if (mask & MAY_NOT_BLOCK)
47018 + return -ECHILD;
47019 +#endif
47020 +
47021 if (S_ISDIR(inode->i_mode)) {
47022 /* DACs are overridable for directories */
47023 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47024 - return 0;
47025 if (!(mask & MAY_WRITE))
47026 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47027 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47028 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47029 return 0;
47030 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47031 + return 0;
47032 return -EACCES;
47033 }
47034 /*
47035 + * Searching includes executable on directories, else just read.
47036 + */
47037 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47038 + if (mask == MAY_READ)
47039 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47040 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47041 + return 0;
47042 +
47043 + /*
47044 * Read/write DACs are always overridable.
47045 * Executable DACs are overridable when there is
47046 * at least one exec bit set.
47047 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47048 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47049 return 0;
47050
47051 - /*
47052 - * Searching includes executable on directories, else just read.
47053 - */
47054 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47055 - if (mask == MAY_READ)
47056 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47057 - return 0;
47058 -
47059 return -EACCES;
47060 }
47061
47062 @@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47063 return error;
47064 }
47065
47066 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47067 + dentry->d_inode, dentry, nd->path.mnt)) {
47068 + error = -EACCES;
47069 + *p = ERR_PTR(error); /* no ->put_link(), please */
47070 + path_put(&nd->path);
47071 + return error;
47072 + }
47073 +
47074 nd->last_type = LAST_BIND;
47075 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47076 error = PTR_ERR(*p);
47077 if (!IS_ERR(*p)) {
47078 - char *s = nd_get_link(nd);
47079 + const char *s = nd_get_link(nd);
47080 error = 0;
47081 if (s)
47082 error = __vfs_follow_link(nd, s);
47083 @@ -1386,6 +1402,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47084 if (!res)
47085 res = walk_component(nd, path, &nd->last,
47086 nd->last_type, LOOKUP_FOLLOW);
47087 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
47088 + res = -EACCES;
47089 + }
47090 put_link(nd, &link, cookie);
47091 } while (res > 0);
47092
47093 @@ -1779,6 +1798,9 @@ static int path_lookupat(int dfd, const char *name,
47094 err = follow_link(&link, nd, &cookie);
47095 if (!err)
47096 err = lookup_last(nd, &path);
47097 + if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
47098 + err = -EACCES;
47099 + }
47100 put_link(nd, &link, cookie);
47101 }
47102 }
47103 @@ -1786,6 +1808,21 @@ static int path_lookupat(int dfd, const char *name,
47104 if (!err)
47105 err = complete_walk(nd);
47106
47107 + if (!(nd->flags & LOOKUP_PARENT)) {
47108 +#ifdef CONFIG_GRKERNSEC
47109 + if (flags & LOOKUP_RCU) {
47110 + if (!err)
47111 + path_put(&nd->path);
47112 + err = -ECHILD;
47113 + } else
47114 +#endif
47115 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47116 + if (!err)
47117 + path_put(&nd->path);
47118 + err = -ENOENT;
47119 + }
47120 + }
47121 +
47122 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47123 if (!nd->inode->i_op->lookup) {
47124 path_put(&nd->path);
47125 @@ -1813,6 +1850,15 @@ static int do_path_lookup(int dfd, const char *name,
47126 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47127
47128 if (likely(!retval)) {
47129 + if (*name != '/' && nd->path.dentry && nd->inode) {
47130 +#ifdef CONFIG_GRKERNSEC
47131 + if (flags & LOOKUP_RCU)
47132 + return -ECHILD;
47133 +#endif
47134 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47135 + return -ENOENT;
47136 + }
47137 +
47138 if (unlikely(!audit_dummy_context())) {
47139 if (nd->path.dentry && nd->inode)
47140 audit_inode(name, nd->path.dentry);
47141 @@ -2155,6 +2201,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47142 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47143 return -EPERM;
47144
47145 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47146 + return -EPERM;
47147 + if (gr_handle_rawio(inode))
47148 + return -EPERM;
47149 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47150 + return -EACCES;
47151 +
47152 return 0;
47153 }
47154
47155 @@ -2220,6 +2273,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47156 error = complete_walk(nd);
47157 if (error)
47158 return ERR_PTR(error);
47159 +#ifdef CONFIG_GRKERNSEC
47160 + if (nd->flags & LOOKUP_RCU) {
47161 + error = -ECHILD;
47162 + goto exit;
47163 + }
47164 +#endif
47165 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47166 + error = -ENOENT;
47167 + goto exit;
47168 + }
47169 audit_inode(pathname, nd->path.dentry);
47170 if (open_flag & O_CREAT) {
47171 error = -EISDIR;
47172 @@ -2230,6 +2293,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47173 error = complete_walk(nd);
47174 if (error)
47175 return ERR_PTR(error);
47176 +#ifdef CONFIG_GRKERNSEC
47177 + if (nd->flags & LOOKUP_RCU) {
47178 + error = -ECHILD;
47179 + goto exit;
47180 + }
47181 +#endif
47182 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47183 + error = -ENOENT;
47184 + goto exit;
47185 + }
47186 audit_inode(pathname, dir);
47187 goto ok;
47188 }
47189 @@ -2285,6 +2358,12 @@ retry_lookup:
47190 /* Negative dentry, just create the file */
47191 if (!dentry->d_inode) {
47192 umode_t mode = op->mode;
47193 +
47194 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47195 + error = -EACCES;
47196 + goto exit_mutex_unlock;
47197 + }
47198 +
47199 if (!IS_POSIXACL(dir->d_inode))
47200 mode &= ~current_umask();
47201 /*
47202 @@ -2308,6 +2387,8 @@ retry_lookup:
47203 error = vfs_create(dir->d_inode, dentry, mode, nd);
47204 if (error)
47205 goto exit_mutex_unlock;
47206 + else
47207 + gr_handle_create(path->dentry, path->mnt);
47208 mutex_unlock(&dir->d_inode->i_mutex);
47209 dput(nd->path.dentry);
47210 nd->path.dentry = dentry;
47211 @@ -2317,6 +2398,19 @@ retry_lookup:
47212 /*
47213 * It already exists.
47214 */
47215 +
47216 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47217 + error = -ENOENT;
47218 + goto exit_mutex_unlock;
47219 + }
47220 +
47221 + /* only check if O_CREAT is specified, all other checks need to go
47222 + into may_open */
47223 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47224 + error = -EACCES;
47225 + goto exit_mutex_unlock;
47226 + }
47227 +
47228 mutex_unlock(&dir->d_inode->i_mutex);
47229 audit_inode(pathname, path->dentry);
47230
47231 @@ -2367,6 +2461,16 @@ finish_lookup:
47232 path_put(&save_parent);
47233 return ERR_PTR(error);
47234 }
47235 +#ifdef CONFIG_GRKERNSEC
47236 + if (nd->flags & LOOKUP_RCU) {
47237 + error = -ECHILD;
47238 + goto exit;
47239 + }
47240 +#endif
47241 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47242 + error = -ENOENT;
47243 + goto exit;
47244 + }
47245 error = -EISDIR;
47246 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47247 goto exit;
47248 @@ -2476,8 +2580,14 @@ static struct file *path_openat(int dfd, const char *pathname,
47249 error = follow_link(&link, nd, &cookie);
47250 if (unlikely(error))
47251 filp = ERR_PTR(error);
47252 - else
47253 + else {
47254 filp = do_last(nd, &path, op, pathname);
47255 + if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
47256 + if (filp)
47257 + fput(filp);
47258 + filp = ERR_PTR(-EACCES);
47259 + }
47260 + }
47261 put_link(nd, &link, cookie);
47262 }
47263 out:
47264 @@ -2577,6 +2687,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47265 *path = nd.path;
47266 return dentry;
47267 eexist:
47268 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47269 + dput(dentry);
47270 + dentry = ERR_PTR(-ENOENT);
47271 + goto fail;
47272 + }
47273 dput(dentry);
47274 dentry = ERR_PTR(-EEXIST);
47275 fail:
47276 @@ -2599,6 +2714,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47277 }
47278 EXPORT_SYMBOL(user_path_create);
47279
47280 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47281 +{
47282 + char *tmp = getname(pathname);
47283 + struct dentry *res;
47284 + if (IS_ERR(tmp))
47285 + return ERR_CAST(tmp);
47286 + res = kern_path_create(dfd, tmp, path, is_dir);
47287 + if (IS_ERR(res))
47288 + putname(tmp);
47289 + else
47290 + *to = tmp;
47291 + return res;
47292 +}
47293 +
47294 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47295 {
47296 int error = may_create(dir, dentry);
47297 @@ -2665,6 +2794,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47298 error = mnt_want_write(path.mnt);
47299 if (error)
47300 goto out_dput;
47301 +
47302 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47303 + error = -EPERM;
47304 + goto out_drop_write;
47305 + }
47306 +
47307 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47308 + error = -EACCES;
47309 + goto out_drop_write;
47310 + }
47311 +
47312 error = security_path_mknod(&path, dentry, mode, dev);
47313 if (error)
47314 goto out_drop_write;
47315 @@ -2682,6 +2822,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47316 }
47317 out_drop_write:
47318 mnt_drop_write(path.mnt);
47319 +
47320 + if (!error)
47321 + gr_handle_create(dentry, path.mnt);
47322 out_dput:
47323 dput(dentry);
47324 mutex_unlock(&path.dentry->d_inode->i_mutex);
47325 @@ -2735,12 +2878,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47326 error = mnt_want_write(path.mnt);
47327 if (error)
47328 goto out_dput;
47329 +
47330 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47331 + error = -EACCES;
47332 + goto out_drop_write;
47333 + }
47334 +
47335 error = security_path_mkdir(&path, dentry, mode);
47336 if (error)
47337 goto out_drop_write;
47338 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47339 out_drop_write:
47340 mnt_drop_write(path.mnt);
47341 +
47342 + if (!error)
47343 + gr_handle_create(dentry, path.mnt);
47344 out_dput:
47345 dput(dentry);
47346 mutex_unlock(&path.dentry->d_inode->i_mutex);
47347 @@ -2820,6 +2972,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47348 char * name;
47349 struct dentry *dentry;
47350 struct nameidata nd;
47351 + ino_t saved_ino = 0;
47352 + dev_t saved_dev = 0;
47353
47354 error = user_path_parent(dfd, pathname, &nd, &name);
47355 if (error)
47356 @@ -2848,6 +3002,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47357 error = -ENOENT;
47358 goto exit3;
47359 }
47360 +
47361 + saved_ino = dentry->d_inode->i_ino;
47362 + saved_dev = gr_get_dev_from_dentry(dentry);
47363 +
47364 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47365 + error = -EACCES;
47366 + goto exit3;
47367 + }
47368 +
47369 error = mnt_want_write(nd.path.mnt);
47370 if (error)
47371 goto exit3;
47372 @@ -2855,6 +3018,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47373 if (error)
47374 goto exit4;
47375 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47376 + if (!error && (saved_dev || saved_ino))
47377 + gr_handle_delete(saved_ino, saved_dev);
47378 exit4:
47379 mnt_drop_write(nd.path.mnt);
47380 exit3:
47381 @@ -2917,6 +3082,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47382 struct dentry *dentry;
47383 struct nameidata nd;
47384 struct inode *inode = NULL;
47385 + ino_t saved_ino = 0;
47386 + dev_t saved_dev = 0;
47387
47388 error = user_path_parent(dfd, pathname, &nd, &name);
47389 if (error)
47390 @@ -2939,6 +3106,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47391 if (!inode)
47392 goto slashes;
47393 ihold(inode);
47394 +
47395 + if (inode->i_nlink <= 1) {
47396 + saved_ino = inode->i_ino;
47397 + saved_dev = gr_get_dev_from_dentry(dentry);
47398 + }
47399 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47400 + error = -EACCES;
47401 + goto exit2;
47402 + }
47403 +
47404 error = mnt_want_write(nd.path.mnt);
47405 if (error)
47406 goto exit2;
47407 @@ -2946,6 +3123,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47408 if (error)
47409 goto exit3;
47410 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47411 + if (!error && (saved_ino || saved_dev))
47412 + gr_handle_delete(saved_ino, saved_dev);
47413 exit3:
47414 mnt_drop_write(nd.path.mnt);
47415 exit2:
47416 @@ -3021,10 +3200,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47417 error = mnt_want_write(path.mnt);
47418 if (error)
47419 goto out_dput;
47420 +
47421 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47422 + error = -EACCES;
47423 + goto out_drop_write;
47424 + }
47425 +
47426 error = security_path_symlink(&path, dentry, from);
47427 if (error)
47428 goto out_drop_write;
47429 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47430 + if (!error)
47431 + gr_handle_create(dentry, path.mnt);
47432 out_drop_write:
47433 mnt_drop_write(path.mnt);
47434 out_dput:
47435 @@ -3099,6 +3286,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47436 {
47437 struct dentry *new_dentry;
47438 struct path old_path, new_path;
47439 + char *to = NULL;
47440 int how = 0;
47441 int error;
47442
47443 @@ -3122,7 +3310,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47444 if (error)
47445 return error;
47446
47447 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47448 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47449 error = PTR_ERR(new_dentry);
47450 if (IS_ERR(new_dentry))
47451 goto out;
47452 @@ -3133,13 +3321,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47453 error = mnt_want_write(new_path.mnt);
47454 if (error)
47455 goto out_dput;
47456 +
47457 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47458 + old_path.dentry->d_inode,
47459 + old_path.dentry->d_inode->i_mode, to)) {
47460 + error = -EACCES;
47461 + goto out_drop_write;
47462 + }
47463 +
47464 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47465 + old_path.dentry, old_path.mnt, to)) {
47466 + error = -EACCES;
47467 + goto out_drop_write;
47468 + }
47469 +
47470 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47471 if (error)
47472 goto out_drop_write;
47473 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47474 + if (!error)
47475 + gr_handle_create(new_dentry, new_path.mnt);
47476 out_drop_write:
47477 mnt_drop_write(new_path.mnt);
47478 out_dput:
47479 + putname(to);
47480 dput(new_dentry);
47481 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47482 path_put(&new_path);
47483 @@ -3373,6 +3578,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47484 if (new_dentry == trap)
47485 goto exit5;
47486
47487 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47488 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47489 + to);
47490 + if (error)
47491 + goto exit5;
47492 +
47493 error = mnt_want_write(oldnd.path.mnt);
47494 if (error)
47495 goto exit5;
47496 @@ -3382,6 +3593,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47497 goto exit6;
47498 error = vfs_rename(old_dir->d_inode, old_dentry,
47499 new_dir->d_inode, new_dentry);
47500 + if (!error)
47501 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47502 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47503 exit6:
47504 mnt_drop_write(oldnd.path.mnt);
47505 exit5:
47506 @@ -3407,6 +3621,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47507
47508 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47509 {
47510 + char tmpbuf[64];
47511 + const char *newlink;
47512 int len;
47513
47514 len = PTR_ERR(link);
47515 @@ -3416,7 +3632,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47516 len = strlen(link);
47517 if (len > (unsigned) buflen)
47518 len = buflen;
47519 - if (copy_to_user(buffer, link, len))
47520 +
47521 + if (len < sizeof(tmpbuf)) {
47522 + memcpy(tmpbuf, link, len);
47523 + newlink = tmpbuf;
47524 + } else
47525 + newlink = link;
47526 +
47527 + if (copy_to_user(buffer, newlink, len))
47528 len = -EFAULT;
47529 out:
47530 return len;
47531 diff --git a/fs/namespace.c b/fs/namespace.c
47532 index 1e4a5fe..a5ce747 100644
47533 --- a/fs/namespace.c
47534 +++ b/fs/namespace.c
47535 @@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47536 if (!(sb->s_flags & MS_RDONLY))
47537 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47538 up_write(&sb->s_umount);
47539 +
47540 + gr_log_remount(mnt->mnt_devname, retval);
47541 +
47542 return retval;
47543 }
47544
47545 @@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47546 br_write_unlock(&vfsmount_lock);
47547 up_write(&namespace_sem);
47548 release_mounts(&umount_list);
47549 +
47550 + gr_log_unmount(mnt->mnt_devname, retval);
47551 +
47552 return retval;
47553 }
47554
47555 @@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47556 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47557 MS_STRICTATIME);
47558
47559 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47560 + retval = -EPERM;
47561 + goto dput_out;
47562 + }
47563 +
47564 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47565 + retval = -EPERM;
47566 + goto dput_out;
47567 + }
47568 +
47569 if (flags & MS_REMOUNT)
47570 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47571 data_page);
47572 @@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47573 dev_name, data_page);
47574 dput_out:
47575 path_put(&path);
47576 +
47577 + gr_log_mount(dev_name, dir_name, retval);
47578 +
47579 return retval;
47580 }
47581
47582 @@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47583 if (error)
47584 goto out2;
47585
47586 + if (gr_handle_chroot_pivot()) {
47587 + error = -EPERM;
47588 + goto out2;
47589 + }
47590 +
47591 get_fs_root(current->fs, &root);
47592 error = lock_mount(&old);
47593 if (error)
47594 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47595 index f729698..2bac081 100644
47596 --- a/fs/nfs/inode.c
47597 +++ b/fs/nfs/inode.c
47598 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47599 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47600 nfsi->attrtimeo_timestamp = jiffies;
47601
47602 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47603 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47604 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47605 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47606 else
47607 @@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47608 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47609 }
47610
47611 -static atomic_long_t nfs_attr_generation_counter;
47612 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47613
47614 static unsigned long nfs_read_attr_generation_counter(void)
47615 {
47616 - return atomic_long_read(&nfs_attr_generation_counter);
47617 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47618 }
47619
47620 unsigned long nfs_inc_attr_generation_counter(void)
47621 {
47622 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47623 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47624 }
47625
47626 void nfs_fattr_init(struct nfs_fattr *fattr)
47627 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47628 index c8bd9c3..4f83416 100644
47629 --- a/fs/nfsd/vfs.c
47630 +++ b/fs/nfsd/vfs.c
47631 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47632 } else {
47633 oldfs = get_fs();
47634 set_fs(KERNEL_DS);
47635 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47636 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47637 set_fs(oldfs);
47638 }
47639
47640 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47641
47642 /* Write the data. */
47643 oldfs = get_fs(); set_fs(KERNEL_DS);
47644 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47645 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47646 set_fs(oldfs);
47647 if (host_err < 0)
47648 goto out_nfserr;
47649 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47650 */
47651
47652 oldfs = get_fs(); set_fs(KERNEL_DS);
47653 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47654 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47655 set_fs(oldfs);
47656
47657 if (host_err < 0)
47658 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47659 index 3568c8a..e0240d8 100644
47660 --- a/fs/notify/fanotify/fanotify_user.c
47661 +++ b/fs/notify/fanotify/fanotify_user.c
47662 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47663 goto out_close_fd;
47664
47665 ret = -EFAULT;
47666 - if (copy_to_user(buf, &fanotify_event_metadata,
47667 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47668 + copy_to_user(buf, &fanotify_event_metadata,
47669 fanotify_event_metadata.event_len))
47670 goto out_kill_access_response;
47671
47672 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47673 index c887b13..0fdf472 100644
47674 --- a/fs/notify/notification.c
47675 +++ b/fs/notify/notification.c
47676 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47677 * get set to 0 so it will never get 'freed'
47678 */
47679 static struct fsnotify_event *q_overflow_event;
47680 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47681 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47682
47683 /**
47684 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47685 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47686 */
47687 u32 fsnotify_get_cookie(void)
47688 {
47689 - return atomic_inc_return(&fsnotify_sync_cookie);
47690 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47691 }
47692 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47693
47694 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47695 index 99e3610..02c1068 100644
47696 --- a/fs/ntfs/dir.c
47697 +++ b/fs/ntfs/dir.c
47698 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47699 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47700 ~(s64)(ndir->itype.index.block_size - 1)));
47701 /* Bounds checks. */
47702 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47703 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47704 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47705 "inode 0x%lx or driver bug.", vdir->i_ino);
47706 goto err_out;
47707 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47708 index 7389d2d..dfd5dbe 100644
47709 --- a/fs/ntfs/file.c
47710 +++ b/fs/ntfs/file.c
47711 @@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47712 #endif /* NTFS_RW */
47713 };
47714
47715 -const struct file_operations ntfs_empty_file_ops = {};
47716 +const struct file_operations ntfs_empty_file_ops __read_only;
47717
47718 -const struct inode_operations ntfs_empty_inode_ops = {};
47719 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47720 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47721 index 210c352..a174f83 100644
47722 --- a/fs/ocfs2/localalloc.c
47723 +++ b/fs/ocfs2/localalloc.c
47724 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47725 goto bail;
47726 }
47727
47728 - atomic_inc(&osb->alloc_stats.moves);
47729 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47730
47731 bail:
47732 if (handle)
47733 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47734 index d355e6e..578d905 100644
47735 --- a/fs/ocfs2/ocfs2.h
47736 +++ b/fs/ocfs2/ocfs2.h
47737 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47738
47739 struct ocfs2_alloc_stats
47740 {
47741 - atomic_t moves;
47742 - atomic_t local_data;
47743 - atomic_t bitmap_data;
47744 - atomic_t bg_allocs;
47745 - atomic_t bg_extends;
47746 + atomic_unchecked_t moves;
47747 + atomic_unchecked_t local_data;
47748 + atomic_unchecked_t bitmap_data;
47749 + atomic_unchecked_t bg_allocs;
47750 + atomic_unchecked_t bg_extends;
47751 };
47752
47753 enum ocfs2_local_alloc_state
47754 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47755 index f169da4..9112253 100644
47756 --- a/fs/ocfs2/suballoc.c
47757 +++ b/fs/ocfs2/suballoc.c
47758 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47759 mlog_errno(status);
47760 goto bail;
47761 }
47762 - atomic_inc(&osb->alloc_stats.bg_extends);
47763 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47764
47765 /* You should never ask for this much metadata */
47766 BUG_ON(bits_wanted >
47767 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47768 mlog_errno(status);
47769 goto bail;
47770 }
47771 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47772 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47773
47774 *suballoc_loc = res.sr_bg_blkno;
47775 *suballoc_bit_start = res.sr_bit_offset;
47776 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47777 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47778 res->sr_bits);
47779
47780 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47781 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47782
47783 BUG_ON(res->sr_bits != 1);
47784
47785 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47786 mlog_errno(status);
47787 goto bail;
47788 }
47789 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47790 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47791
47792 BUG_ON(res.sr_bits != 1);
47793
47794 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47795 cluster_start,
47796 num_clusters);
47797 if (!status)
47798 - atomic_inc(&osb->alloc_stats.local_data);
47799 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47800 } else {
47801 if (min_clusters > (osb->bitmap_cpg - 1)) {
47802 /* The only paths asking for contiguousness
47803 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47804 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47805 res.sr_bg_blkno,
47806 res.sr_bit_offset);
47807 - atomic_inc(&osb->alloc_stats.bitmap_data);
47808 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47809 *num_clusters = res.sr_bits;
47810 }
47811 }
47812 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47813 index 68f4541..89cfe6a 100644
47814 --- a/fs/ocfs2/super.c
47815 +++ b/fs/ocfs2/super.c
47816 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47817 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47818 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47819 "Stats",
47820 - atomic_read(&osb->alloc_stats.bitmap_data),
47821 - atomic_read(&osb->alloc_stats.local_data),
47822 - atomic_read(&osb->alloc_stats.bg_allocs),
47823 - atomic_read(&osb->alloc_stats.moves),
47824 - atomic_read(&osb->alloc_stats.bg_extends));
47825 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47826 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47827 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47828 + atomic_read_unchecked(&osb->alloc_stats.moves),
47829 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47830
47831 out += snprintf(buf + out, len - out,
47832 "%10s => State: %u Descriptor: %llu Size: %u bits "
47833 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47834 spin_lock_init(&osb->osb_xattr_lock);
47835 ocfs2_init_steal_slots(osb);
47836
47837 - atomic_set(&osb->alloc_stats.moves, 0);
47838 - atomic_set(&osb->alloc_stats.local_data, 0);
47839 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47840 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47841 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47842 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47843 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47844 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47845 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47846 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47847
47848 /* Copy the blockcheck stats from the superblock probe */
47849 osb->osb_ecc_stats = *stats;
47850 diff --git a/fs/open.c b/fs/open.c
47851 index 1540632..79d7242 100644
47852 --- a/fs/open.c
47853 +++ b/fs/open.c
47854 @@ -31,6 +31,8 @@
47855 #include <linux/ima.h>
47856 #include <linux/dnotify.h>
47857
47858 +#define CREATE_TRACE_POINTS
47859 +#include <trace/events/fs.h>
47860 #include "internal.h"
47861
47862 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47863 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47864 error = locks_verify_truncate(inode, NULL, length);
47865 if (!error)
47866 error = security_path_truncate(&path);
47867 +
47868 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47869 + error = -EACCES;
47870 +
47871 if (!error)
47872 error = do_truncate(path.dentry, length, 0, NULL);
47873
47874 @@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47875 if (__mnt_is_readonly(path.mnt))
47876 res = -EROFS;
47877
47878 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47879 + res = -EACCES;
47880 +
47881 out_path_release:
47882 path_put(&path);
47883 out:
47884 @@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47885 if (error)
47886 goto dput_and_out;
47887
47888 + gr_log_chdir(path.dentry, path.mnt);
47889 +
47890 set_fs_pwd(current->fs, &path);
47891
47892 dput_and_out:
47893 @@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47894 goto out_putf;
47895
47896 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47897 +
47898 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47899 + error = -EPERM;
47900 +
47901 + if (!error)
47902 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47903 +
47904 if (!error)
47905 set_fs_pwd(current->fs, &file->f_path);
47906 out_putf:
47907 @@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47908 if (error)
47909 goto dput_and_out;
47910
47911 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47912 + goto dput_and_out;
47913 +
47914 set_fs_root(current->fs, &path);
47915 +
47916 + gr_handle_chroot_chdir(&path);
47917 +
47918 error = 0;
47919 dput_and_out:
47920 path_put(&path);
47921 @@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
47922 if (error)
47923 return error;
47924 mutex_lock(&inode->i_mutex);
47925 +
47926 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47927 + error = -EACCES;
47928 + goto out_unlock;
47929 + }
47930 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47931 + error = -EACCES;
47932 + goto out_unlock;
47933 + }
47934 +
47935 error = security_path_chmod(path, mode);
47936 if (error)
47937 goto out_unlock;
47938 @@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47939 uid = make_kuid(current_user_ns(), user);
47940 gid = make_kgid(current_user_ns(), group);
47941
47942 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47943 + return -EACCES;
47944 +
47945 newattrs.ia_valid = ATTR_CTIME;
47946 if (user != (uid_t) -1) {
47947 if (!uid_valid(uid))
47948 @@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47949 } else {
47950 fsnotify_open(f);
47951 fd_install(fd, f);
47952 + trace_do_sys_open(tmp, flags, mode);
47953 }
47954 }
47955 putname(tmp);
47956 diff --git a/fs/pipe.c b/fs/pipe.c
47957 index 49c1065..13b9e12 100644
47958 --- a/fs/pipe.c
47959 +++ b/fs/pipe.c
47960 @@ -438,9 +438,9 @@ redo:
47961 }
47962 if (bufs) /* More to do? */
47963 continue;
47964 - if (!pipe->writers)
47965 + if (!atomic_read(&pipe->writers))
47966 break;
47967 - if (!pipe->waiting_writers) {
47968 + if (!atomic_read(&pipe->waiting_writers)) {
47969 /* syscall merging: Usually we must not sleep
47970 * if O_NONBLOCK is set, or if we got some data.
47971 * But if a writer sleeps in kernel space, then
47972 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47973 mutex_lock(&inode->i_mutex);
47974 pipe = inode->i_pipe;
47975
47976 - if (!pipe->readers) {
47977 + if (!atomic_read(&pipe->readers)) {
47978 send_sig(SIGPIPE, current, 0);
47979 ret = -EPIPE;
47980 goto out;
47981 @@ -553,7 +553,7 @@ redo1:
47982 for (;;) {
47983 int bufs;
47984
47985 - if (!pipe->readers) {
47986 + if (!atomic_read(&pipe->readers)) {
47987 send_sig(SIGPIPE, current, 0);
47988 if (!ret)
47989 ret = -EPIPE;
47990 @@ -644,9 +644,9 @@ redo2:
47991 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47992 do_wakeup = 0;
47993 }
47994 - pipe->waiting_writers++;
47995 + atomic_inc(&pipe->waiting_writers);
47996 pipe_wait(pipe);
47997 - pipe->waiting_writers--;
47998 + atomic_dec(&pipe->waiting_writers);
47999 }
48000 out:
48001 mutex_unlock(&inode->i_mutex);
48002 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48003 mask = 0;
48004 if (filp->f_mode & FMODE_READ) {
48005 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48006 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48007 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48008 mask |= POLLHUP;
48009 }
48010
48011 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48012 * Most Unices do not set POLLERR for FIFOs but on Linux they
48013 * behave exactly like pipes for poll().
48014 */
48015 - if (!pipe->readers)
48016 + if (!atomic_read(&pipe->readers))
48017 mask |= POLLERR;
48018 }
48019
48020 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48021
48022 mutex_lock(&inode->i_mutex);
48023 pipe = inode->i_pipe;
48024 - pipe->readers -= decr;
48025 - pipe->writers -= decw;
48026 + atomic_sub(decr, &pipe->readers);
48027 + atomic_sub(decw, &pipe->writers);
48028
48029 - if (!pipe->readers && !pipe->writers) {
48030 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48031 free_pipe_info(inode);
48032 } else {
48033 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48034 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48035
48036 if (inode->i_pipe) {
48037 ret = 0;
48038 - inode->i_pipe->readers++;
48039 + atomic_inc(&inode->i_pipe->readers);
48040 }
48041
48042 mutex_unlock(&inode->i_mutex);
48043 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48044
48045 if (inode->i_pipe) {
48046 ret = 0;
48047 - inode->i_pipe->writers++;
48048 + atomic_inc(&inode->i_pipe->writers);
48049 }
48050
48051 mutex_unlock(&inode->i_mutex);
48052 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48053 if (inode->i_pipe) {
48054 ret = 0;
48055 if (filp->f_mode & FMODE_READ)
48056 - inode->i_pipe->readers++;
48057 + atomic_inc(&inode->i_pipe->readers);
48058 if (filp->f_mode & FMODE_WRITE)
48059 - inode->i_pipe->writers++;
48060 + atomic_inc(&inode->i_pipe->writers);
48061 }
48062
48063 mutex_unlock(&inode->i_mutex);
48064 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48065 inode->i_pipe = NULL;
48066 }
48067
48068 -static struct vfsmount *pipe_mnt __read_mostly;
48069 +struct vfsmount *pipe_mnt __read_mostly;
48070
48071 /*
48072 * pipefs_dname() is called from d_path().
48073 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48074 goto fail_iput;
48075 inode->i_pipe = pipe;
48076
48077 - pipe->readers = pipe->writers = 1;
48078 + atomic_set(&pipe->readers, 1);
48079 + atomic_set(&pipe->writers, 1);
48080 inode->i_fop = &rdwr_pipefifo_fops;
48081
48082 /*
48083 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48084 index 15af622..0e9f4467 100644
48085 --- a/fs/proc/Kconfig
48086 +++ b/fs/proc/Kconfig
48087 @@ -30,12 +30,12 @@ config PROC_FS
48088
48089 config PROC_KCORE
48090 bool "/proc/kcore support" if !ARM
48091 - depends on PROC_FS && MMU
48092 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48093
48094 config PROC_VMCORE
48095 bool "/proc/vmcore support"
48096 - depends on PROC_FS && CRASH_DUMP
48097 - default y
48098 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48099 + default n
48100 help
48101 Exports the dump image of crashed kernel in ELF format.
48102
48103 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48104 limited in memory.
48105
48106 config PROC_PAGE_MONITOR
48107 - default y
48108 - depends on PROC_FS && MMU
48109 + default n
48110 + depends on PROC_FS && MMU && !GRKERNSEC
48111 bool "Enable /proc page monitoring" if EXPERT
48112 help
48113 Various /proc files exist to monitor process memory utilization:
48114 diff --git a/fs/proc/array.c b/fs/proc/array.c
48115 index c1c207c..5179411 100644
48116 --- a/fs/proc/array.c
48117 +++ b/fs/proc/array.c
48118 @@ -60,6 +60,7 @@
48119 #include <linux/tty.h>
48120 #include <linux/string.h>
48121 #include <linux/mman.h>
48122 +#include <linux/grsecurity.h>
48123 #include <linux/proc_fs.h>
48124 #include <linux/ioport.h>
48125 #include <linux/uaccess.h>
48126 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48127 seq_putc(m, '\n');
48128 }
48129
48130 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48131 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48132 +{
48133 + if (p->mm)
48134 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48135 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48136 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48137 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48138 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48139 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48140 + else
48141 + seq_printf(m, "PaX:\t-----\n");
48142 +}
48143 +#endif
48144 +
48145 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48146 struct pid *pid, struct task_struct *task)
48147 {
48148 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48149 task_cpus_allowed(m, task);
48150 cpuset_task_status_allowed(m, task);
48151 task_context_switch_counts(m, task);
48152 +
48153 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48154 + task_pax(m, task);
48155 +#endif
48156 +
48157 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48158 + task_grsec_rbac(m, task);
48159 +#endif
48160 +
48161 return 0;
48162 }
48163
48164 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48165 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48166 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48167 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48168 +#endif
48169 +
48170 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48171 struct pid *pid, struct task_struct *task, int whole)
48172 {
48173 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48174 char tcomm[sizeof(task->comm)];
48175 unsigned long flags;
48176
48177 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48178 + if (current->exec_id != m->exec_id) {
48179 + gr_log_badprocpid("stat");
48180 + return 0;
48181 + }
48182 +#endif
48183 +
48184 state = *get_task_state(task);
48185 vsize = eip = esp = 0;
48186 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48187 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48188 gtime = task->gtime;
48189 }
48190
48191 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48192 + if (PAX_RAND_FLAGS(mm)) {
48193 + eip = 0;
48194 + esp = 0;
48195 + wchan = 0;
48196 + }
48197 +#endif
48198 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48199 + wchan = 0;
48200 + eip =0;
48201 + esp =0;
48202 +#endif
48203 +
48204 /* scale priority and nice values from timeslices to -20..20 */
48205 /* to make it look like a "normal" Unix priority/nice value */
48206 priority = task_prio(task);
48207 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48208 seq_put_decimal_ull(m, ' ', vsize);
48209 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48210 seq_put_decimal_ull(m, ' ', rsslim);
48211 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48212 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48213 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48214 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48215 +#else
48216 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48217 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48218 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48219 +#endif
48220 seq_put_decimal_ull(m, ' ', esp);
48221 seq_put_decimal_ull(m, ' ', eip);
48222 /* The signal information here is obsolete.
48223 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48224 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48225 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48226
48227 - if (mm && permitted) {
48228 + if (mm && permitted
48229 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48230 + && !PAX_RAND_FLAGS(mm)
48231 +#endif
48232 + ) {
48233 seq_put_decimal_ull(m, ' ', mm->start_data);
48234 seq_put_decimal_ull(m, ' ', mm->end_data);
48235 seq_put_decimal_ull(m, ' ', mm->start_brk);
48236 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48237 struct pid *pid, struct task_struct *task)
48238 {
48239 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48240 - struct mm_struct *mm = get_task_mm(task);
48241 + struct mm_struct *mm;
48242
48243 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48244 + if (current->exec_id != m->exec_id) {
48245 + gr_log_badprocpid("statm");
48246 + return 0;
48247 + }
48248 +#endif
48249 + mm = get_task_mm(task);
48250 if (mm) {
48251 size = task_statm(mm, &shared, &text, &data, &resident);
48252 mmput(mm);
48253 @@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48254 return 0;
48255 }
48256
48257 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48258 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48259 +{
48260 + u32 curr_ip = 0;
48261 + unsigned long flags;
48262 +
48263 + if (lock_task_sighand(task, &flags)) {
48264 + curr_ip = task->signal->curr_ip;
48265 + unlock_task_sighand(task, &flags);
48266 + }
48267 +
48268 + return sprintf(buffer, "%pI4\n", &curr_ip);
48269 +}
48270 +#endif
48271 +
48272 #ifdef CONFIG_CHECKPOINT_RESTORE
48273 static struct pid *
48274 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48275 diff --git a/fs/proc/base.c b/fs/proc/base.c
48276 index 437195f..cd2210d 100644
48277 --- a/fs/proc/base.c
48278 +++ b/fs/proc/base.c
48279 @@ -110,6 +110,14 @@ struct pid_entry {
48280 union proc_op op;
48281 };
48282
48283 +struct getdents_callback {
48284 + struct linux_dirent __user * current_dir;
48285 + struct linux_dirent __user * previous;
48286 + struct file * file;
48287 + int count;
48288 + int error;
48289 +};
48290 +
48291 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48292 .name = (NAME), \
48293 .len = sizeof(NAME) - 1, \
48294 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48295 if (!mm->arg_end)
48296 goto out_mm; /* Shh! No looking before we're done */
48297
48298 + if (gr_acl_handle_procpidmem(task))
48299 + goto out_mm;
48300 +
48301 len = mm->arg_end - mm->arg_start;
48302
48303 if (len > PAGE_SIZE)
48304 @@ -236,12 +247,28 @@ out:
48305 return res;
48306 }
48307
48308 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48309 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48310 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48311 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48312 +#endif
48313 +
48314 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48315 {
48316 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48317 int res = PTR_ERR(mm);
48318 if (mm && !IS_ERR(mm)) {
48319 unsigned int nwords = 0;
48320 +
48321 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48322 + /* allow if we're currently ptracing this task */
48323 + if (PAX_RAND_FLAGS(mm) &&
48324 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48325 + mmput(mm);
48326 + return 0;
48327 + }
48328 +#endif
48329 +
48330 do {
48331 nwords += 2;
48332 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48333 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48334 }
48335
48336
48337 -#ifdef CONFIG_KALLSYMS
48338 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48339 /*
48340 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48341 * Returns the resolved symbol. If that fails, simply return the address.
48342 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48343 mutex_unlock(&task->signal->cred_guard_mutex);
48344 }
48345
48346 -#ifdef CONFIG_STACKTRACE
48347 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48348
48349 #define MAX_STACK_TRACE_DEPTH 64
48350
48351 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48352 return count;
48353 }
48354
48355 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48356 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48357 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48358 {
48359 long nr;
48360 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48361 /************************************************************************/
48362
48363 /* permission checks */
48364 -static int proc_fd_access_allowed(struct inode *inode)
48365 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48366 {
48367 struct task_struct *task;
48368 int allowed = 0;
48369 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48370 */
48371 task = get_proc_task(inode);
48372 if (task) {
48373 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48374 + if (log)
48375 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48376 + else
48377 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48378 put_task_struct(task);
48379 }
48380 return allowed;
48381 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48382 struct task_struct *task,
48383 int hide_pid_min)
48384 {
48385 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48386 + return false;
48387 +
48388 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48389 + rcu_read_lock();
48390 + {
48391 + const struct cred *tmpcred = current_cred();
48392 + const struct cred *cred = __task_cred(task);
48393 +
48394 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48395 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48396 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48397 +#endif
48398 + ) {
48399 + rcu_read_unlock();
48400 + return true;
48401 + }
48402 + }
48403 + rcu_read_unlock();
48404 +
48405 + if (!pid->hide_pid)
48406 + return false;
48407 +#endif
48408 +
48409 if (pid->hide_pid < hide_pid_min)
48410 return true;
48411 if (in_group_p(pid->pid_gid))
48412 return true;
48413 +
48414 return ptrace_may_access(task, PTRACE_MODE_READ);
48415 }
48416
48417 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48418 put_task_struct(task);
48419
48420 if (!has_perms) {
48421 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48422 + {
48423 +#else
48424 if (pid->hide_pid == 2) {
48425 +#endif
48426 /*
48427 * Let's make getdents(), stat(), and open()
48428 * consistent with each other. If a process
48429 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48430 if (!task)
48431 return -ESRCH;
48432
48433 + if (gr_acl_handle_procpidmem(task)) {
48434 + put_task_struct(task);
48435 + return -EPERM;
48436 + }
48437 +
48438 mm = mm_access(task, mode);
48439 put_task_struct(task);
48440
48441 @@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48442 mmput(mm);
48443 }
48444
48445 - /* OK to pass negative loff_t, we can catch out-of-range */
48446 - file->f_mode |= FMODE_UNSIGNED_OFFSET;
48447 file->private_data = mm;
48448
48449 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48450 + file->f_version = current->exec_id;
48451 +#endif
48452 +
48453 return 0;
48454 }
48455
48456 static int mem_open(struct inode *inode, struct file *file)
48457 {
48458 - return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48459 + int ret;
48460 + ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48461 +
48462 + /* OK to pass negative loff_t, we can catch out-of-range */
48463 + file->f_mode |= FMODE_UNSIGNED_OFFSET;
48464 +
48465 + return ret;
48466 }
48467
48468 static ssize_t mem_rw(struct file *file, char __user *buf,
48469 @@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48470 ssize_t copied;
48471 char *page;
48472
48473 +#ifdef CONFIG_GRKERNSEC
48474 + if (write)
48475 + return -EPERM;
48476 +#endif
48477 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48478 + if (file->f_version != current->exec_id) {
48479 + gr_log_badprocpid("mem");
48480 + return 0;
48481 + }
48482 +#endif
48483 +
48484 if (!mm)
48485 return 0;
48486
48487 @@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48488 if (!mm)
48489 return 0;
48490
48491 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48492 + if (file->f_version != current->exec_id) {
48493 + gr_log_badprocpid("environ");
48494 + return 0;
48495 + }
48496 +#endif
48497 +
48498 page = (char *)__get_free_page(GFP_TEMPORARY);
48499 if (!page)
48500 return -ENOMEM;
48501 @@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48502 if (!atomic_inc_not_zero(&mm->mm_users))
48503 goto free;
48504 while (count > 0) {
48505 - int this_len, retval, max_len;
48506 + size_t this_len, max_len;
48507 + int retval;
48508 +
48509 + if (src >= (mm->env_end - mm->env_start))
48510 + break;
48511
48512 this_len = mm->env_end - (mm->env_start + src);
48513
48514 - if (this_len <= 0)
48515 - break;
48516
48517 - max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48518 - this_len = (this_len > max_len) ? max_len : this_len;
48519 + max_len = min_t(size_t, PAGE_SIZE, count);
48520 + this_len = min(max_len, this_len);
48521
48522 retval = access_remote_vm(mm, (mm->env_start + src),
48523 page, this_len, 0);
48524 @@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48525 path_put(&nd->path);
48526
48527 /* Are we allowed to snoop on the tasks file descriptors? */
48528 - if (!proc_fd_access_allowed(inode))
48529 + if (!proc_fd_access_allowed(inode, 0))
48530 goto out;
48531
48532 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48533 @@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48534 struct path path;
48535
48536 /* Are we allowed to snoop on the tasks file descriptors? */
48537 - if (!proc_fd_access_allowed(inode))
48538 - goto out;
48539 + /* logging this is needed for learning on chromium to work properly,
48540 + but we don't want to flood the logs from 'ps' which does a readlink
48541 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48542 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48543 + */
48544 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48545 + if (!proc_fd_access_allowed(inode,0))
48546 + goto out;
48547 + } else {
48548 + if (!proc_fd_access_allowed(inode,1))
48549 + goto out;
48550 + }
48551
48552 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48553 if (error)
48554 @@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48555 rcu_read_lock();
48556 cred = __task_cred(task);
48557 inode->i_uid = cred->euid;
48558 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48559 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48560 +#else
48561 inode->i_gid = cred->egid;
48562 +#endif
48563 rcu_read_unlock();
48564 }
48565 security_task_to_inode(task, inode);
48566 @@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48567 return -ENOENT;
48568 }
48569 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48570 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48571 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48572 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48573 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48574 +#endif
48575 task_dumpable(task)) {
48576 cred = __task_cred(task);
48577 stat->uid = cred->euid;
48578 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48579 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48580 +#else
48581 stat->gid = cred->egid;
48582 +#endif
48583 }
48584 }
48585 rcu_read_unlock();
48586 @@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48587
48588 if (task) {
48589 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48590 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48591 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48592 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48593 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48594 +#endif
48595 task_dumpable(task)) {
48596 rcu_read_lock();
48597 cred = __task_cred(task);
48598 inode->i_uid = cred->euid;
48599 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48600 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48601 +#else
48602 inode->i_gid = cred->egid;
48603 +#endif
48604 rcu_read_unlock();
48605 } else {
48606 inode->i_uid = GLOBAL_ROOT_UID;
48607 @@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48608 int fd = proc_fd(inode);
48609
48610 if (task) {
48611 - files = get_files_struct(task);
48612 + if (!gr_acl_handle_procpidmem(task))
48613 + files = get_files_struct(task);
48614 put_task_struct(task);
48615 }
48616 if (files) {
48617 @@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48618 */
48619 static int proc_fd_permission(struct inode *inode, int mask)
48620 {
48621 + struct task_struct *task;
48622 int rv = generic_permission(inode, mask);
48623 - if (rv == 0)
48624 - return 0;
48625 +
48626 if (task_pid(current) == proc_pid(inode))
48627 rv = 0;
48628 +
48629 + task = get_proc_task(inode);
48630 + if (task == NULL)
48631 + return rv;
48632 +
48633 + if (gr_acl_handle_procpidmem(task))
48634 + rv = -EACCES;
48635 +
48636 + put_task_struct(task);
48637 +
48638 return rv;
48639 }
48640
48641 @@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48642 if (!task)
48643 goto out_no_task;
48644
48645 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48646 + goto out;
48647 +
48648 /*
48649 * Yes, it does not scale. And it should not. Don't add
48650 * new entries into /proc/<tgid>/ without very good reasons.
48651 @@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48652 if (!task)
48653 goto out_no_task;
48654
48655 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48656 + goto out;
48657 +
48658 ret = 0;
48659 i = filp->f_pos;
48660 switch (i) {
48661 @@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48662 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48663 void *cookie)
48664 {
48665 - char *s = nd_get_link(nd);
48666 + const char *s = nd_get_link(nd);
48667 if (!IS_ERR(s))
48668 __putname(s);
48669 }
48670 @@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48671 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48672 #endif
48673 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48674 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48675 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48676 INF("syscall", S_IRUGO, proc_pid_syscall),
48677 #endif
48678 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48679 @@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48680 #ifdef CONFIG_SECURITY
48681 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48682 #endif
48683 -#ifdef CONFIG_KALLSYMS
48684 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48685 INF("wchan", S_IRUGO, proc_pid_wchan),
48686 #endif
48687 -#ifdef CONFIG_STACKTRACE
48688 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48689 ONE("stack", S_IRUGO, proc_pid_stack),
48690 #endif
48691 #ifdef CONFIG_SCHEDSTATS
48692 @@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48693 #ifdef CONFIG_HARDWALL
48694 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48695 #endif
48696 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48697 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48698 +#endif
48699 #ifdef CONFIG_USER_NS
48700 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48701 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48702 @@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48703 if (!inode)
48704 goto out;
48705
48706 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48707 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48708 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48709 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48710 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48711 +#else
48712 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48713 +#endif
48714 inode->i_op = &proc_tgid_base_inode_operations;
48715 inode->i_fop = &proc_tgid_base_operations;
48716 inode->i_flags|=S_IMMUTABLE;
48717 @@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48718 if (!task)
48719 goto out;
48720
48721 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48722 + goto out_put_task;
48723 +
48724 result = proc_pid_instantiate(dir, dentry, task, NULL);
48725 +out_put_task:
48726 put_task_struct(task);
48727 out:
48728 return result;
48729 @@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48730 static int fake_filldir(void *buf, const char *name, int namelen,
48731 loff_t offset, u64 ino, unsigned d_type)
48732 {
48733 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48734 + __buf->error = -EINVAL;
48735 return 0;
48736 }
48737
48738 @@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48739 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48740 #endif
48741 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48742 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48743 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48744 INF("syscall", S_IRUGO, proc_pid_syscall),
48745 #endif
48746 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48747 @@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48748 #ifdef CONFIG_SECURITY
48749 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48750 #endif
48751 -#ifdef CONFIG_KALLSYMS
48752 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48753 INF("wchan", S_IRUGO, proc_pid_wchan),
48754 #endif
48755 -#ifdef CONFIG_STACKTRACE
48756 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48757 ONE("stack", S_IRUGO, proc_pid_stack),
48758 #endif
48759 #ifdef CONFIG_SCHEDSTATS
48760 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48761 index 82676e3..5f8518a 100644
48762 --- a/fs/proc/cmdline.c
48763 +++ b/fs/proc/cmdline.c
48764 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48765
48766 static int __init proc_cmdline_init(void)
48767 {
48768 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48769 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48770 +#else
48771 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48772 +#endif
48773 return 0;
48774 }
48775 module_init(proc_cmdline_init);
48776 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48777 index b143471..bb105e5 100644
48778 --- a/fs/proc/devices.c
48779 +++ b/fs/proc/devices.c
48780 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48781
48782 static int __init proc_devices_init(void)
48783 {
48784 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48785 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48786 +#else
48787 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48788 +#endif
48789 return 0;
48790 }
48791 module_init(proc_devices_init);
48792 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48793 index 7ac817b..abab1a5 100644
48794 --- a/fs/proc/inode.c
48795 +++ b/fs/proc/inode.c
48796 @@ -21,11 +21,17 @@
48797 #include <linux/seq_file.h>
48798 #include <linux/slab.h>
48799 #include <linux/mount.h>
48800 +#include <linux/grsecurity.h>
48801
48802 #include <asm/uaccess.h>
48803
48804 #include "internal.h"
48805
48806 +#ifdef CONFIG_PROC_SYSCTL
48807 +extern const struct inode_operations proc_sys_inode_operations;
48808 +extern const struct inode_operations proc_sys_dir_operations;
48809 +#endif
48810 +
48811 static void proc_evict_inode(struct inode *inode)
48812 {
48813 struct proc_dir_entry *de;
48814 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48815 ns_ops = PROC_I(inode)->ns_ops;
48816 if (ns_ops && ns_ops->put)
48817 ns_ops->put(PROC_I(inode)->ns);
48818 +
48819 +#ifdef CONFIG_PROC_SYSCTL
48820 + if (inode->i_op == &proc_sys_inode_operations ||
48821 + inode->i_op == &proc_sys_dir_operations)
48822 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48823 +#endif
48824 +
48825 }
48826
48827 static struct kmem_cache * proc_inode_cachep;
48828 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48829 if (de->mode) {
48830 inode->i_mode = de->mode;
48831 inode->i_uid = de->uid;
48832 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48833 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48834 +#else
48835 inode->i_gid = de->gid;
48836 +#endif
48837 }
48838 if (de->size)
48839 inode->i_size = de->size;
48840 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48841 index eca4aca..19166b2 100644
48842 --- a/fs/proc/internal.h
48843 +++ b/fs/proc/internal.h
48844 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48845 struct pid *pid, struct task_struct *task);
48846 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48847 struct pid *pid, struct task_struct *task);
48848 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48849 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48850 +#endif
48851 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48852
48853 extern const struct file_operations proc_tid_children_operations;
48854 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48855 index 86c67ee..cdca321 100644
48856 --- a/fs/proc/kcore.c
48857 +++ b/fs/proc/kcore.c
48858 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48859 * the addresses in the elf_phdr on our list.
48860 */
48861 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48862 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48863 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48864 + if (tsz > buflen)
48865 tsz = buflen;
48866 -
48867 +
48868 while (buflen) {
48869 struct kcore_list *m;
48870
48871 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48872 kfree(elf_buf);
48873 } else {
48874 if (kern_addr_valid(start)) {
48875 - unsigned long n;
48876 + char *elf_buf;
48877 + mm_segment_t oldfs;
48878
48879 - n = copy_to_user(buffer, (char *)start, tsz);
48880 - /*
48881 - * We cannot distinguish between fault on source
48882 - * and fault on destination. When this happens
48883 - * we clear too and hope it will trigger the
48884 - * EFAULT again.
48885 - */
48886 - if (n) {
48887 - if (clear_user(buffer + tsz - n,
48888 - n))
48889 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48890 + if (!elf_buf)
48891 + return -ENOMEM;
48892 + oldfs = get_fs();
48893 + set_fs(KERNEL_DS);
48894 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48895 + set_fs(oldfs);
48896 + if (copy_to_user(buffer, elf_buf, tsz)) {
48897 + kfree(elf_buf);
48898 return -EFAULT;
48899 + }
48900 }
48901 + set_fs(oldfs);
48902 + kfree(elf_buf);
48903 } else {
48904 if (clear_user(buffer, tsz))
48905 return -EFAULT;
48906 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48907
48908 static int open_kcore(struct inode *inode, struct file *filp)
48909 {
48910 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48911 + return -EPERM;
48912 +#endif
48913 if (!capable(CAP_SYS_RAWIO))
48914 return -EPERM;
48915 if (kcore_need_update)
48916 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48917 index 80e4645..53e5fcf 100644
48918 --- a/fs/proc/meminfo.c
48919 +++ b/fs/proc/meminfo.c
48920 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48921 vmi.used >> 10,
48922 vmi.largest_chunk >> 10
48923 #ifdef CONFIG_MEMORY_FAILURE
48924 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48925 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48926 #endif
48927 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48928 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48929 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48930 index b1822dd..df622cb 100644
48931 --- a/fs/proc/nommu.c
48932 +++ b/fs/proc/nommu.c
48933 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48934 if (len < 1)
48935 len = 1;
48936 seq_printf(m, "%*c", len, ' ');
48937 - seq_path(m, &file->f_path, "");
48938 + seq_path(m, &file->f_path, "\n\\");
48939 }
48940
48941 seq_putc(m, '\n');
48942 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48943 index 06e1cc1..177cd98 100644
48944 --- a/fs/proc/proc_net.c
48945 +++ b/fs/proc/proc_net.c
48946 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48947 struct task_struct *task;
48948 struct nsproxy *ns;
48949 struct net *net = NULL;
48950 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48951 + const struct cred *cred = current_cred();
48952 +#endif
48953 +
48954 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48955 + if (cred->fsuid)
48956 + return net;
48957 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48958 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48959 + return net;
48960 +#endif
48961
48962 rcu_read_lock();
48963 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48964 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48965 index 3476bca..cb6d86a 100644
48966 --- a/fs/proc/proc_sysctl.c
48967 +++ b/fs/proc/proc_sysctl.c
48968 @@ -12,11 +12,15 @@
48969 #include <linux/module.h>
48970 #include "internal.h"
48971
48972 +extern int gr_handle_chroot_sysctl(const int op);
48973 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48974 + const int op);
48975 +
48976 static const struct dentry_operations proc_sys_dentry_operations;
48977 static const struct file_operations proc_sys_file_operations;
48978 -static const struct inode_operations proc_sys_inode_operations;
48979 +const struct inode_operations proc_sys_inode_operations;
48980 static const struct file_operations proc_sys_dir_file_operations;
48981 -static const struct inode_operations proc_sys_dir_operations;
48982 +const struct inode_operations proc_sys_dir_operations;
48983
48984 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48985 {
48986 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48987
48988 err = NULL;
48989 d_set_d_op(dentry, &proc_sys_dentry_operations);
48990 +
48991 + gr_handle_proc_create(dentry, inode);
48992 +
48993 d_add(dentry, inode);
48994
48995 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48996 + err = ERR_PTR(-ENOENT);
48997 +
48998 out:
48999 sysctl_head_finish(head);
49000 return err;
49001 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49002 struct inode *inode = filp->f_path.dentry->d_inode;
49003 struct ctl_table_header *head = grab_header(inode);
49004 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49005 + int op = write ? MAY_WRITE : MAY_READ;
49006 ssize_t error;
49007 size_t res;
49008
49009 if (IS_ERR(head))
49010 return PTR_ERR(head);
49011
49012 +
49013 /*
49014 * At this point we know that the sysctl was not unregistered
49015 * and won't be until we finish.
49016 */
49017 error = -EPERM;
49018 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49019 + if (sysctl_perm(head->root, table, op))
49020 goto out;
49021
49022 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49023 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49024 if (!table->proc_handler)
49025 goto out;
49026
49027 +#ifdef CONFIG_GRKERNSEC
49028 + error = -EPERM;
49029 + if (gr_handle_chroot_sysctl(op))
49030 + goto out;
49031 + dget(filp->f_path.dentry);
49032 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49033 + dput(filp->f_path.dentry);
49034 + goto out;
49035 + }
49036 + dput(filp->f_path.dentry);
49037 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49038 + goto out;
49039 + if (write && !capable(CAP_SYS_ADMIN))
49040 + goto out;
49041 +#endif
49042 +
49043 /* careful: calling conventions are nasty here */
49044 res = count;
49045 error = table->proc_handler(table, write, buf, &res, ppos);
49046 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49047 return -ENOMEM;
49048 } else {
49049 d_set_d_op(child, &proc_sys_dentry_operations);
49050 +
49051 + gr_handle_proc_create(child, inode);
49052 +
49053 d_add(child, inode);
49054 }
49055 } else {
49056 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49057 if ((*pos)++ < file->f_pos)
49058 return 0;
49059
49060 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49061 + return 0;
49062 +
49063 if (unlikely(S_ISLNK(table->mode)))
49064 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49065 else
49066 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49067 if (IS_ERR(head))
49068 return PTR_ERR(head);
49069
49070 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49071 + return -ENOENT;
49072 +
49073 generic_fillattr(inode, stat);
49074 if (table)
49075 stat->mode = (stat->mode & S_IFMT) | table->mode;
49076 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49077 .llseek = generic_file_llseek,
49078 };
49079
49080 -static const struct inode_operations proc_sys_inode_operations = {
49081 +const struct inode_operations proc_sys_inode_operations = {
49082 .permission = proc_sys_permission,
49083 .setattr = proc_sys_setattr,
49084 .getattr = proc_sys_getattr,
49085 };
49086
49087 -static const struct inode_operations proc_sys_dir_operations = {
49088 +const struct inode_operations proc_sys_dir_operations = {
49089 .lookup = proc_sys_lookup,
49090 .permission = proc_sys_permission,
49091 .setattr = proc_sys_setattr,
49092 diff --git a/fs/proc/root.c b/fs/proc/root.c
49093 index 7c30fce..b3d3aa2 100644
49094 --- a/fs/proc/root.c
49095 +++ b/fs/proc/root.c
49096 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
49097 #ifdef CONFIG_PROC_DEVICETREE
49098 proc_device_tree_init();
49099 #endif
49100 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49101 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49102 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49103 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49104 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49105 +#endif
49106 +#else
49107 proc_mkdir("bus", NULL);
49108 +#endif
49109 proc_sys_init();
49110 }
49111
49112 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49113 index 4540b8f..1b9772f 100644
49114 --- a/fs/proc/task_mmu.c
49115 +++ b/fs/proc/task_mmu.c
49116 @@ -11,12 +11,19 @@
49117 #include <linux/rmap.h>
49118 #include <linux/swap.h>
49119 #include <linux/swapops.h>
49120 +#include <linux/grsecurity.h>
49121
49122 #include <asm/elf.h>
49123 #include <asm/uaccess.h>
49124 #include <asm/tlbflush.h>
49125 #include "internal.h"
49126
49127 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49128 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49129 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49130 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49131 +#endif
49132 +
49133 void task_mem(struct seq_file *m, struct mm_struct *mm)
49134 {
49135 unsigned long data, text, lib, swap;
49136 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49137 "VmExe:\t%8lu kB\n"
49138 "VmLib:\t%8lu kB\n"
49139 "VmPTE:\t%8lu kB\n"
49140 - "VmSwap:\t%8lu kB\n",
49141 - hiwater_vm << (PAGE_SHIFT-10),
49142 + "VmSwap:\t%8lu kB\n"
49143 +
49144 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49145 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49146 +#endif
49147 +
49148 + ,hiwater_vm << (PAGE_SHIFT-10),
49149 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49150 mm->locked_vm << (PAGE_SHIFT-10),
49151 mm->pinned_vm << (PAGE_SHIFT-10),
49152 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49153 data << (PAGE_SHIFT-10),
49154 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49155 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49156 - swap << (PAGE_SHIFT-10));
49157 + swap << (PAGE_SHIFT-10)
49158 +
49159 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49160 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49161 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49162 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49163 +#else
49164 + , mm->context.user_cs_base
49165 + , mm->context.user_cs_limit
49166 +#endif
49167 +#endif
49168 +
49169 + );
49170 }
49171
49172 unsigned long task_vsize(struct mm_struct *mm)
49173 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49174 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49175 }
49176
49177 - /* We don't show the stack guard page in /proc/maps */
49178 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49179 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49180 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49181 +#else
49182 start = vma->vm_start;
49183 - if (stack_guard_page_start(vma, start))
49184 - start += PAGE_SIZE;
49185 end = vma->vm_end;
49186 - if (stack_guard_page_end(vma, end))
49187 - end -= PAGE_SIZE;
49188 +#endif
49189
49190 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49191 start,
49192 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49193 flags & VM_WRITE ? 'w' : '-',
49194 flags & VM_EXEC ? 'x' : '-',
49195 flags & VM_MAYSHARE ? 's' : 'p',
49196 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49197 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49198 +#else
49199 pgoff,
49200 +#endif
49201 MAJOR(dev), MINOR(dev), ino, &len);
49202
49203 /*
49204 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49205 */
49206 if (file) {
49207 pad_len_spaces(m, len);
49208 - seq_path(m, &file->f_path, "\n");
49209 + seq_path(m, &file->f_path, "\n\\");
49210 goto done;
49211 }
49212
49213 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49214 * Thread stack in /proc/PID/task/TID/maps or
49215 * the main process stack.
49216 */
49217 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49218 - vma->vm_end >= mm->start_stack)) {
49219 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49220 + (vma->vm_start <= mm->start_stack &&
49221 + vma->vm_end >= mm->start_stack)) {
49222 name = "[stack]";
49223 } else {
49224 /* Thread stack in /proc/PID/maps */
49225 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49226 struct proc_maps_private *priv = m->private;
49227 struct task_struct *task = priv->task;
49228
49229 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49230 + if (current->exec_id != m->exec_id) {
49231 + gr_log_badprocpid("maps");
49232 + return 0;
49233 + }
49234 +#endif
49235 +
49236 show_map_vma(m, vma, is_pid);
49237
49238 if (m->count < m->size) /* vma is copied successfully */
49239 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49240 .private = &mss,
49241 };
49242
49243 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49244 + if (current->exec_id != m->exec_id) {
49245 + gr_log_badprocpid("smaps");
49246 + return 0;
49247 + }
49248 +#endif
49249 memset(&mss, 0, sizeof mss);
49250 - mss.vma = vma;
49251 - /* mmap_sem is held in m_start */
49252 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49253 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49254 -
49255 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49256 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49257 +#endif
49258 + mss.vma = vma;
49259 + /* mmap_sem is held in m_start */
49260 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49261 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49262 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49263 + }
49264 +#endif
49265 show_map_vma(m, vma, is_pid);
49266
49267 seq_printf(m,
49268 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49269 "KernelPageSize: %8lu kB\n"
49270 "MMUPageSize: %8lu kB\n"
49271 "Locked: %8lu kB\n",
49272 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49273 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49274 +#else
49275 (vma->vm_end - vma->vm_start) >> 10,
49276 +#endif
49277 mss.resident >> 10,
49278 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49279 mss.shared_clean >> 10,
49280 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49281 int n;
49282 char buffer[50];
49283
49284 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49285 + if (current->exec_id != m->exec_id) {
49286 + gr_log_badprocpid("numa_maps");
49287 + return 0;
49288 + }
49289 +#endif
49290 +
49291 if (!mm)
49292 return 0;
49293
49294 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49295 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49296 mpol_cond_put(pol);
49297
49298 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49299 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49300 +#else
49301 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49302 +#endif
49303
49304 if (file) {
49305 seq_printf(m, " file=");
49306 - seq_path(m, &file->f_path, "\n\t= ");
49307 + seq_path(m, &file->f_path, "\n\t\\= ");
49308 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49309 seq_printf(m, " heap");
49310 } else {
49311 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49312 index 1ccfa53..0848f95 100644
49313 --- a/fs/proc/task_nommu.c
49314 +++ b/fs/proc/task_nommu.c
49315 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49316 else
49317 bytes += kobjsize(mm);
49318
49319 - if (current->fs && current->fs->users > 1)
49320 + if (current->fs && atomic_read(&current->fs->users) > 1)
49321 sbytes += kobjsize(current->fs);
49322 else
49323 bytes += kobjsize(current->fs);
49324 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49325
49326 if (file) {
49327 pad_len_spaces(m, len);
49328 - seq_path(m, &file->f_path, "");
49329 + seq_path(m, &file->f_path, "\n\\");
49330 } else if (mm) {
49331 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49332
49333 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49334 index d67908b..d13f6a6 100644
49335 --- a/fs/quota/netlink.c
49336 +++ b/fs/quota/netlink.c
49337 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49338 void quota_send_warning(short type, unsigned int id, dev_t dev,
49339 const char warntype)
49340 {
49341 - static atomic_t seq;
49342 + static atomic_unchecked_t seq;
49343 struct sk_buff *skb;
49344 void *msg_head;
49345 int ret;
49346 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49347 "VFS: Not enough memory to send quota warning.\n");
49348 return;
49349 }
49350 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49351 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49352 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49353 if (!msg_head) {
49354 printk(KERN_ERR
49355 diff --git a/fs/readdir.c b/fs/readdir.c
49356 index 39e3370..20d446d 100644
49357 --- a/fs/readdir.c
49358 +++ b/fs/readdir.c
49359 @@ -17,6 +17,7 @@
49360 #include <linux/security.h>
49361 #include <linux/syscalls.h>
49362 #include <linux/unistd.h>
49363 +#include <linux/namei.h>
49364
49365 #include <asm/uaccess.h>
49366
49367 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49368
49369 struct readdir_callback {
49370 struct old_linux_dirent __user * dirent;
49371 + struct file * file;
49372 int result;
49373 };
49374
49375 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49376 buf->result = -EOVERFLOW;
49377 return -EOVERFLOW;
49378 }
49379 +
49380 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49381 + return 0;
49382 +
49383 buf->result++;
49384 dirent = buf->dirent;
49385 if (!access_ok(VERIFY_WRITE, dirent,
49386 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49387
49388 buf.result = 0;
49389 buf.dirent = dirent;
49390 + buf.file = file;
49391
49392 error = vfs_readdir(file, fillonedir, &buf);
49393 if (buf.result)
49394 @@ -141,6 +148,7 @@ struct linux_dirent {
49395 struct getdents_callback {
49396 struct linux_dirent __user * current_dir;
49397 struct linux_dirent __user * previous;
49398 + struct file * file;
49399 int count;
49400 int error;
49401 };
49402 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49403 buf->error = -EOVERFLOW;
49404 return -EOVERFLOW;
49405 }
49406 +
49407 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49408 + return 0;
49409 +
49410 dirent = buf->previous;
49411 if (dirent) {
49412 if (__put_user(offset, &dirent->d_off))
49413 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49414 buf.previous = NULL;
49415 buf.count = count;
49416 buf.error = 0;
49417 + buf.file = file;
49418
49419 error = vfs_readdir(file, filldir, &buf);
49420 if (error >= 0)
49421 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49422 struct getdents_callback64 {
49423 struct linux_dirent64 __user * current_dir;
49424 struct linux_dirent64 __user * previous;
49425 + struct file *file;
49426 int count;
49427 int error;
49428 };
49429 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49430 buf->error = -EINVAL; /* only used if we fail.. */
49431 if (reclen > buf->count)
49432 return -EINVAL;
49433 +
49434 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49435 + return 0;
49436 +
49437 dirent = buf->previous;
49438 if (dirent) {
49439 if (__put_user(offset, &dirent->d_off))
49440 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49441
49442 buf.current_dir = dirent;
49443 buf.previous = NULL;
49444 + buf.file = file;
49445 buf.count = count;
49446 buf.error = 0;
49447
49448 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49449 error = buf.error;
49450 lastdirent = buf.previous;
49451 if (lastdirent) {
49452 - typeof(lastdirent->d_off) d_off = file->f_pos;
49453 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49454 if (__put_user(d_off, &lastdirent->d_off))
49455 error = -EFAULT;
49456 else
49457 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49458 index 2b7882b..1c5ef48 100644
49459 --- a/fs/reiserfs/do_balan.c
49460 +++ b/fs/reiserfs/do_balan.c
49461 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49462 return;
49463 }
49464
49465 - atomic_inc(&(fs_generation(tb->tb_sb)));
49466 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49467 do_balance_starts(tb);
49468
49469 /* balance leaf returns 0 except if combining L R and S into
49470 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49471 index 2c1ade6..8c59d8d 100644
49472 --- a/fs/reiserfs/procfs.c
49473 +++ b/fs/reiserfs/procfs.c
49474 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49475 "SMALL_TAILS " : "NO_TAILS ",
49476 replay_only(sb) ? "REPLAY_ONLY " : "",
49477 convert_reiserfs(sb) ? "CONV " : "",
49478 - atomic_read(&r->s_generation_counter),
49479 + atomic_read_unchecked(&r->s_generation_counter),
49480 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49481 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49482 SF(s_good_search_by_key_reada), SF(s_bmaps),
49483 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49484 index 33215f5..c5d427a 100644
49485 --- a/fs/reiserfs/reiserfs.h
49486 +++ b/fs/reiserfs/reiserfs.h
49487 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49488 /* Comment? -Hans */
49489 wait_queue_head_t s_wait;
49490 /* To be obsoleted soon by per buffer seals.. -Hans */
49491 - atomic_t s_generation_counter; // increased by one every time the
49492 + atomic_unchecked_t s_generation_counter; // increased by one every time the
49493 // tree gets re-balanced
49494 unsigned long s_properties; /* File system properties. Currently holds
49495 on-disk FS format */
49496 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49497 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49498
49499 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49500 -#define get_generation(s) atomic_read (&fs_generation(s))
49501 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49502 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49503 #define __fs_changed(gen,s) (gen != get_generation (s))
49504 #define fs_changed(gen,s) \
49505 diff --git a/fs/select.c b/fs/select.c
49506 index bae3215..06b4707 100644
49507 --- a/fs/select.c
49508 +++ b/fs/select.c
49509 @@ -20,6 +20,7 @@
49510 #include <linux/export.h>
49511 #include <linux/slab.h>
49512 #include <linux/poll.h>
49513 +#include <linux/security.h>
49514 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49515 #include <linux/file.h>
49516 #include <linux/fdtable.h>
49517 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49518 struct poll_list *walk = head;
49519 unsigned long todo = nfds;
49520
49521 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49522 if (nfds > rlimit(RLIMIT_NOFILE))
49523 return -EINVAL;
49524
49525 diff --git a/fs/seq_file.c b/fs/seq_file.c
49526 index 0cbd049..64e705c 100644
49527 --- a/fs/seq_file.c
49528 +++ b/fs/seq_file.c
49529 @@ -9,6 +9,7 @@
49530 #include <linux/export.h>
49531 #include <linux/seq_file.h>
49532 #include <linux/slab.h>
49533 +#include <linux/sched.h>
49534
49535 #include <asm/uaccess.h>
49536 #include <asm/page.h>
49537 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49538 memset(p, 0, sizeof(*p));
49539 mutex_init(&p->lock);
49540 p->op = op;
49541 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49542 + p->exec_id = current->exec_id;
49543 +#endif
49544
49545 /*
49546 * Wrappers around seq_open(e.g. swaps_open) need to be
49547 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49548 return 0;
49549 }
49550 if (!m->buf) {
49551 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49552 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49553 if (!m->buf)
49554 return -ENOMEM;
49555 }
49556 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49557 Eoverflow:
49558 m->op->stop(m, p);
49559 kfree(m->buf);
49560 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49561 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49562 return !m->buf ? -ENOMEM : -EAGAIN;
49563 }
49564
49565 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49566
49567 /* grab buffer if we didn't have one */
49568 if (!m->buf) {
49569 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49570 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49571 if (!m->buf)
49572 goto Enomem;
49573 }
49574 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49575 goto Fill;
49576 m->op->stop(m, p);
49577 kfree(m->buf);
49578 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49579 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49580 if (!m->buf)
49581 goto Enomem;
49582 m->count = 0;
49583 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49584 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49585 void *data)
49586 {
49587 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49588 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49589 int res = -ENOMEM;
49590
49591 if (op) {
49592 diff --git a/fs/splice.c b/fs/splice.c
49593 index 7bf08fa..eb35c2f 100644
49594 --- a/fs/splice.c
49595 +++ b/fs/splice.c
49596 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49597 pipe_lock(pipe);
49598
49599 for (;;) {
49600 - if (!pipe->readers) {
49601 + if (!atomic_read(&pipe->readers)) {
49602 send_sig(SIGPIPE, current, 0);
49603 if (!ret)
49604 ret = -EPIPE;
49605 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49606 do_wakeup = 0;
49607 }
49608
49609 - pipe->waiting_writers++;
49610 + atomic_inc(&pipe->waiting_writers);
49611 pipe_wait(pipe);
49612 - pipe->waiting_writers--;
49613 + atomic_dec(&pipe->waiting_writers);
49614 }
49615
49616 pipe_unlock(pipe);
49617 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49618 old_fs = get_fs();
49619 set_fs(get_ds());
49620 /* The cast to a user pointer is valid due to the set_fs() */
49621 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49622 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49623 set_fs(old_fs);
49624
49625 return res;
49626 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49627 old_fs = get_fs();
49628 set_fs(get_ds());
49629 /* The cast to a user pointer is valid due to the set_fs() */
49630 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49631 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49632 set_fs(old_fs);
49633
49634 return res;
49635 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49636 goto err;
49637
49638 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49639 - vec[i].iov_base = (void __user *) page_address(page);
49640 + vec[i].iov_base = (void __force_user *) page_address(page);
49641 vec[i].iov_len = this_len;
49642 spd.pages[i] = page;
49643 spd.nr_pages++;
49644 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49645 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49646 {
49647 while (!pipe->nrbufs) {
49648 - if (!pipe->writers)
49649 + if (!atomic_read(&pipe->writers))
49650 return 0;
49651
49652 - if (!pipe->waiting_writers && sd->num_spliced)
49653 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49654 return 0;
49655
49656 if (sd->flags & SPLICE_F_NONBLOCK)
49657 @@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49658 * out of the pipe right after the splice_to_pipe(). So set
49659 * PIPE_READERS appropriately.
49660 */
49661 - pipe->readers = 1;
49662 + atomic_set(&pipe->readers, 1);
49663
49664 current->splice_pipe = pipe;
49665 }
49666 @@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49667 ret = -ERESTARTSYS;
49668 break;
49669 }
49670 - if (!pipe->writers)
49671 + if (!atomic_read(&pipe->writers))
49672 break;
49673 - if (!pipe->waiting_writers) {
49674 + if (!atomic_read(&pipe->waiting_writers)) {
49675 if (flags & SPLICE_F_NONBLOCK) {
49676 ret = -EAGAIN;
49677 break;
49678 @@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49679 pipe_lock(pipe);
49680
49681 while (pipe->nrbufs >= pipe->buffers) {
49682 - if (!pipe->readers) {
49683 + if (!atomic_read(&pipe->readers)) {
49684 send_sig(SIGPIPE, current, 0);
49685 ret = -EPIPE;
49686 break;
49687 @@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49688 ret = -ERESTARTSYS;
49689 break;
49690 }
49691 - pipe->waiting_writers++;
49692 + atomic_inc(&pipe->waiting_writers);
49693 pipe_wait(pipe);
49694 - pipe->waiting_writers--;
49695 + atomic_dec(&pipe->waiting_writers);
49696 }
49697
49698 pipe_unlock(pipe);
49699 @@ -1825,14 +1825,14 @@ retry:
49700 pipe_double_lock(ipipe, opipe);
49701
49702 do {
49703 - if (!opipe->readers) {
49704 + if (!atomic_read(&opipe->readers)) {
49705 send_sig(SIGPIPE, current, 0);
49706 if (!ret)
49707 ret = -EPIPE;
49708 break;
49709 }
49710
49711 - if (!ipipe->nrbufs && !ipipe->writers)
49712 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49713 break;
49714
49715 /*
49716 @@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49717 pipe_double_lock(ipipe, opipe);
49718
49719 do {
49720 - if (!opipe->readers) {
49721 + if (!atomic_read(&opipe->readers)) {
49722 send_sig(SIGPIPE, current, 0);
49723 if (!ret)
49724 ret = -EPIPE;
49725 @@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49726 * return EAGAIN if we have the potential of some data in the
49727 * future, otherwise just return 0
49728 */
49729 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49730 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49731 ret = -EAGAIN;
49732
49733 pipe_unlock(ipipe);
49734 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49735 index e6bb9b2..d8e3951 100644
49736 --- a/fs/sysfs/dir.c
49737 +++ b/fs/sysfs/dir.c
49738 @@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49739 struct sysfs_dirent *sd;
49740 int rc;
49741
49742 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49743 + const char *parent_name = parent_sd->s_name;
49744 +
49745 + mode = S_IFDIR | S_IRWXU;
49746 +
49747 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49748 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49749 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49750 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49751 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49752 +#endif
49753 +
49754 /* allocate */
49755 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49756 if (!sd)
49757 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49758 index 00012e3..8392349 100644
49759 --- a/fs/sysfs/file.c
49760 +++ b/fs/sysfs/file.c
49761 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49762
49763 struct sysfs_open_dirent {
49764 atomic_t refcnt;
49765 - atomic_t event;
49766 + atomic_unchecked_t event;
49767 wait_queue_head_t poll;
49768 struct list_head buffers; /* goes through sysfs_buffer.list */
49769 };
49770 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49771 if (!sysfs_get_active(attr_sd))
49772 return -ENODEV;
49773
49774 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49775 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49776 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49777
49778 sysfs_put_active(attr_sd);
49779 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49780 return -ENOMEM;
49781
49782 atomic_set(&new_od->refcnt, 0);
49783 - atomic_set(&new_od->event, 1);
49784 + atomic_set_unchecked(&new_od->event, 1);
49785 init_waitqueue_head(&new_od->poll);
49786 INIT_LIST_HEAD(&new_od->buffers);
49787 goto retry;
49788 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49789
49790 sysfs_put_active(attr_sd);
49791
49792 - if (buffer->event != atomic_read(&od->event))
49793 + if (buffer->event != atomic_read_unchecked(&od->event))
49794 goto trigger;
49795
49796 return DEFAULT_POLLMASK;
49797 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49798
49799 od = sd->s_attr.open;
49800 if (od) {
49801 - atomic_inc(&od->event);
49802 + atomic_inc_unchecked(&od->event);
49803 wake_up_interruptible(&od->poll);
49804 }
49805
49806 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49807 index a7ac78f..02158e1 100644
49808 --- a/fs/sysfs/symlink.c
49809 +++ b/fs/sysfs/symlink.c
49810 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49811
49812 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49813 {
49814 - char *page = nd_get_link(nd);
49815 + const char *page = nd_get_link(nd);
49816 if (!IS_ERR(page))
49817 free_page((unsigned long)page);
49818 }
49819 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49820 index c175b4d..8f36a16 100644
49821 --- a/fs/udf/misc.c
49822 +++ b/fs/udf/misc.c
49823 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49824
49825 u8 udf_tag_checksum(const struct tag *t)
49826 {
49827 - u8 *data = (u8 *)t;
49828 + const u8 *data = (const u8 *)t;
49829 u8 checksum = 0;
49830 int i;
49831 for (i = 0; i < sizeof(struct tag); ++i)
49832 diff --git a/fs/utimes.c b/fs/utimes.c
49833 index fa4dbe4..e12d1b9 100644
49834 --- a/fs/utimes.c
49835 +++ b/fs/utimes.c
49836 @@ -1,6 +1,7 @@
49837 #include <linux/compiler.h>
49838 #include <linux/file.h>
49839 #include <linux/fs.h>
49840 +#include <linux/security.h>
49841 #include <linux/linkage.h>
49842 #include <linux/mount.h>
49843 #include <linux/namei.h>
49844 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49845 goto mnt_drop_write_and_out;
49846 }
49847 }
49848 +
49849 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49850 + error = -EACCES;
49851 + goto mnt_drop_write_and_out;
49852 + }
49853 +
49854 mutex_lock(&inode->i_mutex);
49855 error = notify_change(path->dentry, &newattrs);
49856 mutex_unlock(&inode->i_mutex);
49857 diff --git a/fs/xattr.c b/fs/xattr.c
49858 index 1d7ac37..23cb9ec 100644
49859 --- a/fs/xattr.c
49860 +++ b/fs/xattr.c
49861 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49862 * Extended attribute SET operations
49863 */
49864 static long
49865 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49866 +setxattr(struct path *path, const char __user *name, const void __user *value,
49867 size_t size, int flags)
49868 {
49869 int error;
49870 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49871 }
49872 }
49873
49874 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49875 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49876 + error = -EACCES;
49877 + goto out;
49878 + }
49879 +
49880 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49881 out:
49882 if (vvalue)
49883 vfree(vvalue);
49884 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49885 return error;
49886 error = mnt_want_write(path.mnt);
49887 if (!error) {
49888 - error = setxattr(path.dentry, name, value, size, flags);
49889 + error = setxattr(&path, name, value, size, flags);
49890 mnt_drop_write(path.mnt);
49891 }
49892 path_put(&path);
49893 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49894 return error;
49895 error = mnt_want_write(path.mnt);
49896 if (!error) {
49897 - error = setxattr(path.dentry, name, value, size, flags);
49898 + error = setxattr(&path, name, value, size, flags);
49899 mnt_drop_write(path.mnt);
49900 }
49901 path_put(&path);
49902 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49903 {
49904 int fput_needed;
49905 struct file *f;
49906 - struct dentry *dentry;
49907 int error = -EBADF;
49908
49909 f = fget_light(fd, &fput_needed);
49910 if (!f)
49911 return error;
49912 - dentry = f->f_path.dentry;
49913 - audit_inode(NULL, dentry);
49914 + audit_inode(NULL, f->f_path.dentry);
49915 error = mnt_want_write_file(f);
49916 if (!error) {
49917 - error = setxattr(dentry, name, value, size, flags);
49918 + error = setxattr(&f->f_path, name, value, size, flags);
49919 mnt_drop_write_file(f);
49920 }
49921 fput_light(f, fput_needed);
49922 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49923 index 69d06b0..c0996e5 100644
49924 --- a/fs/xattr_acl.c
49925 +++ b/fs/xattr_acl.c
49926 @@ -17,8 +17,8 @@
49927 struct posix_acl *
49928 posix_acl_from_xattr(const void *value, size_t size)
49929 {
49930 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49931 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49932 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49933 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49934 int count;
49935 struct posix_acl *acl;
49936 struct posix_acl_entry *acl_e;
49937 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49938 index 58b815e..595ddee 100644
49939 --- a/fs/xfs/xfs_bmap.c
49940 +++ b/fs/xfs/xfs_bmap.c
49941 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
49942 int nmap,
49943 int ret_nmap);
49944 #else
49945 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49946 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49947 #endif /* DEBUG */
49948
49949 STATIC int
49950 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49951 index 19bf0c5..9f26b02 100644
49952 --- a/fs/xfs/xfs_dir2_sf.c
49953 +++ b/fs/xfs/xfs_dir2_sf.c
49954 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
49955 }
49956
49957 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49958 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49959 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49960 + char name[sfep->namelen];
49961 + memcpy(name, sfep->name, sfep->namelen);
49962 + if (filldir(dirent, name, sfep->namelen,
49963 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49964 + *offset = off & 0x7fffffff;
49965 + return 0;
49966 + }
49967 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49968 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49969 *offset = off & 0x7fffffff;
49970 return 0;
49971 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49972 index 3a05a41..320bec6 100644
49973 --- a/fs/xfs/xfs_ioctl.c
49974 +++ b/fs/xfs/xfs_ioctl.c
49975 @@ -126,7 +126,7 @@ xfs_find_handle(
49976 }
49977
49978 error = -EFAULT;
49979 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49980 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49981 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49982 goto out_put;
49983
49984 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49985 index 1a25fd8..e935581 100644
49986 --- a/fs/xfs/xfs_iops.c
49987 +++ b/fs/xfs/xfs_iops.c
49988 @@ -394,7 +394,7 @@ xfs_vn_put_link(
49989 struct nameidata *nd,
49990 void *p)
49991 {
49992 - char *s = nd_get_link(nd);
49993 + const char *s = nd_get_link(nd);
49994
49995 if (!IS_ERR(s))
49996 kfree(s);
49997 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49998 new file mode 100644
49999 index 0000000..4d533f1
50000 --- /dev/null
50001 +++ b/grsecurity/Kconfig
50002 @@ -0,0 +1,941 @@
50003 +#
50004 +# grecurity configuration
50005 +#
50006 +menu "Memory Protections"
50007 +depends on GRKERNSEC
50008 +
50009 +config GRKERNSEC_KMEM
50010 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50011 + default y if GRKERNSEC_CONFIG_AUTO
50012 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50013 + help
50014 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50015 + be written to or read from to modify or leak the contents of the running
50016 + kernel. /dev/port will also not be allowed to be opened. If you have module
50017 + support disabled, enabling this will close up four ways that are
50018 + currently used to insert malicious code into the running kernel.
50019 + Even with all these features enabled, we still highly recommend that
50020 + you use the RBAC system, as it is still possible for an attacker to
50021 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50022 + If you are not using XFree86, you may be able to stop this additional
50023 + case by enabling the 'Disable privileged I/O' option. Though nothing
50024 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50025 + but only to video memory, which is the only writing we allow in this
50026 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50027 + not be allowed to mprotect it with PROT_WRITE later.
50028 + It is highly recommended that you say Y here if you meet all the
50029 + conditions above.
50030 +
50031 +config GRKERNSEC_VM86
50032 + bool "Restrict VM86 mode"
50033 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50034 + depends on X86_32
50035 +
50036 + help
50037 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50038 + make use of a special execution mode on 32bit x86 processors called
50039 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50040 + video cards and will still work with this option enabled. The purpose
50041 + of the option is to prevent exploitation of emulation errors in
50042 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50043 + Nearly all users should be able to enable this option.
50044 +
50045 +config GRKERNSEC_IO
50046 + bool "Disable privileged I/O"
50047 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50048 + depends on X86
50049 + select RTC_CLASS
50050 + select RTC_INTF_DEV
50051 + select RTC_DRV_CMOS
50052 +
50053 + help
50054 + If you say Y here, all ioperm and iopl calls will return an error.
50055 + Ioperm and iopl can be used to modify the running kernel.
50056 + Unfortunately, some programs need this access to operate properly,
50057 + the most notable of which are XFree86 and hwclock. hwclock can be
50058 + remedied by having RTC support in the kernel, so real-time
50059 + clock support is enabled if this option is enabled, to ensure
50060 + that hwclock operates correctly. XFree86 still will not
50061 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50062 + IF YOU USE XFree86. If you use XFree86 and you still want to
50063 + protect your kernel against modification, use the RBAC system.
50064 +
50065 +config GRKERNSEC_PROC_MEMMAP
50066 + bool "Harden ASLR against information leaks and entropy reduction"
50067 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50068 + depends on PAX_NOEXEC || PAX_ASLR
50069 + help
50070 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50071 + give no information about the addresses of its mappings if
50072 + PaX features that rely on random addresses are enabled on the task.
50073 + In addition to sanitizing this information and disabling other
50074 + dangerous sources of information, this option causes reads of sensitive
50075 + /proc/<pid> entries where the file descriptor was opened in a different
50076 + task than the one performing the read. Such attempts are logged.
50077 + This option also limits argv/env strings for suid/sgid binaries
50078 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50079 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50080 + binaries to prevent alternative mmap layouts from being abused.
50081 +
50082 + If you use PaX it is essential that you say Y here as it closes up
50083 + several holes that make full ASLR useless locally.
50084 +
50085 +config GRKERNSEC_BRUTE
50086 + bool "Deter exploit bruteforcing"
50087 + default y if GRKERNSEC_CONFIG_AUTO
50088 + help
50089 + If you say Y here, attempts to bruteforce exploits against forking
50090 + daemons such as apache or sshd, as well as against suid/sgid binaries
50091 + will be deterred. When a child of a forking daemon is killed by PaX
50092 + or crashes due to an illegal instruction or other suspicious signal,
50093 + the parent process will be delayed 30 seconds upon every subsequent
50094 + fork until the administrator is able to assess the situation and
50095 + restart the daemon.
50096 + In the suid/sgid case, the attempt is logged, the user has all their
50097 + processes terminated, and they are prevented from executing any further
50098 + processes for 15 minutes.
50099 + It is recommended that you also enable signal logging in the auditing
50100 + section so that logs are generated when a process triggers a suspicious
50101 + signal.
50102 + If the sysctl option is enabled, a sysctl option with name
50103 + "deter_bruteforce" is created.
50104 +
50105 +
50106 +config GRKERNSEC_MODHARDEN
50107 + bool "Harden module auto-loading"
50108 + default y if GRKERNSEC_CONFIG_AUTO
50109 + depends on MODULES
50110 + help
50111 + If you say Y here, module auto-loading in response to use of some
50112 + feature implemented by an unloaded module will be restricted to
50113 + root users. Enabling this option helps defend against attacks
50114 + by unprivileged users who abuse the auto-loading behavior to
50115 + cause a vulnerable module to load that is then exploited.
50116 +
50117 + If this option prevents a legitimate use of auto-loading for a
50118 + non-root user, the administrator can execute modprobe manually
50119 + with the exact name of the module mentioned in the alert log.
50120 + Alternatively, the administrator can add the module to the list
50121 + of modules loaded at boot by modifying init scripts.
50122 +
50123 + Modification of init scripts will most likely be needed on
50124 + Ubuntu servers with encrypted home directory support enabled,
50125 + as the first non-root user logging in will cause the ecb(aes),
50126 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50127 +
50128 +config GRKERNSEC_HIDESYM
50129 + bool "Hide kernel symbols"
50130 + default y if GRKERNSEC_CONFIG_AUTO
50131 + select PAX_USERCOPY_SLABS
50132 + help
50133 + If you say Y here, getting information on loaded modules, and
50134 + displaying all kernel symbols through a syscall will be restricted
50135 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50136 + /proc/kallsyms will be restricted to the root user. The RBAC
50137 + system can hide that entry even from root.
50138 +
50139 + This option also prevents leaking of kernel addresses through
50140 + several /proc entries.
50141 +
50142 + Note that this option is only effective provided the following
50143 + conditions are met:
50144 + 1) The kernel using grsecurity is not precompiled by some distribution
50145 + 2) You have also enabled GRKERNSEC_DMESG
50146 + 3) You are using the RBAC system and hiding other files such as your
50147 + kernel image and System.map. Alternatively, enabling this option
50148 + causes the permissions on /boot, /lib/modules, and the kernel
50149 + source directory to change at compile time to prevent
50150 + reading by non-root users.
50151 + If the above conditions are met, this option will aid in providing a
50152 + useful protection against local kernel exploitation of overflows
50153 + and arbitrary read/write vulnerabilities.
50154 +
50155 +config GRKERNSEC_KERN_LOCKOUT
50156 + bool "Active kernel exploit response"
50157 + default y if GRKERNSEC_CONFIG_AUTO
50158 + depends on X86 || ARM || PPC || SPARC
50159 + help
50160 + If you say Y here, when a PaX alert is triggered due to suspicious
50161 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50162 + or an OOPS occurs due to bad memory accesses, instead of just
50163 + terminating the offending process (and potentially allowing
50164 + a subsequent exploit from the same user), we will take one of two
50165 + actions:
50166 + If the user was root, we will panic the system
50167 + If the user was non-root, we will log the attempt, terminate
50168 + all processes owned by the user, then prevent them from creating
50169 + any new processes until the system is restarted
50170 + This deters repeated kernel exploitation/bruteforcing attempts
50171 + and is useful for later forensics.
50172 +
50173 +endmenu
50174 +menu "Role Based Access Control Options"
50175 +depends on GRKERNSEC
50176 +
50177 +config GRKERNSEC_RBAC_DEBUG
50178 + bool
50179 +
50180 +config GRKERNSEC_NO_RBAC
50181 + bool "Disable RBAC system"
50182 + help
50183 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50184 + preventing the RBAC system from being enabled. You should only say Y
50185 + here if you have no intention of using the RBAC system, so as to prevent
50186 + an attacker with root access from misusing the RBAC system to hide files
50187 + and processes when loadable module support and /dev/[k]mem have been
50188 + locked down.
50189 +
50190 +config GRKERNSEC_ACL_HIDEKERN
50191 + bool "Hide kernel processes"
50192 + help
50193 + If you say Y here, all kernel threads will be hidden to all
50194 + processes but those whose subject has the "view hidden processes"
50195 + flag.
50196 +
50197 +config GRKERNSEC_ACL_MAXTRIES
50198 + int "Maximum tries before password lockout"
50199 + default 3
50200 + help
50201 + This option enforces the maximum number of times a user can attempt
50202 + to authorize themselves with the grsecurity RBAC system before being
50203 + denied the ability to attempt authorization again for a specified time.
50204 + The lower the number, the harder it will be to brute-force a password.
50205 +
50206 +config GRKERNSEC_ACL_TIMEOUT
50207 + int "Time to wait after max password tries, in seconds"
50208 + default 30
50209 + help
50210 + This option specifies the time the user must wait after attempting to
50211 + authorize to the RBAC system with the maximum number of invalid
50212 + passwords. The higher the number, the harder it will be to brute-force
50213 + a password.
50214 +
50215 +endmenu
50216 +menu "Filesystem Protections"
50217 +depends on GRKERNSEC
50218 +
50219 +config GRKERNSEC_PROC
50220 + bool "Proc restrictions"
50221 + default y if GRKERNSEC_CONFIG_AUTO
50222 + help
50223 + If you say Y here, the permissions of the /proc filesystem
50224 + will be altered to enhance system security and privacy. You MUST
50225 + choose either a user only restriction or a user and group restriction.
50226 + Depending upon the option you choose, you can either restrict users to
50227 + see only the processes they themselves run, or choose a group that can
50228 + view all processes and files normally restricted to root if you choose
50229 + the "restrict to user only" option. NOTE: If you're running identd or
50230 + ntpd as a non-root user, you will have to run it as the group you
50231 + specify here.
50232 +
50233 +config GRKERNSEC_PROC_USER
50234 + bool "Restrict /proc to user only"
50235 + depends on GRKERNSEC_PROC
50236 + help
50237 + If you say Y here, non-root users will only be able to view their own
50238 + processes, and restricts them from viewing network-related information,
50239 + and viewing kernel symbol and module information.
50240 +
50241 +config GRKERNSEC_PROC_USERGROUP
50242 + bool "Allow special group"
50243 + default y if GRKERNSEC_CONFIG_AUTO
50244 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50245 + help
50246 + If you say Y here, you will be able to select a group that will be
50247 + able to view all processes and network-related information. If you've
50248 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50249 + remain hidden. This option is useful if you want to run identd as
50250 + a non-root user.
50251 +
50252 +config GRKERNSEC_PROC_GID
50253 + int "GID for special group"
50254 + depends on GRKERNSEC_PROC_USERGROUP
50255 + default 1001
50256 +
50257 +config GRKERNSEC_PROC_ADD
50258 + bool "Additional restrictions"
50259 + default y if GRKERNSEC_CONFIG_AUTO
50260 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50261 + help
50262 + If you say Y here, additional restrictions will be placed on
50263 + /proc that keep normal users from viewing device information and
50264 + slabinfo information that could be useful for exploits.
50265 +
50266 +config GRKERNSEC_LINK
50267 + bool "Linking restrictions"
50268 + default y if GRKERNSEC_CONFIG_AUTO
50269 + help
50270 + If you say Y here, /tmp race exploits will be prevented, since users
50271 + will no longer be able to follow symlinks owned by other users in
50272 + world-writable +t directories (e.g. /tmp), unless the owner of the
50273 + symlink is the owner of the directory. users will also not be
50274 + able to hardlink to files they do not own. If the sysctl option is
50275 + enabled, a sysctl option with name "linking_restrictions" is created.
50276 +
50277 +config GRKERNSEC_SYMLINKOWN
50278 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50279 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50280 + help
50281 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50282 + that prevents it from being used as a security feature. As Apache
50283 + verifies the symlink by performing a stat() against the target of
50284 + the symlink before it is followed, an attacker can setup a symlink
50285 + to point to a same-owned file, then replace the symlink with one
50286 + that targets another user's file just after Apache "validates" the
50287 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50288 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50289 + will be in place for the group you specify. If the sysctl option
50290 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50291 + created.
50292 +
50293 +config GRKERNSEC_SYMLINKOWN_GID
50294 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50295 + depends on GRKERNSEC_SYMLINKOWN
50296 + default 1006
50297 + help
50298 + Setting this GID determines what group kernel-enforced
50299 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50300 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50301 +
50302 +config GRKERNSEC_FIFO
50303 + bool "FIFO restrictions"
50304 + default y if GRKERNSEC_CONFIG_AUTO
50305 + help
50306 + If you say Y here, users will not be able to write to FIFOs they don't
50307 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50308 + the FIFO is the same owner of the directory it's held in. If the sysctl
50309 + option is enabled, a sysctl option with name "fifo_restrictions" is
50310 + created.
50311 +
50312 +config GRKERNSEC_SYSFS_RESTRICT
50313 + bool "Sysfs/debugfs restriction"
50314 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50315 + depends on SYSFS
50316 + help
50317 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50318 + any filesystem normally mounted under it (e.g. debugfs) will be
50319 + mostly accessible only by root. These filesystems generally provide access
50320 + to hardware and debug information that isn't appropriate for unprivileged
50321 + users of the system. Sysfs and debugfs have also become a large source
50322 + of new vulnerabilities, ranging from infoleaks to local compromise.
50323 + There has been very little oversight with an eye toward security involved
50324 + in adding new exporters of information to these filesystems, so their
50325 + use is discouraged.
50326 + For reasons of compatibility, a few directories have been whitelisted
50327 + for access by non-root users:
50328 + /sys/fs/selinux
50329 + /sys/fs/fuse
50330 + /sys/devices/system/cpu
50331 +
50332 +config GRKERNSEC_ROFS
50333 + bool "Runtime read-only mount protection"
50334 + help
50335 + If you say Y here, a sysctl option with name "romount_protect" will
50336 + be created. By setting this option to 1 at runtime, filesystems
50337 + will be protected in the following ways:
50338 + * No new writable mounts will be allowed
50339 + * Existing read-only mounts won't be able to be remounted read/write
50340 + * Write operations will be denied on all block devices
50341 + This option acts independently of grsec_lock: once it is set to 1,
50342 + it cannot be turned off. Therefore, please be mindful of the resulting
50343 + behavior if this option is enabled in an init script on a read-only
50344 + filesystem. This feature is mainly intended for secure embedded systems.
50345 +
50346 +config GRKERNSEC_CHROOT
50347 + bool "Chroot jail restrictions"
50348 + default y if GRKERNSEC_CONFIG_AUTO
50349 + help
50350 + If you say Y here, you will be able to choose several options that will
50351 + make breaking out of a chrooted jail much more difficult. If you
50352 + encounter no software incompatibilities with the following options, it
50353 + is recommended that you enable each one.
50354 +
50355 +config GRKERNSEC_CHROOT_MOUNT
50356 + bool "Deny mounts"
50357 + default y if GRKERNSEC_CONFIG_AUTO
50358 + depends on GRKERNSEC_CHROOT
50359 + help
50360 + If you say Y here, processes inside a chroot will not be able to
50361 + mount or remount filesystems. If the sysctl option is enabled, a
50362 + sysctl option with name "chroot_deny_mount" is created.
50363 +
50364 +config GRKERNSEC_CHROOT_DOUBLE
50365 + bool "Deny double-chroots"
50366 + default y if GRKERNSEC_CONFIG_AUTO
50367 + depends on GRKERNSEC_CHROOT
50368 + help
50369 + If you say Y here, processes inside a chroot will not be able to chroot
50370 + again outside the chroot. This is a widely used method of breaking
50371 + out of a chroot jail and should not be allowed. If the sysctl
50372 + option is enabled, a sysctl option with name
50373 + "chroot_deny_chroot" is created.
50374 +
50375 +config GRKERNSEC_CHROOT_PIVOT
50376 + bool "Deny pivot_root in chroot"
50377 + default y if GRKERNSEC_CONFIG_AUTO
50378 + depends on GRKERNSEC_CHROOT
50379 + help
50380 + If you say Y here, processes inside a chroot will not be able to use
50381 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50382 + works similar to chroot in that it changes the root filesystem. This
50383 + function could be misused in a chrooted process to attempt to break out
50384 + of the chroot, and therefore should not be allowed. If the sysctl
50385 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50386 + created.
50387 +
50388 +config GRKERNSEC_CHROOT_CHDIR
50389 + bool "Enforce chdir(\"/\") on all chroots"
50390 + default y if GRKERNSEC_CONFIG_AUTO
50391 + depends on GRKERNSEC_CHROOT
50392 + help
50393 + If you say Y here, the current working directory of all newly-chrooted
50394 + applications will be set to the the root directory of the chroot.
50395 + The man page on chroot(2) states:
50396 + Note that this call does not change the current working
50397 + directory, so that `.' can be outside the tree rooted at
50398 + `/'. In particular, the super-user can escape from a
50399 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50400 +
50401 + It is recommended that you say Y here, since it's not known to break
50402 + any software. If the sysctl option is enabled, a sysctl option with
50403 + name "chroot_enforce_chdir" is created.
50404 +
50405 +config GRKERNSEC_CHROOT_CHMOD
50406 + bool "Deny (f)chmod +s"
50407 + default y if GRKERNSEC_CONFIG_AUTO
50408 + depends on GRKERNSEC_CHROOT
50409 + help
50410 + If you say Y here, processes inside a chroot will not be able to chmod
50411 + or fchmod files to make them have suid or sgid bits. This protects
50412 + against another published method of breaking a chroot. If the sysctl
50413 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50414 + created.
50415 +
50416 +config GRKERNSEC_CHROOT_FCHDIR
50417 + bool "Deny fchdir out of chroot"
50418 + default y if GRKERNSEC_CONFIG_AUTO
50419 + depends on GRKERNSEC_CHROOT
50420 + help
50421 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50422 + to a file descriptor of the chrooting process that points to a directory
50423 + outside the filesystem will be stopped. If the sysctl option
50424 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50425 +
50426 +config GRKERNSEC_CHROOT_MKNOD
50427 + bool "Deny mknod"
50428 + default y if GRKERNSEC_CONFIG_AUTO
50429 + depends on GRKERNSEC_CHROOT
50430 + help
50431 + If you say Y here, processes inside a chroot will not be allowed to
50432 + mknod. The problem with using mknod inside a chroot is that it
50433 + would allow an attacker to create a device entry that is the same
50434 + as one on the physical root of your system, which could range from
50435 + anything from the console device to a device for your harddrive (which
50436 + they could then use to wipe the drive or steal data). It is recommended
50437 + that you say Y here, unless you run into software incompatibilities.
50438 + If the sysctl option is enabled, a sysctl option with name
50439 + "chroot_deny_mknod" is created.
50440 +
50441 +config GRKERNSEC_CHROOT_SHMAT
50442 + bool "Deny shmat() out of chroot"
50443 + default y if GRKERNSEC_CONFIG_AUTO
50444 + depends on GRKERNSEC_CHROOT
50445 + help
50446 + If you say Y here, processes inside a chroot will not be able to attach
50447 + to shared memory segments that were created outside of the chroot jail.
50448 + It is recommended that you say Y here. If the sysctl option is enabled,
50449 + a sysctl option with name "chroot_deny_shmat" is created.
50450 +
50451 +config GRKERNSEC_CHROOT_UNIX
50452 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50453 + default y if GRKERNSEC_CONFIG_AUTO
50454 + depends on GRKERNSEC_CHROOT
50455 + help
50456 + If you say Y here, processes inside a chroot will not be able to
50457 + connect to abstract (meaning not belonging to a filesystem) Unix
50458 + domain sockets that were bound outside of a chroot. It is recommended
50459 + that you say Y here. If the sysctl option is enabled, a sysctl option
50460 + with name "chroot_deny_unix" is created.
50461 +
50462 +config GRKERNSEC_CHROOT_FINDTASK
50463 + bool "Protect outside processes"
50464 + default y if GRKERNSEC_CONFIG_AUTO
50465 + depends on GRKERNSEC_CHROOT
50466 + help
50467 + If you say Y here, processes inside a chroot will not be able to
50468 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50469 + getsid, or view any process outside of the chroot. If the sysctl
50470 + option is enabled, a sysctl option with name "chroot_findtask" is
50471 + created.
50472 +
50473 +config GRKERNSEC_CHROOT_NICE
50474 + bool "Restrict priority changes"
50475 + default y if GRKERNSEC_CONFIG_AUTO
50476 + depends on GRKERNSEC_CHROOT
50477 + help
50478 + If you say Y here, processes inside a chroot will not be able to raise
50479 + the priority of processes in the chroot, or alter the priority of
50480 + processes outside the chroot. This provides more security than simply
50481 + removing CAP_SYS_NICE from the process' capability set. If the
50482 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50483 + is created.
50484 +
50485 +config GRKERNSEC_CHROOT_SYSCTL
50486 + bool "Deny sysctl writes"
50487 + default y if GRKERNSEC_CONFIG_AUTO
50488 + depends on GRKERNSEC_CHROOT
50489 + help
50490 + If you say Y here, an attacker in a chroot will not be able to
50491 + write to sysctl entries, either by sysctl(2) or through a /proc
50492 + interface. It is strongly recommended that you say Y here. If the
50493 + sysctl option is enabled, a sysctl option with name
50494 + "chroot_deny_sysctl" is created.
50495 +
50496 +config GRKERNSEC_CHROOT_CAPS
50497 + bool "Capability restrictions"
50498 + default y if GRKERNSEC_CONFIG_AUTO
50499 + depends on GRKERNSEC_CHROOT
50500 + help
50501 + If you say Y here, the capabilities on all processes within a
50502 + chroot jail will be lowered to stop module insertion, raw i/o,
50503 + system and net admin tasks, rebooting the system, modifying immutable
50504 + files, modifying IPC owned by another, and changing the system time.
50505 + This is left an option because it can break some apps. Disable this
50506 + if your chrooted apps are having problems performing those kinds of
50507 + tasks. If the sysctl option is enabled, a sysctl option with
50508 + name "chroot_caps" is created.
50509 +
50510 +endmenu
50511 +menu "Kernel Auditing"
50512 +depends on GRKERNSEC
50513 +
50514 +config GRKERNSEC_AUDIT_GROUP
50515 + bool "Single group for auditing"
50516 + help
50517 + If you say Y here, the exec, chdir, and (un)mount logging features
50518 + will only operate on a group you specify. This option is recommended
50519 + if you only want to watch certain users instead of having a large
50520 + amount of logs from the entire system. If the sysctl option is enabled,
50521 + a sysctl option with name "audit_group" is created.
50522 +
50523 +config GRKERNSEC_AUDIT_GID
50524 + int "GID for auditing"
50525 + depends on GRKERNSEC_AUDIT_GROUP
50526 + default 1007
50527 +
50528 +config GRKERNSEC_EXECLOG
50529 + bool "Exec logging"
50530 + help
50531 + If you say Y here, all execve() calls will be logged (since the
50532 + other exec*() calls are frontends to execve(), all execution
50533 + will be logged). Useful for shell-servers that like to keep track
50534 + of their users. If the sysctl option is enabled, a sysctl option with
50535 + name "exec_logging" is created.
50536 + WARNING: This option when enabled will produce a LOT of logs, especially
50537 + on an active system.
50538 +
50539 +config GRKERNSEC_RESLOG
50540 + bool "Resource logging"
50541 + default y if GRKERNSEC_CONFIG_AUTO
50542 + help
50543 + If you say Y here, all attempts to overstep resource limits will
50544 + be logged with the resource name, the requested size, and the current
50545 + limit. It is highly recommended that you say Y here. If the sysctl
50546 + option is enabled, a sysctl option with name "resource_logging" is
50547 + created. If the RBAC system is enabled, the sysctl value is ignored.
50548 +
50549 +config GRKERNSEC_CHROOT_EXECLOG
50550 + bool "Log execs within chroot"
50551 + help
50552 + If you say Y here, all executions inside a chroot jail will be logged
50553 + to syslog. This can cause a large amount of logs if certain
50554 + applications (eg. djb's daemontools) are installed on the system, and
50555 + is therefore left as an option. If the sysctl option is enabled, a
50556 + sysctl option with name "chroot_execlog" is created.
50557 +
50558 +config GRKERNSEC_AUDIT_PTRACE
50559 + bool "Ptrace logging"
50560 + help
50561 + If you say Y here, all attempts to attach to a process via ptrace
50562 + will be logged. If the sysctl option is enabled, a sysctl option
50563 + with name "audit_ptrace" is created.
50564 +
50565 +config GRKERNSEC_AUDIT_CHDIR
50566 + bool "Chdir logging"
50567 + help
50568 + If you say Y here, all chdir() calls will be logged. If the sysctl
50569 + option is enabled, a sysctl option with name "audit_chdir" is created.
50570 +
50571 +config GRKERNSEC_AUDIT_MOUNT
50572 + bool "(Un)Mount logging"
50573 + help
50574 + If you say Y here, all mounts and unmounts will be logged. If the
50575 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50576 + created.
50577 +
50578 +config GRKERNSEC_SIGNAL
50579 + bool "Signal logging"
50580 + default y if GRKERNSEC_CONFIG_AUTO
50581 + help
50582 + If you say Y here, certain important signals will be logged, such as
50583 + SIGSEGV, which will as a result inform you of when a error in a program
50584 + occurred, which in some cases could mean a possible exploit attempt.
50585 + If the sysctl option is enabled, a sysctl option with name
50586 + "signal_logging" is created.
50587 +
50588 +config GRKERNSEC_FORKFAIL
50589 + bool "Fork failure logging"
50590 + help
50591 + If you say Y here, all failed fork() attempts will be logged.
50592 + This could suggest a fork bomb, or someone attempting to overstep
50593 + their process limit. If the sysctl option is enabled, a sysctl option
50594 + with name "forkfail_logging" is created.
50595 +
50596 +config GRKERNSEC_TIME
50597 + bool "Time change logging"
50598 + default y if GRKERNSEC_CONFIG_AUTO
50599 + help
50600 + If you say Y here, any changes of the system clock will be logged.
50601 + If the sysctl option is enabled, a sysctl option with name
50602 + "timechange_logging" is created.
50603 +
50604 +config GRKERNSEC_PROC_IPADDR
50605 + bool "/proc/<pid>/ipaddr support"
50606 + default y if GRKERNSEC_CONFIG_AUTO
50607 + help
50608 + If you say Y here, a new entry will be added to each /proc/<pid>
50609 + directory that contains the IP address of the person using the task.
50610 + The IP is carried across local TCP and AF_UNIX stream sockets.
50611 + This information can be useful for IDS/IPSes to perform remote response
50612 + to a local attack. The entry is readable by only the owner of the
50613 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50614 + the RBAC system), and thus does not create privacy concerns.
50615 +
50616 +config GRKERNSEC_RWXMAP_LOG
50617 + bool 'Denied RWX mmap/mprotect logging'
50618 + default y if GRKERNSEC_CONFIG_AUTO
50619 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50620 + help
50621 + If you say Y here, calls to mmap() and mprotect() with explicit
50622 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50623 + denied by the PAX_MPROTECT feature. If the sysctl option is
50624 + enabled, a sysctl option with name "rwxmap_logging" is created.
50625 +
50626 +config GRKERNSEC_AUDIT_TEXTREL
50627 + bool 'ELF text relocations logging (READ HELP)'
50628 + depends on PAX_MPROTECT
50629 + help
50630 + If you say Y here, text relocations will be logged with the filename
50631 + of the offending library or binary. The purpose of the feature is
50632 + to help Linux distribution developers get rid of libraries and
50633 + binaries that need text relocations which hinder the future progress
50634 + of PaX. Only Linux distribution developers should say Y here, and
50635 + never on a production machine, as this option creates an information
50636 + leak that could aid an attacker in defeating the randomization of
50637 + a single memory region. If the sysctl option is enabled, a sysctl
50638 + option with name "audit_textrel" is created.
50639 +
50640 +endmenu
50641 +
50642 +menu "Executable Protections"
50643 +depends on GRKERNSEC
50644 +
50645 +config GRKERNSEC_DMESG
50646 + bool "Dmesg(8) restriction"
50647 + default y if GRKERNSEC_CONFIG_AUTO
50648 + help
50649 + If you say Y here, non-root users will not be able to use dmesg(8)
50650 + to view up to the last 4kb of messages in the kernel's log buffer.
50651 + The kernel's log buffer often contains kernel addresses and other
50652 + identifying information useful to an attacker in fingerprinting a
50653 + system for a targeted exploit.
50654 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50655 + created.
50656 +
50657 +config GRKERNSEC_HARDEN_PTRACE
50658 + bool "Deter ptrace-based process snooping"
50659 + default y if GRKERNSEC_CONFIG_AUTO
50660 + help
50661 + If you say Y here, TTY sniffers and other malicious monitoring
50662 + programs implemented through ptrace will be defeated. If you
50663 + have been using the RBAC system, this option has already been
50664 + enabled for several years for all users, with the ability to make
50665 + fine-grained exceptions.
50666 +
50667 + This option only affects the ability of non-root users to ptrace
50668 + processes that are not a descendent of the ptracing process.
50669 + This means that strace ./binary and gdb ./binary will still work,
50670 + but attaching to arbitrary processes will not. If the sysctl
50671 + option is enabled, a sysctl option with name "harden_ptrace" is
50672 + created.
50673 +
50674 +config GRKERNSEC_PTRACE_READEXEC
50675 + bool "Require read access to ptrace sensitive binaries"
50676 + default y if GRKERNSEC_CONFIG_AUTO
50677 + help
50678 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50679 + binaries. This option is useful in environments that
50680 + remove the read bits (e.g. file mode 4711) from suid binaries to
50681 + prevent infoleaking of their contents. This option adds
50682 + consistency to the use of that file mode, as the binary could normally
50683 + be read out when run without privileges while ptracing.
50684 +
50685 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50686 + is created.
50687 +
50688 +config GRKERNSEC_SETXID
50689 + bool "Enforce consistent multithreaded privileges"
50690 + default y if GRKERNSEC_CONFIG_AUTO
50691 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50692 + help
50693 + If you say Y here, a change from a root uid to a non-root uid
50694 + in a multithreaded application will cause the resulting uids,
50695 + gids, supplementary groups, and capabilities in that thread
50696 + to be propagated to the other threads of the process. In most
50697 + cases this is unnecessary, as glibc will emulate this behavior
50698 + on behalf of the application. Other libcs do not act in the
50699 + same way, allowing the other threads of the process to continue
50700 + running with root privileges. If the sysctl option is enabled,
50701 + a sysctl option with name "consistent_setxid" is created.
50702 +
50703 +config GRKERNSEC_TPE
50704 + bool "Trusted Path Execution (TPE)"
50705 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50706 + help
50707 + If you say Y here, you will be able to choose a gid to add to the
50708 + supplementary groups of users you want to mark as "untrusted."
50709 + These users will not be able to execute any files that are not in
50710 + root-owned directories writable only by root. If the sysctl option
50711 + is enabled, a sysctl option with name "tpe" is created.
50712 +
50713 +config GRKERNSEC_TPE_ALL
50714 + bool "Partially restrict all non-root users"
50715 + depends on GRKERNSEC_TPE
50716 + help
50717 + If you say Y here, all non-root users will be covered under
50718 + a weaker TPE restriction. This is separate from, and in addition to,
50719 + the main TPE options that you have selected elsewhere. Thus, if a
50720 + "trusted" GID is chosen, this restriction applies to even that GID.
50721 + Under this restriction, all non-root users will only be allowed to
50722 + execute files in directories they own that are not group or
50723 + world-writable, or in directories owned by root and writable only by
50724 + root. If the sysctl option is enabled, a sysctl option with name
50725 + "tpe_restrict_all" is created.
50726 +
50727 +config GRKERNSEC_TPE_INVERT
50728 + bool "Invert GID option"
50729 + depends on GRKERNSEC_TPE
50730 + help
50731 + If you say Y here, the group you specify in the TPE configuration will
50732 + decide what group TPE restrictions will be *disabled* for. This
50733 + option is useful if you want TPE restrictions to be applied to most
50734 + users on the system. If the sysctl option is enabled, a sysctl option
50735 + with name "tpe_invert" is created. Unlike other sysctl options, this
50736 + entry will default to on for backward-compatibility.
50737 +
50738 +config GRKERNSEC_TPE_GID
50739 + int "GID for untrusted users"
50740 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50741 + default 1005
50742 + help
50743 + Setting this GID determines what group TPE restrictions will be
50744 + *enabled* for. If the sysctl option is enabled, a sysctl option
50745 + with name "tpe_gid" is created.
50746 +
50747 +config GRKERNSEC_TPE_GID
50748 + int "GID for trusted users"
50749 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50750 + default 1005
50751 + help
50752 + Setting this GID determines what group TPE restrictions will be
50753 + *disabled* for. If the sysctl option is enabled, a sysctl option
50754 + with name "tpe_gid" is created.
50755 +
50756 +endmenu
50757 +menu "Network Protections"
50758 +depends on GRKERNSEC
50759 +
50760 +config GRKERNSEC_RANDNET
50761 + bool "Larger entropy pools"
50762 + default y if GRKERNSEC_CONFIG_AUTO
50763 + help
50764 + If you say Y here, the entropy pools used for many features of Linux
50765 + and grsecurity will be doubled in size. Since several grsecurity
50766 + features use additional randomness, it is recommended that you say Y
50767 + here. Saying Y here has a similar effect as modifying
50768 + /proc/sys/kernel/random/poolsize.
50769 +
50770 +config GRKERNSEC_BLACKHOLE
50771 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50772 + default y if GRKERNSEC_CONFIG_AUTO
50773 + depends on NET
50774 + help
50775 + If you say Y here, neither TCP resets nor ICMP
50776 + destination-unreachable packets will be sent in response to packets
50777 + sent to ports for which no associated listening process exists.
50778 + This feature supports both IPV4 and IPV6 and exempts the
50779 + loopback interface from blackholing. Enabling this feature
50780 + makes a host more resilient to DoS attacks and reduces network
50781 + visibility against scanners.
50782 +
50783 + The blackhole feature as-implemented is equivalent to the FreeBSD
50784 + blackhole feature, as it prevents RST responses to all packets, not
50785 + just SYNs. Under most application behavior this causes no
50786 + problems, but applications (like haproxy) may not close certain
50787 + connections in a way that cleanly terminates them on the remote
50788 + end, leaving the remote host in LAST_ACK state. Because of this
50789 + side-effect and to prevent intentional LAST_ACK DoSes, this
50790 + feature also adds automatic mitigation against such attacks.
50791 + The mitigation drastically reduces the amount of time a socket
50792 + can spend in LAST_ACK state. If you're using haproxy and not
50793 + all servers it connects to have this option enabled, consider
50794 + disabling this feature on the haproxy host.
50795 +
50796 + If the sysctl option is enabled, two sysctl options with names
50797 + "ip_blackhole" and "lastack_retries" will be created.
50798 + While "ip_blackhole" takes the standard zero/non-zero on/off
50799 + toggle, "lastack_retries" uses the same kinds of values as
50800 + "tcp_retries1" and "tcp_retries2". The default value of 4
50801 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50802 + state.
50803 +
50804 +config GRKERNSEC_SOCKET
50805 + bool "Socket restrictions"
50806 + depends on NET
50807 + help
50808 + If you say Y here, you will be able to choose from several options.
50809 + If you assign a GID on your system and add it to the supplementary
50810 + groups of users you want to restrict socket access to, this patch
50811 + will perform up to three things, based on the option(s) you choose.
50812 +
50813 +config GRKERNSEC_SOCKET_ALL
50814 + bool "Deny any sockets to group"
50815 + depends on GRKERNSEC_SOCKET
50816 + help
50817 + If you say Y here, you will be able to choose a GID of whose users will
50818 + be unable to connect to other hosts from your machine or run server
50819 + applications from your machine. If the sysctl option is enabled, a
50820 + sysctl option with name "socket_all" is created.
50821 +
50822 +config GRKERNSEC_SOCKET_ALL_GID
50823 + int "GID to deny all sockets for"
50824 + depends on GRKERNSEC_SOCKET_ALL
50825 + default 1004
50826 + help
50827 + Here you can choose the GID to disable socket access for. Remember to
50828 + add the users you want socket access disabled for to the GID
50829 + specified here. If the sysctl option is enabled, a sysctl option
50830 + with name "socket_all_gid" is created.
50831 +
50832 +config GRKERNSEC_SOCKET_CLIENT
50833 + bool "Deny client sockets to group"
50834 + depends on GRKERNSEC_SOCKET
50835 + help
50836 + If you say Y here, you will be able to choose a GID of whose users will
50837 + be unable to connect to other hosts from your machine, but will be
50838 + able to run servers. If this option is enabled, all users in the group
50839 + you specify will have to use passive mode when initiating ftp transfers
50840 + from the shell on your machine. If the sysctl option is enabled, a
50841 + sysctl option with name "socket_client" is created.
50842 +
50843 +config GRKERNSEC_SOCKET_CLIENT_GID
50844 + int "GID to deny client sockets for"
50845 + depends on GRKERNSEC_SOCKET_CLIENT
50846 + default 1003
50847 + help
50848 + Here you can choose the GID to disable client socket access for.
50849 + Remember to add the users you want client socket access disabled for to
50850 + the GID specified here. If the sysctl option is enabled, a sysctl
50851 + option with name "socket_client_gid" is created.
50852 +
50853 +config GRKERNSEC_SOCKET_SERVER
50854 + bool "Deny server sockets to group"
50855 + depends on GRKERNSEC_SOCKET
50856 + help
50857 + If you say Y here, you will be able to choose a GID of whose users will
50858 + be unable to run server applications from your machine. If the sysctl
50859 + option is enabled, a sysctl option with name "socket_server" is created.
50860 +
50861 +config GRKERNSEC_SOCKET_SERVER_GID
50862 + int "GID to deny server sockets for"
50863 + depends on GRKERNSEC_SOCKET_SERVER
50864 + default 1002
50865 + help
50866 + Here you can choose the GID to disable server socket access for.
50867 + Remember to add the users you want server socket access disabled for to
50868 + the GID specified here. If the sysctl option is enabled, a sysctl
50869 + option with name "socket_server_gid" is created.
50870 +
50871 +endmenu
50872 +menu "Sysctl Support"
50873 +depends on GRKERNSEC && SYSCTL
50874 +
50875 +config GRKERNSEC_SYSCTL
50876 + bool "Sysctl support"
50877 + default y if GRKERNSEC_CONFIG_AUTO
50878 + help
50879 + If you say Y here, you will be able to change the options that
50880 + grsecurity runs with at bootup, without having to recompile your
50881 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50882 + to enable (1) or disable (0) various features. All the sysctl entries
50883 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50884 + All features enabled in the kernel configuration are disabled at boot
50885 + if you do not say Y to the "Turn on features by default" option.
50886 + All options should be set at startup, and the grsec_lock entry should
50887 + be set to a non-zero value after all the options are set.
50888 + *THIS IS EXTREMELY IMPORTANT*
50889 +
50890 +config GRKERNSEC_SYSCTL_DISTRO
50891 + bool "Extra sysctl support for distro makers (READ HELP)"
50892 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50893 + help
50894 + If you say Y here, additional sysctl options will be created
50895 + for features that affect processes running as root. Therefore,
50896 + it is critical when using this option that the grsec_lock entry be
50897 + enabled after boot. Only distros with prebuilt kernel packages
50898 + with this option enabled that can ensure grsec_lock is enabled
50899 + after boot should use this option.
50900 + *Failure to set grsec_lock after boot makes all grsec features
50901 + this option covers useless*
50902 +
50903 + Currently this option creates the following sysctl entries:
50904 + "Disable Privileged I/O": "disable_priv_io"
50905 +
50906 +config GRKERNSEC_SYSCTL_ON
50907 + bool "Turn on features by default"
50908 + default y if GRKERNSEC_CONFIG_AUTO
50909 + depends on GRKERNSEC_SYSCTL
50910 + help
50911 + If you say Y here, instead of having all features enabled in the
50912 + kernel configuration disabled at boot time, the features will be
50913 + enabled at boot time. It is recommended you say Y here unless
50914 + there is some reason you would want all sysctl-tunable features to
50915 + be disabled by default. As mentioned elsewhere, it is important
50916 + to enable the grsec_lock entry once you have finished modifying
50917 + the sysctl entries.
50918 +
50919 +endmenu
50920 +menu "Logging Options"
50921 +depends on GRKERNSEC
50922 +
50923 +config GRKERNSEC_FLOODTIME
50924 + int "Seconds in between log messages (minimum)"
50925 + default 10
50926 + help
50927 + This option allows you to enforce the number of seconds between
50928 + grsecurity log messages. The default should be suitable for most
50929 + people, however, if you choose to change it, choose a value small enough
50930 + to allow informative logs to be produced, but large enough to
50931 + prevent flooding.
50932 +
50933 +config GRKERNSEC_FLOODBURST
50934 + int "Number of messages in a burst (maximum)"
50935 + default 6
50936 + help
50937 + This option allows you to choose the maximum number of messages allowed
50938 + within the flood time interval you chose in a separate option. The
50939 + default should be suitable for most people, however if you find that
50940 + many of your logs are being interpreted as flooding, you may want to
50941 + raise this value.
50942 +
50943 +endmenu
50944 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50945 new file mode 100644
50946 index 0000000..1b9afa9
50947 --- /dev/null
50948 +++ b/grsecurity/Makefile
50949 @@ -0,0 +1,38 @@
50950 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50951 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50952 +# into an RBAC system
50953 +#
50954 +# All code in this directory and various hooks inserted throughout the kernel
50955 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50956 +# under the GPL v2 or higher
50957 +
50958 +KBUILD_CFLAGS += -Werror
50959 +
50960 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50961 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50962 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50963 +
50964 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50965 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50966 + gracl_learn.o grsec_log.o
50967 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50968 +
50969 +ifdef CONFIG_NET
50970 +obj-y += grsec_sock.o
50971 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50972 +endif
50973 +
50974 +ifndef CONFIG_GRKERNSEC
50975 +obj-y += grsec_disabled.o
50976 +endif
50977 +
50978 +ifdef CONFIG_GRKERNSEC_HIDESYM
50979 +extra-y := grsec_hidesym.o
50980 +$(obj)/grsec_hidesym.o:
50981 + @-chmod -f 500 /boot
50982 + @-chmod -f 500 /lib/modules
50983 + @-chmod -f 500 /lib64/modules
50984 + @-chmod -f 500 /lib32/modules
50985 + @-chmod -f 700 .
50986 + @echo ' grsec: protected kernel image paths'
50987 +endif
50988 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50989 new file mode 100644
50990 index 0000000..bda2a91
50991 --- /dev/null
50992 +++ b/grsecurity/gracl.c
50993 @@ -0,0 +1,4017 @@
50994 +#include <linux/kernel.h>
50995 +#include <linux/module.h>
50996 +#include <linux/sched.h>
50997 +#include <linux/mm.h>
50998 +#include <linux/file.h>
50999 +#include <linux/fs.h>
51000 +#include <linux/namei.h>
51001 +#include <linux/mount.h>
51002 +#include <linux/tty.h>
51003 +#include <linux/proc_fs.h>
51004 +#include <linux/lglock.h>
51005 +#include <linux/slab.h>
51006 +#include <linux/vmalloc.h>
51007 +#include <linux/types.h>
51008 +#include <linux/sysctl.h>
51009 +#include <linux/netdevice.h>
51010 +#include <linux/ptrace.h>
51011 +#include <linux/gracl.h>
51012 +#include <linux/gralloc.h>
51013 +#include <linux/security.h>
51014 +#include <linux/grinternal.h>
51015 +#include <linux/pid_namespace.h>
51016 +#include <linux/stop_machine.h>
51017 +#include <linux/fdtable.h>
51018 +#include <linux/percpu.h>
51019 +#include <linux/lglock.h>
51020 +#include "../fs/mount.h"
51021 +
51022 +#include <asm/uaccess.h>
51023 +#include <asm/errno.h>
51024 +#include <asm/mman.h>
51025 +
51026 +extern struct lglock vfsmount_lock;
51027 +
51028 +static struct acl_role_db acl_role_set;
51029 +static struct name_db name_set;
51030 +static struct inodev_db inodev_set;
51031 +
51032 +/* for keeping track of userspace pointers used for subjects, so we
51033 + can share references in the kernel as well
51034 +*/
51035 +
51036 +static struct path real_root;
51037 +
51038 +static struct acl_subj_map_db subj_map_set;
51039 +
51040 +static struct acl_role_label *default_role;
51041 +
51042 +static struct acl_role_label *role_list;
51043 +
51044 +static u16 acl_sp_role_value;
51045 +
51046 +extern char *gr_shared_page[4];
51047 +static DEFINE_MUTEX(gr_dev_mutex);
51048 +DEFINE_RWLOCK(gr_inode_lock);
51049 +
51050 +struct gr_arg *gr_usermode;
51051 +
51052 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51053 +
51054 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51055 +extern void gr_clear_learn_entries(void);
51056 +
51057 +#ifdef CONFIG_GRKERNSEC_RESLOG
51058 +extern void gr_log_resource(const struct task_struct *task,
51059 + const int res, const unsigned long wanted, const int gt);
51060 +#endif
51061 +
51062 +unsigned char *gr_system_salt;
51063 +unsigned char *gr_system_sum;
51064 +
51065 +static struct sprole_pw **acl_special_roles = NULL;
51066 +static __u16 num_sprole_pws = 0;
51067 +
51068 +static struct acl_role_label *kernel_role = NULL;
51069 +
51070 +static unsigned int gr_auth_attempts = 0;
51071 +static unsigned long gr_auth_expires = 0UL;
51072 +
51073 +#ifdef CONFIG_NET
51074 +extern struct vfsmount *sock_mnt;
51075 +#endif
51076 +
51077 +extern struct vfsmount *pipe_mnt;
51078 +extern struct vfsmount *shm_mnt;
51079 +#ifdef CONFIG_HUGETLBFS
51080 +extern struct vfsmount *hugetlbfs_vfsmount;
51081 +#endif
51082 +
51083 +static struct acl_object_label *fakefs_obj_rw;
51084 +static struct acl_object_label *fakefs_obj_rwx;
51085 +
51086 +extern int gr_init_uidset(void);
51087 +extern void gr_free_uidset(void);
51088 +extern void gr_remove_uid(uid_t uid);
51089 +extern int gr_find_uid(uid_t uid);
51090 +
51091 +__inline__ int
51092 +gr_acl_is_enabled(void)
51093 +{
51094 + return (gr_status & GR_READY);
51095 +}
51096 +
51097 +#ifdef CONFIG_BTRFS_FS
51098 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51099 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51100 +#endif
51101 +
51102 +static inline dev_t __get_dev(const struct dentry *dentry)
51103 +{
51104 +#ifdef CONFIG_BTRFS_FS
51105 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51106 + return get_btrfs_dev_from_inode(dentry->d_inode);
51107 + else
51108 +#endif
51109 + return dentry->d_inode->i_sb->s_dev;
51110 +}
51111 +
51112 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51113 +{
51114 + return __get_dev(dentry);
51115 +}
51116 +
51117 +static char gr_task_roletype_to_char(struct task_struct *task)
51118 +{
51119 + switch (task->role->roletype &
51120 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51121 + GR_ROLE_SPECIAL)) {
51122 + case GR_ROLE_DEFAULT:
51123 + return 'D';
51124 + case GR_ROLE_USER:
51125 + return 'U';
51126 + case GR_ROLE_GROUP:
51127 + return 'G';
51128 + case GR_ROLE_SPECIAL:
51129 + return 'S';
51130 + }
51131 +
51132 + return 'X';
51133 +}
51134 +
51135 +char gr_roletype_to_char(void)
51136 +{
51137 + return gr_task_roletype_to_char(current);
51138 +}
51139 +
51140 +__inline__ int
51141 +gr_acl_tpe_check(void)
51142 +{
51143 + if (unlikely(!(gr_status & GR_READY)))
51144 + return 0;
51145 + if (current->role->roletype & GR_ROLE_TPE)
51146 + return 1;
51147 + else
51148 + return 0;
51149 +}
51150 +
51151 +int
51152 +gr_handle_rawio(const struct inode *inode)
51153 +{
51154 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51155 + if (inode && S_ISBLK(inode->i_mode) &&
51156 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51157 + !capable(CAP_SYS_RAWIO))
51158 + return 1;
51159 +#endif
51160 + return 0;
51161 +}
51162 +
51163 +static int
51164 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51165 +{
51166 + if (likely(lena != lenb))
51167 + return 0;
51168 +
51169 + return !memcmp(a, b, lena);
51170 +}
51171 +
51172 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51173 +{
51174 + *buflen -= namelen;
51175 + if (*buflen < 0)
51176 + return -ENAMETOOLONG;
51177 + *buffer -= namelen;
51178 + memcpy(*buffer, str, namelen);
51179 + return 0;
51180 +}
51181 +
51182 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51183 +{
51184 + return prepend(buffer, buflen, name->name, name->len);
51185 +}
51186 +
51187 +static int prepend_path(const struct path *path, struct path *root,
51188 + char **buffer, int *buflen)
51189 +{
51190 + struct dentry *dentry = path->dentry;
51191 + struct vfsmount *vfsmnt = path->mnt;
51192 + struct mount *mnt = real_mount(vfsmnt);
51193 + bool slash = false;
51194 + int error = 0;
51195 +
51196 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51197 + struct dentry * parent;
51198 +
51199 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51200 + /* Global root? */
51201 + if (!mnt_has_parent(mnt)) {
51202 + goto out;
51203 + }
51204 + dentry = mnt->mnt_mountpoint;
51205 + mnt = mnt->mnt_parent;
51206 + vfsmnt = &mnt->mnt;
51207 + continue;
51208 + }
51209 + parent = dentry->d_parent;
51210 + prefetch(parent);
51211 + spin_lock(&dentry->d_lock);
51212 + error = prepend_name(buffer, buflen, &dentry->d_name);
51213 + spin_unlock(&dentry->d_lock);
51214 + if (!error)
51215 + error = prepend(buffer, buflen, "/", 1);
51216 + if (error)
51217 + break;
51218 +
51219 + slash = true;
51220 + dentry = parent;
51221 + }
51222 +
51223 +out:
51224 + if (!error && !slash)
51225 + error = prepend(buffer, buflen, "/", 1);
51226 +
51227 + return error;
51228 +}
51229 +
51230 +/* this must be called with vfsmount_lock and rename_lock held */
51231 +
51232 +static char *__our_d_path(const struct path *path, struct path *root,
51233 + char *buf, int buflen)
51234 +{
51235 + char *res = buf + buflen;
51236 + int error;
51237 +
51238 + prepend(&res, &buflen, "\0", 1);
51239 + error = prepend_path(path, root, &res, &buflen);
51240 + if (error)
51241 + return ERR_PTR(error);
51242 +
51243 + return res;
51244 +}
51245 +
51246 +static char *
51247 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51248 +{
51249 + char *retval;
51250 +
51251 + retval = __our_d_path(path, root, buf, buflen);
51252 + if (unlikely(IS_ERR(retval)))
51253 + retval = strcpy(buf, "<path too long>");
51254 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51255 + retval[1] = '\0';
51256 +
51257 + return retval;
51258 +}
51259 +
51260 +static char *
51261 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51262 + char *buf, int buflen)
51263 +{
51264 + struct path path;
51265 + char *res;
51266 +
51267 + path.dentry = (struct dentry *)dentry;
51268 + path.mnt = (struct vfsmount *)vfsmnt;
51269 +
51270 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51271 + by the RBAC system */
51272 + res = gen_full_path(&path, &real_root, buf, buflen);
51273 +
51274 + return res;
51275 +}
51276 +
51277 +static char *
51278 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51279 + char *buf, int buflen)
51280 +{
51281 + char *res;
51282 + struct path path;
51283 + struct path root;
51284 + struct task_struct *reaper = init_pid_ns.child_reaper;
51285 +
51286 + path.dentry = (struct dentry *)dentry;
51287 + path.mnt = (struct vfsmount *)vfsmnt;
51288 +
51289 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51290 + get_fs_root(reaper->fs, &root);
51291 +
51292 + write_seqlock(&rename_lock);
51293 + br_read_lock(&vfsmount_lock);
51294 + res = gen_full_path(&path, &root, buf, buflen);
51295 + br_read_unlock(&vfsmount_lock);
51296 + write_sequnlock(&rename_lock);
51297 +
51298 + path_put(&root);
51299 + return res;
51300 +}
51301 +
51302 +static char *
51303 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51304 +{
51305 + char *ret;
51306 + write_seqlock(&rename_lock);
51307 + br_read_lock(&vfsmount_lock);
51308 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51309 + PAGE_SIZE);
51310 + br_read_unlock(&vfsmount_lock);
51311 + write_sequnlock(&rename_lock);
51312 + return ret;
51313 +}
51314 +
51315 +static char *
51316 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51317 +{
51318 + char *ret;
51319 + char *buf;
51320 + int buflen;
51321 +
51322 + write_seqlock(&rename_lock);
51323 + br_read_lock(&vfsmount_lock);
51324 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51325 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51326 + buflen = (int)(ret - buf);
51327 + if (buflen >= 5)
51328 + prepend(&ret, &buflen, "/proc", 5);
51329 + else
51330 + ret = strcpy(buf, "<path too long>");
51331 + br_read_unlock(&vfsmount_lock);
51332 + write_sequnlock(&rename_lock);
51333 + return ret;
51334 +}
51335 +
51336 +char *
51337 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51338 +{
51339 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51340 + PAGE_SIZE);
51341 +}
51342 +
51343 +char *
51344 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51345 +{
51346 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51347 + PAGE_SIZE);
51348 +}
51349 +
51350 +char *
51351 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51352 +{
51353 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51354 + PAGE_SIZE);
51355 +}
51356 +
51357 +char *
51358 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51359 +{
51360 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51361 + PAGE_SIZE);
51362 +}
51363 +
51364 +char *
51365 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51366 +{
51367 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51368 + PAGE_SIZE);
51369 +}
51370 +
51371 +__inline__ __u32
51372 +to_gr_audit(const __u32 reqmode)
51373 +{
51374 + /* masks off auditable permission flags, then shifts them to create
51375 + auditing flags, and adds the special case of append auditing if
51376 + we're requesting write */
51377 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51378 +}
51379 +
51380 +struct acl_subject_label *
51381 +lookup_subject_map(const struct acl_subject_label *userp)
51382 +{
51383 + unsigned int index = shash(userp, subj_map_set.s_size);
51384 + struct subject_map *match;
51385 +
51386 + match = subj_map_set.s_hash[index];
51387 +
51388 + while (match && match->user != userp)
51389 + match = match->next;
51390 +
51391 + if (match != NULL)
51392 + return match->kernel;
51393 + else
51394 + return NULL;
51395 +}
51396 +
51397 +static void
51398 +insert_subj_map_entry(struct subject_map *subjmap)
51399 +{
51400 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51401 + struct subject_map **curr;
51402 +
51403 + subjmap->prev = NULL;
51404 +
51405 + curr = &subj_map_set.s_hash[index];
51406 + if (*curr != NULL)
51407 + (*curr)->prev = subjmap;
51408 +
51409 + subjmap->next = *curr;
51410 + *curr = subjmap;
51411 +
51412 + return;
51413 +}
51414 +
51415 +static struct acl_role_label *
51416 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51417 + const gid_t gid)
51418 +{
51419 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51420 + struct acl_role_label *match;
51421 + struct role_allowed_ip *ipp;
51422 + unsigned int x;
51423 + u32 curr_ip = task->signal->curr_ip;
51424 +
51425 + task->signal->saved_ip = curr_ip;
51426 +
51427 + match = acl_role_set.r_hash[index];
51428 +
51429 + while (match) {
51430 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51431 + for (x = 0; x < match->domain_child_num; x++) {
51432 + if (match->domain_children[x] == uid)
51433 + goto found;
51434 + }
51435 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51436 + break;
51437 + match = match->next;
51438 + }
51439 +found:
51440 + if (match == NULL) {
51441 + try_group:
51442 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51443 + match = acl_role_set.r_hash[index];
51444 +
51445 + while (match) {
51446 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51447 + for (x = 0; x < match->domain_child_num; x++) {
51448 + if (match->domain_children[x] == gid)
51449 + goto found2;
51450 + }
51451 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51452 + break;
51453 + match = match->next;
51454 + }
51455 +found2:
51456 + if (match == NULL)
51457 + match = default_role;
51458 + if (match->allowed_ips == NULL)
51459 + return match;
51460 + else {
51461 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51462 + if (likely
51463 + ((ntohl(curr_ip) & ipp->netmask) ==
51464 + (ntohl(ipp->addr) & ipp->netmask)))
51465 + return match;
51466 + }
51467 + match = default_role;
51468 + }
51469 + } else if (match->allowed_ips == NULL) {
51470 + return match;
51471 + } else {
51472 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51473 + if (likely
51474 + ((ntohl(curr_ip) & ipp->netmask) ==
51475 + (ntohl(ipp->addr) & ipp->netmask)))
51476 + return match;
51477 + }
51478 + goto try_group;
51479 + }
51480 +
51481 + return match;
51482 +}
51483 +
51484 +struct acl_subject_label *
51485 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51486 + const struct acl_role_label *role)
51487 +{
51488 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51489 + struct acl_subject_label *match;
51490 +
51491 + match = role->subj_hash[index];
51492 +
51493 + while (match && (match->inode != ino || match->device != dev ||
51494 + (match->mode & GR_DELETED))) {
51495 + match = match->next;
51496 + }
51497 +
51498 + if (match && !(match->mode & GR_DELETED))
51499 + return match;
51500 + else
51501 + return NULL;
51502 +}
51503 +
51504 +struct acl_subject_label *
51505 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51506 + const struct acl_role_label *role)
51507 +{
51508 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51509 + struct acl_subject_label *match;
51510 +
51511 + match = role->subj_hash[index];
51512 +
51513 + while (match && (match->inode != ino || match->device != dev ||
51514 + !(match->mode & GR_DELETED))) {
51515 + match = match->next;
51516 + }
51517 +
51518 + if (match && (match->mode & GR_DELETED))
51519 + return match;
51520 + else
51521 + return NULL;
51522 +}
51523 +
51524 +static struct acl_object_label *
51525 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51526 + const struct acl_subject_label *subj)
51527 +{
51528 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51529 + struct acl_object_label *match;
51530 +
51531 + match = subj->obj_hash[index];
51532 +
51533 + while (match && (match->inode != ino || match->device != dev ||
51534 + (match->mode & GR_DELETED))) {
51535 + match = match->next;
51536 + }
51537 +
51538 + if (match && !(match->mode & GR_DELETED))
51539 + return match;
51540 + else
51541 + return NULL;
51542 +}
51543 +
51544 +static struct acl_object_label *
51545 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51546 + const struct acl_subject_label *subj)
51547 +{
51548 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51549 + struct acl_object_label *match;
51550 +
51551 + match = subj->obj_hash[index];
51552 +
51553 + while (match && (match->inode != ino || match->device != dev ||
51554 + !(match->mode & GR_DELETED))) {
51555 + match = match->next;
51556 + }
51557 +
51558 + if (match && (match->mode & GR_DELETED))
51559 + return match;
51560 +
51561 + match = subj->obj_hash[index];
51562 +
51563 + while (match && (match->inode != ino || match->device != dev ||
51564 + (match->mode & GR_DELETED))) {
51565 + match = match->next;
51566 + }
51567 +
51568 + if (match && !(match->mode & GR_DELETED))
51569 + return match;
51570 + else
51571 + return NULL;
51572 +}
51573 +
51574 +static struct name_entry *
51575 +lookup_name_entry(const char *name)
51576 +{
51577 + unsigned int len = strlen(name);
51578 + unsigned int key = full_name_hash(name, len);
51579 + unsigned int index = key % name_set.n_size;
51580 + struct name_entry *match;
51581 +
51582 + match = name_set.n_hash[index];
51583 +
51584 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51585 + match = match->next;
51586 +
51587 + return match;
51588 +}
51589 +
51590 +static struct name_entry *
51591 +lookup_name_entry_create(const char *name)
51592 +{
51593 + unsigned int len = strlen(name);
51594 + unsigned int key = full_name_hash(name, len);
51595 + unsigned int index = key % name_set.n_size;
51596 + struct name_entry *match;
51597 +
51598 + match = name_set.n_hash[index];
51599 +
51600 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51601 + !match->deleted))
51602 + match = match->next;
51603 +
51604 + if (match && match->deleted)
51605 + return match;
51606 +
51607 + match = name_set.n_hash[index];
51608 +
51609 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51610 + match->deleted))
51611 + match = match->next;
51612 +
51613 + if (match && !match->deleted)
51614 + return match;
51615 + else
51616 + return NULL;
51617 +}
51618 +
51619 +static struct inodev_entry *
51620 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51621 +{
51622 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51623 + struct inodev_entry *match;
51624 +
51625 + match = inodev_set.i_hash[index];
51626 +
51627 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51628 + match = match->next;
51629 +
51630 + return match;
51631 +}
51632 +
51633 +static void
51634 +insert_inodev_entry(struct inodev_entry *entry)
51635 +{
51636 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51637 + inodev_set.i_size);
51638 + struct inodev_entry **curr;
51639 +
51640 + entry->prev = NULL;
51641 +
51642 + curr = &inodev_set.i_hash[index];
51643 + if (*curr != NULL)
51644 + (*curr)->prev = entry;
51645 +
51646 + entry->next = *curr;
51647 + *curr = entry;
51648 +
51649 + return;
51650 +}
51651 +
51652 +static void
51653 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51654 +{
51655 + unsigned int index =
51656 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51657 + struct acl_role_label **curr;
51658 + struct acl_role_label *tmp, *tmp2;
51659 +
51660 + curr = &acl_role_set.r_hash[index];
51661 +
51662 + /* simple case, slot is empty, just set it to our role */
51663 + if (*curr == NULL) {
51664 + *curr = role;
51665 + } else {
51666 + /* example:
51667 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51668 + 2 -> 3
51669 + */
51670 + /* first check to see if we can already be reached via this slot */
51671 + tmp = *curr;
51672 + while (tmp && tmp != role)
51673 + tmp = tmp->next;
51674 + if (tmp == role) {
51675 + /* we don't need to add ourselves to this slot's chain */
51676 + return;
51677 + }
51678 + /* we need to add ourselves to this chain, two cases */
51679 + if (role->next == NULL) {
51680 + /* simple case, append the current chain to our role */
51681 + role->next = *curr;
51682 + *curr = role;
51683 + } else {
51684 + /* 1 -> 2 -> 3 -> 4
51685 + 2 -> 3 -> 4
51686 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51687 + */
51688 + /* trickier case: walk our role's chain until we find
51689 + the role for the start of the current slot's chain */
51690 + tmp = role;
51691 + tmp2 = *curr;
51692 + while (tmp->next && tmp->next != tmp2)
51693 + tmp = tmp->next;
51694 + if (tmp->next == tmp2) {
51695 + /* from example above, we found 3, so just
51696 + replace this slot's chain with ours */
51697 + *curr = role;
51698 + } else {
51699 + /* we didn't find a subset of our role's chain
51700 + in the current slot's chain, so append their
51701 + chain to ours, and set us as the first role in
51702 + the slot's chain
51703 +
51704 + we could fold this case with the case above,
51705 + but making it explicit for clarity
51706 + */
51707 + tmp->next = tmp2;
51708 + *curr = role;
51709 + }
51710 + }
51711 + }
51712 +
51713 + return;
51714 +}
51715 +
51716 +static void
51717 +insert_acl_role_label(struct acl_role_label *role)
51718 +{
51719 + int i;
51720 +
51721 + if (role_list == NULL) {
51722 + role_list = role;
51723 + role->prev = NULL;
51724 + } else {
51725 + role->prev = role_list;
51726 + role_list = role;
51727 + }
51728 +
51729 + /* used for hash chains */
51730 + role->next = NULL;
51731 +
51732 + if (role->roletype & GR_ROLE_DOMAIN) {
51733 + for (i = 0; i < role->domain_child_num; i++)
51734 + __insert_acl_role_label(role, role->domain_children[i]);
51735 + } else
51736 + __insert_acl_role_label(role, role->uidgid);
51737 +}
51738 +
51739 +static int
51740 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51741 +{
51742 + struct name_entry **curr, *nentry;
51743 + struct inodev_entry *ientry;
51744 + unsigned int len = strlen(name);
51745 + unsigned int key = full_name_hash(name, len);
51746 + unsigned int index = key % name_set.n_size;
51747 +
51748 + curr = &name_set.n_hash[index];
51749 +
51750 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51751 + curr = &((*curr)->next);
51752 +
51753 + if (*curr != NULL)
51754 + return 1;
51755 +
51756 + nentry = acl_alloc(sizeof (struct name_entry));
51757 + if (nentry == NULL)
51758 + return 0;
51759 + ientry = acl_alloc(sizeof (struct inodev_entry));
51760 + if (ientry == NULL)
51761 + return 0;
51762 + ientry->nentry = nentry;
51763 +
51764 + nentry->key = key;
51765 + nentry->name = name;
51766 + nentry->inode = inode;
51767 + nentry->device = device;
51768 + nentry->len = len;
51769 + nentry->deleted = deleted;
51770 +
51771 + nentry->prev = NULL;
51772 + curr = &name_set.n_hash[index];
51773 + if (*curr != NULL)
51774 + (*curr)->prev = nentry;
51775 + nentry->next = *curr;
51776 + *curr = nentry;
51777 +
51778 + /* insert us into the table searchable by inode/dev */
51779 + insert_inodev_entry(ientry);
51780 +
51781 + return 1;
51782 +}
51783 +
51784 +static void
51785 +insert_acl_obj_label(struct acl_object_label *obj,
51786 + struct acl_subject_label *subj)
51787 +{
51788 + unsigned int index =
51789 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51790 + struct acl_object_label **curr;
51791 +
51792 +
51793 + obj->prev = NULL;
51794 +
51795 + curr = &subj->obj_hash[index];
51796 + if (*curr != NULL)
51797 + (*curr)->prev = obj;
51798 +
51799 + obj->next = *curr;
51800 + *curr = obj;
51801 +
51802 + return;
51803 +}
51804 +
51805 +static void
51806 +insert_acl_subj_label(struct acl_subject_label *obj,
51807 + struct acl_role_label *role)
51808 +{
51809 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51810 + struct acl_subject_label **curr;
51811 +
51812 + obj->prev = NULL;
51813 +
51814 + curr = &role->subj_hash[index];
51815 + if (*curr != NULL)
51816 + (*curr)->prev = obj;
51817 +
51818 + obj->next = *curr;
51819 + *curr = obj;
51820 +
51821 + return;
51822 +}
51823 +
51824 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51825 +
51826 +static void *
51827 +create_table(__u32 * len, int elementsize)
51828 +{
51829 + unsigned int table_sizes[] = {
51830 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51831 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51832 + 4194301, 8388593, 16777213, 33554393, 67108859
51833 + };
51834 + void *newtable = NULL;
51835 + unsigned int pwr = 0;
51836 +
51837 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51838 + table_sizes[pwr] <= *len)
51839 + pwr++;
51840 +
51841 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51842 + return newtable;
51843 +
51844 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51845 + newtable =
51846 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51847 + else
51848 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51849 +
51850 + *len = table_sizes[pwr];
51851 +
51852 + return newtable;
51853 +}
51854 +
51855 +static int
51856 +init_variables(const struct gr_arg *arg)
51857 +{
51858 + struct task_struct *reaper = init_pid_ns.child_reaper;
51859 + unsigned int stacksize;
51860 +
51861 + subj_map_set.s_size = arg->role_db.num_subjects;
51862 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51863 + name_set.n_size = arg->role_db.num_objects;
51864 + inodev_set.i_size = arg->role_db.num_objects;
51865 +
51866 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51867 + !name_set.n_size || !inodev_set.i_size)
51868 + return 1;
51869 +
51870 + if (!gr_init_uidset())
51871 + return 1;
51872 +
51873 + /* set up the stack that holds allocation info */
51874 +
51875 + stacksize = arg->role_db.num_pointers + 5;
51876 +
51877 + if (!acl_alloc_stack_init(stacksize))
51878 + return 1;
51879 +
51880 + /* grab reference for the real root dentry and vfsmount */
51881 + get_fs_root(reaper->fs, &real_root);
51882 +
51883 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51884 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51885 +#endif
51886 +
51887 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51888 + if (fakefs_obj_rw == NULL)
51889 + return 1;
51890 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51891 +
51892 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51893 + if (fakefs_obj_rwx == NULL)
51894 + return 1;
51895 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51896 +
51897 + subj_map_set.s_hash =
51898 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51899 + acl_role_set.r_hash =
51900 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51901 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51902 + inodev_set.i_hash =
51903 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51904 +
51905 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51906 + !name_set.n_hash || !inodev_set.i_hash)
51907 + return 1;
51908 +
51909 + memset(subj_map_set.s_hash, 0,
51910 + sizeof(struct subject_map *) * subj_map_set.s_size);
51911 + memset(acl_role_set.r_hash, 0,
51912 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51913 + memset(name_set.n_hash, 0,
51914 + sizeof (struct name_entry *) * name_set.n_size);
51915 + memset(inodev_set.i_hash, 0,
51916 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51917 +
51918 + return 0;
51919 +}
51920 +
51921 +/* free information not needed after startup
51922 + currently contains user->kernel pointer mappings for subjects
51923 +*/
51924 +
51925 +static void
51926 +free_init_variables(void)
51927 +{
51928 + __u32 i;
51929 +
51930 + if (subj_map_set.s_hash) {
51931 + for (i = 0; i < subj_map_set.s_size; i++) {
51932 + if (subj_map_set.s_hash[i]) {
51933 + kfree(subj_map_set.s_hash[i]);
51934 + subj_map_set.s_hash[i] = NULL;
51935 + }
51936 + }
51937 +
51938 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51939 + PAGE_SIZE)
51940 + kfree(subj_map_set.s_hash);
51941 + else
51942 + vfree(subj_map_set.s_hash);
51943 + }
51944 +
51945 + return;
51946 +}
51947 +
51948 +static void
51949 +free_variables(void)
51950 +{
51951 + struct acl_subject_label *s;
51952 + struct acl_role_label *r;
51953 + struct task_struct *task, *task2;
51954 + unsigned int x;
51955 +
51956 + gr_clear_learn_entries();
51957 +
51958 + read_lock(&tasklist_lock);
51959 + do_each_thread(task2, task) {
51960 + task->acl_sp_role = 0;
51961 + task->acl_role_id = 0;
51962 + task->acl = NULL;
51963 + task->role = NULL;
51964 + } while_each_thread(task2, task);
51965 + read_unlock(&tasklist_lock);
51966 +
51967 + /* release the reference to the real root dentry and vfsmount */
51968 + path_put(&real_root);
51969 + memset(&real_root, 0, sizeof(real_root));
51970 +
51971 + /* free all object hash tables */
51972 +
51973 + FOR_EACH_ROLE_START(r)
51974 + if (r->subj_hash == NULL)
51975 + goto next_role;
51976 + FOR_EACH_SUBJECT_START(r, s, x)
51977 + if (s->obj_hash == NULL)
51978 + break;
51979 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51980 + kfree(s->obj_hash);
51981 + else
51982 + vfree(s->obj_hash);
51983 + FOR_EACH_SUBJECT_END(s, x)
51984 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51985 + if (s->obj_hash == NULL)
51986 + break;
51987 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51988 + kfree(s->obj_hash);
51989 + else
51990 + vfree(s->obj_hash);
51991 + FOR_EACH_NESTED_SUBJECT_END(s)
51992 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51993 + kfree(r->subj_hash);
51994 + else
51995 + vfree(r->subj_hash);
51996 + r->subj_hash = NULL;
51997 +next_role:
51998 + FOR_EACH_ROLE_END(r)
51999 +
52000 + acl_free_all();
52001 +
52002 + if (acl_role_set.r_hash) {
52003 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52004 + PAGE_SIZE)
52005 + kfree(acl_role_set.r_hash);
52006 + else
52007 + vfree(acl_role_set.r_hash);
52008 + }
52009 + if (name_set.n_hash) {
52010 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52011 + PAGE_SIZE)
52012 + kfree(name_set.n_hash);
52013 + else
52014 + vfree(name_set.n_hash);
52015 + }
52016 +
52017 + if (inodev_set.i_hash) {
52018 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52019 + PAGE_SIZE)
52020 + kfree(inodev_set.i_hash);
52021 + else
52022 + vfree(inodev_set.i_hash);
52023 + }
52024 +
52025 + gr_free_uidset();
52026 +
52027 + memset(&name_set, 0, sizeof (struct name_db));
52028 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52029 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52030 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52031 +
52032 + default_role = NULL;
52033 + kernel_role = NULL;
52034 + role_list = NULL;
52035 +
52036 + return;
52037 +}
52038 +
52039 +static __u32
52040 +count_user_objs(struct acl_object_label *userp)
52041 +{
52042 + struct acl_object_label o_tmp;
52043 + __u32 num = 0;
52044 +
52045 + while (userp) {
52046 + if (copy_from_user(&o_tmp, userp,
52047 + sizeof (struct acl_object_label)))
52048 + break;
52049 +
52050 + userp = o_tmp.prev;
52051 + num++;
52052 + }
52053 +
52054 + return num;
52055 +}
52056 +
52057 +static struct acl_subject_label *
52058 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52059 +
52060 +static int
52061 +copy_user_glob(struct acl_object_label *obj)
52062 +{
52063 + struct acl_object_label *g_tmp, **guser;
52064 + unsigned int len;
52065 + char *tmp;
52066 +
52067 + if (obj->globbed == NULL)
52068 + return 0;
52069 +
52070 + guser = &obj->globbed;
52071 + while (*guser) {
52072 + g_tmp = (struct acl_object_label *)
52073 + acl_alloc(sizeof (struct acl_object_label));
52074 + if (g_tmp == NULL)
52075 + return -ENOMEM;
52076 +
52077 + if (copy_from_user(g_tmp, *guser,
52078 + sizeof (struct acl_object_label)))
52079 + return -EFAULT;
52080 +
52081 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52082 +
52083 + if (!len || len >= PATH_MAX)
52084 + return -EINVAL;
52085 +
52086 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52087 + return -ENOMEM;
52088 +
52089 + if (copy_from_user(tmp, g_tmp->filename, len))
52090 + return -EFAULT;
52091 + tmp[len-1] = '\0';
52092 + g_tmp->filename = tmp;
52093 +
52094 + *guser = g_tmp;
52095 + guser = &(g_tmp->next);
52096 + }
52097 +
52098 + return 0;
52099 +}
52100 +
52101 +static int
52102 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52103 + struct acl_role_label *role)
52104 +{
52105 + struct acl_object_label *o_tmp;
52106 + unsigned int len;
52107 + int ret;
52108 + char *tmp;
52109 +
52110 + while (userp) {
52111 + if ((o_tmp = (struct acl_object_label *)
52112 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52113 + return -ENOMEM;
52114 +
52115 + if (copy_from_user(o_tmp, userp,
52116 + sizeof (struct acl_object_label)))
52117 + return -EFAULT;
52118 +
52119 + userp = o_tmp->prev;
52120 +
52121 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52122 +
52123 + if (!len || len >= PATH_MAX)
52124 + return -EINVAL;
52125 +
52126 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52127 + return -ENOMEM;
52128 +
52129 + if (copy_from_user(tmp, o_tmp->filename, len))
52130 + return -EFAULT;
52131 + tmp[len-1] = '\0';
52132 + o_tmp->filename = tmp;
52133 +
52134 + insert_acl_obj_label(o_tmp, subj);
52135 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52136 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52137 + return -ENOMEM;
52138 +
52139 + ret = copy_user_glob(o_tmp);
52140 + if (ret)
52141 + return ret;
52142 +
52143 + if (o_tmp->nested) {
52144 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52145 + if (IS_ERR(o_tmp->nested))
52146 + return PTR_ERR(o_tmp->nested);
52147 +
52148 + /* insert into nested subject list */
52149 + o_tmp->nested->next = role->hash->first;
52150 + role->hash->first = o_tmp->nested;
52151 + }
52152 + }
52153 +
52154 + return 0;
52155 +}
52156 +
52157 +static __u32
52158 +count_user_subjs(struct acl_subject_label *userp)
52159 +{
52160 + struct acl_subject_label s_tmp;
52161 + __u32 num = 0;
52162 +
52163 + while (userp) {
52164 + if (copy_from_user(&s_tmp, userp,
52165 + sizeof (struct acl_subject_label)))
52166 + break;
52167 +
52168 + userp = s_tmp.prev;
52169 + /* do not count nested subjects against this count, since
52170 + they are not included in the hash table, but are
52171 + attached to objects. We have already counted
52172 + the subjects in userspace for the allocation
52173 + stack
52174 + */
52175 + if (!(s_tmp.mode & GR_NESTED))
52176 + num++;
52177 + }
52178 +
52179 + return num;
52180 +}
52181 +
52182 +static int
52183 +copy_user_allowedips(struct acl_role_label *rolep)
52184 +{
52185 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52186 +
52187 + ruserip = rolep->allowed_ips;
52188 +
52189 + while (ruserip) {
52190 + rlast = rtmp;
52191 +
52192 + if ((rtmp = (struct role_allowed_ip *)
52193 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52194 + return -ENOMEM;
52195 +
52196 + if (copy_from_user(rtmp, ruserip,
52197 + sizeof (struct role_allowed_ip)))
52198 + return -EFAULT;
52199 +
52200 + ruserip = rtmp->prev;
52201 +
52202 + if (!rlast) {
52203 + rtmp->prev = NULL;
52204 + rolep->allowed_ips = rtmp;
52205 + } else {
52206 + rlast->next = rtmp;
52207 + rtmp->prev = rlast;
52208 + }
52209 +
52210 + if (!ruserip)
52211 + rtmp->next = NULL;
52212 + }
52213 +
52214 + return 0;
52215 +}
52216 +
52217 +static int
52218 +copy_user_transitions(struct acl_role_label *rolep)
52219 +{
52220 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52221 +
52222 + unsigned int len;
52223 + char *tmp;
52224 +
52225 + rusertp = rolep->transitions;
52226 +
52227 + while (rusertp) {
52228 + rlast = rtmp;
52229 +
52230 + if ((rtmp = (struct role_transition *)
52231 + acl_alloc(sizeof (struct role_transition))) == NULL)
52232 + return -ENOMEM;
52233 +
52234 + if (copy_from_user(rtmp, rusertp,
52235 + sizeof (struct role_transition)))
52236 + return -EFAULT;
52237 +
52238 + rusertp = rtmp->prev;
52239 +
52240 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52241 +
52242 + if (!len || len >= GR_SPROLE_LEN)
52243 + return -EINVAL;
52244 +
52245 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52246 + return -ENOMEM;
52247 +
52248 + if (copy_from_user(tmp, rtmp->rolename, len))
52249 + return -EFAULT;
52250 + tmp[len-1] = '\0';
52251 + rtmp->rolename = tmp;
52252 +
52253 + if (!rlast) {
52254 + rtmp->prev = NULL;
52255 + rolep->transitions = rtmp;
52256 + } else {
52257 + rlast->next = rtmp;
52258 + rtmp->prev = rlast;
52259 + }
52260 +
52261 + if (!rusertp)
52262 + rtmp->next = NULL;
52263 + }
52264 +
52265 + return 0;
52266 +}
52267 +
52268 +static struct acl_subject_label *
52269 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52270 +{
52271 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52272 + unsigned int len;
52273 + char *tmp;
52274 + __u32 num_objs;
52275 + struct acl_ip_label **i_tmp, *i_utmp2;
52276 + struct gr_hash_struct ghash;
52277 + struct subject_map *subjmap;
52278 + unsigned int i_num;
52279 + int err;
52280 +
52281 + s_tmp = lookup_subject_map(userp);
52282 +
52283 + /* we've already copied this subject into the kernel, just return
52284 + the reference to it, and don't copy it over again
52285 + */
52286 + if (s_tmp)
52287 + return(s_tmp);
52288 +
52289 + if ((s_tmp = (struct acl_subject_label *)
52290 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52291 + return ERR_PTR(-ENOMEM);
52292 +
52293 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52294 + if (subjmap == NULL)
52295 + return ERR_PTR(-ENOMEM);
52296 +
52297 + subjmap->user = userp;
52298 + subjmap->kernel = s_tmp;
52299 + insert_subj_map_entry(subjmap);
52300 +
52301 + if (copy_from_user(s_tmp, userp,
52302 + sizeof (struct acl_subject_label)))
52303 + return ERR_PTR(-EFAULT);
52304 +
52305 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52306 +
52307 + if (!len || len >= PATH_MAX)
52308 + return ERR_PTR(-EINVAL);
52309 +
52310 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52311 + return ERR_PTR(-ENOMEM);
52312 +
52313 + if (copy_from_user(tmp, s_tmp->filename, len))
52314 + return ERR_PTR(-EFAULT);
52315 + tmp[len-1] = '\0';
52316 + s_tmp->filename = tmp;
52317 +
52318 + if (!strcmp(s_tmp->filename, "/"))
52319 + role->root_label = s_tmp;
52320 +
52321 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52322 + return ERR_PTR(-EFAULT);
52323 +
52324 + /* copy user and group transition tables */
52325 +
52326 + if (s_tmp->user_trans_num) {
52327 + uid_t *uidlist;
52328 +
52329 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52330 + if (uidlist == NULL)
52331 + return ERR_PTR(-ENOMEM);
52332 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52333 + return ERR_PTR(-EFAULT);
52334 +
52335 + s_tmp->user_transitions = uidlist;
52336 + }
52337 +
52338 + if (s_tmp->group_trans_num) {
52339 + gid_t *gidlist;
52340 +
52341 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52342 + if (gidlist == NULL)
52343 + return ERR_PTR(-ENOMEM);
52344 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52345 + return ERR_PTR(-EFAULT);
52346 +
52347 + s_tmp->group_transitions = gidlist;
52348 + }
52349 +
52350 + /* set up object hash table */
52351 + num_objs = count_user_objs(ghash.first);
52352 +
52353 + s_tmp->obj_hash_size = num_objs;
52354 + s_tmp->obj_hash =
52355 + (struct acl_object_label **)
52356 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52357 +
52358 + if (!s_tmp->obj_hash)
52359 + return ERR_PTR(-ENOMEM);
52360 +
52361 + memset(s_tmp->obj_hash, 0,
52362 + s_tmp->obj_hash_size *
52363 + sizeof (struct acl_object_label *));
52364 +
52365 + /* add in objects */
52366 + err = copy_user_objs(ghash.first, s_tmp, role);
52367 +
52368 + if (err)
52369 + return ERR_PTR(err);
52370 +
52371 + /* set pointer for parent subject */
52372 + if (s_tmp->parent_subject) {
52373 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52374 +
52375 + if (IS_ERR(s_tmp2))
52376 + return s_tmp2;
52377 +
52378 + s_tmp->parent_subject = s_tmp2;
52379 + }
52380 +
52381 + /* add in ip acls */
52382 +
52383 + if (!s_tmp->ip_num) {
52384 + s_tmp->ips = NULL;
52385 + goto insert;
52386 + }
52387 +
52388 + i_tmp =
52389 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52390 + sizeof (struct acl_ip_label *));
52391 +
52392 + if (!i_tmp)
52393 + return ERR_PTR(-ENOMEM);
52394 +
52395 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52396 + *(i_tmp + i_num) =
52397 + (struct acl_ip_label *)
52398 + acl_alloc(sizeof (struct acl_ip_label));
52399 + if (!*(i_tmp + i_num))
52400 + return ERR_PTR(-ENOMEM);
52401 +
52402 + if (copy_from_user
52403 + (&i_utmp2, s_tmp->ips + i_num,
52404 + sizeof (struct acl_ip_label *)))
52405 + return ERR_PTR(-EFAULT);
52406 +
52407 + if (copy_from_user
52408 + (*(i_tmp + i_num), i_utmp2,
52409 + sizeof (struct acl_ip_label)))
52410 + return ERR_PTR(-EFAULT);
52411 +
52412 + if ((*(i_tmp + i_num))->iface == NULL)
52413 + continue;
52414 +
52415 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52416 + if (!len || len >= IFNAMSIZ)
52417 + return ERR_PTR(-EINVAL);
52418 + tmp = acl_alloc(len);
52419 + if (tmp == NULL)
52420 + return ERR_PTR(-ENOMEM);
52421 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52422 + return ERR_PTR(-EFAULT);
52423 + (*(i_tmp + i_num))->iface = tmp;
52424 + }
52425 +
52426 + s_tmp->ips = i_tmp;
52427 +
52428 +insert:
52429 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52430 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52431 + return ERR_PTR(-ENOMEM);
52432 +
52433 + return s_tmp;
52434 +}
52435 +
52436 +static int
52437 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52438 +{
52439 + struct acl_subject_label s_pre;
52440 + struct acl_subject_label * ret;
52441 + int err;
52442 +
52443 + while (userp) {
52444 + if (copy_from_user(&s_pre, userp,
52445 + sizeof (struct acl_subject_label)))
52446 + return -EFAULT;
52447 +
52448 + /* do not add nested subjects here, add
52449 + while parsing objects
52450 + */
52451 +
52452 + if (s_pre.mode & GR_NESTED) {
52453 + userp = s_pre.prev;
52454 + continue;
52455 + }
52456 +
52457 + ret = do_copy_user_subj(userp, role);
52458 +
52459 + err = PTR_ERR(ret);
52460 + if (IS_ERR(ret))
52461 + return err;
52462 +
52463 + insert_acl_subj_label(ret, role);
52464 +
52465 + userp = s_pre.prev;
52466 + }
52467 +
52468 + return 0;
52469 +}
52470 +
52471 +static int
52472 +copy_user_acl(struct gr_arg *arg)
52473 +{
52474 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52475 + struct sprole_pw *sptmp;
52476 + struct gr_hash_struct *ghash;
52477 + uid_t *domainlist;
52478 + unsigned int r_num;
52479 + unsigned int len;
52480 + char *tmp;
52481 + int err = 0;
52482 + __u16 i;
52483 + __u32 num_subjs;
52484 +
52485 + /* we need a default and kernel role */
52486 + if (arg->role_db.num_roles < 2)
52487 + return -EINVAL;
52488 +
52489 + /* copy special role authentication info from userspace */
52490 +
52491 + num_sprole_pws = arg->num_sprole_pws;
52492 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52493 +
52494 + if (!acl_special_roles && num_sprole_pws)
52495 + return -ENOMEM;
52496 +
52497 + for (i = 0; i < num_sprole_pws; i++) {
52498 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52499 + if (!sptmp)
52500 + return -ENOMEM;
52501 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52502 + sizeof (struct sprole_pw)))
52503 + return -EFAULT;
52504 +
52505 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52506 +
52507 + if (!len || len >= GR_SPROLE_LEN)
52508 + return -EINVAL;
52509 +
52510 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52511 + return -ENOMEM;
52512 +
52513 + if (copy_from_user(tmp, sptmp->rolename, len))
52514 + return -EFAULT;
52515 +
52516 + tmp[len-1] = '\0';
52517 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52518 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52519 +#endif
52520 + sptmp->rolename = tmp;
52521 + acl_special_roles[i] = sptmp;
52522 + }
52523 +
52524 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52525 +
52526 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52527 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52528 +
52529 + if (!r_tmp)
52530 + return -ENOMEM;
52531 +
52532 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52533 + sizeof (struct acl_role_label *)))
52534 + return -EFAULT;
52535 +
52536 + if (copy_from_user(r_tmp, r_utmp2,
52537 + sizeof (struct acl_role_label)))
52538 + return -EFAULT;
52539 +
52540 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52541 +
52542 + if (!len || len >= PATH_MAX)
52543 + return -EINVAL;
52544 +
52545 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52546 + return -ENOMEM;
52547 +
52548 + if (copy_from_user(tmp, r_tmp->rolename, len))
52549 + return -EFAULT;
52550 +
52551 + tmp[len-1] = '\0';
52552 + r_tmp->rolename = tmp;
52553 +
52554 + if (!strcmp(r_tmp->rolename, "default")
52555 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52556 + default_role = r_tmp;
52557 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52558 + kernel_role = r_tmp;
52559 + }
52560 +
52561 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52562 + return -ENOMEM;
52563 +
52564 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52565 + return -EFAULT;
52566 +
52567 + r_tmp->hash = ghash;
52568 +
52569 + num_subjs = count_user_subjs(r_tmp->hash->first);
52570 +
52571 + r_tmp->subj_hash_size = num_subjs;
52572 + r_tmp->subj_hash =
52573 + (struct acl_subject_label **)
52574 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52575 +
52576 + if (!r_tmp->subj_hash)
52577 + return -ENOMEM;
52578 +
52579 + err = copy_user_allowedips(r_tmp);
52580 + if (err)
52581 + return err;
52582 +
52583 + /* copy domain info */
52584 + if (r_tmp->domain_children != NULL) {
52585 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52586 + if (domainlist == NULL)
52587 + return -ENOMEM;
52588 +
52589 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52590 + return -EFAULT;
52591 +
52592 + r_tmp->domain_children = domainlist;
52593 + }
52594 +
52595 + err = copy_user_transitions(r_tmp);
52596 + if (err)
52597 + return err;
52598 +
52599 + memset(r_tmp->subj_hash, 0,
52600 + r_tmp->subj_hash_size *
52601 + sizeof (struct acl_subject_label *));
52602 +
52603 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52604 +
52605 + if (err)
52606 + return err;
52607 +
52608 + /* set nested subject list to null */
52609 + r_tmp->hash->first = NULL;
52610 +
52611 + insert_acl_role_label(r_tmp);
52612 + }
52613 +
52614 + if (default_role == NULL || kernel_role == NULL)
52615 + return -EINVAL;
52616 +
52617 + return err;
52618 +}
52619 +
52620 +static int
52621 +gracl_init(struct gr_arg *args)
52622 +{
52623 + int error = 0;
52624 +
52625 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52626 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52627 +
52628 + if (init_variables(args)) {
52629 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52630 + error = -ENOMEM;
52631 + free_variables();
52632 + goto out;
52633 + }
52634 +
52635 + error = copy_user_acl(args);
52636 + free_init_variables();
52637 + if (error) {
52638 + free_variables();
52639 + goto out;
52640 + }
52641 +
52642 + if ((error = gr_set_acls(0))) {
52643 + free_variables();
52644 + goto out;
52645 + }
52646 +
52647 + pax_open_kernel();
52648 + gr_status |= GR_READY;
52649 + pax_close_kernel();
52650 +
52651 + out:
52652 + return error;
52653 +}
52654 +
52655 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52656 +
52657 +static int
52658 +glob_match(const char *p, const char *n)
52659 +{
52660 + char c;
52661 +
52662 + while ((c = *p++) != '\0') {
52663 + switch (c) {
52664 + case '?':
52665 + if (*n == '\0')
52666 + return 1;
52667 + else if (*n == '/')
52668 + return 1;
52669 + break;
52670 + case '\\':
52671 + if (*n != c)
52672 + return 1;
52673 + break;
52674 + case '*':
52675 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52676 + if (*n == '/')
52677 + return 1;
52678 + else if (c == '?') {
52679 + if (*n == '\0')
52680 + return 1;
52681 + else
52682 + ++n;
52683 + }
52684 + }
52685 + if (c == '\0') {
52686 + return 0;
52687 + } else {
52688 + const char *endp;
52689 +
52690 + if ((endp = strchr(n, '/')) == NULL)
52691 + endp = n + strlen(n);
52692 +
52693 + if (c == '[') {
52694 + for (--p; n < endp; ++n)
52695 + if (!glob_match(p, n))
52696 + return 0;
52697 + } else if (c == '/') {
52698 + while (*n != '\0' && *n != '/')
52699 + ++n;
52700 + if (*n == '/' && !glob_match(p, n + 1))
52701 + return 0;
52702 + } else {
52703 + for (--p; n < endp; ++n)
52704 + if (*n == c && !glob_match(p, n))
52705 + return 0;
52706 + }
52707 +
52708 + return 1;
52709 + }
52710 + case '[':
52711 + {
52712 + int not;
52713 + char cold;
52714 +
52715 + if (*n == '\0' || *n == '/')
52716 + return 1;
52717 +
52718 + not = (*p == '!' || *p == '^');
52719 + if (not)
52720 + ++p;
52721 +
52722 + c = *p++;
52723 + for (;;) {
52724 + unsigned char fn = (unsigned char)*n;
52725 +
52726 + if (c == '\0')
52727 + return 1;
52728 + else {
52729 + if (c == fn)
52730 + goto matched;
52731 + cold = c;
52732 + c = *p++;
52733 +
52734 + if (c == '-' && *p != ']') {
52735 + unsigned char cend = *p++;
52736 +
52737 + if (cend == '\0')
52738 + return 1;
52739 +
52740 + if (cold <= fn && fn <= cend)
52741 + goto matched;
52742 +
52743 + c = *p++;
52744 + }
52745 + }
52746 +
52747 + if (c == ']')
52748 + break;
52749 + }
52750 + if (!not)
52751 + return 1;
52752 + break;
52753 + matched:
52754 + while (c != ']') {
52755 + if (c == '\0')
52756 + return 1;
52757 +
52758 + c = *p++;
52759 + }
52760 + if (not)
52761 + return 1;
52762 + }
52763 + break;
52764 + default:
52765 + if (c != *n)
52766 + return 1;
52767 + }
52768 +
52769 + ++n;
52770 + }
52771 +
52772 + if (*n == '\0')
52773 + return 0;
52774 +
52775 + if (*n == '/')
52776 + return 0;
52777 +
52778 + return 1;
52779 +}
52780 +
52781 +static struct acl_object_label *
52782 +chk_glob_label(struct acl_object_label *globbed,
52783 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52784 +{
52785 + struct acl_object_label *tmp;
52786 +
52787 + if (*path == NULL)
52788 + *path = gr_to_filename_nolock(dentry, mnt);
52789 +
52790 + tmp = globbed;
52791 +
52792 + while (tmp) {
52793 + if (!glob_match(tmp->filename, *path))
52794 + return tmp;
52795 + tmp = tmp->next;
52796 + }
52797 +
52798 + return NULL;
52799 +}
52800 +
52801 +static struct acl_object_label *
52802 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52803 + const ino_t curr_ino, const dev_t curr_dev,
52804 + const struct acl_subject_label *subj, char **path, const int checkglob)
52805 +{
52806 + struct acl_subject_label *tmpsubj;
52807 + struct acl_object_label *retval;
52808 + struct acl_object_label *retval2;
52809 +
52810 + tmpsubj = (struct acl_subject_label *) subj;
52811 + read_lock(&gr_inode_lock);
52812 + do {
52813 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52814 + if (retval) {
52815 + if (checkglob && retval->globbed) {
52816 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52817 + if (retval2)
52818 + retval = retval2;
52819 + }
52820 + break;
52821 + }
52822 + } while ((tmpsubj = tmpsubj->parent_subject));
52823 + read_unlock(&gr_inode_lock);
52824 +
52825 + return retval;
52826 +}
52827 +
52828 +static __inline__ struct acl_object_label *
52829 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52830 + struct dentry *curr_dentry,
52831 + const struct acl_subject_label *subj, char **path, const int checkglob)
52832 +{
52833 + int newglob = checkglob;
52834 + ino_t inode;
52835 + dev_t device;
52836 +
52837 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52838 + as we don't want a / * rule to match instead of the / object
52839 + don't do this for create lookups that call this function though, since they're looking up
52840 + on the parent and thus need globbing checks on all paths
52841 + */
52842 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52843 + newglob = GR_NO_GLOB;
52844 +
52845 + spin_lock(&curr_dentry->d_lock);
52846 + inode = curr_dentry->d_inode->i_ino;
52847 + device = __get_dev(curr_dentry);
52848 + spin_unlock(&curr_dentry->d_lock);
52849 +
52850 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52851 +}
52852 +
52853 +static struct acl_object_label *
52854 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52855 + const struct acl_subject_label *subj, char *path, const int checkglob)
52856 +{
52857 + struct dentry *dentry = (struct dentry *) l_dentry;
52858 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52859 + struct mount *real_mnt = real_mount(mnt);
52860 + struct acl_object_label *retval;
52861 + struct dentry *parent;
52862 +
52863 + write_seqlock(&rename_lock);
52864 + br_read_lock(&vfsmount_lock);
52865 +
52866 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52867 +#ifdef CONFIG_NET
52868 + mnt == sock_mnt ||
52869 +#endif
52870 +#ifdef CONFIG_HUGETLBFS
52871 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52872 +#endif
52873 + /* ignore Eric Biederman */
52874 + IS_PRIVATE(l_dentry->d_inode))) {
52875 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52876 + goto out;
52877 + }
52878 +
52879 + for (;;) {
52880 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52881 + break;
52882 +
52883 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52884 + if (!mnt_has_parent(real_mnt))
52885 + break;
52886 +
52887 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52888 + if (retval != NULL)
52889 + goto out;
52890 +
52891 + dentry = real_mnt->mnt_mountpoint;
52892 + real_mnt = real_mnt->mnt_parent;
52893 + mnt = &real_mnt->mnt;
52894 + continue;
52895 + }
52896 +
52897 + parent = dentry->d_parent;
52898 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52899 + if (retval != NULL)
52900 + goto out;
52901 +
52902 + dentry = parent;
52903 + }
52904 +
52905 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52906 +
52907 + /* real_root is pinned so we don't have to hold a reference */
52908 + if (retval == NULL)
52909 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52910 +out:
52911 + br_read_unlock(&vfsmount_lock);
52912 + write_sequnlock(&rename_lock);
52913 +
52914 + BUG_ON(retval == NULL);
52915 +
52916 + return retval;
52917 +}
52918 +
52919 +static __inline__ struct acl_object_label *
52920 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52921 + const struct acl_subject_label *subj)
52922 +{
52923 + char *path = NULL;
52924 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52925 +}
52926 +
52927 +static __inline__ struct acl_object_label *
52928 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52929 + const struct acl_subject_label *subj)
52930 +{
52931 + char *path = NULL;
52932 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52933 +}
52934 +
52935 +static __inline__ struct acl_object_label *
52936 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52937 + const struct acl_subject_label *subj, char *path)
52938 +{
52939 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52940 +}
52941 +
52942 +static struct acl_subject_label *
52943 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52944 + const struct acl_role_label *role)
52945 +{
52946 + struct dentry *dentry = (struct dentry *) l_dentry;
52947 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52948 + struct mount *real_mnt = real_mount(mnt);
52949 + struct acl_subject_label *retval;
52950 + struct dentry *parent;
52951 +
52952 + write_seqlock(&rename_lock);
52953 + br_read_lock(&vfsmount_lock);
52954 +
52955 + for (;;) {
52956 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52957 + break;
52958 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52959 + if (!mnt_has_parent(real_mnt))
52960 + break;
52961 +
52962 + spin_lock(&dentry->d_lock);
52963 + read_lock(&gr_inode_lock);
52964 + retval =
52965 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52966 + __get_dev(dentry), role);
52967 + read_unlock(&gr_inode_lock);
52968 + spin_unlock(&dentry->d_lock);
52969 + if (retval != NULL)
52970 + goto out;
52971 +
52972 + dentry = real_mnt->mnt_mountpoint;
52973 + real_mnt = real_mnt->mnt_parent;
52974 + mnt = &real_mnt->mnt;
52975 + continue;
52976 + }
52977 +
52978 + spin_lock(&dentry->d_lock);
52979 + read_lock(&gr_inode_lock);
52980 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52981 + __get_dev(dentry), role);
52982 + read_unlock(&gr_inode_lock);
52983 + parent = dentry->d_parent;
52984 + spin_unlock(&dentry->d_lock);
52985 +
52986 + if (retval != NULL)
52987 + goto out;
52988 +
52989 + dentry = parent;
52990 + }
52991 +
52992 + spin_lock(&dentry->d_lock);
52993 + read_lock(&gr_inode_lock);
52994 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52995 + __get_dev(dentry), role);
52996 + read_unlock(&gr_inode_lock);
52997 + spin_unlock(&dentry->d_lock);
52998 +
52999 + if (unlikely(retval == NULL)) {
53000 + /* real_root is pinned, we don't need to hold a reference */
53001 + read_lock(&gr_inode_lock);
53002 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53003 + __get_dev(real_root.dentry), role);
53004 + read_unlock(&gr_inode_lock);
53005 + }
53006 +out:
53007 + br_read_unlock(&vfsmount_lock);
53008 + write_sequnlock(&rename_lock);
53009 +
53010 + BUG_ON(retval == NULL);
53011 +
53012 + return retval;
53013 +}
53014 +
53015 +static void
53016 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53017 +{
53018 + struct task_struct *task = current;
53019 + const struct cred *cred = current_cred();
53020 +
53021 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53022 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53023 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53024 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53025 +
53026 + return;
53027 +}
53028 +
53029 +static void
53030 +gr_log_learn_id_change(const char type, const unsigned int real,
53031 + const unsigned int effective, const unsigned int fs)
53032 +{
53033 + struct task_struct *task = current;
53034 + const struct cred *cred = current_cred();
53035 +
53036 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53037 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53038 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53039 + type, real, effective, fs, &task->signal->saved_ip);
53040 +
53041 + return;
53042 +}
53043 +
53044 +__u32
53045 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53046 + const struct vfsmount * mnt)
53047 +{
53048 + __u32 retval = mode;
53049 + struct acl_subject_label *curracl;
53050 + struct acl_object_label *currobj;
53051 +
53052 + if (unlikely(!(gr_status & GR_READY)))
53053 + return (mode & ~GR_AUDITS);
53054 +
53055 + curracl = current->acl;
53056 +
53057 + currobj = chk_obj_label(dentry, mnt, curracl);
53058 + retval = currobj->mode & mode;
53059 +
53060 + /* if we're opening a specified transfer file for writing
53061 + (e.g. /dev/initctl), then transfer our role to init
53062 + */
53063 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53064 + current->role->roletype & GR_ROLE_PERSIST)) {
53065 + struct task_struct *task = init_pid_ns.child_reaper;
53066 +
53067 + if (task->role != current->role) {
53068 + task->acl_sp_role = 0;
53069 + task->acl_role_id = current->acl_role_id;
53070 + task->role = current->role;
53071 + rcu_read_lock();
53072 + read_lock(&grsec_exec_file_lock);
53073 + gr_apply_subject_to_task(task);
53074 + read_unlock(&grsec_exec_file_lock);
53075 + rcu_read_unlock();
53076 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53077 + }
53078 + }
53079 +
53080 + if (unlikely
53081 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53082 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53083 + __u32 new_mode = mode;
53084 +
53085 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53086 +
53087 + retval = new_mode;
53088 +
53089 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53090 + new_mode |= GR_INHERIT;
53091 +
53092 + if (!(mode & GR_NOLEARN))
53093 + gr_log_learn(dentry, mnt, new_mode);
53094 + }
53095 +
53096 + return retval;
53097 +}
53098 +
53099 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53100 + const struct dentry *parent,
53101 + const struct vfsmount *mnt)
53102 +{
53103 + struct name_entry *match;
53104 + struct acl_object_label *matchpo;
53105 + struct acl_subject_label *curracl;
53106 + char *path;
53107 +
53108 + if (unlikely(!(gr_status & GR_READY)))
53109 + return NULL;
53110 +
53111 + preempt_disable();
53112 + path = gr_to_filename_rbac(new_dentry, mnt);
53113 + match = lookup_name_entry_create(path);
53114 +
53115 + curracl = current->acl;
53116 +
53117 + if (match) {
53118 + read_lock(&gr_inode_lock);
53119 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53120 + read_unlock(&gr_inode_lock);
53121 +
53122 + if (matchpo) {
53123 + preempt_enable();
53124 + return matchpo;
53125 + }
53126 + }
53127 +
53128 + // lookup parent
53129 +
53130 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53131 +
53132 + preempt_enable();
53133 + return matchpo;
53134 +}
53135 +
53136 +__u32
53137 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53138 + const struct vfsmount * mnt, const __u32 mode)
53139 +{
53140 + struct acl_object_label *matchpo;
53141 + __u32 retval;
53142 +
53143 + if (unlikely(!(gr_status & GR_READY)))
53144 + return (mode & ~GR_AUDITS);
53145 +
53146 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53147 +
53148 + retval = matchpo->mode & mode;
53149 +
53150 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53151 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53152 + __u32 new_mode = mode;
53153 +
53154 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53155 +
53156 + gr_log_learn(new_dentry, mnt, new_mode);
53157 + return new_mode;
53158 + }
53159 +
53160 + return retval;
53161 +}
53162 +
53163 +__u32
53164 +gr_check_link(const struct dentry * new_dentry,
53165 + const struct dentry * parent_dentry,
53166 + const struct vfsmount * parent_mnt,
53167 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53168 +{
53169 + struct acl_object_label *obj;
53170 + __u32 oldmode, newmode;
53171 + __u32 needmode;
53172 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53173 + GR_DELETE | GR_INHERIT;
53174 +
53175 + if (unlikely(!(gr_status & GR_READY)))
53176 + return (GR_CREATE | GR_LINK);
53177 +
53178 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53179 + oldmode = obj->mode;
53180 +
53181 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53182 + newmode = obj->mode;
53183 +
53184 + needmode = newmode & checkmodes;
53185 +
53186 + // old name for hardlink must have at least the permissions of the new name
53187 + if ((oldmode & needmode) != needmode)
53188 + goto bad;
53189 +
53190 + // if old name had restrictions/auditing, make sure the new name does as well
53191 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53192 +
53193 + // don't allow hardlinking of suid/sgid files without permission
53194 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53195 + needmode |= GR_SETID;
53196 +
53197 + if ((newmode & needmode) != needmode)
53198 + goto bad;
53199 +
53200 + // enforce minimum permissions
53201 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53202 + return newmode;
53203 +bad:
53204 + needmode = oldmode;
53205 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53206 + needmode |= GR_SETID;
53207 +
53208 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53209 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53210 + return (GR_CREATE | GR_LINK);
53211 + } else if (newmode & GR_SUPPRESS)
53212 + return GR_SUPPRESS;
53213 + else
53214 + return 0;
53215 +}
53216 +
53217 +int
53218 +gr_check_hidden_task(const struct task_struct *task)
53219 +{
53220 + if (unlikely(!(gr_status & GR_READY)))
53221 + return 0;
53222 +
53223 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53224 + return 1;
53225 +
53226 + return 0;
53227 +}
53228 +
53229 +int
53230 +gr_check_protected_task(const struct task_struct *task)
53231 +{
53232 + if (unlikely(!(gr_status & GR_READY) || !task))
53233 + return 0;
53234 +
53235 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53236 + task->acl != current->acl)
53237 + return 1;
53238 +
53239 + return 0;
53240 +}
53241 +
53242 +int
53243 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53244 +{
53245 + struct task_struct *p;
53246 + int ret = 0;
53247 +
53248 + if (unlikely(!(gr_status & GR_READY) || !pid))
53249 + return ret;
53250 +
53251 + read_lock(&tasklist_lock);
53252 + do_each_pid_task(pid, type, p) {
53253 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53254 + p->acl != current->acl) {
53255 + ret = 1;
53256 + goto out;
53257 + }
53258 + } while_each_pid_task(pid, type, p);
53259 +out:
53260 + read_unlock(&tasklist_lock);
53261 +
53262 + return ret;
53263 +}
53264 +
53265 +void
53266 +gr_copy_label(struct task_struct *tsk)
53267 +{
53268 + tsk->signal->used_accept = 0;
53269 + tsk->acl_sp_role = 0;
53270 + tsk->acl_role_id = current->acl_role_id;
53271 + tsk->acl = current->acl;
53272 + tsk->role = current->role;
53273 + tsk->signal->curr_ip = current->signal->curr_ip;
53274 + tsk->signal->saved_ip = current->signal->saved_ip;
53275 + if (current->exec_file)
53276 + get_file(current->exec_file);
53277 + tsk->exec_file = current->exec_file;
53278 + tsk->is_writable = current->is_writable;
53279 + if (unlikely(current->signal->used_accept)) {
53280 + current->signal->curr_ip = 0;
53281 + current->signal->saved_ip = 0;
53282 + }
53283 +
53284 + return;
53285 +}
53286 +
53287 +static void
53288 +gr_set_proc_res(struct task_struct *task)
53289 +{
53290 + struct acl_subject_label *proc;
53291 + unsigned short i;
53292 +
53293 + proc = task->acl;
53294 +
53295 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53296 + return;
53297 +
53298 + for (i = 0; i < RLIM_NLIMITS; i++) {
53299 + if (!(proc->resmask & (1 << i)))
53300 + continue;
53301 +
53302 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53303 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53304 + }
53305 +
53306 + return;
53307 +}
53308 +
53309 +extern int __gr_process_user_ban(struct user_struct *user);
53310 +
53311 +int
53312 +gr_check_user_change(int real, int effective, int fs)
53313 +{
53314 + unsigned int i;
53315 + __u16 num;
53316 + uid_t *uidlist;
53317 + int curuid;
53318 + int realok = 0;
53319 + int effectiveok = 0;
53320 + int fsok = 0;
53321 +
53322 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53323 + struct user_struct *user;
53324 +
53325 + if (real == -1)
53326 + goto skipit;
53327 +
53328 + user = find_user(real);
53329 + if (user == NULL)
53330 + goto skipit;
53331 +
53332 + if (__gr_process_user_ban(user)) {
53333 + /* for find_user */
53334 + free_uid(user);
53335 + return 1;
53336 + }
53337 +
53338 + /* for find_user */
53339 + free_uid(user);
53340 +
53341 +skipit:
53342 +#endif
53343 +
53344 + if (unlikely(!(gr_status & GR_READY)))
53345 + return 0;
53346 +
53347 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53348 + gr_log_learn_id_change('u', real, effective, fs);
53349 +
53350 + num = current->acl->user_trans_num;
53351 + uidlist = current->acl->user_transitions;
53352 +
53353 + if (uidlist == NULL)
53354 + return 0;
53355 +
53356 + if (real == -1)
53357 + realok = 1;
53358 + if (effective == -1)
53359 + effectiveok = 1;
53360 + if (fs == -1)
53361 + fsok = 1;
53362 +
53363 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53364 + for (i = 0; i < num; i++) {
53365 + curuid = (int)uidlist[i];
53366 + if (real == curuid)
53367 + realok = 1;
53368 + if (effective == curuid)
53369 + effectiveok = 1;
53370 + if (fs == curuid)
53371 + fsok = 1;
53372 + }
53373 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53374 + for (i = 0; i < num; i++) {
53375 + curuid = (int)uidlist[i];
53376 + if (real == curuid)
53377 + break;
53378 + if (effective == curuid)
53379 + break;
53380 + if (fs == curuid)
53381 + break;
53382 + }
53383 + /* not in deny list */
53384 + if (i == num) {
53385 + realok = 1;
53386 + effectiveok = 1;
53387 + fsok = 1;
53388 + }
53389 + }
53390 +
53391 + if (realok && effectiveok && fsok)
53392 + return 0;
53393 + else {
53394 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53395 + return 1;
53396 + }
53397 +}
53398 +
53399 +int
53400 +gr_check_group_change(int real, int effective, int fs)
53401 +{
53402 + unsigned int i;
53403 + __u16 num;
53404 + gid_t *gidlist;
53405 + int curgid;
53406 + int realok = 0;
53407 + int effectiveok = 0;
53408 + int fsok = 0;
53409 +
53410 + if (unlikely(!(gr_status & GR_READY)))
53411 + return 0;
53412 +
53413 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53414 + gr_log_learn_id_change('g', real, effective, fs);
53415 +
53416 + num = current->acl->group_trans_num;
53417 + gidlist = current->acl->group_transitions;
53418 +
53419 + if (gidlist == NULL)
53420 + return 0;
53421 +
53422 + if (real == -1)
53423 + realok = 1;
53424 + if (effective == -1)
53425 + effectiveok = 1;
53426 + if (fs == -1)
53427 + fsok = 1;
53428 +
53429 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53430 + for (i = 0; i < num; i++) {
53431 + curgid = (int)gidlist[i];
53432 + if (real == curgid)
53433 + realok = 1;
53434 + if (effective == curgid)
53435 + effectiveok = 1;
53436 + if (fs == curgid)
53437 + fsok = 1;
53438 + }
53439 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53440 + for (i = 0; i < num; i++) {
53441 + curgid = (int)gidlist[i];
53442 + if (real == curgid)
53443 + break;
53444 + if (effective == curgid)
53445 + break;
53446 + if (fs == curgid)
53447 + break;
53448 + }
53449 + /* not in deny list */
53450 + if (i == num) {
53451 + realok = 1;
53452 + effectiveok = 1;
53453 + fsok = 1;
53454 + }
53455 + }
53456 +
53457 + if (realok && effectiveok && fsok)
53458 + return 0;
53459 + else {
53460 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53461 + return 1;
53462 + }
53463 +}
53464 +
53465 +extern int gr_acl_is_capable(const int cap);
53466 +
53467 +void
53468 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53469 +{
53470 + struct acl_role_label *role = task->role;
53471 + struct acl_subject_label *subj = NULL;
53472 + struct acl_object_label *obj;
53473 + struct file *filp;
53474 +
53475 + if (unlikely(!(gr_status & GR_READY)))
53476 + return;
53477 +
53478 + filp = task->exec_file;
53479 +
53480 + /* kernel process, we'll give them the kernel role */
53481 + if (unlikely(!filp)) {
53482 + task->role = kernel_role;
53483 + task->acl = kernel_role->root_label;
53484 + return;
53485 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53486 + role = lookup_acl_role_label(task, uid, gid);
53487 +
53488 + /* don't change the role if we're not a privileged process */
53489 + if (role && task->role != role &&
53490 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53491 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53492 + return;
53493 +
53494 + /* perform subject lookup in possibly new role
53495 + we can use this result below in the case where role == task->role
53496 + */
53497 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53498 +
53499 + /* if we changed uid/gid, but result in the same role
53500 + and are using inheritance, don't lose the inherited subject
53501 + if current subject is other than what normal lookup
53502 + would result in, we arrived via inheritance, don't
53503 + lose subject
53504 + */
53505 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53506 + (subj == task->acl)))
53507 + task->acl = subj;
53508 +
53509 + task->role = role;
53510 +
53511 + task->is_writable = 0;
53512 +
53513 + /* ignore additional mmap checks for processes that are writable
53514 + by the default ACL */
53515 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53516 + if (unlikely(obj->mode & GR_WRITE))
53517 + task->is_writable = 1;
53518 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53519 + if (unlikely(obj->mode & GR_WRITE))
53520 + task->is_writable = 1;
53521 +
53522 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53523 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53524 +#endif
53525 +
53526 + gr_set_proc_res(task);
53527 +
53528 + return;
53529 +}
53530 +
53531 +int
53532 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53533 + const int unsafe_flags)
53534 +{
53535 + struct task_struct *task = current;
53536 + struct acl_subject_label *newacl;
53537 + struct acl_object_label *obj;
53538 + __u32 retmode;
53539 +
53540 + if (unlikely(!(gr_status & GR_READY)))
53541 + return 0;
53542 +
53543 + newacl = chk_subj_label(dentry, mnt, task->role);
53544 +
53545 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53546 + did an exec
53547 + */
53548 + rcu_read_lock();
53549 + read_lock(&tasklist_lock);
53550 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53551 + (task->parent->acl->mode & GR_POVERRIDE))) {
53552 + read_unlock(&tasklist_lock);
53553 + rcu_read_unlock();
53554 + goto skip_check;
53555 + }
53556 + read_unlock(&tasklist_lock);
53557 + rcu_read_unlock();
53558 +
53559 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53560 + !(task->role->roletype & GR_ROLE_GOD) &&
53561 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53562 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53563 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53564 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53565 + else
53566 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53567 + return -EACCES;
53568 + }
53569 +
53570 +skip_check:
53571 +
53572 + obj = chk_obj_label(dentry, mnt, task->acl);
53573 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53574 +
53575 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53576 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53577 + if (obj->nested)
53578 + task->acl = obj->nested;
53579 + else
53580 + task->acl = newacl;
53581 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53582 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53583 +
53584 + task->is_writable = 0;
53585 +
53586 + /* ignore additional mmap checks for processes that are writable
53587 + by the default ACL */
53588 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53589 + if (unlikely(obj->mode & GR_WRITE))
53590 + task->is_writable = 1;
53591 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53592 + if (unlikely(obj->mode & GR_WRITE))
53593 + task->is_writable = 1;
53594 +
53595 + gr_set_proc_res(task);
53596 +
53597 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53598 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53599 +#endif
53600 + return 0;
53601 +}
53602 +
53603 +/* always called with valid inodev ptr */
53604 +static void
53605 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53606 +{
53607 + struct acl_object_label *matchpo;
53608 + struct acl_subject_label *matchps;
53609 + struct acl_subject_label *subj;
53610 + struct acl_role_label *role;
53611 + unsigned int x;
53612 +
53613 + FOR_EACH_ROLE_START(role)
53614 + FOR_EACH_SUBJECT_START(role, subj, x)
53615 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53616 + matchpo->mode |= GR_DELETED;
53617 + FOR_EACH_SUBJECT_END(subj,x)
53618 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53619 + if (subj->inode == ino && subj->device == dev)
53620 + subj->mode |= GR_DELETED;
53621 + FOR_EACH_NESTED_SUBJECT_END(subj)
53622 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53623 + matchps->mode |= GR_DELETED;
53624 + FOR_EACH_ROLE_END(role)
53625 +
53626 + inodev->nentry->deleted = 1;
53627 +
53628 + return;
53629 +}
53630 +
53631 +void
53632 +gr_handle_delete(const ino_t ino, const dev_t dev)
53633 +{
53634 + struct inodev_entry *inodev;
53635 +
53636 + if (unlikely(!(gr_status & GR_READY)))
53637 + return;
53638 +
53639 + write_lock(&gr_inode_lock);
53640 + inodev = lookup_inodev_entry(ino, dev);
53641 + if (inodev != NULL)
53642 + do_handle_delete(inodev, ino, dev);
53643 + write_unlock(&gr_inode_lock);
53644 +
53645 + return;
53646 +}
53647 +
53648 +static void
53649 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53650 + const ino_t newinode, const dev_t newdevice,
53651 + struct acl_subject_label *subj)
53652 +{
53653 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53654 + struct acl_object_label *match;
53655 +
53656 + match = subj->obj_hash[index];
53657 +
53658 + while (match && (match->inode != oldinode ||
53659 + match->device != olddevice ||
53660 + !(match->mode & GR_DELETED)))
53661 + match = match->next;
53662 +
53663 + if (match && (match->inode == oldinode)
53664 + && (match->device == olddevice)
53665 + && (match->mode & GR_DELETED)) {
53666 + if (match->prev == NULL) {
53667 + subj->obj_hash[index] = match->next;
53668 + if (match->next != NULL)
53669 + match->next->prev = NULL;
53670 + } else {
53671 + match->prev->next = match->next;
53672 + if (match->next != NULL)
53673 + match->next->prev = match->prev;
53674 + }
53675 + match->prev = NULL;
53676 + match->next = NULL;
53677 + match->inode = newinode;
53678 + match->device = newdevice;
53679 + match->mode &= ~GR_DELETED;
53680 +
53681 + insert_acl_obj_label(match, subj);
53682 + }
53683 +
53684 + return;
53685 +}
53686 +
53687 +static void
53688 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53689 + const ino_t newinode, const dev_t newdevice,
53690 + struct acl_role_label *role)
53691 +{
53692 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53693 + struct acl_subject_label *match;
53694 +
53695 + match = role->subj_hash[index];
53696 +
53697 + while (match && (match->inode != oldinode ||
53698 + match->device != olddevice ||
53699 + !(match->mode & GR_DELETED)))
53700 + match = match->next;
53701 +
53702 + if (match && (match->inode == oldinode)
53703 + && (match->device == olddevice)
53704 + && (match->mode & GR_DELETED)) {
53705 + if (match->prev == NULL) {
53706 + role->subj_hash[index] = match->next;
53707 + if (match->next != NULL)
53708 + match->next->prev = NULL;
53709 + } else {
53710 + match->prev->next = match->next;
53711 + if (match->next != NULL)
53712 + match->next->prev = match->prev;
53713 + }
53714 + match->prev = NULL;
53715 + match->next = NULL;
53716 + match->inode = newinode;
53717 + match->device = newdevice;
53718 + match->mode &= ~GR_DELETED;
53719 +
53720 + insert_acl_subj_label(match, role);
53721 + }
53722 +
53723 + return;
53724 +}
53725 +
53726 +static void
53727 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53728 + const ino_t newinode, const dev_t newdevice)
53729 +{
53730 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53731 + struct inodev_entry *match;
53732 +
53733 + match = inodev_set.i_hash[index];
53734 +
53735 + while (match && (match->nentry->inode != oldinode ||
53736 + match->nentry->device != olddevice || !match->nentry->deleted))
53737 + match = match->next;
53738 +
53739 + if (match && (match->nentry->inode == oldinode)
53740 + && (match->nentry->device == olddevice) &&
53741 + match->nentry->deleted) {
53742 + if (match->prev == NULL) {
53743 + inodev_set.i_hash[index] = match->next;
53744 + if (match->next != NULL)
53745 + match->next->prev = NULL;
53746 + } else {
53747 + match->prev->next = match->next;
53748 + if (match->next != NULL)
53749 + match->next->prev = match->prev;
53750 + }
53751 + match->prev = NULL;
53752 + match->next = NULL;
53753 + match->nentry->inode = newinode;
53754 + match->nentry->device = newdevice;
53755 + match->nentry->deleted = 0;
53756 +
53757 + insert_inodev_entry(match);
53758 + }
53759 +
53760 + return;
53761 +}
53762 +
53763 +static void
53764 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53765 +{
53766 + struct acl_subject_label *subj;
53767 + struct acl_role_label *role;
53768 + unsigned int x;
53769 +
53770 + FOR_EACH_ROLE_START(role)
53771 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53772 +
53773 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53774 + if ((subj->inode == ino) && (subj->device == dev)) {
53775 + subj->inode = ino;
53776 + subj->device = dev;
53777 + }
53778 + FOR_EACH_NESTED_SUBJECT_END(subj)
53779 + FOR_EACH_SUBJECT_START(role, subj, x)
53780 + update_acl_obj_label(matchn->inode, matchn->device,
53781 + ino, dev, subj);
53782 + FOR_EACH_SUBJECT_END(subj,x)
53783 + FOR_EACH_ROLE_END(role)
53784 +
53785 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53786 +
53787 + return;
53788 +}
53789 +
53790 +static void
53791 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53792 + const struct vfsmount *mnt)
53793 +{
53794 + ino_t ino = dentry->d_inode->i_ino;
53795 + dev_t dev = __get_dev(dentry);
53796 +
53797 + __do_handle_create(matchn, ino, dev);
53798 +
53799 + return;
53800 +}
53801 +
53802 +void
53803 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53804 +{
53805 + struct name_entry *matchn;
53806 +
53807 + if (unlikely(!(gr_status & GR_READY)))
53808 + return;
53809 +
53810 + preempt_disable();
53811 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53812 +
53813 + if (unlikely((unsigned long)matchn)) {
53814 + write_lock(&gr_inode_lock);
53815 + do_handle_create(matchn, dentry, mnt);
53816 + write_unlock(&gr_inode_lock);
53817 + }
53818 + preempt_enable();
53819 +
53820 + return;
53821 +}
53822 +
53823 +void
53824 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53825 +{
53826 + struct name_entry *matchn;
53827 +
53828 + if (unlikely(!(gr_status & GR_READY)))
53829 + return;
53830 +
53831 + preempt_disable();
53832 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53833 +
53834 + if (unlikely((unsigned long)matchn)) {
53835 + write_lock(&gr_inode_lock);
53836 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53837 + write_unlock(&gr_inode_lock);
53838 + }
53839 + preempt_enable();
53840 +
53841 + return;
53842 +}
53843 +
53844 +void
53845 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53846 + struct dentry *old_dentry,
53847 + struct dentry *new_dentry,
53848 + struct vfsmount *mnt, const __u8 replace)
53849 +{
53850 + struct name_entry *matchn;
53851 + struct inodev_entry *inodev;
53852 + struct inode *inode = new_dentry->d_inode;
53853 + ino_t old_ino = old_dentry->d_inode->i_ino;
53854 + dev_t old_dev = __get_dev(old_dentry);
53855 +
53856 + /* vfs_rename swaps the name and parent link for old_dentry and
53857 + new_dentry
53858 + at this point, old_dentry has the new name, parent link, and inode
53859 + for the renamed file
53860 + if a file is being replaced by a rename, new_dentry has the inode
53861 + and name for the replaced file
53862 + */
53863 +
53864 + if (unlikely(!(gr_status & GR_READY)))
53865 + return;
53866 +
53867 + preempt_disable();
53868 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53869 +
53870 + /* we wouldn't have to check d_inode if it weren't for
53871 + NFS silly-renaming
53872 + */
53873 +
53874 + write_lock(&gr_inode_lock);
53875 + if (unlikely(replace && inode)) {
53876 + ino_t new_ino = inode->i_ino;
53877 + dev_t new_dev = __get_dev(new_dentry);
53878 +
53879 + inodev = lookup_inodev_entry(new_ino, new_dev);
53880 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53881 + do_handle_delete(inodev, new_ino, new_dev);
53882 + }
53883 +
53884 + inodev = lookup_inodev_entry(old_ino, old_dev);
53885 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53886 + do_handle_delete(inodev, old_ino, old_dev);
53887 +
53888 + if (unlikely((unsigned long)matchn))
53889 + do_handle_create(matchn, old_dentry, mnt);
53890 +
53891 + write_unlock(&gr_inode_lock);
53892 + preempt_enable();
53893 +
53894 + return;
53895 +}
53896 +
53897 +static int
53898 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53899 + unsigned char **sum)
53900 +{
53901 + struct acl_role_label *r;
53902 + struct role_allowed_ip *ipp;
53903 + struct role_transition *trans;
53904 + unsigned int i;
53905 + int found = 0;
53906 + u32 curr_ip = current->signal->curr_ip;
53907 +
53908 + current->signal->saved_ip = curr_ip;
53909 +
53910 + /* check transition table */
53911 +
53912 + for (trans = current->role->transitions; trans; trans = trans->next) {
53913 + if (!strcmp(rolename, trans->rolename)) {
53914 + found = 1;
53915 + break;
53916 + }
53917 + }
53918 +
53919 + if (!found)
53920 + return 0;
53921 +
53922 + /* handle special roles that do not require authentication
53923 + and check ip */
53924 +
53925 + FOR_EACH_ROLE_START(r)
53926 + if (!strcmp(rolename, r->rolename) &&
53927 + (r->roletype & GR_ROLE_SPECIAL)) {
53928 + found = 0;
53929 + if (r->allowed_ips != NULL) {
53930 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53931 + if ((ntohl(curr_ip) & ipp->netmask) ==
53932 + (ntohl(ipp->addr) & ipp->netmask))
53933 + found = 1;
53934 + }
53935 + } else
53936 + found = 2;
53937 + if (!found)
53938 + return 0;
53939 +
53940 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53941 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53942 + *salt = NULL;
53943 + *sum = NULL;
53944 + return 1;
53945 + }
53946 + }
53947 + FOR_EACH_ROLE_END(r)
53948 +
53949 + for (i = 0; i < num_sprole_pws; i++) {
53950 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53951 + *salt = acl_special_roles[i]->salt;
53952 + *sum = acl_special_roles[i]->sum;
53953 + return 1;
53954 + }
53955 + }
53956 +
53957 + return 0;
53958 +}
53959 +
53960 +static void
53961 +assign_special_role(char *rolename)
53962 +{
53963 + struct acl_object_label *obj;
53964 + struct acl_role_label *r;
53965 + struct acl_role_label *assigned = NULL;
53966 + struct task_struct *tsk;
53967 + struct file *filp;
53968 +
53969 + FOR_EACH_ROLE_START(r)
53970 + if (!strcmp(rolename, r->rolename) &&
53971 + (r->roletype & GR_ROLE_SPECIAL)) {
53972 + assigned = r;
53973 + break;
53974 + }
53975 + FOR_EACH_ROLE_END(r)
53976 +
53977 + if (!assigned)
53978 + return;
53979 +
53980 + read_lock(&tasklist_lock);
53981 + read_lock(&grsec_exec_file_lock);
53982 +
53983 + tsk = current->real_parent;
53984 + if (tsk == NULL)
53985 + goto out_unlock;
53986 +
53987 + filp = tsk->exec_file;
53988 + if (filp == NULL)
53989 + goto out_unlock;
53990 +
53991 + tsk->is_writable = 0;
53992 +
53993 + tsk->acl_sp_role = 1;
53994 + tsk->acl_role_id = ++acl_sp_role_value;
53995 + tsk->role = assigned;
53996 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53997 +
53998 + /* ignore additional mmap checks for processes that are writable
53999 + by the default ACL */
54000 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54001 + if (unlikely(obj->mode & GR_WRITE))
54002 + tsk->is_writable = 1;
54003 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54004 + if (unlikely(obj->mode & GR_WRITE))
54005 + tsk->is_writable = 1;
54006 +
54007 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54008 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54009 +#endif
54010 +
54011 +out_unlock:
54012 + read_unlock(&grsec_exec_file_lock);
54013 + read_unlock(&tasklist_lock);
54014 + return;
54015 +}
54016 +
54017 +int gr_check_secure_terminal(struct task_struct *task)
54018 +{
54019 + struct task_struct *p, *p2, *p3;
54020 + struct files_struct *files;
54021 + struct fdtable *fdt;
54022 + struct file *our_file = NULL, *file;
54023 + int i;
54024 +
54025 + if (task->signal->tty == NULL)
54026 + return 1;
54027 +
54028 + files = get_files_struct(task);
54029 + if (files != NULL) {
54030 + rcu_read_lock();
54031 + fdt = files_fdtable(files);
54032 + for (i=0; i < fdt->max_fds; i++) {
54033 + file = fcheck_files(files, i);
54034 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54035 + get_file(file);
54036 + our_file = file;
54037 + }
54038 + }
54039 + rcu_read_unlock();
54040 + put_files_struct(files);
54041 + }
54042 +
54043 + if (our_file == NULL)
54044 + return 1;
54045 +
54046 + read_lock(&tasklist_lock);
54047 + do_each_thread(p2, p) {
54048 + files = get_files_struct(p);
54049 + if (files == NULL ||
54050 + (p->signal && p->signal->tty == task->signal->tty)) {
54051 + if (files != NULL)
54052 + put_files_struct(files);
54053 + continue;
54054 + }
54055 + rcu_read_lock();
54056 + fdt = files_fdtable(files);
54057 + for (i=0; i < fdt->max_fds; i++) {
54058 + file = fcheck_files(files, i);
54059 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54060 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54061 + p3 = task;
54062 + while (p3->pid > 0) {
54063 + if (p3 == p)
54064 + break;
54065 + p3 = p3->real_parent;
54066 + }
54067 + if (p3 == p)
54068 + break;
54069 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54070 + gr_handle_alertkill(p);
54071 + rcu_read_unlock();
54072 + put_files_struct(files);
54073 + read_unlock(&tasklist_lock);
54074 + fput(our_file);
54075 + return 0;
54076 + }
54077 + }
54078 + rcu_read_unlock();
54079 + put_files_struct(files);
54080 + } while_each_thread(p2, p);
54081 + read_unlock(&tasklist_lock);
54082 +
54083 + fput(our_file);
54084 + return 1;
54085 +}
54086 +
54087 +static int gr_rbac_disable(void *unused)
54088 +{
54089 + pax_open_kernel();
54090 + gr_status &= ~GR_READY;
54091 + pax_close_kernel();
54092 +
54093 + return 0;
54094 +}
54095 +
54096 +ssize_t
54097 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54098 +{
54099 + struct gr_arg_wrapper uwrap;
54100 + unsigned char *sprole_salt = NULL;
54101 + unsigned char *sprole_sum = NULL;
54102 + int error = sizeof (struct gr_arg_wrapper);
54103 + int error2 = 0;
54104 +
54105 + mutex_lock(&gr_dev_mutex);
54106 +
54107 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54108 + error = -EPERM;
54109 + goto out;
54110 + }
54111 +
54112 + if (count != sizeof (struct gr_arg_wrapper)) {
54113 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54114 + error = -EINVAL;
54115 + goto out;
54116 + }
54117 +
54118 +
54119 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54120 + gr_auth_expires = 0;
54121 + gr_auth_attempts = 0;
54122 + }
54123 +
54124 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54125 + error = -EFAULT;
54126 + goto out;
54127 + }
54128 +
54129 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54130 + error = -EINVAL;
54131 + goto out;
54132 + }
54133 +
54134 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54135 + error = -EFAULT;
54136 + goto out;
54137 + }
54138 +
54139 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54140 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54141 + time_after(gr_auth_expires, get_seconds())) {
54142 + error = -EBUSY;
54143 + goto out;
54144 + }
54145 +
54146 + /* if non-root trying to do anything other than use a special role,
54147 + do not attempt authentication, do not count towards authentication
54148 + locking
54149 + */
54150 +
54151 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54152 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54153 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54154 + error = -EPERM;
54155 + goto out;
54156 + }
54157 +
54158 + /* ensure pw and special role name are null terminated */
54159 +
54160 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54161 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54162 +
54163 + /* Okay.
54164 + * We have our enough of the argument structure..(we have yet
54165 + * to copy_from_user the tables themselves) . Copy the tables
54166 + * only if we need them, i.e. for loading operations. */
54167 +
54168 + switch (gr_usermode->mode) {
54169 + case GR_STATUS:
54170 + if (gr_status & GR_READY) {
54171 + error = 1;
54172 + if (!gr_check_secure_terminal(current))
54173 + error = 3;
54174 + } else
54175 + error = 2;
54176 + goto out;
54177 + case GR_SHUTDOWN:
54178 + if ((gr_status & GR_READY)
54179 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54180 + stop_machine(gr_rbac_disable, NULL, NULL);
54181 + free_variables();
54182 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54183 + memset(gr_system_salt, 0, GR_SALT_LEN);
54184 + memset(gr_system_sum, 0, GR_SHA_LEN);
54185 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54186 + } else if (gr_status & GR_READY) {
54187 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54188 + error = -EPERM;
54189 + } else {
54190 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54191 + error = -EAGAIN;
54192 + }
54193 + break;
54194 + case GR_ENABLE:
54195 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54196 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54197 + else {
54198 + if (gr_status & GR_READY)
54199 + error = -EAGAIN;
54200 + else
54201 + error = error2;
54202 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54203 + }
54204 + break;
54205 + case GR_RELOAD:
54206 + if (!(gr_status & GR_READY)) {
54207 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54208 + error = -EAGAIN;
54209 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54210 + stop_machine(gr_rbac_disable, NULL, NULL);
54211 + free_variables();
54212 + error2 = gracl_init(gr_usermode);
54213 + if (!error2)
54214 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54215 + else {
54216 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54217 + error = error2;
54218 + }
54219 + } else {
54220 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54221 + error = -EPERM;
54222 + }
54223 + break;
54224 + case GR_SEGVMOD:
54225 + if (unlikely(!(gr_status & GR_READY))) {
54226 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54227 + error = -EAGAIN;
54228 + break;
54229 + }
54230 +
54231 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54232 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54233 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54234 + struct acl_subject_label *segvacl;
54235 + segvacl =
54236 + lookup_acl_subj_label(gr_usermode->segv_inode,
54237 + gr_usermode->segv_device,
54238 + current->role);
54239 + if (segvacl) {
54240 + segvacl->crashes = 0;
54241 + segvacl->expires = 0;
54242 + }
54243 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54244 + gr_remove_uid(gr_usermode->segv_uid);
54245 + }
54246 + } else {
54247 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54248 + error = -EPERM;
54249 + }
54250 + break;
54251 + case GR_SPROLE:
54252 + case GR_SPROLEPAM:
54253 + if (unlikely(!(gr_status & GR_READY))) {
54254 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54255 + error = -EAGAIN;
54256 + break;
54257 + }
54258 +
54259 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54260 + current->role->expires = 0;
54261 + current->role->auth_attempts = 0;
54262 + }
54263 +
54264 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54265 + time_after(current->role->expires, get_seconds())) {
54266 + error = -EBUSY;
54267 + goto out;
54268 + }
54269 +
54270 + if (lookup_special_role_auth
54271 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54272 + && ((!sprole_salt && !sprole_sum)
54273 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54274 + char *p = "";
54275 + assign_special_role(gr_usermode->sp_role);
54276 + read_lock(&tasklist_lock);
54277 + if (current->real_parent)
54278 + p = current->real_parent->role->rolename;
54279 + read_unlock(&tasklist_lock);
54280 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54281 + p, acl_sp_role_value);
54282 + } else {
54283 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54284 + error = -EPERM;
54285 + if(!(current->role->auth_attempts++))
54286 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54287 +
54288 + goto out;
54289 + }
54290 + break;
54291 + case GR_UNSPROLE:
54292 + if (unlikely(!(gr_status & GR_READY))) {
54293 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54294 + error = -EAGAIN;
54295 + break;
54296 + }
54297 +
54298 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54299 + char *p = "";
54300 + int i = 0;
54301 +
54302 + read_lock(&tasklist_lock);
54303 + if (current->real_parent) {
54304 + p = current->real_parent->role->rolename;
54305 + i = current->real_parent->acl_role_id;
54306 + }
54307 + read_unlock(&tasklist_lock);
54308 +
54309 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54310 + gr_set_acls(1);
54311 + } else {
54312 + error = -EPERM;
54313 + goto out;
54314 + }
54315 + break;
54316 + default:
54317 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54318 + error = -EINVAL;
54319 + break;
54320 + }
54321 +
54322 + if (error != -EPERM)
54323 + goto out;
54324 +
54325 + if(!(gr_auth_attempts++))
54326 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54327 +
54328 + out:
54329 + mutex_unlock(&gr_dev_mutex);
54330 + return error;
54331 +}
54332 +
54333 +/* must be called with
54334 + rcu_read_lock();
54335 + read_lock(&tasklist_lock);
54336 + read_lock(&grsec_exec_file_lock);
54337 +*/
54338 +int gr_apply_subject_to_task(struct task_struct *task)
54339 +{
54340 + struct acl_object_label *obj;
54341 + char *tmpname;
54342 + struct acl_subject_label *tmpsubj;
54343 + struct file *filp;
54344 + struct name_entry *nmatch;
54345 +
54346 + filp = task->exec_file;
54347 + if (filp == NULL)
54348 + return 0;
54349 +
54350 + /* the following is to apply the correct subject
54351 + on binaries running when the RBAC system
54352 + is enabled, when the binaries have been
54353 + replaced or deleted since their execution
54354 + -----
54355 + when the RBAC system starts, the inode/dev
54356 + from exec_file will be one the RBAC system
54357 + is unaware of. It only knows the inode/dev
54358 + of the present file on disk, or the absence
54359 + of it.
54360 + */
54361 + preempt_disable();
54362 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54363 +
54364 + nmatch = lookup_name_entry(tmpname);
54365 + preempt_enable();
54366 + tmpsubj = NULL;
54367 + if (nmatch) {
54368 + if (nmatch->deleted)
54369 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54370 + else
54371 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54372 + if (tmpsubj != NULL)
54373 + task->acl = tmpsubj;
54374 + }
54375 + if (tmpsubj == NULL)
54376 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54377 + task->role);
54378 + if (task->acl) {
54379 + task->is_writable = 0;
54380 + /* ignore additional mmap checks for processes that are writable
54381 + by the default ACL */
54382 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54383 + if (unlikely(obj->mode & GR_WRITE))
54384 + task->is_writable = 1;
54385 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54386 + if (unlikely(obj->mode & GR_WRITE))
54387 + task->is_writable = 1;
54388 +
54389 + gr_set_proc_res(task);
54390 +
54391 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54392 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54393 +#endif
54394 + } else {
54395 + return 1;
54396 + }
54397 +
54398 + return 0;
54399 +}
54400 +
54401 +int
54402 +gr_set_acls(const int type)
54403 +{
54404 + struct task_struct *task, *task2;
54405 + struct acl_role_label *role = current->role;
54406 + __u16 acl_role_id = current->acl_role_id;
54407 + const struct cred *cred;
54408 + int ret;
54409 +
54410 + rcu_read_lock();
54411 + read_lock(&tasklist_lock);
54412 + read_lock(&grsec_exec_file_lock);
54413 + do_each_thread(task2, task) {
54414 + /* check to see if we're called from the exit handler,
54415 + if so, only replace ACLs that have inherited the admin
54416 + ACL */
54417 +
54418 + if (type && (task->role != role ||
54419 + task->acl_role_id != acl_role_id))
54420 + continue;
54421 +
54422 + task->acl_role_id = 0;
54423 + task->acl_sp_role = 0;
54424 +
54425 + if (task->exec_file) {
54426 + cred = __task_cred(task);
54427 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54428 + ret = gr_apply_subject_to_task(task);
54429 + if (ret) {
54430 + read_unlock(&grsec_exec_file_lock);
54431 + read_unlock(&tasklist_lock);
54432 + rcu_read_unlock();
54433 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54434 + return ret;
54435 + }
54436 + } else {
54437 + // it's a kernel process
54438 + task->role = kernel_role;
54439 + task->acl = kernel_role->root_label;
54440 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54441 + task->acl->mode &= ~GR_PROCFIND;
54442 +#endif
54443 + }
54444 + } while_each_thread(task2, task);
54445 + read_unlock(&grsec_exec_file_lock);
54446 + read_unlock(&tasklist_lock);
54447 + rcu_read_unlock();
54448 +
54449 + return 0;
54450 +}
54451 +
54452 +void
54453 +gr_learn_resource(const struct task_struct *task,
54454 + const int res, const unsigned long wanted, const int gt)
54455 +{
54456 + struct acl_subject_label *acl;
54457 + const struct cred *cred;
54458 +
54459 + if (unlikely((gr_status & GR_READY) &&
54460 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54461 + goto skip_reslog;
54462 +
54463 +#ifdef CONFIG_GRKERNSEC_RESLOG
54464 + gr_log_resource(task, res, wanted, gt);
54465 +#endif
54466 + skip_reslog:
54467 +
54468 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54469 + return;
54470 +
54471 + acl = task->acl;
54472 +
54473 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54474 + !(acl->resmask & (1 << (unsigned short) res))))
54475 + return;
54476 +
54477 + if (wanted >= acl->res[res].rlim_cur) {
54478 + unsigned long res_add;
54479 +
54480 + res_add = wanted;
54481 + switch (res) {
54482 + case RLIMIT_CPU:
54483 + res_add += GR_RLIM_CPU_BUMP;
54484 + break;
54485 + case RLIMIT_FSIZE:
54486 + res_add += GR_RLIM_FSIZE_BUMP;
54487 + break;
54488 + case RLIMIT_DATA:
54489 + res_add += GR_RLIM_DATA_BUMP;
54490 + break;
54491 + case RLIMIT_STACK:
54492 + res_add += GR_RLIM_STACK_BUMP;
54493 + break;
54494 + case RLIMIT_CORE:
54495 + res_add += GR_RLIM_CORE_BUMP;
54496 + break;
54497 + case RLIMIT_RSS:
54498 + res_add += GR_RLIM_RSS_BUMP;
54499 + break;
54500 + case RLIMIT_NPROC:
54501 + res_add += GR_RLIM_NPROC_BUMP;
54502 + break;
54503 + case RLIMIT_NOFILE:
54504 + res_add += GR_RLIM_NOFILE_BUMP;
54505 + break;
54506 + case RLIMIT_MEMLOCK:
54507 + res_add += GR_RLIM_MEMLOCK_BUMP;
54508 + break;
54509 + case RLIMIT_AS:
54510 + res_add += GR_RLIM_AS_BUMP;
54511 + break;
54512 + case RLIMIT_LOCKS:
54513 + res_add += GR_RLIM_LOCKS_BUMP;
54514 + break;
54515 + case RLIMIT_SIGPENDING:
54516 + res_add += GR_RLIM_SIGPENDING_BUMP;
54517 + break;
54518 + case RLIMIT_MSGQUEUE:
54519 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54520 + break;
54521 + case RLIMIT_NICE:
54522 + res_add += GR_RLIM_NICE_BUMP;
54523 + break;
54524 + case RLIMIT_RTPRIO:
54525 + res_add += GR_RLIM_RTPRIO_BUMP;
54526 + break;
54527 + case RLIMIT_RTTIME:
54528 + res_add += GR_RLIM_RTTIME_BUMP;
54529 + break;
54530 + }
54531 +
54532 + acl->res[res].rlim_cur = res_add;
54533 +
54534 + if (wanted > acl->res[res].rlim_max)
54535 + acl->res[res].rlim_max = res_add;
54536 +
54537 + /* only log the subject filename, since resource logging is supported for
54538 + single-subject learning only */
54539 + rcu_read_lock();
54540 + cred = __task_cred(task);
54541 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54542 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54543 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54544 + "", (unsigned long) res, &task->signal->saved_ip);
54545 + rcu_read_unlock();
54546 + }
54547 +
54548 + return;
54549 +}
54550 +
54551 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54552 +void
54553 +pax_set_initial_flags(struct linux_binprm *bprm)
54554 +{
54555 + struct task_struct *task = current;
54556 + struct acl_subject_label *proc;
54557 + unsigned long flags;
54558 +
54559 + if (unlikely(!(gr_status & GR_READY)))
54560 + return;
54561 +
54562 + flags = pax_get_flags(task);
54563 +
54564 + proc = task->acl;
54565 +
54566 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54567 + flags &= ~MF_PAX_PAGEEXEC;
54568 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54569 + flags &= ~MF_PAX_SEGMEXEC;
54570 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54571 + flags &= ~MF_PAX_RANDMMAP;
54572 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54573 + flags &= ~MF_PAX_EMUTRAMP;
54574 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54575 + flags &= ~MF_PAX_MPROTECT;
54576 +
54577 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54578 + flags |= MF_PAX_PAGEEXEC;
54579 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54580 + flags |= MF_PAX_SEGMEXEC;
54581 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54582 + flags |= MF_PAX_RANDMMAP;
54583 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54584 + flags |= MF_PAX_EMUTRAMP;
54585 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54586 + flags |= MF_PAX_MPROTECT;
54587 +
54588 + pax_set_flags(task, flags);
54589 +
54590 + return;
54591 +}
54592 +#endif
54593 +
54594 +int
54595 +gr_handle_proc_ptrace(struct task_struct *task)
54596 +{
54597 + struct file *filp;
54598 + struct task_struct *tmp = task;
54599 + struct task_struct *curtemp = current;
54600 + __u32 retmode;
54601 +
54602 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54603 + if (unlikely(!(gr_status & GR_READY)))
54604 + return 0;
54605 +#endif
54606 +
54607 + read_lock(&tasklist_lock);
54608 + read_lock(&grsec_exec_file_lock);
54609 + filp = task->exec_file;
54610 +
54611 + while (tmp->pid > 0) {
54612 + if (tmp == curtemp)
54613 + break;
54614 + tmp = tmp->real_parent;
54615 + }
54616 +
54617 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54618 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54619 + read_unlock(&grsec_exec_file_lock);
54620 + read_unlock(&tasklist_lock);
54621 + return 1;
54622 + }
54623 +
54624 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54625 + if (!(gr_status & GR_READY)) {
54626 + read_unlock(&grsec_exec_file_lock);
54627 + read_unlock(&tasklist_lock);
54628 + return 0;
54629 + }
54630 +#endif
54631 +
54632 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54633 + read_unlock(&grsec_exec_file_lock);
54634 + read_unlock(&tasklist_lock);
54635 +
54636 + if (retmode & GR_NOPTRACE)
54637 + return 1;
54638 +
54639 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54640 + && (current->acl != task->acl || (current->acl != current->role->root_label
54641 + && current->pid != task->pid)))
54642 + return 1;
54643 +
54644 + return 0;
54645 +}
54646 +
54647 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54648 +{
54649 + if (unlikely(!(gr_status & GR_READY)))
54650 + return;
54651 +
54652 + if (!(current->role->roletype & GR_ROLE_GOD))
54653 + return;
54654 +
54655 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54656 + p->role->rolename, gr_task_roletype_to_char(p),
54657 + p->acl->filename);
54658 +}
54659 +
54660 +int
54661 +gr_handle_ptrace(struct task_struct *task, const long request)
54662 +{
54663 + struct task_struct *tmp = task;
54664 + struct task_struct *curtemp = current;
54665 + __u32 retmode;
54666 +
54667 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54668 + if (unlikely(!(gr_status & GR_READY)))
54669 + return 0;
54670 +#endif
54671 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54672 + read_lock(&tasklist_lock);
54673 + while (tmp->pid > 0) {
54674 + if (tmp == curtemp)
54675 + break;
54676 + tmp = tmp->real_parent;
54677 + }
54678 +
54679 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54680 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54681 + read_unlock(&tasklist_lock);
54682 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54683 + return 1;
54684 + }
54685 + read_unlock(&tasklist_lock);
54686 + }
54687 +
54688 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54689 + if (!(gr_status & GR_READY))
54690 + return 0;
54691 +#endif
54692 +
54693 + read_lock(&grsec_exec_file_lock);
54694 + if (unlikely(!task->exec_file)) {
54695 + read_unlock(&grsec_exec_file_lock);
54696 + return 0;
54697 + }
54698 +
54699 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54700 + read_unlock(&grsec_exec_file_lock);
54701 +
54702 + if (retmode & GR_NOPTRACE) {
54703 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54704 + return 1;
54705 + }
54706 +
54707 + if (retmode & GR_PTRACERD) {
54708 + switch (request) {
54709 + case PTRACE_SEIZE:
54710 + case PTRACE_POKETEXT:
54711 + case PTRACE_POKEDATA:
54712 + case PTRACE_POKEUSR:
54713 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54714 + case PTRACE_SETREGS:
54715 + case PTRACE_SETFPREGS:
54716 +#endif
54717 +#ifdef CONFIG_X86
54718 + case PTRACE_SETFPXREGS:
54719 +#endif
54720 +#ifdef CONFIG_ALTIVEC
54721 + case PTRACE_SETVRREGS:
54722 +#endif
54723 + return 1;
54724 + default:
54725 + return 0;
54726 + }
54727 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54728 + !(current->role->roletype & GR_ROLE_GOD) &&
54729 + (current->acl != task->acl)) {
54730 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54731 + return 1;
54732 + }
54733 +
54734 + return 0;
54735 +}
54736 +
54737 +static int is_writable_mmap(const struct file *filp)
54738 +{
54739 + struct task_struct *task = current;
54740 + struct acl_object_label *obj, *obj2;
54741 +
54742 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54743 + !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))) {
54744 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54745 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54746 + task->role->root_label);
54747 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54748 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54749 + return 1;
54750 + }
54751 + }
54752 + return 0;
54753 +}
54754 +
54755 +int
54756 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54757 +{
54758 + __u32 mode;
54759 +
54760 + if (unlikely(!file || !(prot & PROT_EXEC)))
54761 + return 1;
54762 +
54763 + if (is_writable_mmap(file))
54764 + return 0;
54765 +
54766 + mode =
54767 + gr_search_file(file->f_path.dentry,
54768 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54769 + file->f_path.mnt);
54770 +
54771 + if (!gr_tpe_allow(file))
54772 + return 0;
54773 +
54774 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54775 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54776 + return 0;
54777 + } else if (unlikely(!(mode & GR_EXEC))) {
54778 + return 0;
54779 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54780 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54781 + return 1;
54782 + }
54783 +
54784 + return 1;
54785 +}
54786 +
54787 +int
54788 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54789 +{
54790 + __u32 mode;
54791 +
54792 + if (unlikely(!file || !(prot & PROT_EXEC)))
54793 + return 1;
54794 +
54795 + if (is_writable_mmap(file))
54796 + return 0;
54797 +
54798 + mode =
54799 + gr_search_file(file->f_path.dentry,
54800 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54801 + file->f_path.mnt);
54802 +
54803 + if (!gr_tpe_allow(file))
54804 + return 0;
54805 +
54806 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54807 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54808 + return 0;
54809 + } else if (unlikely(!(mode & GR_EXEC))) {
54810 + return 0;
54811 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54812 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54813 + return 1;
54814 + }
54815 +
54816 + return 1;
54817 +}
54818 +
54819 +void
54820 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54821 +{
54822 + unsigned long runtime;
54823 + unsigned long cputime;
54824 + unsigned int wday, cday;
54825 + __u8 whr, chr;
54826 + __u8 wmin, cmin;
54827 + __u8 wsec, csec;
54828 + struct timespec timeval;
54829 +
54830 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54831 + !(task->acl->mode & GR_PROCACCT)))
54832 + return;
54833 +
54834 + do_posix_clock_monotonic_gettime(&timeval);
54835 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54836 + wday = runtime / (3600 * 24);
54837 + runtime -= wday * (3600 * 24);
54838 + whr = runtime / 3600;
54839 + runtime -= whr * 3600;
54840 + wmin = runtime / 60;
54841 + runtime -= wmin * 60;
54842 + wsec = runtime;
54843 +
54844 + cputime = (task->utime + task->stime) / HZ;
54845 + cday = cputime / (3600 * 24);
54846 + cputime -= cday * (3600 * 24);
54847 + chr = cputime / 3600;
54848 + cputime -= chr * 3600;
54849 + cmin = cputime / 60;
54850 + cputime -= cmin * 60;
54851 + csec = cputime;
54852 +
54853 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54854 +
54855 + return;
54856 +}
54857 +
54858 +void gr_set_kernel_label(struct task_struct *task)
54859 +{
54860 + if (gr_status & GR_READY) {
54861 + task->role = kernel_role;
54862 + task->acl = kernel_role->root_label;
54863 + }
54864 + return;
54865 +}
54866 +
54867 +#ifdef CONFIG_TASKSTATS
54868 +int gr_is_taskstats_denied(int pid)
54869 +{
54870 + struct task_struct *task;
54871 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54872 + const struct cred *cred;
54873 +#endif
54874 + int ret = 0;
54875 +
54876 + /* restrict taskstats viewing to un-chrooted root users
54877 + who have the 'view' subject flag if the RBAC system is enabled
54878 + */
54879 +
54880 + rcu_read_lock();
54881 + read_lock(&tasklist_lock);
54882 + task = find_task_by_vpid(pid);
54883 + if (task) {
54884 +#ifdef CONFIG_GRKERNSEC_CHROOT
54885 + if (proc_is_chrooted(task))
54886 + ret = -EACCES;
54887 +#endif
54888 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54889 + cred = __task_cred(task);
54890 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54891 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
54892 + ret = -EACCES;
54893 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54894 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54895 + ret = -EACCES;
54896 +#endif
54897 +#endif
54898 + if (gr_status & GR_READY) {
54899 + if (!(task->acl->mode & GR_VIEW))
54900 + ret = -EACCES;
54901 + }
54902 + } else
54903 + ret = -ENOENT;
54904 +
54905 + read_unlock(&tasklist_lock);
54906 + rcu_read_unlock();
54907 +
54908 + return ret;
54909 +}
54910 +#endif
54911 +
54912 +/* AUXV entries are filled via a descendant of search_binary_handler
54913 + after we've already applied the subject for the target
54914 +*/
54915 +int gr_acl_enable_at_secure(void)
54916 +{
54917 + if (unlikely(!(gr_status & GR_READY)))
54918 + return 0;
54919 +
54920 + if (current->acl->mode & GR_ATSECURE)
54921 + return 1;
54922 +
54923 + return 0;
54924 +}
54925 +
54926 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54927 +{
54928 + struct task_struct *task = current;
54929 + struct dentry *dentry = file->f_path.dentry;
54930 + struct vfsmount *mnt = file->f_path.mnt;
54931 + struct acl_object_label *obj, *tmp;
54932 + struct acl_subject_label *subj;
54933 + unsigned int bufsize;
54934 + int is_not_root;
54935 + char *path;
54936 + dev_t dev = __get_dev(dentry);
54937 +
54938 + if (unlikely(!(gr_status & GR_READY)))
54939 + return 1;
54940 +
54941 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54942 + return 1;
54943 +
54944 + /* ignore Eric Biederman */
54945 + if (IS_PRIVATE(dentry->d_inode))
54946 + return 1;
54947 +
54948 + subj = task->acl;
54949 + read_lock(&gr_inode_lock);
54950 + do {
54951 + obj = lookup_acl_obj_label(ino, dev, subj);
54952 + if (obj != NULL) {
54953 + read_unlock(&gr_inode_lock);
54954 + return (obj->mode & GR_FIND) ? 1 : 0;
54955 + }
54956 + } while ((subj = subj->parent_subject));
54957 + read_unlock(&gr_inode_lock);
54958 +
54959 + /* this is purely an optimization since we're looking for an object
54960 + for the directory we're doing a readdir on
54961 + if it's possible for any globbed object to match the entry we're
54962 + filling into the directory, then the object we find here will be
54963 + an anchor point with attached globbed objects
54964 + */
54965 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54966 + if (obj->globbed == NULL)
54967 + return (obj->mode & GR_FIND) ? 1 : 0;
54968 +
54969 + is_not_root = ((obj->filename[0] == '/') &&
54970 + (obj->filename[1] == '\0')) ? 0 : 1;
54971 + bufsize = PAGE_SIZE - namelen - is_not_root;
54972 +
54973 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54974 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54975 + return 1;
54976 +
54977 + preempt_disable();
54978 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54979 + bufsize);
54980 +
54981 + bufsize = strlen(path);
54982 +
54983 + /* if base is "/", don't append an additional slash */
54984 + if (is_not_root)
54985 + *(path + bufsize) = '/';
54986 + memcpy(path + bufsize + is_not_root, name, namelen);
54987 + *(path + bufsize + namelen + is_not_root) = '\0';
54988 +
54989 + tmp = obj->globbed;
54990 + while (tmp) {
54991 + if (!glob_match(tmp->filename, path)) {
54992 + preempt_enable();
54993 + return (tmp->mode & GR_FIND) ? 1 : 0;
54994 + }
54995 + tmp = tmp->next;
54996 + }
54997 + preempt_enable();
54998 + return (obj->mode & GR_FIND) ? 1 : 0;
54999 +}
55000 +
55001 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55002 +EXPORT_SYMBOL(gr_acl_is_enabled);
55003 +#endif
55004 +EXPORT_SYMBOL(gr_learn_resource);
55005 +EXPORT_SYMBOL(gr_set_kernel_label);
55006 +#ifdef CONFIG_SECURITY
55007 +EXPORT_SYMBOL(gr_check_user_change);
55008 +EXPORT_SYMBOL(gr_check_group_change);
55009 +#endif
55010 +
55011 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55012 new file mode 100644
55013 index 0000000..34fefda
55014 --- /dev/null
55015 +++ b/grsecurity/gracl_alloc.c
55016 @@ -0,0 +1,105 @@
55017 +#include <linux/kernel.h>
55018 +#include <linux/mm.h>
55019 +#include <linux/slab.h>
55020 +#include <linux/vmalloc.h>
55021 +#include <linux/gracl.h>
55022 +#include <linux/grsecurity.h>
55023 +
55024 +static unsigned long alloc_stack_next = 1;
55025 +static unsigned long alloc_stack_size = 1;
55026 +static void **alloc_stack;
55027 +
55028 +static __inline__ int
55029 +alloc_pop(void)
55030 +{
55031 + if (alloc_stack_next == 1)
55032 + return 0;
55033 +
55034 + kfree(alloc_stack[alloc_stack_next - 2]);
55035 +
55036 + alloc_stack_next--;
55037 +
55038 + return 1;
55039 +}
55040 +
55041 +static __inline__ int
55042 +alloc_push(void *buf)
55043 +{
55044 + if (alloc_stack_next >= alloc_stack_size)
55045 + return 1;
55046 +
55047 + alloc_stack[alloc_stack_next - 1] = buf;
55048 +
55049 + alloc_stack_next++;
55050 +
55051 + return 0;
55052 +}
55053 +
55054 +void *
55055 +acl_alloc(unsigned long len)
55056 +{
55057 + void *ret = NULL;
55058 +
55059 + if (!len || len > PAGE_SIZE)
55060 + goto out;
55061 +
55062 + ret = kmalloc(len, GFP_KERNEL);
55063 +
55064 + if (ret) {
55065 + if (alloc_push(ret)) {
55066 + kfree(ret);
55067 + ret = NULL;
55068 + }
55069 + }
55070 +
55071 +out:
55072 + return ret;
55073 +}
55074 +
55075 +void *
55076 +acl_alloc_num(unsigned long num, unsigned long len)
55077 +{
55078 + if (!len || (num > (PAGE_SIZE / len)))
55079 + return NULL;
55080 +
55081 + return acl_alloc(num * len);
55082 +}
55083 +
55084 +void
55085 +acl_free_all(void)
55086 +{
55087 + if (gr_acl_is_enabled() || !alloc_stack)
55088 + return;
55089 +
55090 + while (alloc_pop()) ;
55091 +
55092 + if (alloc_stack) {
55093 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55094 + kfree(alloc_stack);
55095 + else
55096 + vfree(alloc_stack);
55097 + }
55098 +
55099 + alloc_stack = NULL;
55100 + alloc_stack_size = 1;
55101 + alloc_stack_next = 1;
55102 +
55103 + return;
55104 +}
55105 +
55106 +int
55107 +acl_alloc_stack_init(unsigned long size)
55108 +{
55109 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55110 + alloc_stack =
55111 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55112 + else
55113 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55114 +
55115 + alloc_stack_size = size;
55116 +
55117 + if (!alloc_stack)
55118 + return 0;
55119 + else
55120 + return 1;
55121 +}
55122 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55123 new file mode 100644
55124 index 0000000..6d21049
55125 --- /dev/null
55126 +++ b/grsecurity/gracl_cap.c
55127 @@ -0,0 +1,110 @@
55128 +#include <linux/kernel.h>
55129 +#include <linux/module.h>
55130 +#include <linux/sched.h>
55131 +#include <linux/gracl.h>
55132 +#include <linux/grsecurity.h>
55133 +#include <linux/grinternal.h>
55134 +
55135 +extern const char *captab_log[];
55136 +extern int captab_log_entries;
55137 +
55138 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55139 +{
55140 + struct acl_subject_label *curracl;
55141 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55142 + kernel_cap_t cap_audit = __cap_empty_set;
55143 +
55144 + if (!gr_acl_is_enabled())
55145 + return 1;
55146 +
55147 + curracl = task->acl;
55148 +
55149 + cap_drop = curracl->cap_lower;
55150 + cap_mask = curracl->cap_mask;
55151 + cap_audit = curracl->cap_invert_audit;
55152 +
55153 + while ((curracl = curracl->parent_subject)) {
55154 + /* if the cap isn't specified in the current computed mask but is specified in the
55155 + current level subject, and is lowered in the current level subject, then add
55156 + it to the set of dropped capabilities
55157 + otherwise, add the current level subject's mask to the current computed mask
55158 + */
55159 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55160 + cap_raise(cap_mask, cap);
55161 + if (cap_raised(curracl->cap_lower, cap))
55162 + cap_raise(cap_drop, cap);
55163 + if (cap_raised(curracl->cap_invert_audit, cap))
55164 + cap_raise(cap_audit, cap);
55165 + }
55166 + }
55167 +
55168 + if (!cap_raised(cap_drop, cap)) {
55169 + if (cap_raised(cap_audit, cap))
55170 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55171 + return 1;
55172 + }
55173 +
55174 + curracl = task->acl;
55175 +
55176 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55177 + && cap_raised(cred->cap_effective, cap)) {
55178 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55179 + task->role->roletype, cred->uid,
55180 + cred->gid, task->exec_file ?
55181 + gr_to_filename(task->exec_file->f_path.dentry,
55182 + task->exec_file->f_path.mnt) : curracl->filename,
55183 + curracl->filename, 0UL,
55184 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55185 + return 1;
55186 + }
55187 +
55188 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55189 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55190 +
55191 + return 0;
55192 +}
55193 +
55194 +int
55195 +gr_acl_is_capable(const int cap)
55196 +{
55197 + return gr_task_acl_is_capable(current, current_cred(), cap);
55198 +}
55199 +
55200 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55201 +{
55202 + struct acl_subject_label *curracl;
55203 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55204 +
55205 + if (!gr_acl_is_enabled())
55206 + return 1;
55207 +
55208 + curracl = task->acl;
55209 +
55210 + cap_drop = curracl->cap_lower;
55211 + cap_mask = curracl->cap_mask;
55212 +
55213 + while ((curracl = curracl->parent_subject)) {
55214 + /* if the cap isn't specified in the current computed mask but is specified in the
55215 + current level subject, and is lowered in the current level subject, then add
55216 + it to the set of dropped capabilities
55217 + otherwise, add the current level subject's mask to the current computed mask
55218 + */
55219 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55220 + cap_raise(cap_mask, cap);
55221 + if (cap_raised(curracl->cap_lower, cap))
55222 + cap_raise(cap_drop, cap);
55223 + }
55224 + }
55225 +
55226 + if (!cap_raised(cap_drop, cap))
55227 + return 1;
55228 +
55229 + return 0;
55230 +}
55231 +
55232 +int
55233 +gr_acl_is_capable_nolog(const int cap)
55234 +{
55235 + return gr_task_acl_is_capable_nolog(current, cap);
55236 +}
55237 +
55238 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55239 new file mode 100644
55240 index 0000000..88d0e87
55241 --- /dev/null
55242 +++ b/grsecurity/gracl_fs.c
55243 @@ -0,0 +1,435 @@
55244 +#include <linux/kernel.h>
55245 +#include <linux/sched.h>
55246 +#include <linux/types.h>
55247 +#include <linux/fs.h>
55248 +#include <linux/file.h>
55249 +#include <linux/stat.h>
55250 +#include <linux/grsecurity.h>
55251 +#include <linux/grinternal.h>
55252 +#include <linux/gracl.h>
55253 +
55254 +umode_t
55255 +gr_acl_umask(void)
55256 +{
55257 + if (unlikely(!gr_acl_is_enabled()))
55258 + return 0;
55259 +
55260 + return current->role->umask;
55261 +}
55262 +
55263 +__u32
55264 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55265 + const struct vfsmount * mnt)
55266 +{
55267 + __u32 mode;
55268 +
55269 + if (unlikely(!dentry->d_inode))
55270 + return GR_FIND;
55271 +
55272 + mode =
55273 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55274 +
55275 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55276 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55277 + return mode;
55278 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55279 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55280 + return 0;
55281 + } else if (unlikely(!(mode & GR_FIND)))
55282 + return 0;
55283 +
55284 + return GR_FIND;
55285 +}
55286 +
55287 +__u32
55288 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55289 + int acc_mode)
55290 +{
55291 + __u32 reqmode = GR_FIND;
55292 + __u32 mode;
55293 +
55294 + if (unlikely(!dentry->d_inode))
55295 + return reqmode;
55296 +
55297 + if (acc_mode & MAY_APPEND)
55298 + reqmode |= GR_APPEND;
55299 + else if (acc_mode & MAY_WRITE)
55300 + reqmode |= GR_WRITE;
55301 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55302 + reqmode |= GR_READ;
55303 +
55304 + mode =
55305 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55306 + mnt);
55307 +
55308 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55309 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55310 + reqmode & GR_READ ? " reading" : "",
55311 + reqmode & GR_WRITE ? " writing" : reqmode &
55312 + GR_APPEND ? " appending" : "");
55313 + return reqmode;
55314 + } else
55315 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55316 + {
55317 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55318 + reqmode & GR_READ ? " reading" : "",
55319 + reqmode & GR_WRITE ? " writing" : reqmode &
55320 + GR_APPEND ? " appending" : "");
55321 + return 0;
55322 + } else if (unlikely((mode & reqmode) != reqmode))
55323 + return 0;
55324 +
55325 + return reqmode;
55326 +}
55327 +
55328 +__u32
55329 +gr_acl_handle_creat(const struct dentry * dentry,
55330 + const struct dentry * p_dentry,
55331 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55332 + const int imode)
55333 +{
55334 + __u32 reqmode = GR_WRITE | GR_CREATE;
55335 + __u32 mode;
55336 +
55337 + if (acc_mode & MAY_APPEND)
55338 + reqmode |= GR_APPEND;
55339 + // if a directory was required or the directory already exists, then
55340 + // don't count this open as a read
55341 + if ((acc_mode & MAY_READ) &&
55342 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55343 + reqmode |= GR_READ;
55344 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55345 + reqmode |= GR_SETID;
55346 +
55347 + mode =
55348 + gr_check_create(dentry, p_dentry, p_mnt,
55349 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55350 +
55351 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55352 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55353 + reqmode & GR_READ ? " reading" : "",
55354 + reqmode & GR_WRITE ? " writing" : reqmode &
55355 + GR_APPEND ? " appending" : "");
55356 + return reqmode;
55357 + } else
55358 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55359 + {
55360 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55361 + reqmode & GR_READ ? " reading" : "",
55362 + reqmode & GR_WRITE ? " writing" : reqmode &
55363 + GR_APPEND ? " appending" : "");
55364 + return 0;
55365 + } else if (unlikely((mode & reqmode) != reqmode))
55366 + return 0;
55367 +
55368 + return reqmode;
55369 +}
55370 +
55371 +__u32
55372 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55373 + const int fmode)
55374 +{
55375 + __u32 mode, reqmode = GR_FIND;
55376 +
55377 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55378 + reqmode |= GR_EXEC;
55379 + if (fmode & S_IWOTH)
55380 + reqmode |= GR_WRITE;
55381 + if (fmode & S_IROTH)
55382 + reqmode |= GR_READ;
55383 +
55384 + mode =
55385 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55386 + mnt);
55387 +
55388 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55389 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55390 + reqmode & GR_READ ? " reading" : "",
55391 + reqmode & GR_WRITE ? " writing" : "",
55392 + reqmode & GR_EXEC ? " executing" : "");
55393 + return reqmode;
55394 + } else
55395 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55396 + {
55397 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55398 + reqmode & GR_READ ? " reading" : "",
55399 + reqmode & GR_WRITE ? " writing" : "",
55400 + reqmode & GR_EXEC ? " executing" : "");
55401 + return 0;
55402 + } else if (unlikely((mode & reqmode) != reqmode))
55403 + return 0;
55404 +
55405 + return reqmode;
55406 +}
55407 +
55408 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55409 +{
55410 + __u32 mode;
55411 +
55412 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55413 +
55414 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55415 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55416 + return mode;
55417 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55418 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55419 + return 0;
55420 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55421 + return 0;
55422 +
55423 + return (reqmode);
55424 +}
55425 +
55426 +__u32
55427 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55428 +{
55429 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55430 +}
55431 +
55432 +__u32
55433 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55434 +{
55435 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55436 +}
55437 +
55438 +__u32
55439 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55440 +{
55441 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55442 +}
55443 +
55444 +__u32
55445 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55446 +{
55447 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55448 +}
55449 +
55450 +__u32
55451 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55452 + umode_t *modeptr)
55453 +{
55454 + umode_t mode;
55455 +
55456 + *modeptr &= ~gr_acl_umask();
55457 + mode = *modeptr;
55458 +
55459 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55460 + return 1;
55461 +
55462 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55463 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55464 + GR_CHMOD_ACL_MSG);
55465 + } else {
55466 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55467 + }
55468 +}
55469 +
55470 +__u32
55471 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55472 +{
55473 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55474 +}
55475 +
55476 +__u32
55477 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55478 +{
55479 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55480 +}
55481 +
55482 +__u32
55483 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55484 +{
55485 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55486 +}
55487 +
55488 +__u32
55489 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55490 +{
55491 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55492 + GR_UNIXCONNECT_ACL_MSG);
55493 +}
55494 +
55495 +/* hardlinks require at minimum create and link permission,
55496 + any additional privilege required is based on the
55497 + privilege of the file being linked to
55498 +*/
55499 +__u32
55500 +gr_acl_handle_link(const struct dentry * new_dentry,
55501 + const struct dentry * parent_dentry,
55502 + const struct vfsmount * parent_mnt,
55503 + const struct dentry * old_dentry,
55504 + const struct vfsmount * old_mnt, const char *to)
55505 +{
55506 + __u32 mode;
55507 + __u32 needmode = GR_CREATE | GR_LINK;
55508 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55509 +
55510 + mode =
55511 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55512 + old_mnt);
55513 +
55514 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55515 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55516 + return mode;
55517 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55518 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55519 + return 0;
55520 + } else if (unlikely((mode & needmode) != needmode))
55521 + return 0;
55522 +
55523 + return 1;
55524 +}
55525 +
55526 +__u32
55527 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55528 + const struct dentry * parent_dentry,
55529 + const struct vfsmount * parent_mnt, const char *from)
55530 +{
55531 + __u32 needmode = GR_WRITE | GR_CREATE;
55532 + __u32 mode;
55533 +
55534 + mode =
55535 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55536 + GR_CREATE | GR_AUDIT_CREATE |
55537 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55538 +
55539 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55540 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55541 + return mode;
55542 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55543 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55544 + return 0;
55545 + } else if (unlikely((mode & needmode) != needmode))
55546 + return 0;
55547 +
55548 + return (GR_WRITE | GR_CREATE);
55549 +}
55550 +
55551 +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)
55552 +{
55553 + __u32 mode;
55554 +
55555 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55556 +
55557 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55558 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55559 + return mode;
55560 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55561 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55562 + return 0;
55563 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55564 + return 0;
55565 +
55566 + return (reqmode);
55567 +}
55568 +
55569 +__u32
55570 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55571 + const struct dentry * parent_dentry,
55572 + const struct vfsmount * parent_mnt,
55573 + const int mode)
55574 +{
55575 + __u32 reqmode = GR_WRITE | GR_CREATE;
55576 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55577 + reqmode |= GR_SETID;
55578 +
55579 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55580 + reqmode, GR_MKNOD_ACL_MSG);
55581 +}
55582 +
55583 +__u32
55584 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55585 + const struct dentry *parent_dentry,
55586 + const struct vfsmount *parent_mnt)
55587 +{
55588 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55589 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55590 +}
55591 +
55592 +#define RENAME_CHECK_SUCCESS(old, new) \
55593 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55594 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55595 +
55596 +int
55597 +gr_acl_handle_rename(struct dentry *new_dentry,
55598 + struct dentry *parent_dentry,
55599 + const struct vfsmount *parent_mnt,
55600 + struct dentry *old_dentry,
55601 + struct inode *old_parent_inode,
55602 + struct vfsmount *old_mnt, const char *newname)
55603 +{
55604 + __u32 comp1, comp2;
55605 + int error = 0;
55606 +
55607 + if (unlikely(!gr_acl_is_enabled()))
55608 + return 0;
55609 +
55610 + if (!new_dentry->d_inode) {
55611 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55612 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55613 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55614 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55615 + GR_DELETE | GR_AUDIT_DELETE |
55616 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55617 + GR_SUPPRESS, old_mnt);
55618 + } else {
55619 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55620 + GR_CREATE | GR_DELETE |
55621 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55622 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55623 + GR_SUPPRESS, parent_mnt);
55624 + comp2 =
55625 + gr_search_file(old_dentry,
55626 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55627 + GR_DELETE | GR_AUDIT_DELETE |
55628 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55629 + }
55630 +
55631 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55632 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55633 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55634 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55635 + && !(comp2 & GR_SUPPRESS)) {
55636 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55637 + error = -EACCES;
55638 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55639 + error = -EACCES;
55640 +
55641 + return error;
55642 +}
55643 +
55644 +void
55645 +gr_acl_handle_exit(void)
55646 +{
55647 + u16 id;
55648 + char *rolename;
55649 + struct file *exec_file;
55650 +
55651 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55652 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55653 + id = current->acl_role_id;
55654 + rolename = current->role->rolename;
55655 + gr_set_acls(1);
55656 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55657 + }
55658 +
55659 + write_lock(&grsec_exec_file_lock);
55660 + exec_file = current->exec_file;
55661 + current->exec_file = NULL;
55662 + write_unlock(&grsec_exec_file_lock);
55663 +
55664 + if (exec_file)
55665 + fput(exec_file);
55666 +}
55667 +
55668 +int
55669 +gr_acl_handle_procpidmem(const struct task_struct *task)
55670 +{
55671 + if (unlikely(!gr_acl_is_enabled()))
55672 + return 0;
55673 +
55674 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55675 + return -EACCES;
55676 +
55677 + return 0;
55678 +}
55679 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55680 new file mode 100644
55681 index 0000000..58800a7
55682 --- /dev/null
55683 +++ b/grsecurity/gracl_ip.c
55684 @@ -0,0 +1,384 @@
55685 +#include <linux/kernel.h>
55686 +#include <asm/uaccess.h>
55687 +#include <asm/errno.h>
55688 +#include <net/sock.h>
55689 +#include <linux/file.h>
55690 +#include <linux/fs.h>
55691 +#include <linux/net.h>
55692 +#include <linux/in.h>
55693 +#include <linux/skbuff.h>
55694 +#include <linux/ip.h>
55695 +#include <linux/udp.h>
55696 +#include <linux/types.h>
55697 +#include <linux/sched.h>
55698 +#include <linux/netdevice.h>
55699 +#include <linux/inetdevice.h>
55700 +#include <linux/gracl.h>
55701 +#include <linux/grsecurity.h>
55702 +#include <linux/grinternal.h>
55703 +
55704 +#define GR_BIND 0x01
55705 +#define GR_CONNECT 0x02
55706 +#define GR_INVERT 0x04
55707 +#define GR_BINDOVERRIDE 0x08
55708 +#define GR_CONNECTOVERRIDE 0x10
55709 +#define GR_SOCK_FAMILY 0x20
55710 +
55711 +static const char * gr_protocols[IPPROTO_MAX] = {
55712 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55713 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55714 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55715 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55716 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55717 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55718 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55719 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55720 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55721 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55722 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55723 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55724 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55725 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55726 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55727 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55728 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55729 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55730 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55731 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55732 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55733 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55734 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55735 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55736 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55737 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55738 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55739 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55740 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55741 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55742 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55743 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55744 + };
55745 +
55746 +static const char * gr_socktypes[SOCK_MAX] = {
55747 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55748 + "unknown:7", "unknown:8", "unknown:9", "packet"
55749 + };
55750 +
55751 +static const char * gr_sockfamilies[AF_MAX+1] = {
55752 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55753 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55754 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55755 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55756 + };
55757 +
55758 +const char *
55759 +gr_proto_to_name(unsigned char proto)
55760 +{
55761 + return gr_protocols[proto];
55762 +}
55763 +
55764 +const char *
55765 +gr_socktype_to_name(unsigned char type)
55766 +{
55767 + return gr_socktypes[type];
55768 +}
55769 +
55770 +const char *
55771 +gr_sockfamily_to_name(unsigned char family)
55772 +{
55773 + return gr_sockfamilies[family];
55774 +}
55775 +
55776 +int
55777 +gr_search_socket(const int domain, const int type, const int protocol)
55778 +{
55779 + struct acl_subject_label *curr;
55780 + const struct cred *cred = current_cred();
55781 +
55782 + if (unlikely(!gr_acl_is_enabled()))
55783 + goto exit;
55784 +
55785 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55786 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55787 + goto exit; // let the kernel handle it
55788 +
55789 + curr = current->acl;
55790 +
55791 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55792 + /* the family is allowed, if this is PF_INET allow it only if
55793 + the extra sock type/protocol checks pass */
55794 + if (domain == PF_INET)
55795 + goto inet_check;
55796 + goto exit;
55797 + } else {
55798 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55799 + __u32 fakeip = 0;
55800 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55801 + current->role->roletype, cred->uid,
55802 + cred->gid, current->exec_file ?
55803 + gr_to_filename(current->exec_file->f_path.dentry,
55804 + current->exec_file->f_path.mnt) :
55805 + curr->filename, curr->filename,
55806 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55807 + &current->signal->saved_ip);
55808 + goto exit;
55809 + }
55810 + goto exit_fail;
55811 + }
55812 +
55813 +inet_check:
55814 + /* the rest of this checking is for IPv4 only */
55815 + if (!curr->ips)
55816 + goto exit;
55817 +
55818 + if ((curr->ip_type & (1 << type)) &&
55819 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55820 + goto exit;
55821 +
55822 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55823 + /* we don't place acls on raw sockets , and sometimes
55824 + dgram/ip sockets are opened for ioctl and not
55825 + bind/connect, so we'll fake a bind learn log */
55826 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55827 + __u32 fakeip = 0;
55828 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55829 + current->role->roletype, cred->uid,
55830 + cred->gid, current->exec_file ?
55831 + gr_to_filename(current->exec_file->f_path.dentry,
55832 + current->exec_file->f_path.mnt) :
55833 + curr->filename, curr->filename,
55834 + &fakeip, 0, type,
55835 + protocol, GR_CONNECT, &current->signal->saved_ip);
55836 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55837 + __u32 fakeip = 0;
55838 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55839 + current->role->roletype, cred->uid,
55840 + cred->gid, current->exec_file ?
55841 + gr_to_filename(current->exec_file->f_path.dentry,
55842 + current->exec_file->f_path.mnt) :
55843 + curr->filename, curr->filename,
55844 + &fakeip, 0, type,
55845 + protocol, GR_BIND, &current->signal->saved_ip);
55846 + }
55847 + /* we'll log when they use connect or bind */
55848 + goto exit;
55849 + }
55850 +
55851 +exit_fail:
55852 + if (domain == PF_INET)
55853 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55854 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55855 + else
55856 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55857 + gr_socktype_to_name(type), protocol);
55858 +
55859 + return 0;
55860 +exit:
55861 + return 1;
55862 +}
55863 +
55864 +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)
55865 +{
55866 + if ((ip->mode & mode) &&
55867 + (ip_port >= ip->low) &&
55868 + (ip_port <= ip->high) &&
55869 + ((ntohl(ip_addr) & our_netmask) ==
55870 + (ntohl(our_addr) & our_netmask))
55871 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55872 + && (ip->type & (1 << type))) {
55873 + if (ip->mode & GR_INVERT)
55874 + return 2; // specifically denied
55875 + else
55876 + return 1; // allowed
55877 + }
55878 +
55879 + return 0; // not specifically allowed, may continue parsing
55880 +}
55881 +
55882 +static int
55883 +gr_search_connectbind(const int full_mode, struct sock *sk,
55884 + struct sockaddr_in *addr, const int type)
55885 +{
55886 + char iface[IFNAMSIZ] = {0};
55887 + struct acl_subject_label *curr;
55888 + struct acl_ip_label *ip;
55889 + struct inet_sock *isk;
55890 + struct net_device *dev;
55891 + struct in_device *idev;
55892 + unsigned long i;
55893 + int ret;
55894 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55895 + __u32 ip_addr = 0;
55896 + __u32 our_addr;
55897 + __u32 our_netmask;
55898 + char *p;
55899 + __u16 ip_port = 0;
55900 + const struct cred *cred = current_cred();
55901 +
55902 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55903 + return 0;
55904 +
55905 + curr = current->acl;
55906 + isk = inet_sk(sk);
55907 +
55908 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55909 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55910 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55911 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55912 + struct sockaddr_in saddr;
55913 + int err;
55914 +
55915 + saddr.sin_family = AF_INET;
55916 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55917 + saddr.sin_port = isk->inet_sport;
55918 +
55919 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55920 + if (err)
55921 + return err;
55922 +
55923 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55924 + if (err)
55925 + return err;
55926 + }
55927 +
55928 + if (!curr->ips)
55929 + return 0;
55930 +
55931 + ip_addr = addr->sin_addr.s_addr;
55932 + ip_port = ntohs(addr->sin_port);
55933 +
55934 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55935 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55936 + current->role->roletype, cred->uid,
55937 + cred->gid, current->exec_file ?
55938 + gr_to_filename(current->exec_file->f_path.dentry,
55939 + current->exec_file->f_path.mnt) :
55940 + curr->filename, curr->filename,
55941 + &ip_addr, ip_port, type,
55942 + sk->sk_protocol, mode, &current->signal->saved_ip);
55943 + return 0;
55944 + }
55945 +
55946 + for (i = 0; i < curr->ip_num; i++) {
55947 + ip = *(curr->ips + i);
55948 + if (ip->iface != NULL) {
55949 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55950 + p = strchr(iface, ':');
55951 + if (p != NULL)
55952 + *p = '\0';
55953 + dev = dev_get_by_name(sock_net(sk), iface);
55954 + if (dev == NULL)
55955 + continue;
55956 + idev = in_dev_get(dev);
55957 + if (idev == NULL) {
55958 + dev_put(dev);
55959 + continue;
55960 + }
55961 + rcu_read_lock();
55962 + for_ifa(idev) {
55963 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55964 + our_addr = ifa->ifa_address;
55965 + our_netmask = 0xffffffff;
55966 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55967 + if (ret == 1) {
55968 + rcu_read_unlock();
55969 + in_dev_put(idev);
55970 + dev_put(dev);
55971 + return 0;
55972 + } else if (ret == 2) {
55973 + rcu_read_unlock();
55974 + in_dev_put(idev);
55975 + dev_put(dev);
55976 + goto denied;
55977 + }
55978 + }
55979 + } endfor_ifa(idev);
55980 + rcu_read_unlock();
55981 + in_dev_put(idev);
55982 + dev_put(dev);
55983 + } else {
55984 + our_addr = ip->addr;
55985 + our_netmask = ip->netmask;
55986 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55987 + if (ret == 1)
55988 + return 0;
55989 + else if (ret == 2)
55990 + goto denied;
55991 + }
55992 + }
55993 +
55994 +denied:
55995 + if (mode == GR_BIND)
55996 + 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));
55997 + else if (mode == GR_CONNECT)
55998 + 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));
55999 +
56000 + return -EACCES;
56001 +}
56002 +
56003 +int
56004 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56005 +{
56006 + /* always allow disconnection of dgram sockets with connect */
56007 + if (addr->sin_family == AF_UNSPEC)
56008 + return 0;
56009 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56010 +}
56011 +
56012 +int
56013 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56014 +{
56015 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56016 +}
56017 +
56018 +int gr_search_listen(struct socket *sock)
56019 +{
56020 + struct sock *sk = sock->sk;
56021 + struct sockaddr_in addr;
56022 +
56023 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56024 + addr.sin_port = inet_sk(sk)->inet_sport;
56025 +
56026 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56027 +}
56028 +
56029 +int gr_search_accept(struct socket *sock)
56030 +{
56031 + struct sock *sk = sock->sk;
56032 + struct sockaddr_in addr;
56033 +
56034 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56035 + addr.sin_port = inet_sk(sk)->inet_sport;
56036 +
56037 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56038 +}
56039 +
56040 +int
56041 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56042 +{
56043 + if (addr)
56044 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56045 + else {
56046 + struct sockaddr_in sin;
56047 + const struct inet_sock *inet = inet_sk(sk);
56048 +
56049 + sin.sin_addr.s_addr = inet->inet_daddr;
56050 + sin.sin_port = inet->inet_dport;
56051 +
56052 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56053 + }
56054 +}
56055 +
56056 +int
56057 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56058 +{
56059 + struct sockaddr_in sin;
56060 +
56061 + if (unlikely(skb->len < sizeof (struct udphdr)))
56062 + return 0; // skip this packet
56063 +
56064 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56065 + sin.sin_port = udp_hdr(skb)->source;
56066 +
56067 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56068 +}
56069 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56070 new file mode 100644
56071 index 0000000..25f54ef
56072 --- /dev/null
56073 +++ b/grsecurity/gracl_learn.c
56074 @@ -0,0 +1,207 @@
56075 +#include <linux/kernel.h>
56076 +#include <linux/mm.h>
56077 +#include <linux/sched.h>
56078 +#include <linux/poll.h>
56079 +#include <linux/string.h>
56080 +#include <linux/file.h>
56081 +#include <linux/types.h>
56082 +#include <linux/vmalloc.h>
56083 +#include <linux/grinternal.h>
56084 +
56085 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56086 + size_t count, loff_t *ppos);
56087 +extern int gr_acl_is_enabled(void);
56088 +
56089 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56090 +static int gr_learn_attached;
56091 +
56092 +/* use a 512k buffer */
56093 +#define LEARN_BUFFER_SIZE (512 * 1024)
56094 +
56095 +static DEFINE_SPINLOCK(gr_learn_lock);
56096 +static DEFINE_MUTEX(gr_learn_user_mutex);
56097 +
56098 +/* we need to maintain two buffers, so that the kernel context of grlearn
56099 + uses a semaphore around the userspace copying, and the other kernel contexts
56100 + use a spinlock when copying into the buffer, since they cannot sleep
56101 +*/
56102 +static char *learn_buffer;
56103 +static char *learn_buffer_user;
56104 +static int learn_buffer_len;
56105 +static int learn_buffer_user_len;
56106 +
56107 +static ssize_t
56108 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56109 +{
56110 + DECLARE_WAITQUEUE(wait, current);
56111 + ssize_t retval = 0;
56112 +
56113 + add_wait_queue(&learn_wait, &wait);
56114 + set_current_state(TASK_INTERRUPTIBLE);
56115 + do {
56116 + mutex_lock(&gr_learn_user_mutex);
56117 + spin_lock(&gr_learn_lock);
56118 + if (learn_buffer_len)
56119 + break;
56120 + spin_unlock(&gr_learn_lock);
56121 + mutex_unlock(&gr_learn_user_mutex);
56122 + if (file->f_flags & O_NONBLOCK) {
56123 + retval = -EAGAIN;
56124 + goto out;
56125 + }
56126 + if (signal_pending(current)) {
56127 + retval = -ERESTARTSYS;
56128 + goto out;
56129 + }
56130 +
56131 + schedule();
56132 + } while (1);
56133 +
56134 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56135 + learn_buffer_user_len = learn_buffer_len;
56136 + retval = learn_buffer_len;
56137 + learn_buffer_len = 0;
56138 +
56139 + spin_unlock(&gr_learn_lock);
56140 +
56141 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56142 + retval = -EFAULT;
56143 +
56144 + mutex_unlock(&gr_learn_user_mutex);
56145 +out:
56146 + set_current_state(TASK_RUNNING);
56147 + remove_wait_queue(&learn_wait, &wait);
56148 + return retval;
56149 +}
56150 +
56151 +static unsigned int
56152 +poll_learn(struct file * file, poll_table * wait)
56153 +{
56154 + poll_wait(file, &learn_wait, wait);
56155 +
56156 + if (learn_buffer_len)
56157 + return (POLLIN | POLLRDNORM);
56158 +
56159 + return 0;
56160 +}
56161 +
56162 +void
56163 +gr_clear_learn_entries(void)
56164 +{
56165 + char *tmp;
56166 +
56167 + mutex_lock(&gr_learn_user_mutex);
56168 + spin_lock(&gr_learn_lock);
56169 + tmp = learn_buffer;
56170 + learn_buffer = NULL;
56171 + spin_unlock(&gr_learn_lock);
56172 + if (tmp)
56173 + vfree(tmp);
56174 + if (learn_buffer_user != NULL) {
56175 + vfree(learn_buffer_user);
56176 + learn_buffer_user = NULL;
56177 + }
56178 + learn_buffer_len = 0;
56179 + mutex_unlock(&gr_learn_user_mutex);
56180 +
56181 + return;
56182 +}
56183 +
56184 +void
56185 +gr_add_learn_entry(const char *fmt, ...)
56186 +{
56187 + va_list args;
56188 + unsigned int len;
56189 +
56190 + if (!gr_learn_attached)
56191 + return;
56192 +
56193 + spin_lock(&gr_learn_lock);
56194 +
56195 + /* leave a gap at the end so we know when it's "full" but don't have to
56196 + compute the exact length of the string we're trying to append
56197 + */
56198 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56199 + spin_unlock(&gr_learn_lock);
56200 + wake_up_interruptible(&learn_wait);
56201 + return;
56202 + }
56203 + if (learn_buffer == NULL) {
56204 + spin_unlock(&gr_learn_lock);
56205 + return;
56206 + }
56207 +
56208 + va_start(args, fmt);
56209 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56210 + va_end(args);
56211 +
56212 + learn_buffer_len += len + 1;
56213 +
56214 + spin_unlock(&gr_learn_lock);
56215 + wake_up_interruptible(&learn_wait);
56216 +
56217 + return;
56218 +}
56219 +
56220 +static int
56221 +open_learn(struct inode *inode, struct file *file)
56222 +{
56223 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56224 + return -EBUSY;
56225 + if (file->f_mode & FMODE_READ) {
56226 + int retval = 0;
56227 + mutex_lock(&gr_learn_user_mutex);
56228 + if (learn_buffer == NULL)
56229 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56230 + if (learn_buffer_user == NULL)
56231 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56232 + if (learn_buffer == NULL) {
56233 + retval = -ENOMEM;
56234 + goto out_error;
56235 + }
56236 + if (learn_buffer_user == NULL) {
56237 + retval = -ENOMEM;
56238 + goto out_error;
56239 + }
56240 + learn_buffer_len = 0;
56241 + learn_buffer_user_len = 0;
56242 + gr_learn_attached = 1;
56243 +out_error:
56244 + mutex_unlock(&gr_learn_user_mutex);
56245 + return retval;
56246 + }
56247 + return 0;
56248 +}
56249 +
56250 +static int
56251 +close_learn(struct inode *inode, struct file *file)
56252 +{
56253 + if (file->f_mode & FMODE_READ) {
56254 + char *tmp = NULL;
56255 + mutex_lock(&gr_learn_user_mutex);
56256 + spin_lock(&gr_learn_lock);
56257 + tmp = learn_buffer;
56258 + learn_buffer = NULL;
56259 + spin_unlock(&gr_learn_lock);
56260 + if (tmp)
56261 + vfree(tmp);
56262 + if (learn_buffer_user != NULL) {
56263 + vfree(learn_buffer_user);
56264 + learn_buffer_user = NULL;
56265 + }
56266 + learn_buffer_len = 0;
56267 + learn_buffer_user_len = 0;
56268 + gr_learn_attached = 0;
56269 + mutex_unlock(&gr_learn_user_mutex);
56270 + }
56271 +
56272 + return 0;
56273 +}
56274 +
56275 +const struct file_operations grsec_fops = {
56276 + .read = read_learn,
56277 + .write = write_grsec_handler,
56278 + .open = open_learn,
56279 + .release = close_learn,
56280 + .poll = poll_learn,
56281 +};
56282 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56283 new file mode 100644
56284 index 0000000..39645c9
56285 --- /dev/null
56286 +++ b/grsecurity/gracl_res.c
56287 @@ -0,0 +1,68 @@
56288 +#include <linux/kernel.h>
56289 +#include <linux/sched.h>
56290 +#include <linux/gracl.h>
56291 +#include <linux/grinternal.h>
56292 +
56293 +static const char *restab_log[] = {
56294 + [RLIMIT_CPU] = "RLIMIT_CPU",
56295 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56296 + [RLIMIT_DATA] = "RLIMIT_DATA",
56297 + [RLIMIT_STACK] = "RLIMIT_STACK",
56298 + [RLIMIT_CORE] = "RLIMIT_CORE",
56299 + [RLIMIT_RSS] = "RLIMIT_RSS",
56300 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56301 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56302 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56303 + [RLIMIT_AS] = "RLIMIT_AS",
56304 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56305 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56306 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56307 + [RLIMIT_NICE] = "RLIMIT_NICE",
56308 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56309 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56310 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56311 +};
56312 +
56313 +void
56314 +gr_log_resource(const struct task_struct *task,
56315 + const int res, const unsigned long wanted, const int gt)
56316 +{
56317 + const struct cred *cred;
56318 + unsigned long rlim;
56319 +
56320 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56321 + return;
56322 +
56323 + // not yet supported resource
56324 + if (unlikely(!restab_log[res]))
56325 + return;
56326 +
56327 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56328 + rlim = task_rlimit_max(task, res);
56329 + else
56330 + rlim = task_rlimit(task, res);
56331 +
56332 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56333 + return;
56334 +
56335 + rcu_read_lock();
56336 + cred = __task_cred(task);
56337 +
56338 + if (res == RLIMIT_NPROC &&
56339 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56340 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56341 + goto out_rcu_unlock;
56342 + else if (res == RLIMIT_MEMLOCK &&
56343 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56344 + goto out_rcu_unlock;
56345 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56346 + goto out_rcu_unlock;
56347 + rcu_read_unlock();
56348 +
56349 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56350 +
56351 + return;
56352 +out_rcu_unlock:
56353 + rcu_read_unlock();
56354 + return;
56355 +}
56356 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56357 new file mode 100644
56358 index 0000000..25197e9
56359 --- /dev/null
56360 +++ b/grsecurity/gracl_segv.c
56361 @@ -0,0 +1,299 @@
56362 +#include <linux/kernel.h>
56363 +#include <linux/mm.h>
56364 +#include <asm/uaccess.h>
56365 +#include <asm/errno.h>
56366 +#include <asm/mman.h>
56367 +#include <net/sock.h>
56368 +#include <linux/file.h>
56369 +#include <linux/fs.h>
56370 +#include <linux/net.h>
56371 +#include <linux/in.h>
56372 +#include <linux/slab.h>
56373 +#include <linux/types.h>
56374 +#include <linux/sched.h>
56375 +#include <linux/timer.h>
56376 +#include <linux/gracl.h>
56377 +#include <linux/grsecurity.h>
56378 +#include <linux/grinternal.h>
56379 +
56380 +static struct crash_uid *uid_set;
56381 +static unsigned short uid_used;
56382 +static DEFINE_SPINLOCK(gr_uid_lock);
56383 +extern rwlock_t gr_inode_lock;
56384 +extern struct acl_subject_label *
56385 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56386 + struct acl_role_label *role);
56387 +
56388 +#ifdef CONFIG_BTRFS_FS
56389 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56390 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56391 +#endif
56392 +
56393 +static inline dev_t __get_dev(const struct dentry *dentry)
56394 +{
56395 +#ifdef CONFIG_BTRFS_FS
56396 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56397 + return get_btrfs_dev_from_inode(dentry->d_inode);
56398 + else
56399 +#endif
56400 + return dentry->d_inode->i_sb->s_dev;
56401 +}
56402 +
56403 +int
56404 +gr_init_uidset(void)
56405 +{
56406 + uid_set =
56407 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56408 + uid_used = 0;
56409 +
56410 + return uid_set ? 1 : 0;
56411 +}
56412 +
56413 +void
56414 +gr_free_uidset(void)
56415 +{
56416 + if (uid_set)
56417 + kfree(uid_set);
56418 +
56419 + return;
56420 +}
56421 +
56422 +int
56423 +gr_find_uid(const uid_t uid)
56424 +{
56425 + struct crash_uid *tmp = uid_set;
56426 + uid_t buid;
56427 + int low = 0, high = uid_used - 1, mid;
56428 +
56429 + while (high >= low) {
56430 + mid = (low + high) >> 1;
56431 + buid = tmp[mid].uid;
56432 + if (buid == uid)
56433 + return mid;
56434 + if (buid > uid)
56435 + high = mid - 1;
56436 + if (buid < uid)
56437 + low = mid + 1;
56438 + }
56439 +
56440 + return -1;
56441 +}
56442 +
56443 +static __inline__ void
56444 +gr_insertsort(void)
56445 +{
56446 + unsigned short i, j;
56447 + struct crash_uid index;
56448 +
56449 + for (i = 1; i < uid_used; i++) {
56450 + index = uid_set[i];
56451 + j = i;
56452 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56453 + uid_set[j] = uid_set[j - 1];
56454 + j--;
56455 + }
56456 + uid_set[j] = index;
56457 + }
56458 +
56459 + return;
56460 +}
56461 +
56462 +static __inline__ void
56463 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56464 +{
56465 + int loc;
56466 +
56467 + if (uid_used == GR_UIDTABLE_MAX)
56468 + return;
56469 +
56470 + loc = gr_find_uid(uid);
56471 +
56472 + if (loc >= 0) {
56473 + uid_set[loc].expires = expires;
56474 + return;
56475 + }
56476 +
56477 + uid_set[uid_used].uid = uid;
56478 + uid_set[uid_used].expires = expires;
56479 + uid_used++;
56480 +
56481 + gr_insertsort();
56482 +
56483 + return;
56484 +}
56485 +
56486 +void
56487 +gr_remove_uid(const unsigned short loc)
56488 +{
56489 + unsigned short i;
56490 +
56491 + for (i = loc + 1; i < uid_used; i++)
56492 + uid_set[i - 1] = uid_set[i];
56493 +
56494 + uid_used--;
56495 +
56496 + return;
56497 +}
56498 +
56499 +int
56500 +gr_check_crash_uid(const uid_t uid)
56501 +{
56502 + int loc;
56503 + int ret = 0;
56504 +
56505 + if (unlikely(!gr_acl_is_enabled()))
56506 + return 0;
56507 +
56508 + spin_lock(&gr_uid_lock);
56509 + loc = gr_find_uid(uid);
56510 +
56511 + if (loc < 0)
56512 + goto out_unlock;
56513 +
56514 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56515 + gr_remove_uid(loc);
56516 + else
56517 + ret = 1;
56518 +
56519 +out_unlock:
56520 + spin_unlock(&gr_uid_lock);
56521 + return ret;
56522 +}
56523 +
56524 +static __inline__ int
56525 +proc_is_setxid(const struct cred *cred)
56526 +{
56527 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56528 + !uid_eq(cred->uid, cred->fsuid))
56529 + return 1;
56530 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56531 + !uid_eq(cred->gid, cred->fsgid))
56532 + return 1;
56533 +
56534 + return 0;
56535 +}
56536 +
56537 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56538 +
56539 +void
56540 +gr_handle_crash(struct task_struct *task, const int sig)
56541 +{
56542 + struct acl_subject_label *curr;
56543 + struct task_struct *tsk, *tsk2;
56544 + const struct cred *cred;
56545 + const struct cred *cred2;
56546 +
56547 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56548 + return;
56549 +
56550 + if (unlikely(!gr_acl_is_enabled()))
56551 + return;
56552 +
56553 + curr = task->acl;
56554 +
56555 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56556 + return;
56557 +
56558 + if (time_before_eq(curr->expires, get_seconds())) {
56559 + curr->expires = 0;
56560 + curr->crashes = 0;
56561 + }
56562 +
56563 + curr->crashes++;
56564 +
56565 + if (!curr->expires)
56566 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56567 +
56568 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56569 + time_after(curr->expires, get_seconds())) {
56570 + rcu_read_lock();
56571 + cred = __task_cred(task);
56572 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56573 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56574 + spin_lock(&gr_uid_lock);
56575 + gr_insert_uid(cred->uid, curr->expires);
56576 + spin_unlock(&gr_uid_lock);
56577 + curr->expires = 0;
56578 + curr->crashes = 0;
56579 + read_lock(&tasklist_lock);
56580 + do_each_thread(tsk2, tsk) {
56581 + cred2 = __task_cred(tsk);
56582 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
56583 + gr_fake_force_sig(SIGKILL, tsk);
56584 + } while_each_thread(tsk2, tsk);
56585 + read_unlock(&tasklist_lock);
56586 + } else {
56587 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56588 + read_lock(&tasklist_lock);
56589 + read_lock(&grsec_exec_file_lock);
56590 + do_each_thread(tsk2, tsk) {
56591 + if (likely(tsk != task)) {
56592 + // if this thread has the same subject as the one that triggered
56593 + // RES_CRASH and it's the same binary, kill it
56594 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56595 + gr_fake_force_sig(SIGKILL, tsk);
56596 + }
56597 + } while_each_thread(tsk2, tsk);
56598 + read_unlock(&grsec_exec_file_lock);
56599 + read_unlock(&tasklist_lock);
56600 + }
56601 + rcu_read_unlock();
56602 + }
56603 +
56604 + return;
56605 +}
56606 +
56607 +int
56608 +gr_check_crash_exec(const struct file *filp)
56609 +{
56610 + struct acl_subject_label *curr;
56611 +
56612 + if (unlikely(!gr_acl_is_enabled()))
56613 + return 0;
56614 +
56615 + read_lock(&gr_inode_lock);
56616 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56617 + __get_dev(filp->f_path.dentry),
56618 + current->role);
56619 + read_unlock(&gr_inode_lock);
56620 +
56621 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56622 + (!curr->crashes && !curr->expires))
56623 + return 0;
56624 +
56625 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56626 + time_after(curr->expires, get_seconds()))
56627 + return 1;
56628 + else if (time_before_eq(curr->expires, get_seconds())) {
56629 + curr->crashes = 0;
56630 + curr->expires = 0;
56631 + }
56632 +
56633 + return 0;
56634 +}
56635 +
56636 +void
56637 +gr_handle_alertkill(struct task_struct *task)
56638 +{
56639 + struct acl_subject_label *curracl;
56640 + __u32 curr_ip;
56641 + struct task_struct *p, *p2;
56642 +
56643 + if (unlikely(!gr_acl_is_enabled()))
56644 + return;
56645 +
56646 + curracl = task->acl;
56647 + curr_ip = task->signal->curr_ip;
56648 +
56649 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56650 + read_lock(&tasklist_lock);
56651 + do_each_thread(p2, p) {
56652 + if (p->signal->curr_ip == curr_ip)
56653 + gr_fake_force_sig(SIGKILL, p);
56654 + } while_each_thread(p2, p);
56655 + read_unlock(&tasklist_lock);
56656 + } else if (curracl->mode & GR_KILLPROC)
56657 + gr_fake_force_sig(SIGKILL, task);
56658 +
56659 + return;
56660 +}
56661 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56662 new file mode 100644
56663 index 0000000..9d83a69
56664 --- /dev/null
56665 +++ b/grsecurity/gracl_shm.c
56666 @@ -0,0 +1,40 @@
56667 +#include <linux/kernel.h>
56668 +#include <linux/mm.h>
56669 +#include <linux/sched.h>
56670 +#include <linux/file.h>
56671 +#include <linux/ipc.h>
56672 +#include <linux/gracl.h>
56673 +#include <linux/grsecurity.h>
56674 +#include <linux/grinternal.h>
56675 +
56676 +int
56677 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56678 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56679 +{
56680 + struct task_struct *task;
56681 +
56682 + if (!gr_acl_is_enabled())
56683 + return 1;
56684 +
56685 + rcu_read_lock();
56686 + read_lock(&tasklist_lock);
56687 +
56688 + task = find_task_by_vpid(shm_cprid);
56689 +
56690 + if (unlikely(!task))
56691 + task = find_task_by_vpid(shm_lapid);
56692 +
56693 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56694 + (task->pid == shm_lapid)) &&
56695 + (task->acl->mode & GR_PROTSHM) &&
56696 + (task->acl != current->acl))) {
56697 + read_unlock(&tasklist_lock);
56698 + rcu_read_unlock();
56699 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56700 + return 0;
56701 + }
56702 + read_unlock(&tasklist_lock);
56703 + rcu_read_unlock();
56704 +
56705 + return 1;
56706 +}
56707 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56708 new file mode 100644
56709 index 0000000..bc0be01
56710 --- /dev/null
56711 +++ b/grsecurity/grsec_chdir.c
56712 @@ -0,0 +1,19 @@
56713 +#include <linux/kernel.h>
56714 +#include <linux/sched.h>
56715 +#include <linux/fs.h>
56716 +#include <linux/file.h>
56717 +#include <linux/grsecurity.h>
56718 +#include <linux/grinternal.h>
56719 +
56720 +void
56721 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56722 +{
56723 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56724 + if ((grsec_enable_chdir && grsec_enable_group &&
56725 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56726 + !grsec_enable_group)) {
56727 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56728 + }
56729 +#endif
56730 + return;
56731 +}
56732 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56733 new file mode 100644
56734 index 0000000..9807ee2
56735 --- /dev/null
56736 +++ b/grsecurity/grsec_chroot.c
56737 @@ -0,0 +1,368 @@
56738 +#include <linux/kernel.h>
56739 +#include <linux/module.h>
56740 +#include <linux/sched.h>
56741 +#include <linux/file.h>
56742 +#include <linux/fs.h>
56743 +#include <linux/mount.h>
56744 +#include <linux/types.h>
56745 +#include "../fs/mount.h"
56746 +#include <linux/grsecurity.h>
56747 +#include <linux/grinternal.h>
56748 +
56749 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56750 +{
56751 +#ifdef CONFIG_GRKERNSEC
56752 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56753 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56754 + task->gr_is_chrooted = 1;
56755 + else
56756 + task->gr_is_chrooted = 0;
56757 +
56758 + task->gr_chroot_dentry = path->dentry;
56759 +#endif
56760 + return;
56761 +}
56762 +
56763 +void gr_clear_chroot_entries(struct task_struct *task)
56764 +{
56765 +#ifdef CONFIG_GRKERNSEC
56766 + task->gr_is_chrooted = 0;
56767 + task->gr_chroot_dentry = NULL;
56768 +#endif
56769 + return;
56770 +}
56771 +
56772 +int
56773 +gr_handle_chroot_unix(const pid_t pid)
56774 +{
56775 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56776 + struct task_struct *p;
56777 +
56778 + if (unlikely(!grsec_enable_chroot_unix))
56779 + return 1;
56780 +
56781 + if (likely(!proc_is_chrooted(current)))
56782 + return 1;
56783 +
56784 + rcu_read_lock();
56785 + read_lock(&tasklist_lock);
56786 + p = find_task_by_vpid_unrestricted(pid);
56787 + if (unlikely(p && !have_same_root(current, p))) {
56788 + read_unlock(&tasklist_lock);
56789 + rcu_read_unlock();
56790 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56791 + return 0;
56792 + }
56793 + read_unlock(&tasklist_lock);
56794 + rcu_read_unlock();
56795 +#endif
56796 + return 1;
56797 +}
56798 +
56799 +int
56800 +gr_handle_chroot_nice(void)
56801 +{
56802 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56803 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56804 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56805 + return -EPERM;
56806 + }
56807 +#endif
56808 + return 0;
56809 +}
56810 +
56811 +int
56812 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56813 +{
56814 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56815 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56816 + && proc_is_chrooted(current)) {
56817 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56818 + return -EACCES;
56819 + }
56820 +#endif
56821 + return 0;
56822 +}
56823 +
56824 +int
56825 +gr_handle_chroot_rawio(const struct inode *inode)
56826 +{
56827 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56828 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56829 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56830 + return 1;
56831 +#endif
56832 + return 0;
56833 +}
56834 +
56835 +int
56836 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56837 +{
56838 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56839 + struct task_struct *p;
56840 + int ret = 0;
56841 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56842 + return ret;
56843 +
56844 + read_lock(&tasklist_lock);
56845 + do_each_pid_task(pid, type, p) {
56846 + if (!have_same_root(current, p)) {
56847 + ret = 1;
56848 + goto out;
56849 + }
56850 + } while_each_pid_task(pid, type, p);
56851 +out:
56852 + read_unlock(&tasklist_lock);
56853 + return ret;
56854 +#endif
56855 + return 0;
56856 +}
56857 +
56858 +int
56859 +gr_pid_is_chrooted(struct task_struct *p)
56860 +{
56861 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56862 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56863 + return 0;
56864 +
56865 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56866 + !have_same_root(current, p)) {
56867 + return 1;
56868 + }
56869 +#endif
56870 + return 0;
56871 +}
56872 +
56873 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56874 +
56875 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56876 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56877 +{
56878 + struct path path, currentroot;
56879 + int ret = 0;
56880 +
56881 + path.dentry = (struct dentry *)u_dentry;
56882 + path.mnt = (struct vfsmount *)u_mnt;
56883 + get_fs_root(current->fs, &currentroot);
56884 + if (path_is_under(&path, &currentroot))
56885 + ret = 1;
56886 + path_put(&currentroot);
56887 +
56888 + return ret;
56889 +}
56890 +#endif
56891 +
56892 +int
56893 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56894 +{
56895 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56896 + if (!grsec_enable_chroot_fchdir)
56897 + return 1;
56898 +
56899 + if (!proc_is_chrooted(current))
56900 + return 1;
56901 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56902 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56903 + return 0;
56904 + }
56905 +#endif
56906 + return 1;
56907 +}
56908 +
56909 +int
56910 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56911 + const time_t shm_createtime)
56912 +{
56913 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56914 + struct task_struct *p;
56915 + time_t starttime;
56916 +
56917 + if (unlikely(!grsec_enable_chroot_shmat))
56918 + return 1;
56919 +
56920 + if (likely(!proc_is_chrooted(current)))
56921 + return 1;
56922 +
56923 + rcu_read_lock();
56924 + read_lock(&tasklist_lock);
56925 +
56926 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56927 + starttime = p->start_time.tv_sec;
56928 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56929 + if (have_same_root(current, p)) {
56930 + goto allow;
56931 + } else {
56932 + read_unlock(&tasklist_lock);
56933 + rcu_read_unlock();
56934 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56935 + return 0;
56936 + }
56937 + }
56938 + /* creator exited, pid reuse, fall through to next check */
56939 + }
56940 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56941 + if (unlikely(!have_same_root(current, p))) {
56942 + read_unlock(&tasklist_lock);
56943 + rcu_read_unlock();
56944 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56945 + return 0;
56946 + }
56947 + }
56948 +
56949 +allow:
56950 + read_unlock(&tasklist_lock);
56951 + rcu_read_unlock();
56952 +#endif
56953 + return 1;
56954 +}
56955 +
56956 +void
56957 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56958 +{
56959 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56960 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56961 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56962 +#endif
56963 + return;
56964 +}
56965 +
56966 +int
56967 +gr_handle_chroot_mknod(const struct dentry *dentry,
56968 + const struct vfsmount *mnt, const int mode)
56969 +{
56970 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56971 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56972 + proc_is_chrooted(current)) {
56973 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56974 + return -EPERM;
56975 + }
56976 +#endif
56977 + return 0;
56978 +}
56979 +
56980 +int
56981 +gr_handle_chroot_mount(const struct dentry *dentry,
56982 + const struct vfsmount *mnt, const char *dev_name)
56983 +{
56984 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56985 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56986 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56987 + return -EPERM;
56988 + }
56989 +#endif
56990 + return 0;
56991 +}
56992 +
56993 +int
56994 +gr_handle_chroot_pivot(void)
56995 +{
56996 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56997 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56998 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56999 + return -EPERM;
57000 + }
57001 +#endif
57002 + return 0;
57003 +}
57004 +
57005 +int
57006 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57007 +{
57008 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57009 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57010 + !gr_is_outside_chroot(dentry, mnt)) {
57011 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57012 + return -EPERM;
57013 + }
57014 +#endif
57015 + return 0;
57016 +}
57017 +
57018 +extern const char *captab_log[];
57019 +extern int captab_log_entries;
57020 +
57021 +int
57022 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57023 +{
57024 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57025 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57026 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57027 + if (cap_raised(chroot_caps, cap)) {
57028 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57029 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57030 + }
57031 + return 0;
57032 + }
57033 + }
57034 +#endif
57035 + return 1;
57036 +}
57037 +
57038 +int
57039 +gr_chroot_is_capable(const int cap)
57040 +{
57041 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57042 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57043 +#endif
57044 + return 1;
57045 +}
57046 +
57047 +int
57048 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57049 +{
57050 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57051 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57052 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57053 + if (cap_raised(chroot_caps, cap)) {
57054 + return 0;
57055 + }
57056 + }
57057 +#endif
57058 + return 1;
57059 +}
57060 +
57061 +int
57062 +gr_chroot_is_capable_nolog(const int cap)
57063 +{
57064 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57065 + return gr_task_chroot_is_capable_nolog(current, cap);
57066 +#endif
57067 + return 1;
57068 +}
57069 +
57070 +int
57071 +gr_handle_chroot_sysctl(const int op)
57072 +{
57073 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57074 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57075 + proc_is_chrooted(current))
57076 + return -EACCES;
57077 +#endif
57078 + return 0;
57079 +}
57080 +
57081 +void
57082 +gr_handle_chroot_chdir(struct path *path)
57083 +{
57084 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57085 + if (grsec_enable_chroot_chdir)
57086 + set_fs_pwd(current->fs, path);
57087 +#endif
57088 + return;
57089 +}
57090 +
57091 +int
57092 +gr_handle_chroot_chmod(const struct dentry *dentry,
57093 + const struct vfsmount *mnt, const int mode)
57094 +{
57095 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57096 + /* allow chmod +s on directories, but not files */
57097 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57098 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57099 + proc_is_chrooted(current)) {
57100 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57101 + return -EPERM;
57102 + }
57103 +#endif
57104 + return 0;
57105 +}
57106 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57107 new file mode 100644
57108 index 0000000..213ad8b
57109 --- /dev/null
57110 +++ b/grsecurity/grsec_disabled.c
57111 @@ -0,0 +1,437 @@
57112 +#include <linux/kernel.h>
57113 +#include <linux/module.h>
57114 +#include <linux/sched.h>
57115 +#include <linux/file.h>
57116 +#include <linux/fs.h>
57117 +#include <linux/kdev_t.h>
57118 +#include <linux/net.h>
57119 +#include <linux/in.h>
57120 +#include <linux/ip.h>
57121 +#include <linux/skbuff.h>
57122 +#include <linux/sysctl.h>
57123 +
57124 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57125 +void
57126 +pax_set_initial_flags(struct linux_binprm *bprm)
57127 +{
57128 + return;
57129 +}
57130 +#endif
57131 +
57132 +#ifdef CONFIG_SYSCTL
57133 +__u32
57134 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57135 +{
57136 + return 0;
57137 +}
57138 +#endif
57139 +
57140 +#ifdef CONFIG_TASKSTATS
57141 +int gr_is_taskstats_denied(int pid)
57142 +{
57143 + return 0;
57144 +}
57145 +#endif
57146 +
57147 +int
57148 +gr_acl_is_enabled(void)
57149 +{
57150 + return 0;
57151 +}
57152 +
57153 +void
57154 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57155 +{
57156 + return;
57157 +}
57158 +
57159 +int
57160 +gr_handle_rawio(const struct inode *inode)
57161 +{
57162 + return 0;
57163 +}
57164 +
57165 +void
57166 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57167 +{
57168 + return;
57169 +}
57170 +
57171 +int
57172 +gr_handle_ptrace(struct task_struct *task, const long request)
57173 +{
57174 + return 0;
57175 +}
57176 +
57177 +int
57178 +gr_handle_proc_ptrace(struct task_struct *task)
57179 +{
57180 + return 0;
57181 +}
57182 +
57183 +void
57184 +gr_learn_resource(const struct task_struct *task,
57185 + const int res, const unsigned long wanted, const int gt)
57186 +{
57187 + return;
57188 +}
57189 +
57190 +int
57191 +gr_set_acls(const int type)
57192 +{
57193 + return 0;
57194 +}
57195 +
57196 +int
57197 +gr_check_hidden_task(const struct task_struct *tsk)
57198 +{
57199 + return 0;
57200 +}
57201 +
57202 +int
57203 +gr_check_protected_task(const struct task_struct *task)
57204 +{
57205 + return 0;
57206 +}
57207 +
57208 +int
57209 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57210 +{
57211 + return 0;
57212 +}
57213 +
57214 +void
57215 +gr_copy_label(struct task_struct *tsk)
57216 +{
57217 + return;
57218 +}
57219 +
57220 +void
57221 +gr_set_pax_flags(struct task_struct *task)
57222 +{
57223 + return;
57224 +}
57225 +
57226 +int
57227 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57228 + const int unsafe_share)
57229 +{
57230 + return 0;
57231 +}
57232 +
57233 +void
57234 +gr_handle_delete(const ino_t ino, const dev_t dev)
57235 +{
57236 + return;
57237 +}
57238 +
57239 +void
57240 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57241 +{
57242 + return;
57243 +}
57244 +
57245 +void
57246 +gr_handle_crash(struct task_struct *task, const int sig)
57247 +{
57248 + return;
57249 +}
57250 +
57251 +int
57252 +gr_check_crash_exec(const struct file *filp)
57253 +{
57254 + return 0;
57255 +}
57256 +
57257 +int
57258 +gr_check_crash_uid(const uid_t uid)
57259 +{
57260 + return 0;
57261 +}
57262 +
57263 +void
57264 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57265 + struct dentry *old_dentry,
57266 + struct dentry *new_dentry,
57267 + struct vfsmount *mnt, const __u8 replace)
57268 +{
57269 + return;
57270 +}
57271 +
57272 +int
57273 +gr_search_socket(const int family, const int type, const int protocol)
57274 +{
57275 + return 1;
57276 +}
57277 +
57278 +int
57279 +gr_search_connectbind(const int mode, const struct socket *sock,
57280 + const struct sockaddr_in *addr)
57281 +{
57282 + return 0;
57283 +}
57284 +
57285 +void
57286 +gr_handle_alertkill(struct task_struct *task)
57287 +{
57288 + return;
57289 +}
57290 +
57291 +__u32
57292 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57293 +{
57294 + return 1;
57295 +}
57296 +
57297 +__u32
57298 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57299 + const struct vfsmount * mnt)
57300 +{
57301 + return 1;
57302 +}
57303 +
57304 +__u32
57305 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57306 + int acc_mode)
57307 +{
57308 + return 1;
57309 +}
57310 +
57311 +__u32
57312 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57313 +{
57314 + return 1;
57315 +}
57316 +
57317 +__u32
57318 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57319 +{
57320 + return 1;
57321 +}
57322 +
57323 +int
57324 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57325 + unsigned int *vm_flags)
57326 +{
57327 + return 1;
57328 +}
57329 +
57330 +__u32
57331 +gr_acl_handle_truncate(const struct dentry * dentry,
57332 + const struct vfsmount * mnt)
57333 +{
57334 + return 1;
57335 +}
57336 +
57337 +__u32
57338 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57339 +{
57340 + return 1;
57341 +}
57342 +
57343 +__u32
57344 +gr_acl_handle_access(const struct dentry * dentry,
57345 + const struct vfsmount * mnt, const int fmode)
57346 +{
57347 + return 1;
57348 +}
57349 +
57350 +__u32
57351 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57352 + umode_t *mode)
57353 +{
57354 + return 1;
57355 +}
57356 +
57357 +__u32
57358 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57359 +{
57360 + return 1;
57361 +}
57362 +
57363 +__u32
57364 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57365 +{
57366 + return 1;
57367 +}
57368 +
57369 +void
57370 +grsecurity_init(void)
57371 +{
57372 + return;
57373 +}
57374 +
57375 +umode_t gr_acl_umask(void)
57376 +{
57377 + return 0;
57378 +}
57379 +
57380 +__u32
57381 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57382 + const struct dentry * parent_dentry,
57383 + const struct vfsmount * parent_mnt,
57384 + const int mode)
57385 +{
57386 + return 1;
57387 +}
57388 +
57389 +__u32
57390 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57391 + const struct dentry * parent_dentry,
57392 + const struct vfsmount * parent_mnt)
57393 +{
57394 + return 1;
57395 +}
57396 +
57397 +__u32
57398 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57399 + const struct dentry * parent_dentry,
57400 + const struct vfsmount * parent_mnt, const char *from)
57401 +{
57402 + return 1;
57403 +}
57404 +
57405 +__u32
57406 +gr_acl_handle_link(const struct dentry * new_dentry,
57407 + const struct dentry * parent_dentry,
57408 + const struct vfsmount * parent_mnt,
57409 + const struct dentry * old_dentry,
57410 + const struct vfsmount * old_mnt, const char *to)
57411 +{
57412 + return 1;
57413 +}
57414 +
57415 +int
57416 +gr_acl_handle_rename(const struct dentry *new_dentry,
57417 + const struct dentry *parent_dentry,
57418 + const struct vfsmount *parent_mnt,
57419 + const struct dentry *old_dentry,
57420 + const struct inode *old_parent_inode,
57421 + const struct vfsmount *old_mnt, const char *newname)
57422 +{
57423 + return 0;
57424 +}
57425 +
57426 +int
57427 +gr_acl_handle_filldir(const struct file *file, const char *name,
57428 + const int namelen, const ino_t ino)
57429 +{
57430 + return 1;
57431 +}
57432 +
57433 +int
57434 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57435 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57436 +{
57437 + return 1;
57438 +}
57439 +
57440 +int
57441 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57442 +{
57443 + return 0;
57444 +}
57445 +
57446 +int
57447 +gr_search_accept(const struct socket *sock)
57448 +{
57449 + return 0;
57450 +}
57451 +
57452 +int
57453 +gr_search_listen(const struct socket *sock)
57454 +{
57455 + return 0;
57456 +}
57457 +
57458 +int
57459 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57460 +{
57461 + return 0;
57462 +}
57463 +
57464 +__u32
57465 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57466 +{
57467 + return 1;
57468 +}
57469 +
57470 +__u32
57471 +gr_acl_handle_creat(const struct dentry * dentry,
57472 + const struct dentry * p_dentry,
57473 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57474 + const int imode)
57475 +{
57476 + return 1;
57477 +}
57478 +
57479 +void
57480 +gr_acl_handle_exit(void)
57481 +{
57482 + return;
57483 +}
57484 +
57485 +int
57486 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57487 +{
57488 + return 1;
57489 +}
57490 +
57491 +void
57492 +gr_set_role_label(const uid_t uid, const gid_t gid)
57493 +{
57494 + return;
57495 +}
57496 +
57497 +int
57498 +gr_acl_handle_procpidmem(const struct task_struct *task)
57499 +{
57500 + return 0;
57501 +}
57502 +
57503 +int
57504 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57505 +{
57506 + return 0;
57507 +}
57508 +
57509 +int
57510 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57511 +{
57512 + return 0;
57513 +}
57514 +
57515 +void
57516 +gr_set_kernel_label(struct task_struct *task)
57517 +{
57518 + return;
57519 +}
57520 +
57521 +int
57522 +gr_check_user_change(int real, int effective, int fs)
57523 +{
57524 + return 0;
57525 +}
57526 +
57527 +int
57528 +gr_check_group_change(int real, int effective, int fs)
57529 +{
57530 + return 0;
57531 +}
57532 +
57533 +int gr_acl_enable_at_secure(void)
57534 +{
57535 + return 0;
57536 +}
57537 +
57538 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57539 +{
57540 + return dentry->d_inode->i_sb->s_dev;
57541 +}
57542 +
57543 +EXPORT_SYMBOL(gr_learn_resource);
57544 +EXPORT_SYMBOL(gr_set_kernel_label);
57545 +#ifdef CONFIG_SECURITY
57546 +EXPORT_SYMBOL(gr_check_user_change);
57547 +EXPORT_SYMBOL(gr_check_group_change);
57548 +#endif
57549 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57550 new file mode 100644
57551 index 0000000..abfa971
57552 --- /dev/null
57553 +++ b/grsecurity/grsec_exec.c
57554 @@ -0,0 +1,174 @@
57555 +#include <linux/kernel.h>
57556 +#include <linux/sched.h>
57557 +#include <linux/file.h>
57558 +#include <linux/binfmts.h>
57559 +#include <linux/fs.h>
57560 +#include <linux/types.h>
57561 +#include <linux/grdefs.h>
57562 +#include <linux/grsecurity.h>
57563 +#include <linux/grinternal.h>
57564 +#include <linux/capability.h>
57565 +#include <linux/module.h>
57566 +
57567 +#include <asm/uaccess.h>
57568 +
57569 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57570 +static char gr_exec_arg_buf[132];
57571 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57572 +#endif
57573 +
57574 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57575 +
57576 +void
57577 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57578 +{
57579 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57580 + char *grarg = gr_exec_arg_buf;
57581 + unsigned int i, x, execlen = 0;
57582 + char c;
57583 +
57584 + if (!((grsec_enable_execlog && grsec_enable_group &&
57585 + in_group_p(grsec_audit_gid))
57586 + || (grsec_enable_execlog && !grsec_enable_group)))
57587 + return;
57588 +
57589 + mutex_lock(&gr_exec_arg_mutex);
57590 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57591 +
57592 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57593 + const char __user *p;
57594 + unsigned int len;
57595 +
57596 + p = get_user_arg_ptr(argv, i);
57597 + if (IS_ERR(p))
57598 + goto log;
57599 +
57600 + len = strnlen_user(p, 128 - execlen);
57601 + if (len > 128 - execlen)
57602 + len = 128 - execlen;
57603 + else if (len > 0)
57604 + len--;
57605 + if (copy_from_user(grarg + execlen, p, len))
57606 + goto log;
57607 +
57608 + /* rewrite unprintable characters */
57609 + for (x = 0; x < len; x++) {
57610 + c = *(grarg + execlen + x);
57611 + if (c < 32 || c > 126)
57612 + *(grarg + execlen + x) = ' ';
57613 + }
57614 +
57615 + execlen += len;
57616 + *(grarg + execlen) = ' ';
57617 + *(grarg + execlen + 1) = '\0';
57618 + execlen++;
57619 + }
57620 +
57621 + log:
57622 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57623 + bprm->file->f_path.mnt, grarg);
57624 + mutex_unlock(&gr_exec_arg_mutex);
57625 +#endif
57626 + return;
57627 +}
57628 +
57629 +#ifdef CONFIG_GRKERNSEC
57630 +extern int gr_acl_is_capable(const int cap);
57631 +extern int gr_acl_is_capable_nolog(const int cap);
57632 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57633 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57634 +extern int gr_chroot_is_capable(const int cap);
57635 +extern int gr_chroot_is_capable_nolog(const int cap);
57636 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57637 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57638 +#endif
57639 +
57640 +const char *captab_log[] = {
57641 + "CAP_CHOWN",
57642 + "CAP_DAC_OVERRIDE",
57643 + "CAP_DAC_READ_SEARCH",
57644 + "CAP_FOWNER",
57645 + "CAP_FSETID",
57646 + "CAP_KILL",
57647 + "CAP_SETGID",
57648 + "CAP_SETUID",
57649 + "CAP_SETPCAP",
57650 + "CAP_LINUX_IMMUTABLE",
57651 + "CAP_NET_BIND_SERVICE",
57652 + "CAP_NET_BROADCAST",
57653 + "CAP_NET_ADMIN",
57654 + "CAP_NET_RAW",
57655 + "CAP_IPC_LOCK",
57656 + "CAP_IPC_OWNER",
57657 + "CAP_SYS_MODULE",
57658 + "CAP_SYS_RAWIO",
57659 + "CAP_SYS_CHROOT",
57660 + "CAP_SYS_PTRACE",
57661 + "CAP_SYS_PACCT",
57662 + "CAP_SYS_ADMIN",
57663 + "CAP_SYS_BOOT",
57664 + "CAP_SYS_NICE",
57665 + "CAP_SYS_RESOURCE",
57666 + "CAP_SYS_TIME",
57667 + "CAP_SYS_TTY_CONFIG",
57668 + "CAP_MKNOD",
57669 + "CAP_LEASE",
57670 + "CAP_AUDIT_WRITE",
57671 + "CAP_AUDIT_CONTROL",
57672 + "CAP_SETFCAP",
57673 + "CAP_MAC_OVERRIDE",
57674 + "CAP_MAC_ADMIN",
57675 + "CAP_SYSLOG",
57676 + "CAP_WAKE_ALARM"
57677 +};
57678 +
57679 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57680 +
57681 +int gr_is_capable(const int cap)
57682 +{
57683 +#ifdef CONFIG_GRKERNSEC
57684 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57685 + return 1;
57686 + return 0;
57687 +#else
57688 + return 1;
57689 +#endif
57690 +}
57691 +
57692 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57693 +{
57694 +#ifdef CONFIG_GRKERNSEC
57695 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57696 + return 1;
57697 + return 0;
57698 +#else
57699 + return 1;
57700 +#endif
57701 +}
57702 +
57703 +int gr_is_capable_nolog(const int cap)
57704 +{
57705 +#ifdef CONFIG_GRKERNSEC
57706 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57707 + return 1;
57708 + return 0;
57709 +#else
57710 + return 1;
57711 +#endif
57712 +}
57713 +
57714 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57715 +{
57716 +#ifdef CONFIG_GRKERNSEC
57717 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57718 + return 1;
57719 + return 0;
57720 +#else
57721 + return 1;
57722 +#endif
57723 +}
57724 +
57725 +EXPORT_SYMBOL(gr_is_capable);
57726 +EXPORT_SYMBOL(gr_is_capable_nolog);
57727 +EXPORT_SYMBOL(gr_task_is_capable);
57728 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57729 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57730 new file mode 100644
57731 index 0000000..d3ee748
57732 --- /dev/null
57733 +++ b/grsecurity/grsec_fifo.c
57734 @@ -0,0 +1,24 @@
57735 +#include <linux/kernel.h>
57736 +#include <linux/sched.h>
57737 +#include <linux/fs.h>
57738 +#include <linux/file.h>
57739 +#include <linux/grinternal.h>
57740 +
57741 +int
57742 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57743 + const struct dentry *dir, const int flag, const int acc_mode)
57744 +{
57745 +#ifdef CONFIG_GRKERNSEC_FIFO
57746 + const struct cred *cred = current_cred();
57747 +
57748 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57749 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57750 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57751 + (cred->fsuid != dentry->d_inode->i_uid)) {
57752 + if (!inode_permission(dentry->d_inode, acc_mode))
57753 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57754 + return -EACCES;
57755 + }
57756 +#endif
57757 + return 0;
57758 +}
57759 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57760 new file mode 100644
57761 index 0000000..8ca18bf
57762 --- /dev/null
57763 +++ b/grsecurity/grsec_fork.c
57764 @@ -0,0 +1,23 @@
57765 +#include <linux/kernel.h>
57766 +#include <linux/sched.h>
57767 +#include <linux/grsecurity.h>
57768 +#include <linux/grinternal.h>
57769 +#include <linux/errno.h>
57770 +
57771 +void
57772 +gr_log_forkfail(const int retval)
57773 +{
57774 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57775 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57776 + switch (retval) {
57777 + case -EAGAIN:
57778 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57779 + break;
57780 + case -ENOMEM:
57781 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57782 + break;
57783 + }
57784 + }
57785 +#endif
57786 + return;
57787 +}
57788 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57789 new file mode 100644
57790 index 0000000..05a6015
57791 --- /dev/null
57792 +++ b/grsecurity/grsec_init.c
57793 @@ -0,0 +1,283 @@
57794 +#include <linux/kernel.h>
57795 +#include <linux/sched.h>
57796 +#include <linux/mm.h>
57797 +#include <linux/gracl.h>
57798 +#include <linux/slab.h>
57799 +#include <linux/vmalloc.h>
57800 +#include <linux/percpu.h>
57801 +#include <linux/module.h>
57802 +
57803 +int grsec_enable_ptrace_readexec;
57804 +int grsec_enable_setxid;
57805 +int grsec_enable_symlinkown;
57806 +int grsec_symlinkown_gid;
57807 +int grsec_enable_brute;
57808 +int grsec_enable_link;
57809 +int grsec_enable_dmesg;
57810 +int grsec_enable_harden_ptrace;
57811 +int grsec_enable_fifo;
57812 +int grsec_enable_execlog;
57813 +int grsec_enable_signal;
57814 +int grsec_enable_forkfail;
57815 +int grsec_enable_audit_ptrace;
57816 +int grsec_enable_time;
57817 +int grsec_enable_audit_textrel;
57818 +int grsec_enable_group;
57819 +int grsec_audit_gid;
57820 +int grsec_enable_chdir;
57821 +int grsec_enable_mount;
57822 +int grsec_enable_rofs;
57823 +int grsec_enable_chroot_findtask;
57824 +int grsec_enable_chroot_mount;
57825 +int grsec_enable_chroot_shmat;
57826 +int grsec_enable_chroot_fchdir;
57827 +int grsec_enable_chroot_double;
57828 +int grsec_enable_chroot_pivot;
57829 +int grsec_enable_chroot_chdir;
57830 +int grsec_enable_chroot_chmod;
57831 +int grsec_enable_chroot_mknod;
57832 +int grsec_enable_chroot_nice;
57833 +int grsec_enable_chroot_execlog;
57834 +int grsec_enable_chroot_caps;
57835 +int grsec_enable_chroot_sysctl;
57836 +int grsec_enable_chroot_unix;
57837 +int grsec_enable_tpe;
57838 +int grsec_tpe_gid;
57839 +int grsec_enable_blackhole;
57840 +#ifdef CONFIG_IPV6_MODULE
57841 +EXPORT_SYMBOL(grsec_enable_blackhole);
57842 +#endif
57843 +int grsec_lastack_retries;
57844 +int grsec_enable_tpe_all;
57845 +int grsec_enable_tpe_invert;
57846 +int grsec_enable_socket_all;
57847 +int grsec_socket_all_gid;
57848 +int grsec_enable_socket_client;
57849 +int grsec_socket_client_gid;
57850 +int grsec_enable_socket_server;
57851 +int grsec_socket_server_gid;
57852 +int grsec_resource_logging;
57853 +int grsec_disable_privio;
57854 +int grsec_enable_log_rwxmaps;
57855 +int grsec_lock;
57856 +
57857 +DEFINE_SPINLOCK(grsec_alert_lock);
57858 +unsigned long grsec_alert_wtime = 0;
57859 +unsigned long grsec_alert_fyet = 0;
57860 +
57861 +DEFINE_SPINLOCK(grsec_audit_lock);
57862 +
57863 +DEFINE_RWLOCK(grsec_exec_file_lock);
57864 +
57865 +char *gr_shared_page[4];
57866 +
57867 +char *gr_alert_log_fmt;
57868 +char *gr_audit_log_fmt;
57869 +char *gr_alert_log_buf;
57870 +char *gr_audit_log_buf;
57871 +
57872 +extern struct gr_arg *gr_usermode;
57873 +extern unsigned char *gr_system_salt;
57874 +extern unsigned char *gr_system_sum;
57875 +
57876 +void __init
57877 +grsecurity_init(void)
57878 +{
57879 + int j;
57880 + /* create the per-cpu shared pages */
57881 +
57882 +#ifdef CONFIG_X86
57883 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57884 +#endif
57885 +
57886 + for (j = 0; j < 4; j++) {
57887 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57888 + if (gr_shared_page[j] == NULL) {
57889 + panic("Unable to allocate grsecurity shared page");
57890 + return;
57891 + }
57892 + }
57893 +
57894 + /* allocate log buffers */
57895 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57896 + if (!gr_alert_log_fmt) {
57897 + panic("Unable to allocate grsecurity alert log format buffer");
57898 + return;
57899 + }
57900 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57901 + if (!gr_audit_log_fmt) {
57902 + panic("Unable to allocate grsecurity audit log format buffer");
57903 + return;
57904 + }
57905 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57906 + if (!gr_alert_log_buf) {
57907 + panic("Unable to allocate grsecurity alert log buffer");
57908 + return;
57909 + }
57910 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57911 + if (!gr_audit_log_buf) {
57912 + panic("Unable to allocate grsecurity audit log buffer");
57913 + return;
57914 + }
57915 +
57916 + /* allocate memory for authentication structure */
57917 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57918 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57919 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57920 +
57921 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57922 + panic("Unable to allocate grsecurity authentication structure");
57923 + return;
57924 + }
57925 +
57926 +
57927 +#ifdef CONFIG_GRKERNSEC_IO
57928 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57929 + grsec_disable_privio = 1;
57930 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57931 + grsec_disable_privio = 1;
57932 +#else
57933 + grsec_disable_privio = 0;
57934 +#endif
57935 +#endif
57936 +
57937 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57938 + /* for backward compatibility, tpe_invert always defaults to on if
57939 + enabled in the kernel
57940 + */
57941 + grsec_enable_tpe_invert = 1;
57942 +#endif
57943 +
57944 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57945 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57946 + grsec_lock = 1;
57947 +#endif
57948 +
57949 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57950 + grsec_enable_audit_textrel = 1;
57951 +#endif
57952 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57953 + grsec_enable_log_rwxmaps = 1;
57954 +#endif
57955 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57956 + grsec_enable_group = 1;
57957 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57958 +#endif
57959 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57960 + grsec_enable_ptrace_readexec = 1;
57961 +#endif
57962 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57963 + grsec_enable_chdir = 1;
57964 +#endif
57965 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57966 + grsec_enable_harden_ptrace = 1;
57967 +#endif
57968 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57969 + grsec_enable_mount = 1;
57970 +#endif
57971 +#ifdef CONFIG_GRKERNSEC_LINK
57972 + grsec_enable_link = 1;
57973 +#endif
57974 +#ifdef CONFIG_GRKERNSEC_BRUTE
57975 + grsec_enable_brute = 1;
57976 +#endif
57977 +#ifdef CONFIG_GRKERNSEC_DMESG
57978 + grsec_enable_dmesg = 1;
57979 +#endif
57980 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57981 + grsec_enable_blackhole = 1;
57982 + grsec_lastack_retries = 4;
57983 +#endif
57984 +#ifdef CONFIG_GRKERNSEC_FIFO
57985 + grsec_enable_fifo = 1;
57986 +#endif
57987 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57988 + grsec_enable_execlog = 1;
57989 +#endif
57990 +#ifdef CONFIG_GRKERNSEC_SETXID
57991 + grsec_enable_setxid = 1;
57992 +#endif
57993 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57994 + grsec_enable_signal = 1;
57995 +#endif
57996 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57997 + grsec_enable_forkfail = 1;
57998 +#endif
57999 +#ifdef CONFIG_GRKERNSEC_TIME
58000 + grsec_enable_time = 1;
58001 +#endif
58002 +#ifdef CONFIG_GRKERNSEC_RESLOG
58003 + grsec_resource_logging = 1;
58004 +#endif
58005 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58006 + grsec_enable_chroot_findtask = 1;
58007 +#endif
58008 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58009 + grsec_enable_chroot_unix = 1;
58010 +#endif
58011 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58012 + grsec_enable_chroot_mount = 1;
58013 +#endif
58014 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58015 + grsec_enable_chroot_fchdir = 1;
58016 +#endif
58017 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58018 + grsec_enable_chroot_shmat = 1;
58019 +#endif
58020 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58021 + grsec_enable_audit_ptrace = 1;
58022 +#endif
58023 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58024 + grsec_enable_chroot_double = 1;
58025 +#endif
58026 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58027 + grsec_enable_chroot_pivot = 1;
58028 +#endif
58029 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58030 + grsec_enable_chroot_chdir = 1;
58031 +#endif
58032 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58033 + grsec_enable_chroot_chmod = 1;
58034 +#endif
58035 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58036 + grsec_enable_chroot_mknod = 1;
58037 +#endif
58038 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58039 + grsec_enable_chroot_nice = 1;
58040 +#endif
58041 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58042 + grsec_enable_chroot_execlog = 1;
58043 +#endif
58044 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58045 + grsec_enable_chroot_caps = 1;
58046 +#endif
58047 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58048 + grsec_enable_chroot_sysctl = 1;
58049 +#endif
58050 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58051 + grsec_enable_symlinkown = 1;
58052 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58053 +#endif
58054 +#ifdef CONFIG_GRKERNSEC_TPE
58055 + grsec_enable_tpe = 1;
58056 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58057 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58058 + grsec_enable_tpe_all = 1;
58059 +#endif
58060 +#endif
58061 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58062 + grsec_enable_socket_all = 1;
58063 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58064 +#endif
58065 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58066 + grsec_enable_socket_client = 1;
58067 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58068 +#endif
58069 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58070 + grsec_enable_socket_server = 1;
58071 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58072 +#endif
58073 +#endif
58074 +
58075 + return;
58076 +}
58077 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58078 new file mode 100644
58079 index 0000000..551a2e7
58080 --- /dev/null
58081 +++ b/grsecurity/grsec_link.c
58082 @@ -0,0 +1,59 @@
58083 +#include <linux/kernel.h>
58084 +#include <linux/sched.h>
58085 +#include <linux/fs.h>
58086 +#include <linux/file.h>
58087 +#include <linux/grinternal.h>
58088 +
58089 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58090 +{
58091 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58092 + const struct inode *link_inode = link->dentry->d_inode;
58093 +
58094 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58095 + /* ignore root-owned links, e.g. /proc/self */
58096 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) &&
58097 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58098 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58099 + return 1;
58100 + }
58101 +#endif
58102 + return 0;
58103 +}
58104 +
58105 +int
58106 +gr_handle_follow_link(const struct inode *parent,
58107 + const struct inode *inode,
58108 + const struct dentry *dentry, const struct vfsmount *mnt)
58109 +{
58110 +#ifdef CONFIG_GRKERNSEC_LINK
58111 + const struct cred *cred = current_cred();
58112 +
58113 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58114 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58115 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58116 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58117 + return -EACCES;
58118 + }
58119 +#endif
58120 + return 0;
58121 +}
58122 +
58123 +int
58124 +gr_handle_hardlink(const struct dentry *dentry,
58125 + const struct vfsmount *mnt,
58126 + struct inode *inode, const int mode, const char *to)
58127 +{
58128 +#ifdef CONFIG_GRKERNSEC_LINK
58129 + const struct cred *cred = current_cred();
58130 +
58131 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58132 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58133 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58134 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58135 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58136 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58137 + return -EPERM;
58138 + }
58139 +#endif
58140 + return 0;
58141 +}
58142 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58143 new file mode 100644
58144 index 0000000..a45d2e9
58145 --- /dev/null
58146 +++ b/grsecurity/grsec_log.c
58147 @@ -0,0 +1,322 @@
58148 +#include <linux/kernel.h>
58149 +#include <linux/sched.h>
58150 +#include <linux/file.h>
58151 +#include <linux/tty.h>
58152 +#include <linux/fs.h>
58153 +#include <linux/grinternal.h>
58154 +
58155 +#ifdef CONFIG_TREE_PREEMPT_RCU
58156 +#define DISABLE_PREEMPT() preempt_disable()
58157 +#define ENABLE_PREEMPT() preempt_enable()
58158 +#else
58159 +#define DISABLE_PREEMPT()
58160 +#define ENABLE_PREEMPT()
58161 +#endif
58162 +
58163 +#define BEGIN_LOCKS(x) \
58164 + DISABLE_PREEMPT(); \
58165 + rcu_read_lock(); \
58166 + read_lock(&tasklist_lock); \
58167 + read_lock(&grsec_exec_file_lock); \
58168 + if (x != GR_DO_AUDIT) \
58169 + spin_lock(&grsec_alert_lock); \
58170 + else \
58171 + spin_lock(&grsec_audit_lock)
58172 +
58173 +#define END_LOCKS(x) \
58174 + if (x != GR_DO_AUDIT) \
58175 + spin_unlock(&grsec_alert_lock); \
58176 + else \
58177 + spin_unlock(&grsec_audit_lock); \
58178 + read_unlock(&grsec_exec_file_lock); \
58179 + read_unlock(&tasklist_lock); \
58180 + rcu_read_unlock(); \
58181 + ENABLE_PREEMPT(); \
58182 + if (x == GR_DONT_AUDIT) \
58183 + gr_handle_alertkill(current)
58184 +
58185 +enum {
58186 + FLOODING,
58187 + NO_FLOODING
58188 +};
58189 +
58190 +extern char *gr_alert_log_fmt;
58191 +extern char *gr_audit_log_fmt;
58192 +extern char *gr_alert_log_buf;
58193 +extern char *gr_audit_log_buf;
58194 +
58195 +static int gr_log_start(int audit)
58196 +{
58197 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58198 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58199 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58200 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58201 + unsigned long curr_secs = get_seconds();
58202 +
58203 + if (audit == GR_DO_AUDIT)
58204 + goto set_fmt;
58205 +
58206 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58207 + grsec_alert_wtime = curr_secs;
58208 + grsec_alert_fyet = 0;
58209 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58210 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58211 + grsec_alert_fyet++;
58212 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58213 + grsec_alert_wtime = curr_secs;
58214 + grsec_alert_fyet++;
58215 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58216 + return FLOODING;
58217 + }
58218 + else return FLOODING;
58219 +
58220 +set_fmt:
58221 +#endif
58222 + memset(buf, 0, PAGE_SIZE);
58223 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58224 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58225 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58226 + } else if (current->signal->curr_ip) {
58227 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58228 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58229 + } else if (gr_acl_is_enabled()) {
58230 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58231 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58232 + } else {
58233 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58234 + strcpy(buf, fmt);
58235 + }
58236 +
58237 + return NO_FLOODING;
58238 +}
58239 +
58240 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58241 + __attribute__ ((format (printf, 2, 0)));
58242 +
58243 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58244 +{
58245 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58246 + unsigned int len = strlen(buf);
58247 +
58248 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58249 +
58250 + return;
58251 +}
58252 +
58253 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58254 + __attribute__ ((format (printf, 2, 3)));
58255 +
58256 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58257 +{
58258 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58259 + unsigned int len = strlen(buf);
58260 + va_list ap;
58261 +
58262 + va_start(ap, msg);
58263 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58264 + va_end(ap);
58265 +
58266 + return;
58267 +}
58268 +
58269 +static void gr_log_end(int audit, int append_default)
58270 +{
58271 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58272 +
58273 + if (append_default) {
58274 + unsigned int len = strlen(buf);
58275 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58276 + }
58277 +
58278 + printk("%s\n", buf);
58279 +
58280 + return;
58281 +}
58282 +
58283 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58284 +{
58285 + int logtype;
58286 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58287 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58288 + void *voidptr = NULL;
58289 + int num1 = 0, num2 = 0;
58290 + unsigned long ulong1 = 0, ulong2 = 0;
58291 + struct dentry *dentry = NULL;
58292 + struct vfsmount *mnt = NULL;
58293 + struct file *file = NULL;
58294 + struct task_struct *task = NULL;
58295 + const struct cred *cred, *pcred;
58296 + va_list ap;
58297 +
58298 + BEGIN_LOCKS(audit);
58299 + logtype = gr_log_start(audit);
58300 + if (logtype == FLOODING) {
58301 + END_LOCKS(audit);
58302 + return;
58303 + }
58304 + va_start(ap, argtypes);
58305 + switch (argtypes) {
58306 + case GR_TTYSNIFF:
58307 + task = va_arg(ap, struct task_struct *);
58308 + 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);
58309 + break;
58310 + case GR_SYSCTL_HIDDEN:
58311 + str1 = va_arg(ap, char *);
58312 + gr_log_middle_varargs(audit, msg, result, str1);
58313 + break;
58314 + case GR_RBAC:
58315 + dentry = va_arg(ap, struct dentry *);
58316 + mnt = va_arg(ap, struct vfsmount *);
58317 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58318 + break;
58319 + case GR_RBAC_STR:
58320 + dentry = va_arg(ap, struct dentry *);
58321 + mnt = va_arg(ap, struct vfsmount *);
58322 + str1 = va_arg(ap, char *);
58323 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58324 + break;
58325 + case GR_STR_RBAC:
58326 + str1 = va_arg(ap, char *);
58327 + dentry = va_arg(ap, struct dentry *);
58328 + mnt = va_arg(ap, struct vfsmount *);
58329 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58330 + break;
58331 + case GR_RBAC_MODE2:
58332 + dentry = va_arg(ap, struct dentry *);
58333 + mnt = va_arg(ap, struct vfsmount *);
58334 + str1 = va_arg(ap, char *);
58335 + str2 = va_arg(ap, char *);
58336 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58337 + break;
58338 + case GR_RBAC_MODE3:
58339 + dentry = va_arg(ap, struct dentry *);
58340 + mnt = va_arg(ap, struct vfsmount *);
58341 + str1 = va_arg(ap, char *);
58342 + str2 = va_arg(ap, char *);
58343 + str3 = va_arg(ap, char *);
58344 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58345 + break;
58346 + case GR_FILENAME:
58347 + dentry = va_arg(ap, struct dentry *);
58348 + mnt = va_arg(ap, struct vfsmount *);
58349 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58350 + break;
58351 + case GR_STR_FILENAME:
58352 + str1 = va_arg(ap, char *);
58353 + dentry = va_arg(ap, struct dentry *);
58354 + mnt = va_arg(ap, struct vfsmount *);
58355 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58356 + break;
58357 + case GR_FILENAME_STR:
58358 + dentry = va_arg(ap, struct dentry *);
58359 + mnt = va_arg(ap, struct vfsmount *);
58360 + str1 = va_arg(ap, char *);
58361 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58362 + break;
58363 + case GR_FILENAME_TWO_INT:
58364 + dentry = va_arg(ap, struct dentry *);
58365 + mnt = va_arg(ap, struct vfsmount *);
58366 + num1 = va_arg(ap, int);
58367 + num2 = va_arg(ap, int);
58368 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58369 + break;
58370 + case GR_FILENAME_TWO_INT_STR:
58371 + dentry = va_arg(ap, struct dentry *);
58372 + mnt = va_arg(ap, struct vfsmount *);
58373 + num1 = va_arg(ap, int);
58374 + num2 = va_arg(ap, int);
58375 + str1 = va_arg(ap, char *);
58376 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58377 + break;
58378 + case GR_TEXTREL:
58379 + file = va_arg(ap, struct file *);
58380 + ulong1 = va_arg(ap, unsigned long);
58381 + ulong2 = va_arg(ap, unsigned long);
58382 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58383 + break;
58384 + case GR_PTRACE:
58385 + task = va_arg(ap, struct task_struct *);
58386 + 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);
58387 + break;
58388 + case GR_RESOURCE:
58389 + task = va_arg(ap, struct task_struct *);
58390 + cred = __task_cred(task);
58391 + pcred = __task_cred(task->real_parent);
58392 + ulong1 = va_arg(ap, unsigned long);
58393 + str1 = va_arg(ap, char *);
58394 + ulong2 = va_arg(ap, unsigned long);
58395 + 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);
58396 + break;
58397 + case GR_CAP:
58398 + task = va_arg(ap, struct task_struct *);
58399 + cred = __task_cred(task);
58400 + pcred = __task_cred(task->real_parent);
58401 + str1 = va_arg(ap, char *);
58402 + 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);
58403 + break;
58404 + case GR_SIG:
58405 + str1 = va_arg(ap, char *);
58406 + voidptr = va_arg(ap, void *);
58407 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58408 + break;
58409 + case GR_SIG2:
58410 + task = va_arg(ap, struct task_struct *);
58411 + cred = __task_cred(task);
58412 + pcred = __task_cred(task->real_parent);
58413 + num1 = va_arg(ap, int);
58414 + 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);
58415 + break;
58416 + case GR_CRASH1:
58417 + task = va_arg(ap, struct task_struct *);
58418 + cred = __task_cred(task);
58419 + pcred = __task_cred(task->real_parent);
58420 + ulong1 = va_arg(ap, unsigned long);
58421 + 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);
58422 + break;
58423 + case GR_CRASH2:
58424 + task = va_arg(ap, struct task_struct *);
58425 + cred = __task_cred(task);
58426 + pcred = __task_cred(task->real_parent);
58427 + ulong1 = va_arg(ap, unsigned long);
58428 + 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);
58429 + break;
58430 + case GR_RWXMAP:
58431 + file = va_arg(ap, struct file *);
58432 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58433 + break;
58434 + case GR_PSACCT:
58435 + {
58436 + unsigned int wday, cday;
58437 + __u8 whr, chr;
58438 + __u8 wmin, cmin;
58439 + __u8 wsec, csec;
58440 + char cur_tty[64] = { 0 };
58441 + char parent_tty[64] = { 0 };
58442 +
58443 + task = va_arg(ap, struct task_struct *);
58444 + wday = va_arg(ap, unsigned int);
58445 + cday = va_arg(ap, unsigned int);
58446 + whr = va_arg(ap, int);
58447 + chr = va_arg(ap, int);
58448 + wmin = va_arg(ap, int);
58449 + cmin = va_arg(ap, int);
58450 + wsec = va_arg(ap, int);
58451 + csec = va_arg(ap, int);
58452 + ulong1 = va_arg(ap, unsigned long);
58453 + cred = __task_cred(task);
58454 + pcred = __task_cred(task->real_parent);
58455 +
58456 + 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);
58457 + }
58458 + break;
58459 + default:
58460 + gr_log_middle(audit, msg, ap);
58461 + }
58462 + va_end(ap);
58463 + // these don't need DEFAULTSECARGS printed on the end
58464 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58465 + gr_log_end(audit, 0);
58466 + else
58467 + gr_log_end(audit, 1);
58468 + END_LOCKS(audit);
58469 +}
58470 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58471 new file mode 100644
58472 index 0000000..f536303
58473 --- /dev/null
58474 +++ b/grsecurity/grsec_mem.c
58475 @@ -0,0 +1,40 @@
58476 +#include <linux/kernel.h>
58477 +#include <linux/sched.h>
58478 +#include <linux/mm.h>
58479 +#include <linux/mman.h>
58480 +#include <linux/grinternal.h>
58481 +
58482 +void
58483 +gr_handle_ioperm(void)
58484 +{
58485 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58486 + return;
58487 +}
58488 +
58489 +void
58490 +gr_handle_iopl(void)
58491 +{
58492 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58493 + return;
58494 +}
58495 +
58496 +void
58497 +gr_handle_mem_readwrite(u64 from, u64 to)
58498 +{
58499 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58500 + return;
58501 +}
58502 +
58503 +void
58504 +gr_handle_vm86(void)
58505 +{
58506 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58507 + return;
58508 +}
58509 +
58510 +void
58511 +gr_log_badprocpid(const char *entry)
58512 +{
58513 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58514 + return;
58515 +}
58516 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58517 new file mode 100644
58518 index 0000000..2131422
58519 --- /dev/null
58520 +++ b/grsecurity/grsec_mount.c
58521 @@ -0,0 +1,62 @@
58522 +#include <linux/kernel.h>
58523 +#include <linux/sched.h>
58524 +#include <linux/mount.h>
58525 +#include <linux/grsecurity.h>
58526 +#include <linux/grinternal.h>
58527 +
58528 +void
58529 +gr_log_remount(const char *devname, const int retval)
58530 +{
58531 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58532 + if (grsec_enable_mount && (retval >= 0))
58533 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58534 +#endif
58535 + return;
58536 +}
58537 +
58538 +void
58539 +gr_log_unmount(const char *devname, const int retval)
58540 +{
58541 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58542 + if (grsec_enable_mount && (retval >= 0))
58543 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58544 +#endif
58545 + return;
58546 +}
58547 +
58548 +void
58549 +gr_log_mount(const char *from, const char *to, const int retval)
58550 +{
58551 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58552 + if (grsec_enable_mount && (retval >= 0))
58553 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58554 +#endif
58555 + return;
58556 +}
58557 +
58558 +int
58559 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58560 +{
58561 +#ifdef CONFIG_GRKERNSEC_ROFS
58562 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58563 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58564 + return -EPERM;
58565 + } else
58566 + return 0;
58567 +#endif
58568 + return 0;
58569 +}
58570 +
58571 +int
58572 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58573 +{
58574 +#ifdef CONFIG_GRKERNSEC_ROFS
58575 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58576 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58577 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58578 + return -EPERM;
58579 + } else
58580 + return 0;
58581 +#endif
58582 + return 0;
58583 +}
58584 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58585 new file mode 100644
58586 index 0000000..a3b12a0
58587 --- /dev/null
58588 +++ b/grsecurity/grsec_pax.c
58589 @@ -0,0 +1,36 @@
58590 +#include <linux/kernel.h>
58591 +#include <linux/sched.h>
58592 +#include <linux/mm.h>
58593 +#include <linux/file.h>
58594 +#include <linux/grinternal.h>
58595 +#include <linux/grsecurity.h>
58596 +
58597 +void
58598 +gr_log_textrel(struct vm_area_struct * vma)
58599 +{
58600 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58601 + if (grsec_enable_audit_textrel)
58602 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58603 +#endif
58604 + return;
58605 +}
58606 +
58607 +void
58608 +gr_log_rwxmmap(struct file *file)
58609 +{
58610 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58611 + if (grsec_enable_log_rwxmaps)
58612 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58613 +#endif
58614 + return;
58615 +}
58616 +
58617 +void
58618 +gr_log_rwxmprotect(struct file *file)
58619 +{
58620 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58621 + if (grsec_enable_log_rwxmaps)
58622 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58623 +#endif
58624 + return;
58625 +}
58626 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58627 new file mode 100644
58628 index 0000000..f7f29aa
58629 --- /dev/null
58630 +++ b/grsecurity/grsec_ptrace.c
58631 @@ -0,0 +1,30 @@
58632 +#include <linux/kernel.h>
58633 +#include <linux/sched.h>
58634 +#include <linux/grinternal.h>
58635 +#include <linux/security.h>
58636 +
58637 +void
58638 +gr_audit_ptrace(struct task_struct *task)
58639 +{
58640 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58641 + if (grsec_enable_audit_ptrace)
58642 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58643 +#endif
58644 + return;
58645 +}
58646 +
58647 +int
58648 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58649 +{
58650 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58651 + const struct dentry *dentry = file->f_path.dentry;
58652 + const struct vfsmount *mnt = file->f_path.mnt;
58653 +
58654 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58655 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58656 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58657 + return -EACCES;
58658 + }
58659 +#endif
58660 + return 0;
58661 +}
58662 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58663 new file mode 100644
58664 index 0000000..b4ac94c
58665 --- /dev/null
58666 +++ b/grsecurity/grsec_sig.c
58667 @@ -0,0 +1,209 @@
58668 +#include <linux/kernel.h>
58669 +#include <linux/sched.h>
58670 +#include <linux/delay.h>
58671 +#include <linux/grsecurity.h>
58672 +#include <linux/grinternal.h>
58673 +#include <linux/hardirq.h>
58674 +
58675 +char *signames[] = {
58676 + [SIGSEGV] = "Segmentation fault",
58677 + [SIGILL] = "Illegal instruction",
58678 + [SIGABRT] = "Abort",
58679 + [SIGBUS] = "Invalid alignment/Bus error"
58680 +};
58681 +
58682 +void
58683 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58684 +{
58685 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58686 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58687 + (sig == SIGABRT) || (sig == SIGBUS))) {
58688 + if (t->pid == current->pid) {
58689 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58690 + } else {
58691 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58692 + }
58693 + }
58694 +#endif
58695 + return;
58696 +}
58697 +
58698 +int
58699 +gr_handle_signal(const struct task_struct *p, const int sig)
58700 +{
58701 +#ifdef CONFIG_GRKERNSEC
58702 + /* ignore the 0 signal for protected task checks */
58703 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58704 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58705 + return -EPERM;
58706 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58707 + return -EPERM;
58708 + }
58709 +#endif
58710 + return 0;
58711 +}
58712 +
58713 +#ifdef CONFIG_GRKERNSEC
58714 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58715 +
58716 +int gr_fake_force_sig(int sig, struct task_struct *t)
58717 +{
58718 + unsigned long int flags;
58719 + int ret, blocked, ignored;
58720 + struct k_sigaction *action;
58721 +
58722 + spin_lock_irqsave(&t->sighand->siglock, flags);
58723 + action = &t->sighand->action[sig-1];
58724 + ignored = action->sa.sa_handler == SIG_IGN;
58725 + blocked = sigismember(&t->blocked, sig);
58726 + if (blocked || ignored) {
58727 + action->sa.sa_handler = SIG_DFL;
58728 + if (blocked) {
58729 + sigdelset(&t->blocked, sig);
58730 + recalc_sigpending_and_wake(t);
58731 + }
58732 + }
58733 + if (action->sa.sa_handler == SIG_DFL)
58734 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58735 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58736 +
58737 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58738 +
58739 + return ret;
58740 +}
58741 +#endif
58742 +
58743 +#ifdef CONFIG_GRKERNSEC_BRUTE
58744 +#define GR_USER_BAN_TIME (15 * 60)
58745 +
58746 +static int __get_dumpable(unsigned long mm_flags)
58747 +{
58748 + int ret;
58749 +
58750 + ret = mm_flags & MMF_DUMPABLE_MASK;
58751 + return (ret >= 2) ? 2 : ret;
58752 +}
58753 +#endif
58754 +
58755 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58756 +{
58757 +#ifdef CONFIG_GRKERNSEC_BRUTE
58758 + kuid_t uid = GLOBAL_ROOT_UID;
58759 +
58760 + if (!grsec_enable_brute)
58761 + return;
58762 +
58763 + rcu_read_lock();
58764 + read_lock(&tasklist_lock);
58765 + read_lock(&grsec_exec_file_lock);
58766 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58767 + p->real_parent->brute = 1;
58768 + else {
58769 + const struct cred *cred = __task_cred(p), *cred2;
58770 + struct task_struct *tsk, *tsk2;
58771 +
58772 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58773 + struct user_struct *user;
58774 +
58775 + uid = cred->uid;
58776 +
58777 + /* this is put upon execution past expiration */
58778 + user = find_user(uid);
58779 + if (user == NULL)
58780 + goto unlock;
58781 + user->banned = 1;
58782 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58783 + if (user->ban_expires == ~0UL)
58784 + user->ban_expires--;
58785 +
58786 + do_each_thread(tsk2, tsk) {
58787 + cred2 = __task_cred(tsk);
58788 + if (tsk != p && uid_eq(cred2->uid, uid))
58789 + gr_fake_force_sig(SIGKILL, tsk);
58790 + } while_each_thread(tsk2, tsk);
58791 + }
58792 + }
58793 +unlock:
58794 + read_unlock(&grsec_exec_file_lock);
58795 + read_unlock(&tasklist_lock);
58796 + rcu_read_unlock();
58797 +
58798 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
58799 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
58800 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
58801 +
58802 +#endif
58803 + return;
58804 +}
58805 +
58806 +void gr_handle_brute_check(void)
58807 +{
58808 +#ifdef CONFIG_GRKERNSEC_BRUTE
58809 + if (current->brute)
58810 + msleep(30 * 1000);
58811 +#endif
58812 + return;
58813 +}
58814 +
58815 +void gr_handle_kernel_exploit(void)
58816 +{
58817 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58818 + const struct cred *cred;
58819 + struct task_struct *tsk, *tsk2;
58820 + struct user_struct *user;
58821 + kuid_t uid;
58822 +
58823 + if (in_irq() || in_serving_softirq() || in_nmi())
58824 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58825 +
58826 + uid = current_uid();
58827 +
58828 + if (uid_eq(uid, GLOBAL_ROOT_UID))
58829 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58830 + else {
58831 + /* kill all the processes of this user, hold a reference
58832 + to their creds struct, and prevent them from creating
58833 + another process until system reset
58834 + */
58835 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
58836 + from_kuid_munged(&init_user_ns, uid));
58837 + /* we intentionally leak this ref */
58838 + user = get_uid(current->cred->user);
58839 + if (user) {
58840 + user->banned = 1;
58841 + user->ban_expires = ~0UL;
58842 + }
58843 +
58844 + read_lock(&tasklist_lock);
58845 + do_each_thread(tsk2, tsk) {
58846 + cred = __task_cred(tsk);
58847 + if (uid_eq(cred->uid, uid))
58848 + gr_fake_force_sig(SIGKILL, tsk);
58849 + } while_each_thread(tsk2, tsk);
58850 + read_unlock(&tasklist_lock);
58851 + }
58852 +#endif
58853 +}
58854 +
58855 +int __gr_process_user_ban(struct user_struct *user)
58856 +{
58857 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58858 + if (unlikely(user->banned)) {
58859 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58860 + user->banned = 0;
58861 + user->ban_expires = 0;
58862 + free_uid(user);
58863 + } else
58864 + return -EPERM;
58865 + }
58866 +#endif
58867 + return 0;
58868 +}
58869 +
58870 +int gr_process_user_ban(void)
58871 +{
58872 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58873 + return __gr_process_user_ban(current->cred->user);
58874 +#endif
58875 + return 0;
58876 +}
58877 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58878 new file mode 100644
58879 index 0000000..4030d57
58880 --- /dev/null
58881 +++ b/grsecurity/grsec_sock.c
58882 @@ -0,0 +1,244 @@
58883 +#include <linux/kernel.h>
58884 +#include <linux/module.h>
58885 +#include <linux/sched.h>
58886 +#include <linux/file.h>
58887 +#include <linux/net.h>
58888 +#include <linux/in.h>
58889 +#include <linux/ip.h>
58890 +#include <net/sock.h>
58891 +#include <net/inet_sock.h>
58892 +#include <linux/grsecurity.h>
58893 +#include <linux/grinternal.h>
58894 +#include <linux/gracl.h>
58895 +
58896 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58897 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58898 +
58899 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58900 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58901 +
58902 +#ifdef CONFIG_UNIX_MODULE
58903 +EXPORT_SYMBOL(gr_acl_handle_unix);
58904 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58905 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58906 +EXPORT_SYMBOL(gr_handle_create);
58907 +#endif
58908 +
58909 +#ifdef CONFIG_GRKERNSEC
58910 +#define gr_conn_table_size 32749
58911 +struct conn_table_entry {
58912 + struct conn_table_entry *next;
58913 + struct signal_struct *sig;
58914 +};
58915 +
58916 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58917 +DEFINE_SPINLOCK(gr_conn_table_lock);
58918 +
58919 +extern const char * gr_socktype_to_name(unsigned char type);
58920 +extern const char * gr_proto_to_name(unsigned char proto);
58921 +extern const char * gr_sockfamily_to_name(unsigned char family);
58922 +
58923 +static __inline__ int
58924 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58925 +{
58926 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58927 +}
58928 +
58929 +static __inline__ int
58930 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58931 + __u16 sport, __u16 dport)
58932 +{
58933 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58934 + sig->gr_sport == sport && sig->gr_dport == dport))
58935 + return 1;
58936 + else
58937 + return 0;
58938 +}
58939 +
58940 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58941 +{
58942 + struct conn_table_entry **match;
58943 + unsigned int index;
58944 +
58945 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58946 + sig->gr_sport, sig->gr_dport,
58947 + gr_conn_table_size);
58948 +
58949 + newent->sig = sig;
58950 +
58951 + match = &gr_conn_table[index];
58952 + newent->next = *match;
58953 + *match = newent;
58954 +
58955 + return;
58956 +}
58957 +
58958 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58959 +{
58960 + struct conn_table_entry *match, *last = NULL;
58961 + unsigned int index;
58962 +
58963 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58964 + sig->gr_sport, sig->gr_dport,
58965 + gr_conn_table_size);
58966 +
58967 + match = gr_conn_table[index];
58968 + while (match && !conn_match(match->sig,
58969 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58970 + sig->gr_dport)) {
58971 + last = match;
58972 + match = match->next;
58973 + }
58974 +
58975 + if (match) {
58976 + if (last)
58977 + last->next = match->next;
58978 + else
58979 + gr_conn_table[index] = NULL;
58980 + kfree(match);
58981 + }
58982 +
58983 + return;
58984 +}
58985 +
58986 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58987 + __u16 sport, __u16 dport)
58988 +{
58989 + struct conn_table_entry *match;
58990 + unsigned int index;
58991 +
58992 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58993 +
58994 + match = gr_conn_table[index];
58995 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58996 + match = match->next;
58997 +
58998 + if (match)
58999 + return match->sig;
59000 + else
59001 + return NULL;
59002 +}
59003 +
59004 +#endif
59005 +
59006 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59007 +{
59008 +#ifdef CONFIG_GRKERNSEC
59009 + struct signal_struct *sig = task->signal;
59010 + struct conn_table_entry *newent;
59011 +
59012 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59013 + if (newent == NULL)
59014 + return;
59015 + /* no bh lock needed since we are called with bh disabled */
59016 + spin_lock(&gr_conn_table_lock);
59017 + gr_del_task_from_ip_table_nolock(sig);
59018 + sig->gr_saddr = inet->inet_rcv_saddr;
59019 + sig->gr_daddr = inet->inet_daddr;
59020 + sig->gr_sport = inet->inet_sport;
59021 + sig->gr_dport = inet->inet_dport;
59022 + gr_add_to_task_ip_table_nolock(sig, newent);
59023 + spin_unlock(&gr_conn_table_lock);
59024 +#endif
59025 + return;
59026 +}
59027 +
59028 +void gr_del_task_from_ip_table(struct task_struct *task)
59029 +{
59030 +#ifdef CONFIG_GRKERNSEC
59031 + spin_lock_bh(&gr_conn_table_lock);
59032 + gr_del_task_from_ip_table_nolock(task->signal);
59033 + spin_unlock_bh(&gr_conn_table_lock);
59034 +#endif
59035 + return;
59036 +}
59037 +
59038 +void
59039 +gr_attach_curr_ip(const struct sock *sk)
59040 +{
59041 +#ifdef CONFIG_GRKERNSEC
59042 + struct signal_struct *p, *set;
59043 + const struct inet_sock *inet = inet_sk(sk);
59044 +
59045 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59046 + return;
59047 +
59048 + set = current->signal;
59049 +
59050 + spin_lock_bh(&gr_conn_table_lock);
59051 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59052 + inet->inet_dport, inet->inet_sport);
59053 + if (unlikely(p != NULL)) {
59054 + set->curr_ip = p->curr_ip;
59055 + set->used_accept = 1;
59056 + gr_del_task_from_ip_table_nolock(p);
59057 + spin_unlock_bh(&gr_conn_table_lock);
59058 + return;
59059 + }
59060 + spin_unlock_bh(&gr_conn_table_lock);
59061 +
59062 + set->curr_ip = inet->inet_daddr;
59063 + set->used_accept = 1;
59064 +#endif
59065 + return;
59066 +}
59067 +
59068 +int
59069 +gr_handle_sock_all(const int family, const int type, const int protocol)
59070 +{
59071 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59072 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59073 + (family != AF_UNIX)) {
59074 + if (family == AF_INET)
59075 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59076 + else
59077 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59078 + return -EACCES;
59079 + }
59080 +#endif
59081 + return 0;
59082 +}
59083 +
59084 +int
59085 +gr_handle_sock_server(const struct sockaddr *sck)
59086 +{
59087 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59088 + if (grsec_enable_socket_server &&
59089 + in_group_p(grsec_socket_server_gid) &&
59090 + sck && (sck->sa_family != AF_UNIX) &&
59091 + (sck->sa_family != AF_LOCAL)) {
59092 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59093 + return -EACCES;
59094 + }
59095 +#endif
59096 + return 0;
59097 +}
59098 +
59099 +int
59100 +gr_handle_sock_server_other(const struct sock *sck)
59101 +{
59102 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59103 + if (grsec_enable_socket_server &&
59104 + in_group_p(grsec_socket_server_gid) &&
59105 + sck && (sck->sk_family != AF_UNIX) &&
59106 + (sck->sk_family != AF_LOCAL)) {
59107 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59108 + return -EACCES;
59109 + }
59110 +#endif
59111 + return 0;
59112 +}
59113 +
59114 +int
59115 +gr_handle_sock_client(const struct sockaddr *sck)
59116 +{
59117 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59118 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59119 + sck && (sck->sa_family != AF_UNIX) &&
59120 + (sck->sa_family != AF_LOCAL)) {
59121 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59122 + return -EACCES;
59123 + }
59124 +#endif
59125 + return 0;
59126 +}
59127 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59128 new file mode 100644
59129 index 0000000..f55ef0f
59130 --- /dev/null
59131 +++ b/grsecurity/grsec_sysctl.c
59132 @@ -0,0 +1,469 @@
59133 +#include <linux/kernel.h>
59134 +#include <linux/sched.h>
59135 +#include <linux/sysctl.h>
59136 +#include <linux/grsecurity.h>
59137 +#include <linux/grinternal.h>
59138 +
59139 +int
59140 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59141 +{
59142 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59143 + if (dirname == NULL || name == NULL)
59144 + return 0;
59145 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59146 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59147 + return -EACCES;
59148 + }
59149 +#endif
59150 + return 0;
59151 +}
59152 +
59153 +#ifdef CONFIG_GRKERNSEC_ROFS
59154 +static int __maybe_unused one = 1;
59155 +#endif
59156 +
59157 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59158 +struct ctl_table grsecurity_table[] = {
59159 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59160 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59161 +#ifdef CONFIG_GRKERNSEC_IO
59162 + {
59163 + .procname = "disable_priv_io",
59164 + .data = &grsec_disable_privio,
59165 + .maxlen = sizeof(int),
59166 + .mode = 0600,
59167 + .proc_handler = &proc_dointvec,
59168 + },
59169 +#endif
59170 +#endif
59171 +#ifdef CONFIG_GRKERNSEC_LINK
59172 + {
59173 + .procname = "linking_restrictions",
59174 + .data = &grsec_enable_link,
59175 + .maxlen = sizeof(int),
59176 + .mode = 0600,
59177 + .proc_handler = &proc_dointvec,
59178 + },
59179 +#endif
59180 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59181 + {
59182 + .procname = "enforce_symlinksifowner",
59183 + .data = &grsec_enable_symlinkown,
59184 + .maxlen = sizeof(int),
59185 + .mode = 0600,
59186 + .proc_handler = &proc_dointvec,
59187 + },
59188 + {
59189 + .procname = "symlinkown_gid",
59190 + .data = &grsec_symlinkown_gid,
59191 + .maxlen = sizeof(int),
59192 + .mode = 0600,
59193 + .proc_handler = &proc_dointvec,
59194 + },
59195 +#endif
59196 +#ifdef CONFIG_GRKERNSEC_BRUTE
59197 + {
59198 + .procname = "deter_bruteforce",
59199 + .data = &grsec_enable_brute,
59200 + .maxlen = sizeof(int),
59201 + .mode = 0600,
59202 + .proc_handler = &proc_dointvec,
59203 + },
59204 +#endif
59205 +#ifdef CONFIG_GRKERNSEC_FIFO
59206 + {
59207 + .procname = "fifo_restrictions",
59208 + .data = &grsec_enable_fifo,
59209 + .maxlen = sizeof(int),
59210 + .mode = 0600,
59211 + .proc_handler = &proc_dointvec,
59212 + },
59213 +#endif
59214 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59215 + {
59216 + .procname = "ptrace_readexec",
59217 + .data = &grsec_enable_ptrace_readexec,
59218 + .maxlen = sizeof(int),
59219 + .mode = 0600,
59220 + .proc_handler = &proc_dointvec,
59221 + },
59222 +#endif
59223 +#ifdef CONFIG_GRKERNSEC_SETXID
59224 + {
59225 + .procname = "consistent_setxid",
59226 + .data = &grsec_enable_setxid,
59227 + .maxlen = sizeof(int),
59228 + .mode = 0600,
59229 + .proc_handler = &proc_dointvec,
59230 + },
59231 +#endif
59232 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59233 + {
59234 + .procname = "ip_blackhole",
59235 + .data = &grsec_enable_blackhole,
59236 + .maxlen = sizeof(int),
59237 + .mode = 0600,
59238 + .proc_handler = &proc_dointvec,
59239 + },
59240 + {
59241 + .procname = "lastack_retries",
59242 + .data = &grsec_lastack_retries,
59243 + .maxlen = sizeof(int),
59244 + .mode = 0600,
59245 + .proc_handler = &proc_dointvec,
59246 + },
59247 +#endif
59248 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59249 + {
59250 + .procname = "exec_logging",
59251 + .data = &grsec_enable_execlog,
59252 + .maxlen = sizeof(int),
59253 + .mode = 0600,
59254 + .proc_handler = &proc_dointvec,
59255 + },
59256 +#endif
59257 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59258 + {
59259 + .procname = "rwxmap_logging",
59260 + .data = &grsec_enable_log_rwxmaps,
59261 + .maxlen = sizeof(int),
59262 + .mode = 0600,
59263 + .proc_handler = &proc_dointvec,
59264 + },
59265 +#endif
59266 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59267 + {
59268 + .procname = "signal_logging",
59269 + .data = &grsec_enable_signal,
59270 + .maxlen = sizeof(int),
59271 + .mode = 0600,
59272 + .proc_handler = &proc_dointvec,
59273 + },
59274 +#endif
59275 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59276 + {
59277 + .procname = "forkfail_logging",
59278 + .data = &grsec_enable_forkfail,
59279 + .maxlen = sizeof(int),
59280 + .mode = 0600,
59281 + .proc_handler = &proc_dointvec,
59282 + },
59283 +#endif
59284 +#ifdef CONFIG_GRKERNSEC_TIME
59285 + {
59286 + .procname = "timechange_logging",
59287 + .data = &grsec_enable_time,
59288 + .maxlen = sizeof(int),
59289 + .mode = 0600,
59290 + .proc_handler = &proc_dointvec,
59291 + },
59292 +#endif
59293 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59294 + {
59295 + .procname = "chroot_deny_shmat",
59296 + .data = &grsec_enable_chroot_shmat,
59297 + .maxlen = sizeof(int),
59298 + .mode = 0600,
59299 + .proc_handler = &proc_dointvec,
59300 + },
59301 +#endif
59302 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59303 + {
59304 + .procname = "chroot_deny_unix",
59305 + .data = &grsec_enable_chroot_unix,
59306 + .maxlen = sizeof(int),
59307 + .mode = 0600,
59308 + .proc_handler = &proc_dointvec,
59309 + },
59310 +#endif
59311 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59312 + {
59313 + .procname = "chroot_deny_mount",
59314 + .data = &grsec_enable_chroot_mount,
59315 + .maxlen = sizeof(int),
59316 + .mode = 0600,
59317 + .proc_handler = &proc_dointvec,
59318 + },
59319 +#endif
59320 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59321 + {
59322 + .procname = "chroot_deny_fchdir",
59323 + .data = &grsec_enable_chroot_fchdir,
59324 + .maxlen = sizeof(int),
59325 + .mode = 0600,
59326 + .proc_handler = &proc_dointvec,
59327 + },
59328 +#endif
59329 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59330 + {
59331 + .procname = "chroot_deny_chroot",
59332 + .data = &grsec_enable_chroot_double,
59333 + .maxlen = sizeof(int),
59334 + .mode = 0600,
59335 + .proc_handler = &proc_dointvec,
59336 + },
59337 +#endif
59338 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59339 + {
59340 + .procname = "chroot_deny_pivot",
59341 + .data = &grsec_enable_chroot_pivot,
59342 + .maxlen = sizeof(int),
59343 + .mode = 0600,
59344 + .proc_handler = &proc_dointvec,
59345 + },
59346 +#endif
59347 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59348 + {
59349 + .procname = "chroot_enforce_chdir",
59350 + .data = &grsec_enable_chroot_chdir,
59351 + .maxlen = sizeof(int),
59352 + .mode = 0600,
59353 + .proc_handler = &proc_dointvec,
59354 + },
59355 +#endif
59356 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59357 + {
59358 + .procname = "chroot_deny_chmod",
59359 + .data = &grsec_enable_chroot_chmod,
59360 + .maxlen = sizeof(int),
59361 + .mode = 0600,
59362 + .proc_handler = &proc_dointvec,
59363 + },
59364 +#endif
59365 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59366 + {
59367 + .procname = "chroot_deny_mknod",
59368 + .data = &grsec_enable_chroot_mknod,
59369 + .maxlen = sizeof(int),
59370 + .mode = 0600,
59371 + .proc_handler = &proc_dointvec,
59372 + },
59373 +#endif
59374 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59375 + {
59376 + .procname = "chroot_restrict_nice",
59377 + .data = &grsec_enable_chroot_nice,
59378 + .maxlen = sizeof(int),
59379 + .mode = 0600,
59380 + .proc_handler = &proc_dointvec,
59381 + },
59382 +#endif
59383 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59384 + {
59385 + .procname = "chroot_execlog",
59386 + .data = &grsec_enable_chroot_execlog,
59387 + .maxlen = sizeof(int),
59388 + .mode = 0600,
59389 + .proc_handler = &proc_dointvec,
59390 + },
59391 +#endif
59392 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59393 + {
59394 + .procname = "chroot_caps",
59395 + .data = &grsec_enable_chroot_caps,
59396 + .maxlen = sizeof(int),
59397 + .mode = 0600,
59398 + .proc_handler = &proc_dointvec,
59399 + },
59400 +#endif
59401 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59402 + {
59403 + .procname = "chroot_deny_sysctl",
59404 + .data = &grsec_enable_chroot_sysctl,
59405 + .maxlen = sizeof(int),
59406 + .mode = 0600,
59407 + .proc_handler = &proc_dointvec,
59408 + },
59409 +#endif
59410 +#ifdef CONFIG_GRKERNSEC_TPE
59411 + {
59412 + .procname = "tpe",
59413 + .data = &grsec_enable_tpe,
59414 + .maxlen = sizeof(int),
59415 + .mode = 0600,
59416 + .proc_handler = &proc_dointvec,
59417 + },
59418 + {
59419 + .procname = "tpe_gid",
59420 + .data = &grsec_tpe_gid,
59421 + .maxlen = sizeof(int),
59422 + .mode = 0600,
59423 + .proc_handler = &proc_dointvec,
59424 + },
59425 +#endif
59426 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59427 + {
59428 + .procname = "tpe_invert",
59429 + .data = &grsec_enable_tpe_invert,
59430 + .maxlen = sizeof(int),
59431 + .mode = 0600,
59432 + .proc_handler = &proc_dointvec,
59433 + },
59434 +#endif
59435 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59436 + {
59437 + .procname = "tpe_restrict_all",
59438 + .data = &grsec_enable_tpe_all,
59439 + .maxlen = sizeof(int),
59440 + .mode = 0600,
59441 + .proc_handler = &proc_dointvec,
59442 + },
59443 +#endif
59444 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59445 + {
59446 + .procname = "socket_all",
59447 + .data = &grsec_enable_socket_all,
59448 + .maxlen = sizeof(int),
59449 + .mode = 0600,
59450 + .proc_handler = &proc_dointvec,
59451 + },
59452 + {
59453 + .procname = "socket_all_gid",
59454 + .data = &grsec_socket_all_gid,
59455 + .maxlen = sizeof(int),
59456 + .mode = 0600,
59457 + .proc_handler = &proc_dointvec,
59458 + },
59459 +#endif
59460 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59461 + {
59462 + .procname = "socket_client",
59463 + .data = &grsec_enable_socket_client,
59464 + .maxlen = sizeof(int),
59465 + .mode = 0600,
59466 + .proc_handler = &proc_dointvec,
59467 + },
59468 + {
59469 + .procname = "socket_client_gid",
59470 + .data = &grsec_socket_client_gid,
59471 + .maxlen = sizeof(int),
59472 + .mode = 0600,
59473 + .proc_handler = &proc_dointvec,
59474 + },
59475 +#endif
59476 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59477 + {
59478 + .procname = "socket_server",
59479 + .data = &grsec_enable_socket_server,
59480 + .maxlen = sizeof(int),
59481 + .mode = 0600,
59482 + .proc_handler = &proc_dointvec,
59483 + },
59484 + {
59485 + .procname = "socket_server_gid",
59486 + .data = &grsec_socket_server_gid,
59487 + .maxlen = sizeof(int),
59488 + .mode = 0600,
59489 + .proc_handler = &proc_dointvec,
59490 + },
59491 +#endif
59492 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59493 + {
59494 + .procname = "audit_group",
59495 + .data = &grsec_enable_group,
59496 + .maxlen = sizeof(int),
59497 + .mode = 0600,
59498 + .proc_handler = &proc_dointvec,
59499 + },
59500 + {
59501 + .procname = "audit_gid",
59502 + .data = &grsec_audit_gid,
59503 + .maxlen = sizeof(int),
59504 + .mode = 0600,
59505 + .proc_handler = &proc_dointvec,
59506 + },
59507 +#endif
59508 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59509 + {
59510 + .procname = "audit_chdir",
59511 + .data = &grsec_enable_chdir,
59512 + .maxlen = sizeof(int),
59513 + .mode = 0600,
59514 + .proc_handler = &proc_dointvec,
59515 + },
59516 +#endif
59517 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59518 + {
59519 + .procname = "audit_mount",
59520 + .data = &grsec_enable_mount,
59521 + .maxlen = sizeof(int),
59522 + .mode = 0600,
59523 + .proc_handler = &proc_dointvec,
59524 + },
59525 +#endif
59526 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59527 + {
59528 + .procname = "audit_textrel",
59529 + .data = &grsec_enable_audit_textrel,
59530 + .maxlen = sizeof(int),
59531 + .mode = 0600,
59532 + .proc_handler = &proc_dointvec,
59533 + },
59534 +#endif
59535 +#ifdef CONFIG_GRKERNSEC_DMESG
59536 + {
59537 + .procname = "dmesg",
59538 + .data = &grsec_enable_dmesg,
59539 + .maxlen = sizeof(int),
59540 + .mode = 0600,
59541 + .proc_handler = &proc_dointvec,
59542 + },
59543 +#endif
59544 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59545 + {
59546 + .procname = "chroot_findtask",
59547 + .data = &grsec_enable_chroot_findtask,
59548 + .maxlen = sizeof(int),
59549 + .mode = 0600,
59550 + .proc_handler = &proc_dointvec,
59551 + },
59552 +#endif
59553 +#ifdef CONFIG_GRKERNSEC_RESLOG
59554 + {
59555 + .procname = "resource_logging",
59556 + .data = &grsec_resource_logging,
59557 + .maxlen = sizeof(int),
59558 + .mode = 0600,
59559 + .proc_handler = &proc_dointvec,
59560 + },
59561 +#endif
59562 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59563 + {
59564 + .procname = "audit_ptrace",
59565 + .data = &grsec_enable_audit_ptrace,
59566 + .maxlen = sizeof(int),
59567 + .mode = 0600,
59568 + .proc_handler = &proc_dointvec,
59569 + },
59570 +#endif
59571 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59572 + {
59573 + .procname = "harden_ptrace",
59574 + .data = &grsec_enable_harden_ptrace,
59575 + .maxlen = sizeof(int),
59576 + .mode = 0600,
59577 + .proc_handler = &proc_dointvec,
59578 + },
59579 +#endif
59580 + {
59581 + .procname = "grsec_lock",
59582 + .data = &grsec_lock,
59583 + .maxlen = sizeof(int),
59584 + .mode = 0600,
59585 + .proc_handler = &proc_dointvec,
59586 + },
59587 +#endif
59588 +#ifdef CONFIG_GRKERNSEC_ROFS
59589 + {
59590 + .procname = "romount_protect",
59591 + .data = &grsec_enable_rofs,
59592 + .maxlen = sizeof(int),
59593 + .mode = 0600,
59594 + .proc_handler = &proc_dointvec_minmax,
59595 + .extra1 = &one,
59596 + .extra2 = &one,
59597 + },
59598 +#endif
59599 + { }
59600 +};
59601 +#endif
59602 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59603 new file mode 100644
59604 index 0000000..0dc13c3
59605 --- /dev/null
59606 +++ b/grsecurity/grsec_time.c
59607 @@ -0,0 +1,16 @@
59608 +#include <linux/kernel.h>
59609 +#include <linux/sched.h>
59610 +#include <linux/grinternal.h>
59611 +#include <linux/module.h>
59612 +
59613 +void
59614 +gr_log_timechange(void)
59615 +{
59616 +#ifdef CONFIG_GRKERNSEC_TIME
59617 + if (grsec_enable_time)
59618 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59619 +#endif
59620 + return;
59621 +}
59622 +
59623 +EXPORT_SYMBOL(gr_log_timechange);
59624 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59625 new file mode 100644
59626 index 0000000..07e0dc0
59627 --- /dev/null
59628 +++ b/grsecurity/grsec_tpe.c
59629 @@ -0,0 +1,73 @@
59630 +#include <linux/kernel.h>
59631 +#include <linux/sched.h>
59632 +#include <linux/file.h>
59633 +#include <linux/fs.h>
59634 +#include <linux/grinternal.h>
59635 +
59636 +extern int gr_acl_tpe_check(void);
59637 +
59638 +int
59639 +gr_tpe_allow(const struct file *file)
59640 +{
59641 +#ifdef CONFIG_GRKERNSEC
59642 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59643 + const struct cred *cred = current_cred();
59644 + char *msg = NULL;
59645 + char *msg2 = NULL;
59646 +
59647 + // never restrict root
59648 + if (!cred->uid)
59649 + return 1;
59650 +
59651 + if (grsec_enable_tpe) {
59652 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59653 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59654 + msg = "not being in trusted group";
59655 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59656 + msg = "being in untrusted group";
59657 +#else
59658 + if (in_group_p(grsec_tpe_gid))
59659 + msg = "being in untrusted group";
59660 +#endif
59661 + }
59662 + if (!msg && gr_acl_tpe_check())
59663 + msg = "being in untrusted role";
59664 +
59665 + // not in any affected group/role
59666 + if (!msg)
59667 + goto next_check;
59668 +
59669 + if (inode->i_uid)
59670 + msg2 = "file in non-root-owned directory";
59671 + else if (inode->i_mode & S_IWOTH)
59672 + msg2 = "file in world-writable directory";
59673 + else if (inode->i_mode & S_IWGRP)
59674 + msg2 = "file in group-writable directory";
59675 +
59676 + if (msg && msg2) {
59677 + char fullmsg[70] = {0};
59678 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59679 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59680 + return 0;
59681 + }
59682 + msg = NULL;
59683 +next_check:
59684 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59685 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59686 + return 1;
59687 +
59688 + if (inode->i_uid && (inode->i_uid != cred->uid))
59689 + msg = "directory not owned by user";
59690 + else if (inode->i_mode & S_IWOTH)
59691 + msg = "file in world-writable directory";
59692 + else if (inode->i_mode & S_IWGRP)
59693 + msg = "file in group-writable directory";
59694 +
59695 + if (msg) {
59696 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59697 + return 0;
59698 + }
59699 +#endif
59700 +#endif
59701 + return 1;
59702 +}
59703 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59704 new file mode 100644
59705 index 0000000..9f7b1ac
59706 --- /dev/null
59707 +++ b/grsecurity/grsum.c
59708 @@ -0,0 +1,61 @@
59709 +#include <linux/err.h>
59710 +#include <linux/kernel.h>
59711 +#include <linux/sched.h>
59712 +#include <linux/mm.h>
59713 +#include <linux/scatterlist.h>
59714 +#include <linux/crypto.h>
59715 +#include <linux/gracl.h>
59716 +
59717 +
59718 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59719 +#error "crypto and sha256 must be built into the kernel"
59720 +#endif
59721 +
59722 +int
59723 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59724 +{
59725 + char *p;
59726 + struct crypto_hash *tfm;
59727 + struct hash_desc desc;
59728 + struct scatterlist sg;
59729 + unsigned char temp_sum[GR_SHA_LEN];
59730 + volatile int retval = 0;
59731 + volatile int dummy = 0;
59732 + unsigned int i;
59733 +
59734 + sg_init_table(&sg, 1);
59735 +
59736 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59737 + if (IS_ERR(tfm)) {
59738 + /* should never happen, since sha256 should be built in */
59739 + return 1;
59740 + }
59741 +
59742 + desc.tfm = tfm;
59743 + desc.flags = 0;
59744 +
59745 + crypto_hash_init(&desc);
59746 +
59747 + p = salt;
59748 + sg_set_buf(&sg, p, GR_SALT_LEN);
59749 + crypto_hash_update(&desc, &sg, sg.length);
59750 +
59751 + p = entry->pw;
59752 + sg_set_buf(&sg, p, strlen(p));
59753 +
59754 + crypto_hash_update(&desc, &sg, sg.length);
59755 +
59756 + crypto_hash_final(&desc, temp_sum);
59757 +
59758 + memset(entry->pw, 0, GR_PW_LEN);
59759 +
59760 + for (i = 0; i < GR_SHA_LEN; i++)
59761 + if (sum[i] != temp_sum[i])
59762 + retval = 1;
59763 + else
59764 + dummy = 1; // waste a cycle
59765 +
59766 + crypto_free_hash(tfm);
59767 +
59768 + return retval;
59769 +}
59770 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59771 index 9e6e1c6..d47b906 100644
59772 --- a/include/acpi/acpi_bus.h
59773 +++ b/include/acpi/acpi_bus.h
59774 @@ -138,7 +138,7 @@ struct acpi_device_ops {
59775 acpi_op_bind bind;
59776 acpi_op_unbind unbind;
59777 acpi_op_notify notify;
59778 -};
59779 +} __no_const;
59780
59781 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59782
59783 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59784 index b7babf0..3ba8aee 100644
59785 --- a/include/asm-generic/atomic-long.h
59786 +++ b/include/asm-generic/atomic-long.h
59787 @@ -22,6 +22,12 @@
59788
59789 typedef atomic64_t atomic_long_t;
59790
59791 +#ifdef CONFIG_PAX_REFCOUNT
59792 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59793 +#else
59794 +typedef atomic64_t atomic_long_unchecked_t;
59795 +#endif
59796 +
59797 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59798
59799 static inline long atomic_long_read(atomic_long_t *l)
59800 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59801 return (long)atomic64_read(v);
59802 }
59803
59804 +#ifdef CONFIG_PAX_REFCOUNT
59805 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59806 +{
59807 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59808 +
59809 + return (long)atomic64_read_unchecked(v);
59810 +}
59811 +#endif
59812 +
59813 static inline void atomic_long_set(atomic_long_t *l, long i)
59814 {
59815 atomic64_t *v = (atomic64_t *)l;
59816 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59817 atomic64_set(v, i);
59818 }
59819
59820 +#ifdef CONFIG_PAX_REFCOUNT
59821 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59822 +{
59823 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59824 +
59825 + atomic64_set_unchecked(v, i);
59826 +}
59827 +#endif
59828 +
59829 static inline void atomic_long_inc(atomic_long_t *l)
59830 {
59831 atomic64_t *v = (atomic64_t *)l;
59832 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59833 atomic64_inc(v);
59834 }
59835
59836 +#ifdef CONFIG_PAX_REFCOUNT
59837 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59838 +{
59839 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59840 +
59841 + atomic64_inc_unchecked(v);
59842 +}
59843 +#endif
59844 +
59845 static inline void atomic_long_dec(atomic_long_t *l)
59846 {
59847 atomic64_t *v = (atomic64_t *)l;
59848 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59849 atomic64_dec(v);
59850 }
59851
59852 +#ifdef CONFIG_PAX_REFCOUNT
59853 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59854 +{
59855 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59856 +
59857 + atomic64_dec_unchecked(v);
59858 +}
59859 +#endif
59860 +
59861 static inline void atomic_long_add(long i, atomic_long_t *l)
59862 {
59863 atomic64_t *v = (atomic64_t *)l;
59864 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59865 atomic64_add(i, v);
59866 }
59867
59868 +#ifdef CONFIG_PAX_REFCOUNT
59869 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59870 +{
59871 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59872 +
59873 + atomic64_add_unchecked(i, v);
59874 +}
59875 +#endif
59876 +
59877 static inline void atomic_long_sub(long i, atomic_long_t *l)
59878 {
59879 atomic64_t *v = (atomic64_t *)l;
59880 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59881 atomic64_sub(i, v);
59882 }
59883
59884 +#ifdef CONFIG_PAX_REFCOUNT
59885 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59886 +{
59887 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59888 +
59889 + atomic64_sub_unchecked(i, v);
59890 +}
59891 +#endif
59892 +
59893 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59894 {
59895 atomic64_t *v = (atomic64_t *)l;
59896 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59897 return (long)atomic64_inc_return(v);
59898 }
59899
59900 +#ifdef CONFIG_PAX_REFCOUNT
59901 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59902 +{
59903 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59904 +
59905 + return (long)atomic64_inc_return_unchecked(v);
59906 +}
59907 +#endif
59908 +
59909 static inline long atomic_long_dec_return(atomic_long_t *l)
59910 {
59911 atomic64_t *v = (atomic64_t *)l;
59912 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59913
59914 typedef atomic_t atomic_long_t;
59915
59916 +#ifdef CONFIG_PAX_REFCOUNT
59917 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59918 +#else
59919 +typedef atomic_t atomic_long_unchecked_t;
59920 +#endif
59921 +
59922 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59923 static inline long atomic_long_read(atomic_long_t *l)
59924 {
59925 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59926 return (long)atomic_read(v);
59927 }
59928
59929 +#ifdef CONFIG_PAX_REFCOUNT
59930 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59931 +{
59932 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59933 +
59934 + return (long)atomic_read_unchecked(v);
59935 +}
59936 +#endif
59937 +
59938 static inline void atomic_long_set(atomic_long_t *l, long i)
59939 {
59940 atomic_t *v = (atomic_t *)l;
59941 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59942 atomic_set(v, i);
59943 }
59944
59945 +#ifdef CONFIG_PAX_REFCOUNT
59946 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59947 +{
59948 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59949 +
59950 + atomic_set_unchecked(v, i);
59951 +}
59952 +#endif
59953 +
59954 static inline void atomic_long_inc(atomic_long_t *l)
59955 {
59956 atomic_t *v = (atomic_t *)l;
59957 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59958 atomic_inc(v);
59959 }
59960
59961 +#ifdef CONFIG_PAX_REFCOUNT
59962 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59963 +{
59964 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59965 +
59966 + atomic_inc_unchecked(v);
59967 +}
59968 +#endif
59969 +
59970 static inline void atomic_long_dec(atomic_long_t *l)
59971 {
59972 atomic_t *v = (atomic_t *)l;
59973 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59974 atomic_dec(v);
59975 }
59976
59977 +#ifdef CONFIG_PAX_REFCOUNT
59978 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59979 +{
59980 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59981 +
59982 + atomic_dec_unchecked(v);
59983 +}
59984 +#endif
59985 +
59986 static inline void atomic_long_add(long i, atomic_long_t *l)
59987 {
59988 atomic_t *v = (atomic_t *)l;
59989 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59990 atomic_add(i, v);
59991 }
59992
59993 +#ifdef CONFIG_PAX_REFCOUNT
59994 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59995 +{
59996 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59997 +
59998 + atomic_add_unchecked(i, v);
59999 +}
60000 +#endif
60001 +
60002 static inline void atomic_long_sub(long i, atomic_long_t *l)
60003 {
60004 atomic_t *v = (atomic_t *)l;
60005 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60006 atomic_sub(i, v);
60007 }
60008
60009 +#ifdef CONFIG_PAX_REFCOUNT
60010 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60011 +{
60012 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60013 +
60014 + atomic_sub_unchecked(i, v);
60015 +}
60016 +#endif
60017 +
60018 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60019 {
60020 atomic_t *v = (atomic_t *)l;
60021 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60022 return (long)atomic_inc_return(v);
60023 }
60024
60025 +#ifdef CONFIG_PAX_REFCOUNT
60026 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60027 +{
60028 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60029 +
60030 + return (long)atomic_inc_return_unchecked(v);
60031 +}
60032 +#endif
60033 +
60034 static inline long atomic_long_dec_return(atomic_long_t *l)
60035 {
60036 atomic_t *v = (atomic_t *)l;
60037 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60038
60039 #endif /* BITS_PER_LONG == 64 */
60040
60041 +#ifdef CONFIG_PAX_REFCOUNT
60042 +static inline void pax_refcount_needs_these_functions(void)
60043 +{
60044 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60045 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60046 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60047 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60048 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60049 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60050 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60051 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60052 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60053 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60054 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60055 +#ifdef CONFIG_X86
60056 + atomic_clear_mask_unchecked(0, NULL);
60057 + atomic_set_mask_unchecked(0, NULL);
60058 +#endif
60059 +
60060 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60061 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60062 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60063 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60064 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60065 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60066 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60067 +}
60068 +#else
60069 +#define atomic_read_unchecked(v) atomic_read(v)
60070 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60071 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60072 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60073 +#define atomic_inc_unchecked(v) atomic_inc(v)
60074 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60075 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60076 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60077 +#define atomic_dec_unchecked(v) atomic_dec(v)
60078 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60079 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60080 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60081 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60082 +
60083 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60084 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60085 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60086 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60087 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60088 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60089 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60090 +#endif
60091 +
60092 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60093 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60094 index 1ced641..c896ee8 100644
60095 --- a/include/asm-generic/atomic.h
60096 +++ b/include/asm-generic/atomic.h
60097 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60098 * Atomically clears the bits set in @mask from @v
60099 */
60100 #ifndef atomic_clear_mask
60101 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60102 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60103 {
60104 unsigned long flags;
60105
60106 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60107 index b18ce4f..2ee2843 100644
60108 --- a/include/asm-generic/atomic64.h
60109 +++ b/include/asm-generic/atomic64.h
60110 @@ -16,6 +16,8 @@ typedef struct {
60111 long long counter;
60112 } atomic64_t;
60113
60114 +typedef atomic64_t atomic64_unchecked_t;
60115 +
60116 #define ATOMIC64_INIT(i) { (i) }
60117
60118 extern long long atomic64_read(const atomic64_t *v);
60119 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60120 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60121 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60122
60123 +#define atomic64_read_unchecked(v) atomic64_read(v)
60124 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60125 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60126 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60127 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60128 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60129 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60130 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60131 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60132 +
60133 #endif /* _ASM_GENERIC_ATOMIC64_H */
60134 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60135 index 1bfcfe5..e04c5c9 100644
60136 --- a/include/asm-generic/cache.h
60137 +++ b/include/asm-generic/cache.h
60138 @@ -6,7 +6,7 @@
60139 * cache lines need to provide their own cache.h.
60140 */
60141
60142 -#define L1_CACHE_SHIFT 5
60143 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60144 +#define L1_CACHE_SHIFT 5UL
60145 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60146
60147 #endif /* __ASM_GENERIC_CACHE_H */
60148 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60149 index 0d68a1e..b74a761 100644
60150 --- a/include/asm-generic/emergency-restart.h
60151 +++ b/include/asm-generic/emergency-restart.h
60152 @@ -1,7 +1,7 @@
60153 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60154 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60155
60156 -static inline void machine_emergency_restart(void)
60157 +static inline __noreturn void machine_emergency_restart(void)
60158 {
60159 machine_restart(NULL);
60160 }
60161 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60162 index 0232ccb..13d9165 100644
60163 --- a/include/asm-generic/kmap_types.h
60164 +++ b/include/asm-generic/kmap_types.h
60165 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60166 KMAP_D(17) KM_NMI,
60167 KMAP_D(18) KM_NMI_PTE,
60168 KMAP_D(19) KM_KDB,
60169 +KMAP_D(20) KM_CLEARPAGE,
60170 /*
60171 * Remember to update debug_kmap_atomic() when adding new kmap types!
60172 */
60173 -KMAP_D(20) KM_TYPE_NR
60174 +KMAP_D(21) KM_TYPE_NR
60175 };
60176
60177 #undef KMAP_D
60178 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60179 index 9ceb03b..2efbcbd 100644
60180 --- a/include/asm-generic/local.h
60181 +++ b/include/asm-generic/local.h
60182 @@ -39,6 +39,7 @@ typedef struct
60183 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60184 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60185 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60186 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60187
60188 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60189 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60190 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60191 index 725612b..9cc513a 100644
60192 --- a/include/asm-generic/pgtable-nopmd.h
60193 +++ b/include/asm-generic/pgtable-nopmd.h
60194 @@ -1,14 +1,19 @@
60195 #ifndef _PGTABLE_NOPMD_H
60196 #define _PGTABLE_NOPMD_H
60197
60198 -#ifndef __ASSEMBLY__
60199 -
60200 #include <asm-generic/pgtable-nopud.h>
60201
60202 -struct mm_struct;
60203 -
60204 #define __PAGETABLE_PMD_FOLDED
60205
60206 +#define PMD_SHIFT PUD_SHIFT
60207 +#define PTRS_PER_PMD 1
60208 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60209 +#define PMD_MASK (~(PMD_SIZE-1))
60210 +
60211 +#ifndef __ASSEMBLY__
60212 +
60213 +struct mm_struct;
60214 +
60215 /*
60216 * Having the pmd type consist of a pud gets the size right, and allows
60217 * us to conceptually access the pud entry that this pmd is folded into
60218 @@ -16,11 +21,6 @@ struct mm_struct;
60219 */
60220 typedef struct { pud_t pud; } pmd_t;
60221
60222 -#define PMD_SHIFT PUD_SHIFT
60223 -#define PTRS_PER_PMD 1
60224 -#define PMD_SIZE (1UL << PMD_SHIFT)
60225 -#define PMD_MASK (~(PMD_SIZE-1))
60226 -
60227 /*
60228 * The "pud_xxx()" functions here are trivial for a folded two-level
60229 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60230 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60231 index 810431d..0ec4804f 100644
60232 --- a/include/asm-generic/pgtable-nopud.h
60233 +++ b/include/asm-generic/pgtable-nopud.h
60234 @@ -1,10 +1,15 @@
60235 #ifndef _PGTABLE_NOPUD_H
60236 #define _PGTABLE_NOPUD_H
60237
60238 -#ifndef __ASSEMBLY__
60239 -
60240 #define __PAGETABLE_PUD_FOLDED
60241
60242 +#define PUD_SHIFT PGDIR_SHIFT
60243 +#define PTRS_PER_PUD 1
60244 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60245 +#define PUD_MASK (~(PUD_SIZE-1))
60246 +
60247 +#ifndef __ASSEMBLY__
60248 +
60249 /*
60250 * Having the pud type consist of a pgd gets the size right, and allows
60251 * us to conceptually access the pgd entry that this pud is folded into
60252 @@ -12,11 +17,6 @@
60253 */
60254 typedef struct { pgd_t pgd; } pud_t;
60255
60256 -#define PUD_SHIFT PGDIR_SHIFT
60257 -#define PTRS_PER_PUD 1
60258 -#define PUD_SIZE (1UL << PUD_SHIFT)
60259 -#define PUD_MASK (~(PUD_SIZE-1))
60260 -
60261 /*
60262 * The "pgd_xxx()" functions here are trivial for a folded two-level
60263 * setup: the pud is never bad, and a pud always exists (as it's folded
60264 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60265 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60266
60267 #define pgd_populate(mm, pgd, pud) do { } while (0)
60268 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60269 /*
60270 * (puds are folded into pgds so this doesn't get actually called,
60271 * but the define is needed for a generic inline function.)
60272 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60273 index ff4947b..f48183f 100644
60274 --- a/include/asm-generic/pgtable.h
60275 +++ b/include/asm-generic/pgtable.h
60276 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60277 #endif
60278 }
60279
60280 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60281 +static inline unsigned long pax_open_kernel(void) { return 0; }
60282 +#endif
60283 +
60284 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60285 +static inline unsigned long pax_close_kernel(void) { return 0; }
60286 +#endif
60287 +
60288 #endif /* CONFIG_MMU */
60289
60290 #endif /* !__ASSEMBLY__ */
60291 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60292 index 4e2e1cc..12c266b 100644
60293 --- a/include/asm-generic/vmlinux.lds.h
60294 +++ b/include/asm-generic/vmlinux.lds.h
60295 @@ -218,6 +218,7 @@
60296 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60297 VMLINUX_SYMBOL(__start_rodata) = .; \
60298 *(.rodata) *(.rodata.*) \
60299 + *(.data..read_only) \
60300 *(__vermagic) /* Kernel version magic */ \
60301 . = ALIGN(8); \
60302 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60303 @@ -716,17 +717,18 @@
60304 * section in the linker script will go there too. @phdr should have
60305 * a leading colon.
60306 *
60307 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60308 + * Note that this macros defines per_cpu_load as an absolute symbol.
60309 * If there is no need to put the percpu section at a predetermined
60310 * address, use PERCPU_SECTION.
60311 */
60312 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60313 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60314 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60315 + per_cpu_load = .; \
60316 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60317 - LOAD_OFFSET) { \
60318 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60319 PERCPU_INPUT(cacheline) \
60320 } phdr \
60321 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60322 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60323
60324 /**
60325 * PERCPU_SECTION - define output section for percpu area, simple version
60326 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60327 index 31ad880..4e79884 100644
60328 --- a/include/drm/drmP.h
60329 +++ b/include/drm/drmP.h
60330 @@ -72,6 +72,7 @@
60331 #include <linux/workqueue.h>
60332 #include <linux/poll.h>
60333 #include <asm/pgalloc.h>
60334 +#include <asm/local.h>
60335 #include "drm.h"
60336
60337 #include <linux/idr.h>
60338 @@ -1074,7 +1075,7 @@ struct drm_device {
60339
60340 /** \name Usage Counters */
60341 /*@{ */
60342 - int open_count; /**< Outstanding files open */
60343 + local_t open_count; /**< Outstanding files open */
60344 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60345 atomic_t vma_count; /**< Outstanding vma areas open */
60346 int buf_use; /**< Buffers in use -- cannot alloc */
60347 @@ -1085,7 +1086,7 @@ struct drm_device {
60348 /*@{ */
60349 unsigned long counters;
60350 enum drm_stat_type types[15];
60351 - atomic_t counts[15];
60352 + atomic_unchecked_t counts[15];
60353 /*@} */
60354
60355 struct list_head filelist;
60356 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60357 index 7988e55..ec974c9 100644
60358 --- a/include/drm/drm_crtc_helper.h
60359 +++ b/include/drm/drm_crtc_helper.h
60360 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60361
60362 /* disable crtc when not in use - more explicit than dpms off */
60363 void (*disable)(struct drm_crtc *crtc);
60364 -};
60365 +} __no_const;
60366
60367 /**
60368 * drm_encoder_helper_funcs - helper operations for encoders
60369 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60370 struct drm_connector *connector);
60371 /* disable encoder when not in use - more explicit than dpms off */
60372 void (*disable)(struct drm_encoder *encoder);
60373 -};
60374 +} __no_const;
60375
60376 /**
60377 * drm_connector_helper_funcs - helper operations for connectors
60378 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60379 index d6d1da4..fdd1ac5 100644
60380 --- a/include/drm/ttm/ttm_memory.h
60381 +++ b/include/drm/ttm/ttm_memory.h
60382 @@ -48,7 +48,7 @@
60383
60384 struct ttm_mem_shrink {
60385 int (*do_shrink) (struct ttm_mem_shrink *);
60386 -};
60387 +} __no_const;
60388
60389 /**
60390 * struct ttm_mem_global - Global memory accounting structure.
60391 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60392 index e86dfca..40cc55f 100644
60393 --- a/include/linux/a.out.h
60394 +++ b/include/linux/a.out.h
60395 @@ -39,6 +39,14 @@ enum machine_type {
60396 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60397 };
60398
60399 +/* Constants for the N_FLAGS field */
60400 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60401 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60402 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60403 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60404 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60405 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60406 +
60407 #if !defined (N_MAGIC)
60408 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60409 #endif
60410 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60411 index 06fd4bb..1caec0d 100644
60412 --- a/include/linux/atmdev.h
60413 +++ b/include/linux/atmdev.h
60414 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60415 #endif
60416
60417 struct k_atm_aal_stats {
60418 -#define __HANDLE_ITEM(i) atomic_t i
60419 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60420 __AAL_STAT_ITEMS
60421 #undef __HANDLE_ITEM
60422 };
60423 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60424 index 366422b..1fa7f84 100644
60425 --- a/include/linux/binfmts.h
60426 +++ b/include/linux/binfmts.h
60427 @@ -89,6 +89,7 @@ struct linux_binfmt {
60428 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60429 int (*load_shlib)(struct file *);
60430 int (*core_dump)(struct coredump_params *cprm);
60431 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60432 unsigned long min_coredump; /* minimal dump size */
60433 };
60434
60435 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60436 index 07954b0..cb2ae71 100644
60437 --- a/include/linux/blkdev.h
60438 +++ b/include/linux/blkdev.h
60439 @@ -1393,7 +1393,7 @@ struct block_device_operations {
60440 /* this callback is with swap_lock and sometimes page table lock held */
60441 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60442 struct module *owner;
60443 -};
60444 +} __do_const;
60445
60446 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60447 unsigned long);
60448 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60449 index 4d1a074..88f929a 100644
60450 --- a/include/linux/blktrace_api.h
60451 +++ b/include/linux/blktrace_api.h
60452 @@ -162,7 +162,7 @@ struct blk_trace {
60453 struct dentry *dir;
60454 struct dentry *dropped_file;
60455 struct dentry *msg_file;
60456 - atomic_t dropped;
60457 + atomic_unchecked_t dropped;
60458 };
60459
60460 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60461 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60462 index 83195fb..0b0f77d 100644
60463 --- a/include/linux/byteorder/little_endian.h
60464 +++ b/include/linux/byteorder/little_endian.h
60465 @@ -42,51 +42,51 @@
60466
60467 static inline __le64 __cpu_to_le64p(const __u64 *p)
60468 {
60469 - return (__force __le64)*p;
60470 + return (__force const __le64)*p;
60471 }
60472 static inline __u64 __le64_to_cpup(const __le64 *p)
60473 {
60474 - return (__force __u64)*p;
60475 + return (__force const __u64)*p;
60476 }
60477 static inline __le32 __cpu_to_le32p(const __u32 *p)
60478 {
60479 - return (__force __le32)*p;
60480 + return (__force const __le32)*p;
60481 }
60482 static inline __u32 __le32_to_cpup(const __le32 *p)
60483 {
60484 - return (__force __u32)*p;
60485 + return (__force const __u32)*p;
60486 }
60487 static inline __le16 __cpu_to_le16p(const __u16 *p)
60488 {
60489 - return (__force __le16)*p;
60490 + return (__force const __le16)*p;
60491 }
60492 static inline __u16 __le16_to_cpup(const __le16 *p)
60493 {
60494 - return (__force __u16)*p;
60495 + return (__force const __u16)*p;
60496 }
60497 static inline __be64 __cpu_to_be64p(const __u64 *p)
60498 {
60499 - return (__force __be64)__swab64p(p);
60500 + return (__force const __be64)__swab64p(p);
60501 }
60502 static inline __u64 __be64_to_cpup(const __be64 *p)
60503 {
60504 - return __swab64p((__u64 *)p);
60505 + return __swab64p((const __u64 *)p);
60506 }
60507 static inline __be32 __cpu_to_be32p(const __u32 *p)
60508 {
60509 - return (__force __be32)__swab32p(p);
60510 + return (__force const __be32)__swab32p(p);
60511 }
60512 static inline __u32 __be32_to_cpup(const __be32 *p)
60513 {
60514 - return __swab32p((__u32 *)p);
60515 + return __swab32p((const __u32 *)p);
60516 }
60517 static inline __be16 __cpu_to_be16p(const __u16 *p)
60518 {
60519 - return (__force __be16)__swab16p(p);
60520 + return (__force const __be16)__swab16p(p);
60521 }
60522 static inline __u16 __be16_to_cpup(const __be16 *p)
60523 {
60524 - return __swab16p((__u16 *)p);
60525 + return __swab16p((const __u16 *)p);
60526 }
60527 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60528 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60529 diff --git a/include/linux/cache.h b/include/linux/cache.h
60530 index 4c57065..4307975 100644
60531 --- a/include/linux/cache.h
60532 +++ b/include/linux/cache.h
60533 @@ -16,6 +16,10 @@
60534 #define __read_mostly
60535 #endif
60536
60537 +#ifndef __read_only
60538 +#define __read_only __read_mostly
60539 +#endif
60540 +
60541 #ifndef ____cacheline_aligned
60542 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60543 #endif
60544 diff --git a/include/linux/capability.h b/include/linux/capability.h
60545 index d10b7ed..11390a1 100644
60546 --- a/include/linux/capability.h
60547 +++ b/include/linux/capability.h
60548 @@ -553,6 +553,9 @@ extern bool capable(int cap);
60549 extern bool ns_capable(struct user_namespace *ns, int cap);
60550 extern bool nsown_capable(int cap);
60551 extern bool inode_capable(const struct inode *inode, int cap);
60552 +extern bool capable_nolog(int cap);
60553 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60554 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
60555
60556 /* audit system wants to get cap info from files as well */
60557 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60558 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60559 index 42e55de..1cd0e66 100644
60560 --- a/include/linux/cleancache.h
60561 +++ b/include/linux/cleancache.h
60562 @@ -31,7 +31,7 @@ struct cleancache_ops {
60563 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60564 void (*invalidate_inode)(int, struct cleancache_filekey);
60565 void (*invalidate_fs)(int);
60566 -};
60567 +} __no_const;
60568
60569 extern struct cleancache_ops
60570 cleancache_register_ops(struct cleancache_ops *ops);
60571 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
60572 index 4a0b483..f1f70ba 100644
60573 --- a/include/linux/clk-provider.h
60574 +++ b/include/linux/clk-provider.h
60575 @@ -110,6 +110,7 @@ struct clk_ops {
60576 unsigned long);
60577 void (*init)(struct clk_hw *hw);
60578 };
60579 +typedef struct clk_ops __no_const clk_ops_no_const;
60580
60581 /**
60582 * struct clk_init_data - holds init data that's common to all clocks and is
60583 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60584 index 2f40791..9c9e13c 100644
60585 --- a/include/linux/compiler-gcc4.h
60586 +++ b/include/linux/compiler-gcc4.h
60587 @@ -32,6 +32,20 @@
60588 #define __linktime_error(message) __attribute__((__error__(message)))
60589
60590 #if __GNUC_MINOR__ >= 5
60591 +
60592 +#ifdef CONSTIFY_PLUGIN
60593 +#define __no_const __attribute__((no_const))
60594 +#define __do_const __attribute__((do_const))
60595 +#endif
60596 +
60597 +#ifdef SIZE_OVERFLOW_PLUGIN
60598 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60599 +#endif
60600 +
60601 +#ifdef LATENT_ENTROPY_PLUGIN
60602 +#define __latent_entropy __attribute__((latent_entropy))
60603 +#endif
60604 +
60605 /*
60606 * Mark a position in code as unreachable. This can be used to
60607 * suppress control flow warnings after asm blocks that transfer
60608 @@ -47,6 +61,11 @@
60609 #define __noclone __attribute__((__noclone__))
60610
60611 #endif
60612 +
60613 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60614 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60615 +#define __bos0(ptr) __bos((ptr), 0)
60616 +#define __bos1(ptr) __bos((ptr), 1)
60617 #endif
60618
60619 #if __GNUC_MINOR__ > 0
60620 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60621 index 923d093..1fef491 100644
60622 --- a/include/linux/compiler.h
60623 +++ b/include/linux/compiler.h
60624 @@ -5,31 +5,62 @@
60625
60626 #ifdef __CHECKER__
60627 # define __user __attribute__((noderef, address_space(1)))
60628 +# define __force_user __force __user
60629 # define __kernel __attribute__((address_space(0)))
60630 +# define __force_kernel __force __kernel
60631 # define __safe __attribute__((safe))
60632 # define __force __attribute__((force))
60633 # define __nocast __attribute__((nocast))
60634 # define __iomem __attribute__((noderef, address_space(2)))
60635 +# define __force_iomem __force __iomem
60636 # define __acquires(x) __attribute__((context(x,0,1)))
60637 # define __releases(x) __attribute__((context(x,1,0)))
60638 # define __acquire(x) __context__(x,1)
60639 # define __release(x) __context__(x,-1)
60640 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60641 # define __percpu __attribute__((noderef, address_space(3)))
60642 +# define __force_percpu __force __percpu
60643 #ifdef CONFIG_SPARSE_RCU_POINTER
60644 # define __rcu __attribute__((noderef, address_space(4)))
60645 +# define __force_rcu __force __rcu
60646 #else
60647 # define __rcu
60648 +# define __force_rcu
60649 #endif
60650 extern void __chk_user_ptr(const volatile void __user *);
60651 extern void __chk_io_ptr(const volatile void __iomem *);
60652 +#elif defined(CHECKER_PLUGIN)
60653 +//# define __user
60654 +//# define __force_user
60655 +//# define __kernel
60656 +//# define __force_kernel
60657 +# define __safe
60658 +# define __force
60659 +# define __nocast
60660 +# define __iomem
60661 +# define __force_iomem
60662 +# define __chk_user_ptr(x) (void)0
60663 +# define __chk_io_ptr(x) (void)0
60664 +# define __builtin_warning(x, y...) (1)
60665 +# define __acquires(x)
60666 +# define __releases(x)
60667 +# define __acquire(x) (void)0
60668 +# define __release(x) (void)0
60669 +# define __cond_lock(x,c) (c)
60670 +# define __percpu
60671 +# define __force_percpu
60672 +# define __rcu
60673 +# define __force_rcu
60674 #else
60675 # define __user
60676 +# define __force_user
60677 # define __kernel
60678 +# define __force_kernel
60679 # define __safe
60680 # define __force
60681 # define __nocast
60682 # define __iomem
60683 +# define __force_iomem
60684 # define __chk_user_ptr(x) (void)0
60685 # define __chk_io_ptr(x) (void)0
60686 # define __builtin_warning(x, y...) (1)
60687 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60688 # define __release(x) (void)0
60689 # define __cond_lock(x,c) (c)
60690 # define __percpu
60691 +# define __force_percpu
60692 # define __rcu
60693 +# define __force_rcu
60694 #endif
60695
60696 #ifdef __KERNEL__
60697 @@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60698 # define __attribute_const__ /* unimplemented */
60699 #endif
60700
60701 +#ifndef __no_const
60702 +# define __no_const
60703 +#endif
60704 +
60705 +#ifndef __do_const
60706 +# define __do_const
60707 +#endif
60708 +
60709 +#ifndef __size_overflow
60710 +# define __size_overflow(...)
60711 +#endif
60712 +
60713 +#ifndef __latent_entropy
60714 +# define __latent_entropy
60715 +#endif
60716 +
60717 /*
60718 * Tell gcc if a function is cold. The compiler will assume any path
60719 * directly leading to the call is unlikely.
60720 @@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60721 #define __cold
60722 #endif
60723
60724 +#ifndef __alloc_size
60725 +#define __alloc_size(...)
60726 +#endif
60727 +
60728 +#ifndef __bos
60729 +#define __bos(ptr, arg)
60730 +#endif
60731 +
60732 +#ifndef __bos0
60733 +#define __bos0(ptr)
60734 +#endif
60735 +
60736 +#ifndef __bos1
60737 +#define __bos1(ptr)
60738 +#endif
60739 +
60740 /* Simple shorthand for a section definition */
60741 #ifndef __section
60742 # define __section(S) __attribute__ ((__section__(#S)))
60743 @@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60744 * use is to mediate communication between process-level code and irq/NMI
60745 * handlers, all running on the same CPU.
60746 */
60747 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60748 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60749 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60750
60751 #endif /* __LINUX_COMPILER_H */
60752 diff --git a/include/linux/cred.h b/include/linux/cred.h
60753 index ebbed2c..908cc2c 100644
60754 --- a/include/linux/cred.h
60755 +++ b/include/linux/cred.h
60756 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60757 static inline void validate_process_creds(void)
60758 {
60759 }
60760 +static inline void validate_task_creds(struct task_struct *task)
60761 +{
60762 +}
60763 #endif
60764
60765 /**
60766 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60767 index b92eadf..b4ecdc1 100644
60768 --- a/include/linux/crypto.h
60769 +++ b/include/linux/crypto.h
60770 @@ -373,7 +373,7 @@ struct cipher_tfm {
60771 const u8 *key, unsigned int keylen);
60772 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60773 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60774 -};
60775 +} __no_const;
60776
60777 struct hash_tfm {
60778 int (*init)(struct hash_desc *desc);
60779 @@ -394,13 +394,13 @@ struct compress_tfm {
60780 int (*cot_decompress)(struct crypto_tfm *tfm,
60781 const u8 *src, unsigned int slen,
60782 u8 *dst, unsigned int *dlen);
60783 -};
60784 +} __no_const;
60785
60786 struct rng_tfm {
60787 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60788 unsigned int dlen);
60789 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60790 -};
60791 +} __no_const;
60792
60793 #define crt_ablkcipher crt_u.ablkcipher
60794 #define crt_aead crt_u.aead
60795 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60796 index 7925bf0..d5143d2 100644
60797 --- a/include/linux/decompress/mm.h
60798 +++ b/include/linux/decompress/mm.h
60799 @@ -77,7 +77,7 @@ static void free(void *where)
60800 * warnings when not needed (indeed large_malloc / large_free are not
60801 * needed by inflate */
60802
60803 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60804 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60805 #define free(a) kfree(a)
60806
60807 #define large_malloc(a) vmalloc(a)
60808 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60809 index dfc099e..e583e66 100644
60810 --- a/include/linux/dma-mapping.h
60811 +++ b/include/linux/dma-mapping.h
60812 @@ -51,7 +51,7 @@ struct dma_map_ops {
60813 u64 (*get_required_mask)(struct device *dev);
60814 #endif
60815 int is_phys;
60816 -};
60817 +} __do_const;
60818
60819 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60820
60821 diff --git a/include/linux/efi.h b/include/linux/efi.h
60822 index ec45ccd..9923c32 100644
60823 --- a/include/linux/efi.h
60824 +++ b/include/linux/efi.h
60825 @@ -635,7 +635,7 @@ struct efivar_operations {
60826 efi_get_variable_t *get_variable;
60827 efi_get_next_variable_t *get_next_variable;
60828 efi_set_variable_t *set_variable;
60829 -};
60830 +} __no_const;
60831
60832 struct efivars {
60833 /*
60834 diff --git a/include/linux/elf.h b/include/linux/elf.h
60835 index 999b4f5..57753b4 100644
60836 --- a/include/linux/elf.h
60837 +++ b/include/linux/elf.h
60838 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60839 #define PT_GNU_EH_FRAME 0x6474e550
60840
60841 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60842 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60843 +
60844 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60845 +
60846 +/* Constants for the e_flags field */
60847 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60848 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60849 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60850 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60851 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60852 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60853
60854 /*
60855 * Extended Numbering
60856 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60857 #define DT_DEBUG 21
60858 #define DT_TEXTREL 22
60859 #define DT_JMPREL 23
60860 +#define DT_FLAGS 30
60861 + #define DF_TEXTREL 0x00000004
60862 #define DT_ENCODING 32
60863 #define OLD_DT_LOOS 0x60000000
60864 #define DT_LOOS 0x6000000d
60865 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60866 #define PF_W 0x2
60867 #define PF_X 0x1
60868
60869 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60870 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60871 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60872 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60873 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60874 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60875 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60876 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60877 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60878 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60879 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60880 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60881 +
60882 typedef struct elf32_phdr{
60883 Elf32_Word p_type;
60884 Elf32_Off p_offset;
60885 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60886 #define EI_OSABI 7
60887 #define EI_PAD 8
60888
60889 +#define EI_PAX 14
60890 +
60891 #define ELFMAG0 0x7f /* EI_MAG */
60892 #define ELFMAG1 'E'
60893 #define ELFMAG2 'L'
60894 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60895 #define elf_note elf32_note
60896 #define elf_addr_t Elf32_Off
60897 #define Elf_Half Elf32_Half
60898 +#define elf_dyn Elf32_Dyn
60899
60900 #else
60901
60902 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60903 #define elf_note elf64_note
60904 #define elf_addr_t Elf64_Off
60905 #define Elf_Half Elf64_Half
60906 +#define elf_dyn Elf64_Dyn
60907
60908 #endif
60909
60910 diff --git a/include/linux/filter.h b/include/linux/filter.h
60911 index 82b0135..917914d 100644
60912 --- a/include/linux/filter.h
60913 +++ b/include/linux/filter.h
60914 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
60915
60916 struct sk_buff;
60917 struct sock;
60918 +struct bpf_jit_work;
60919
60920 struct sk_filter
60921 {
60922 @@ -153,6 +154,9 @@ struct sk_filter
60923 unsigned int len; /* Number of filter blocks */
60924 unsigned int (*bpf_func)(const struct sk_buff *skb,
60925 const struct sock_filter *filter);
60926 +#ifdef CONFIG_BPF_JIT
60927 + struct bpf_jit_work *work;
60928 +#endif
60929 struct rcu_head rcu;
60930 struct sock_filter insns[0];
60931 };
60932 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60933 index 7edcf10..714d5e8 100644
60934 --- a/include/linux/firewire.h
60935 +++ b/include/linux/firewire.h
60936 @@ -430,7 +430,7 @@ struct fw_iso_context {
60937 union {
60938 fw_iso_callback_t sc;
60939 fw_iso_mc_callback_t mc;
60940 - } callback;
60941 + } __no_const callback;
60942 void *callback_data;
60943 };
60944
60945 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
60946 index 0e4e2ee..4ff4312 100644
60947 --- a/include/linux/frontswap.h
60948 +++ b/include/linux/frontswap.h
60949 @@ -11,7 +11,7 @@ struct frontswap_ops {
60950 int (*load)(unsigned, pgoff_t, struct page *);
60951 void (*invalidate_page)(unsigned, pgoff_t);
60952 void (*invalidate_area)(unsigned);
60953 -};
60954 +} __no_const;
60955
60956 extern bool frontswap_enabled;
60957 extern struct frontswap_ops
60958 diff --git a/include/linux/fs.h b/include/linux/fs.h
60959 index 17fd887..8eebca0 100644
60960 --- a/include/linux/fs.h
60961 +++ b/include/linux/fs.h
60962 @@ -1663,7 +1663,8 @@ struct file_operations {
60963 int (*setlease)(struct file *, long, struct file_lock **);
60964 long (*fallocate)(struct file *file, int mode, loff_t offset,
60965 loff_t len);
60966 -};
60967 +} __do_const;
60968 +typedef struct file_operations __no_const file_operations_no_const;
60969
60970 struct inode_operations {
60971 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60972 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60973 index 003dc0f..3c4ea97 100644
60974 --- a/include/linux/fs_struct.h
60975 +++ b/include/linux/fs_struct.h
60976 @@ -6,7 +6,7 @@
60977 #include <linux/seqlock.h>
60978
60979 struct fs_struct {
60980 - int users;
60981 + atomic_t users;
60982 spinlock_t lock;
60983 seqcount_t seq;
60984 int umask;
60985 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60986 index ce31408..b1ad003 100644
60987 --- a/include/linux/fscache-cache.h
60988 +++ b/include/linux/fscache-cache.h
60989 @@ -102,7 +102,7 @@ struct fscache_operation {
60990 fscache_operation_release_t release;
60991 };
60992
60993 -extern atomic_t fscache_op_debug_id;
60994 +extern atomic_unchecked_t fscache_op_debug_id;
60995 extern void fscache_op_work_func(struct work_struct *work);
60996
60997 extern void fscache_enqueue_operation(struct fscache_operation *);
60998 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60999 {
61000 INIT_WORK(&op->work, fscache_op_work_func);
61001 atomic_set(&op->usage, 1);
61002 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61003 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61004 op->processor = processor;
61005 op->release = release;
61006 INIT_LIST_HEAD(&op->pend_link);
61007 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61008 index a6dfe69..569586df 100644
61009 --- a/include/linux/fsnotify.h
61010 +++ b/include/linux/fsnotify.h
61011 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61012 */
61013 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61014 {
61015 - return kstrdup(name, GFP_KERNEL);
61016 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61017 }
61018
61019 /*
61020 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61021 index 63d966d..cdcb717 100644
61022 --- a/include/linux/fsnotify_backend.h
61023 +++ b/include/linux/fsnotify_backend.h
61024 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61025 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61026 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61027 };
61028 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61029
61030 /*
61031 * A group is a "thing" that wants to receive notification about filesystem
61032 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61033 index 176a939..1462211 100644
61034 --- a/include/linux/ftrace_event.h
61035 +++ b/include/linux/ftrace_event.h
61036 @@ -97,7 +97,7 @@ struct trace_event_functions {
61037 trace_print_func raw;
61038 trace_print_func hex;
61039 trace_print_func binary;
61040 -};
61041 +} __no_const;
61042
61043 struct trace_event {
61044 struct hlist_node node;
61045 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61046 extern int trace_add_event_call(struct ftrace_event_call *call);
61047 extern void trace_remove_event_call(struct ftrace_event_call *call);
61048
61049 -#define is_signed_type(type) (((type)(-1)) < 0)
61050 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61051
61052 int trace_set_clr_event(const char *system, const char *event, int set);
61053
61054 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61055 index 017a7fb..33a8507 100644
61056 --- a/include/linux/genhd.h
61057 +++ b/include/linux/genhd.h
61058 @@ -185,7 +185,7 @@ struct gendisk {
61059 struct kobject *slave_dir;
61060
61061 struct timer_rand_state *random;
61062 - atomic_t sync_io; /* RAID */
61063 + atomic_unchecked_t sync_io; /* RAID */
61064 struct disk_events *ev;
61065 #ifdef CONFIG_BLK_DEV_INTEGRITY
61066 struct blk_integrity *integrity;
61067 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61068 index 1e49be4..b8a9305 100644
61069 --- a/include/linux/gfp.h
61070 +++ b/include/linux/gfp.h
61071 @@ -38,6 +38,12 @@ struct vm_area_struct;
61072 #define ___GFP_OTHER_NODE 0x800000u
61073 #define ___GFP_WRITE 0x1000000u
61074
61075 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61076 +#define ___GFP_USERCOPY 0x2000000u
61077 +#else
61078 +#define ___GFP_USERCOPY 0
61079 +#endif
61080 +
61081 /*
61082 * GFP bitmasks..
61083 *
61084 @@ -87,6 +93,7 @@ struct vm_area_struct;
61085 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61086 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61087 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61088 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61089
61090 /*
61091 * This may seem redundant, but it's a way of annotating false positives vs.
61092 @@ -94,7 +101,7 @@ struct vm_area_struct;
61093 */
61094 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61095
61096 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61097 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61098 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61099
61100 /* This equals 0, but use constants in case they ever change */
61101 @@ -148,6 +155,8 @@ struct vm_area_struct;
61102 /* 4GB DMA on some platforms */
61103 #define GFP_DMA32 __GFP_DMA32
61104
61105 +#define GFP_USERCOPY __GFP_USERCOPY
61106 +
61107 /* Convert GFP flags to their corresponding migrate type */
61108 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61109 {
61110 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61111 new file mode 100644
61112 index 0000000..c938b1f
61113 --- /dev/null
61114 +++ b/include/linux/gracl.h
61115 @@ -0,0 +1,319 @@
61116 +#ifndef GR_ACL_H
61117 +#define GR_ACL_H
61118 +
61119 +#include <linux/grdefs.h>
61120 +#include <linux/resource.h>
61121 +#include <linux/capability.h>
61122 +#include <linux/dcache.h>
61123 +#include <asm/resource.h>
61124 +
61125 +/* Major status information */
61126 +
61127 +#define GR_VERSION "grsecurity 2.9.1"
61128 +#define GRSECURITY_VERSION 0x2901
61129 +
61130 +enum {
61131 + GR_SHUTDOWN = 0,
61132 + GR_ENABLE = 1,
61133 + GR_SPROLE = 2,
61134 + GR_RELOAD = 3,
61135 + GR_SEGVMOD = 4,
61136 + GR_STATUS = 5,
61137 + GR_UNSPROLE = 6,
61138 + GR_PASSSET = 7,
61139 + GR_SPROLEPAM = 8,
61140 +};
61141 +
61142 +/* Password setup definitions
61143 + * kernel/grhash.c */
61144 +enum {
61145 + GR_PW_LEN = 128,
61146 + GR_SALT_LEN = 16,
61147 + GR_SHA_LEN = 32,
61148 +};
61149 +
61150 +enum {
61151 + GR_SPROLE_LEN = 64,
61152 +};
61153 +
61154 +enum {
61155 + GR_NO_GLOB = 0,
61156 + GR_REG_GLOB,
61157 + GR_CREATE_GLOB
61158 +};
61159 +
61160 +#define GR_NLIMITS 32
61161 +
61162 +/* Begin Data Structures */
61163 +
61164 +struct sprole_pw {
61165 + unsigned char *rolename;
61166 + unsigned char salt[GR_SALT_LEN];
61167 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61168 +};
61169 +
61170 +struct name_entry {
61171 + __u32 key;
61172 + ino_t inode;
61173 + dev_t device;
61174 + char *name;
61175 + __u16 len;
61176 + __u8 deleted;
61177 + struct name_entry *prev;
61178 + struct name_entry *next;
61179 +};
61180 +
61181 +struct inodev_entry {
61182 + struct name_entry *nentry;
61183 + struct inodev_entry *prev;
61184 + struct inodev_entry *next;
61185 +};
61186 +
61187 +struct acl_role_db {
61188 + struct acl_role_label **r_hash;
61189 + __u32 r_size;
61190 +};
61191 +
61192 +struct inodev_db {
61193 + struct inodev_entry **i_hash;
61194 + __u32 i_size;
61195 +};
61196 +
61197 +struct name_db {
61198 + struct name_entry **n_hash;
61199 + __u32 n_size;
61200 +};
61201 +
61202 +struct crash_uid {
61203 + uid_t uid;
61204 + unsigned long expires;
61205 +};
61206 +
61207 +struct gr_hash_struct {
61208 + void **table;
61209 + void **nametable;
61210 + void *first;
61211 + __u32 table_size;
61212 + __u32 used_size;
61213 + int type;
61214 +};
61215 +
61216 +/* Userspace Grsecurity ACL data structures */
61217 +
61218 +struct acl_subject_label {
61219 + char *filename;
61220 + ino_t inode;
61221 + dev_t device;
61222 + __u32 mode;
61223 + kernel_cap_t cap_mask;
61224 + kernel_cap_t cap_lower;
61225 + kernel_cap_t cap_invert_audit;
61226 +
61227 + struct rlimit res[GR_NLIMITS];
61228 + __u32 resmask;
61229 +
61230 + __u8 user_trans_type;
61231 + __u8 group_trans_type;
61232 + uid_t *user_transitions;
61233 + gid_t *group_transitions;
61234 + __u16 user_trans_num;
61235 + __u16 group_trans_num;
61236 +
61237 + __u32 sock_families[2];
61238 + __u32 ip_proto[8];
61239 + __u32 ip_type;
61240 + struct acl_ip_label **ips;
61241 + __u32 ip_num;
61242 + __u32 inaddr_any_override;
61243 +
61244 + __u32 crashes;
61245 + unsigned long expires;
61246 +
61247 + struct acl_subject_label *parent_subject;
61248 + struct gr_hash_struct *hash;
61249 + struct acl_subject_label *prev;
61250 + struct acl_subject_label *next;
61251 +
61252 + struct acl_object_label **obj_hash;
61253 + __u32 obj_hash_size;
61254 + __u16 pax_flags;
61255 +};
61256 +
61257 +struct role_allowed_ip {
61258 + __u32 addr;
61259 + __u32 netmask;
61260 +
61261 + struct role_allowed_ip *prev;
61262 + struct role_allowed_ip *next;
61263 +};
61264 +
61265 +struct role_transition {
61266 + char *rolename;
61267 +
61268 + struct role_transition *prev;
61269 + struct role_transition *next;
61270 +};
61271 +
61272 +struct acl_role_label {
61273 + char *rolename;
61274 + uid_t uidgid;
61275 + __u16 roletype;
61276 +
61277 + __u16 auth_attempts;
61278 + unsigned long expires;
61279 +
61280 + struct acl_subject_label *root_label;
61281 + struct gr_hash_struct *hash;
61282 +
61283 + struct acl_role_label *prev;
61284 + struct acl_role_label *next;
61285 +
61286 + struct role_transition *transitions;
61287 + struct role_allowed_ip *allowed_ips;
61288 + uid_t *domain_children;
61289 + __u16 domain_child_num;
61290 +
61291 + umode_t umask;
61292 +
61293 + struct acl_subject_label **subj_hash;
61294 + __u32 subj_hash_size;
61295 +};
61296 +
61297 +struct user_acl_role_db {
61298 + struct acl_role_label **r_table;
61299 + __u32 num_pointers; /* Number of allocations to track */
61300 + __u32 num_roles; /* Number of roles */
61301 + __u32 num_domain_children; /* Number of domain children */
61302 + __u32 num_subjects; /* Number of subjects */
61303 + __u32 num_objects; /* Number of objects */
61304 +};
61305 +
61306 +struct acl_object_label {
61307 + char *filename;
61308 + ino_t inode;
61309 + dev_t device;
61310 + __u32 mode;
61311 +
61312 + struct acl_subject_label *nested;
61313 + struct acl_object_label *globbed;
61314 +
61315 + /* next two structures not used */
61316 +
61317 + struct acl_object_label *prev;
61318 + struct acl_object_label *next;
61319 +};
61320 +
61321 +struct acl_ip_label {
61322 + char *iface;
61323 + __u32 addr;
61324 + __u32 netmask;
61325 + __u16 low, high;
61326 + __u8 mode;
61327 + __u32 type;
61328 + __u32 proto[8];
61329 +
61330 + /* next two structures not used */
61331 +
61332 + struct acl_ip_label *prev;
61333 + struct acl_ip_label *next;
61334 +};
61335 +
61336 +struct gr_arg {
61337 + struct user_acl_role_db role_db;
61338 + unsigned char pw[GR_PW_LEN];
61339 + unsigned char salt[GR_SALT_LEN];
61340 + unsigned char sum[GR_SHA_LEN];
61341 + unsigned char sp_role[GR_SPROLE_LEN];
61342 + struct sprole_pw *sprole_pws;
61343 + dev_t segv_device;
61344 + ino_t segv_inode;
61345 + uid_t segv_uid;
61346 + __u16 num_sprole_pws;
61347 + __u16 mode;
61348 +};
61349 +
61350 +struct gr_arg_wrapper {
61351 + struct gr_arg *arg;
61352 + __u32 version;
61353 + __u32 size;
61354 +};
61355 +
61356 +struct subject_map {
61357 + struct acl_subject_label *user;
61358 + struct acl_subject_label *kernel;
61359 + struct subject_map *prev;
61360 + struct subject_map *next;
61361 +};
61362 +
61363 +struct acl_subj_map_db {
61364 + struct subject_map **s_hash;
61365 + __u32 s_size;
61366 +};
61367 +
61368 +/* End Data Structures Section */
61369 +
61370 +/* Hash functions generated by empirical testing by Brad Spengler
61371 + Makes good use of the low bits of the inode. Generally 0-1 times
61372 + in loop for successful match. 0-3 for unsuccessful match.
61373 + Shift/add algorithm with modulus of table size and an XOR*/
61374 +
61375 +static __inline__ unsigned int
61376 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61377 +{
61378 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61379 +}
61380 +
61381 + static __inline__ unsigned int
61382 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61383 +{
61384 + return ((const unsigned long)userp % sz);
61385 +}
61386 +
61387 +static __inline__ unsigned int
61388 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61389 +{
61390 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61391 +}
61392 +
61393 +static __inline__ unsigned int
61394 +nhash(const char *name, const __u16 len, const unsigned int sz)
61395 +{
61396 + return full_name_hash((const unsigned char *)name, len) % sz;
61397 +}
61398 +
61399 +#define FOR_EACH_ROLE_START(role) \
61400 + role = role_list; \
61401 + while (role) {
61402 +
61403 +#define FOR_EACH_ROLE_END(role) \
61404 + role = role->prev; \
61405 + }
61406 +
61407 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61408 + subj = NULL; \
61409 + iter = 0; \
61410 + while (iter < role->subj_hash_size) { \
61411 + if (subj == NULL) \
61412 + subj = role->subj_hash[iter]; \
61413 + if (subj == NULL) { \
61414 + iter++; \
61415 + continue; \
61416 + }
61417 +
61418 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61419 + subj = subj->next; \
61420 + if (subj == NULL) \
61421 + iter++; \
61422 + }
61423 +
61424 +
61425 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61426 + subj = role->hash->first; \
61427 + while (subj != NULL) {
61428 +
61429 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61430 + subj = subj->next; \
61431 + }
61432 +
61433 +#endif
61434 +
61435 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61436 new file mode 100644
61437 index 0000000..323ecf2
61438 --- /dev/null
61439 +++ b/include/linux/gralloc.h
61440 @@ -0,0 +1,9 @@
61441 +#ifndef __GRALLOC_H
61442 +#define __GRALLOC_H
61443 +
61444 +void acl_free_all(void);
61445 +int acl_alloc_stack_init(unsigned long size);
61446 +void *acl_alloc(unsigned long len);
61447 +void *acl_alloc_num(unsigned long num, unsigned long len);
61448 +
61449 +#endif
61450 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61451 new file mode 100644
61452 index 0000000..b30e9bc
61453 --- /dev/null
61454 +++ b/include/linux/grdefs.h
61455 @@ -0,0 +1,140 @@
61456 +#ifndef GRDEFS_H
61457 +#define GRDEFS_H
61458 +
61459 +/* Begin grsecurity status declarations */
61460 +
61461 +enum {
61462 + GR_READY = 0x01,
61463 + GR_STATUS_INIT = 0x00 // disabled state
61464 +};
61465 +
61466 +/* Begin ACL declarations */
61467 +
61468 +/* Role flags */
61469 +
61470 +enum {
61471 + GR_ROLE_USER = 0x0001,
61472 + GR_ROLE_GROUP = 0x0002,
61473 + GR_ROLE_DEFAULT = 0x0004,
61474 + GR_ROLE_SPECIAL = 0x0008,
61475 + GR_ROLE_AUTH = 0x0010,
61476 + GR_ROLE_NOPW = 0x0020,
61477 + GR_ROLE_GOD = 0x0040,
61478 + GR_ROLE_LEARN = 0x0080,
61479 + GR_ROLE_TPE = 0x0100,
61480 + GR_ROLE_DOMAIN = 0x0200,
61481 + GR_ROLE_PAM = 0x0400,
61482 + GR_ROLE_PERSIST = 0x0800
61483 +};
61484 +
61485 +/* ACL Subject and Object mode flags */
61486 +enum {
61487 + GR_DELETED = 0x80000000
61488 +};
61489 +
61490 +/* ACL Object-only mode flags */
61491 +enum {
61492 + GR_READ = 0x00000001,
61493 + GR_APPEND = 0x00000002,
61494 + GR_WRITE = 0x00000004,
61495 + GR_EXEC = 0x00000008,
61496 + GR_FIND = 0x00000010,
61497 + GR_INHERIT = 0x00000020,
61498 + GR_SETID = 0x00000040,
61499 + GR_CREATE = 0x00000080,
61500 + GR_DELETE = 0x00000100,
61501 + GR_LINK = 0x00000200,
61502 + GR_AUDIT_READ = 0x00000400,
61503 + GR_AUDIT_APPEND = 0x00000800,
61504 + GR_AUDIT_WRITE = 0x00001000,
61505 + GR_AUDIT_EXEC = 0x00002000,
61506 + GR_AUDIT_FIND = 0x00004000,
61507 + GR_AUDIT_INHERIT= 0x00008000,
61508 + GR_AUDIT_SETID = 0x00010000,
61509 + GR_AUDIT_CREATE = 0x00020000,
61510 + GR_AUDIT_DELETE = 0x00040000,
61511 + GR_AUDIT_LINK = 0x00080000,
61512 + GR_PTRACERD = 0x00100000,
61513 + GR_NOPTRACE = 0x00200000,
61514 + GR_SUPPRESS = 0x00400000,
61515 + GR_NOLEARN = 0x00800000,
61516 + GR_INIT_TRANSFER= 0x01000000
61517 +};
61518 +
61519 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61520 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61521 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61522 +
61523 +/* ACL subject-only mode flags */
61524 +enum {
61525 + GR_KILL = 0x00000001,
61526 + GR_VIEW = 0x00000002,
61527 + GR_PROTECTED = 0x00000004,
61528 + GR_LEARN = 0x00000008,
61529 + GR_OVERRIDE = 0x00000010,
61530 + /* just a placeholder, this mode is only used in userspace */
61531 + GR_DUMMY = 0x00000020,
61532 + GR_PROTSHM = 0x00000040,
61533 + GR_KILLPROC = 0x00000080,
61534 + GR_KILLIPPROC = 0x00000100,
61535 + /* just a placeholder, this mode is only used in userspace */
61536 + GR_NOTROJAN = 0x00000200,
61537 + GR_PROTPROCFD = 0x00000400,
61538 + GR_PROCACCT = 0x00000800,
61539 + GR_RELAXPTRACE = 0x00001000,
61540 + GR_NESTED = 0x00002000,
61541 + GR_INHERITLEARN = 0x00004000,
61542 + GR_PROCFIND = 0x00008000,
61543 + GR_POVERRIDE = 0x00010000,
61544 + GR_KERNELAUTH = 0x00020000,
61545 + GR_ATSECURE = 0x00040000,
61546 + GR_SHMEXEC = 0x00080000
61547 +};
61548 +
61549 +enum {
61550 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61551 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61552 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61553 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61554 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61555 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61556 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61557 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61558 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61559 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61560 +};
61561 +
61562 +enum {
61563 + GR_ID_USER = 0x01,
61564 + GR_ID_GROUP = 0x02,
61565 +};
61566 +
61567 +enum {
61568 + GR_ID_ALLOW = 0x01,
61569 + GR_ID_DENY = 0x02,
61570 +};
61571 +
61572 +#define GR_CRASH_RES 31
61573 +#define GR_UIDTABLE_MAX 500
61574 +
61575 +/* begin resource learning section */
61576 +enum {
61577 + GR_RLIM_CPU_BUMP = 60,
61578 + GR_RLIM_FSIZE_BUMP = 50000,
61579 + GR_RLIM_DATA_BUMP = 10000,
61580 + GR_RLIM_STACK_BUMP = 1000,
61581 + GR_RLIM_CORE_BUMP = 10000,
61582 + GR_RLIM_RSS_BUMP = 500000,
61583 + GR_RLIM_NPROC_BUMP = 1,
61584 + GR_RLIM_NOFILE_BUMP = 5,
61585 + GR_RLIM_MEMLOCK_BUMP = 50000,
61586 + GR_RLIM_AS_BUMP = 500000,
61587 + GR_RLIM_LOCKS_BUMP = 2,
61588 + GR_RLIM_SIGPENDING_BUMP = 5,
61589 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61590 + GR_RLIM_NICE_BUMP = 1,
61591 + GR_RLIM_RTPRIO_BUMP = 1,
61592 + GR_RLIM_RTTIME_BUMP = 1000000
61593 +};
61594 +
61595 +#endif
61596 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61597 new file mode 100644
61598 index 0000000..c9292f7
61599 --- /dev/null
61600 +++ b/include/linux/grinternal.h
61601 @@ -0,0 +1,223 @@
61602 +#ifndef __GRINTERNAL_H
61603 +#define __GRINTERNAL_H
61604 +
61605 +#ifdef CONFIG_GRKERNSEC
61606 +
61607 +#include <linux/fs.h>
61608 +#include <linux/mnt_namespace.h>
61609 +#include <linux/nsproxy.h>
61610 +#include <linux/gracl.h>
61611 +#include <linux/grdefs.h>
61612 +#include <linux/grmsg.h>
61613 +
61614 +void gr_add_learn_entry(const char *fmt, ...)
61615 + __attribute__ ((format (printf, 1, 2)));
61616 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61617 + const struct vfsmount *mnt);
61618 +__u32 gr_check_create(const struct dentry *new_dentry,
61619 + const struct dentry *parent,
61620 + const struct vfsmount *mnt, const __u32 mode);
61621 +int gr_check_protected_task(const struct task_struct *task);
61622 +__u32 to_gr_audit(const __u32 reqmode);
61623 +int gr_set_acls(const int type);
61624 +int gr_apply_subject_to_task(struct task_struct *task);
61625 +int gr_acl_is_enabled(void);
61626 +char gr_roletype_to_char(void);
61627 +
61628 +void gr_handle_alertkill(struct task_struct *task);
61629 +char *gr_to_filename(const struct dentry *dentry,
61630 + const struct vfsmount *mnt);
61631 +char *gr_to_filename1(const struct dentry *dentry,
61632 + const struct vfsmount *mnt);
61633 +char *gr_to_filename2(const struct dentry *dentry,
61634 + const struct vfsmount *mnt);
61635 +char *gr_to_filename3(const struct dentry *dentry,
61636 + const struct vfsmount *mnt);
61637 +
61638 +extern int grsec_enable_ptrace_readexec;
61639 +extern int grsec_enable_harden_ptrace;
61640 +extern int grsec_enable_link;
61641 +extern int grsec_enable_fifo;
61642 +extern int grsec_enable_execve;
61643 +extern int grsec_enable_shm;
61644 +extern int grsec_enable_execlog;
61645 +extern int grsec_enable_signal;
61646 +extern int grsec_enable_audit_ptrace;
61647 +extern int grsec_enable_forkfail;
61648 +extern int grsec_enable_time;
61649 +extern int grsec_enable_rofs;
61650 +extern int grsec_enable_chroot_shmat;
61651 +extern int grsec_enable_chroot_mount;
61652 +extern int grsec_enable_chroot_double;
61653 +extern int grsec_enable_chroot_pivot;
61654 +extern int grsec_enable_chroot_chdir;
61655 +extern int grsec_enable_chroot_chmod;
61656 +extern int grsec_enable_chroot_mknod;
61657 +extern int grsec_enable_chroot_fchdir;
61658 +extern int grsec_enable_chroot_nice;
61659 +extern int grsec_enable_chroot_execlog;
61660 +extern int grsec_enable_chroot_caps;
61661 +extern int grsec_enable_chroot_sysctl;
61662 +extern int grsec_enable_chroot_unix;
61663 +extern int grsec_enable_symlinkown;
61664 +extern int grsec_symlinkown_gid;
61665 +extern int grsec_enable_tpe;
61666 +extern int grsec_tpe_gid;
61667 +extern int grsec_enable_tpe_all;
61668 +extern int grsec_enable_tpe_invert;
61669 +extern int grsec_enable_socket_all;
61670 +extern int grsec_socket_all_gid;
61671 +extern int grsec_enable_socket_client;
61672 +extern int grsec_socket_client_gid;
61673 +extern int grsec_enable_socket_server;
61674 +extern int grsec_socket_server_gid;
61675 +extern int grsec_audit_gid;
61676 +extern int grsec_enable_group;
61677 +extern int grsec_enable_audit_textrel;
61678 +extern int grsec_enable_log_rwxmaps;
61679 +extern int grsec_enable_mount;
61680 +extern int grsec_enable_chdir;
61681 +extern int grsec_resource_logging;
61682 +extern int grsec_enable_blackhole;
61683 +extern int grsec_lastack_retries;
61684 +extern int grsec_enable_brute;
61685 +extern int grsec_lock;
61686 +
61687 +extern spinlock_t grsec_alert_lock;
61688 +extern unsigned long grsec_alert_wtime;
61689 +extern unsigned long grsec_alert_fyet;
61690 +
61691 +extern spinlock_t grsec_audit_lock;
61692 +
61693 +extern rwlock_t grsec_exec_file_lock;
61694 +
61695 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61696 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61697 + (tsk)->exec_file->f_vfsmnt) : "/")
61698 +
61699 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61700 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61701 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61702 +
61703 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61704 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61705 + (tsk)->exec_file->f_vfsmnt) : "/")
61706 +
61707 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61708 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61709 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61710 +
61711 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61712 +
61713 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61714 +
61715 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61716 + (task)->pid, (cred)->uid, \
61717 + (cred)->euid, (cred)->gid, (cred)->egid, \
61718 + gr_parent_task_fullpath(task), \
61719 + (task)->real_parent->comm, (task)->real_parent->pid, \
61720 + (pcred)->uid, (pcred)->euid, \
61721 + (pcred)->gid, (pcred)->egid
61722 +
61723 +#define GR_CHROOT_CAPS {{ \
61724 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61725 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61726 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61727 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61728 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61729 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61730 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61731 +
61732 +#define security_learn(normal_msg,args...) \
61733 +({ \
61734 + read_lock(&grsec_exec_file_lock); \
61735 + gr_add_learn_entry(normal_msg "\n", ## args); \
61736 + read_unlock(&grsec_exec_file_lock); \
61737 +})
61738 +
61739 +enum {
61740 + GR_DO_AUDIT,
61741 + GR_DONT_AUDIT,
61742 + /* used for non-audit messages that we shouldn't kill the task on */
61743 + GR_DONT_AUDIT_GOOD
61744 +};
61745 +
61746 +enum {
61747 + GR_TTYSNIFF,
61748 + GR_RBAC,
61749 + GR_RBAC_STR,
61750 + GR_STR_RBAC,
61751 + GR_RBAC_MODE2,
61752 + GR_RBAC_MODE3,
61753 + GR_FILENAME,
61754 + GR_SYSCTL_HIDDEN,
61755 + GR_NOARGS,
61756 + GR_ONE_INT,
61757 + GR_ONE_INT_TWO_STR,
61758 + GR_ONE_STR,
61759 + GR_STR_INT,
61760 + GR_TWO_STR_INT,
61761 + GR_TWO_INT,
61762 + GR_TWO_U64,
61763 + GR_THREE_INT,
61764 + GR_FIVE_INT_TWO_STR,
61765 + GR_TWO_STR,
61766 + GR_THREE_STR,
61767 + GR_FOUR_STR,
61768 + GR_STR_FILENAME,
61769 + GR_FILENAME_STR,
61770 + GR_FILENAME_TWO_INT,
61771 + GR_FILENAME_TWO_INT_STR,
61772 + GR_TEXTREL,
61773 + GR_PTRACE,
61774 + GR_RESOURCE,
61775 + GR_CAP,
61776 + GR_SIG,
61777 + GR_SIG2,
61778 + GR_CRASH1,
61779 + GR_CRASH2,
61780 + GR_PSACCT,
61781 + GR_RWXMAP
61782 +};
61783 +
61784 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61785 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61786 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61787 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61788 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61789 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61790 +#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)
61791 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61792 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61793 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61794 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61795 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61796 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61797 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61798 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61799 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61800 +#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)
61801 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61802 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61803 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61804 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61805 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61806 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61807 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61808 +#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)
61809 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61810 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61811 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61812 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61813 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61814 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61815 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61816 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61817 +#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)
61818 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61819 +
61820 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61821 +
61822 +#endif
61823 +
61824 +#endif
61825 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61826 new file mode 100644
61827 index 0000000..54f4e85
61828 --- /dev/null
61829 +++ b/include/linux/grmsg.h
61830 @@ -0,0 +1,110 @@
61831 +#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"
61832 +#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"
61833 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61834 +#define GR_STOPMOD_MSG "denied modification of module state by "
61835 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61836 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61837 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61838 +#define GR_IOPL_MSG "denied use of iopl() by "
61839 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61840 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61841 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61842 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61843 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61844 +#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"
61845 +#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"
61846 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61847 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61848 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61849 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61850 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61851 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61852 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61853 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61854 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61855 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61856 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61857 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61858 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61859 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61860 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61861 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61862 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61863 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61864 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61865 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61866 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61867 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61868 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61869 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61870 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61871 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61872 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61873 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61874 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61875 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61876 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61877 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61878 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61879 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61880 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61881 +#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"
61882 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61883 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61884 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61885 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61886 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61887 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61888 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61889 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61890 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61891 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61892 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61893 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61894 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61895 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61896 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61897 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61898 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61899 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61900 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61901 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61902 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61903 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61904 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61905 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61906 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61907 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61908 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61909 +#define GR_TIME_MSG "time set by "
61910 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61911 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61912 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61913 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61914 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61915 +#define GR_BIND_MSG "denied bind() by "
61916 +#define GR_CONNECT_MSG "denied connect() by "
61917 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61918 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61919 +#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"
61920 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61921 +#define GR_CAP_ACL_MSG "use of %s denied for "
61922 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61923 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61924 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61925 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61926 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61927 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61928 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61929 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61930 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61931 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61932 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61933 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61934 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61935 +#define GR_VM86_MSG "denied use of vm86 by "
61936 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61937 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61938 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61939 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61940 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61941 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61942 new file mode 100644
61943 index 0000000..38bfb04
61944 --- /dev/null
61945 +++ b/include/linux/grsecurity.h
61946 @@ -0,0 +1,233 @@
61947 +#ifndef GR_SECURITY_H
61948 +#define GR_SECURITY_H
61949 +#include <linux/fs.h>
61950 +#include <linux/fs_struct.h>
61951 +#include <linux/binfmts.h>
61952 +#include <linux/gracl.h>
61953 +
61954 +/* notify of brain-dead configs */
61955 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61956 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61957 +#endif
61958 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61959 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61960 +#endif
61961 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61962 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61963 +#endif
61964 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61965 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61966 +#endif
61967 +
61968 +#include <linux/compat.h>
61969 +
61970 +struct user_arg_ptr {
61971 +#ifdef CONFIG_COMPAT
61972 + bool is_compat;
61973 +#endif
61974 + union {
61975 + const char __user *const __user *native;
61976 +#ifdef CONFIG_COMPAT
61977 + compat_uptr_t __user *compat;
61978 +#endif
61979 + } ptr;
61980 +};
61981 +
61982 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61983 +void gr_handle_brute_check(void);
61984 +void gr_handle_kernel_exploit(void);
61985 +int gr_process_user_ban(void);
61986 +
61987 +char gr_roletype_to_char(void);
61988 +
61989 +int gr_acl_enable_at_secure(void);
61990 +
61991 +int gr_check_user_change(int real, int effective, int fs);
61992 +int gr_check_group_change(int real, int effective, int fs);
61993 +
61994 +void gr_del_task_from_ip_table(struct task_struct *p);
61995 +
61996 +int gr_pid_is_chrooted(struct task_struct *p);
61997 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61998 +int gr_handle_chroot_nice(void);
61999 +int gr_handle_chroot_sysctl(const int op);
62000 +int gr_handle_chroot_setpriority(struct task_struct *p,
62001 + const int niceval);
62002 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62003 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62004 + const struct vfsmount *mnt);
62005 +void gr_handle_chroot_chdir(struct path *path);
62006 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62007 + const struct vfsmount *mnt, const int mode);
62008 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62009 + const struct vfsmount *mnt, const int mode);
62010 +int gr_handle_chroot_mount(const struct dentry *dentry,
62011 + const struct vfsmount *mnt,
62012 + const char *dev_name);
62013 +int gr_handle_chroot_pivot(void);
62014 +int gr_handle_chroot_unix(const pid_t pid);
62015 +
62016 +int gr_handle_rawio(const struct inode *inode);
62017 +
62018 +void gr_handle_ioperm(void);
62019 +void gr_handle_iopl(void);
62020 +
62021 +umode_t gr_acl_umask(void);
62022 +
62023 +int gr_tpe_allow(const struct file *file);
62024 +
62025 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62026 +void gr_clear_chroot_entries(struct task_struct *task);
62027 +
62028 +void gr_log_forkfail(const int retval);
62029 +void gr_log_timechange(void);
62030 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62031 +void gr_log_chdir(const struct dentry *dentry,
62032 + const struct vfsmount *mnt);
62033 +void gr_log_chroot_exec(const struct dentry *dentry,
62034 + const struct vfsmount *mnt);
62035 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62036 +void gr_log_remount(const char *devname, const int retval);
62037 +void gr_log_unmount(const char *devname, const int retval);
62038 +void gr_log_mount(const char *from, const char *to, const int retval);
62039 +void gr_log_textrel(struct vm_area_struct *vma);
62040 +void gr_log_rwxmmap(struct file *file);
62041 +void gr_log_rwxmprotect(struct file *file);
62042 +
62043 +int gr_handle_follow_link(const struct inode *parent,
62044 + const struct inode *inode,
62045 + const struct dentry *dentry,
62046 + const struct vfsmount *mnt);
62047 +int gr_handle_fifo(const struct dentry *dentry,
62048 + const struct vfsmount *mnt,
62049 + const struct dentry *dir, const int flag,
62050 + const int acc_mode);
62051 +int gr_handle_hardlink(const struct dentry *dentry,
62052 + const struct vfsmount *mnt,
62053 + struct inode *inode,
62054 + const int mode, const char *to);
62055 +
62056 +int gr_is_capable(const int cap);
62057 +int gr_is_capable_nolog(const int cap);
62058 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62059 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62060 +
62061 +void gr_learn_resource(const struct task_struct *task, const int limit,
62062 + const unsigned long wanted, const int gt);
62063 +void gr_copy_label(struct task_struct *tsk);
62064 +void gr_handle_crash(struct task_struct *task, const int sig);
62065 +int gr_handle_signal(const struct task_struct *p, const int sig);
62066 +int gr_check_crash_uid(const uid_t uid);
62067 +int gr_check_protected_task(const struct task_struct *task);
62068 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62069 +int gr_acl_handle_mmap(const struct file *file,
62070 + const unsigned long prot);
62071 +int gr_acl_handle_mprotect(const struct file *file,
62072 + const unsigned long prot);
62073 +int gr_check_hidden_task(const struct task_struct *tsk);
62074 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62075 + const struct vfsmount *mnt);
62076 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62077 + const struct vfsmount *mnt);
62078 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62079 + const struct vfsmount *mnt, const int fmode);
62080 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62081 + const struct vfsmount *mnt, umode_t *mode);
62082 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62083 + const struct vfsmount *mnt);
62084 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62085 + const struct vfsmount *mnt);
62086 +int gr_handle_ptrace(struct task_struct *task, const long request);
62087 +int gr_handle_proc_ptrace(struct task_struct *task);
62088 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62089 + const struct vfsmount *mnt);
62090 +int gr_check_crash_exec(const struct file *filp);
62091 +int gr_acl_is_enabled(void);
62092 +void gr_set_kernel_label(struct task_struct *task);
62093 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62094 + const gid_t gid);
62095 +int gr_set_proc_label(const struct dentry *dentry,
62096 + const struct vfsmount *mnt,
62097 + const int unsafe_flags);
62098 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62099 + const struct vfsmount *mnt);
62100 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62101 + const struct vfsmount *mnt, int acc_mode);
62102 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62103 + const struct dentry *p_dentry,
62104 + const struct vfsmount *p_mnt,
62105 + int open_flags, int acc_mode, const int imode);
62106 +void gr_handle_create(const struct dentry *dentry,
62107 + const struct vfsmount *mnt);
62108 +void gr_handle_proc_create(const struct dentry *dentry,
62109 + const struct inode *inode);
62110 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62111 + const struct dentry *parent_dentry,
62112 + const struct vfsmount *parent_mnt,
62113 + const int mode);
62114 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62115 + const struct dentry *parent_dentry,
62116 + const struct vfsmount *parent_mnt);
62117 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62118 + const struct vfsmount *mnt);
62119 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62120 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62121 + const struct vfsmount *mnt);
62122 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62123 + const struct dentry *parent_dentry,
62124 + const struct vfsmount *parent_mnt,
62125 + const char *from);
62126 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62127 + const struct dentry *parent_dentry,
62128 + const struct vfsmount *parent_mnt,
62129 + const struct dentry *old_dentry,
62130 + const struct vfsmount *old_mnt, const char *to);
62131 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62132 +int gr_acl_handle_rename(struct dentry *new_dentry,
62133 + struct dentry *parent_dentry,
62134 + const struct vfsmount *parent_mnt,
62135 + struct dentry *old_dentry,
62136 + struct inode *old_parent_inode,
62137 + struct vfsmount *old_mnt, const char *newname);
62138 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62139 + struct dentry *old_dentry,
62140 + struct dentry *new_dentry,
62141 + struct vfsmount *mnt, const __u8 replace);
62142 +__u32 gr_check_link(const struct dentry *new_dentry,
62143 + const struct dentry *parent_dentry,
62144 + const struct vfsmount *parent_mnt,
62145 + const struct dentry *old_dentry,
62146 + const struct vfsmount *old_mnt);
62147 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62148 + const unsigned int namelen, const ino_t ino);
62149 +
62150 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62151 + const struct vfsmount *mnt);
62152 +void gr_acl_handle_exit(void);
62153 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62154 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62155 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62156 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62157 +void gr_audit_ptrace(struct task_struct *task);
62158 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62159 +
62160 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62161 +
62162 +#ifdef CONFIG_GRKERNSEC
62163 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62164 +void gr_handle_vm86(void);
62165 +void gr_handle_mem_readwrite(u64 from, u64 to);
62166 +
62167 +void gr_log_badprocpid(const char *entry);
62168 +
62169 +extern int grsec_enable_dmesg;
62170 +extern int grsec_disable_privio;
62171 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62172 +extern int grsec_enable_chroot_findtask;
62173 +#endif
62174 +#ifdef CONFIG_GRKERNSEC_SETXID
62175 +extern int grsec_enable_setxid;
62176 +#endif
62177 +#endif
62178 +
62179 +#endif
62180 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62181 new file mode 100644
62182 index 0000000..e7ffaaf
62183 --- /dev/null
62184 +++ b/include/linux/grsock.h
62185 @@ -0,0 +1,19 @@
62186 +#ifndef __GRSOCK_H
62187 +#define __GRSOCK_H
62188 +
62189 +extern void gr_attach_curr_ip(const struct sock *sk);
62190 +extern int gr_handle_sock_all(const int family, const int type,
62191 + const int protocol);
62192 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62193 +extern int gr_handle_sock_server_other(const struct sock *sck);
62194 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62195 +extern int gr_search_connect(struct socket * sock,
62196 + struct sockaddr_in * addr);
62197 +extern int gr_search_bind(struct socket * sock,
62198 + struct sockaddr_in * addr);
62199 +extern int gr_search_listen(struct socket * sock);
62200 +extern int gr_search_accept(struct socket * sock);
62201 +extern int gr_search_socket(const int domain, const int type,
62202 + const int protocol);
62203 +
62204 +#endif
62205 diff --git a/include/linux/hid.h b/include/linux/hid.h
62206 index 449fa38..b37c8cc 100644
62207 --- a/include/linux/hid.h
62208 +++ b/include/linux/hid.h
62209 @@ -704,7 +704,7 @@ struct hid_ll_driver {
62210 unsigned int code, int value);
62211
62212 int (*parse)(struct hid_device *hdev);
62213 -};
62214 +} __no_const;
62215
62216 #define PM_HINT_FULLON 1<<5
62217 #define PM_HINT_NORMAL 1<<1
62218 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62219 index d3999b4..1304cb4 100644
62220 --- a/include/linux/highmem.h
62221 +++ b/include/linux/highmem.h
62222 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62223 kunmap_atomic(kaddr);
62224 }
62225
62226 +static inline void sanitize_highpage(struct page *page)
62227 +{
62228 + void *kaddr;
62229 + unsigned long flags;
62230 +
62231 + local_irq_save(flags);
62232 + kaddr = kmap_atomic(page);
62233 + clear_page(kaddr);
62234 + kunmap_atomic(kaddr);
62235 + local_irq_restore(flags);
62236 +}
62237 +
62238 static inline void zero_user_segments(struct page *page,
62239 unsigned start1, unsigned end1,
62240 unsigned start2, unsigned end2)
62241 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62242 index ddfa041..a44cfff 100644
62243 --- a/include/linux/i2c.h
62244 +++ b/include/linux/i2c.h
62245 @@ -366,6 +366,7 @@ struct i2c_algorithm {
62246 /* To determine what the adapter supports */
62247 u32 (*functionality) (struct i2c_adapter *);
62248 };
62249 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62250
62251 /*
62252 * i2c_adapter is the structure used to identify a physical i2c bus along
62253 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62254 index d23c3c2..eb63c81 100644
62255 --- a/include/linux/i2o.h
62256 +++ b/include/linux/i2o.h
62257 @@ -565,7 +565,7 @@ struct i2o_controller {
62258 struct i2o_device *exec; /* Executive */
62259 #if BITS_PER_LONG == 64
62260 spinlock_t context_list_lock; /* lock for context_list */
62261 - atomic_t context_list_counter; /* needed for unique contexts */
62262 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62263 struct list_head context_list; /* list of context id's
62264 and pointers */
62265 #endif
62266 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62267 index 8185f57..7b2d222 100644
62268 --- a/include/linux/if_team.h
62269 +++ b/include/linux/if_team.h
62270 @@ -74,6 +74,7 @@ struct team_mode_ops {
62271 void (*port_leave)(struct team *team, struct team_port *port);
62272 void (*port_change_mac)(struct team *team, struct team_port *port);
62273 };
62274 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62275
62276 enum team_option_type {
62277 TEAM_OPTION_TYPE_U32,
62278 @@ -136,7 +137,7 @@ struct team {
62279 struct list_head option_inst_list; /* list of option instances */
62280
62281 const struct team_mode *mode;
62282 - struct team_mode_ops ops;
62283 + team_mode_ops_no_const ops;
62284 long mode_priv[TEAM_MODE_PRIV_LONGS];
62285 };
62286
62287 diff --git a/include/linux/init.h b/include/linux/init.h
62288 index 6b95109..bcbdd68 100644
62289 --- a/include/linux/init.h
62290 +++ b/include/linux/init.h
62291 @@ -39,9 +39,15 @@
62292 * Also note, that this data cannot be "const".
62293 */
62294
62295 +#ifdef MODULE
62296 +#define add_latent_entropy
62297 +#else
62298 +#define add_latent_entropy __latent_entropy
62299 +#endif
62300 +
62301 /* These are for everybody (although not all archs will actually
62302 discard it in modules) */
62303 -#define __init __section(.init.text) __cold notrace
62304 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62305 #define __initdata __section(.init.data)
62306 #define __initconst __section(.init.rodata)
62307 #define __exitdata __section(.exit.data)
62308 @@ -83,7 +89,7 @@
62309 #define __exit __section(.exit.text) __exitused __cold notrace
62310
62311 /* Used for HOTPLUG */
62312 -#define __devinit __section(.devinit.text) __cold notrace
62313 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62314 #define __devinitdata __section(.devinit.data)
62315 #define __devinitconst __section(.devinit.rodata)
62316 #define __devexit __section(.devexit.text) __exitused __cold notrace
62317 @@ -91,7 +97,7 @@
62318 #define __devexitconst __section(.devexit.rodata)
62319
62320 /* Used for HOTPLUG_CPU */
62321 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62322 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62323 #define __cpuinitdata __section(.cpuinit.data)
62324 #define __cpuinitconst __section(.cpuinit.rodata)
62325 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62326 @@ -99,7 +105,7 @@
62327 #define __cpuexitconst __section(.cpuexit.rodata)
62328
62329 /* Used for MEMORY_HOTPLUG */
62330 -#define __meminit __section(.meminit.text) __cold notrace
62331 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62332 #define __meminitdata __section(.meminit.data)
62333 #define __meminitconst __section(.meminit.rodata)
62334 #define __memexit __section(.memexit.text) __exitused __cold notrace
62335 @@ -294,13 +300,13 @@ void __init parse_early_options(char *cmdline);
62336
62337 /* Each module must use one module_init(). */
62338 #define module_init(initfn) \
62339 - static inline initcall_t __inittest(void) \
62340 + static inline __used initcall_t __inittest(void) \
62341 { return initfn; } \
62342 int init_module(void) __attribute__((alias(#initfn)));
62343
62344 /* This is only required if you want to be unloadable. */
62345 #define module_exit(exitfn) \
62346 - static inline exitcall_t __exittest(void) \
62347 + static inline __used exitcall_t __exittest(void) \
62348 { return exitfn; } \
62349 void cleanup_module(void) __attribute__((alias(#exitfn)));
62350
62351 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62352 index 9e65eff..b131e8b 100644
62353 --- a/include/linux/init_task.h
62354 +++ b/include/linux/init_task.h
62355 @@ -134,6 +134,12 @@ extern struct cred init_cred;
62356
62357 #define INIT_TASK_COMM "swapper"
62358
62359 +#ifdef CONFIG_X86
62360 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62361 +#else
62362 +#define INIT_TASK_THREAD_INFO
62363 +#endif
62364 +
62365 /*
62366 * INIT_TASK is used to set up the first task table, touch at
62367 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62368 @@ -172,6 +178,7 @@ extern struct cred init_cred;
62369 RCU_INIT_POINTER(.cred, &init_cred), \
62370 .comm = INIT_TASK_COMM, \
62371 .thread = INIT_THREAD, \
62372 + INIT_TASK_THREAD_INFO \
62373 .fs = &init_fs, \
62374 .files = &init_files, \
62375 .signal = &init_signals, \
62376 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62377 index e6ca56d..8583707 100644
62378 --- a/include/linux/intel-iommu.h
62379 +++ b/include/linux/intel-iommu.h
62380 @@ -296,7 +296,7 @@ struct iommu_flush {
62381 u8 fm, u64 type);
62382 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62383 unsigned int size_order, u64 type);
62384 -};
62385 +} __no_const;
62386
62387 enum {
62388 SR_DMAR_FECTL_REG,
62389 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62390 index e68a8e5..811b9af 100644
62391 --- a/include/linux/interrupt.h
62392 +++ b/include/linux/interrupt.h
62393 @@ -435,7 +435,7 @@ enum
62394 /* map softirq index to softirq name. update 'softirq_to_name' in
62395 * kernel/softirq.c when adding a new softirq.
62396 */
62397 -extern char *softirq_to_name[NR_SOFTIRQS];
62398 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62399
62400 /* softirq mask and active fields moved to irq_cpustat_t in
62401 * asm/hardirq.h to get better cache usage. KAO
62402 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62403
62404 struct softirq_action
62405 {
62406 - void (*action)(struct softirq_action *);
62407 + void (*action)(void);
62408 };
62409
62410 asmlinkage void do_softirq(void);
62411 asmlinkage void __do_softirq(void);
62412 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62413 +extern void open_softirq(int nr, void (*action)(void));
62414 extern void softirq_init(void);
62415 extern void __raise_softirq_irqoff(unsigned int nr);
62416
62417 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62418 index 6883e19..06992b1 100644
62419 --- a/include/linux/kallsyms.h
62420 +++ b/include/linux/kallsyms.h
62421 @@ -15,7 +15,8 @@
62422
62423 struct module;
62424
62425 -#ifdef CONFIG_KALLSYMS
62426 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62427 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62428 /* Lookup the address for a symbol. Returns 0 if not found. */
62429 unsigned long kallsyms_lookup_name(const char *name);
62430
62431 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62432 /* Stupid that this does nothing, but I didn't create this mess. */
62433 #define __print_symbol(fmt, addr)
62434 #endif /*CONFIG_KALLSYMS*/
62435 +#else /* when included by kallsyms.c, vsnprintf.c, or
62436 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62437 +extern void __print_symbol(const char *fmt, unsigned long address);
62438 +extern int sprint_backtrace(char *buffer, unsigned long address);
62439 +extern int sprint_symbol(char *buffer, unsigned long address);
62440 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62441 +const char *kallsyms_lookup(unsigned long addr,
62442 + unsigned long *symbolsize,
62443 + unsigned long *offset,
62444 + char **modname, char *namebuf);
62445 +#endif
62446
62447 /* This macro allows us to keep printk typechecking */
62448 static __printf(1, 2)
62449 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62450 index c4d2fc1..5df9c19 100644
62451 --- a/include/linux/kgdb.h
62452 +++ b/include/linux/kgdb.h
62453 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62454 extern int kgdb_io_module_registered;
62455
62456 extern atomic_t kgdb_setting_breakpoint;
62457 -extern atomic_t kgdb_cpu_doing_single_step;
62458 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62459
62460 extern struct task_struct *kgdb_usethread;
62461 extern struct task_struct *kgdb_contthread;
62462 @@ -252,7 +252,7 @@ struct kgdb_arch {
62463 void (*disable_hw_break)(struct pt_regs *regs);
62464 void (*remove_all_hw_break)(void);
62465 void (*correct_hw_break)(void);
62466 -};
62467 +} __do_const;
62468
62469 /**
62470 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62471 @@ -277,7 +277,7 @@ struct kgdb_io {
62472 void (*pre_exception) (void);
62473 void (*post_exception) (void);
62474 int is_console;
62475 -};
62476 +} __do_const;
62477
62478 extern struct kgdb_arch arch_kgdb_ops;
62479
62480 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62481 index 5398d58..5883a34 100644
62482 --- a/include/linux/kmod.h
62483 +++ b/include/linux/kmod.h
62484 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62485 * usually useless though. */
62486 extern __printf(2, 3)
62487 int __request_module(bool wait, const char *name, ...);
62488 +extern __printf(3, 4)
62489 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62490 #define request_module(mod...) __request_module(true, mod)
62491 #define request_module_nowait(mod...) __request_module(false, mod)
62492 #define try_then_request_module(x, mod...) \
62493 diff --git a/include/linux/kref.h b/include/linux/kref.h
62494 index 9c07dce..a92fa71 100644
62495 --- a/include/linux/kref.h
62496 +++ b/include/linux/kref.h
62497 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62498 static inline int kref_sub(struct kref *kref, unsigned int count,
62499 void (*release)(struct kref *kref))
62500 {
62501 - WARN_ON(release == NULL);
62502 + BUG_ON(release == NULL);
62503
62504 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62505 release(kref);
62506 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62507 index 96c158a..1864db5 100644
62508 --- a/include/linux/kvm_host.h
62509 +++ b/include/linux/kvm_host.h
62510 @@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62511 void vcpu_load(struct kvm_vcpu *vcpu);
62512 void vcpu_put(struct kvm_vcpu *vcpu);
62513
62514 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62515 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62516 struct module *module);
62517 void kvm_exit(void);
62518
62519 @@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62520 struct kvm_guest_debug *dbg);
62521 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62522
62523 -int kvm_arch_init(void *opaque);
62524 +int kvm_arch_init(const void *opaque);
62525 void kvm_arch_exit(void);
62526
62527 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62528 diff --git a/include/linux/libata.h b/include/linux/libata.h
62529 index 6e887c7..4539601 100644
62530 --- a/include/linux/libata.h
62531 +++ b/include/linux/libata.h
62532 @@ -910,7 +910,7 @@ struct ata_port_operations {
62533 * fields must be pointers.
62534 */
62535 const struct ata_port_operations *inherits;
62536 -};
62537 +} __do_const;
62538
62539 struct ata_port_info {
62540 unsigned long flags;
62541 diff --git a/include/linux/memory.h b/include/linux/memory.h
62542 index 1ac7f6e..a5794d0 100644
62543 --- a/include/linux/memory.h
62544 +++ b/include/linux/memory.h
62545 @@ -143,7 +143,7 @@ struct memory_accessor {
62546 size_t count);
62547 ssize_t (*write)(struct memory_accessor *, const char *buf,
62548 off_t offset, size_t count);
62549 -};
62550 +} __no_const;
62551
62552 /*
62553 * Kernel text modification mutex, used for code patching. Users of this lock
62554 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62555 index 1318ca6..7521340 100644
62556 --- a/include/linux/mfd/abx500.h
62557 +++ b/include/linux/mfd/abx500.h
62558 @@ -452,6 +452,7 @@ struct abx500_ops {
62559 int (*event_registers_startup_state_get) (struct device *, u8 *);
62560 int (*startup_irq_enabled) (struct device *, unsigned int);
62561 };
62562 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62563
62564 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62565 void abx500_remove_ops(struct device *dev);
62566 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62567 index 9b07725..3d55001 100644
62568 --- a/include/linux/mfd/abx500/ux500_chargalg.h
62569 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
62570 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
62571 int (*enable) (struct ux500_charger *, int, int, int);
62572 int (*kick_wd) (struct ux500_charger *);
62573 int (*update_curr) (struct ux500_charger *, int);
62574 -};
62575 +} __no_const;
62576
62577 /**
62578 * struct ux500_charger - power supply ux500 charger sub class
62579 diff --git a/include/linux/mm.h b/include/linux/mm.h
62580 index b36d08c..410ee7c 100644
62581 --- a/include/linux/mm.h
62582 +++ b/include/linux/mm.h
62583 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62584
62585 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62586 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62587 +
62588 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62589 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62590 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62591 +#else
62592 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62593 +#endif
62594 +
62595 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62596 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62597
62598 @@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62599 int set_page_dirty_lock(struct page *page);
62600 int clear_page_dirty_for_io(struct page *page);
62601
62602 -/* Is the vma a continuation of the stack vma above it? */
62603 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62604 -{
62605 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62606 -}
62607 -
62608 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62609 - unsigned long addr)
62610 -{
62611 - return (vma->vm_flags & VM_GROWSDOWN) &&
62612 - (vma->vm_start == addr) &&
62613 - !vma_growsdown(vma->vm_prev, addr);
62614 -}
62615 -
62616 -/* Is the vma a continuation of the stack vma below it? */
62617 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62618 -{
62619 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62620 -}
62621 -
62622 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62623 - unsigned long addr)
62624 -{
62625 - return (vma->vm_flags & VM_GROWSUP) &&
62626 - (vma->vm_end == addr) &&
62627 - !vma_growsup(vma->vm_next, addr);
62628 -}
62629 -
62630 extern pid_t
62631 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62632
62633 @@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62634 }
62635 #endif
62636
62637 +#ifdef CONFIG_MMU
62638 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62639 +#else
62640 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62641 +{
62642 + return __pgprot(0);
62643 +}
62644 +#endif
62645 +
62646 int vma_wants_writenotify(struct vm_area_struct *vma);
62647
62648 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62649 @@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62650 {
62651 return 0;
62652 }
62653 +
62654 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62655 + unsigned long address)
62656 +{
62657 + return 0;
62658 +}
62659 #else
62660 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62661 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62662 #endif
62663
62664 #ifdef __PAGETABLE_PMD_FOLDED
62665 @@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62666 {
62667 return 0;
62668 }
62669 +
62670 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62671 + unsigned long address)
62672 +{
62673 + return 0;
62674 +}
62675 #else
62676 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62677 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62678 #endif
62679
62680 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62681 @@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62682 NULL: pud_offset(pgd, address);
62683 }
62684
62685 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62686 +{
62687 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62688 + NULL: pud_offset(pgd, address);
62689 +}
62690 +
62691 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62692 {
62693 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62694 NULL: pmd_offset(pud, address);
62695 }
62696 +
62697 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62698 +{
62699 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62700 + NULL: pmd_offset(pud, address);
62701 +}
62702 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62703
62704 #if USE_SPLIT_PTLOCKS
62705 @@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62706 unsigned long, unsigned long,
62707 unsigned long, unsigned long);
62708 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62709 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62710
62711 /* These take the mm semaphore themselves */
62712 extern unsigned long vm_brk(unsigned long, unsigned long);
62713 @@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62714 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62715 struct vm_area_struct **pprev);
62716
62717 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62718 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62719 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62720 +
62721 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62722 NULL if none. Assume start_addr < end_addr. */
62723 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62724 @@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62725 return vma;
62726 }
62727
62728 -#ifdef CONFIG_MMU
62729 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62730 -#else
62731 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62732 -{
62733 - return __pgprot(0);
62734 -}
62735 -#endif
62736 -
62737 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62738 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62739 unsigned long pfn, unsigned long size, pgprot_t);
62740 @@ -1598,7 +1608,7 @@ extern int unpoison_memory(unsigned long pfn);
62741 extern int sysctl_memory_failure_early_kill;
62742 extern int sysctl_memory_failure_recovery;
62743 extern void shake_page(struct page *p, int access);
62744 -extern atomic_long_t mce_bad_pages;
62745 +extern atomic_long_unchecked_t mce_bad_pages;
62746 extern int soft_offline_page(struct page *page, int flags);
62747
62748 extern void dump_page(struct page *page);
62749 @@ -1629,5 +1639,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62750 static inline bool page_is_guard(struct page *page) { return false; }
62751 #endif /* CONFIG_DEBUG_PAGEALLOC */
62752
62753 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62754 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62755 +#else
62756 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62757 +#endif
62758 +
62759 #endif /* __KERNEL__ */
62760 #endif /* _LINUX_MM_H */
62761 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62762 index 704a626..bb0705a 100644
62763 --- a/include/linux/mm_types.h
62764 +++ b/include/linux/mm_types.h
62765 @@ -263,6 +263,8 @@ struct vm_area_struct {
62766 #ifdef CONFIG_NUMA
62767 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62768 #endif
62769 +
62770 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62771 };
62772
62773 struct core_thread {
62774 @@ -337,7 +339,7 @@ struct mm_struct {
62775 unsigned long def_flags;
62776 unsigned long nr_ptes; /* Page table pages */
62777 unsigned long start_code, end_code, start_data, end_data;
62778 - unsigned long start_brk, brk, start_stack;
62779 + unsigned long brk_gap, start_brk, brk, start_stack;
62780 unsigned long arg_start, arg_end, env_start, env_end;
62781
62782 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62783 @@ -389,6 +391,24 @@ struct mm_struct {
62784 struct cpumask cpumask_allocation;
62785 #endif
62786 struct uprobes_state uprobes_state;
62787 +
62788 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62789 + unsigned long pax_flags;
62790 +#endif
62791 +
62792 +#ifdef CONFIG_PAX_DLRESOLVE
62793 + unsigned long call_dl_resolve;
62794 +#endif
62795 +
62796 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62797 + unsigned long call_syscall;
62798 +#endif
62799 +
62800 +#ifdef CONFIG_PAX_ASLR
62801 + unsigned long delta_mmap; /* randomized offset */
62802 + unsigned long delta_stack; /* randomized offset */
62803 +#endif
62804 +
62805 };
62806
62807 static inline void mm_init_cpumask(struct mm_struct *mm)
62808 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62809 index 1d1b1e1..2a13c78 100644
62810 --- a/include/linux/mmu_notifier.h
62811 +++ b/include/linux/mmu_notifier.h
62812 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62813 */
62814 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62815 ({ \
62816 - pte_t __pte; \
62817 + pte_t ___pte; \
62818 struct vm_area_struct *___vma = __vma; \
62819 unsigned long ___address = __address; \
62820 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62821 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62822 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62823 - __pte; \
62824 + ___pte; \
62825 })
62826
62827 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62828 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62829 index 68c569f..5f43753 100644
62830 --- a/include/linux/mmzone.h
62831 +++ b/include/linux/mmzone.h
62832 @@ -411,7 +411,7 @@ struct zone {
62833 unsigned long flags; /* zone flags, see below */
62834
62835 /* Zone statistics */
62836 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62837 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62838
62839 /*
62840 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62841 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62842 index 5db9382..50e801d 100644
62843 --- a/include/linux/mod_devicetable.h
62844 +++ b/include/linux/mod_devicetable.h
62845 @@ -12,7 +12,7 @@
62846 typedef unsigned long kernel_ulong_t;
62847 #endif
62848
62849 -#define PCI_ANY_ID (~0)
62850 +#define PCI_ANY_ID ((__u16)~0)
62851
62852 struct pci_device_id {
62853 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62854 @@ -131,7 +131,7 @@ struct usb_device_id {
62855 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62856 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62857
62858 -#define HID_ANY_ID (~0)
62859 +#define HID_ANY_ID (~0U)
62860 #define HID_BUS_ANY 0xffff
62861 #define HID_GROUP_ANY 0x0000
62862
62863 diff --git a/include/linux/module.h b/include/linux/module.h
62864 index fbcafe2..e5d9587 100644
62865 --- a/include/linux/module.h
62866 +++ b/include/linux/module.h
62867 @@ -17,6 +17,7 @@
62868 #include <linux/moduleparam.h>
62869 #include <linux/tracepoint.h>
62870 #include <linux/export.h>
62871 +#include <linux/fs.h>
62872
62873 #include <linux/percpu.h>
62874 #include <asm/module.h>
62875 @@ -273,19 +274,16 @@ struct module
62876 int (*init)(void);
62877
62878 /* If this is non-NULL, vfree after init() returns */
62879 - void *module_init;
62880 + void *module_init_rx, *module_init_rw;
62881
62882 /* Here is the actual code + data, vfree'd on unload. */
62883 - void *module_core;
62884 + void *module_core_rx, *module_core_rw;
62885
62886 /* Here are the sizes of the init and core sections */
62887 - unsigned int init_size, core_size;
62888 + unsigned int init_size_rw, core_size_rw;
62889
62890 /* The size of the executable code in each section. */
62891 - unsigned int init_text_size, core_text_size;
62892 -
62893 - /* Size of RO sections of the module (text+rodata) */
62894 - unsigned int init_ro_size, core_ro_size;
62895 + unsigned int init_size_rx, core_size_rx;
62896
62897 /* Arch-specific module values */
62898 struct mod_arch_specific arch;
62899 @@ -341,6 +339,10 @@ struct module
62900 #ifdef CONFIG_EVENT_TRACING
62901 struct ftrace_event_call **trace_events;
62902 unsigned int num_trace_events;
62903 + struct file_operations trace_id;
62904 + struct file_operations trace_enable;
62905 + struct file_operations trace_format;
62906 + struct file_operations trace_filter;
62907 #endif
62908 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62909 unsigned int num_ftrace_callsites;
62910 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62911 bool is_module_percpu_address(unsigned long addr);
62912 bool is_module_text_address(unsigned long addr);
62913
62914 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62915 +{
62916 +
62917 +#ifdef CONFIG_PAX_KERNEXEC
62918 + if (ktla_ktva(addr) >= (unsigned long)start &&
62919 + ktla_ktva(addr) < (unsigned long)start + size)
62920 + return 1;
62921 +#endif
62922 +
62923 + return ((void *)addr >= start && (void *)addr < start + size);
62924 +}
62925 +
62926 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62927 +{
62928 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62929 +}
62930 +
62931 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62932 +{
62933 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62934 +}
62935 +
62936 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62937 +{
62938 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62939 +}
62940 +
62941 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62942 +{
62943 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62944 +}
62945 +
62946 static inline int within_module_core(unsigned long addr, struct module *mod)
62947 {
62948 - return (unsigned long)mod->module_core <= addr &&
62949 - addr < (unsigned long)mod->module_core + mod->core_size;
62950 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62951 }
62952
62953 static inline int within_module_init(unsigned long addr, struct module *mod)
62954 {
62955 - return (unsigned long)mod->module_init <= addr &&
62956 - addr < (unsigned long)mod->module_init + mod->init_size;
62957 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62958 }
62959
62960 /* Search for module by name: must hold module_mutex. */
62961 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62962 index b2be02e..72d2f78 100644
62963 --- a/include/linux/moduleloader.h
62964 +++ b/include/linux/moduleloader.h
62965 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62966
62967 /* Allocator used for allocating struct module, core sections and init
62968 sections. Returns NULL on failure. */
62969 -void *module_alloc(unsigned long size);
62970 +void *module_alloc(unsigned long size) __size_overflow(1);
62971 +
62972 +#ifdef CONFIG_PAX_KERNEXEC
62973 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62974 +#else
62975 +#define module_alloc_exec(x) module_alloc(x)
62976 +#endif
62977
62978 /* Free memory returned from module_alloc. */
62979 void module_free(struct module *mod, void *module_region);
62980
62981 +#ifdef CONFIG_PAX_KERNEXEC
62982 +void module_free_exec(struct module *mod, void *module_region);
62983 +#else
62984 +#define module_free_exec(x, y) module_free((x), (y))
62985 +#endif
62986 +
62987 /* Apply the given relocation to the (simplified) ELF. Return -error
62988 or 0. */
62989 int apply_relocate(Elf_Shdr *sechdrs,
62990 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62991 index d6a5806..7c13347 100644
62992 --- a/include/linux/moduleparam.h
62993 +++ b/include/linux/moduleparam.h
62994 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62995 * @len is usually just sizeof(string).
62996 */
62997 #define module_param_string(name, string, len, perm) \
62998 - static const struct kparam_string __param_string_##name \
62999 + static const struct kparam_string __param_string_##name __used \
63000 = { len, string }; \
63001 __module_param_call(MODULE_PARAM_PREFIX, name, \
63002 &param_ops_string, \
63003 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63004 */
63005 #define module_param_array_named(name, array, type, nump, perm) \
63006 param_check_##type(name, &(array)[0]); \
63007 - static const struct kparam_array __param_arr_##name \
63008 + static const struct kparam_array __param_arr_##name __used \
63009 = { .max = ARRAY_SIZE(array), .num = nump, \
63010 .ops = &param_ops_##type, \
63011 .elemsize = sizeof(array[0]), .elem = array }; \
63012 diff --git a/include/linux/namei.h b/include/linux/namei.h
63013 index ffc0213..2c1f2cb 100644
63014 --- a/include/linux/namei.h
63015 +++ b/include/linux/namei.h
63016 @@ -24,7 +24,7 @@ struct nameidata {
63017 unsigned seq;
63018 int last_type;
63019 unsigned depth;
63020 - char *saved_names[MAX_NESTED_LINKS + 1];
63021 + const char *saved_names[MAX_NESTED_LINKS + 1];
63022
63023 /* Intent data */
63024 union {
63025 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63026 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63027 extern void unlock_rename(struct dentry *, struct dentry *);
63028
63029 -static inline void nd_set_link(struct nameidata *nd, char *path)
63030 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63031 {
63032 nd->saved_names[nd->depth] = path;
63033 }
63034
63035 -static inline char *nd_get_link(struct nameidata *nd)
63036 +static inline const char *nd_get_link(const struct nameidata *nd)
63037 {
63038 return nd->saved_names[nd->depth];
63039 }
63040 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63041 index d94cb14..e64c951 100644
63042 --- a/include/linux/netdevice.h
63043 +++ b/include/linux/netdevice.h
63044 @@ -1026,6 +1026,7 @@ struct net_device_ops {
63045 struct net_device *dev,
63046 int idx);
63047 };
63048 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63049
63050 /*
63051 * The DEVICE structure.
63052 @@ -1087,7 +1088,7 @@ struct net_device {
63053 int iflink;
63054
63055 struct net_device_stats stats;
63056 - atomic_long_t rx_dropped; /* dropped packets by core network
63057 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63058 * Do not use this in drivers.
63059 */
63060
63061 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63062 new file mode 100644
63063 index 0000000..33f4af8
63064 --- /dev/null
63065 +++ b/include/linux/netfilter/xt_gradm.h
63066 @@ -0,0 +1,9 @@
63067 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63068 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63069 +
63070 +struct xt_gradm_mtinfo {
63071 + __u16 flags;
63072 + __u16 invflags;
63073 +};
63074 +
63075 +#endif
63076 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63077 index c65a18a..0c05f3a 100644
63078 --- a/include/linux/of_pdt.h
63079 +++ b/include/linux/of_pdt.h
63080 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63081
63082 /* return 0 on success; fill in 'len' with number of bytes in path */
63083 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63084 -};
63085 +} __no_const;
63086
63087 extern void *prom_early_alloc(unsigned long size);
63088
63089 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63090 index a4c5624..79d6d88 100644
63091 --- a/include/linux/oprofile.h
63092 +++ b/include/linux/oprofile.h
63093 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63094 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63095 char const * name, ulong * val);
63096
63097 -/** Create a file for read-only access to an atomic_t. */
63098 +/** Create a file for read-only access to an atomic_unchecked_t. */
63099 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63100 - char const * name, atomic_t * val);
63101 + char const * name, atomic_unchecked_t * val);
63102
63103 /** create a directory */
63104 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63105 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63106 index 45db49f..386788e 100644
63107 --- a/include/linux/perf_event.h
63108 +++ b/include/linux/perf_event.h
63109 @@ -879,8 +879,8 @@ struct perf_event {
63110
63111 enum perf_event_active_state state;
63112 unsigned int attach_state;
63113 - local64_t count;
63114 - atomic64_t child_count;
63115 + local64_t count; /* PaX: fix it one day */
63116 + atomic64_unchecked_t child_count;
63117
63118 /*
63119 * These are the total time in nanoseconds that the event
63120 @@ -931,8 +931,8 @@ struct perf_event {
63121 * These accumulate total time (in nanoseconds) that children
63122 * events have been enabled and running, respectively.
63123 */
63124 - atomic64_t child_total_time_enabled;
63125 - atomic64_t child_total_time_running;
63126 + atomic64_unchecked_t child_total_time_enabled;
63127 + atomic64_unchecked_t child_total_time_running;
63128
63129 /*
63130 * Protect attach/detach and child_list:
63131 diff --git a/include/linux/personality.h b/include/linux/personality.h
63132 index 8fc7dd1a..c19d89e 100644
63133 --- a/include/linux/personality.h
63134 +++ b/include/linux/personality.h
63135 @@ -44,6 +44,7 @@ enum {
63136 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63137 ADDR_NO_RANDOMIZE | \
63138 ADDR_COMPAT_LAYOUT | \
63139 + ADDR_LIMIT_3GB | \
63140 MMAP_PAGE_ZERO)
63141
63142 /*
63143 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63144 index e1ac1ce..0675fed 100644
63145 --- a/include/linux/pipe_fs_i.h
63146 +++ b/include/linux/pipe_fs_i.h
63147 @@ -45,9 +45,9 @@ struct pipe_buffer {
63148 struct pipe_inode_info {
63149 wait_queue_head_t wait;
63150 unsigned int nrbufs, curbuf, buffers;
63151 - unsigned int readers;
63152 - unsigned int writers;
63153 - unsigned int waiting_writers;
63154 + atomic_t readers;
63155 + atomic_t writers;
63156 + atomic_t waiting_writers;
63157 unsigned int r_counter;
63158 unsigned int w_counter;
63159 struct page *tmp_page;
63160 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63161 index f271860..6b3bec5 100644
63162 --- a/include/linux/pm_runtime.h
63163 +++ b/include/linux/pm_runtime.h
63164 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63165
63166 static inline void pm_runtime_mark_last_busy(struct device *dev)
63167 {
63168 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63169 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63170 }
63171
63172 #else /* !CONFIG_PM_RUNTIME */
63173 diff --git a/include/linux/poison.h b/include/linux/poison.h
63174 index 2110a81..13a11bb 100644
63175 --- a/include/linux/poison.h
63176 +++ b/include/linux/poison.h
63177 @@ -19,8 +19,8 @@
63178 * under normal circumstances, used to verify that nobody uses
63179 * non-initialized list entries.
63180 */
63181 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63182 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63183 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63184 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63185
63186 /********** include/linux/timer.h **********/
63187 /*
63188 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63189 index 5a710b9..0b0dab9 100644
63190 --- a/include/linux/preempt.h
63191 +++ b/include/linux/preempt.h
63192 @@ -126,7 +126,7 @@ struct preempt_ops {
63193 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63194 void (*sched_out)(struct preempt_notifier *notifier,
63195 struct task_struct *next);
63196 -};
63197 +} __no_const;
63198
63199 /**
63200 * preempt_notifier - key for installing preemption notifiers
63201 diff --git a/include/linux/printk.h b/include/linux/printk.h
63202 index 1bec2f7..b66e833 100644
63203 --- a/include/linux/printk.h
63204 +++ b/include/linux/printk.h
63205 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63206 extern int printk_needs_cpu(int cpu);
63207 extern void printk_tick(void);
63208
63209 +extern int kptr_restrict;
63210 +
63211 #ifdef CONFIG_PRINTK
63212 asmlinkage __printf(5, 0)
63213 int vprintk_emit(int facility, int level,
63214 @@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63215
63216 extern int printk_delay_msec;
63217 extern int dmesg_restrict;
63218 -extern int kptr_restrict;
63219
63220 void log_buf_kexec_setup(void);
63221 void __init setup_log_buf(int early);
63222 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63223 index 3fd2e87..d93a721 100644
63224 --- a/include/linux/proc_fs.h
63225 +++ b/include/linux/proc_fs.h
63226 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63227 return proc_create_data(name, mode, parent, proc_fops, NULL);
63228 }
63229
63230 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63231 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63232 +{
63233 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63234 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63235 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63236 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63237 +#else
63238 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63239 +#endif
63240 +}
63241 +
63242 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63243 umode_t mode, struct proc_dir_entry *base,
63244 read_proc_t *read_proc, void * data)
63245 @@ -258,7 +270,7 @@ union proc_op {
63246 int (*proc_show)(struct seq_file *m,
63247 struct pid_namespace *ns, struct pid *pid,
63248 struct task_struct *task);
63249 -};
63250 +} __no_const;
63251
63252 struct ctl_table_header;
63253 struct ctl_table;
63254 diff --git a/include/linux/random.h b/include/linux/random.h
63255 index 8f74538..de61694 100644
63256 --- a/include/linux/random.h
63257 +++ b/include/linux/random.h
63258 @@ -54,6 +54,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63259 unsigned int value);
63260 extern void add_interrupt_randomness(int irq);
63261
63262 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63263 +extern void transfer_latent_entropy(void);
63264 +#endif
63265 +
63266 extern void get_random_bytes(void *buf, int nbytes);
63267 void generate_random_uuid(unsigned char uuid_out[16]);
63268
63269 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63270
63271 u32 prandom32(struct rnd_state *);
63272
63273 +static inline unsigned long pax_get_random_long(void)
63274 +{
63275 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63276 +}
63277 +
63278 /*
63279 * Handle minimum values for seeds
63280 */
63281 static inline u32 __seed(u32 x, u32 m)
63282 {
63283 - return (x < m) ? x + m : x;
63284 + return (x <= m) ? x + m + 1 : x;
63285 }
63286
63287 /**
63288 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63289 index e0879a7..a12f962 100644
63290 --- a/include/linux/reboot.h
63291 +++ b/include/linux/reboot.h
63292 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63293 * Architecture-specific implementations of sys_reboot commands.
63294 */
63295
63296 -extern void machine_restart(char *cmd);
63297 -extern void machine_halt(void);
63298 -extern void machine_power_off(void);
63299 +extern void machine_restart(char *cmd) __noreturn;
63300 +extern void machine_halt(void) __noreturn;
63301 +extern void machine_power_off(void) __noreturn;
63302
63303 extern void machine_shutdown(void);
63304 struct pt_regs;
63305 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63306 */
63307
63308 extern void kernel_restart_prepare(char *cmd);
63309 -extern void kernel_restart(char *cmd);
63310 -extern void kernel_halt(void);
63311 -extern void kernel_power_off(void);
63312 +extern void kernel_restart(char *cmd) __noreturn;
63313 +extern void kernel_halt(void) __noreturn;
63314 +extern void kernel_power_off(void) __noreturn;
63315
63316 extern int C_A_D; /* for sysctl */
63317 void ctrl_alt_del(void);
63318 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63319 * Emergency restart, callable from an interrupt handler.
63320 */
63321
63322 -extern void emergency_restart(void);
63323 +extern void emergency_restart(void) __noreturn;
63324 #include <asm/emergency-restart.h>
63325
63326 #endif
63327 diff --git a/include/linux/relay.h b/include/linux/relay.h
63328 index 91cacc3..b55ff74 100644
63329 --- a/include/linux/relay.h
63330 +++ b/include/linux/relay.h
63331 @@ -160,7 +160,7 @@ struct rchan_callbacks
63332 * The callback should return 0 if successful, negative if not.
63333 */
63334 int (*remove_buf_file)(struct dentry *dentry);
63335 -};
63336 +} __no_const;
63337
63338 /*
63339 * CONFIG_RELAY kernel API, kernel/relay.c
63340 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63341 index 6fdf027..ff72610 100644
63342 --- a/include/linux/rfkill.h
63343 +++ b/include/linux/rfkill.h
63344 @@ -147,6 +147,7 @@ struct rfkill_ops {
63345 void (*query)(struct rfkill *rfkill, void *data);
63346 int (*set_block)(void *data, bool blocked);
63347 };
63348 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63349
63350 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63351 /**
63352 diff --git a/include/linux/rio.h b/include/linux/rio.h
63353 index a90ebad..fd87b5d 100644
63354 --- a/include/linux/rio.h
63355 +++ b/include/linux/rio.h
63356 @@ -321,7 +321,7 @@ struct rio_ops {
63357 int mbox, void *buffer, size_t len);
63358 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63359 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63360 -};
63361 +} __no_const;
63362
63363 #define RIO_RESOURCE_MEM 0x00000100
63364 #define RIO_RESOURCE_DOORBELL 0x00000200
63365 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63366 index 3fce545..b4fed6e 100644
63367 --- a/include/linux/rmap.h
63368 +++ b/include/linux/rmap.h
63369 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63370 void anon_vma_init(void); /* create anon_vma_cachep */
63371 int anon_vma_prepare(struct vm_area_struct *);
63372 void unlink_anon_vmas(struct vm_area_struct *);
63373 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63374 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63375 void anon_vma_moveto_tail(struct vm_area_struct *);
63376 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63377 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63378
63379 static inline void anon_vma_merge(struct vm_area_struct *vma,
63380 struct vm_area_struct *next)
63381 diff --git a/include/linux/sched.h b/include/linux/sched.h
63382 index 4a1f493..5812aeb 100644
63383 --- a/include/linux/sched.h
63384 +++ b/include/linux/sched.h
63385 @@ -101,6 +101,7 @@ struct bio_list;
63386 struct fs_struct;
63387 struct perf_event_context;
63388 struct blk_plug;
63389 +struct linux_binprm;
63390
63391 /*
63392 * List of flags we want to share for kernel threads,
63393 @@ -384,10 +385,13 @@ struct user_namespace;
63394 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63395
63396 extern int sysctl_max_map_count;
63397 +extern unsigned long sysctl_heap_stack_gap;
63398
63399 #include <linux/aio.h>
63400
63401 #ifdef CONFIG_MMU
63402 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63403 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63404 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63405 extern unsigned long
63406 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63407 @@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63408 extern void set_dumpable(struct mm_struct *mm, int value);
63409 extern int get_dumpable(struct mm_struct *mm);
63410
63411 +/* get/set_dumpable() values */
63412 +#define SUID_DUMPABLE_DISABLED 0
63413 +#define SUID_DUMPABLE_ENABLED 1
63414 +#define SUID_DUMPABLE_SAFE 2
63415 +
63416 /* mm flags */
63417 /* dumpable bits */
63418 #define MMF_DUMPABLE 0 /* core dump is permitted */
63419 @@ -646,6 +655,17 @@ struct signal_struct {
63420 #ifdef CONFIG_TASKSTATS
63421 struct taskstats *stats;
63422 #endif
63423 +
63424 +#ifdef CONFIG_GRKERNSEC
63425 + u32 curr_ip;
63426 + u32 saved_ip;
63427 + u32 gr_saddr;
63428 + u32 gr_daddr;
63429 + u16 gr_sport;
63430 + u16 gr_dport;
63431 + u8 used_accept:1;
63432 +#endif
63433 +
63434 #ifdef CONFIG_AUDIT
63435 unsigned audit_tty;
63436 struct tty_audit_buf *tty_audit_buf;
63437 @@ -729,6 +749,11 @@ struct user_struct {
63438 struct key *session_keyring; /* UID's default session keyring */
63439 #endif
63440
63441 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63442 + unsigned int banned;
63443 + unsigned long ban_expires;
63444 +#endif
63445 +
63446 /* Hash table maintenance information */
63447 struct hlist_node uidhash_node;
63448 kuid_t uid;
63449 @@ -1348,8 +1373,8 @@ struct task_struct {
63450 struct list_head thread_group;
63451
63452 struct completion *vfork_done; /* for vfork() */
63453 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63454 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63455 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63456 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63457
63458 cputime_t utime, stime, utimescaled, stimescaled;
63459 cputime_t gtime;
63460 @@ -1365,11 +1390,6 @@ struct task_struct {
63461 struct task_cputime cputime_expires;
63462 struct list_head cpu_timers[3];
63463
63464 -/* process credentials */
63465 - const struct cred __rcu *real_cred; /* objective and real subjective task
63466 - * credentials (COW) */
63467 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63468 - * credentials (COW) */
63469 char comm[TASK_COMM_LEN]; /* executable name excluding path
63470 - access with [gs]et_task_comm (which lock
63471 it with task_lock())
63472 @@ -1386,8 +1406,16 @@ struct task_struct {
63473 #endif
63474 /* CPU-specific state of this task */
63475 struct thread_struct thread;
63476 +/* thread_info moved to task_struct */
63477 +#ifdef CONFIG_X86
63478 + struct thread_info tinfo;
63479 +#endif
63480 /* filesystem information */
63481 struct fs_struct *fs;
63482 +
63483 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63484 + * credentials (COW) */
63485 +
63486 /* open file information */
63487 struct files_struct *files;
63488 /* namespaces */
63489 @@ -1431,6 +1459,11 @@ struct task_struct {
63490 struct rt_mutex_waiter *pi_blocked_on;
63491 #endif
63492
63493 +/* process credentials */
63494 + const struct cred __rcu *real_cred; /* objective and real subjective task
63495 + * credentials (COW) */
63496 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63497 +
63498 #ifdef CONFIG_DEBUG_MUTEXES
63499 /* mutex deadlock detection */
63500 struct mutex_waiter *blocked_on;
63501 @@ -1547,6 +1580,27 @@ struct task_struct {
63502 unsigned long default_timer_slack_ns;
63503
63504 struct list_head *scm_work_list;
63505 +
63506 +#ifdef CONFIG_GRKERNSEC
63507 + /* grsecurity */
63508 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63509 + u64 exec_id;
63510 +#endif
63511 +#ifdef CONFIG_GRKERNSEC_SETXID
63512 + const struct cred *delayed_cred;
63513 +#endif
63514 + struct dentry *gr_chroot_dentry;
63515 + struct acl_subject_label *acl;
63516 + struct acl_role_label *role;
63517 + struct file *exec_file;
63518 + u16 acl_role_id;
63519 + /* is this the task that authenticated to the special role */
63520 + u8 acl_sp_role;
63521 + u8 is_writable;
63522 + u8 brute;
63523 + u8 gr_is_chrooted;
63524 +#endif
63525 +
63526 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63527 /* Index of current stored address in ret_stack */
63528 int curr_ret_stack;
63529 @@ -1585,6 +1639,51 @@ struct task_struct {
63530 #endif
63531 };
63532
63533 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63534 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63535 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63536 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63537 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63538 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63539 +
63540 +#ifdef CONFIG_PAX_SOFTMODE
63541 +extern int pax_softmode;
63542 +#endif
63543 +
63544 +extern int pax_check_flags(unsigned long *);
63545 +
63546 +/* if tsk != current then task_lock must be held on it */
63547 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63548 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63549 +{
63550 + if (likely(tsk->mm))
63551 + return tsk->mm->pax_flags;
63552 + else
63553 + return 0UL;
63554 +}
63555 +
63556 +/* if tsk != current then task_lock must be held on it */
63557 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63558 +{
63559 + if (likely(tsk->mm)) {
63560 + tsk->mm->pax_flags = flags;
63561 + return 0;
63562 + }
63563 + return -EINVAL;
63564 +}
63565 +#endif
63566 +
63567 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63568 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63569 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63570 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63571 +#endif
63572 +
63573 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63574 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63575 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63576 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
63577 +
63578 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63579 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63580
63581 @@ -2112,7 +2211,9 @@ void yield(void);
63582 extern struct exec_domain default_exec_domain;
63583
63584 union thread_union {
63585 +#ifndef CONFIG_X86
63586 struct thread_info thread_info;
63587 +#endif
63588 unsigned long stack[THREAD_SIZE/sizeof(long)];
63589 };
63590
63591 @@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63592 */
63593
63594 extern struct task_struct *find_task_by_vpid(pid_t nr);
63595 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63596 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63597 struct pid_namespace *ns);
63598
63599 @@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63600 extern void exit_itimers(struct signal_struct *);
63601 extern void flush_itimer_signals(void);
63602
63603 -extern void do_group_exit(int);
63604 +extern __noreturn void do_group_exit(int);
63605
63606 extern void daemonize(const char *, ...);
63607 extern int allow_signal(int);
63608 @@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63609
63610 #endif
63611
63612 -static inline int object_is_on_stack(void *obj)
63613 +static inline int object_starts_on_stack(void *obj)
63614 {
63615 - void *stack = task_stack_page(current);
63616 + const void *stack = task_stack_page(current);
63617
63618 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63619 }
63620 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63621 index 899fbb4..1cb4138 100644
63622 --- a/include/linux/screen_info.h
63623 +++ b/include/linux/screen_info.h
63624 @@ -43,7 +43,8 @@ struct screen_info {
63625 __u16 pages; /* 0x32 */
63626 __u16 vesa_attributes; /* 0x34 */
63627 __u32 capabilities; /* 0x36 */
63628 - __u8 _reserved[6]; /* 0x3a */
63629 + __u16 vesapm_size; /* 0x3a */
63630 + __u8 _reserved[4]; /* 0x3c */
63631 } __attribute__((packed));
63632
63633 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63634 diff --git a/include/linux/security.h b/include/linux/security.h
63635 index 4e5a73c..a5784a1 100644
63636 --- a/include/linux/security.h
63637 +++ b/include/linux/security.h
63638 @@ -26,6 +26,7 @@
63639 #include <linux/capability.h>
63640 #include <linux/slab.h>
63641 #include <linux/err.h>
63642 +#include <linux/grsecurity.h>
63643
63644 struct linux_binprm;
63645 struct cred;
63646 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63647 index fc61854..d7c490b 100644
63648 --- a/include/linux/seq_file.h
63649 +++ b/include/linux/seq_file.h
63650 @@ -25,6 +25,9 @@ struct seq_file {
63651 struct mutex lock;
63652 const struct seq_operations *op;
63653 int poll_event;
63654 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63655 + u64 exec_id;
63656 +#endif
63657 void *private;
63658 };
63659
63660 @@ -34,6 +37,7 @@ struct seq_operations {
63661 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63662 int (*show) (struct seq_file *m, void *v);
63663 };
63664 +typedef struct seq_operations __no_const seq_operations_no_const;
63665
63666 #define SEQ_SKIP 1
63667
63668 diff --git a/include/linux/shm.h b/include/linux/shm.h
63669 index 92808b8..c28cac4 100644
63670 --- a/include/linux/shm.h
63671 +++ b/include/linux/shm.h
63672 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63673
63674 /* The task created the shm object. NULL if the task is dead. */
63675 struct task_struct *shm_creator;
63676 +#ifdef CONFIG_GRKERNSEC
63677 + time_t shm_createtime;
63678 + pid_t shm_lapid;
63679 +#endif
63680 };
63681
63682 /* shm_mode upper byte flags */
63683 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63684 index 642cb73..7ff7f9f 100644
63685 --- a/include/linux/skbuff.h
63686 +++ b/include/linux/skbuff.h
63687 @@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63688 */
63689 static inline int skb_queue_empty(const struct sk_buff_head *list)
63690 {
63691 - return list->next == (struct sk_buff *)list;
63692 + return list->next == (const struct sk_buff *)list;
63693 }
63694
63695 /**
63696 @@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63697 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63698 const struct sk_buff *skb)
63699 {
63700 - return skb->next == (struct sk_buff *)list;
63701 + return skb->next == (const struct sk_buff *)list;
63702 }
63703
63704 /**
63705 @@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63706 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63707 const struct sk_buff *skb)
63708 {
63709 - return skb->prev == (struct sk_buff *)list;
63710 + return skb->prev == (const struct sk_buff *)list;
63711 }
63712
63713 /**
63714 @@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63715 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63716 */
63717 #ifndef NET_SKB_PAD
63718 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63719 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63720 #endif
63721
63722 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63723 diff --git a/include/linux/slab.h b/include/linux/slab.h
63724 index 67d5d94..371d9a7 100644
63725 --- a/include/linux/slab.h
63726 +++ b/include/linux/slab.h
63727 @@ -11,12 +11,20 @@
63728
63729 #include <linux/gfp.h>
63730 #include <linux/types.h>
63731 +#include <linux/err.h>
63732
63733 /*
63734 * Flags to pass to kmem_cache_create().
63735 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63736 */
63737 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63738 +
63739 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63740 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63741 +#else
63742 +#define SLAB_USERCOPY 0x00000000UL
63743 +#endif
63744 +
63745 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63746 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63747 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63748 @@ -87,10 +95,13 @@
63749 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63750 * Both make kfree a no-op.
63751 */
63752 -#define ZERO_SIZE_PTR ((void *)16)
63753 +#define ZERO_SIZE_PTR \
63754 +({ \
63755 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63756 + (void *)(-MAX_ERRNO-1L); \
63757 +})
63758
63759 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63760 - (unsigned long)ZERO_SIZE_PTR)
63761 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63762
63763 /*
63764 * struct kmem_cache related prototypes
63765 @@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63766 void kfree(const void *);
63767 void kzfree(const void *);
63768 size_t ksize(const void *);
63769 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63770 +bool is_usercopy_object(const void *ptr);
63771
63772 /*
63773 * Allocator specific definitions. These are mainly used to establish optimized
63774 @@ -240,6 +253,7 @@ size_t ksize(const void *);
63775 * for general use, and so are not documented here. For a full list of
63776 * potential flags, always refer to linux/gfp.h.
63777 */
63778 +static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
63779 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
63780 {
63781 if (size != 0 && n > SIZE_MAX / size)
63782 @@ -298,7 +312,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63783 */
63784 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63785 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63786 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63787 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63788 #define kmalloc_track_caller(size, flags) \
63789 __kmalloc_track_caller(size, flags, _RET_IP_)
63790 #else
63791 @@ -317,7 +331,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63792 */
63793 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63794 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63795 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63796 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63797 #define kmalloc_node_track_caller(size, flags, node) \
63798 __kmalloc_node_track_caller(size, flags, node, \
63799 _RET_IP_)
63800 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63801 index fbd1117..0a3d314 100644
63802 --- a/include/linux/slab_def.h
63803 +++ b/include/linux/slab_def.h
63804 @@ -66,10 +66,10 @@ struct kmem_cache {
63805 unsigned long node_allocs;
63806 unsigned long node_frees;
63807 unsigned long node_overflow;
63808 - atomic_t allochit;
63809 - atomic_t allocmiss;
63810 - atomic_t freehit;
63811 - atomic_t freemiss;
63812 + atomic_unchecked_t allochit;
63813 + atomic_unchecked_t allocmiss;
63814 + atomic_unchecked_t freehit;
63815 + atomic_unchecked_t freemiss;
63816
63817 /*
63818 * If debugging is enabled, then the allocator can add additional
63819 @@ -103,11 +103,16 @@ struct cache_sizes {
63820 #ifdef CONFIG_ZONE_DMA
63821 struct kmem_cache *cs_dmacachep;
63822 #endif
63823 +
63824 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63825 + struct kmem_cache *cs_usercopycachep;
63826 +#endif
63827 +
63828 };
63829 extern struct cache_sizes malloc_sizes[];
63830
63831 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63832 -void *__kmalloc(size_t size, gfp_t flags);
63833 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63834
63835 #ifdef CONFIG_TRACING
63836 extern void *kmem_cache_alloc_trace(size_t size,
63837 @@ -150,6 +155,13 @@ found:
63838 cachep = malloc_sizes[i].cs_dmacachep;
63839 else
63840 #endif
63841 +
63842 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63843 + if (flags & GFP_USERCOPY)
63844 + cachep = malloc_sizes[i].cs_usercopycachep;
63845 + else
63846 +#endif
63847 +
63848 cachep = malloc_sizes[i].cs_cachep;
63849
63850 ret = kmem_cache_alloc_trace(size, cachep, flags);
63851 @@ -160,7 +172,7 @@ found:
63852 }
63853
63854 #ifdef CONFIG_NUMA
63855 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63856 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63857 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63858
63859 #ifdef CONFIG_TRACING
63860 @@ -203,6 +215,13 @@ found:
63861 cachep = malloc_sizes[i].cs_dmacachep;
63862 else
63863 #endif
63864 +
63865 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63866 + if (flags & GFP_USERCOPY)
63867 + cachep = malloc_sizes[i].cs_usercopycachep;
63868 + else
63869 +#endif
63870 +
63871 cachep = malloc_sizes[i].cs_cachep;
63872
63873 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
63874 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63875 index 0ec00b3..39cb7fc 100644
63876 --- a/include/linux/slob_def.h
63877 +++ b/include/linux/slob_def.h
63878 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63879 return kmem_cache_alloc_node(cachep, flags, -1);
63880 }
63881
63882 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63883 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63884
63885 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63886 {
63887 @@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63888 return __kmalloc_node(size, flags, -1);
63889 }
63890
63891 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63892 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63893 {
63894 return kmalloc(size, flags);
63895 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63896 index c2f8c8b..be9e036 100644
63897 --- a/include/linux/slub_def.h
63898 +++ b/include/linux/slub_def.h
63899 @@ -92,7 +92,7 @@ struct kmem_cache {
63900 struct kmem_cache_order_objects max;
63901 struct kmem_cache_order_objects min;
63902 gfp_t allocflags; /* gfp flags to use on each alloc */
63903 - int refcount; /* Refcount for slab cache destroy */
63904 + atomic_t refcount; /* Refcount for slab cache destroy */
63905 void (*ctor)(void *);
63906 int inuse; /* Offset to metadata */
63907 int align; /* Alignment */
63908 @@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63909 * Sorry that the following has to be that ugly but some versions of GCC
63910 * have trouble with constant propagation and loops.
63911 */
63912 +static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63913 static __always_inline int kmalloc_index(size_t size)
63914 {
63915 if (!size)
63916 @@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63917 }
63918
63919 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63920 -void *__kmalloc(size_t size, gfp_t flags);
63921 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63922
63923 static __always_inline void *
63924 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63925 @@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63926 }
63927 #endif
63928
63929 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63930 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63931 {
63932 unsigned int order = get_order(size);
63933 @@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63934 }
63935
63936 #ifdef CONFIG_NUMA
63937 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63938 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63939 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63940
63941 #ifdef CONFIG_TRACING
63942 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63943 index de8832d..0147b46 100644
63944 --- a/include/linux/sonet.h
63945 +++ b/include/linux/sonet.h
63946 @@ -61,7 +61,7 @@ struct sonet_stats {
63947 #include <linux/atomic.h>
63948
63949 struct k_sonet_stats {
63950 -#define __HANDLE_ITEM(i) atomic_t i
63951 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63952 __SONET_ITEMS
63953 #undef __HANDLE_ITEM
63954 };
63955 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63956 index 523547e..2cb7140 100644
63957 --- a/include/linux/sunrpc/clnt.h
63958 +++ b/include/linux/sunrpc/clnt.h
63959 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63960 {
63961 switch (sap->sa_family) {
63962 case AF_INET:
63963 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63964 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63965 case AF_INET6:
63966 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63967 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63968 }
63969 return 0;
63970 }
63971 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63972 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63973 const struct sockaddr *src)
63974 {
63975 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63976 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63977 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63978
63979 dsin->sin_family = ssin->sin_family;
63980 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63981 if (sa->sa_family != AF_INET6)
63982 return 0;
63983
63984 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63985 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63986 }
63987
63988 #endif /* __KERNEL__ */
63989 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63990 index dc0c3cc..8503fb6 100644
63991 --- a/include/linux/sunrpc/sched.h
63992 +++ b/include/linux/sunrpc/sched.h
63993 @@ -106,6 +106,7 @@ struct rpc_call_ops {
63994 void (*rpc_count_stats)(struct rpc_task *, void *);
63995 void (*rpc_release)(void *);
63996 };
63997 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63998
63999 struct rpc_task_setup {
64000 struct rpc_task *task;
64001 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64002 index 0b8e3e6..33e0a01 100644
64003 --- a/include/linux/sunrpc/svc_rdma.h
64004 +++ b/include/linux/sunrpc/svc_rdma.h
64005 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64006 extern unsigned int svcrdma_max_requests;
64007 extern unsigned int svcrdma_max_req_size;
64008
64009 -extern atomic_t rdma_stat_recv;
64010 -extern atomic_t rdma_stat_read;
64011 -extern atomic_t rdma_stat_write;
64012 -extern atomic_t rdma_stat_sq_starve;
64013 -extern atomic_t rdma_stat_rq_starve;
64014 -extern atomic_t rdma_stat_rq_poll;
64015 -extern atomic_t rdma_stat_rq_prod;
64016 -extern atomic_t rdma_stat_sq_poll;
64017 -extern atomic_t rdma_stat_sq_prod;
64018 +extern atomic_unchecked_t rdma_stat_recv;
64019 +extern atomic_unchecked_t rdma_stat_read;
64020 +extern atomic_unchecked_t rdma_stat_write;
64021 +extern atomic_unchecked_t rdma_stat_sq_starve;
64022 +extern atomic_unchecked_t rdma_stat_rq_starve;
64023 +extern atomic_unchecked_t rdma_stat_rq_poll;
64024 +extern atomic_unchecked_t rdma_stat_rq_prod;
64025 +extern atomic_unchecked_t rdma_stat_sq_poll;
64026 +extern atomic_unchecked_t rdma_stat_sq_prod;
64027
64028 #define RPCRDMA_VERSION 1
64029
64030 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64031 index c34b4c8..a65b67d 100644
64032 --- a/include/linux/sysctl.h
64033 +++ b/include/linux/sysctl.h
64034 @@ -155,7 +155,11 @@ enum
64035 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64036 };
64037
64038 -
64039 +#ifdef CONFIG_PAX_SOFTMODE
64040 +enum {
64041 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64042 +};
64043 +#endif
64044
64045 /* CTL_VM names: */
64046 enum
64047 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64048
64049 extern int proc_dostring(struct ctl_table *, int,
64050 void __user *, size_t *, loff_t *);
64051 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64052 + void __user *, size_t *, loff_t *);
64053 extern int proc_dointvec(struct ctl_table *, int,
64054 void __user *, size_t *, loff_t *);
64055 extern int proc_dointvec_minmax(struct ctl_table *, int,
64056 diff --git a/include/linux/tty.h b/include/linux/tty.h
64057 index 9f47ab5..73da944 100644
64058 --- a/include/linux/tty.h
64059 +++ b/include/linux/tty.h
64060 @@ -225,7 +225,7 @@ struct tty_port {
64061 const struct tty_port_operations *ops; /* Port operations */
64062 spinlock_t lock; /* Lock protecting tty field */
64063 int blocked_open; /* Waiting to open */
64064 - int count; /* Usage count */
64065 + atomic_t count; /* Usage count */
64066 wait_queue_head_t open_wait; /* Open waiters */
64067 wait_queue_head_t close_wait; /* Close waiters */
64068 wait_queue_head_t delta_msr_wait; /* Modem status change */
64069 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64070 struct tty_struct *tty, struct file *filp);
64071 static inline int tty_port_users(struct tty_port *port)
64072 {
64073 - return port->count + port->blocked_open;
64074 + return atomic_read(&port->count) + port->blocked_open;
64075 }
64076
64077 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64078 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64079 index fb79dd8d..07d4773 100644
64080 --- a/include/linux/tty_ldisc.h
64081 +++ b/include/linux/tty_ldisc.h
64082 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64083
64084 struct module *owner;
64085
64086 - int refcount;
64087 + atomic_t refcount;
64088 };
64089
64090 struct tty_ldisc {
64091 diff --git a/include/linux/types.h b/include/linux/types.h
64092 index 9c1bd53..c2370f6 100644
64093 --- a/include/linux/types.h
64094 +++ b/include/linux/types.h
64095 @@ -220,10 +220,26 @@ typedef struct {
64096 int counter;
64097 } atomic_t;
64098
64099 +#ifdef CONFIG_PAX_REFCOUNT
64100 +typedef struct {
64101 + int counter;
64102 +} atomic_unchecked_t;
64103 +#else
64104 +typedef atomic_t atomic_unchecked_t;
64105 +#endif
64106 +
64107 #ifdef CONFIG_64BIT
64108 typedef struct {
64109 long counter;
64110 } atomic64_t;
64111 +
64112 +#ifdef CONFIG_PAX_REFCOUNT
64113 +typedef struct {
64114 + long counter;
64115 +} atomic64_unchecked_t;
64116 +#else
64117 +typedef atomic64_t atomic64_unchecked_t;
64118 +#endif
64119 #endif
64120
64121 struct list_head {
64122 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64123 index 5ca0951..ab496a5 100644
64124 --- a/include/linux/uaccess.h
64125 +++ b/include/linux/uaccess.h
64126 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64127 long ret; \
64128 mm_segment_t old_fs = get_fs(); \
64129 \
64130 - set_fs(KERNEL_DS); \
64131 pagefault_disable(); \
64132 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64133 - pagefault_enable(); \
64134 + set_fs(KERNEL_DS); \
64135 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64136 set_fs(old_fs); \
64137 + pagefault_enable(); \
64138 ret; \
64139 })
64140
64141 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64142 index 99c1b4d..bb94261 100644
64143 --- a/include/linux/unaligned/access_ok.h
64144 +++ b/include/linux/unaligned/access_ok.h
64145 @@ -6,32 +6,32 @@
64146
64147 static inline u16 get_unaligned_le16(const void *p)
64148 {
64149 - return le16_to_cpup((__le16 *)p);
64150 + return le16_to_cpup((const __le16 *)p);
64151 }
64152
64153 static inline u32 get_unaligned_le32(const void *p)
64154 {
64155 - return le32_to_cpup((__le32 *)p);
64156 + return le32_to_cpup((const __le32 *)p);
64157 }
64158
64159 static inline u64 get_unaligned_le64(const void *p)
64160 {
64161 - return le64_to_cpup((__le64 *)p);
64162 + return le64_to_cpup((const __le64 *)p);
64163 }
64164
64165 static inline u16 get_unaligned_be16(const void *p)
64166 {
64167 - return be16_to_cpup((__be16 *)p);
64168 + return be16_to_cpup((const __be16 *)p);
64169 }
64170
64171 static inline u32 get_unaligned_be32(const void *p)
64172 {
64173 - return be32_to_cpup((__be32 *)p);
64174 + return be32_to_cpup((const __be32 *)p);
64175 }
64176
64177 static inline u64 get_unaligned_be64(const void *p)
64178 {
64179 - return be64_to_cpup((__be64 *)p);
64180 + return be64_to_cpup((const __be64 *)p);
64181 }
64182
64183 static inline void put_unaligned_le16(u16 val, void *p)
64184 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64185 index 547e59c..db6ad19 100644
64186 --- a/include/linux/usb/renesas_usbhs.h
64187 +++ b/include/linux/usb/renesas_usbhs.h
64188 @@ -39,7 +39,7 @@ enum {
64189 */
64190 struct renesas_usbhs_driver_callback {
64191 int (*notify_hotplug)(struct platform_device *pdev);
64192 -};
64193 +} __no_const;
64194
64195 /*
64196 * callback functions for platform
64197 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64198 * VBUS control is needed for Host
64199 */
64200 int (*set_vbus)(struct platform_device *pdev, int enable);
64201 -};
64202 +} __no_const;
64203
64204 /*
64205 * parameters for renesas usbhs
64206 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64207 index 6f8fbcf..8259001 100644
64208 --- a/include/linux/vermagic.h
64209 +++ b/include/linux/vermagic.h
64210 @@ -25,9 +25,35 @@
64211 #define MODULE_ARCH_VERMAGIC ""
64212 #endif
64213
64214 +#ifdef CONFIG_PAX_REFCOUNT
64215 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64216 +#else
64217 +#define MODULE_PAX_REFCOUNT ""
64218 +#endif
64219 +
64220 +#ifdef CONSTIFY_PLUGIN
64221 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64222 +#else
64223 +#define MODULE_CONSTIFY_PLUGIN ""
64224 +#endif
64225 +
64226 +#ifdef STACKLEAK_PLUGIN
64227 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64228 +#else
64229 +#define MODULE_STACKLEAK_PLUGIN ""
64230 +#endif
64231 +
64232 +#ifdef CONFIG_GRKERNSEC
64233 +#define MODULE_GRSEC "GRSEC "
64234 +#else
64235 +#define MODULE_GRSEC ""
64236 +#endif
64237 +
64238 #define VERMAGIC_STRING \
64239 UTS_RELEASE " " \
64240 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64241 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64242 - MODULE_ARCH_VERMAGIC
64243 + MODULE_ARCH_VERMAGIC \
64244 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64245 + MODULE_GRSEC
64246
64247 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64248 index dcdfc2b..ec79ab5 100644
64249 --- a/include/linux/vmalloc.h
64250 +++ b/include/linux/vmalloc.h
64251 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64252 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64253 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64254 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64255 +
64256 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64257 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64258 +#endif
64259 +
64260 /* bits [20..32] reserved for arch specific ioremap internals */
64261
64262 /*
64263 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64264 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64265 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64266 unsigned long start, unsigned long end, gfp_t gfp_mask,
64267 - pgprot_t prot, int node, void *caller);
64268 + pgprot_t prot, int node, void *caller) __size_overflow(1);
64269 extern void vfree(const void *addr);
64270
64271 extern void *vmap(struct page **pages, unsigned int count,
64272 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64273 extern void free_vm_area(struct vm_struct *area);
64274
64275 /* for /dev/kmem */
64276 -extern long vread(char *buf, char *addr, unsigned long count);
64277 -extern long vwrite(char *buf, char *addr, unsigned long count);
64278 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64279 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64280
64281 /*
64282 * Internals. Dont't use..
64283 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64284 index 65efb92..137adbb 100644
64285 --- a/include/linux/vmstat.h
64286 +++ b/include/linux/vmstat.h
64287 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64288 /*
64289 * Zone based page accounting with per cpu differentials.
64290 */
64291 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64292 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64293
64294 static inline void zone_page_state_add(long x, struct zone *zone,
64295 enum zone_stat_item item)
64296 {
64297 - atomic_long_add(x, &zone->vm_stat[item]);
64298 - atomic_long_add(x, &vm_stat[item]);
64299 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64300 + atomic_long_add_unchecked(x, &vm_stat[item]);
64301 }
64302
64303 static inline unsigned long global_page_state(enum zone_stat_item item)
64304 {
64305 - long x = atomic_long_read(&vm_stat[item]);
64306 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64307 #ifdef CONFIG_SMP
64308 if (x < 0)
64309 x = 0;
64310 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64311 static inline unsigned long zone_page_state(struct zone *zone,
64312 enum zone_stat_item item)
64313 {
64314 - long x = atomic_long_read(&zone->vm_stat[item]);
64315 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64316 #ifdef CONFIG_SMP
64317 if (x < 0)
64318 x = 0;
64319 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64320 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64321 enum zone_stat_item item)
64322 {
64323 - long x = atomic_long_read(&zone->vm_stat[item]);
64324 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64325
64326 #ifdef CONFIG_SMP
64327 int cpu;
64328 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64329
64330 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64331 {
64332 - atomic_long_inc(&zone->vm_stat[item]);
64333 - atomic_long_inc(&vm_stat[item]);
64334 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64335 + atomic_long_inc_unchecked(&vm_stat[item]);
64336 }
64337
64338 static inline void __inc_zone_page_state(struct page *page,
64339 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64340
64341 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64342 {
64343 - atomic_long_dec(&zone->vm_stat[item]);
64344 - atomic_long_dec(&vm_stat[item]);
64345 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64346 + atomic_long_dec_unchecked(&vm_stat[item]);
64347 }
64348
64349 static inline void __dec_zone_page_state(struct page *page,
64350 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64351 index e5d1220..ef6e406 100644
64352 --- a/include/linux/xattr.h
64353 +++ b/include/linux/xattr.h
64354 @@ -57,6 +57,11 @@
64355 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64356 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64357
64358 +/* User namespace */
64359 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64360 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64361 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64362 +
64363 #ifdef __KERNEL__
64364
64365 #include <linux/types.h>
64366 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64367 index 944ecdf..a3994fc 100644
64368 --- a/include/media/saa7146_vv.h
64369 +++ b/include/media/saa7146_vv.h
64370 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64371 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64372
64373 /* the extension can override this */
64374 - struct v4l2_ioctl_ops vid_ops;
64375 - struct v4l2_ioctl_ops vbi_ops;
64376 + v4l2_ioctl_ops_no_const vid_ops;
64377 + v4l2_ioctl_ops_no_const vbi_ops;
64378 /* pointer to the saa7146 core ops */
64379 const struct v4l2_ioctl_ops *core_ops;
64380
64381 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64382 index a056e6e..31023a5 100644
64383 --- a/include/media/v4l2-dev.h
64384 +++ b/include/media/v4l2-dev.h
64385 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64386 int (*mmap) (struct file *, struct vm_area_struct *);
64387 int (*open) (struct file *);
64388 int (*release) (struct file *);
64389 -};
64390 +} __do_const;
64391 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64392
64393 /*
64394 * Newer version of video_device, handled by videodev2.c
64395 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64396 index d8b76f7..7d5aa18 100644
64397 --- a/include/media/v4l2-ioctl.h
64398 +++ b/include/media/v4l2-ioctl.h
64399 @@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64400 long (*vidioc_default) (struct file *file, void *fh,
64401 bool valid_prio, int cmd, void *arg);
64402 };
64403 -
64404 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64405
64406 /* v4l debugging and diagnostics */
64407
64408 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64409 index 439dadc..1c67e3f 100644
64410 --- a/include/net/caif/caif_hsi.h
64411 +++ b/include/net/caif/caif_hsi.h
64412 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64413 void (*rx_done_cb) (struct cfhsi_drv *drv);
64414 void (*wake_up_cb) (struct cfhsi_drv *drv);
64415 void (*wake_down_cb) (struct cfhsi_drv *drv);
64416 -};
64417 +} __no_const;
64418
64419 /* Structure implemented by HSI device. */
64420 struct cfhsi_dev {
64421 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64422 index 9e5425b..8136ffc 100644
64423 --- a/include/net/caif/cfctrl.h
64424 +++ b/include/net/caif/cfctrl.h
64425 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64426 void (*radioset_rsp)(void);
64427 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64428 struct cflayer *client_layer);
64429 -};
64430 +} __no_const;
64431
64432 /* Link Setup Parameters for CAIF-Links. */
64433 struct cfctrl_link_param {
64434 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64435 struct cfctrl {
64436 struct cfsrvl serv;
64437 struct cfctrl_rsp res;
64438 - atomic_t req_seq_no;
64439 - atomic_t rsp_seq_no;
64440 + atomic_unchecked_t req_seq_no;
64441 + atomic_unchecked_t rsp_seq_no;
64442 struct list_head list;
64443 /* Protects from simultaneous access to first_req list */
64444 spinlock_t info_list_lock;
64445 diff --git a/include/net/flow.h b/include/net/flow.h
64446 index 6c469db..7743b8e 100644
64447 --- a/include/net/flow.h
64448 +++ b/include/net/flow.h
64449 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64450
64451 extern void flow_cache_flush(void);
64452 extern void flow_cache_flush_deferred(void);
64453 -extern atomic_t flow_cache_genid;
64454 +extern atomic_unchecked_t flow_cache_genid;
64455
64456 #endif
64457 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64458 index 2040bff..f4c0733 100644
64459 --- a/include/net/inetpeer.h
64460 +++ b/include/net/inetpeer.h
64461 @@ -51,8 +51,8 @@ struct inet_peer {
64462 */
64463 union {
64464 struct {
64465 - atomic_t rid; /* Frag reception counter */
64466 - atomic_t ip_id_count; /* IP ID for the next packet */
64467 + atomic_unchecked_t rid; /* Frag reception counter */
64468 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64469 __u32 tcp_ts;
64470 __u32 tcp_ts_stamp;
64471 };
64472 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64473 more++;
64474 inet_peer_refcheck(p);
64475 do {
64476 - old = atomic_read(&p->ip_id_count);
64477 + old = atomic_read_unchecked(&p->ip_id_count);
64478 new = old + more;
64479 if (!new)
64480 new = 1;
64481 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64482 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64483 return new;
64484 }
64485
64486 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64487 index 78df0866..00e5c9b 100644
64488 --- a/include/net/ip_fib.h
64489 +++ b/include/net/ip_fib.h
64490 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64491
64492 #define FIB_RES_SADDR(net, res) \
64493 ((FIB_RES_NH(res).nh_saddr_genid == \
64494 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64495 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64496 FIB_RES_NH(res).nh_saddr : \
64497 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64498 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64499 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64500 index 95374d1..2300e36 100644
64501 --- a/include/net/ip_vs.h
64502 +++ b/include/net/ip_vs.h
64503 @@ -510,7 +510,7 @@ struct ip_vs_conn {
64504 struct ip_vs_conn *control; /* Master control connection */
64505 atomic_t n_control; /* Number of controlled ones */
64506 struct ip_vs_dest *dest; /* real server */
64507 - atomic_t in_pkts; /* incoming packet counter */
64508 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64509
64510 /* packet transmitter for different forwarding methods. If it
64511 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64512 @@ -648,7 +648,7 @@ struct ip_vs_dest {
64513 __be16 port; /* port number of the server */
64514 union nf_inet_addr addr; /* IP address of the server */
64515 volatile unsigned int flags; /* dest status flags */
64516 - atomic_t conn_flags; /* flags to copy to conn */
64517 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64518 atomic_t weight; /* server weight */
64519
64520 atomic_t refcnt; /* reference counter */
64521 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64522 index 69b610a..fe3962c 100644
64523 --- a/include/net/irda/ircomm_core.h
64524 +++ b/include/net/irda/ircomm_core.h
64525 @@ -51,7 +51,7 @@ typedef struct {
64526 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64527 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64528 struct ircomm_info *);
64529 -} call_t;
64530 +} __no_const call_t;
64531
64532 struct ircomm_cb {
64533 irda_queue_t queue;
64534 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64535 index 59ba38bc..d515662 100644
64536 --- a/include/net/irda/ircomm_tty.h
64537 +++ b/include/net/irda/ircomm_tty.h
64538 @@ -35,6 +35,7 @@
64539 #include <linux/termios.h>
64540 #include <linux/timer.h>
64541 #include <linux/tty.h> /* struct tty_struct */
64542 +#include <asm/local.h>
64543
64544 #include <net/irda/irias_object.h>
64545 #include <net/irda/ircomm_core.h>
64546 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64547 unsigned short close_delay;
64548 unsigned short closing_wait; /* time to wait before closing */
64549
64550 - int open_count;
64551 - int blocked_open; /* # of blocked opens */
64552 + local_t open_count;
64553 + local_t blocked_open; /* # of blocked opens */
64554
64555 /* Protect concurent access to :
64556 * o self->open_count
64557 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64558 index cc7c197..9f2da2a 100644
64559 --- a/include/net/iucv/af_iucv.h
64560 +++ b/include/net/iucv/af_iucv.h
64561 @@ -141,7 +141,7 @@ struct iucv_sock {
64562 struct iucv_sock_list {
64563 struct hlist_head head;
64564 rwlock_t lock;
64565 - atomic_t autobind_name;
64566 + atomic_unchecked_t autobind_name;
64567 };
64568
64569 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64570 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64571 index 6cdfeed..55a0256 100644
64572 --- a/include/net/neighbour.h
64573 +++ b/include/net/neighbour.h
64574 @@ -123,7 +123,7 @@ struct neigh_ops {
64575 void (*error_report)(struct neighbour *, struct sk_buff *);
64576 int (*output)(struct neighbour *, struct sk_buff *);
64577 int (*connected_output)(struct neighbour *, struct sk_buff *);
64578 -};
64579 +} __do_const;
64580
64581 struct pneigh_entry {
64582 struct pneigh_entry *next;
64583 diff --git a/include/net/netlink.h b/include/net/netlink.h
64584 index 785f37a..c81dc0c 100644
64585 --- a/include/net/netlink.h
64586 +++ b/include/net/netlink.h
64587 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64588 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64589 {
64590 if (mark)
64591 - skb_trim(skb, (unsigned char *) mark - skb->data);
64592 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64593 }
64594
64595 /**
64596 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64597 index bbd023a..97c6d0d 100644
64598 --- a/include/net/netns/ipv4.h
64599 +++ b/include/net/netns/ipv4.h
64600 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64601 unsigned int sysctl_ping_group_range[2];
64602 long sysctl_tcp_mem[3];
64603
64604 - atomic_t rt_genid;
64605 - atomic_t dev_addr_genid;
64606 + atomic_unchecked_t rt_genid;
64607 + atomic_unchecked_t dev_addr_genid;
64608
64609 #ifdef CONFIG_IP_MROUTE
64610 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64611 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64612 index a2ef814..31a8e3f 100644
64613 --- a/include/net/sctp/sctp.h
64614 +++ b/include/net/sctp/sctp.h
64615 @@ -318,9 +318,9 @@ do { \
64616
64617 #else /* SCTP_DEBUG */
64618
64619 -#define SCTP_DEBUG_PRINTK(whatever...)
64620 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64621 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64622 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64623 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64624 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64625 #define SCTP_ENABLE_DEBUG
64626 #define SCTP_DISABLE_DEBUG
64627 #define SCTP_ASSERT(expr, str, func)
64628 diff --git a/include/net/sock.h b/include/net/sock.h
64629 index 4a45216..7af2578 100644
64630 --- a/include/net/sock.h
64631 +++ b/include/net/sock.h
64632 @@ -303,7 +303,7 @@ struct sock {
64633 #ifdef CONFIG_RPS
64634 __u32 sk_rxhash;
64635 #endif
64636 - atomic_t sk_drops;
64637 + atomic_unchecked_t sk_drops;
64638 int sk_rcvbuf;
64639
64640 struct sk_filter __rcu *sk_filter;
64641 @@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64642 }
64643
64644 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64645 - char __user *from, char *to,
64646 + char __user *from, unsigned char *to,
64647 int copy, int offset)
64648 {
64649 if (skb->ip_summed == CHECKSUM_NONE) {
64650 diff --git a/include/net/tcp.h b/include/net/tcp.h
64651 index e79aa48..9929421 100644
64652 --- a/include/net/tcp.h
64653 +++ b/include/net/tcp.h
64654 @@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64655 char *name;
64656 sa_family_t family;
64657 const struct file_operations *seq_fops;
64658 - struct seq_operations seq_ops;
64659 + seq_operations_no_const seq_ops;
64660 };
64661
64662 struct tcp_iter_state {
64663 diff --git a/include/net/udp.h b/include/net/udp.h
64664 index 065f379..b661b40 100644
64665 --- a/include/net/udp.h
64666 +++ b/include/net/udp.h
64667 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64668 sa_family_t family;
64669 struct udp_table *udp_table;
64670 const struct file_operations *seq_fops;
64671 - struct seq_operations seq_ops;
64672 + seq_operations_no_const seq_ops;
64673 };
64674
64675 struct udp_iter_state {
64676 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64677 index e0a55df..5890bca07 100644
64678 --- a/include/net/xfrm.h
64679 +++ b/include/net/xfrm.h
64680 @@ -505,7 +505,7 @@ struct xfrm_policy {
64681 struct timer_list timer;
64682
64683 struct flow_cache_object flo;
64684 - atomic_t genid;
64685 + atomic_unchecked_t genid;
64686 u32 priority;
64687 u32 index;
64688 struct xfrm_mark mark;
64689 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64690 index 1a046b1..ee0bef0 100644
64691 --- a/include/rdma/iw_cm.h
64692 +++ b/include/rdma/iw_cm.h
64693 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64694 int backlog);
64695
64696 int (*destroy_listen)(struct iw_cm_id *cm_id);
64697 -};
64698 +} __no_const;
64699
64700 /**
64701 * iw_create_cm_id - Create an IW CM identifier.
64702 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64703 index 8f9dfba..610ab6c 100644
64704 --- a/include/scsi/libfc.h
64705 +++ b/include/scsi/libfc.h
64706 @@ -756,6 +756,7 @@ struct libfc_function_template {
64707 */
64708 void (*disc_stop_final) (struct fc_lport *);
64709 };
64710 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64711
64712 /**
64713 * struct fc_disc - Discovery context
64714 @@ -861,7 +862,7 @@ struct fc_lport {
64715 struct fc_vport *vport;
64716
64717 /* Operational Information */
64718 - struct libfc_function_template tt;
64719 + libfc_function_template_no_const tt;
64720 u8 link_up;
64721 u8 qfull;
64722 enum fc_lport_state state;
64723 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64724 index ba96988..ecf2eb9 100644
64725 --- a/include/scsi/scsi_device.h
64726 +++ b/include/scsi/scsi_device.h
64727 @@ -163,9 +163,9 @@ struct scsi_device {
64728 unsigned int max_device_blocked; /* what device_blocked counts down from */
64729 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64730
64731 - atomic_t iorequest_cnt;
64732 - atomic_t iodone_cnt;
64733 - atomic_t ioerr_cnt;
64734 + atomic_unchecked_t iorequest_cnt;
64735 + atomic_unchecked_t iodone_cnt;
64736 + atomic_unchecked_t ioerr_cnt;
64737
64738 struct device sdev_gendev,
64739 sdev_dev;
64740 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64741 index 719faf1..07b6728 100644
64742 --- a/include/scsi/scsi_transport_fc.h
64743 +++ b/include/scsi/scsi_transport_fc.h
64744 @@ -739,7 +739,8 @@ struct fc_function_template {
64745 unsigned long show_host_system_hostname:1;
64746
64747 unsigned long disable_target_scan:1;
64748 -};
64749 +} __do_const;
64750 +typedef struct fc_function_template __no_const fc_function_template_no_const;
64751
64752
64753 /**
64754 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64755 index 030b87c..98a6954 100644
64756 --- a/include/sound/ak4xxx-adda.h
64757 +++ b/include/sound/ak4xxx-adda.h
64758 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64759 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64760 unsigned char val);
64761 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64762 -};
64763 +} __no_const;
64764
64765 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64766
64767 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64768 index 8c05e47..2b5df97 100644
64769 --- a/include/sound/hwdep.h
64770 +++ b/include/sound/hwdep.h
64771 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64772 struct snd_hwdep_dsp_status *status);
64773 int (*dsp_load)(struct snd_hwdep *hw,
64774 struct snd_hwdep_dsp_image *image);
64775 -};
64776 +} __no_const;
64777
64778 struct snd_hwdep {
64779 struct snd_card *card;
64780 diff --git a/include/sound/info.h b/include/sound/info.h
64781 index 9ca1a49..aba1728 100644
64782 --- a/include/sound/info.h
64783 +++ b/include/sound/info.h
64784 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64785 struct snd_info_buffer *buffer);
64786 void (*write)(struct snd_info_entry *entry,
64787 struct snd_info_buffer *buffer);
64788 -};
64789 +} __no_const;
64790
64791 struct snd_info_entry_ops {
64792 int (*open)(struct snd_info_entry *entry,
64793 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64794 index 0d11128..814178e 100644
64795 --- a/include/sound/pcm.h
64796 +++ b/include/sound/pcm.h
64797 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64798 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64799 int (*ack)(struct snd_pcm_substream *substream);
64800 };
64801 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64802
64803 /*
64804 *
64805 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64806 index af1b49e..a5d55a5 100644
64807 --- a/include/sound/sb16_csp.h
64808 +++ b/include/sound/sb16_csp.h
64809 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64810 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64811 int (*csp_stop) (struct snd_sb_csp * p);
64812 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64813 -};
64814 +} __no_const;
64815
64816 /*
64817 * CSP private data
64818 diff --git a/include/sound/soc.h b/include/sound/soc.h
64819 index c703871..f7fbbbd 100644
64820 --- a/include/sound/soc.h
64821 +++ b/include/sound/soc.h
64822 @@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
64823 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64824 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64825 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
64826 -};
64827 +} __do_const;
64828
64829 struct snd_soc_platform {
64830 const char *name;
64831 @@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
64832 struct snd_soc_dai_link *dai_link;
64833 struct mutex pcm_mutex;
64834 enum snd_soc_pcm_subclass pcm_subclass;
64835 - struct snd_pcm_ops ops;
64836 + snd_pcm_ops_no_const ops;
64837
64838 unsigned int dev_registered:1;
64839
64840 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
64841 index 0c3c2fb..d9d9990 100644
64842 --- a/include/sound/tea575x-tuner.h
64843 +++ b/include/sound/tea575x-tuner.h
64844 @@ -44,7 +44,7 @@ struct snd_tea575x_ops {
64845
64846 struct snd_tea575x {
64847 struct v4l2_device *v4l2_dev;
64848 - struct v4l2_file_operations fops;
64849 + v4l2_file_operations_no_const fops;
64850 struct video_device vd; /* video device */
64851 int radio_nr; /* radio_nr */
64852 bool tea5759; /* 5759 chip is present */
64853 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64854 index 4119966..1a4671c 100644
64855 --- a/include/sound/ymfpci.h
64856 +++ b/include/sound/ymfpci.h
64857 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64858 spinlock_t reg_lock;
64859 spinlock_t voice_lock;
64860 wait_queue_head_t interrupt_sleep;
64861 - atomic_t interrupt_sleep_count;
64862 + atomic_unchecked_t interrupt_sleep_count;
64863 struct snd_info_entry *proc_entry;
64864 const struct firmware *dsp_microcode;
64865 const struct firmware *controller_microcode;
64866 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64867 index dc35d86..4725f45 100644
64868 --- a/include/target/target_core_base.h
64869 +++ b/include/target/target_core_base.h
64870 @@ -440,7 +440,7 @@ struct t10_reservation_ops {
64871 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64872 int (*t10_pr_register)(struct se_cmd *);
64873 int (*t10_pr_clear)(struct se_cmd *);
64874 -};
64875 +} __no_const;
64876
64877 struct t10_reservation {
64878 /* Reservation effects all target ports */
64879 @@ -779,7 +779,7 @@ struct se_device {
64880 spinlock_t stats_lock;
64881 /* Active commands on this virtual SE device */
64882 atomic_t simple_cmds;
64883 - atomic_t dev_ordered_id;
64884 + atomic_unchecked_t dev_ordered_id;
64885 atomic_t execute_tasks;
64886 atomic_t dev_ordered_sync;
64887 atomic_t dev_qf_count;
64888 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64889 new file mode 100644
64890 index 0000000..2efe49d
64891 --- /dev/null
64892 +++ b/include/trace/events/fs.h
64893 @@ -0,0 +1,53 @@
64894 +#undef TRACE_SYSTEM
64895 +#define TRACE_SYSTEM fs
64896 +
64897 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64898 +#define _TRACE_FS_H
64899 +
64900 +#include <linux/fs.h>
64901 +#include <linux/tracepoint.h>
64902 +
64903 +TRACE_EVENT(do_sys_open,
64904 +
64905 + TP_PROTO(char *filename, int flags, int mode),
64906 +
64907 + TP_ARGS(filename, flags, mode),
64908 +
64909 + TP_STRUCT__entry(
64910 + __string( filename, filename )
64911 + __field( int, flags )
64912 + __field( int, mode )
64913 + ),
64914 +
64915 + TP_fast_assign(
64916 + __assign_str(filename, filename);
64917 + __entry->flags = flags;
64918 + __entry->mode = mode;
64919 + ),
64920 +
64921 + TP_printk("\"%s\" %x %o",
64922 + __get_str(filename), __entry->flags, __entry->mode)
64923 +);
64924 +
64925 +TRACE_EVENT(open_exec,
64926 +
64927 + TP_PROTO(const char *filename),
64928 +
64929 + TP_ARGS(filename),
64930 +
64931 + TP_STRUCT__entry(
64932 + __string( filename, filename )
64933 + ),
64934 +
64935 + TP_fast_assign(
64936 + __assign_str(filename, filename);
64937 + ),
64938 +
64939 + TP_printk("\"%s\"",
64940 + __get_str(filename))
64941 +);
64942 +
64943 +#endif /* _TRACE_FS_H */
64944 +
64945 +/* This part must be outside protection */
64946 +#include <trace/define_trace.h>
64947 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64948 index 1c09820..7f5ec79 100644
64949 --- a/include/trace/events/irq.h
64950 +++ b/include/trace/events/irq.h
64951 @@ -36,7 +36,7 @@ struct softirq_action;
64952 */
64953 TRACE_EVENT(irq_handler_entry,
64954
64955 - TP_PROTO(int irq, struct irqaction *action),
64956 + TP_PROTO(int irq, const struct irqaction *action),
64957
64958 TP_ARGS(irq, action),
64959
64960 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64961 */
64962 TRACE_EVENT(irq_handler_exit,
64963
64964 - TP_PROTO(int irq, struct irqaction *action, int ret),
64965 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64966
64967 TP_ARGS(irq, action, ret),
64968
64969 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64970 index f9466fa..f4e2b81 100644
64971 --- a/include/video/udlfb.h
64972 +++ b/include/video/udlfb.h
64973 @@ -53,10 +53,10 @@ struct dlfb_data {
64974 u32 pseudo_palette[256];
64975 int blank_mode; /*one of FB_BLANK_ */
64976 /* blit-only rendering path metrics, exposed through sysfs */
64977 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64978 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64979 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64980 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64981 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64982 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64983 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64984 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64985 };
64986
64987 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64988 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64989 index 0993a22..32ba2fe 100644
64990 --- a/include/video/uvesafb.h
64991 +++ b/include/video/uvesafb.h
64992 @@ -177,6 +177,7 @@ struct uvesafb_par {
64993 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64994 u8 pmi_setpal; /* PMI for palette changes */
64995 u16 *pmi_base; /* protected mode interface location */
64996 + u8 *pmi_code; /* protected mode code location */
64997 void *pmi_start;
64998 void *pmi_pal;
64999 u8 *vbe_state_orig; /*
65000 diff --git a/init/Kconfig b/init/Kconfig
65001 index d07dcf9..fa47d0e 100644
65002 --- a/init/Kconfig
65003 +++ b/init/Kconfig
65004 @@ -835,6 +835,7 @@ endif # CGROUPS
65005
65006 config CHECKPOINT_RESTORE
65007 bool "Checkpoint/restore support" if EXPERT
65008 + depends on !GRKERNSEC
65009 default n
65010 help
65011 Enables additional kernel features in a sake of checkpoint/restore.
65012 @@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65013 # Security modules
65014 depends on SECURITY_TOMOYO = n
65015 depends on SECURITY_APPARMOR = n
65016 + depends on GRKERNSEC = n
65017
65018 config UIDGID_STRICT_TYPE_CHECKS
65019 bool "Require conversions between uid/gids and their internal representation"
65020 @@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65021
65022 config COMPAT_BRK
65023 bool "Disable heap randomization"
65024 - default y
65025 + default n
65026 help
65027 Randomizing heap placement makes heap exploits harder, but it
65028 also breaks ancient binaries (including anything libc5 based).
65029 @@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65030 config STOP_MACHINE
65031 bool
65032 default y
65033 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65034 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65035 help
65036 Need stop_machine() primitive.
65037
65038 diff --git a/init/Makefile b/init/Makefile
65039 index 7bc47ee..6da2dc7 100644
65040 --- a/init/Makefile
65041 +++ b/init/Makefile
65042 @@ -2,6 +2,9 @@
65043 # Makefile for the linux kernel.
65044 #
65045
65046 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65047 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65048 +
65049 obj-y := main.o version.o mounts.o
65050 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65051 obj-y += noinitramfs.o
65052 diff --git a/init/do_mounts.c b/init/do_mounts.c
65053 index d3f0aee..c9322f5 100644
65054 --- a/init/do_mounts.c
65055 +++ b/init/do_mounts.c
65056 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65057 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65058 {
65059 struct super_block *s;
65060 - int err = sys_mount(name, "/root", fs, flags, data);
65061 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65062 if (err)
65063 return err;
65064
65065 - sys_chdir("/root");
65066 + sys_chdir((const char __force_user *)"/root");
65067 s = current->fs->pwd.dentry->d_sb;
65068 ROOT_DEV = s->s_dev;
65069 printk(KERN_INFO
65070 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65071 va_start(args, fmt);
65072 vsprintf(buf, fmt, args);
65073 va_end(args);
65074 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65075 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65076 if (fd >= 0) {
65077 sys_ioctl(fd, FDEJECT, 0);
65078 sys_close(fd);
65079 }
65080 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65081 - fd = sys_open("/dev/console", O_RDWR, 0);
65082 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65083 if (fd >= 0) {
65084 sys_ioctl(fd, TCGETS, (long)&termios);
65085 termios.c_lflag &= ~ICANON;
65086 sys_ioctl(fd, TCSETSF, (long)&termios);
65087 - sys_read(fd, &c, 1);
65088 + sys_read(fd, (char __user *)&c, 1);
65089 termios.c_lflag |= ICANON;
65090 sys_ioctl(fd, TCSETSF, (long)&termios);
65091 sys_close(fd);
65092 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65093 mount_root();
65094 out:
65095 devtmpfs_mount("dev");
65096 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65097 - sys_chroot(".");
65098 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65099 + sys_chroot((const char __force_user *)".");
65100 }
65101 diff --git a/init/do_mounts.h b/init/do_mounts.h
65102 index f5b978a..69dbfe8 100644
65103 --- a/init/do_mounts.h
65104 +++ b/init/do_mounts.h
65105 @@ -15,15 +15,15 @@ extern int root_mountflags;
65106
65107 static inline int create_dev(char *name, dev_t dev)
65108 {
65109 - sys_unlink(name);
65110 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65111 + sys_unlink((char __force_user *)name);
65112 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65113 }
65114
65115 #if BITS_PER_LONG == 32
65116 static inline u32 bstat(char *name)
65117 {
65118 struct stat64 stat;
65119 - if (sys_stat64(name, &stat) != 0)
65120 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65121 return 0;
65122 if (!S_ISBLK(stat.st_mode))
65123 return 0;
65124 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65125 static inline u32 bstat(char *name)
65126 {
65127 struct stat stat;
65128 - if (sys_newstat(name, &stat) != 0)
65129 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65130 return 0;
65131 if (!S_ISBLK(stat.st_mode))
65132 return 0;
65133 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65134 index 135959a2..28a3f43 100644
65135 --- a/init/do_mounts_initrd.c
65136 +++ b/init/do_mounts_initrd.c
65137 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65138 create_dev("/dev/root.old", Root_RAM0);
65139 /* mount initrd on rootfs' /root */
65140 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65141 - sys_mkdir("/old", 0700);
65142 - root_fd = sys_open("/", 0, 0);
65143 - old_fd = sys_open("/old", 0, 0);
65144 + sys_mkdir((const char __force_user *)"/old", 0700);
65145 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65146 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65147 /* move initrd over / and chdir/chroot in initrd root */
65148 - sys_chdir("/root");
65149 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65150 - sys_chroot(".");
65151 + sys_chdir((const char __force_user *)"/root");
65152 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65153 + sys_chroot((const char __force_user *)".");
65154
65155 /*
65156 * In case that a resume from disk is carried out by linuxrc or one of
65157 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65158
65159 /* move initrd to rootfs' /old */
65160 sys_fchdir(old_fd);
65161 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65162 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65163 /* switch root and cwd back to / of rootfs */
65164 sys_fchdir(root_fd);
65165 - sys_chroot(".");
65166 + sys_chroot((const char __force_user *)".");
65167 sys_close(old_fd);
65168 sys_close(root_fd);
65169
65170 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65171 - sys_chdir("/old");
65172 + sys_chdir((const char __force_user *)"/old");
65173 return;
65174 }
65175
65176 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65177 mount_root();
65178
65179 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65180 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65181 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65182 if (!error)
65183 printk("okay\n");
65184 else {
65185 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65186 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65187 if (error == -ENOENT)
65188 printk("/initrd does not exist. Ignored.\n");
65189 else
65190 printk("failed\n");
65191 printk(KERN_NOTICE "Unmounting old root\n");
65192 - sys_umount("/old", MNT_DETACH);
65193 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65194 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65195 if (fd < 0) {
65196 error = fd;
65197 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65198 * mounted in the normal path.
65199 */
65200 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65201 - sys_unlink("/initrd.image");
65202 + sys_unlink((const char __force_user *)"/initrd.image");
65203 handle_initrd();
65204 return 1;
65205 }
65206 }
65207 - sys_unlink("/initrd.image");
65208 + sys_unlink((const char __force_user *)"/initrd.image");
65209 return 0;
65210 }
65211 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65212 index 8cb6db5..d729f50 100644
65213 --- a/init/do_mounts_md.c
65214 +++ b/init/do_mounts_md.c
65215 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65216 partitioned ? "_d" : "", minor,
65217 md_setup_args[ent].device_names);
65218
65219 - fd = sys_open(name, 0, 0);
65220 + fd = sys_open((char __force_user *)name, 0, 0);
65221 if (fd < 0) {
65222 printk(KERN_ERR "md: open failed - cannot start "
65223 "array %s\n", name);
65224 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65225 * array without it
65226 */
65227 sys_close(fd);
65228 - fd = sys_open(name, 0, 0);
65229 + fd = sys_open((char __force_user *)name, 0, 0);
65230 sys_ioctl(fd, BLKRRPART, 0);
65231 }
65232 sys_close(fd);
65233 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65234
65235 wait_for_device_probe();
65236
65237 - fd = sys_open("/dev/md0", 0, 0);
65238 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65239 if (fd >= 0) {
65240 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65241 sys_close(fd);
65242 diff --git a/init/init_task.c b/init/init_task.c
65243 index 8b2f399..f0797c9 100644
65244 --- a/init/init_task.c
65245 +++ b/init/init_task.c
65246 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65247 * Initial thread structure. Alignment of this is handled by a special
65248 * linker map entry.
65249 */
65250 +#ifdef CONFIG_X86
65251 +union thread_union init_thread_union __init_task_data;
65252 +#else
65253 union thread_union init_thread_union __init_task_data =
65254 { INIT_THREAD_INFO(init_task) };
65255 +#endif
65256 diff --git a/init/initramfs.c b/init/initramfs.c
65257 index 84c6bf1..8899338 100644
65258 --- a/init/initramfs.c
65259 +++ b/init/initramfs.c
65260 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65261 }
65262 }
65263
65264 -static long __init do_utime(char *filename, time_t mtime)
65265 +static long __init do_utime(char __force_user *filename, time_t mtime)
65266 {
65267 struct timespec t[2];
65268
65269 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65270 struct dir_entry *de, *tmp;
65271 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65272 list_del(&de->list);
65273 - do_utime(de->name, de->mtime);
65274 + do_utime((char __force_user *)de->name, de->mtime);
65275 kfree(de->name);
65276 kfree(de);
65277 }
65278 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65279 if (nlink >= 2) {
65280 char *old = find_link(major, minor, ino, mode, collected);
65281 if (old)
65282 - return (sys_link(old, collected) < 0) ? -1 : 1;
65283 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65284 }
65285 return 0;
65286 }
65287 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65288 {
65289 struct stat st;
65290
65291 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65292 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65293 if (S_ISDIR(st.st_mode))
65294 - sys_rmdir(path);
65295 + sys_rmdir((char __force_user *)path);
65296 else
65297 - sys_unlink(path);
65298 + sys_unlink((char __force_user *)path);
65299 }
65300 }
65301
65302 @@ -315,7 +315,7 @@ static int __init do_name(void)
65303 int openflags = O_WRONLY|O_CREAT;
65304 if (ml != 1)
65305 openflags |= O_TRUNC;
65306 - wfd = sys_open(collected, openflags, mode);
65307 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65308
65309 if (wfd >= 0) {
65310 sys_fchown(wfd, uid, gid);
65311 @@ -327,17 +327,17 @@ static int __init do_name(void)
65312 }
65313 }
65314 } else if (S_ISDIR(mode)) {
65315 - sys_mkdir(collected, mode);
65316 - sys_chown(collected, uid, gid);
65317 - sys_chmod(collected, mode);
65318 + sys_mkdir((char __force_user *)collected, mode);
65319 + sys_chown((char __force_user *)collected, uid, gid);
65320 + sys_chmod((char __force_user *)collected, mode);
65321 dir_add(collected, mtime);
65322 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65323 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65324 if (maybe_link() == 0) {
65325 - sys_mknod(collected, mode, rdev);
65326 - sys_chown(collected, uid, gid);
65327 - sys_chmod(collected, mode);
65328 - do_utime(collected, mtime);
65329 + sys_mknod((char __force_user *)collected, mode, rdev);
65330 + sys_chown((char __force_user *)collected, uid, gid);
65331 + sys_chmod((char __force_user *)collected, mode);
65332 + do_utime((char __force_user *)collected, mtime);
65333 }
65334 }
65335 return 0;
65336 @@ -346,15 +346,15 @@ static int __init do_name(void)
65337 static int __init do_copy(void)
65338 {
65339 if (count >= body_len) {
65340 - sys_write(wfd, victim, body_len);
65341 + sys_write(wfd, (char __force_user *)victim, body_len);
65342 sys_close(wfd);
65343 - do_utime(vcollected, mtime);
65344 + do_utime((char __force_user *)vcollected, mtime);
65345 kfree(vcollected);
65346 eat(body_len);
65347 state = SkipIt;
65348 return 0;
65349 } else {
65350 - sys_write(wfd, victim, count);
65351 + sys_write(wfd, (char __force_user *)victim, count);
65352 body_len -= count;
65353 eat(count);
65354 return 1;
65355 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
65356 {
65357 collected[N_ALIGN(name_len) + body_len] = '\0';
65358 clean_path(collected, 0);
65359 - sys_symlink(collected + N_ALIGN(name_len), collected);
65360 - sys_lchown(collected, uid, gid);
65361 - do_utime(collected, mtime);
65362 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65363 + sys_lchown((char __force_user *)collected, uid, gid);
65364 + do_utime((char __force_user *)collected, mtime);
65365 state = SkipIt;
65366 next_state = Reset;
65367 return 0;
65368 diff --git a/init/main.c b/init/main.c
65369 index b5cc0a7..5605c91 100644
65370 --- a/init/main.c
65371 +++ b/init/main.c
65372 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65373 extern void tc_init(void);
65374 #endif
65375
65376 +extern void grsecurity_init(void);
65377 +
65378 /*
65379 * Debug helper: via this flag we know that we are in 'early bootup code'
65380 * where only the boot processor is running with IRQ disabled. This means
65381 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65382
65383 __setup("reset_devices", set_reset_devices);
65384
65385 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65386 +extern char pax_enter_kernel_user[];
65387 +extern char pax_exit_kernel_user[];
65388 +extern pgdval_t clone_pgd_mask;
65389 +#endif
65390 +
65391 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65392 +static int __init setup_pax_nouderef(char *str)
65393 +{
65394 +#ifdef CONFIG_X86_32
65395 + unsigned int cpu;
65396 + struct desc_struct *gdt;
65397 +
65398 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65399 + gdt = get_cpu_gdt_table(cpu);
65400 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65401 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65402 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65403 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65404 + }
65405 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65406 +#else
65407 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65408 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65409 + clone_pgd_mask = ~(pgdval_t)0UL;
65410 +#endif
65411 +
65412 + return 0;
65413 +}
65414 +early_param("pax_nouderef", setup_pax_nouderef);
65415 +#endif
65416 +
65417 +#ifdef CONFIG_PAX_SOFTMODE
65418 +int pax_softmode;
65419 +
65420 +static int __init setup_pax_softmode(char *str)
65421 +{
65422 + get_option(&str, &pax_softmode);
65423 + return 1;
65424 +}
65425 +__setup("pax_softmode=", setup_pax_softmode);
65426 +#endif
65427 +
65428 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65429 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65430 static const char *panic_later, *panic_param;
65431 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65432 {
65433 int count = preempt_count();
65434 int ret;
65435 + const char *msg1 = "", *msg2 = "";
65436
65437 if (initcall_debug)
65438 ret = do_one_initcall_debug(fn);
65439 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65440 sprintf(msgbuf, "error code %d ", ret);
65441
65442 if (preempt_count() != count) {
65443 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65444 + msg1 = " preemption imbalance";
65445 preempt_count() = count;
65446 }
65447 if (irqs_disabled()) {
65448 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65449 + msg2 = " disabled interrupts";
65450 local_irq_enable();
65451 }
65452 - if (msgbuf[0]) {
65453 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65454 + if (msgbuf[0] || *msg1 || *msg2) {
65455 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65456 }
65457
65458 return ret;
65459 @@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65460 level, level,
65461 &repair_env_string);
65462
65463 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65464 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65465 do_one_initcall(*fn);
65466 +
65467 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65468 + transfer_latent_entropy();
65469 +#endif
65470 +
65471 + }
65472 }
65473
65474 static void __init do_initcalls(void)
65475 @@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65476 {
65477 initcall_t *fn;
65478
65479 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
65480 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65481 do_one_initcall(*fn);
65482 +
65483 +#ifdef CONFIG_PAX_LATENT_ENTROPY
65484 + transfer_latent_entropy();
65485 +#endif
65486 +
65487 + }
65488 }
65489
65490 static void run_init_process(const char *init_filename)
65491 @@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65492 do_basic_setup();
65493
65494 /* Open the /dev/console on the rootfs, this should never fail */
65495 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65496 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65497 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65498
65499 (void) sys_dup(0);
65500 @@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65501 if (!ramdisk_execute_command)
65502 ramdisk_execute_command = "/init";
65503
65504 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65505 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65506 ramdisk_execute_command = NULL;
65507 prepare_namespace();
65508 }
65509
65510 + grsecurity_init();
65511 +
65512 /*
65513 * Ok, we have completed the initial bootup, and
65514 * we're essentially up and running. Get rid of the
65515 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65516 index 8ce5769..4666884 100644
65517 --- a/ipc/mqueue.c
65518 +++ b/ipc/mqueue.c
65519 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65520 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65521 info->attr.mq_msgsize);
65522
65523 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65524 spin_lock(&mq_lock);
65525 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65526 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65527 diff --git a/ipc/msg.c b/ipc/msg.c
65528 index 7385de2..a8180e08 100644
65529 --- a/ipc/msg.c
65530 +++ b/ipc/msg.c
65531 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65532 return security_msg_queue_associate(msq, msgflg);
65533 }
65534
65535 +static struct ipc_ops msg_ops = {
65536 + .getnew = newque,
65537 + .associate = msg_security,
65538 + .more_checks = NULL
65539 +};
65540 +
65541 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65542 {
65543 struct ipc_namespace *ns;
65544 - struct ipc_ops msg_ops;
65545 struct ipc_params msg_params;
65546
65547 ns = current->nsproxy->ipc_ns;
65548
65549 - msg_ops.getnew = newque;
65550 - msg_ops.associate = msg_security;
65551 - msg_ops.more_checks = NULL;
65552 -
65553 msg_params.key = key;
65554 msg_params.flg = msgflg;
65555
65556 diff --git a/ipc/sem.c b/ipc/sem.c
65557 index 5215a81..cfc0cac 100644
65558 --- a/ipc/sem.c
65559 +++ b/ipc/sem.c
65560 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65561 return 0;
65562 }
65563
65564 +static struct ipc_ops sem_ops = {
65565 + .getnew = newary,
65566 + .associate = sem_security,
65567 + .more_checks = sem_more_checks
65568 +};
65569 +
65570 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65571 {
65572 struct ipc_namespace *ns;
65573 - struct ipc_ops sem_ops;
65574 struct ipc_params sem_params;
65575
65576 ns = current->nsproxy->ipc_ns;
65577 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65578 if (nsems < 0 || nsems > ns->sc_semmsl)
65579 return -EINVAL;
65580
65581 - sem_ops.getnew = newary;
65582 - sem_ops.associate = sem_security;
65583 - sem_ops.more_checks = sem_more_checks;
65584 -
65585 sem_params.key = key;
65586 sem_params.flg = semflg;
65587 sem_params.u.nsems = nsems;
65588 diff --git a/ipc/shm.c b/ipc/shm.c
65589 index 41c1285..cf6404c 100644
65590 --- a/ipc/shm.c
65591 +++ b/ipc/shm.c
65592 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65593 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65594 #endif
65595
65596 +#ifdef CONFIG_GRKERNSEC
65597 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65598 + const time_t shm_createtime, const uid_t cuid,
65599 + const int shmid);
65600 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65601 + const time_t shm_createtime);
65602 +#endif
65603 +
65604 void shm_init_ns(struct ipc_namespace *ns)
65605 {
65606 ns->shm_ctlmax = SHMMAX;
65607 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65608 shp->shm_lprid = 0;
65609 shp->shm_atim = shp->shm_dtim = 0;
65610 shp->shm_ctim = get_seconds();
65611 +#ifdef CONFIG_GRKERNSEC
65612 + {
65613 + struct timespec timeval;
65614 + do_posix_clock_monotonic_gettime(&timeval);
65615 +
65616 + shp->shm_createtime = timeval.tv_sec;
65617 + }
65618 +#endif
65619 shp->shm_segsz = size;
65620 shp->shm_nattch = 0;
65621 shp->shm_file = file;
65622 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65623 return 0;
65624 }
65625
65626 +static struct ipc_ops shm_ops = {
65627 + .getnew = newseg,
65628 + .associate = shm_security,
65629 + .more_checks = shm_more_checks
65630 +};
65631 +
65632 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65633 {
65634 struct ipc_namespace *ns;
65635 - struct ipc_ops shm_ops;
65636 struct ipc_params shm_params;
65637
65638 ns = current->nsproxy->ipc_ns;
65639
65640 - shm_ops.getnew = newseg;
65641 - shm_ops.associate = shm_security;
65642 - shm_ops.more_checks = shm_more_checks;
65643 -
65644 shm_params.key = key;
65645 shm_params.flg = shmflg;
65646 shm_params.u.size = size;
65647 @@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65648 f_mode = FMODE_READ | FMODE_WRITE;
65649 }
65650 if (shmflg & SHM_EXEC) {
65651 +
65652 +#ifdef CONFIG_PAX_MPROTECT
65653 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65654 + goto out;
65655 +#endif
65656 +
65657 prot |= PROT_EXEC;
65658 acc_mode |= S_IXUGO;
65659 }
65660 @@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65661 if (err)
65662 goto out_unlock;
65663
65664 +#ifdef CONFIG_GRKERNSEC
65665 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65666 + shp->shm_perm.cuid, shmid) ||
65667 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65668 + err = -EACCES;
65669 + goto out_unlock;
65670 + }
65671 +#endif
65672 +
65673 path = shp->shm_file->f_path;
65674 path_get(&path);
65675 shp->shm_nattch++;
65676 +#ifdef CONFIG_GRKERNSEC
65677 + shp->shm_lapid = current->pid;
65678 +#endif
65679 size = i_size_read(path.dentry->d_inode);
65680 shm_unlock(shp);
65681
65682 diff --git a/kernel/acct.c b/kernel/acct.c
65683 index 02e6167..54824f7 100644
65684 --- a/kernel/acct.c
65685 +++ b/kernel/acct.c
65686 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65687 */
65688 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65689 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65690 - file->f_op->write(file, (char *)&ac,
65691 + file->f_op->write(file, (char __force_user *)&ac,
65692 sizeof(acct_t), &file->f_pos);
65693 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65694 set_fs(fs);
65695 diff --git a/kernel/audit.c b/kernel/audit.c
65696 index 1c7f2c6..9ba5359 100644
65697 --- a/kernel/audit.c
65698 +++ b/kernel/audit.c
65699 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65700 3) suppressed due to audit_rate_limit
65701 4) suppressed due to audit_backlog_limit
65702 */
65703 -static atomic_t audit_lost = ATOMIC_INIT(0);
65704 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65705
65706 /* The netlink socket. */
65707 static struct sock *audit_sock;
65708 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65709 unsigned long now;
65710 int print;
65711
65712 - atomic_inc(&audit_lost);
65713 + atomic_inc_unchecked(&audit_lost);
65714
65715 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65716
65717 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65718 printk(KERN_WARNING
65719 "audit: audit_lost=%d audit_rate_limit=%d "
65720 "audit_backlog_limit=%d\n",
65721 - atomic_read(&audit_lost),
65722 + atomic_read_unchecked(&audit_lost),
65723 audit_rate_limit,
65724 audit_backlog_limit);
65725 audit_panic(message);
65726 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65727 status_set.pid = audit_pid;
65728 status_set.rate_limit = audit_rate_limit;
65729 status_set.backlog_limit = audit_backlog_limit;
65730 - status_set.lost = atomic_read(&audit_lost);
65731 + status_set.lost = atomic_read_unchecked(&audit_lost);
65732 status_set.backlog = skb_queue_len(&audit_skb_queue);
65733 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65734 &status_set, sizeof(status_set));
65735 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65736 index 4b96415..d8c16ee 100644
65737 --- a/kernel/auditsc.c
65738 +++ b/kernel/auditsc.c
65739 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65740 }
65741
65742 /* global counter which is incremented every time something logs in */
65743 -static atomic_t session_id = ATOMIC_INIT(0);
65744 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65745
65746 /**
65747 * audit_set_loginuid - set current task's audit_context loginuid
65748 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65749 return -EPERM;
65750 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65751
65752 - sessionid = atomic_inc_return(&session_id);
65753 + sessionid = atomic_inc_return_unchecked(&session_id);
65754 if (context && context->in_syscall) {
65755 struct audit_buffer *ab;
65756
65757 diff --git a/kernel/capability.c b/kernel/capability.c
65758 index 493d972..ea17248 100644
65759 --- a/kernel/capability.c
65760 +++ b/kernel/capability.c
65761 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65762 * before modification is attempted and the application
65763 * fails.
65764 */
65765 + if (tocopy > ARRAY_SIZE(kdata))
65766 + return -EFAULT;
65767 +
65768 if (copy_to_user(dataptr, kdata, tocopy
65769 * sizeof(struct __user_cap_data_struct))) {
65770 return -EFAULT;
65771 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65772 int ret;
65773
65774 rcu_read_lock();
65775 - ret = security_capable(__task_cred(t), ns, cap);
65776 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65777 + gr_task_is_capable(t, __task_cred(t), cap);
65778 rcu_read_unlock();
65779
65780 - return (ret == 0);
65781 + return ret;
65782 }
65783
65784 /**
65785 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65786 int ret;
65787
65788 rcu_read_lock();
65789 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65790 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65791 rcu_read_unlock();
65792
65793 - return (ret == 0);
65794 + return ret;
65795 }
65796
65797 /**
65798 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65799 BUG();
65800 }
65801
65802 - if (security_capable(current_cred(), ns, cap) == 0) {
65803 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65804 current->flags |= PF_SUPERPRIV;
65805 return true;
65806 }
65807 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65808 }
65809 EXPORT_SYMBOL(ns_capable);
65810
65811 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65812 +{
65813 + if (unlikely(!cap_valid(cap))) {
65814 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65815 + BUG();
65816 + }
65817 +
65818 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65819 + current->flags |= PF_SUPERPRIV;
65820 + return true;
65821 + }
65822 + return false;
65823 +}
65824 +EXPORT_SYMBOL(ns_capable_nolog);
65825 +
65826 /**
65827 * capable - Determine if the current task has a superior capability in effect
65828 * @cap: The capability to be tested for
65829 @@ -408,6 +427,12 @@ bool capable(int cap)
65830 }
65831 EXPORT_SYMBOL(capable);
65832
65833 +bool capable_nolog(int cap)
65834 +{
65835 + return ns_capable_nolog(&init_user_ns, cap);
65836 +}
65837 +EXPORT_SYMBOL(capable_nolog);
65838 +
65839 /**
65840 * nsown_capable - Check superior capability to one's own user_ns
65841 * @cap: The capability in question
65842 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
65843
65844 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65845 }
65846 +
65847 +bool inode_capable_nolog(const struct inode *inode, int cap)
65848 +{
65849 + struct user_namespace *ns = current_user_ns();
65850 +
65851 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65852 +}
65853 diff --git a/kernel/compat.c b/kernel/compat.c
65854 index c28a306..b4d0cf3 100644
65855 --- a/kernel/compat.c
65856 +++ b/kernel/compat.c
65857 @@ -13,6 +13,7 @@
65858
65859 #include <linux/linkage.h>
65860 #include <linux/compat.h>
65861 +#include <linux/module.h>
65862 #include <linux/errno.h>
65863 #include <linux/time.h>
65864 #include <linux/signal.h>
65865 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65866 mm_segment_t oldfs;
65867 long ret;
65868
65869 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65870 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65871 oldfs = get_fs();
65872 set_fs(KERNEL_DS);
65873 ret = hrtimer_nanosleep_restart(restart);
65874 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65875 oldfs = get_fs();
65876 set_fs(KERNEL_DS);
65877 ret = hrtimer_nanosleep(&tu,
65878 - rmtp ? (struct timespec __user *)&rmt : NULL,
65879 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65880 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65881 set_fs(oldfs);
65882
65883 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65884 mm_segment_t old_fs = get_fs();
65885
65886 set_fs(KERNEL_DS);
65887 - ret = sys_sigpending((old_sigset_t __user *) &s);
65888 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65889 set_fs(old_fs);
65890 if (ret == 0)
65891 ret = put_user(s, set);
65892 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65893 mm_segment_t old_fs = get_fs();
65894
65895 set_fs(KERNEL_DS);
65896 - ret = sys_old_getrlimit(resource, &r);
65897 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65898 set_fs(old_fs);
65899
65900 if (!ret) {
65901 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65902 mm_segment_t old_fs = get_fs();
65903
65904 set_fs(KERNEL_DS);
65905 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65906 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65907 set_fs(old_fs);
65908
65909 if (ret)
65910 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65911 set_fs (KERNEL_DS);
65912 ret = sys_wait4(pid,
65913 (stat_addr ?
65914 - (unsigned int __user *) &status : NULL),
65915 - options, (struct rusage __user *) &r);
65916 + (unsigned int __force_user *) &status : NULL),
65917 + options, (struct rusage __force_user *) &r);
65918 set_fs (old_fs);
65919
65920 if (ret > 0) {
65921 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65922 memset(&info, 0, sizeof(info));
65923
65924 set_fs(KERNEL_DS);
65925 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65926 - uru ? (struct rusage __user *)&ru : NULL);
65927 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65928 + uru ? (struct rusage __force_user *)&ru : NULL);
65929 set_fs(old_fs);
65930
65931 if ((ret < 0) || (info.si_signo == 0))
65932 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65933 oldfs = get_fs();
65934 set_fs(KERNEL_DS);
65935 err = sys_timer_settime(timer_id, flags,
65936 - (struct itimerspec __user *) &newts,
65937 - (struct itimerspec __user *) &oldts);
65938 + (struct itimerspec __force_user *) &newts,
65939 + (struct itimerspec __force_user *) &oldts);
65940 set_fs(oldfs);
65941 if (!err && old && put_compat_itimerspec(old, &oldts))
65942 return -EFAULT;
65943 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65944 oldfs = get_fs();
65945 set_fs(KERNEL_DS);
65946 err = sys_timer_gettime(timer_id,
65947 - (struct itimerspec __user *) &ts);
65948 + (struct itimerspec __force_user *) &ts);
65949 set_fs(oldfs);
65950 if (!err && put_compat_itimerspec(setting, &ts))
65951 return -EFAULT;
65952 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65953 oldfs = get_fs();
65954 set_fs(KERNEL_DS);
65955 err = sys_clock_settime(which_clock,
65956 - (struct timespec __user *) &ts);
65957 + (struct timespec __force_user *) &ts);
65958 set_fs(oldfs);
65959 return err;
65960 }
65961 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65962 oldfs = get_fs();
65963 set_fs(KERNEL_DS);
65964 err = sys_clock_gettime(which_clock,
65965 - (struct timespec __user *) &ts);
65966 + (struct timespec __force_user *) &ts);
65967 set_fs(oldfs);
65968 if (!err && put_compat_timespec(&ts, tp))
65969 return -EFAULT;
65970 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65971
65972 oldfs = get_fs();
65973 set_fs(KERNEL_DS);
65974 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65975 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65976 set_fs(oldfs);
65977
65978 err = compat_put_timex(utp, &txc);
65979 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65980 oldfs = get_fs();
65981 set_fs(KERNEL_DS);
65982 err = sys_clock_getres(which_clock,
65983 - (struct timespec __user *) &ts);
65984 + (struct timespec __force_user *) &ts);
65985 set_fs(oldfs);
65986 if (!err && tp && put_compat_timespec(&ts, tp))
65987 return -EFAULT;
65988 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65989 long err;
65990 mm_segment_t oldfs;
65991 struct timespec tu;
65992 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65993 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65994
65995 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65996 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65997 oldfs = get_fs();
65998 set_fs(KERNEL_DS);
65999 err = clock_nanosleep_restart(restart);
66000 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66001 oldfs = get_fs();
66002 set_fs(KERNEL_DS);
66003 err = sys_clock_nanosleep(which_clock, flags,
66004 - (struct timespec __user *) &in,
66005 - (struct timespec __user *) &out);
66006 + (struct timespec __force_user *) &in,
66007 + (struct timespec __force_user *) &out);
66008 set_fs(oldfs);
66009
66010 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66011 diff --git a/kernel/configs.c b/kernel/configs.c
66012 index 42e8fa0..9e7406b 100644
66013 --- a/kernel/configs.c
66014 +++ b/kernel/configs.c
66015 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66016 struct proc_dir_entry *entry;
66017
66018 /* create the current config file */
66019 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66020 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66021 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66022 + &ikconfig_file_ops);
66023 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66024 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66025 + &ikconfig_file_ops);
66026 +#endif
66027 +#else
66028 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66029 &ikconfig_file_ops);
66030 +#endif
66031 +
66032 if (!entry)
66033 return -ENOMEM;
66034
66035 diff --git a/kernel/cred.c b/kernel/cred.c
66036 index de728ac..e3c267c 100644
66037 --- a/kernel/cred.c
66038 +++ b/kernel/cred.c
66039 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66040 validate_creds(cred);
66041 alter_cred_subscribers(cred, -1);
66042 put_cred(cred);
66043 +
66044 +#ifdef CONFIG_GRKERNSEC_SETXID
66045 + cred = (struct cred *) tsk->delayed_cred;
66046 + if (cred != NULL) {
66047 + tsk->delayed_cred = NULL;
66048 + validate_creds(cred);
66049 + alter_cred_subscribers(cred, -1);
66050 + put_cred(cred);
66051 + }
66052 +#endif
66053 }
66054
66055 /**
66056 @@ -469,7 +479,7 @@ error_put:
66057 * Always returns 0 thus allowing this function to be tail-called at the end
66058 * of, say, sys_setgid().
66059 */
66060 -int commit_creds(struct cred *new)
66061 +static int __commit_creds(struct cred *new)
66062 {
66063 struct task_struct *task = current;
66064 const struct cred *old = task->real_cred;
66065 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66066
66067 get_cred(new); /* we will require a ref for the subj creds too */
66068
66069 + gr_set_role_label(task, new->uid, new->gid);
66070 +
66071 /* dumpability changes */
66072 if (!uid_eq(old->euid, new->euid) ||
66073 !gid_eq(old->egid, new->egid) ||
66074 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66075 put_cred(old);
66076 return 0;
66077 }
66078 +#ifdef CONFIG_GRKERNSEC_SETXID
66079 +extern int set_user(struct cred *new);
66080 +
66081 +void gr_delayed_cred_worker(void)
66082 +{
66083 + const struct cred *new = current->delayed_cred;
66084 + struct cred *ncred;
66085 +
66086 + current->delayed_cred = NULL;
66087 +
66088 + if (current_uid() && new != NULL) {
66089 + // from doing get_cred on it when queueing this
66090 + put_cred(new);
66091 + return;
66092 + } else if (new == NULL)
66093 + return;
66094 +
66095 + ncred = prepare_creds();
66096 + if (!ncred)
66097 + goto die;
66098 + // uids
66099 + ncred->uid = new->uid;
66100 + ncred->euid = new->euid;
66101 + ncred->suid = new->suid;
66102 + ncred->fsuid = new->fsuid;
66103 + // gids
66104 + ncred->gid = new->gid;
66105 + ncred->egid = new->egid;
66106 + ncred->sgid = new->sgid;
66107 + ncred->fsgid = new->fsgid;
66108 + // groups
66109 + if (set_groups(ncred, new->group_info) < 0) {
66110 + abort_creds(ncred);
66111 + goto die;
66112 + }
66113 + // caps
66114 + ncred->securebits = new->securebits;
66115 + ncred->cap_inheritable = new->cap_inheritable;
66116 + ncred->cap_permitted = new->cap_permitted;
66117 + ncred->cap_effective = new->cap_effective;
66118 + ncred->cap_bset = new->cap_bset;
66119 +
66120 + if (set_user(ncred)) {
66121 + abort_creds(ncred);
66122 + goto die;
66123 + }
66124 +
66125 + // from doing get_cred on it when queueing this
66126 + put_cred(new);
66127 +
66128 + __commit_creds(ncred);
66129 + return;
66130 +die:
66131 + // from doing get_cred on it when queueing this
66132 + put_cred(new);
66133 + do_group_exit(SIGKILL);
66134 +}
66135 +#endif
66136 +
66137 +int commit_creds(struct cred *new)
66138 +{
66139 +#ifdef CONFIG_GRKERNSEC_SETXID
66140 + int ret;
66141 + int schedule_it = 0;
66142 + struct task_struct *t;
66143 +
66144 + /* we won't get called with tasklist_lock held for writing
66145 + and interrupts disabled as the cred struct in that case is
66146 + init_cred
66147 + */
66148 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66149 + !current_uid() && new->uid) {
66150 + schedule_it = 1;
66151 + }
66152 + ret = __commit_creds(new);
66153 + if (schedule_it) {
66154 + rcu_read_lock();
66155 + read_lock(&tasklist_lock);
66156 + for (t = next_thread(current); t != current;
66157 + t = next_thread(t)) {
66158 + if (t->delayed_cred == NULL) {
66159 + t->delayed_cred = get_cred(new);
66160 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66161 + set_tsk_need_resched(t);
66162 + }
66163 + }
66164 + read_unlock(&tasklist_lock);
66165 + rcu_read_unlock();
66166 + }
66167 + return ret;
66168 +#else
66169 + return __commit_creds(new);
66170 +#endif
66171 +}
66172 +
66173 EXPORT_SYMBOL(commit_creds);
66174
66175 /**
66176 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66177 index 0557f24..1a00d9a 100644
66178 --- a/kernel/debug/debug_core.c
66179 +++ b/kernel/debug/debug_core.c
66180 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66181 */
66182 static atomic_t masters_in_kgdb;
66183 static atomic_t slaves_in_kgdb;
66184 -static atomic_t kgdb_break_tasklet_var;
66185 +static atomic_unchecked_t kgdb_break_tasklet_var;
66186 atomic_t kgdb_setting_breakpoint;
66187
66188 struct task_struct *kgdb_usethread;
66189 @@ -132,7 +132,7 @@ int kgdb_single_step;
66190 static pid_t kgdb_sstep_pid;
66191
66192 /* to keep track of the CPU which is doing the single stepping*/
66193 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66194 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66195
66196 /*
66197 * If you are debugging a problem where roundup (the collection of
66198 @@ -540,7 +540,7 @@ return_normal:
66199 * kernel will only try for the value of sstep_tries before
66200 * giving up and continuing on.
66201 */
66202 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66203 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66204 (kgdb_info[cpu].task &&
66205 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66206 atomic_set(&kgdb_active, -1);
66207 @@ -634,8 +634,8 @@ cpu_master_loop:
66208 }
66209
66210 kgdb_restore:
66211 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66212 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66213 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66214 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66215 if (kgdb_info[sstep_cpu].task)
66216 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66217 else
66218 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66219 static void kgdb_tasklet_bpt(unsigned long ing)
66220 {
66221 kgdb_breakpoint();
66222 - atomic_set(&kgdb_break_tasklet_var, 0);
66223 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66224 }
66225
66226 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66227
66228 void kgdb_schedule_breakpoint(void)
66229 {
66230 - if (atomic_read(&kgdb_break_tasklet_var) ||
66231 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66232 atomic_read(&kgdb_active) != -1 ||
66233 atomic_read(&kgdb_setting_breakpoint))
66234 return;
66235 - atomic_inc(&kgdb_break_tasklet_var);
66236 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66237 tasklet_schedule(&kgdb_tasklet_breakpoint);
66238 }
66239 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66240 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66241 index 1f91413..362a0a1 100644
66242 --- a/kernel/debug/kdb/kdb_main.c
66243 +++ b/kernel/debug/kdb/kdb_main.c
66244 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66245 list_for_each_entry(mod, kdb_modules, list) {
66246
66247 kdb_printf("%-20s%8u 0x%p ", mod->name,
66248 - mod->core_size, (void *)mod);
66249 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66250 #ifdef CONFIG_MODULE_UNLOAD
66251 kdb_printf("%4ld ", module_refcount(mod));
66252 #endif
66253 @@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66254 kdb_printf(" (Loading)");
66255 else
66256 kdb_printf(" (Live)");
66257 - kdb_printf(" 0x%p", mod->module_core);
66258 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66259
66260 #ifdef CONFIG_MODULE_UNLOAD
66261 {
66262 diff --git a/kernel/events/core.c b/kernel/events/core.c
66263 index d7d71d6..f54b76f 100644
66264 --- a/kernel/events/core.c
66265 +++ b/kernel/events/core.c
66266 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66267 return 0;
66268 }
66269
66270 -static atomic64_t perf_event_id;
66271 +static atomic64_unchecked_t perf_event_id;
66272
66273 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66274 enum event_type_t event_type);
66275 @@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66276
66277 static inline u64 perf_event_count(struct perf_event *event)
66278 {
66279 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66280 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66281 }
66282
66283 static u64 perf_event_read(struct perf_event *event)
66284 @@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66285 mutex_lock(&event->child_mutex);
66286 total += perf_event_read(event);
66287 *enabled += event->total_time_enabled +
66288 - atomic64_read(&event->child_total_time_enabled);
66289 + atomic64_read_unchecked(&event->child_total_time_enabled);
66290 *running += event->total_time_running +
66291 - atomic64_read(&event->child_total_time_running);
66292 + atomic64_read_unchecked(&event->child_total_time_running);
66293
66294 list_for_each_entry(child, &event->child_list, child_list) {
66295 total += perf_event_read(child);
66296 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66297 userpg->offset -= local64_read(&event->hw.prev_count);
66298
66299 userpg->time_enabled = enabled +
66300 - atomic64_read(&event->child_total_time_enabled);
66301 + atomic64_read_unchecked(&event->child_total_time_enabled);
66302
66303 userpg->time_running = running +
66304 - atomic64_read(&event->child_total_time_running);
66305 + atomic64_read_unchecked(&event->child_total_time_running);
66306
66307 arch_perf_update_userpage(userpg, now);
66308
66309 @@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66310 values[n++] = perf_event_count(event);
66311 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66312 values[n++] = enabled +
66313 - atomic64_read(&event->child_total_time_enabled);
66314 + atomic64_read_unchecked(&event->child_total_time_enabled);
66315 }
66316 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66317 values[n++] = running +
66318 - atomic64_read(&event->child_total_time_running);
66319 + atomic64_read_unchecked(&event->child_total_time_running);
66320 }
66321 if (read_format & PERF_FORMAT_ID)
66322 values[n++] = primary_event_id(event);
66323 @@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66324 * need to add enough zero bytes after the string to handle
66325 * the 64bit alignment we do later.
66326 */
66327 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66328 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
66329 if (!buf) {
66330 name = strncpy(tmp, "//enomem", sizeof(tmp));
66331 goto got_name;
66332 }
66333 - name = d_path(&file->f_path, buf, PATH_MAX);
66334 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66335 if (IS_ERR(name)) {
66336 name = strncpy(tmp, "//toolong", sizeof(tmp));
66337 goto got_name;
66338 @@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66339 event->parent = parent_event;
66340
66341 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66342 - event->id = atomic64_inc_return(&perf_event_id);
66343 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
66344
66345 event->state = PERF_EVENT_STATE_INACTIVE;
66346
66347 @@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66348 /*
66349 * Add back the child's count to the parent's count:
66350 */
66351 - atomic64_add(child_val, &parent_event->child_count);
66352 - atomic64_add(child_event->total_time_enabled,
66353 + atomic64_add_unchecked(child_val, &parent_event->child_count);
66354 + atomic64_add_unchecked(child_event->total_time_enabled,
66355 &parent_event->child_total_time_enabled);
66356 - atomic64_add(child_event->total_time_running,
66357 + atomic64_add_unchecked(child_event->total_time_running,
66358 &parent_event->child_total_time_running);
66359
66360 /*
66361 diff --git a/kernel/exit.c b/kernel/exit.c
66362 index 2f59cc3..ce5b167 100644
66363 --- a/kernel/exit.c
66364 +++ b/kernel/exit.c
66365 @@ -59,6 +59,10 @@
66366 #include <asm/pgtable.h>
66367 #include <asm/mmu_context.h>
66368
66369 +#ifdef CONFIG_GRKERNSEC
66370 +extern rwlock_t grsec_exec_file_lock;
66371 +#endif
66372 +
66373 static void exit_mm(struct task_struct * tsk);
66374
66375 static void __unhash_process(struct task_struct *p, bool group_dead)
66376 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66377 struct task_struct *leader;
66378 int zap_leader;
66379 repeat:
66380 +#ifdef CONFIG_NET
66381 + gr_del_task_from_ip_table(p);
66382 +#endif
66383 +
66384 /* don't need to get the RCU readlock here - the process is dead and
66385 * can't be modifying its own credentials. But shut RCU-lockdep up */
66386 rcu_read_lock();
66387 @@ -394,7 +402,7 @@ int allow_signal(int sig)
66388 * know it'll be handled, so that they don't get converted to
66389 * SIGKILL or just silently dropped.
66390 */
66391 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66392 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66393 recalc_sigpending();
66394 spin_unlock_irq(&current->sighand->siglock);
66395 return 0;
66396 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66397 vsnprintf(current->comm, sizeof(current->comm), name, args);
66398 va_end(args);
66399
66400 +#ifdef CONFIG_GRKERNSEC
66401 + write_lock(&grsec_exec_file_lock);
66402 + if (current->exec_file) {
66403 + fput(current->exec_file);
66404 + current->exec_file = NULL;
66405 + }
66406 + write_unlock(&grsec_exec_file_lock);
66407 +#endif
66408 +
66409 + gr_set_kernel_label(current);
66410 +
66411 /*
66412 * If we were started as result of loading a module, close all of the
66413 * user space pages. We don't need them, and if we didn't close them
66414 @@ -907,6 +926,8 @@ void do_exit(long code)
66415 struct task_struct *tsk = current;
66416 int group_dead;
66417
66418 + set_fs(USER_DS);
66419 +
66420 profile_task_exit(tsk);
66421
66422 WARN_ON(blk_needs_flush_plug(tsk));
66423 @@ -923,7 +944,6 @@ void do_exit(long code)
66424 * mm_release()->clear_child_tid() from writing to a user-controlled
66425 * kernel address.
66426 */
66427 - set_fs(USER_DS);
66428
66429 ptrace_event(PTRACE_EVENT_EXIT, code);
66430
66431 @@ -985,6 +1005,9 @@ void do_exit(long code)
66432 tsk->exit_code = code;
66433 taskstats_exit(tsk, group_dead);
66434
66435 + gr_acl_handle_psacct(tsk, code);
66436 + gr_acl_handle_exit();
66437 +
66438 exit_mm(tsk);
66439
66440 if (group_dead)
66441 @@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66442 * Take down every thread in the group. This is called by fatal signals
66443 * as well as by sys_exit_group (below).
66444 */
66445 -void
66446 +__noreturn void
66447 do_group_exit(int exit_code)
66448 {
66449 struct signal_struct *sig = current->signal;
66450 diff --git a/kernel/fork.c b/kernel/fork.c
66451 index f00e319..c212fbc 100644
66452 --- a/kernel/fork.c
66453 +++ b/kernel/fork.c
66454 @@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66455 *stackend = STACK_END_MAGIC; /* for overflow detection */
66456
66457 #ifdef CONFIG_CC_STACKPROTECTOR
66458 - tsk->stack_canary = get_random_int();
66459 + tsk->stack_canary = pax_get_random_long();
66460 #endif
66461
66462 /*
66463 @@ -345,13 +345,78 @@ out:
66464 }
66465
66466 #ifdef CONFIG_MMU
66467 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66468 +{
66469 + struct vm_area_struct *tmp;
66470 + unsigned long charge;
66471 + struct mempolicy *pol;
66472 + struct file *file;
66473 +
66474 + charge = 0;
66475 + if (mpnt->vm_flags & VM_ACCOUNT) {
66476 + unsigned long len;
66477 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66478 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66479 + goto fail_nomem;
66480 + charge = len;
66481 + }
66482 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66483 + if (!tmp)
66484 + goto fail_nomem;
66485 + *tmp = *mpnt;
66486 + tmp->vm_mm = mm;
66487 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66488 + pol = mpol_dup(vma_policy(mpnt));
66489 + if (IS_ERR(pol))
66490 + goto fail_nomem_policy;
66491 + vma_set_policy(tmp, pol);
66492 + if (anon_vma_fork(tmp, mpnt))
66493 + goto fail_nomem_anon_vma_fork;
66494 + tmp->vm_flags &= ~VM_LOCKED;
66495 + tmp->vm_next = tmp->vm_prev = NULL;
66496 + tmp->vm_mirror = NULL;
66497 + file = tmp->vm_file;
66498 + if (file) {
66499 + struct inode *inode = file->f_path.dentry->d_inode;
66500 + struct address_space *mapping = file->f_mapping;
66501 +
66502 + get_file(file);
66503 + if (tmp->vm_flags & VM_DENYWRITE)
66504 + atomic_dec(&inode->i_writecount);
66505 + mutex_lock(&mapping->i_mmap_mutex);
66506 + if (tmp->vm_flags & VM_SHARED)
66507 + mapping->i_mmap_writable++;
66508 + flush_dcache_mmap_lock(mapping);
66509 + /* insert tmp into the share list, just after mpnt */
66510 + vma_prio_tree_add(tmp, mpnt);
66511 + flush_dcache_mmap_unlock(mapping);
66512 + mutex_unlock(&mapping->i_mmap_mutex);
66513 + }
66514 +
66515 + /*
66516 + * Clear hugetlb-related page reserves for children. This only
66517 + * affects MAP_PRIVATE mappings. Faults generated by the child
66518 + * are not guaranteed to succeed, even if read-only
66519 + */
66520 + if (is_vm_hugetlb_page(tmp))
66521 + reset_vma_resv_huge_pages(tmp);
66522 +
66523 + return tmp;
66524 +
66525 +fail_nomem_anon_vma_fork:
66526 + mpol_put(pol);
66527 +fail_nomem_policy:
66528 + kmem_cache_free(vm_area_cachep, tmp);
66529 +fail_nomem:
66530 + vm_unacct_memory(charge);
66531 + return NULL;
66532 +}
66533 +
66534 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66535 {
66536 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66537 struct rb_node **rb_link, *rb_parent;
66538 int retval;
66539 - unsigned long charge;
66540 - struct mempolicy *pol;
66541
66542 down_write(&oldmm->mmap_sem);
66543 flush_cache_dup_mm(oldmm);
66544 @@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66545 mm->locked_vm = 0;
66546 mm->mmap = NULL;
66547 mm->mmap_cache = NULL;
66548 - mm->free_area_cache = oldmm->mmap_base;
66549 - mm->cached_hole_size = ~0UL;
66550 + mm->free_area_cache = oldmm->free_area_cache;
66551 + mm->cached_hole_size = oldmm->cached_hole_size;
66552 mm->map_count = 0;
66553 cpumask_clear(mm_cpumask(mm));
66554 mm->mm_rb = RB_ROOT;
66555 @@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66556
66557 prev = NULL;
66558 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66559 - struct file *file;
66560 -
66561 if (mpnt->vm_flags & VM_DONTCOPY) {
66562 long pages = vma_pages(mpnt);
66563 mm->total_vm -= pages;
66564 @@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66565 -pages);
66566 continue;
66567 }
66568 - charge = 0;
66569 - if (mpnt->vm_flags & VM_ACCOUNT) {
66570 - unsigned long len;
66571 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66572 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66573 - goto fail_nomem;
66574 - charge = len;
66575 + tmp = dup_vma(mm, oldmm, mpnt);
66576 + if (!tmp) {
66577 + retval = -ENOMEM;
66578 + goto out;
66579 }
66580 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66581 - if (!tmp)
66582 - goto fail_nomem;
66583 - *tmp = *mpnt;
66584 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66585 - pol = mpol_dup(vma_policy(mpnt));
66586 - retval = PTR_ERR(pol);
66587 - if (IS_ERR(pol))
66588 - goto fail_nomem_policy;
66589 - vma_set_policy(tmp, pol);
66590 - tmp->vm_mm = mm;
66591 - if (anon_vma_fork(tmp, mpnt))
66592 - goto fail_nomem_anon_vma_fork;
66593 - tmp->vm_flags &= ~VM_LOCKED;
66594 - tmp->vm_next = tmp->vm_prev = NULL;
66595 - file = tmp->vm_file;
66596 - if (file) {
66597 - struct inode *inode = file->f_path.dentry->d_inode;
66598 - struct address_space *mapping = file->f_mapping;
66599 -
66600 - get_file(file);
66601 - if (tmp->vm_flags & VM_DENYWRITE)
66602 - atomic_dec(&inode->i_writecount);
66603 - mutex_lock(&mapping->i_mmap_mutex);
66604 - if (tmp->vm_flags & VM_SHARED)
66605 - mapping->i_mmap_writable++;
66606 - flush_dcache_mmap_lock(mapping);
66607 - /* insert tmp into the share list, just after mpnt */
66608 - vma_prio_tree_add(tmp, mpnt);
66609 - flush_dcache_mmap_unlock(mapping);
66610 - mutex_unlock(&mapping->i_mmap_mutex);
66611 - }
66612 -
66613 - /*
66614 - * Clear hugetlb-related page reserves for children. This only
66615 - * affects MAP_PRIVATE mappings. Faults generated by the child
66616 - * are not guaranteed to succeed, even if read-only
66617 - */
66618 - if (is_vm_hugetlb_page(tmp))
66619 - reset_vma_resv_huge_pages(tmp);
66620
66621 /*
66622 * Link in the new vma and copy the page table entries.
66623 @@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66624 if (retval)
66625 goto out;
66626
66627 - if (file && uprobe_mmap(tmp))
66628 + if (tmp->vm_file && uprobe_mmap(tmp))
66629 goto out;
66630 }
66631 +
66632 +#ifdef CONFIG_PAX_SEGMEXEC
66633 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66634 + struct vm_area_struct *mpnt_m;
66635 +
66636 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66637 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66638 +
66639 + if (!mpnt->vm_mirror)
66640 + continue;
66641 +
66642 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66643 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66644 + mpnt->vm_mirror = mpnt_m;
66645 + } else {
66646 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66647 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66648 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66649 + mpnt->vm_mirror->vm_mirror = mpnt;
66650 + }
66651 + }
66652 + BUG_ON(mpnt_m);
66653 + }
66654 +#endif
66655 +
66656 /* a new mm has just been created */
66657 arch_dup_mmap(oldmm, mm);
66658 retval = 0;
66659 @@ -470,14 +515,6 @@ out:
66660 flush_tlb_mm(oldmm);
66661 up_write(&oldmm->mmap_sem);
66662 return retval;
66663 -fail_nomem_anon_vma_fork:
66664 - mpol_put(pol);
66665 -fail_nomem_policy:
66666 - kmem_cache_free(vm_area_cachep, tmp);
66667 -fail_nomem:
66668 - retval = -ENOMEM;
66669 - vm_unacct_memory(charge);
66670 - goto out;
66671 }
66672
66673 static inline int mm_alloc_pgd(struct mm_struct *mm)
66674 @@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66675 return ERR_PTR(err);
66676
66677 mm = get_task_mm(task);
66678 - if (mm && mm != current->mm &&
66679 - !ptrace_may_access(task, mode)) {
66680 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66681 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66682 mmput(mm);
66683 mm = ERR_PTR(-EACCES);
66684 }
66685 @@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66686 spin_unlock(&fs->lock);
66687 return -EAGAIN;
66688 }
66689 - fs->users++;
66690 + atomic_inc(&fs->users);
66691 spin_unlock(&fs->lock);
66692 return 0;
66693 }
66694 tsk->fs = copy_fs_struct(fs);
66695 if (!tsk->fs)
66696 return -ENOMEM;
66697 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66698 return 0;
66699 }
66700
66701 @@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66702 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66703 #endif
66704 retval = -EAGAIN;
66705 +
66706 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66707 +
66708 if (atomic_read(&p->real_cred->user->processes) >=
66709 task_rlimit(p, RLIMIT_NPROC)) {
66710 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66711 @@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66712 /* Need tasklist lock for parent etc handling! */
66713 write_lock_irq(&tasklist_lock);
66714
66715 + /* synchronizes with gr_set_acls() */
66716 + gr_copy_label(p);
66717 +
66718 /* CLONE_PARENT re-uses the old parent */
66719 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66720 p->real_parent = current->real_parent;
66721 @@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66722 bad_fork_free:
66723 free_task(p);
66724 fork_out:
66725 + gr_log_forkfail(retval);
66726 +
66727 return ERR_PTR(retval);
66728 }
66729
66730 @@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66731 if (clone_flags & CLONE_PARENT_SETTID)
66732 put_user(nr, parent_tidptr);
66733
66734 + gr_handle_brute_check();
66735 +
66736 if (clone_flags & CLONE_VFORK) {
66737 p->vfork_done = &vfork;
66738 init_completion(&vfork);
66739 @@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66740 return 0;
66741
66742 /* don't need lock here; in the worst case we'll do useless copy */
66743 - if (fs->users == 1)
66744 + if (atomic_read(&fs->users) == 1)
66745 return 0;
66746
66747 *new_fsp = copy_fs_struct(fs);
66748 @@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66749 fs = current->fs;
66750 spin_lock(&fs->lock);
66751 current->fs = new_fs;
66752 - if (--fs->users)
66753 + gr_set_chroot_entries(current, &current->fs->root);
66754 + if (atomic_dec_return(&fs->users))
66755 new_fs = NULL;
66756 else
66757 new_fs = fs;
66758 diff --git a/kernel/futex.c b/kernel/futex.c
66759 index e2b0fb9..ced552c 100644
66760 --- a/kernel/futex.c
66761 +++ b/kernel/futex.c
66762 @@ -54,6 +54,7 @@
66763 #include <linux/mount.h>
66764 #include <linux/pagemap.h>
66765 #include <linux/syscalls.h>
66766 +#include <linux/ptrace.h>
66767 #include <linux/signal.h>
66768 #include <linux/export.h>
66769 #include <linux/magic.h>
66770 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66771 struct page *page, *page_head;
66772 int err, ro = 0;
66773
66774 +#ifdef CONFIG_PAX_SEGMEXEC
66775 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66776 + return -EFAULT;
66777 +#endif
66778 +
66779 /*
66780 * The futex address must be "naturally" aligned.
66781 */
66782 @@ -2231,11 +2237,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
66783 * @uaddr2: the pi futex we will take prior to returning to user-space
66784 *
66785 * The caller will wait on uaddr and will be requeued by futex_requeue() to
66786 - * uaddr2 which must be PI aware. Normal wakeup will wake on uaddr2 and
66787 - * complete the acquisition of the rt_mutex prior to returning to userspace.
66788 - * This ensures the rt_mutex maintains an owner when it has waiters; without
66789 - * one, the pi logic wouldn't know which task to boost/deboost, if there was a
66790 - * need to.
66791 + * uaddr2 which must be PI aware and unique from uaddr. Normal wakeup will wake
66792 + * on uaddr2 and complete the acquisition of the rt_mutex prior to returning to
66793 + * userspace. This ensures the rt_mutex maintains an owner when it has waiters;
66794 + * without one, the pi logic would not know which task to boost/deboost, if
66795 + * there was a need to.
66796 *
66797 * We call schedule in futex_wait_queue_me() when we enqueue and return there
66798 * via the following:
66799 @@ -2272,6 +2278,9 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66800 struct futex_q q = futex_q_init;
66801 int res, ret;
66802
66803 + if (uaddr == uaddr2)
66804 + return -EINVAL;
66805 +
66806 if (!bitset)
66807 return -EINVAL;
66808
66809 @@ -2370,7 +2379,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66810 * fault, unlock the rt_mutex and return the fault to userspace.
66811 */
66812 if (ret == -EFAULT) {
66813 - if (rt_mutex_owner(pi_mutex) == current)
66814 + if (pi_mutex && rt_mutex_owner(pi_mutex) == current)
66815 rt_mutex_unlock(pi_mutex);
66816 } else if (ret == -EINTR) {
66817 /*
66818 @@ -2711,6 +2720,7 @@ static int __init futex_init(void)
66819 {
66820 u32 curval;
66821 int i;
66822 + mm_segment_t oldfs;
66823
66824 /*
66825 * This will fail and we want it. Some arch implementations do
66826 @@ -2722,8 +2732,11 @@ static int __init futex_init(void)
66827 * implementation, the non-functional ones will return
66828 * -ENOSYS.
66829 */
66830 + oldfs = get_fs();
66831 + set_fs(USER_DS);
66832 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66833 futex_cmpxchg_enabled = 1;
66834 + set_fs(oldfs);
66835
66836 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66837 plist_head_init(&futex_queues[i].chain);
66838 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66839 index 9b22d03..6295b62 100644
66840 --- a/kernel/gcov/base.c
66841 +++ b/kernel/gcov/base.c
66842 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66843 }
66844
66845 #ifdef CONFIG_MODULES
66846 -static inline int within(void *addr, void *start, unsigned long size)
66847 -{
66848 - return ((addr >= start) && (addr < start + size));
66849 -}
66850 -
66851 /* Update list and generate events when modules are unloaded. */
66852 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66853 void *data)
66854 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66855 prev = NULL;
66856 /* Remove entries located in module from linked list. */
66857 for (info = gcov_info_head; info; info = info->next) {
66858 - if (within(info, mod->module_core, mod->core_size)) {
66859 + if (within_module_core_rw((unsigned long)info, mod)) {
66860 if (prev)
66861 prev->next = info->next;
66862 else
66863 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66864 index 6db7a5e..25b6648 100644
66865 --- a/kernel/hrtimer.c
66866 +++ b/kernel/hrtimer.c
66867 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66868 local_irq_restore(flags);
66869 }
66870
66871 -static void run_hrtimer_softirq(struct softirq_action *h)
66872 +static void run_hrtimer_softirq(void)
66873 {
66874 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66875
66876 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66877 index 4304919..408c4c0 100644
66878 --- a/kernel/jump_label.c
66879 +++ b/kernel/jump_label.c
66880 @@ -13,6 +13,7 @@
66881 #include <linux/sort.h>
66882 #include <linux/err.h>
66883 #include <linux/static_key.h>
66884 +#include <linux/mm.h>
66885
66886 #ifdef HAVE_JUMP_LABEL
66887
66888 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66889
66890 size = (((unsigned long)stop - (unsigned long)start)
66891 / sizeof(struct jump_entry));
66892 + pax_open_kernel();
66893 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66894 + pax_close_kernel();
66895 }
66896
66897 static void jump_label_update(struct static_key *key, int enable);
66898 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66899 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66900 struct jump_entry *iter;
66901
66902 + pax_open_kernel();
66903 for (iter = iter_start; iter < iter_stop; iter++) {
66904 if (within_module_init(iter->code, mod))
66905 iter->code = 0;
66906 }
66907 + pax_close_kernel();
66908 }
66909
66910 static int
66911 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66912 index 2169fee..45c017a 100644
66913 --- a/kernel/kallsyms.c
66914 +++ b/kernel/kallsyms.c
66915 @@ -11,6 +11,9 @@
66916 * Changed the compression method from stem compression to "table lookup"
66917 * compression (see scripts/kallsyms.c for a more complete description)
66918 */
66919 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66920 +#define __INCLUDED_BY_HIDESYM 1
66921 +#endif
66922 #include <linux/kallsyms.h>
66923 #include <linux/module.h>
66924 #include <linux/init.h>
66925 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66926
66927 static inline int is_kernel_inittext(unsigned long addr)
66928 {
66929 + if (system_state != SYSTEM_BOOTING)
66930 + return 0;
66931 +
66932 if (addr >= (unsigned long)_sinittext
66933 && addr <= (unsigned long)_einittext)
66934 return 1;
66935 return 0;
66936 }
66937
66938 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66939 +#ifdef CONFIG_MODULES
66940 +static inline int is_module_text(unsigned long addr)
66941 +{
66942 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66943 + return 1;
66944 +
66945 + addr = ktla_ktva(addr);
66946 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66947 +}
66948 +#else
66949 +static inline int is_module_text(unsigned long addr)
66950 +{
66951 + return 0;
66952 +}
66953 +#endif
66954 +#endif
66955 +
66956 static inline int is_kernel_text(unsigned long addr)
66957 {
66958 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66959 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66960
66961 static inline int is_kernel(unsigned long addr)
66962 {
66963 +
66964 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66965 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66966 + return 1;
66967 +
66968 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66969 +#else
66970 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66971 +#endif
66972 +
66973 return 1;
66974 return in_gate_area_no_mm(addr);
66975 }
66976
66977 static int is_ksym_addr(unsigned long addr)
66978 {
66979 +
66980 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66981 + if (is_module_text(addr))
66982 + return 0;
66983 +#endif
66984 +
66985 if (all_var)
66986 return is_kernel(addr);
66987
66988 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66989
66990 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66991 {
66992 - iter->name[0] = '\0';
66993 iter->nameoff = get_symbol_offset(new_pos);
66994 iter->pos = new_pos;
66995 }
66996 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
66997 {
66998 struct kallsym_iter *iter = m->private;
66999
67000 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67001 + if (current_uid())
67002 + return 0;
67003 +#endif
67004 +
67005 /* Some debugging symbols have no name. Ignore them. */
67006 if (!iter->name[0])
67007 return 0;
67008 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67009 */
67010 type = iter->exported ? toupper(iter->type) :
67011 tolower(iter->type);
67012 +
67013 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67014 type, iter->name, iter->module_name);
67015 } else
67016 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67017 struct kallsym_iter *iter;
67018 int ret;
67019
67020 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67021 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67022 if (!iter)
67023 return -ENOMEM;
67024 reset_iter(iter, 0);
67025 diff --git a/kernel/kexec.c b/kernel/kexec.c
67026 index 4e2e472..cd0c7ae 100644
67027 --- a/kernel/kexec.c
67028 +++ b/kernel/kexec.c
67029 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67030 unsigned long flags)
67031 {
67032 struct compat_kexec_segment in;
67033 - struct kexec_segment out, __user *ksegments;
67034 + struct kexec_segment out;
67035 + struct kexec_segment __user *ksegments;
67036 unsigned long i, result;
67037
67038 /* Don't allow clients that don't understand the native
67039 diff --git a/kernel/kmod.c b/kernel/kmod.c
67040 index ff2c7cb..085d7af 100644
67041 --- a/kernel/kmod.c
67042 +++ b/kernel/kmod.c
67043 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67044 kfree(info->argv);
67045 }
67046
67047 -static int call_modprobe(char *module_name, int wait)
67048 +static int call_modprobe(char *module_name, char *module_param, int wait)
67049 {
67050 static char *envp[] = {
67051 "HOME=/",
67052 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67053 NULL
67054 };
67055
67056 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67057 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67058 if (!argv)
67059 goto out;
67060
67061 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67062 argv[1] = "-q";
67063 argv[2] = "--";
67064 argv[3] = module_name; /* check free_modprobe_argv() */
67065 - argv[4] = NULL;
67066 + argv[4] = module_param;
67067 + argv[5] = NULL;
67068
67069 return call_usermodehelper_fns(modprobe_path, argv, envp,
67070 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67071 @@ -112,9 +113,8 @@ out:
67072 * If module auto-loading support is disabled then this function
67073 * becomes a no-operation.
67074 */
67075 -int __request_module(bool wait, const char *fmt, ...)
67076 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67077 {
67078 - va_list args;
67079 char module_name[MODULE_NAME_LEN];
67080 unsigned int max_modprobes;
67081 int ret;
67082 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67083 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67084 static int kmod_loop_msg;
67085
67086 - va_start(args, fmt);
67087 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67088 - va_end(args);
67089 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67090 if (ret >= MODULE_NAME_LEN)
67091 return -ENAMETOOLONG;
67092
67093 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67094 if (ret)
67095 return ret;
67096
67097 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67098 + if (!current_uid()) {
67099 + /* hack to workaround consolekit/udisks stupidity */
67100 + read_lock(&tasklist_lock);
67101 + if (!strcmp(current->comm, "mount") &&
67102 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67103 + read_unlock(&tasklist_lock);
67104 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67105 + return -EPERM;
67106 + }
67107 + read_unlock(&tasklist_lock);
67108 + }
67109 +#endif
67110 +
67111 /* If modprobe needs a service that is in a module, we get a recursive
67112 * loop. Limit the number of running kmod threads to max_threads/2 or
67113 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67114 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67115
67116 trace_module_request(module_name, wait, _RET_IP_);
67117
67118 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67119 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67120
67121 atomic_dec(&kmod_concurrent);
67122 return ret;
67123 }
67124 +
67125 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67126 +{
67127 + va_list args;
67128 + int ret;
67129 +
67130 + va_start(args, fmt);
67131 + ret = ____request_module(wait, module_param, fmt, args);
67132 + va_end(args);
67133 +
67134 + return ret;
67135 +}
67136 +
67137 +int __request_module(bool wait, const char *fmt, ...)
67138 +{
67139 + va_list args;
67140 + int ret;
67141 +
67142 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67143 + if (current_uid()) {
67144 + char module_param[MODULE_NAME_LEN];
67145 +
67146 + memset(module_param, 0, sizeof(module_param));
67147 +
67148 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67149 +
67150 + va_start(args, fmt);
67151 + ret = ____request_module(wait, module_param, fmt, args);
67152 + va_end(args);
67153 +
67154 + return ret;
67155 + }
67156 +#endif
67157 +
67158 + va_start(args, fmt);
67159 + ret = ____request_module(wait, NULL, fmt, args);
67160 + va_end(args);
67161 +
67162 + return ret;
67163 +}
67164 +
67165 EXPORT_SYMBOL(__request_module);
67166 #endif /* CONFIG_MODULES */
67167
67168 @@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67169 *
67170 * Thus the __user pointer cast is valid here.
67171 */
67172 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67173 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67174
67175 /*
67176 * If ret is 0, either ____call_usermodehelper failed and the
67177 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67178 index c62b854..cb67968 100644
67179 --- a/kernel/kprobes.c
67180 +++ b/kernel/kprobes.c
67181 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67182 * kernel image and loaded module images reside. This is required
67183 * so x86_64 can correctly handle the %rip-relative fixups.
67184 */
67185 - kip->insns = module_alloc(PAGE_SIZE);
67186 + kip->insns = module_alloc_exec(PAGE_SIZE);
67187 if (!kip->insns) {
67188 kfree(kip);
67189 return NULL;
67190 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67191 */
67192 if (!list_is_singular(&kip->list)) {
67193 list_del(&kip->list);
67194 - module_free(NULL, kip->insns);
67195 + module_free_exec(NULL, kip->insns);
67196 kfree(kip);
67197 }
67198 return 1;
67199 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67200 {
67201 int i, err = 0;
67202 unsigned long offset = 0, size = 0;
67203 - char *modname, namebuf[128];
67204 + char *modname, namebuf[KSYM_NAME_LEN];
67205 const char *symbol_name;
67206 void *addr;
67207 struct kprobe_blackpoint *kb;
67208 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67209 const char *sym = NULL;
67210 unsigned int i = *(loff_t *) v;
67211 unsigned long offset = 0;
67212 - char *modname, namebuf[128];
67213 + char *modname, namebuf[KSYM_NAME_LEN];
67214
67215 head = &kprobe_table[i];
67216 preempt_disable();
67217 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67218 index 4e316e1..5501eef 100644
67219 --- a/kernel/ksysfs.c
67220 +++ b/kernel/ksysfs.c
67221 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67222 {
67223 if (count+1 > UEVENT_HELPER_PATH_LEN)
67224 return -ENOENT;
67225 + if (!capable(CAP_SYS_ADMIN))
67226 + return -EPERM;
67227 memcpy(uevent_helper, buf, count);
67228 uevent_helper[count] = '\0';
67229 if (count && uevent_helper[count-1] == '\n')
67230 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67231 index ea9ee45..67ebc8f 100644
67232 --- a/kernel/lockdep.c
67233 +++ b/kernel/lockdep.c
67234 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67235 end = (unsigned long) &_end,
67236 addr = (unsigned long) obj;
67237
67238 +#ifdef CONFIG_PAX_KERNEXEC
67239 + start = ktla_ktva(start);
67240 +#endif
67241 +
67242 /*
67243 * static variable?
67244 */
67245 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67246 if (!static_obj(lock->key)) {
67247 debug_locks_off();
67248 printk("INFO: trying to register non-static key.\n");
67249 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67250 printk("the code is fine but needs lockdep annotation.\n");
67251 printk("turning off the locking correctness validator.\n");
67252 dump_stack();
67253 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67254 if (!class)
67255 return 0;
67256 }
67257 - atomic_inc((atomic_t *)&class->ops);
67258 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67259 if (very_verbose(class)) {
67260 printk("\nacquire class [%p] %s", class->key, class->name);
67261 if (class->name_version > 1)
67262 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67263 index 91c32a0..b2c71c5 100644
67264 --- a/kernel/lockdep_proc.c
67265 +++ b/kernel/lockdep_proc.c
67266 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67267
67268 static void print_name(struct seq_file *m, struct lock_class *class)
67269 {
67270 - char str[128];
67271 + char str[KSYM_NAME_LEN];
67272 const char *name = class->name;
67273
67274 if (!name) {
67275 diff --git a/kernel/module.c b/kernel/module.c
67276 index 4edbd9c..165e780 100644
67277 --- a/kernel/module.c
67278 +++ b/kernel/module.c
67279 @@ -58,6 +58,7 @@
67280 #include <linux/jump_label.h>
67281 #include <linux/pfn.h>
67282 #include <linux/bsearch.h>
67283 +#include <linux/grsecurity.h>
67284
67285 #define CREATE_TRACE_POINTS
67286 #include <trace/events/module.h>
67287 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67288
67289 /* Bounds of module allocation, for speeding __module_address.
67290 * Protected by module_mutex. */
67291 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67292 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67293 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67294
67295 int register_module_notifier(struct notifier_block * nb)
67296 {
67297 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67298 return true;
67299
67300 list_for_each_entry_rcu(mod, &modules, list) {
67301 - struct symsearch arr[] = {
67302 + struct symsearch modarr[] = {
67303 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67304 NOT_GPL_ONLY, false },
67305 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67306 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67307 #endif
67308 };
67309
67310 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67311 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67312 return true;
67313 }
67314 return false;
67315 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67316 static int percpu_modalloc(struct module *mod,
67317 unsigned long size, unsigned long align)
67318 {
67319 - if (align > PAGE_SIZE) {
67320 + if (align-1 >= PAGE_SIZE) {
67321 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67322 mod->name, align, PAGE_SIZE);
67323 align = PAGE_SIZE;
67324 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67325 static ssize_t show_coresize(struct module_attribute *mattr,
67326 struct module_kobject *mk, char *buffer)
67327 {
67328 - return sprintf(buffer, "%u\n", mk->mod->core_size);
67329 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67330 }
67331
67332 static struct module_attribute modinfo_coresize =
67333 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67334 static ssize_t show_initsize(struct module_attribute *mattr,
67335 struct module_kobject *mk, char *buffer)
67336 {
67337 - return sprintf(buffer, "%u\n", mk->mod->init_size);
67338 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67339 }
67340
67341 static struct module_attribute modinfo_initsize =
67342 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67343 */
67344 #ifdef CONFIG_SYSFS
67345
67346 -#ifdef CONFIG_KALLSYMS
67347 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67348 static inline bool sect_empty(const Elf_Shdr *sect)
67349 {
67350 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67351 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67352
67353 static void unset_module_core_ro_nx(struct module *mod)
67354 {
67355 - set_page_attributes(mod->module_core + mod->core_text_size,
67356 - mod->module_core + mod->core_size,
67357 + set_page_attributes(mod->module_core_rw,
67358 + mod->module_core_rw + mod->core_size_rw,
67359 set_memory_x);
67360 - set_page_attributes(mod->module_core,
67361 - mod->module_core + mod->core_ro_size,
67362 + set_page_attributes(mod->module_core_rx,
67363 + mod->module_core_rx + mod->core_size_rx,
67364 set_memory_rw);
67365 }
67366
67367 static void unset_module_init_ro_nx(struct module *mod)
67368 {
67369 - set_page_attributes(mod->module_init + mod->init_text_size,
67370 - mod->module_init + mod->init_size,
67371 + set_page_attributes(mod->module_init_rw,
67372 + mod->module_init_rw + mod->init_size_rw,
67373 set_memory_x);
67374 - set_page_attributes(mod->module_init,
67375 - mod->module_init + mod->init_ro_size,
67376 + set_page_attributes(mod->module_init_rx,
67377 + mod->module_init_rx + mod->init_size_rx,
67378 set_memory_rw);
67379 }
67380
67381 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67382
67383 mutex_lock(&module_mutex);
67384 list_for_each_entry_rcu(mod, &modules, list) {
67385 - if ((mod->module_core) && (mod->core_text_size)) {
67386 - set_page_attributes(mod->module_core,
67387 - mod->module_core + mod->core_text_size,
67388 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67389 + set_page_attributes(mod->module_core_rx,
67390 + mod->module_core_rx + mod->core_size_rx,
67391 set_memory_rw);
67392 }
67393 - if ((mod->module_init) && (mod->init_text_size)) {
67394 - set_page_attributes(mod->module_init,
67395 - mod->module_init + mod->init_text_size,
67396 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67397 + set_page_attributes(mod->module_init_rx,
67398 + mod->module_init_rx + mod->init_size_rx,
67399 set_memory_rw);
67400 }
67401 }
67402 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67403
67404 mutex_lock(&module_mutex);
67405 list_for_each_entry_rcu(mod, &modules, list) {
67406 - if ((mod->module_core) && (mod->core_text_size)) {
67407 - set_page_attributes(mod->module_core,
67408 - mod->module_core + mod->core_text_size,
67409 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
67410 + set_page_attributes(mod->module_core_rx,
67411 + mod->module_core_rx + mod->core_size_rx,
67412 set_memory_ro);
67413 }
67414 - if ((mod->module_init) && (mod->init_text_size)) {
67415 - set_page_attributes(mod->module_init,
67416 - mod->module_init + mod->init_text_size,
67417 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
67418 + set_page_attributes(mod->module_init_rx,
67419 + mod->module_init_rx + mod->init_size_rx,
67420 set_memory_ro);
67421 }
67422 }
67423 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67424
67425 /* This may be NULL, but that's OK */
67426 unset_module_init_ro_nx(mod);
67427 - module_free(mod, mod->module_init);
67428 + module_free(mod, mod->module_init_rw);
67429 + module_free_exec(mod, mod->module_init_rx);
67430 kfree(mod->args);
67431 percpu_modfree(mod);
67432
67433 /* Free lock-classes: */
67434 - lockdep_free_key_range(mod->module_core, mod->core_size);
67435 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67436 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67437
67438 /* Finally, free the core (containing the module structure) */
67439 unset_module_core_ro_nx(mod);
67440 - module_free(mod, mod->module_core);
67441 + module_free_exec(mod, mod->module_core_rx);
67442 + module_free(mod, mod->module_core_rw);
67443
67444 #ifdef CONFIG_MPU
67445 update_protections(current->mm);
67446 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67447 int ret = 0;
67448 const struct kernel_symbol *ksym;
67449
67450 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67451 + int is_fs_load = 0;
67452 + int register_filesystem_found = 0;
67453 + char *p;
67454 +
67455 + p = strstr(mod->args, "grsec_modharden_fs");
67456 + if (p) {
67457 + char *endptr = p + strlen("grsec_modharden_fs");
67458 + /* copy \0 as well */
67459 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67460 + is_fs_load = 1;
67461 + }
67462 +#endif
67463 +
67464 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67465 const char *name = info->strtab + sym[i].st_name;
67466
67467 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67468 + /* it's a real shame this will never get ripped and copied
67469 + upstream! ;(
67470 + */
67471 + if (is_fs_load && !strcmp(name, "register_filesystem"))
67472 + register_filesystem_found = 1;
67473 +#endif
67474 +
67475 switch (sym[i].st_shndx) {
67476 case SHN_COMMON:
67477 /* We compiled with -fno-common. These are not
67478 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67479 ksym = resolve_symbol_wait(mod, info, name);
67480 /* Ok if resolved. */
67481 if (ksym && !IS_ERR(ksym)) {
67482 + pax_open_kernel();
67483 sym[i].st_value = ksym->value;
67484 + pax_close_kernel();
67485 break;
67486 }
67487
67488 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67489 secbase = (unsigned long)mod_percpu(mod);
67490 else
67491 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67492 + pax_open_kernel();
67493 sym[i].st_value += secbase;
67494 + pax_close_kernel();
67495 break;
67496 }
67497 }
67498
67499 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67500 + if (is_fs_load && !register_filesystem_found) {
67501 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67502 + ret = -EPERM;
67503 + }
67504 +#endif
67505 +
67506 return ret;
67507 }
67508
67509 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67510 || s->sh_entsize != ~0UL
67511 || strstarts(sname, ".init"))
67512 continue;
67513 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67514 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67515 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67516 + else
67517 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67518 pr_debug("\t%s\n", sname);
67519 }
67520 - switch (m) {
67521 - case 0: /* executable */
67522 - mod->core_size = debug_align(mod->core_size);
67523 - mod->core_text_size = mod->core_size;
67524 - break;
67525 - case 1: /* RO: text and ro-data */
67526 - mod->core_size = debug_align(mod->core_size);
67527 - mod->core_ro_size = mod->core_size;
67528 - break;
67529 - case 3: /* whole core */
67530 - mod->core_size = debug_align(mod->core_size);
67531 - break;
67532 - }
67533 }
67534
67535 pr_debug("Init section allocation order:\n");
67536 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67537 || s->sh_entsize != ~0UL
67538 || !strstarts(sname, ".init"))
67539 continue;
67540 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67541 - | INIT_OFFSET_MASK);
67542 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67543 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67544 + else
67545 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67546 + s->sh_entsize |= INIT_OFFSET_MASK;
67547 pr_debug("\t%s\n", sname);
67548 }
67549 - switch (m) {
67550 - case 0: /* executable */
67551 - mod->init_size = debug_align(mod->init_size);
67552 - mod->init_text_size = mod->init_size;
67553 - break;
67554 - case 1: /* RO: text and ro-data */
67555 - mod->init_size = debug_align(mod->init_size);
67556 - mod->init_ro_size = mod->init_size;
67557 - break;
67558 - case 3: /* whole init */
67559 - mod->init_size = debug_align(mod->init_size);
67560 - break;
67561 - }
67562 }
67563 }
67564
67565 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67566
67567 /* Put symbol section at end of init part of module. */
67568 symsect->sh_flags |= SHF_ALLOC;
67569 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67570 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67571 info->index.sym) | INIT_OFFSET_MASK;
67572 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67573
67574 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67575 }
67576
67577 /* Append room for core symbols at end of core part. */
67578 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67579 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67580 - mod->core_size += strtab_size;
67581 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67582 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67583 + mod->core_size_rx += strtab_size;
67584
67585 /* Put string table section at end of init part of module. */
67586 strsect->sh_flags |= SHF_ALLOC;
67587 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67588 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67589 info->index.str) | INIT_OFFSET_MASK;
67590 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67591 }
67592 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67593 /* Make sure we get permanent strtab: don't use info->strtab. */
67594 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67595
67596 + pax_open_kernel();
67597 +
67598 /* Set types up while we still have access to sections. */
67599 for (i = 0; i < mod->num_symtab; i++)
67600 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67601
67602 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67603 - mod->core_strtab = s = mod->module_core + info->stroffs;
67604 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67605 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67606 src = mod->symtab;
67607 *dst = *src;
67608 *s++ = 0;
67609 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67610 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67611 }
67612 mod->core_num_syms = ndst;
67613 +
67614 + pax_close_kernel();
67615 }
67616 #else
67617 static inline void layout_symtab(struct module *mod, struct load_info *info)
67618 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67619 return size == 0 ? NULL : vmalloc_exec(size);
67620 }
67621
67622 -static void *module_alloc_update_bounds(unsigned long size)
67623 +static void *module_alloc_update_bounds_rw(unsigned long size)
67624 {
67625 void *ret = module_alloc(size);
67626
67627 if (ret) {
67628 mutex_lock(&module_mutex);
67629 /* Update module bounds. */
67630 - if ((unsigned long)ret < module_addr_min)
67631 - module_addr_min = (unsigned long)ret;
67632 - if ((unsigned long)ret + size > module_addr_max)
67633 - module_addr_max = (unsigned long)ret + size;
67634 + if ((unsigned long)ret < module_addr_min_rw)
67635 + module_addr_min_rw = (unsigned long)ret;
67636 + if ((unsigned long)ret + size > module_addr_max_rw)
67637 + module_addr_max_rw = (unsigned long)ret + size;
67638 + mutex_unlock(&module_mutex);
67639 + }
67640 + return ret;
67641 +}
67642 +
67643 +static void *module_alloc_update_bounds_rx(unsigned long size)
67644 +{
67645 + void *ret = module_alloc_exec(size);
67646 +
67647 + if (ret) {
67648 + mutex_lock(&module_mutex);
67649 + /* Update module bounds. */
67650 + if ((unsigned long)ret < module_addr_min_rx)
67651 + module_addr_min_rx = (unsigned long)ret;
67652 + if ((unsigned long)ret + size > module_addr_max_rx)
67653 + module_addr_max_rx = (unsigned long)ret + size;
67654 mutex_unlock(&module_mutex);
67655 }
67656 return ret;
67657 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67658 static int check_modinfo(struct module *mod, struct load_info *info)
67659 {
67660 const char *modmagic = get_modinfo(info, "vermagic");
67661 + const char *license = get_modinfo(info, "license");
67662 int err;
67663
67664 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67665 + if (!license || !license_is_gpl_compatible(license))
67666 + return -ENOEXEC;
67667 +#endif
67668 +
67669 /* This is allowed: modprobe --force will invalidate it. */
67670 if (!modmagic) {
67671 err = try_to_force_load(mod, "bad vermagic");
67672 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67673 }
67674
67675 /* Set up license info based on the info section */
67676 - set_license(mod, get_modinfo(info, "license"));
67677 + set_license(mod, license);
67678
67679 return 0;
67680 }
67681 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67682 void *ptr;
67683
67684 /* Do the allocs. */
67685 - ptr = module_alloc_update_bounds(mod->core_size);
67686 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67687 /*
67688 * The pointer to this block is stored in the module structure
67689 * which is inside the block. Just mark it as not being a
67690 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67691 if (!ptr)
67692 return -ENOMEM;
67693
67694 - memset(ptr, 0, mod->core_size);
67695 - mod->module_core = ptr;
67696 + memset(ptr, 0, mod->core_size_rw);
67697 + mod->module_core_rw = ptr;
67698
67699 - ptr = module_alloc_update_bounds(mod->init_size);
67700 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67701 /*
67702 * The pointer to this block is stored in the module structure
67703 * which is inside the block. This block doesn't need to be
67704 * scanned as it contains data and code that will be freed
67705 * after the module is initialized.
67706 */
67707 - kmemleak_ignore(ptr);
67708 - if (!ptr && mod->init_size) {
67709 - module_free(mod, mod->module_core);
67710 + kmemleak_not_leak(ptr);
67711 + if (!ptr && mod->init_size_rw) {
67712 + module_free(mod, mod->module_core_rw);
67713 return -ENOMEM;
67714 }
67715 - memset(ptr, 0, mod->init_size);
67716 - mod->module_init = ptr;
67717 + memset(ptr, 0, mod->init_size_rw);
67718 + mod->module_init_rw = ptr;
67719 +
67720 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67721 + kmemleak_not_leak(ptr);
67722 + if (!ptr) {
67723 + module_free(mod, mod->module_init_rw);
67724 + module_free(mod, mod->module_core_rw);
67725 + return -ENOMEM;
67726 + }
67727 +
67728 + pax_open_kernel();
67729 + memset(ptr, 0, mod->core_size_rx);
67730 + pax_close_kernel();
67731 + mod->module_core_rx = ptr;
67732 +
67733 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67734 + kmemleak_not_leak(ptr);
67735 + if (!ptr && mod->init_size_rx) {
67736 + module_free_exec(mod, mod->module_core_rx);
67737 + module_free(mod, mod->module_init_rw);
67738 + module_free(mod, mod->module_core_rw);
67739 + return -ENOMEM;
67740 + }
67741 +
67742 + pax_open_kernel();
67743 + memset(ptr, 0, mod->init_size_rx);
67744 + pax_close_kernel();
67745 + mod->module_init_rx = ptr;
67746
67747 /* Transfer each section which specifies SHF_ALLOC */
67748 pr_debug("final section addresses:\n");
67749 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67750 if (!(shdr->sh_flags & SHF_ALLOC))
67751 continue;
67752
67753 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67754 - dest = mod->module_init
67755 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67756 - else
67757 - dest = mod->module_core + shdr->sh_entsize;
67758 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67759 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67760 + dest = mod->module_init_rw
67761 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67762 + else
67763 + dest = mod->module_init_rx
67764 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67765 + } else {
67766 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67767 + dest = mod->module_core_rw + shdr->sh_entsize;
67768 + else
67769 + dest = mod->module_core_rx + shdr->sh_entsize;
67770 + }
67771 +
67772 + if (shdr->sh_type != SHT_NOBITS) {
67773 +
67774 +#ifdef CONFIG_PAX_KERNEXEC
67775 +#ifdef CONFIG_X86_64
67776 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67777 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67778 +#endif
67779 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67780 + pax_open_kernel();
67781 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67782 + pax_close_kernel();
67783 + } else
67784 +#endif
67785
67786 - if (shdr->sh_type != SHT_NOBITS)
67787 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67788 + }
67789 /* Update sh_addr to point to copy in image. */
67790 - shdr->sh_addr = (unsigned long)dest;
67791 +
67792 +#ifdef CONFIG_PAX_KERNEXEC
67793 + if (shdr->sh_flags & SHF_EXECINSTR)
67794 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67795 + else
67796 +#endif
67797 +
67798 + shdr->sh_addr = (unsigned long)dest;
67799 pr_debug("\t0x%lx %s\n",
67800 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67801 }
67802 @@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67803 * Do it before processing of module parameters, so the module
67804 * can provide parameter accessor functions of its own.
67805 */
67806 - if (mod->module_init)
67807 - flush_icache_range((unsigned long)mod->module_init,
67808 - (unsigned long)mod->module_init
67809 - + mod->init_size);
67810 - flush_icache_range((unsigned long)mod->module_core,
67811 - (unsigned long)mod->module_core + mod->core_size);
67812 + if (mod->module_init_rx)
67813 + flush_icache_range((unsigned long)mod->module_init_rx,
67814 + (unsigned long)mod->module_init_rx
67815 + + mod->init_size_rx);
67816 + flush_icache_range((unsigned long)mod->module_core_rx,
67817 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67818
67819 set_fs(old_fs);
67820 }
67821 @@ -2834,8 +2934,10 @@ out:
67822 static void module_deallocate(struct module *mod, struct load_info *info)
67823 {
67824 percpu_modfree(mod);
67825 - module_free(mod, mod->module_init);
67826 - module_free(mod, mod->module_core);
67827 + module_free_exec(mod, mod->module_init_rx);
67828 + module_free_exec(mod, mod->module_core_rx);
67829 + module_free(mod, mod->module_init_rw);
67830 + module_free(mod, mod->module_core_rw);
67831 }
67832
67833 int __weak module_finalize(const Elf_Ehdr *hdr,
67834 @@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
67835 static int post_relocation(struct module *mod, const struct load_info *info)
67836 {
67837 /* Sort exception table now relocations are done. */
67838 + pax_open_kernel();
67839 sort_extable(mod->extable, mod->extable + mod->num_exentries);
67840 + pax_close_kernel();
67841
67842 /* Copy relocated percpu area over. */
67843 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
67844 @@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
67845 if (err)
67846 goto free_unload;
67847
67848 + /* Now copy in args */
67849 + mod->args = strndup_user(uargs, ~0UL >> 1);
67850 + if (IS_ERR(mod->args)) {
67851 + err = PTR_ERR(mod->args);
67852 + goto free_unload;
67853 + }
67854 +
67855 /* Set up MODINFO_ATTR fields */
67856 setup_modinfo(mod, &info);
67857
67858 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67859 + {
67860 + char *p, *p2;
67861 +
67862 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67863 + 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);
67864 + err = -EPERM;
67865 + goto free_modinfo;
67866 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67867 + p += strlen("grsec_modharden_normal");
67868 + p2 = strstr(p, "_");
67869 + if (p2) {
67870 + *p2 = '\0';
67871 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67872 + *p2 = '_';
67873 + }
67874 + err = -EPERM;
67875 + goto free_modinfo;
67876 + }
67877 + }
67878 +#endif
67879 +
67880 /* Fix up syms, so that st_value is a pointer to location. */
67881 err = simplify_symbols(mod, &info);
67882 if (err < 0)
67883 @@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
67884
67885 flush_module_icache(mod);
67886
67887 - /* Now copy in args */
67888 - mod->args = strndup_user(uargs, ~0UL >> 1);
67889 - if (IS_ERR(mod->args)) {
67890 - err = PTR_ERR(mod->args);
67891 - goto free_arch_cleanup;
67892 - }
67893 -
67894 /* Mark state as coming so strong_try_module_get() ignores us. */
67895 mod->state = MODULE_STATE_COMING;
67896
67897 @@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
67898 unlock:
67899 mutex_unlock(&module_mutex);
67900 synchronize_sched();
67901 - kfree(mod->args);
67902 - free_arch_cleanup:
67903 module_arch_cleanup(mod);
67904 free_modinfo:
67905 free_modinfo(mod);
67906 + kfree(mod->args);
67907 free_unload:
67908 module_unload_free(mod);
67909 free_module:
67910 @@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67911 MODULE_STATE_COMING, mod);
67912
67913 /* Set RO and NX regions for core */
67914 - set_section_ro_nx(mod->module_core,
67915 - mod->core_text_size,
67916 - mod->core_ro_size,
67917 - mod->core_size);
67918 + set_section_ro_nx(mod->module_core_rx,
67919 + mod->core_size_rx,
67920 + mod->core_size_rx,
67921 + mod->core_size_rx);
67922
67923 /* Set RO and NX regions for init */
67924 - set_section_ro_nx(mod->module_init,
67925 - mod->init_text_size,
67926 - mod->init_ro_size,
67927 - mod->init_size);
67928 + set_section_ro_nx(mod->module_init_rx,
67929 + mod->init_size_rx,
67930 + mod->init_size_rx,
67931 + mod->init_size_rx);
67932
67933 do_mod_ctors(mod);
67934 /* Start the module */
67935 @@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67936 mod->strtab = mod->core_strtab;
67937 #endif
67938 unset_module_init_ro_nx(mod);
67939 - module_free(mod, mod->module_init);
67940 - mod->module_init = NULL;
67941 - mod->init_size = 0;
67942 - mod->init_ro_size = 0;
67943 - mod->init_text_size = 0;
67944 + module_free(mod, mod->module_init_rw);
67945 + module_free_exec(mod, mod->module_init_rx);
67946 + mod->module_init_rw = NULL;
67947 + mod->module_init_rx = NULL;
67948 + mod->init_size_rw = 0;
67949 + mod->init_size_rx = 0;
67950 mutex_unlock(&module_mutex);
67951
67952 return 0;
67953 @@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
67954 unsigned long nextval;
67955
67956 /* At worse, next value is at end of module */
67957 - if (within_module_init(addr, mod))
67958 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67959 + if (within_module_init_rx(addr, mod))
67960 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67961 + else if (within_module_init_rw(addr, mod))
67962 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67963 + else if (within_module_core_rx(addr, mod))
67964 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67965 + else if (within_module_core_rw(addr, mod))
67966 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67967 else
67968 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67969 + return NULL;
67970
67971 /* Scan for closest preceding symbol, and next symbol. (ELF
67972 starts real symbols at 1). */
67973 @@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
67974 char buf[8];
67975
67976 seq_printf(m, "%s %u",
67977 - mod->name, mod->init_size + mod->core_size);
67978 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67979 print_unload_info(m, mod);
67980
67981 /* Informative for users. */
67982 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
67983 mod->state == MODULE_STATE_COMING ? "Loading":
67984 "Live");
67985 /* Used by oprofile and other similar tools. */
67986 - seq_printf(m, " 0x%pK", mod->module_core);
67987 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67988
67989 /* Taints info */
67990 if (mod->taints)
67991 @@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
67992
67993 static int __init proc_modules_init(void)
67994 {
67995 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67996 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67997 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67998 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67999 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68000 +#else
68001 proc_create("modules", 0, NULL, &proc_modules_operations);
68002 +#endif
68003 +#else
68004 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68005 +#endif
68006 return 0;
68007 }
68008 module_init(proc_modules_init);
68009 @@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68010 {
68011 struct module *mod;
68012
68013 - if (addr < module_addr_min || addr > module_addr_max)
68014 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68015 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68016 return NULL;
68017
68018 list_for_each_entry_rcu(mod, &modules, list)
68019 - if (within_module_core(addr, mod)
68020 - || within_module_init(addr, mod))
68021 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68022 return mod;
68023 return NULL;
68024 }
68025 @@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68026 */
68027 struct module *__module_text_address(unsigned long addr)
68028 {
68029 - struct module *mod = __module_address(addr);
68030 + struct module *mod;
68031 +
68032 +#ifdef CONFIG_X86_32
68033 + addr = ktla_ktva(addr);
68034 +#endif
68035 +
68036 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68037 + return NULL;
68038 +
68039 + mod = __module_address(addr);
68040 +
68041 if (mod) {
68042 /* Make sure it's within the text section. */
68043 - if (!within(addr, mod->module_init, mod->init_text_size)
68044 - && !within(addr, mod->module_core, mod->core_text_size))
68045 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68046 mod = NULL;
68047 }
68048 return mod;
68049 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68050 index 7e3443f..b2a1e6b 100644
68051 --- a/kernel/mutex-debug.c
68052 +++ b/kernel/mutex-debug.c
68053 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68054 }
68055
68056 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68057 - struct thread_info *ti)
68058 + struct task_struct *task)
68059 {
68060 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68061
68062 /* Mark the current thread as blocked on the lock: */
68063 - ti->task->blocked_on = waiter;
68064 + task->blocked_on = waiter;
68065 }
68066
68067 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68068 - struct thread_info *ti)
68069 + struct task_struct *task)
68070 {
68071 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68072 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68073 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68074 - ti->task->blocked_on = NULL;
68075 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68076 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68077 + task->blocked_on = NULL;
68078
68079 list_del_init(&waiter->list);
68080 waiter->task = NULL;
68081 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68082 index 0799fd3..d06ae3b 100644
68083 --- a/kernel/mutex-debug.h
68084 +++ b/kernel/mutex-debug.h
68085 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68086 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68087 extern void debug_mutex_add_waiter(struct mutex *lock,
68088 struct mutex_waiter *waiter,
68089 - struct thread_info *ti);
68090 + struct task_struct *task);
68091 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68092 - struct thread_info *ti);
68093 + struct task_struct *task);
68094 extern void debug_mutex_unlock(struct mutex *lock);
68095 extern void debug_mutex_init(struct mutex *lock, const char *name,
68096 struct lock_class_key *key);
68097 diff --git a/kernel/mutex.c b/kernel/mutex.c
68098 index a307cc9..27fd2e9 100644
68099 --- a/kernel/mutex.c
68100 +++ b/kernel/mutex.c
68101 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68102 spin_lock_mutex(&lock->wait_lock, flags);
68103
68104 debug_mutex_lock_common(lock, &waiter);
68105 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68106 + debug_mutex_add_waiter(lock, &waiter, task);
68107
68108 /* add waiting tasks to the end of the waitqueue (FIFO): */
68109 list_add_tail(&waiter.list, &lock->wait_list);
68110 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68111 * TASK_UNINTERRUPTIBLE case.)
68112 */
68113 if (unlikely(signal_pending_state(state, task))) {
68114 - mutex_remove_waiter(lock, &waiter,
68115 - task_thread_info(task));
68116 + mutex_remove_waiter(lock, &waiter, task);
68117 mutex_release(&lock->dep_map, 1, ip);
68118 spin_unlock_mutex(&lock->wait_lock, flags);
68119
68120 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68121 done:
68122 lock_acquired(&lock->dep_map, ip);
68123 /* got the lock - rejoice! */
68124 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68125 + mutex_remove_waiter(lock, &waiter, task);
68126 mutex_set_owner(lock);
68127
68128 /* set it to 0 if there are no waiters left: */
68129 diff --git a/kernel/panic.c b/kernel/panic.c
68130 index d2a5f4e..5edc1d9 100644
68131 --- a/kernel/panic.c
68132 +++ b/kernel/panic.c
68133 @@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68134 int state = 0;
68135
68136 /*
68137 + * Disable local interrupts. This will prevent panic_smp_self_stop
68138 + * from deadlocking the first cpu that invokes the panic, since
68139 + * there is nothing to prevent an interrupt handler (that runs
68140 + * after the panic_lock is acquired) from invoking panic again.
68141 + */
68142 + local_irq_disable();
68143 +
68144 + /*
68145 * It's possible to come here directly from a panic-assertion and
68146 * not have preempt disabled. Some functions called from here want
68147 * preempt to be disabled. No point enabling it later though...
68148 @@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68149 const char *board;
68150
68151 printk(KERN_WARNING "------------[ cut here ]------------\n");
68152 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68153 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68154 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68155 if (board)
68156 printk(KERN_WARNING "Hardware name: %s\n", board);
68157 @@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68158 */
68159 void __stack_chk_fail(void)
68160 {
68161 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68162 + dump_stack();
68163 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68164 __builtin_return_address(0));
68165 }
68166 EXPORT_SYMBOL(__stack_chk_fail);
68167 diff --git a/kernel/pid.c b/kernel/pid.c
68168 index e86b291a..e8b0fb5 100644
68169 --- a/kernel/pid.c
68170 +++ b/kernel/pid.c
68171 @@ -33,6 +33,7 @@
68172 #include <linux/rculist.h>
68173 #include <linux/bootmem.h>
68174 #include <linux/hash.h>
68175 +#include <linux/security.h>
68176 #include <linux/pid_namespace.h>
68177 #include <linux/init_task.h>
68178 #include <linux/syscalls.h>
68179 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68180
68181 int pid_max = PID_MAX_DEFAULT;
68182
68183 -#define RESERVED_PIDS 300
68184 +#define RESERVED_PIDS 500
68185
68186 int pid_max_min = RESERVED_PIDS + 1;
68187 int pid_max_max = PID_MAX_LIMIT;
68188 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68189 */
68190 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68191 {
68192 + struct task_struct *task;
68193 +
68194 rcu_lockdep_assert(rcu_read_lock_held(),
68195 "find_task_by_pid_ns() needs rcu_read_lock()"
68196 " protection");
68197 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68198 +
68199 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68200 +
68201 + if (gr_pid_is_chrooted(task))
68202 + return NULL;
68203 +
68204 + return task;
68205 }
68206
68207 struct task_struct *find_task_by_vpid(pid_t vnr)
68208 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68209 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68210 }
68211
68212 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68213 +{
68214 + rcu_lockdep_assert(rcu_read_lock_held(),
68215 + "find_task_by_pid_ns() needs rcu_read_lock()"
68216 + " protection");
68217 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68218 +}
68219 +
68220 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68221 {
68222 struct pid *pid;
68223 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68224 index 125cb67..a4d1c30 100644
68225 --- a/kernel/posix-cpu-timers.c
68226 +++ b/kernel/posix-cpu-timers.c
68227 @@ -6,6 +6,7 @@
68228 #include <linux/posix-timers.h>
68229 #include <linux/errno.h>
68230 #include <linux/math64.h>
68231 +#include <linux/security.h>
68232 #include <asm/uaccess.h>
68233 #include <linux/kernel_stat.h>
68234 #include <trace/events/timer.h>
68235 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68236
68237 static __init int init_posix_cpu_timers(void)
68238 {
68239 - struct k_clock process = {
68240 + static struct k_clock process = {
68241 .clock_getres = process_cpu_clock_getres,
68242 .clock_get = process_cpu_clock_get,
68243 .timer_create = process_cpu_timer_create,
68244 .nsleep = process_cpu_nsleep,
68245 .nsleep_restart = process_cpu_nsleep_restart,
68246 };
68247 - struct k_clock thread = {
68248 + static struct k_clock thread = {
68249 .clock_getres = thread_cpu_clock_getres,
68250 .clock_get = thread_cpu_clock_get,
68251 .timer_create = thread_cpu_timer_create,
68252 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68253 index 69185ae..cc2847a 100644
68254 --- a/kernel/posix-timers.c
68255 +++ b/kernel/posix-timers.c
68256 @@ -43,6 +43,7 @@
68257 #include <linux/idr.h>
68258 #include <linux/posix-clock.h>
68259 #include <linux/posix-timers.h>
68260 +#include <linux/grsecurity.h>
68261 #include <linux/syscalls.h>
68262 #include <linux/wait.h>
68263 #include <linux/workqueue.h>
68264 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68265 * which we beg off on and pass to do_sys_settimeofday().
68266 */
68267
68268 -static struct k_clock posix_clocks[MAX_CLOCKS];
68269 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68270
68271 /*
68272 * These ones are defined below.
68273 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68274 */
68275 static __init int init_posix_timers(void)
68276 {
68277 - struct k_clock clock_realtime = {
68278 + static struct k_clock clock_realtime = {
68279 .clock_getres = hrtimer_get_res,
68280 .clock_get = posix_clock_realtime_get,
68281 .clock_set = posix_clock_realtime_set,
68282 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68283 .timer_get = common_timer_get,
68284 .timer_del = common_timer_del,
68285 };
68286 - struct k_clock clock_monotonic = {
68287 + static struct k_clock clock_monotonic = {
68288 .clock_getres = hrtimer_get_res,
68289 .clock_get = posix_ktime_get_ts,
68290 .nsleep = common_nsleep,
68291 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68292 .timer_get = common_timer_get,
68293 .timer_del = common_timer_del,
68294 };
68295 - struct k_clock clock_monotonic_raw = {
68296 + static struct k_clock clock_monotonic_raw = {
68297 .clock_getres = hrtimer_get_res,
68298 .clock_get = posix_get_monotonic_raw,
68299 };
68300 - struct k_clock clock_realtime_coarse = {
68301 + static struct k_clock clock_realtime_coarse = {
68302 .clock_getres = posix_get_coarse_res,
68303 .clock_get = posix_get_realtime_coarse,
68304 };
68305 - struct k_clock clock_monotonic_coarse = {
68306 + static struct k_clock clock_monotonic_coarse = {
68307 .clock_getres = posix_get_coarse_res,
68308 .clock_get = posix_get_monotonic_coarse,
68309 };
68310 - struct k_clock clock_boottime = {
68311 + static struct k_clock clock_boottime = {
68312 .clock_getres = hrtimer_get_res,
68313 .clock_get = posix_get_boottime,
68314 .nsleep = common_nsleep,
68315 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68316 return;
68317 }
68318
68319 - posix_clocks[clock_id] = *new_clock;
68320 + posix_clocks[clock_id] = new_clock;
68321 }
68322 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68323
68324 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68325 return (id & CLOCKFD_MASK) == CLOCKFD ?
68326 &clock_posix_dynamic : &clock_posix_cpu;
68327
68328 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68329 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68330 return NULL;
68331 - return &posix_clocks[id];
68332 + return posix_clocks[id];
68333 }
68334
68335 static int common_timer_create(struct k_itimer *new_timer)
68336 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68337 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68338 return -EFAULT;
68339
68340 + /* only the CLOCK_REALTIME clock can be set, all other clocks
68341 + have their clock_set fptr set to a nosettime dummy function
68342 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68343 + call common_clock_set, which calls do_sys_settimeofday, which
68344 + we hook
68345 + */
68346 +
68347 return kc->clock_set(which_clock, &new_tp);
68348 }
68349
68350 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68351 index d523593..68197a4 100644
68352 --- a/kernel/power/poweroff.c
68353 +++ b/kernel/power/poweroff.c
68354 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68355 .enable_mask = SYSRQ_ENABLE_BOOT,
68356 };
68357
68358 -static int pm_sysrq_init(void)
68359 +static int __init pm_sysrq_init(void)
68360 {
68361 register_sysrq_key('o', &sysrq_poweroff_op);
68362 return 0;
68363 diff --git a/kernel/power/process.c b/kernel/power/process.c
68364 index 19db29f..33b52b6 100644
68365 --- a/kernel/power/process.c
68366 +++ b/kernel/power/process.c
68367 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68368 u64 elapsed_csecs64;
68369 unsigned int elapsed_csecs;
68370 bool wakeup = false;
68371 + bool timedout = false;
68372
68373 do_gettimeofday(&start);
68374
68375 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68376
68377 while (true) {
68378 todo = 0;
68379 + if (time_after(jiffies, end_time))
68380 + timedout = true;
68381 read_lock(&tasklist_lock);
68382 do_each_thread(g, p) {
68383 if (p == current || !freeze_task(p))
68384 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68385 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68386 * transition can't race with task state testing here.
68387 */
68388 - if (!task_is_stopped_or_traced(p) &&
68389 - !freezer_should_skip(p))
68390 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68391 todo++;
68392 + if (timedout) {
68393 + printk(KERN_ERR "Task refusing to freeze:\n");
68394 + sched_show_task(p);
68395 + }
68396 + }
68397 } while_each_thread(g, p);
68398 read_unlock(&tasklist_lock);
68399
68400 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68401 todo += wq_busy;
68402 }
68403
68404 - if (!todo || time_after(jiffies, end_time))
68405 + if (!todo || timedout)
68406 break;
68407
68408 if (pm_wakeup_pending()) {
68409 diff --git a/kernel/printk.c b/kernel/printk.c
68410 index ac4bc9e..1d2db99 100644
68411 --- a/kernel/printk.c
68412 +++ b/kernel/printk.c
68413 @@ -781,6 +781,11 @@ static int check_syslog_permissions(int type, bool from_file)
68414 if (from_file && type != SYSLOG_ACTION_OPEN)
68415 return 0;
68416
68417 +#ifdef CONFIG_GRKERNSEC_DMESG
68418 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68419 + return -EPERM;
68420 +#endif
68421 +
68422 if (syslog_action_restricted(type)) {
68423 if (capable(CAP_SYSLOG))
68424 return 0;
68425 diff --git a/kernel/profile.c b/kernel/profile.c
68426 index 76b8e77..a2930e8 100644
68427 --- a/kernel/profile.c
68428 +++ b/kernel/profile.c
68429 @@ -39,7 +39,7 @@ struct profile_hit {
68430 /* Oprofile timer tick hook */
68431 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68432
68433 -static atomic_t *prof_buffer;
68434 +static atomic_unchecked_t *prof_buffer;
68435 static unsigned long prof_len, prof_shift;
68436
68437 int prof_on __read_mostly;
68438 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68439 hits[i].pc = 0;
68440 continue;
68441 }
68442 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68443 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68444 hits[i].hits = hits[i].pc = 0;
68445 }
68446 }
68447 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68448 * Add the current hit(s) and flush the write-queue out
68449 * to the global buffer:
68450 */
68451 - atomic_add(nr_hits, &prof_buffer[pc]);
68452 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68453 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68454 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68455 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68456 hits[i].pc = hits[i].hits = 0;
68457 }
68458 out:
68459 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68460 {
68461 unsigned long pc;
68462 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68463 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68464 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68465 }
68466 #endif /* !CONFIG_SMP */
68467
68468 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68469 return -EFAULT;
68470 buf++; p++; count--; read++;
68471 }
68472 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68473 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68474 if (copy_to_user(buf, (void *)pnt, count))
68475 return -EFAULT;
68476 read += count;
68477 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68478 }
68479 #endif
68480 profile_discard_flip_buffers();
68481 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68482 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68483 return count;
68484 }
68485
68486 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68487 index a232bb5..2a65ef9 100644
68488 --- a/kernel/ptrace.c
68489 +++ b/kernel/ptrace.c
68490 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68491
68492 if (seize)
68493 flags |= PT_SEIZED;
68494 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68495 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68496 flags |= PT_PTRACE_CAP;
68497 task->ptrace = flags;
68498
68499 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68500 break;
68501 return -EIO;
68502 }
68503 - if (copy_to_user(dst, buf, retval))
68504 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68505 return -EFAULT;
68506 copied += retval;
68507 src += retval;
68508 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68509 bool seized = child->ptrace & PT_SEIZED;
68510 int ret = -EIO;
68511 siginfo_t siginfo, *si;
68512 - void __user *datavp = (void __user *) data;
68513 + void __user *datavp = (__force void __user *) data;
68514 unsigned long __user *datalp = datavp;
68515 unsigned long flags;
68516
68517 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68518 goto out;
68519 }
68520
68521 + if (gr_handle_ptrace(child, request)) {
68522 + ret = -EPERM;
68523 + goto out_put_task_struct;
68524 + }
68525 +
68526 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68527 ret = ptrace_attach(child, request, addr, data);
68528 /*
68529 * Some architectures need to do book-keeping after
68530 * a ptrace attach.
68531 */
68532 - if (!ret)
68533 + if (!ret) {
68534 arch_ptrace_attach(child);
68535 + gr_audit_ptrace(child);
68536 + }
68537 goto out_put_task_struct;
68538 }
68539
68540 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68541 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68542 if (copied != sizeof(tmp))
68543 return -EIO;
68544 - return put_user(tmp, (unsigned long __user *)data);
68545 + return put_user(tmp, (__force unsigned long __user *)data);
68546 }
68547
68548 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68549 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68550 goto out;
68551 }
68552
68553 + if (gr_handle_ptrace(child, request)) {
68554 + ret = -EPERM;
68555 + goto out_put_task_struct;
68556 + }
68557 +
68558 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68559 ret = ptrace_attach(child, request, addr, data);
68560 /*
68561 * Some architectures need to do book-keeping after
68562 * a ptrace attach.
68563 */
68564 - if (!ret)
68565 + if (!ret) {
68566 arch_ptrace_attach(child);
68567 + gr_audit_ptrace(child);
68568 + }
68569 goto out_put_task_struct;
68570 }
68571
68572 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68573 index 37a5444..eec170a 100644
68574 --- a/kernel/rcutiny.c
68575 +++ b/kernel/rcutiny.c
68576 @@ -46,7 +46,7 @@
68577 struct rcu_ctrlblk;
68578 static void invoke_rcu_callbacks(void);
68579 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68580 -static void rcu_process_callbacks(struct softirq_action *unused);
68581 +static void rcu_process_callbacks(void);
68582 static void __call_rcu(struct rcu_head *head,
68583 void (*func)(struct rcu_head *rcu),
68584 struct rcu_ctrlblk *rcp);
68585 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68586 rcu_is_callbacks_kthread()));
68587 }
68588
68589 -static void rcu_process_callbacks(struct softirq_action *unused)
68590 +static void rcu_process_callbacks(void)
68591 {
68592 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68593 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68594 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68595 index fc31a2d..be2ec04 100644
68596 --- a/kernel/rcutiny_plugin.h
68597 +++ b/kernel/rcutiny_plugin.h
68598 @@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68599 have_rcu_kthread_work = morework;
68600 local_irq_restore(flags);
68601 if (work)
68602 - rcu_process_callbacks(NULL);
68603 + rcu_process_callbacks();
68604 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68605 }
68606
68607 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68608 index e66b34a..4b8b626 100644
68609 --- a/kernel/rcutorture.c
68610 +++ b/kernel/rcutorture.c
68611 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68612 { 0 };
68613 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68614 { 0 };
68615 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68616 -static atomic_t n_rcu_torture_alloc;
68617 -static atomic_t n_rcu_torture_alloc_fail;
68618 -static atomic_t n_rcu_torture_free;
68619 -static atomic_t n_rcu_torture_mberror;
68620 -static atomic_t n_rcu_torture_error;
68621 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68622 +static atomic_unchecked_t n_rcu_torture_alloc;
68623 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68624 +static atomic_unchecked_t n_rcu_torture_free;
68625 +static atomic_unchecked_t n_rcu_torture_mberror;
68626 +static atomic_unchecked_t n_rcu_torture_error;
68627 static long n_rcu_torture_barrier_error;
68628 static long n_rcu_torture_boost_ktrerror;
68629 static long n_rcu_torture_boost_rterror;
68630 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68631
68632 spin_lock_bh(&rcu_torture_lock);
68633 if (list_empty(&rcu_torture_freelist)) {
68634 - atomic_inc(&n_rcu_torture_alloc_fail);
68635 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68636 spin_unlock_bh(&rcu_torture_lock);
68637 return NULL;
68638 }
68639 - atomic_inc(&n_rcu_torture_alloc);
68640 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68641 p = rcu_torture_freelist.next;
68642 list_del_init(p);
68643 spin_unlock_bh(&rcu_torture_lock);
68644 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68645 static void
68646 rcu_torture_free(struct rcu_torture *p)
68647 {
68648 - atomic_inc(&n_rcu_torture_free);
68649 + atomic_inc_unchecked(&n_rcu_torture_free);
68650 spin_lock_bh(&rcu_torture_lock);
68651 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68652 spin_unlock_bh(&rcu_torture_lock);
68653 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68654 i = rp->rtort_pipe_count;
68655 if (i > RCU_TORTURE_PIPE_LEN)
68656 i = RCU_TORTURE_PIPE_LEN;
68657 - atomic_inc(&rcu_torture_wcount[i]);
68658 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68659 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68660 rp->rtort_mbtest = 0;
68661 rcu_torture_free(rp);
68662 @@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68663 i = rp->rtort_pipe_count;
68664 if (i > RCU_TORTURE_PIPE_LEN)
68665 i = RCU_TORTURE_PIPE_LEN;
68666 - atomic_inc(&rcu_torture_wcount[i]);
68667 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68668 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68669 rp->rtort_mbtest = 0;
68670 list_del(&rp->rtort_free);
68671 @@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68672 i = old_rp->rtort_pipe_count;
68673 if (i > RCU_TORTURE_PIPE_LEN)
68674 i = RCU_TORTURE_PIPE_LEN;
68675 - atomic_inc(&rcu_torture_wcount[i]);
68676 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68677 old_rp->rtort_pipe_count++;
68678 cur_ops->deferred_free(old_rp);
68679 }
68680 @@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68681 }
68682 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68683 if (p->rtort_mbtest == 0)
68684 - atomic_inc(&n_rcu_torture_mberror);
68685 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68686 spin_lock(&rand_lock);
68687 cur_ops->read_delay(&rand);
68688 n_rcu_torture_timers++;
68689 @@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68690 }
68691 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68692 if (p->rtort_mbtest == 0)
68693 - atomic_inc(&n_rcu_torture_mberror);
68694 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68695 cur_ops->read_delay(&rand);
68696 preempt_disable();
68697 pipe_count = p->rtort_pipe_count;
68698 @@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68699 rcu_torture_current,
68700 rcu_torture_current_version,
68701 list_empty(&rcu_torture_freelist),
68702 - atomic_read(&n_rcu_torture_alloc),
68703 - atomic_read(&n_rcu_torture_alloc_fail),
68704 - atomic_read(&n_rcu_torture_free),
68705 - atomic_read(&n_rcu_torture_mberror),
68706 + atomic_read_unchecked(&n_rcu_torture_alloc),
68707 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68708 + atomic_read_unchecked(&n_rcu_torture_free),
68709 + atomic_read_unchecked(&n_rcu_torture_mberror),
68710 n_rcu_torture_boost_ktrerror,
68711 n_rcu_torture_boost_rterror,
68712 n_rcu_torture_boost_failure,
68713 @@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68714 n_barrier_attempts,
68715 n_rcu_torture_barrier_error);
68716 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68717 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68718 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68719 n_rcu_torture_barrier_error != 0 ||
68720 n_rcu_torture_boost_ktrerror != 0 ||
68721 n_rcu_torture_boost_rterror != 0 ||
68722 n_rcu_torture_boost_failure != 0 ||
68723 i > 1) {
68724 cnt += sprintf(&page[cnt], "!!! ");
68725 - atomic_inc(&n_rcu_torture_error);
68726 + atomic_inc_unchecked(&n_rcu_torture_error);
68727 WARN_ON_ONCE(1);
68728 }
68729 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68730 @@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68731 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68732 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68733 cnt += sprintf(&page[cnt], " %d",
68734 - atomic_read(&rcu_torture_wcount[i]));
68735 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68736 }
68737 cnt += sprintf(&page[cnt], "\n");
68738 if (cur_ops->stats)
68739 @@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68740
68741 if (cur_ops->cleanup)
68742 cur_ops->cleanup();
68743 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68744 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68745 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68746 else if (n_online_successes != n_online_attempts ||
68747 n_offline_successes != n_offline_attempts)
68748 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68749
68750 rcu_torture_current = NULL;
68751 rcu_torture_current_version = 0;
68752 - atomic_set(&n_rcu_torture_alloc, 0);
68753 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68754 - atomic_set(&n_rcu_torture_free, 0);
68755 - atomic_set(&n_rcu_torture_mberror, 0);
68756 - atomic_set(&n_rcu_torture_error, 0);
68757 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68758 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68759 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68760 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68761 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68762 n_rcu_torture_barrier_error = 0;
68763 n_rcu_torture_boost_ktrerror = 0;
68764 n_rcu_torture_boost_rterror = 0;
68765 n_rcu_torture_boost_failure = 0;
68766 n_rcu_torture_boosts = 0;
68767 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68768 - atomic_set(&rcu_torture_wcount[i], 0);
68769 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68770 for_each_possible_cpu(cpu) {
68771 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68772 per_cpu(rcu_torture_count, cpu)[i] = 0;
68773 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68774 index 4b97bba..b92c9d2 100644
68775 --- a/kernel/rcutree.c
68776 +++ b/kernel/rcutree.c
68777 @@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68778 rcu_prepare_for_idle(smp_processor_id());
68779 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68780 smp_mb__before_atomic_inc(); /* See above. */
68781 - atomic_inc(&rdtp->dynticks);
68782 + atomic_inc_unchecked(&rdtp->dynticks);
68783 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68784 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68785 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68786
68787 /*
68788 * The idle task is not permitted to enter the idle loop while
68789 @@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68790 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68791 {
68792 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68793 - atomic_inc(&rdtp->dynticks);
68794 + atomic_inc_unchecked(&rdtp->dynticks);
68795 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68796 smp_mb__after_atomic_inc(); /* See above. */
68797 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68798 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68799 rcu_cleanup_after_idle(smp_processor_id());
68800 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68801 if (!is_idle_task(current)) {
68802 @@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68803 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68804
68805 if (rdtp->dynticks_nmi_nesting == 0 &&
68806 - (atomic_read(&rdtp->dynticks) & 0x1))
68807 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68808 return;
68809 rdtp->dynticks_nmi_nesting++;
68810 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68811 - atomic_inc(&rdtp->dynticks);
68812 + atomic_inc_unchecked(&rdtp->dynticks);
68813 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68814 smp_mb__after_atomic_inc(); /* See above. */
68815 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68816 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68817 }
68818
68819 /**
68820 @@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
68821 return;
68822 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68823 smp_mb__before_atomic_inc(); /* See above. */
68824 - atomic_inc(&rdtp->dynticks);
68825 + atomic_inc_unchecked(&rdtp->dynticks);
68826 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68827 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68828 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68829 }
68830
68831 #ifdef CONFIG_PROVE_RCU
68832 @@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
68833 int ret;
68834
68835 preempt_disable();
68836 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68837 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68838 preempt_enable();
68839 return ret;
68840 }
68841 @@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68842 */
68843 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68844 {
68845 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68846 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68847 return (rdp->dynticks_snap & 0x1) == 0;
68848 }
68849
68850 @@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68851 unsigned int curr;
68852 unsigned int snap;
68853
68854 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68855 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68856 snap = (unsigned int)rdp->dynticks_snap;
68857
68858 /*
68859 @@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
68860 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68861 */
68862 if (till_stall_check < 3) {
68863 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68864 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68865 till_stall_check = 3;
68866 } else if (till_stall_check > 300) {
68867 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68868 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68869 till_stall_check = 300;
68870 }
68871 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68872 @@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68873 /*
68874 * Do RCU core processing for the current CPU.
68875 */
68876 -static void rcu_process_callbacks(struct softirq_action *unused)
68877 +static void rcu_process_callbacks(void)
68878 {
68879 trace_rcu_utilization("Start RCU core");
68880 __rcu_process_callbacks(&rcu_sched_state,
68881 @@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
68882 }
68883 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
68884
68885 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68886 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68887 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68888 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68889
68890 static int synchronize_sched_expedited_cpu_stop(void *data)
68891 {
68892 @@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
68893 int firstsnap, s, snap, trycount = 0;
68894
68895 /* Note that atomic_inc_return() implies full memory barrier. */
68896 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68897 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68898 get_online_cpus();
68899 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
68900
68901 @@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
68902 }
68903
68904 /* Check to see if someone else did our work for us. */
68905 - s = atomic_read(&sync_sched_expedited_done);
68906 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68907 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68908 smp_mb(); /* ensure test happens before caller kfree */
68909 return;
68910 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
68911 * grace period works for us.
68912 */
68913 get_online_cpus();
68914 - snap = atomic_read(&sync_sched_expedited_started);
68915 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68916 smp_mb(); /* ensure read is before try_stop_cpus(). */
68917 }
68918
68919 @@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
68920 * than we did beat us to the punch.
68921 */
68922 do {
68923 - s = atomic_read(&sync_sched_expedited_done);
68924 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68925 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68926 smp_mb(); /* ensure test happens before caller kfree */
68927 break;
68928 }
68929 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68930 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68931
68932 put_online_cpus();
68933 }
68934 @@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68935 rdp->qlen = 0;
68936 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68937 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
68938 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68939 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68940 rdp->cpu = cpu;
68941 rdp->rsp = rsp;
68942 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68943 @@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68944 rdp->n_force_qs_snap = rsp->n_force_qs;
68945 rdp->blimit = blimit;
68946 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
68947 - atomic_set(&rdp->dynticks->dynticks,
68948 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68949 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68950 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68951 rcu_prepare_for_idle_init(cpu);
68952 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68953
68954 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68955 index 19b61ac..5c60a94 100644
68956 --- a/kernel/rcutree.h
68957 +++ b/kernel/rcutree.h
68958 @@ -83,7 +83,7 @@ struct rcu_dynticks {
68959 long long dynticks_nesting; /* Track irq/process nesting level. */
68960 /* Process level is worth LLONG_MAX/2. */
68961 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68962 - atomic_t dynticks; /* Even value for idle, else odd. */
68963 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68964 #ifdef CONFIG_RCU_FAST_NO_HZ
68965 int dyntick_drain; /* Prepare-for-idle state variable. */
68966 unsigned long dyntick_holdoff;
68967 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68968 index 3e48994..d94f03a 100644
68969 --- a/kernel/rcutree_plugin.h
68970 +++ b/kernel/rcutree_plugin.h
68971 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
68972
68973 /* Clean up and exit. */
68974 smp_mb(); /* ensure expedited GP seen before counter increment. */
68975 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68976 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68977 unlock_mb_ret:
68978 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68979 mb_ret:
68980 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68981 index d4bc16d..c234a5c 100644
68982 --- a/kernel/rcutree_trace.c
68983 +++ b/kernel/rcutree_trace.c
68984 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68985 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68986 rdp->qs_pending);
68987 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68988 - atomic_read(&rdp->dynticks->dynticks),
68989 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68990 rdp->dynticks->dynticks_nesting,
68991 rdp->dynticks->dynticks_nmi_nesting,
68992 rdp->dynticks_fqs);
68993 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68994 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68995 rdp->qs_pending);
68996 seq_printf(m, ",%d,%llx,%d,%lu",
68997 - atomic_read(&rdp->dynticks->dynticks),
68998 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68999 rdp->dynticks->dynticks_nesting,
69000 rdp->dynticks->dynticks_nmi_nesting,
69001 rdp->dynticks_fqs);
69002 diff --git a/kernel/resource.c b/kernel/resource.c
69003 index e1d2b8e..24820bb 100644
69004 --- a/kernel/resource.c
69005 +++ b/kernel/resource.c
69006 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69007
69008 static int __init ioresources_init(void)
69009 {
69010 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69011 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69012 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69013 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69014 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69015 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69016 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69017 +#endif
69018 +#else
69019 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69020 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69021 +#endif
69022 return 0;
69023 }
69024 __initcall(ioresources_init);
69025 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69026 index 98ec494..4241d6d 100644
69027 --- a/kernel/rtmutex-tester.c
69028 +++ b/kernel/rtmutex-tester.c
69029 @@ -20,7 +20,7 @@
69030 #define MAX_RT_TEST_MUTEXES 8
69031
69032 static spinlock_t rttest_lock;
69033 -static atomic_t rttest_event;
69034 +static atomic_unchecked_t rttest_event;
69035
69036 struct test_thread_data {
69037 int opcode;
69038 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69039
69040 case RTTEST_LOCKCONT:
69041 td->mutexes[td->opdata] = 1;
69042 - td->event = atomic_add_return(1, &rttest_event);
69043 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69044 return 0;
69045
69046 case RTTEST_RESET:
69047 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69048 return 0;
69049
69050 case RTTEST_RESETEVENT:
69051 - atomic_set(&rttest_event, 0);
69052 + atomic_set_unchecked(&rttest_event, 0);
69053 return 0;
69054
69055 default:
69056 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69057 return ret;
69058
69059 td->mutexes[id] = 1;
69060 - td->event = atomic_add_return(1, &rttest_event);
69061 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69062 rt_mutex_lock(&mutexes[id]);
69063 - td->event = atomic_add_return(1, &rttest_event);
69064 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69065 td->mutexes[id] = 4;
69066 return 0;
69067
69068 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69069 return ret;
69070
69071 td->mutexes[id] = 1;
69072 - td->event = atomic_add_return(1, &rttest_event);
69073 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69074 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69075 - td->event = atomic_add_return(1, &rttest_event);
69076 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69077 td->mutexes[id] = ret ? 0 : 4;
69078 return ret ? -EINTR : 0;
69079
69080 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69081 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69082 return ret;
69083
69084 - td->event = atomic_add_return(1, &rttest_event);
69085 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69086 rt_mutex_unlock(&mutexes[id]);
69087 - td->event = atomic_add_return(1, &rttest_event);
69088 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69089 td->mutexes[id] = 0;
69090 return 0;
69091
69092 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69093 break;
69094
69095 td->mutexes[dat] = 2;
69096 - td->event = atomic_add_return(1, &rttest_event);
69097 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69098 break;
69099
69100 default:
69101 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69102 return;
69103
69104 td->mutexes[dat] = 3;
69105 - td->event = atomic_add_return(1, &rttest_event);
69106 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69107 break;
69108
69109 case RTTEST_LOCKNOWAIT:
69110 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69111 return;
69112
69113 td->mutexes[dat] = 1;
69114 - td->event = atomic_add_return(1, &rttest_event);
69115 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69116 return;
69117
69118 default:
69119 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69120 index 0984a21..939f183 100644
69121 --- a/kernel/sched/auto_group.c
69122 +++ b/kernel/sched/auto_group.c
69123 @@ -11,7 +11,7 @@
69124
69125 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69126 static struct autogroup autogroup_default;
69127 -static atomic_t autogroup_seq_nr;
69128 +static atomic_unchecked_t autogroup_seq_nr;
69129
69130 void __init autogroup_init(struct task_struct *init_task)
69131 {
69132 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69133
69134 kref_init(&ag->kref);
69135 init_rwsem(&ag->lock);
69136 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69137 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69138 ag->tg = tg;
69139 #ifdef CONFIG_RT_GROUP_SCHED
69140 /*
69141 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69142 index 468bdd4..b941572 100644
69143 --- a/kernel/sched/core.c
69144 +++ b/kernel/sched/core.c
69145 @@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69146 /* convert nice value [19,-20] to rlimit style value [1,40] */
69147 int nice_rlim = 20 - nice;
69148
69149 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69150 +
69151 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69152 capable(CAP_SYS_NICE));
69153 }
69154 @@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69155 if (nice > 19)
69156 nice = 19;
69157
69158 - if (increment < 0 && !can_nice(current, nice))
69159 + if (increment < 0 && (!can_nice(current, nice) ||
69160 + gr_handle_chroot_nice()))
69161 return -EPERM;
69162
69163 retval = security_task_setnice(current, nice);
69164 @@ -4284,6 +4287,7 @@ recheck:
69165 unsigned long rlim_rtprio =
69166 task_rlimit(p, RLIMIT_RTPRIO);
69167
69168 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69169 /* can't set/change the rt policy */
69170 if (policy != p->policy && !rlim_rtprio)
69171 return -EPERM;
69172 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69173 index c099cc6..06aec4f 100644
69174 --- a/kernel/sched/fair.c
69175 +++ b/kernel/sched/fair.c
69176 @@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69177 * run_rebalance_domains is triggered when needed from the scheduler tick.
69178 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69179 */
69180 -static void run_rebalance_domains(struct softirq_action *h)
69181 +static void run_rebalance_domains(void)
69182 {
69183 int this_cpu = smp_processor_id();
69184 struct rq *this_rq = cpu_rq(this_cpu);
69185 diff --git a/kernel/signal.c b/kernel/signal.c
69186 index 6771027..763e51e 100644
69187 --- a/kernel/signal.c
69188 +++ b/kernel/signal.c
69189 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69190
69191 int print_fatal_signals __read_mostly;
69192
69193 -static void __user *sig_handler(struct task_struct *t, int sig)
69194 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69195 {
69196 return t->sighand->action[sig - 1].sa.sa_handler;
69197 }
69198
69199 -static int sig_handler_ignored(void __user *handler, int sig)
69200 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69201 {
69202 /* Is it explicitly or implicitly ignored? */
69203 return handler == SIG_IGN ||
69204 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69205
69206 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69207 {
69208 - void __user *handler;
69209 + __sighandler_t handler;
69210
69211 handler = sig_handler(t, sig);
69212
69213 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69214 atomic_inc(&user->sigpending);
69215 rcu_read_unlock();
69216
69217 + if (!override_rlimit)
69218 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69219 +
69220 if (override_rlimit ||
69221 atomic_read(&user->sigpending) <=
69222 task_rlimit(t, RLIMIT_SIGPENDING)) {
69223 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69224
69225 int unhandled_signal(struct task_struct *tsk, int sig)
69226 {
69227 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69228 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69229 if (is_global_init(tsk))
69230 return 1;
69231 if (handler != SIG_IGN && handler != SIG_DFL)
69232 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69233 }
69234 }
69235
69236 + /* allow glibc communication via tgkill to other threads in our
69237 + thread group */
69238 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69239 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69240 + && gr_handle_signal(t, sig))
69241 + return -EPERM;
69242 +
69243 return security_task_kill(t, info, sig, 0);
69244 }
69245
69246 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69247 return send_signal(sig, info, p, 1);
69248 }
69249
69250 -static int
69251 +int
69252 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69253 {
69254 return send_signal(sig, info, t, 0);
69255 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69256 unsigned long int flags;
69257 int ret, blocked, ignored;
69258 struct k_sigaction *action;
69259 + int is_unhandled = 0;
69260
69261 spin_lock_irqsave(&t->sighand->siglock, flags);
69262 action = &t->sighand->action[sig-1];
69263 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69264 }
69265 if (action->sa.sa_handler == SIG_DFL)
69266 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69267 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69268 + is_unhandled = 1;
69269 ret = specific_send_sig_info(sig, info, t);
69270 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69271
69272 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69273 + normal operation */
69274 + if (is_unhandled) {
69275 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69276 + gr_handle_crash(t, sig);
69277 + }
69278 +
69279 return ret;
69280 }
69281
69282 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69283 ret = check_kill_permission(sig, info, p);
69284 rcu_read_unlock();
69285
69286 - if (!ret && sig)
69287 + if (!ret && sig) {
69288 ret = do_send_sig_info(sig, info, p, true);
69289 + if (!ret)
69290 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69291 + }
69292
69293 return ret;
69294 }
69295 @@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69296 int error = -ESRCH;
69297
69298 rcu_read_lock();
69299 - p = find_task_by_vpid(pid);
69300 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69301 + /* allow glibc communication via tgkill to other threads in our
69302 + thread group */
69303 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69304 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69305 + p = find_task_by_vpid_unrestricted(pid);
69306 + else
69307 +#endif
69308 + p = find_task_by_vpid(pid);
69309 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69310 error = check_kill_permission(sig, info, p);
69311 /*
69312 diff --git a/kernel/smp.c b/kernel/smp.c
69313 index d0ae5b2..b87c5a8 100644
69314 --- a/kernel/smp.c
69315 +++ b/kernel/smp.c
69316 @@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69317 }
69318 EXPORT_SYMBOL(smp_call_function);
69319
69320 -void ipi_call_lock(void)
69321 +void ipi_call_lock(void) __acquires(call_function.lock)
69322 {
69323 raw_spin_lock(&call_function.lock);
69324 }
69325
69326 -void ipi_call_unlock(void)
69327 +void ipi_call_unlock(void) __releases(call_function.lock)
69328 {
69329 raw_spin_unlock(&call_function.lock);
69330 }
69331
69332 -void ipi_call_lock_irq(void)
69333 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69334 {
69335 raw_spin_lock_irq(&call_function.lock);
69336 }
69337
69338 -void ipi_call_unlock_irq(void)
69339 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69340 {
69341 raw_spin_unlock_irq(&call_function.lock);
69342 }
69343 diff --git a/kernel/softirq.c b/kernel/softirq.c
69344 index 671f959..91c51cb 100644
69345 --- a/kernel/softirq.c
69346 +++ b/kernel/softirq.c
69347 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69348
69349 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69350
69351 -char *softirq_to_name[NR_SOFTIRQS] = {
69352 +const char * const softirq_to_name[NR_SOFTIRQS] = {
69353 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69354 "TASKLET", "SCHED", "HRTIMER", "RCU"
69355 };
69356 @@ -235,7 +235,7 @@ restart:
69357 kstat_incr_softirqs_this_cpu(vec_nr);
69358
69359 trace_softirq_entry(vec_nr);
69360 - h->action(h);
69361 + h->action();
69362 trace_softirq_exit(vec_nr);
69363 if (unlikely(prev_count != preempt_count())) {
69364 printk(KERN_ERR "huh, entered softirq %u %s %p"
69365 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69366 or_softirq_pending(1UL << nr);
69367 }
69368
69369 -void open_softirq(int nr, void (*action)(struct softirq_action *))
69370 +void open_softirq(int nr, void (*action)(void))
69371 {
69372 - softirq_vec[nr].action = action;
69373 + pax_open_kernel();
69374 + *(void **)&softirq_vec[nr].action = action;
69375 + pax_close_kernel();
69376 }
69377
69378 /*
69379 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69380
69381 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69382
69383 -static void tasklet_action(struct softirq_action *a)
69384 +static void tasklet_action(void)
69385 {
69386 struct tasklet_struct *list;
69387
69388 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69389 }
69390 }
69391
69392 -static void tasklet_hi_action(struct softirq_action *a)
69393 +static void tasklet_hi_action(void)
69394 {
69395 struct tasklet_struct *list;
69396
69397 diff --git a/kernel/srcu.c b/kernel/srcu.c
69398 index 2095be3..9a5b89d 100644
69399 --- a/kernel/srcu.c
69400 +++ b/kernel/srcu.c
69401 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69402 preempt_disable();
69403 idx = rcu_dereference_index_check(sp->completed,
69404 rcu_read_lock_sched_held()) & 0x1;
69405 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69406 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69407 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69408 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69409 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69410 preempt_enable();
69411 return idx;
69412 }
69413 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69414 {
69415 preempt_disable();
69416 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69417 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69418 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69419 preempt_enable();
69420 }
69421 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69422 diff --git a/kernel/sys.c b/kernel/sys.c
69423 index 2d39a84..f778b49 100644
69424 --- a/kernel/sys.c
69425 +++ b/kernel/sys.c
69426 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69427 error = -EACCES;
69428 goto out;
69429 }
69430 +
69431 + if (gr_handle_chroot_setpriority(p, niceval)) {
69432 + error = -EACCES;
69433 + goto out;
69434 + }
69435 +
69436 no_nice = security_task_setnice(p, niceval);
69437 if (no_nice) {
69438 error = no_nice;
69439 @@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69440 goto error;
69441 }
69442
69443 + if (gr_check_group_change(new->gid, new->egid, -1))
69444 + goto error;
69445 +
69446 if (rgid != (gid_t) -1 ||
69447 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69448 new->sgid = new->egid;
69449 @@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69450 old = current_cred();
69451
69452 retval = -EPERM;
69453 +
69454 + if (gr_check_group_change(kgid, kgid, kgid))
69455 + goto error;
69456 +
69457 if (nsown_capable(CAP_SETGID))
69458 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69459 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69460 @@ -646,7 +659,7 @@ error:
69461 /*
69462 * change the user struct in a credentials set to match the new UID
69463 */
69464 -static int set_user(struct cred *new)
69465 +int set_user(struct cred *new)
69466 {
69467 struct user_struct *new_user;
69468
69469 @@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69470 goto error;
69471 }
69472
69473 + if (gr_check_user_change(new->uid, new->euid, -1))
69474 + goto error;
69475 +
69476 if (!uid_eq(new->uid, old->uid)) {
69477 retval = set_user(new);
69478 if (retval < 0)
69479 @@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69480 old = current_cred();
69481
69482 retval = -EPERM;
69483 +
69484 + if (gr_check_crash_uid(kuid))
69485 + goto error;
69486 + if (gr_check_user_change(kuid, kuid, kuid))
69487 + goto error;
69488 +
69489 if (nsown_capable(CAP_SETUID)) {
69490 new->suid = new->uid = kuid;
69491 if (!uid_eq(kuid, old->uid)) {
69492 @@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69493 goto error;
69494 }
69495
69496 + if (gr_check_user_change(kruid, keuid, -1))
69497 + goto error;
69498 +
69499 if (ruid != (uid_t) -1) {
69500 new->uid = kruid;
69501 if (!uid_eq(kruid, old->uid)) {
69502 @@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69503 goto error;
69504 }
69505
69506 + if (gr_check_group_change(krgid, kegid, -1))
69507 + goto error;
69508 +
69509 if (rgid != (gid_t) -1)
69510 new->gid = krgid;
69511 if (egid != (gid_t) -1)
69512 @@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69513 if (!uid_valid(kuid))
69514 return old_fsuid;
69515
69516 + if (gr_check_user_change(-1, -1, kuid))
69517 + goto error;
69518 +
69519 new = prepare_creds();
69520 if (!new)
69521 return old_fsuid;
69522 @@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69523 }
69524 }
69525
69526 +error:
69527 abort_creds(new);
69528 return old_fsuid;
69529
69530 @@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69531 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69532 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69533 nsown_capable(CAP_SETGID)) {
69534 + if (gr_check_group_change(-1, -1, kgid))
69535 + goto error;
69536 +
69537 if (!gid_eq(kgid, old->fsgid)) {
69538 new->fsgid = kgid;
69539 goto change_okay;
69540 }
69541 }
69542
69543 +error:
69544 abort_creds(new);
69545 return old_fsgid;
69546
69547 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69548 }
69549 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69550 snprintf(buf, len, "2.6.%u%s", v, rest);
69551 - ret = copy_to_user(release, buf, len);
69552 + if (len > sizeof(buf))
69553 + ret = -EFAULT;
69554 + else
69555 + ret = copy_to_user(release, buf, len);
69556 }
69557 return ret;
69558 }
69559 @@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69560 return -EFAULT;
69561
69562 down_read(&uts_sem);
69563 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
69564 + error = __copy_to_user(name->sysname, &utsname()->sysname,
69565 __OLD_UTS_LEN);
69566 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69567 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69568 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
69569 __OLD_UTS_LEN);
69570 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69571 - error |= __copy_to_user(&name->release, &utsname()->release,
69572 + error |= __copy_to_user(name->release, &utsname()->release,
69573 __OLD_UTS_LEN);
69574 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69575 - error |= __copy_to_user(&name->version, &utsname()->version,
69576 + error |= __copy_to_user(name->version, &utsname()->version,
69577 __OLD_UTS_LEN);
69578 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69579 - error |= __copy_to_user(&name->machine, &utsname()->machine,
69580 + error |= __copy_to_user(name->machine, &utsname()->machine,
69581 __OLD_UTS_LEN);
69582 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69583 up_read(&uts_sem);
69584 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69585 error = get_dumpable(me->mm);
69586 break;
69587 case PR_SET_DUMPABLE:
69588 - if (arg2 < 0 || arg2 > 1) {
69589 + if (arg2 > 1) {
69590 error = -EINVAL;
69591 break;
69592 }
69593 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69594 index 4ab1187..33f4f2b 100644
69595 --- a/kernel/sysctl.c
69596 +++ b/kernel/sysctl.c
69597 @@ -91,7 +91,6 @@
69598
69599
69600 #if defined(CONFIG_SYSCTL)
69601 -
69602 /* External variables not in a header file. */
69603 extern int sysctl_overcommit_memory;
69604 extern int sysctl_overcommit_ratio;
69605 @@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69606 void __user *buffer, size_t *lenp, loff_t *ppos);
69607 #endif
69608
69609 -#ifdef CONFIG_PRINTK
69610 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69611 void __user *buffer, size_t *lenp, loff_t *ppos);
69612 -#endif
69613 +
69614 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69615 + void __user *buffer, size_t *lenp, loff_t *ppos);
69616 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69617 + void __user *buffer, size_t *lenp, loff_t *ppos);
69618
69619 #ifdef CONFIG_MAGIC_SYSRQ
69620 /* Note: sysrq code uses it's own private copy */
69621 @@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69622
69623 #endif
69624
69625 +extern struct ctl_table grsecurity_table[];
69626 +
69627 static struct ctl_table kern_table[];
69628 static struct ctl_table vm_table[];
69629 static struct ctl_table fs_table[];
69630 @@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69631 int sysctl_legacy_va_layout;
69632 #endif
69633
69634 +#ifdef CONFIG_PAX_SOFTMODE
69635 +static ctl_table pax_table[] = {
69636 + {
69637 + .procname = "softmode",
69638 + .data = &pax_softmode,
69639 + .maxlen = sizeof(unsigned int),
69640 + .mode = 0600,
69641 + .proc_handler = &proc_dointvec,
69642 + },
69643 +
69644 + { }
69645 +};
69646 +#endif
69647 +
69648 /* The default sysctl tables: */
69649
69650 static struct ctl_table sysctl_base_table[] = {
69651 @@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69652 #endif
69653
69654 static struct ctl_table kern_table[] = {
69655 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69656 + {
69657 + .procname = "grsecurity",
69658 + .mode = 0500,
69659 + .child = grsecurity_table,
69660 + },
69661 +#endif
69662 +
69663 +#ifdef CONFIG_PAX_SOFTMODE
69664 + {
69665 + .procname = "pax",
69666 + .mode = 0500,
69667 + .child = pax_table,
69668 + },
69669 +#endif
69670 +
69671 {
69672 .procname = "sched_child_runs_first",
69673 .data = &sysctl_sched_child_runs_first,
69674 @@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69675 .data = core_pattern,
69676 .maxlen = CORENAME_MAX_SIZE,
69677 .mode = 0644,
69678 - .proc_handler = proc_dostring,
69679 + .proc_handler = proc_dostring_coredump,
69680 },
69681 {
69682 .procname = "core_pipe_limit",
69683 @@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69684 .data = &modprobe_path,
69685 .maxlen = KMOD_PATH_LEN,
69686 .mode = 0644,
69687 - .proc_handler = proc_dostring,
69688 + .proc_handler = proc_dostring_modpriv,
69689 },
69690 {
69691 .procname = "modules_disabled",
69692 @@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69693 .extra1 = &zero,
69694 .extra2 = &one,
69695 },
69696 +#endif
69697 {
69698 .procname = "kptr_restrict",
69699 .data = &kptr_restrict,
69700 .maxlen = sizeof(int),
69701 .mode = 0644,
69702 .proc_handler = proc_dointvec_minmax_sysadmin,
69703 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69704 + .extra1 = &two,
69705 +#else
69706 .extra1 = &zero,
69707 +#endif
69708 .extra2 = &two,
69709 },
69710 -#endif
69711 {
69712 .procname = "ngroups_max",
69713 .data = &ngroups_max,
69714 @@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69715 .proc_handler = proc_dointvec_minmax,
69716 .extra1 = &zero,
69717 },
69718 + {
69719 + .procname = "heap_stack_gap",
69720 + .data = &sysctl_heap_stack_gap,
69721 + .maxlen = sizeof(sysctl_heap_stack_gap),
69722 + .mode = 0644,
69723 + .proc_handler = proc_doulongvec_minmax,
69724 + },
69725 #else
69726 {
69727 .procname = "nr_trim_pages",
69728 @@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69729 .data = &suid_dumpable,
69730 .maxlen = sizeof(int),
69731 .mode = 0644,
69732 - .proc_handler = proc_dointvec_minmax,
69733 + .proc_handler = proc_dointvec_minmax_coredump,
69734 .extra1 = &zero,
69735 .extra2 = &two,
69736 },
69737 @@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69738 buffer, lenp, ppos);
69739 }
69740
69741 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69742 + void __user *buffer, size_t *lenp, loff_t *ppos)
69743 +{
69744 + if (write && !capable(CAP_SYS_MODULE))
69745 + return -EPERM;
69746 +
69747 + return _proc_do_string(table->data, table->maxlen, write,
69748 + buffer, lenp, ppos);
69749 +}
69750 +
69751 static size_t proc_skip_spaces(char **buf)
69752 {
69753 size_t ret;
69754 @@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69755 len = strlen(tmp);
69756 if (len > *size)
69757 len = *size;
69758 + if (len > sizeof(tmp))
69759 + len = sizeof(tmp);
69760 if (copy_to_user(*buf, tmp, len))
69761 return -EFAULT;
69762 *size -= len;
69763 @@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69764 return err;
69765 }
69766
69767 -#ifdef CONFIG_PRINTK
69768 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69769 void __user *buffer, size_t *lenp, loff_t *ppos)
69770 {
69771 @@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69772
69773 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69774 }
69775 -#endif
69776
69777 struct do_proc_dointvec_minmax_conv_param {
69778 int *min;
69779 @@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69780 do_proc_dointvec_minmax_conv, &param);
69781 }
69782
69783 +static void validate_coredump_safety(void)
69784 +{
69785 + if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69786 + core_pattern[0] != '/' && core_pattern[0] != '|') {
69787 + printk(KERN_WARNING "Unsafe core_pattern used with "\
69788 + "suid_dumpable=2. Pipe handler or fully qualified "\
69789 + "core dump path required.\n");
69790 + }
69791 +}
69792 +
69793 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69794 + void __user *buffer, size_t *lenp, loff_t *ppos)
69795 +{
69796 + int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69797 + if (!error)
69798 + validate_coredump_safety();
69799 + return error;
69800 +}
69801 +
69802 +static int proc_dostring_coredump(struct ctl_table *table, int write,
69803 + void __user *buffer, size_t *lenp, loff_t *ppos)
69804 +{
69805 + int error = proc_dostring(table, write, buffer, lenp, ppos);
69806 + if (!error)
69807 + validate_coredump_safety();
69808 + return error;
69809 +}
69810 +
69811 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69812 void __user *buffer,
69813 size_t *lenp, loff_t *ppos,
69814 @@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69815 *i = val;
69816 } else {
69817 val = convdiv * (*i) / convmul;
69818 - if (!first)
69819 + if (!first) {
69820 err = proc_put_char(&buffer, &left, '\t');
69821 + if (err)
69822 + break;
69823 + }
69824 err = proc_put_long(&buffer, &left, val, false);
69825 if (err)
69826 break;
69827 @@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69828 return -ENOSYS;
69829 }
69830
69831 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69832 + void __user *buffer, size_t *lenp, loff_t *ppos)
69833 +{
69834 + return -ENOSYS;
69835 +}
69836 +
69837 int proc_dointvec(struct ctl_table *table, int write,
69838 void __user *buffer, size_t *lenp, loff_t *ppos)
69839 {
69840 @@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69841 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69842 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69843 EXPORT_SYMBOL(proc_dostring);
69844 +EXPORT_SYMBOL(proc_dostring_modpriv);
69845 EXPORT_SYMBOL(proc_doulongvec_minmax);
69846 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69847 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69848 index a650694..aaeeb20 100644
69849 --- a/kernel/sysctl_binary.c
69850 +++ b/kernel/sysctl_binary.c
69851 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69852 int i;
69853
69854 set_fs(KERNEL_DS);
69855 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69856 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69857 set_fs(old_fs);
69858 if (result < 0)
69859 goto out_kfree;
69860 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69861 }
69862
69863 set_fs(KERNEL_DS);
69864 - result = vfs_write(file, buffer, str - buffer, &pos);
69865 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69866 set_fs(old_fs);
69867 if (result < 0)
69868 goto out_kfree;
69869 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69870 int i;
69871
69872 set_fs(KERNEL_DS);
69873 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69874 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69875 set_fs(old_fs);
69876 if (result < 0)
69877 goto out_kfree;
69878 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69879 }
69880
69881 set_fs(KERNEL_DS);
69882 - result = vfs_write(file, buffer, str - buffer, &pos);
69883 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69884 set_fs(old_fs);
69885 if (result < 0)
69886 goto out_kfree;
69887 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69888 int i;
69889
69890 set_fs(KERNEL_DS);
69891 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69892 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69893 set_fs(old_fs);
69894 if (result < 0)
69895 goto out;
69896 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69897 __le16 dnaddr;
69898
69899 set_fs(KERNEL_DS);
69900 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69901 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69902 set_fs(old_fs);
69903 if (result < 0)
69904 goto out;
69905 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69906 le16_to_cpu(dnaddr) & 0x3ff);
69907
69908 set_fs(KERNEL_DS);
69909 - result = vfs_write(file, buf, len, &pos);
69910 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69911 set_fs(old_fs);
69912 if (result < 0)
69913 goto out;
69914 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69915 index e660464..c8b9e67 100644
69916 --- a/kernel/taskstats.c
69917 +++ b/kernel/taskstats.c
69918 @@ -27,9 +27,12 @@
69919 #include <linux/cgroup.h>
69920 #include <linux/fs.h>
69921 #include <linux/file.h>
69922 +#include <linux/grsecurity.h>
69923 #include <net/genetlink.h>
69924 #include <linux/atomic.h>
69925
69926 +extern int gr_is_taskstats_denied(int pid);
69927 +
69928 /*
69929 * Maximum length of a cpumask that can be specified in
69930 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69931 @@ -556,6 +559,9 @@ err:
69932
69933 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69934 {
69935 + if (gr_is_taskstats_denied(current->pid))
69936 + return -EACCES;
69937 +
69938 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69939 return cmd_attr_register_cpumask(info);
69940 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69941 diff --git a/kernel/time.c b/kernel/time.c
69942 index ba744cf..267b7c5 100644
69943 --- a/kernel/time.c
69944 +++ b/kernel/time.c
69945 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69946 return error;
69947
69948 if (tz) {
69949 + /* we log in do_settimeofday called below, so don't log twice
69950 + */
69951 + if (!tv)
69952 + gr_log_timechange();
69953 +
69954 sys_tz = *tz;
69955 update_vsyscall_tz();
69956 if (firsttime) {
69957 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69958 index aa27d39..34d221c 100644
69959 --- a/kernel/time/alarmtimer.c
69960 +++ b/kernel/time/alarmtimer.c
69961 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
69962 struct platform_device *pdev;
69963 int error = 0;
69964 int i;
69965 - struct k_clock alarm_clock = {
69966 + static struct k_clock alarm_clock = {
69967 .clock_getres = alarm_clock_getres,
69968 .clock_get = alarm_clock_get,
69969 .timer_create = alarm_timer_create,
69970 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69971 index f113755..ec24223 100644
69972 --- a/kernel/time/tick-broadcast.c
69973 +++ b/kernel/time/tick-broadcast.c
69974 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69975 * then clear the broadcast bit.
69976 */
69977 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69978 - int cpu = smp_processor_id();
69979 + cpu = smp_processor_id();
69980
69981 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69982 tick_broadcast_clear_oneshot(cpu);
69983 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69984 index 3447cfa..291806b 100644
69985 --- a/kernel/time/timekeeping.c
69986 +++ b/kernel/time/timekeeping.c
69987 @@ -14,6 +14,7 @@
69988 #include <linux/init.h>
69989 #include <linux/mm.h>
69990 #include <linux/sched.h>
69991 +#include <linux/grsecurity.h>
69992 #include <linux/syscore_ops.h>
69993 #include <linux/clocksource.h>
69994 #include <linux/jiffies.h>
69995 @@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
69996 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69997 return -EINVAL;
69998
69999 + gr_log_timechange();
70000 +
70001 write_seqlock_irqsave(&timekeeper.lock, flags);
70002
70003 timekeeping_forward_now();
70004 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70005 index 3258455..f35227d 100644
70006 --- a/kernel/time/timer_list.c
70007 +++ b/kernel/time/timer_list.c
70008 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70009
70010 static void print_name_offset(struct seq_file *m, void *sym)
70011 {
70012 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70013 + SEQ_printf(m, "<%p>", NULL);
70014 +#else
70015 char symname[KSYM_NAME_LEN];
70016
70017 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70018 SEQ_printf(m, "<%pK>", sym);
70019 else
70020 SEQ_printf(m, "%s", symname);
70021 +#endif
70022 }
70023
70024 static void
70025 @@ -112,7 +116,11 @@ next_one:
70026 static void
70027 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70028 {
70029 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70030 + SEQ_printf(m, " .base: %p\n", NULL);
70031 +#else
70032 SEQ_printf(m, " .base: %pK\n", base);
70033 +#endif
70034 SEQ_printf(m, " .index: %d\n",
70035 base->index);
70036 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70037 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70038 {
70039 struct proc_dir_entry *pe;
70040
70041 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70042 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70043 +#else
70044 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70045 +#endif
70046 if (!pe)
70047 return -ENOMEM;
70048 return 0;
70049 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70050 index 0b537f2..9e71eca 100644
70051 --- a/kernel/time/timer_stats.c
70052 +++ b/kernel/time/timer_stats.c
70053 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70054 static unsigned long nr_entries;
70055 static struct entry entries[MAX_ENTRIES];
70056
70057 -static atomic_t overflow_count;
70058 +static atomic_unchecked_t overflow_count;
70059
70060 /*
70061 * The entries are in a hash-table, for fast lookup:
70062 @@ -140,7 +140,7 @@ static void reset_entries(void)
70063 nr_entries = 0;
70064 memset(entries, 0, sizeof(entries));
70065 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70066 - atomic_set(&overflow_count, 0);
70067 + atomic_set_unchecked(&overflow_count, 0);
70068 }
70069
70070 static struct entry *alloc_entry(void)
70071 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70072 if (likely(entry))
70073 entry->count++;
70074 else
70075 - atomic_inc(&overflow_count);
70076 + atomic_inc_unchecked(&overflow_count);
70077
70078 out_unlock:
70079 raw_spin_unlock_irqrestore(lock, flags);
70080 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70081
70082 static void print_name_offset(struct seq_file *m, unsigned long addr)
70083 {
70084 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70085 + seq_printf(m, "<%p>", NULL);
70086 +#else
70087 char symname[KSYM_NAME_LEN];
70088
70089 if (lookup_symbol_name(addr, symname) < 0)
70090 seq_printf(m, "<%p>", (void *)addr);
70091 else
70092 seq_printf(m, "%s", symname);
70093 +#endif
70094 }
70095
70096 static int tstats_show(struct seq_file *m, void *v)
70097 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70098
70099 seq_puts(m, "Timer Stats Version: v0.2\n");
70100 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70101 - if (atomic_read(&overflow_count))
70102 + if (atomic_read_unchecked(&overflow_count))
70103 seq_printf(m, "Overflow: %d entries\n",
70104 - atomic_read(&overflow_count));
70105 + atomic_read_unchecked(&overflow_count));
70106
70107 for (i = 0; i < nr_entries; i++) {
70108 entry = entries + i;
70109 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70110 {
70111 struct proc_dir_entry *pe;
70112
70113 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70114 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70115 +#else
70116 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70117 +#endif
70118 if (!pe)
70119 return -ENOMEM;
70120 return 0;
70121 diff --git a/kernel/timer.c b/kernel/timer.c
70122 index 6ec7e7e..cbc448b 100644
70123 --- a/kernel/timer.c
70124 +++ b/kernel/timer.c
70125 @@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70126 /*
70127 * This function runs timers and the timer-tq in bottom half context.
70128 */
70129 -static void run_timer_softirq(struct softirq_action *h)
70130 +static void run_timer_softirq(void)
70131 {
70132 struct tvec_base *base = __this_cpu_read(tvec_bases);
70133
70134 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70135 index c0bd030..62a1927 100644
70136 --- a/kernel/trace/blktrace.c
70137 +++ b/kernel/trace/blktrace.c
70138 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70139 struct blk_trace *bt = filp->private_data;
70140 char buf[16];
70141
70142 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70143 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70144
70145 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70146 }
70147 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70148 return 1;
70149
70150 bt = buf->chan->private_data;
70151 - atomic_inc(&bt->dropped);
70152 + atomic_inc_unchecked(&bt->dropped);
70153 return 0;
70154 }
70155
70156 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70157
70158 bt->dir = dir;
70159 bt->dev = dev;
70160 - atomic_set(&bt->dropped, 0);
70161 + atomic_set_unchecked(&bt->dropped, 0);
70162
70163 ret = -EIO;
70164 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70165 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70166 index a008663..30d7429 100644
70167 --- a/kernel/trace/ftrace.c
70168 +++ b/kernel/trace/ftrace.c
70169 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70170 if (unlikely(ftrace_disabled))
70171 return 0;
70172
70173 + ret = ftrace_arch_code_modify_prepare();
70174 + FTRACE_WARN_ON(ret);
70175 + if (ret)
70176 + return 0;
70177 +
70178 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70179 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70180 if (ret) {
70181 ftrace_bug(ret, ip);
70182 - return 0;
70183 }
70184 - return 1;
70185 + return ret ? 0 : 1;
70186 }
70187
70188 /*
70189 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70190
70191 int
70192 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70193 - void *data)
70194 + void *data)
70195 {
70196 struct ftrace_func_probe *entry;
70197 struct ftrace_page *pg;
70198 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70199 if (!count)
70200 return 0;
70201
70202 + pax_open_kernel();
70203 sort(start, count, sizeof(*start),
70204 ftrace_cmp_ips, ftrace_swap_ips);
70205 + pax_close_kernel();
70206
70207 start_pg = ftrace_allocate_pages(count);
70208 if (!start_pg)
70209 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70210 index a7fa070..403bc8d 100644
70211 --- a/kernel/trace/trace.c
70212 +++ b/kernel/trace/trace.c
70213 @@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70214 };
70215 #endif
70216
70217 -static struct dentry *d_tracer;
70218 -
70219 struct dentry *tracing_init_dentry(void)
70220 {
70221 + static struct dentry *d_tracer;
70222 static int once;
70223
70224 if (d_tracer)
70225 @@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70226 return d_tracer;
70227 }
70228
70229 -static struct dentry *d_percpu;
70230 -
70231 struct dentry *tracing_dentry_percpu(void)
70232 {
70233 + static struct dentry *d_percpu;
70234 static int once;
70235 struct dentry *d_tracer;
70236
70237 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70238 index 29111da..d190fe2 100644
70239 --- a/kernel/trace/trace_events.c
70240 +++ b/kernel/trace/trace_events.c
70241 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70242 struct ftrace_module_file_ops {
70243 struct list_head list;
70244 struct module *mod;
70245 - struct file_operations id;
70246 - struct file_operations enable;
70247 - struct file_operations format;
70248 - struct file_operations filter;
70249 };
70250
70251 static struct ftrace_module_file_ops *
70252 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70253
70254 file_ops->mod = mod;
70255
70256 - file_ops->id = ftrace_event_id_fops;
70257 - file_ops->id.owner = mod;
70258 -
70259 - file_ops->enable = ftrace_enable_fops;
70260 - file_ops->enable.owner = mod;
70261 -
70262 - file_ops->filter = ftrace_event_filter_fops;
70263 - file_ops->filter.owner = mod;
70264 -
70265 - file_ops->format = ftrace_event_format_fops;
70266 - file_ops->format.owner = mod;
70267 + pax_open_kernel();
70268 + *(void **)&mod->trace_id.owner = mod;
70269 + *(void **)&mod->trace_enable.owner = mod;
70270 + *(void **)&mod->trace_filter.owner = mod;
70271 + *(void **)&mod->trace_format.owner = mod;
70272 + pax_close_kernel();
70273
70274 list_add(&file_ops->list, &ftrace_module_file_list);
70275
70276 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70277
70278 for_each_event(call, start, end) {
70279 __trace_add_event_call(*call, mod,
70280 - &file_ops->id, &file_ops->enable,
70281 - &file_ops->filter, &file_ops->format);
70282 + &mod->trace_id, &mod->trace_enable,
70283 + &mod->trace_filter, &mod->trace_format);
70284 }
70285 }
70286
70287 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70288 index fd3c8aa..5f324a6 100644
70289 --- a/kernel/trace/trace_mmiotrace.c
70290 +++ b/kernel/trace/trace_mmiotrace.c
70291 @@ -24,7 +24,7 @@ struct header_iter {
70292 static struct trace_array *mmio_trace_array;
70293 static bool overrun_detected;
70294 static unsigned long prev_overruns;
70295 -static atomic_t dropped_count;
70296 +static atomic_unchecked_t dropped_count;
70297
70298 static void mmio_reset_data(struct trace_array *tr)
70299 {
70300 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70301
70302 static unsigned long count_overruns(struct trace_iterator *iter)
70303 {
70304 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70305 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70306 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70307
70308 if (over > prev_overruns)
70309 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70310 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70311 sizeof(*entry), 0, pc);
70312 if (!event) {
70313 - atomic_inc(&dropped_count);
70314 + atomic_inc_unchecked(&dropped_count);
70315 return;
70316 }
70317 entry = ring_buffer_event_data(event);
70318 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70319 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70320 sizeof(*entry), 0, pc);
70321 if (!event) {
70322 - atomic_inc(&dropped_count);
70323 + atomic_inc_unchecked(&dropped_count);
70324 return;
70325 }
70326 entry = ring_buffer_event_data(event);
70327 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70328 index df611a0..10d8b32 100644
70329 --- a/kernel/trace/trace_output.c
70330 +++ b/kernel/trace/trace_output.c
70331 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70332
70333 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70334 if (!IS_ERR(p)) {
70335 - p = mangle_path(s->buffer + s->len, p, "\n");
70336 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70337 if (p) {
70338 s->len = p - s->buffer;
70339 return 1;
70340 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70341 index d4545f4..a9010a1 100644
70342 --- a/kernel/trace/trace_stack.c
70343 +++ b/kernel/trace/trace_stack.c
70344 @@ -53,7 +53,7 @@ static inline void check_stack(void)
70345 return;
70346
70347 /* we do not handle interrupt stacks yet */
70348 - if (!object_is_on_stack(&this_size))
70349 + if (!object_starts_on_stack(&this_size))
70350 return;
70351
70352 local_irq_save(flags);
70353 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70354 index ff5bdee..3eaeba6 100644
70355 --- a/lib/Kconfig.debug
70356 +++ b/lib/Kconfig.debug
70357 @@ -1165,6 +1165,7 @@ config LATENCYTOP
70358 depends on DEBUG_KERNEL
70359 depends on STACKTRACE_SUPPORT
70360 depends on PROC_FS
70361 + depends on !GRKERNSEC_HIDESYM
70362 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70363 select KALLSYMS
70364 select KALLSYMS_ALL
70365 diff --git a/lib/bitmap.c b/lib/bitmap.c
70366 index 06fdfa1..97c5c7d 100644
70367 --- a/lib/bitmap.c
70368 +++ b/lib/bitmap.c
70369 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70370 {
70371 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70372 u32 chunk;
70373 - const char __user __force *ubuf = (const char __user __force *)buf;
70374 + const char __user *ubuf = (const char __force_user *)buf;
70375
70376 bitmap_zero(maskp, nmaskbits);
70377
70378 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70379 {
70380 if (!access_ok(VERIFY_READ, ubuf, ulen))
70381 return -EFAULT;
70382 - return __bitmap_parse((const char __force *)ubuf,
70383 + return __bitmap_parse((const char __force_kernel *)ubuf,
70384 ulen, 1, maskp, nmaskbits);
70385
70386 }
70387 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70388 {
70389 unsigned a, b;
70390 int c, old_c, totaldigits;
70391 - const char __user __force *ubuf = (const char __user __force *)buf;
70392 + const char __user *ubuf = (const char __force_user *)buf;
70393 int exp_digit, in_range;
70394
70395 totaldigits = c = 0;
70396 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70397 {
70398 if (!access_ok(VERIFY_READ, ubuf, ulen))
70399 return -EFAULT;
70400 - return __bitmap_parselist((const char __force *)ubuf,
70401 + return __bitmap_parselist((const char __force_kernel *)ubuf,
70402 ulen, 1, maskp, nmaskbits);
70403 }
70404 EXPORT_SYMBOL(bitmap_parselist_user);
70405 diff --git a/lib/bug.c b/lib/bug.c
70406 index a28c141..2bd3d95 100644
70407 --- a/lib/bug.c
70408 +++ b/lib/bug.c
70409 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70410 return BUG_TRAP_TYPE_NONE;
70411
70412 bug = find_bug(bugaddr);
70413 + if (!bug)
70414 + return BUG_TRAP_TYPE_NONE;
70415
70416 file = NULL;
70417 line = 0;
70418 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70419 index d11808c..dc2d6f8 100644
70420 --- a/lib/debugobjects.c
70421 +++ b/lib/debugobjects.c
70422 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70423 if (limit > 4)
70424 return;
70425
70426 - is_on_stack = object_is_on_stack(addr);
70427 + is_on_stack = object_starts_on_stack(addr);
70428 if (is_on_stack == onstack)
70429 return;
70430
70431 diff --git a/lib/devres.c b/lib/devres.c
70432 index 80b9c76..9e32279 100644
70433 --- a/lib/devres.c
70434 +++ b/lib/devres.c
70435 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70436 void devm_iounmap(struct device *dev, void __iomem *addr)
70437 {
70438 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70439 - (void *)addr));
70440 + (void __force *)addr));
70441 iounmap(addr);
70442 }
70443 EXPORT_SYMBOL(devm_iounmap);
70444 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70445 {
70446 ioport_unmap(addr);
70447 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70448 - devm_ioport_map_match, (void *)addr));
70449 + devm_ioport_map_match, (void __force *)addr));
70450 }
70451 EXPORT_SYMBOL(devm_ioport_unmap);
70452
70453 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70454 index 66ce414..6f0a0dd 100644
70455 --- a/lib/dma-debug.c
70456 +++ b/lib/dma-debug.c
70457 @@ -924,7 +924,7 @@ out:
70458
70459 static void check_for_stack(struct device *dev, void *addr)
70460 {
70461 - if (object_is_on_stack(addr))
70462 + if (object_starts_on_stack(addr))
70463 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70464 "stack [addr=%p]\n", addr);
70465 }
70466 diff --git a/lib/extable.c b/lib/extable.c
70467 index 4cac81e..4d66cfc 100644
70468 --- a/lib/extable.c
70469 +++ b/lib/extable.c
70470 @@ -13,6 +13,7 @@
70471 #include <linux/init.h>
70472 #include <linux/sort.h>
70473 #include <asm/uaccess.h>
70474 +#include <asm/pgtable.h>
70475
70476 #ifndef ARCH_HAS_SORT_EXTABLE
70477 /*
70478 diff --git a/lib/inflate.c b/lib/inflate.c
70479 index 013a761..c28f3fc 100644
70480 --- a/lib/inflate.c
70481 +++ b/lib/inflate.c
70482 @@ -269,7 +269,7 @@ static void free(void *where)
70483 malloc_ptr = free_mem_ptr;
70484 }
70485 #else
70486 -#define malloc(a) kmalloc(a, GFP_KERNEL)
70487 +#define malloc(a) kmalloc((a), GFP_KERNEL)
70488 #define free(a) kfree(a)
70489 #endif
70490
70491 diff --git a/lib/ioremap.c b/lib/ioremap.c
70492 index 0c9216c..863bd89 100644
70493 --- a/lib/ioremap.c
70494 +++ b/lib/ioremap.c
70495 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70496 unsigned long next;
70497
70498 phys_addr -= addr;
70499 - pmd = pmd_alloc(&init_mm, pud, addr);
70500 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70501 if (!pmd)
70502 return -ENOMEM;
70503 do {
70504 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70505 unsigned long next;
70506
70507 phys_addr -= addr;
70508 - pud = pud_alloc(&init_mm, pgd, addr);
70509 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
70510 if (!pud)
70511 return -ENOMEM;
70512 do {
70513 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70514 index bd2bea9..6b3c95e 100644
70515 --- a/lib/is_single_threaded.c
70516 +++ b/lib/is_single_threaded.c
70517 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70518 struct task_struct *p, *t;
70519 bool ret;
70520
70521 + if (!mm)
70522 + return true;
70523 +
70524 if (atomic_read(&task->signal->live) != 1)
70525 return false;
70526
70527 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70528 index e796429..6e38f9f 100644
70529 --- a/lib/radix-tree.c
70530 +++ b/lib/radix-tree.c
70531 @@ -92,7 +92,7 @@ struct radix_tree_preload {
70532 int nr;
70533 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70534 };
70535 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70536 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70537
70538 static inline void *ptr_to_indirect(void *ptr)
70539 {
70540 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70541 index c3f36d41..5c5aeb5 100644
70542 --- a/lib/vsprintf.c
70543 +++ b/lib/vsprintf.c
70544 @@ -16,6 +16,9 @@
70545 * - scnprintf and vscnprintf
70546 */
70547
70548 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70549 +#define __INCLUDED_BY_HIDESYM 1
70550 +#endif
70551 #include <stdarg.h>
70552 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70553 #include <linux/types.h>
70554 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70555 char sym[KSYM_SYMBOL_LEN];
70556 if (ext == 'B')
70557 sprint_backtrace(sym, value);
70558 - else if (ext != 'f' && ext != 's')
70559 + else if (ext != 'f' && ext != 's' && ext != 'a')
70560 sprint_symbol(sym, value);
70561 else
70562 sprint_symbol_no_offset(sym, value);
70563 @@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70564 return number(buf, end, *(const netdev_features_t *)addr, spec);
70565 }
70566
70567 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70568 +int kptr_restrict __read_mostly = 2;
70569 +#else
70570 int kptr_restrict __read_mostly;
70571 +#endif
70572
70573 /*
70574 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70575 @@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70576 * - 'S' For symbolic direct pointers with offset
70577 * - 's' For symbolic direct pointers without offset
70578 * - 'B' For backtraced symbolic direct pointers with offset
70579 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70580 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70581 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70582 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70583 * - 'M' For a 6-byte MAC address, it prints the address in the
70584 @@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70585
70586 if (!ptr && *fmt != 'K') {
70587 /*
70588 - * Print (null) with the same width as a pointer so it makes
70589 + * Print (nil) with the same width as a pointer so it makes
70590 * tabular output look nice.
70591 */
70592 if (spec.field_width == -1)
70593 spec.field_width = default_width;
70594 - return string(buf, end, "(null)", spec);
70595 + return string(buf, end, "(nil)", spec);
70596 }
70597
70598 switch (*fmt) {
70599 @@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70600 /* Fallthrough */
70601 case 'S':
70602 case 's':
70603 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70604 + break;
70605 +#else
70606 + return symbol_string(buf, end, ptr, spec, *fmt);
70607 +#endif
70608 + case 'A':
70609 + case 'a':
70610 case 'B':
70611 return symbol_string(buf, end, ptr, spec, *fmt);
70612 case 'R':
70613 @@ -1025,12 +1041,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70614 va_end(va);
70615 return buf;
70616 }
70617 + case 'P':
70618 + break;
70619 case 'K':
70620 /*
70621 * %pK cannot be used in IRQ context because its test
70622 * for CAP_SYSLOG would be meaningless.
70623 */
70624 - if (in_irq() || in_serving_softirq() || in_nmi()) {
70625 + if (kptr_restrict && (in_irq() || in_serving_softirq() ||
70626 + in_nmi())) {
70627 if (spec.field_width == -1)
70628 spec.field_width = default_width;
70629 return string(buf, end, "pK-error", spec);
70630 @@ -1047,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70631 }
70632 break;
70633 }
70634 +
70635 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70636 + /* 'P' = approved pointers to copy to userland,
70637 + as in the /proc/kallsyms case, as we make it display nothing
70638 + for non-root users, and the real contents for root users
70639 + Also ignore 'K' pointers, since we force their NULLing for non-root users
70640 + above
70641 + */
70642 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70643 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70644 + dump_stack();
70645 + ptr = NULL;
70646 + }
70647 +#endif
70648 +
70649 spec.flags |= SMALL;
70650 if (spec.field_width == -1) {
70651 spec.field_width = default_width;
70652 @@ -1758,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70653 typeof(type) value; \
70654 if (sizeof(type) == 8) { \
70655 args = PTR_ALIGN(args, sizeof(u32)); \
70656 - *(u32 *)&value = *(u32 *)args; \
70657 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70658 + *(u32 *)&value = *(const u32 *)args; \
70659 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70660 } else { \
70661 args = PTR_ALIGN(args, sizeof(type)); \
70662 - value = *(typeof(type) *)args; \
70663 + value = *(const typeof(type) *)args; \
70664 } \
70665 args += sizeof(type); \
70666 value; \
70667 @@ -1825,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70668 case FORMAT_TYPE_STR: {
70669 const char *str_arg = args;
70670 args += strlen(str_arg) + 1;
70671 - str = string(str, end, (char *)str_arg, spec);
70672 + str = string(str, end, str_arg, spec);
70673 break;
70674 }
70675
70676 diff --git a/localversion-grsec b/localversion-grsec
70677 new file mode 100644
70678 index 0000000..7cd6065
70679 --- /dev/null
70680 +++ b/localversion-grsec
70681 @@ -0,0 +1 @@
70682 +-grsec
70683 diff --git a/mm/Kconfig b/mm/Kconfig
70684 index 82fed4e..979e814 100644
70685 --- a/mm/Kconfig
70686 +++ b/mm/Kconfig
70687 @@ -247,10 +247,10 @@ config KSM
70688 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70689
70690 config DEFAULT_MMAP_MIN_ADDR
70691 - int "Low address space to protect from user allocation"
70692 + int "Low address space to protect from user allocation"
70693 depends on MMU
70694 - default 4096
70695 - help
70696 + default 65536
70697 + help
70698 This is the portion of low virtual memory which should be protected
70699 from userspace allocation. Keeping a user from writing to low pages
70700 can help reduce the impact of kernel NULL pointer bugs.
70701 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
70702
70703 config HWPOISON_INJECT
70704 tristate "HWPoison pages injector"
70705 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70706 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70707 select PROC_PAGE_MONITOR
70708
70709 config NOMMU_INITIAL_TRIM_EXCESS
70710 diff --git a/mm/filemap.c b/mm/filemap.c
70711 index a4a5260..6151dc5 100644
70712 --- a/mm/filemap.c
70713 +++ b/mm/filemap.c
70714 @@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70715 struct address_space *mapping = file->f_mapping;
70716
70717 if (!mapping->a_ops->readpage)
70718 - return -ENOEXEC;
70719 + return -ENODEV;
70720 file_accessed(file);
70721 vma->vm_ops = &generic_file_vm_ops;
70722 vma->vm_flags |= VM_CAN_NONLINEAR;
70723 @@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70724 *pos = i_size_read(inode);
70725
70726 if (limit != RLIM_INFINITY) {
70727 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70728 if (*pos >= limit) {
70729 send_sig(SIGXFSZ, current, 0);
70730 return -EFBIG;
70731 diff --git a/mm/fremap.c b/mm/fremap.c
70732 index 9ed4fd4..c42648d 100644
70733 --- a/mm/fremap.c
70734 +++ b/mm/fremap.c
70735 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70736 retry:
70737 vma = find_vma(mm, start);
70738
70739 +#ifdef CONFIG_PAX_SEGMEXEC
70740 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70741 + goto out;
70742 +#endif
70743 +
70744 /*
70745 * Make sure the vma is shared, that it supports prefaulting,
70746 * and that the remapped range is valid and fully within
70747 diff --git a/mm/highmem.c b/mm/highmem.c
70748 index 57d82c6..e9e0552 100644
70749 --- a/mm/highmem.c
70750 +++ b/mm/highmem.c
70751 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70752 * So no dangers, even with speculative execution.
70753 */
70754 page = pte_page(pkmap_page_table[i]);
70755 + pax_open_kernel();
70756 pte_clear(&init_mm, (unsigned long)page_address(page),
70757 &pkmap_page_table[i]);
70758 -
70759 + pax_close_kernel();
70760 set_page_address(page, NULL);
70761 need_flush = 1;
70762 }
70763 @@ -186,9 +187,11 @@ start:
70764 }
70765 }
70766 vaddr = PKMAP_ADDR(last_pkmap_nr);
70767 +
70768 + pax_open_kernel();
70769 set_pte_at(&init_mm, vaddr,
70770 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70771 -
70772 + pax_close_kernel();
70773 pkmap_count[last_pkmap_nr] = 1;
70774 set_page_address(page, (void *)vaddr);
70775
70776 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70777 index 57c4b93..24b8f59 100644
70778 --- a/mm/huge_memory.c
70779 +++ b/mm/huge_memory.c
70780 @@ -735,7 +735,7 @@ out:
70781 * run pte_offset_map on the pmd, if an huge pmd could
70782 * materialize from under us from a different thread.
70783 */
70784 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70785 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70786 return VM_FAULT_OOM;
70787 /* if an huge pmd materialized from under us just retry later */
70788 if (unlikely(pmd_trans_huge(*pmd)))
70789 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70790 index e198831..38d524f 100644
70791 --- a/mm/hugetlb.c
70792 +++ b/mm/hugetlb.c
70793 @@ -2447,6 +2447,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70794 return 1;
70795 }
70796
70797 +#ifdef CONFIG_PAX_SEGMEXEC
70798 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70799 +{
70800 + struct mm_struct *mm = vma->vm_mm;
70801 + struct vm_area_struct *vma_m;
70802 + unsigned long address_m;
70803 + pte_t *ptep_m;
70804 +
70805 + vma_m = pax_find_mirror_vma(vma);
70806 + if (!vma_m)
70807 + return;
70808 +
70809 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70810 + address_m = address + SEGMEXEC_TASK_SIZE;
70811 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70812 + get_page(page_m);
70813 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70814 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70815 +}
70816 +#endif
70817 +
70818 /*
70819 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70820 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70821 @@ -2559,6 +2580,11 @@ retry_avoidcopy:
70822 make_huge_pte(vma, new_page, 1));
70823 page_remove_rmap(old_page);
70824 hugepage_add_new_anon_rmap(new_page, vma, address);
70825 +
70826 +#ifdef CONFIG_PAX_SEGMEXEC
70827 + pax_mirror_huge_pte(vma, address, new_page);
70828 +#endif
70829 +
70830 /* Make the old page be freed below */
70831 new_page = old_page;
70832 mmu_notifier_invalidate_range_end(mm,
70833 @@ -2713,6 +2739,10 @@ retry:
70834 && (vma->vm_flags & VM_SHARED)));
70835 set_huge_pte_at(mm, address, ptep, new_pte);
70836
70837 +#ifdef CONFIG_PAX_SEGMEXEC
70838 + pax_mirror_huge_pte(vma, address, page);
70839 +#endif
70840 +
70841 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70842 /* Optimization, do the COW without a second fault */
70843 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70844 @@ -2742,6 +2772,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70845 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70846 struct hstate *h = hstate_vma(vma);
70847
70848 +#ifdef CONFIG_PAX_SEGMEXEC
70849 + struct vm_area_struct *vma_m;
70850 +#endif
70851 +
70852 address &= huge_page_mask(h);
70853
70854 ptep = huge_pte_offset(mm, address);
70855 @@ -2755,6 +2789,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70856 VM_FAULT_SET_HINDEX(h - hstates);
70857 }
70858
70859 +#ifdef CONFIG_PAX_SEGMEXEC
70860 + vma_m = pax_find_mirror_vma(vma);
70861 + if (vma_m) {
70862 + unsigned long address_m;
70863 +
70864 + if (vma->vm_start > vma_m->vm_start) {
70865 + address_m = address;
70866 + address -= SEGMEXEC_TASK_SIZE;
70867 + vma = vma_m;
70868 + h = hstate_vma(vma);
70869 + } else
70870 + address_m = address + SEGMEXEC_TASK_SIZE;
70871 +
70872 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70873 + return VM_FAULT_OOM;
70874 + address_m &= HPAGE_MASK;
70875 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70876 + }
70877 +#endif
70878 +
70879 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70880 if (!ptep)
70881 return VM_FAULT_OOM;
70882 diff --git a/mm/internal.h b/mm/internal.h
70883 index 2ba87fb..7f451e2 100644
70884 --- a/mm/internal.h
70885 +++ b/mm/internal.h
70886 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70887 * in mm/page_alloc.c
70888 */
70889 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70890 +extern void free_compound_page(struct page *page);
70891 extern void prep_compound_page(struct page *page, unsigned long order);
70892 #ifdef CONFIG_MEMORY_FAILURE
70893 extern bool is_free_buddy_page(struct page *page);
70894 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70895 index 45eb621..6ccd8ea 100644
70896 --- a/mm/kmemleak.c
70897 +++ b/mm/kmemleak.c
70898 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70899
70900 for (i = 0; i < object->trace_len; i++) {
70901 void *ptr = (void *)object->trace[i];
70902 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70903 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70904 }
70905 }
70906
70907 diff --git a/mm/maccess.c b/mm/maccess.c
70908 index d53adf9..03a24bf 100644
70909 --- a/mm/maccess.c
70910 +++ b/mm/maccess.c
70911 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70912 set_fs(KERNEL_DS);
70913 pagefault_disable();
70914 ret = __copy_from_user_inatomic(dst,
70915 - (__force const void __user *)src, size);
70916 + (const void __force_user *)src, size);
70917 pagefault_enable();
70918 set_fs(old_fs);
70919
70920 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70921
70922 set_fs(KERNEL_DS);
70923 pagefault_disable();
70924 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70925 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70926 pagefault_enable();
70927 set_fs(old_fs);
70928
70929 diff --git a/mm/madvise.c b/mm/madvise.c
70930 index 14d260f..b2a80fd 100644
70931 --- a/mm/madvise.c
70932 +++ b/mm/madvise.c
70933 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70934 pgoff_t pgoff;
70935 unsigned long new_flags = vma->vm_flags;
70936
70937 +#ifdef CONFIG_PAX_SEGMEXEC
70938 + struct vm_area_struct *vma_m;
70939 +#endif
70940 +
70941 switch (behavior) {
70942 case MADV_NORMAL:
70943 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70944 @@ -119,6 +123,13 @@ success:
70945 /*
70946 * vm_flags is protected by the mmap_sem held in write mode.
70947 */
70948 +
70949 +#ifdef CONFIG_PAX_SEGMEXEC
70950 + vma_m = pax_find_mirror_vma(vma);
70951 + if (vma_m)
70952 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70953 +#endif
70954 +
70955 vma->vm_flags = new_flags;
70956
70957 out:
70958 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70959 struct vm_area_struct ** prev,
70960 unsigned long start, unsigned long end)
70961 {
70962 +
70963 +#ifdef CONFIG_PAX_SEGMEXEC
70964 + struct vm_area_struct *vma_m;
70965 +#endif
70966 +
70967 *prev = vma;
70968 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70969 return -EINVAL;
70970 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70971 zap_page_range(vma, start, end - start, &details);
70972 } else
70973 zap_page_range(vma, start, end - start, NULL);
70974 +
70975 +#ifdef CONFIG_PAX_SEGMEXEC
70976 + vma_m = pax_find_mirror_vma(vma);
70977 + if (vma_m) {
70978 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70979 + struct zap_details details = {
70980 + .nonlinear_vma = vma_m,
70981 + .last_index = ULONG_MAX,
70982 + };
70983 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70984 + } else
70985 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70986 + }
70987 +#endif
70988 +
70989 return 0;
70990 }
70991
70992 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70993 if (end < start)
70994 goto out;
70995
70996 +#ifdef CONFIG_PAX_SEGMEXEC
70997 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70998 + if (end > SEGMEXEC_TASK_SIZE)
70999 + goto out;
71000 + } else
71001 +#endif
71002 +
71003 + if (end > TASK_SIZE)
71004 + goto out;
71005 +
71006 error = 0;
71007 if (end == start)
71008 goto out;
71009 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71010 index ab1e714..415de01 100644
71011 --- a/mm/memory-failure.c
71012 +++ b/mm/memory-failure.c
71013 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71014
71015 int sysctl_memory_failure_recovery __read_mostly = 1;
71016
71017 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71018 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71019
71020 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71021
71022 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71023 pfn, t->comm, t->pid);
71024 si.si_signo = SIGBUS;
71025 si.si_errno = 0;
71026 - si.si_addr = (void *)addr;
71027 + si.si_addr = (void __user *)addr;
71028 #ifdef __ARCH_SI_TRAPNO
71029 si.si_trapno = trapno;
71030 #endif
71031 @@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71032 }
71033
71034 nr_pages = 1 << compound_trans_order(hpage);
71035 - atomic_long_add(nr_pages, &mce_bad_pages);
71036 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71037
71038 /*
71039 * We need/can do nothing about count=0 pages.
71040 @@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71041 if (!PageHWPoison(hpage)
71042 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71043 || (p != hpage && TestSetPageHWPoison(hpage))) {
71044 - atomic_long_sub(nr_pages, &mce_bad_pages);
71045 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71046 return 0;
71047 }
71048 set_page_hwpoison_huge_page(hpage);
71049 @@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71050 }
71051 if (hwpoison_filter(p)) {
71052 if (TestClearPageHWPoison(p))
71053 - atomic_long_sub(nr_pages, &mce_bad_pages);
71054 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71055 unlock_page(hpage);
71056 put_page(hpage);
71057 return 0;
71058 @@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
71059 return 0;
71060 }
71061 if (TestClearPageHWPoison(p))
71062 - atomic_long_sub(nr_pages, &mce_bad_pages);
71063 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71064 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71065 return 0;
71066 }
71067 @@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
71068 */
71069 if (TestClearPageHWPoison(page)) {
71070 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71071 - atomic_long_sub(nr_pages, &mce_bad_pages);
71072 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71073 freeit = 1;
71074 if (PageHuge(page))
71075 clear_page_hwpoison_huge_page(page);
71076 @@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71077 }
71078 done:
71079 if (!PageHWPoison(hpage))
71080 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71081 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71082 set_page_hwpoison_huge_page(hpage);
71083 dequeue_hwpoisoned_huge_page(hpage);
71084 /* keep elevated page count for bad page */
71085 @@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
71086 return ret;
71087
71088 done:
71089 - atomic_long_add(1, &mce_bad_pages);
71090 + atomic_long_add_unchecked(1, &mce_bad_pages);
71091 SetPageHWPoison(page);
71092 /* keep elevated page count for bad page */
71093 return ret;
71094 diff --git a/mm/memory.c b/mm/memory.c
71095 index 2466d12..08be4f6 100644
71096 --- a/mm/memory.c
71097 +++ b/mm/memory.c
71098 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71099 return;
71100
71101 pmd = pmd_offset(pud, start);
71102 +
71103 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71104 pud_clear(pud);
71105 pmd_free_tlb(tlb, pmd, start);
71106 +#endif
71107 +
71108 }
71109
71110 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71111 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71112 if (end - 1 > ceiling - 1)
71113 return;
71114
71115 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71116 pud = pud_offset(pgd, start);
71117 pgd_clear(pgd);
71118 pud_free_tlb(tlb, pud, start);
71119 +#endif
71120 +
71121 }
71122
71123 /*
71124 @@ -1602,12 +1609,6 @@ no_page_table:
71125 return page;
71126 }
71127
71128 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71129 -{
71130 - return stack_guard_page_start(vma, addr) ||
71131 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71132 -}
71133 -
71134 /**
71135 * __get_user_pages() - pin user pages in memory
71136 * @tsk: task_struct of target task
71137 @@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71138 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71139 i = 0;
71140
71141 - do {
71142 + while (nr_pages) {
71143 struct vm_area_struct *vma;
71144
71145 - vma = find_extend_vma(mm, start);
71146 + vma = find_vma(mm, start);
71147 if (!vma && in_gate_area(mm, start)) {
71148 unsigned long pg = start & PAGE_MASK;
71149 pgd_t *pgd;
71150 @@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71151 goto next_page;
71152 }
71153
71154 - if (!vma ||
71155 + if (!vma || start < vma->vm_start ||
71156 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71157 !(vm_flags & vma->vm_flags))
71158 return i ? : -EFAULT;
71159 @@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71160 int ret;
71161 unsigned int fault_flags = 0;
71162
71163 - /* For mlock, just skip the stack guard page. */
71164 - if (foll_flags & FOLL_MLOCK) {
71165 - if (stack_guard_page(vma, start))
71166 - goto next_page;
71167 - }
71168 if (foll_flags & FOLL_WRITE)
71169 fault_flags |= FAULT_FLAG_WRITE;
71170 if (nonblocking)
71171 @@ -1836,7 +1832,7 @@ next_page:
71172 start += PAGE_SIZE;
71173 nr_pages--;
71174 } while (nr_pages && start < vma->vm_end);
71175 - } while (nr_pages);
71176 + }
71177 return i;
71178 }
71179 EXPORT_SYMBOL(__get_user_pages);
71180 @@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71181 page_add_file_rmap(page);
71182 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71183
71184 +#ifdef CONFIG_PAX_SEGMEXEC
71185 + pax_mirror_file_pte(vma, addr, page, ptl);
71186 +#endif
71187 +
71188 retval = 0;
71189 pte_unmap_unlock(pte, ptl);
71190 return retval;
71191 @@ -2077,10 +2077,22 @@ out:
71192 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71193 struct page *page)
71194 {
71195 +
71196 +#ifdef CONFIG_PAX_SEGMEXEC
71197 + struct vm_area_struct *vma_m;
71198 +#endif
71199 +
71200 if (addr < vma->vm_start || addr >= vma->vm_end)
71201 return -EFAULT;
71202 if (!page_count(page))
71203 return -EINVAL;
71204 +
71205 +#ifdef CONFIG_PAX_SEGMEXEC
71206 + vma_m = pax_find_mirror_vma(vma);
71207 + if (vma_m)
71208 + vma_m->vm_flags |= VM_INSERTPAGE;
71209 +#endif
71210 +
71211 vma->vm_flags |= VM_INSERTPAGE;
71212 return insert_page(vma, addr, page, vma->vm_page_prot);
71213 }
71214 @@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71215 unsigned long pfn)
71216 {
71217 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71218 + BUG_ON(vma->vm_mirror);
71219
71220 if (addr < vma->vm_start || addr >= vma->vm_end)
71221 return -EFAULT;
71222 @@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71223
71224 BUG_ON(pud_huge(*pud));
71225
71226 - pmd = pmd_alloc(mm, pud, addr);
71227 + pmd = (mm == &init_mm) ?
71228 + pmd_alloc_kernel(mm, pud, addr) :
71229 + pmd_alloc(mm, pud, addr);
71230 if (!pmd)
71231 return -ENOMEM;
71232 do {
71233 @@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71234 unsigned long next;
71235 int err;
71236
71237 - pud = pud_alloc(mm, pgd, addr);
71238 + pud = (mm == &init_mm) ?
71239 + pud_alloc_kernel(mm, pgd, addr) :
71240 + pud_alloc(mm, pgd, addr);
71241 if (!pud)
71242 return -ENOMEM;
71243 do {
71244 @@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71245 copy_user_highpage(dst, src, va, vma);
71246 }
71247
71248 +#ifdef CONFIG_PAX_SEGMEXEC
71249 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71250 +{
71251 + struct mm_struct *mm = vma->vm_mm;
71252 + spinlock_t *ptl;
71253 + pte_t *pte, entry;
71254 +
71255 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71256 + entry = *pte;
71257 + if (!pte_present(entry)) {
71258 + if (!pte_none(entry)) {
71259 + BUG_ON(pte_file(entry));
71260 + free_swap_and_cache(pte_to_swp_entry(entry));
71261 + pte_clear_not_present_full(mm, address, pte, 0);
71262 + }
71263 + } else {
71264 + struct page *page;
71265 +
71266 + flush_cache_page(vma, address, pte_pfn(entry));
71267 + entry = ptep_clear_flush(vma, address, pte);
71268 + BUG_ON(pte_dirty(entry));
71269 + page = vm_normal_page(vma, address, entry);
71270 + if (page) {
71271 + update_hiwater_rss(mm);
71272 + if (PageAnon(page))
71273 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71274 + else
71275 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71276 + page_remove_rmap(page);
71277 + page_cache_release(page);
71278 + }
71279 + }
71280 + pte_unmap_unlock(pte, ptl);
71281 +}
71282 +
71283 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71284 + *
71285 + * the ptl of the lower mapped page is held on entry and is not released on exit
71286 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71287 + */
71288 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71289 +{
71290 + struct mm_struct *mm = vma->vm_mm;
71291 + unsigned long address_m;
71292 + spinlock_t *ptl_m;
71293 + struct vm_area_struct *vma_m;
71294 + pmd_t *pmd_m;
71295 + pte_t *pte_m, entry_m;
71296 +
71297 + BUG_ON(!page_m || !PageAnon(page_m));
71298 +
71299 + vma_m = pax_find_mirror_vma(vma);
71300 + if (!vma_m)
71301 + return;
71302 +
71303 + BUG_ON(!PageLocked(page_m));
71304 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71305 + address_m = address + SEGMEXEC_TASK_SIZE;
71306 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71307 + pte_m = pte_offset_map(pmd_m, address_m);
71308 + ptl_m = pte_lockptr(mm, pmd_m);
71309 + if (ptl != ptl_m) {
71310 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71311 + if (!pte_none(*pte_m))
71312 + goto out;
71313 + }
71314 +
71315 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71316 + page_cache_get(page_m);
71317 + page_add_anon_rmap(page_m, vma_m, address_m);
71318 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71319 + set_pte_at(mm, address_m, pte_m, entry_m);
71320 + update_mmu_cache(vma_m, address_m, entry_m);
71321 +out:
71322 + if (ptl != ptl_m)
71323 + spin_unlock(ptl_m);
71324 + pte_unmap(pte_m);
71325 + unlock_page(page_m);
71326 +}
71327 +
71328 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71329 +{
71330 + struct mm_struct *mm = vma->vm_mm;
71331 + unsigned long address_m;
71332 + spinlock_t *ptl_m;
71333 + struct vm_area_struct *vma_m;
71334 + pmd_t *pmd_m;
71335 + pte_t *pte_m, entry_m;
71336 +
71337 + BUG_ON(!page_m || PageAnon(page_m));
71338 +
71339 + vma_m = pax_find_mirror_vma(vma);
71340 + if (!vma_m)
71341 + return;
71342 +
71343 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71344 + address_m = address + SEGMEXEC_TASK_SIZE;
71345 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71346 + pte_m = pte_offset_map(pmd_m, address_m);
71347 + ptl_m = pte_lockptr(mm, pmd_m);
71348 + if (ptl != ptl_m) {
71349 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71350 + if (!pte_none(*pte_m))
71351 + goto out;
71352 + }
71353 +
71354 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71355 + page_cache_get(page_m);
71356 + page_add_file_rmap(page_m);
71357 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71358 + set_pte_at(mm, address_m, pte_m, entry_m);
71359 + update_mmu_cache(vma_m, address_m, entry_m);
71360 +out:
71361 + if (ptl != ptl_m)
71362 + spin_unlock(ptl_m);
71363 + pte_unmap(pte_m);
71364 +}
71365 +
71366 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71367 +{
71368 + struct mm_struct *mm = vma->vm_mm;
71369 + unsigned long address_m;
71370 + spinlock_t *ptl_m;
71371 + struct vm_area_struct *vma_m;
71372 + pmd_t *pmd_m;
71373 + pte_t *pte_m, entry_m;
71374 +
71375 + vma_m = pax_find_mirror_vma(vma);
71376 + if (!vma_m)
71377 + return;
71378 +
71379 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71380 + address_m = address + SEGMEXEC_TASK_SIZE;
71381 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71382 + pte_m = pte_offset_map(pmd_m, address_m);
71383 + ptl_m = pte_lockptr(mm, pmd_m);
71384 + if (ptl != ptl_m) {
71385 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71386 + if (!pte_none(*pte_m))
71387 + goto out;
71388 + }
71389 +
71390 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71391 + set_pte_at(mm, address_m, pte_m, entry_m);
71392 +out:
71393 + if (ptl != ptl_m)
71394 + spin_unlock(ptl_m);
71395 + pte_unmap(pte_m);
71396 +}
71397 +
71398 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71399 +{
71400 + struct page *page_m;
71401 + pte_t entry;
71402 +
71403 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71404 + goto out;
71405 +
71406 + entry = *pte;
71407 + page_m = vm_normal_page(vma, address, entry);
71408 + if (!page_m)
71409 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71410 + else if (PageAnon(page_m)) {
71411 + if (pax_find_mirror_vma(vma)) {
71412 + pte_unmap_unlock(pte, ptl);
71413 + lock_page(page_m);
71414 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71415 + if (pte_same(entry, *pte))
71416 + pax_mirror_anon_pte(vma, address, page_m, ptl);
71417 + else
71418 + unlock_page(page_m);
71419 + }
71420 + } else
71421 + pax_mirror_file_pte(vma, address, page_m, ptl);
71422 +
71423 +out:
71424 + pte_unmap_unlock(pte, ptl);
71425 +}
71426 +#endif
71427 +
71428 /*
71429 * This routine handles present pages, when users try to write
71430 * to a shared page. It is done by copying the page to a new address
71431 @@ -2692,6 +2889,12 @@ gotten:
71432 */
71433 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71434 if (likely(pte_same(*page_table, orig_pte))) {
71435 +
71436 +#ifdef CONFIG_PAX_SEGMEXEC
71437 + if (pax_find_mirror_vma(vma))
71438 + BUG_ON(!trylock_page(new_page));
71439 +#endif
71440 +
71441 if (old_page) {
71442 if (!PageAnon(old_page)) {
71443 dec_mm_counter_fast(mm, MM_FILEPAGES);
71444 @@ -2743,6 +2946,10 @@ gotten:
71445 page_remove_rmap(old_page);
71446 }
71447
71448 +#ifdef CONFIG_PAX_SEGMEXEC
71449 + pax_mirror_anon_pte(vma, address, new_page, ptl);
71450 +#endif
71451 +
71452 /* Free the old page.. */
71453 new_page = old_page;
71454 ret |= VM_FAULT_WRITE;
71455 @@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71456 swap_free(entry);
71457 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71458 try_to_free_swap(page);
71459 +
71460 +#ifdef CONFIG_PAX_SEGMEXEC
71461 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71462 +#endif
71463 +
71464 unlock_page(page);
71465 if (swapcache) {
71466 /*
71467 @@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71468
71469 /* No need to invalidate - it was non-present before */
71470 update_mmu_cache(vma, address, page_table);
71471 +
71472 +#ifdef CONFIG_PAX_SEGMEXEC
71473 + pax_mirror_anon_pte(vma, address, page, ptl);
71474 +#endif
71475 +
71476 unlock:
71477 pte_unmap_unlock(page_table, ptl);
71478 out:
71479 @@ -3064,40 +3281,6 @@ out_release:
71480 }
71481
71482 /*
71483 - * This is like a special single-page "expand_{down|up}wards()",
71484 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
71485 - * doesn't hit another vma.
71486 - */
71487 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71488 -{
71489 - address &= PAGE_MASK;
71490 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71491 - struct vm_area_struct *prev = vma->vm_prev;
71492 -
71493 - /*
71494 - * Is there a mapping abutting this one below?
71495 - *
71496 - * That's only ok if it's the same stack mapping
71497 - * that has gotten split..
71498 - */
71499 - if (prev && prev->vm_end == address)
71500 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71501 -
71502 - expand_downwards(vma, address - PAGE_SIZE);
71503 - }
71504 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71505 - struct vm_area_struct *next = vma->vm_next;
71506 -
71507 - /* As VM_GROWSDOWN but s/below/above/ */
71508 - if (next && next->vm_start == address + PAGE_SIZE)
71509 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71510 -
71511 - expand_upwards(vma, address + PAGE_SIZE);
71512 - }
71513 - return 0;
71514 -}
71515 -
71516 -/*
71517 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71518 * but allow concurrent faults), and pte mapped but not yet locked.
71519 * We return with mmap_sem still held, but pte unmapped and unlocked.
71520 @@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71521 unsigned long address, pte_t *page_table, pmd_t *pmd,
71522 unsigned int flags)
71523 {
71524 - struct page *page;
71525 + struct page *page = NULL;
71526 spinlock_t *ptl;
71527 pte_t entry;
71528
71529 - pte_unmap(page_table);
71530 -
71531 - /* Check if we need to add a guard page to the stack */
71532 - if (check_stack_guard_page(vma, address) < 0)
71533 - return VM_FAULT_SIGBUS;
71534 -
71535 - /* Use the zero-page for reads */
71536 if (!(flags & FAULT_FLAG_WRITE)) {
71537 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71538 vma->vm_page_prot));
71539 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71540 + ptl = pte_lockptr(mm, pmd);
71541 + spin_lock(ptl);
71542 if (!pte_none(*page_table))
71543 goto unlock;
71544 goto setpte;
71545 }
71546
71547 /* Allocate our own private page. */
71548 + pte_unmap(page_table);
71549 +
71550 if (unlikely(anon_vma_prepare(vma)))
71551 goto oom;
71552 page = alloc_zeroed_user_highpage_movable(vma, address);
71553 @@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71554 if (!pte_none(*page_table))
71555 goto release;
71556
71557 +#ifdef CONFIG_PAX_SEGMEXEC
71558 + if (pax_find_mirror_vma(vma))
71559 + BUG_ON(!trylock_page(page));
71560 +#endif
71561 +
71562 inc_mm_counter_fast(mm, MM_ANONPAGES);
71563 page_add_new_anon_rmap(page, vma, address);
71564 setpte:
71565 @@ -3152,6 +3336,12 @@ setpte:
71566
71567 /* No need to invalidate - it was non-present before */
71568 update_mmu_cache(vma, address, page_table);
71569 +
71570 +#ifdef CONFIG_PAX_SEGMEXEC
71571 + if (page)
71572 + pax_mirror_anon_pte(vma, address, page, ptl);
71573 +#endif
71574 +
71575 unlock:
71576 pte_unmap_unlock(page_table, ptl);
71577 return 0;
71578 @@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71579 */
71580 /* Only go through if we didn't race with anybody else... */
71581 if (likely(pte_same(*page_table, orig_pte))) {
71582 +
71583 +#ifdef CONFIG_PAX_SEGMEXEC
71584 + if (anon && pax_find_mirror_vma(vma))
71585 + BUG_ON(!trylock_page(page));
71586 +#endif
71587 +
71588 flush_icache_page(vma, page);
71589 entry = mk_pte(page, vma->vm_page_prot);
71590 if (flags & FAULT_FLAG_WRITE)
71591 @@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71592
71593 /* no need to invalidate: a not-present page won't be cached */
71594 update_mmu_cache(vma, address, page_table);
71595 +
71596 +#ifdef CONFIG_PAX_SEGMEXEC
71597 + if (anon)
71598 + pax_mirror_anon_pte(vma, address, page, ptl);
71599 + else
71600 + pax_mirror_file_pte(vma, address, page, ptl);
71601 +#endif
71602 +
71603 } else {
71604 if (cow_page)
71605 mem_cgroup_uncharge_page(cow_page);
71606 @@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71607 if (flags & FAULT_FLAG_WRITE)
71608 flush_tlb_fix_spurious_fault(vma, address);
71609 }
71610 +
71611 +#ifdef CONFIG_PAX_SEGMEXEC
71612 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71613 + return 0;
71614 +#endif
71615 +
71616 unlock:
71617 pte_unmap_unlock(pte, ptl);
71618 return 0;
71619 @@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71620 pmd_t *pmd;
71621 pte_t *pte;
71622
71623 +#ifdef CONFIG_PAX_SEGMEXEC
71624 + struct vm_area_struct *vma_m;
71625 +#endif
71626 +
71627 __set_current_state(TASK_RUNNING);
71628
71629 count_vm_event(PGFAULT);
71630 @@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71631 if (unlikely(is_vm_hugetlb_page(vma)))
71632 return hugetlb_fault(mm, vma, address, flags);
71633
71634 +#ifdef CONFIG_PAX_SEGMEXEC
71635 + vma_m = pax_find_mirror_vma(vma);
71636 + if (vma_m) {
71637 + unsigned long address_m;
71638 + pgd_t *pgd_m;
71639 + pud_t *pud_m;
71640 + pmd_t *pmd_m;
71641 +
71642 + if (vma->vm_start > vma_m->vm_start) {
71643 + address_m = address;
71644 + address -= SEGMEXEC_TASK_SIZE;
71645 + vma = vma_m;
71646 + } else
71647 + address_m = address + SEGMEXEC_TASK_SIZE;
71648 +
71649 + pgd_m = pgd_offset(mm, address_m);
71650 + pud_m = pud_alloc(mm, pgd_m, address_m);
71651 + if (!pud_m)
71652 + return VM_FAULT_OOM;
71653 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71654 + if (!pmd_m)
71655 + return VM_FAULT_OOM;
71656 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71657 + return VM_FAULT_OOM;
71658 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71659 + }
71660 +#endif
71661 +
71662 retry:
71663 pgd = pgd_offset(mm, address);
71664 pud = pud_alloc(mm, pgd, address);
71665 @@ -3535,7 +3777,7 @@ retry:
71666 * run pte_offset_map on the pmd, if an huge pmd could
71667 * materialize from under us from a different thread.
71668 */
71669 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71670 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71671 return VM_FAULT_OOM;
71672 /* if an huge pmd materialized from under us just retry later */
71673 if (unlikely(pmd_trans_huge(*pmd)))
71674 @@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71675 spin_unlock(&mm->page_table_lock);
71676 return 0;
71677 }
71678 +
71679 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71680 +{
71681 + pud_t *new = pud_alloc_one(mm, address);
71682 + if (!new)
71683 + return -ENOMEM;
71684 +
71685 + smp_wmb(); /* See comment in __pte_alloc */
71686 +
71687 + spin_lock(&mm->page_table_lock);
71688 + if (pgd_present(*pgd)) /* Another has populated it */
71689 + pud_free(mm, new);
71690 + else
71691 + pgd_populate_kernel(mm, pgd, new);
71692 + spin_unlock(&mm->page_table_lock);
71693 + return 0;
71694 +}
71695 #endif /* __PAGETABLE_PUD_FOLDED */
71696
71697 #ifndef __PAGETABLE_PMD_FOLDED
71698 @@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71699 spin_unlock(&mm->page_table_lock);
71700 return 0;
71701 }
71702 +
71703 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71704 +{
71705 + pmd_t *new = pmd_alloc_one(mm, address);
71706 + if (!new)
71707 + return -ENOMEM;
71708 +
71709 + smp_wmb(); /* See comment in __pte_alloc */
71710 +
71711 + spin_lock(&mm->page_table_lock);
71712 +#ifndef __ARCH_HAS_4LEVEL_HACK
71713 + if (pud_present(*pud)) /* Another has populated it */
71714 + pmd_free(mm, new);
71715 + else
71716 + pud_populate_kernel(mm, pud, new);
71717 +#else
71718 + if (pgd_present(*pud)) /* Another has populated it */
71719 + pmd_free(mm, new);
71720 + else
71721 + pgd_populate_kernel(mm, pud, new);
71722 +#endif /* __ARCH_HAS_4LEVEL_HACK */
71723 + spin_unlock(&mm->page_table_lock);
71724 + return 0;
71725 +}
71726 #endif /* __PAGETABLE_PMD_FOLDED */
71727
71728 int make_pages_present(unsigned long addr, unsigned long end)
71729 @@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71730 gate_vma.vm_start = FIXADDR_USER_START;
71731 gate_vma.vm_end = FIXADDR_USER_END;
71732 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71733 - gate_vma.vm_page_prot = __P101;
71734 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71735
71736 return 0;
71737 }
71738 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71739 index 1d771e4..f9a6808 100644
71740 --- a/mm/mempolicy.c
71741 +++ b/mm/mempolicy.c
71742 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71743 unsigned long vmstart;
71744 unsigned long vmend;
71745
71746 +#ifdef CONFIG_PAX_SEGMEXEC
71747 + struct vm_area_struct *vma_m;
71748 +#endif
71749 +
71750 vma = find_vma(mm, start);
71751 if (!vma || vma->vm_start > start)
71752 return -EFAULT;
71753 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71754 if (err)
71755 goto out;
71756 }
71757 +
71758 +#ifdef CONFIG_PAX_SEGMEXEC
71759 + vma_m = pax_find_mirror_vma(vma);
71760 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71761 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71762 + if (err)
71763 + goto out;
71764 + }
71765 +#endif
71766 +
71767 }
71768
71769 out:
71770 @@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71771
71772 if (end < start)
71773 return -EINVAL;
71774 +
71775 +#ifdef CONFIG_PAX_SEGMEXEC
71776 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71777 + if (end > SEGMEXEC_TASK_SIZE)
71778 + return -EINVAL;
71779 + } else
71780 +#endif
71781 +
71782 + if (end > TASK_SIZE)
71783 + return -EINVAL;
71784 +
71785 if (end == start)
71786 return 0;
71787
71788 @@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71789 */
71790 tcred = __task_cred(task);
71791 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71792 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71793 - !capable(CAP_SYS_NICE)) {
71794 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71795 rcu_read_unlock();
71796 err = -EPERM;
71797 goto out_put;
71798 @@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71799 goto out;
71800 }
71801
71802 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71803 + if (mm != current->mm &&
71804 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71805 + mmput(mm);
71806 + err = -EPERM;
71807 + goto out;
71808 + }
71809 +#endif
71810 +
71811 err = do_migrate_pages(mm, old, new,
71812 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71813
71814 diff --git a/mm/mlock.c b/mm/mlock.c
71815 index ef726e8..cd7f1ec 100644
71816 --- a/mm/mlock.c
71817 +++ b/mm/mlock.c
71818 @@ -13,6 +13,7 @@
71819 #include <linux/pagemap.h>
71820 #include <linux/mempolicy.h>
71821 #include <linux/syscalls.h>
71822 +#include <linux/security.h>
71823 #include <linux/sched.h>
71824 #include <linux/export.h>
71825 #include <linux/rmap.h>
71826 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71827 {
71828 unsigned long nstart, end, tmp;
71829 struct vm_area_struct * vma, * prev;
71830 - int error;
71831 + int error = 0;
71832
71833 VM_BUG_ON(start & ~PAGE_MASK);
71834 VM_BUG_ON(len != PAGE_ALIGN(len));
71835 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71836 return -EINVAL;
71837 if (end == start)
71838 return 0;
71839 + if (end > TASK_SIZE)
71840 + return -EINVAL;
71841 +
71842 vma = find_vma(current->mm, start);
71843 if (!vma || vma->vm_start > start)
71844 return -ENOMEM;
71845 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71846 for (nstart = start ; ; ) {
71847 vm_flags_t newflags;
71848
71849 +#ifdef CONFIG_PAX_SEGMEXEC
71850 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71851 + break;
71852 +#endif
71853 +
71854 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71855
71856 newflags = vma->vm_flags | VM_LOCKED;
71857 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71858 lock_limit >>= PAGE_SHIFT;
71859
71860 /* check against resource limits */
71861 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71862 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71863 error = do_mlock(start, len, 1);
71864 up_write(&current->mm->mmap_sem);
71865 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71866 static int do_mlockall(int flags)
71867 {
71868 struct vm_area_struct * vma, * prev = NULL;
71869 - unsigned int def_flags = 0;
71870
71871 if (flags & MCL_FUTURE)
71872 - def_flags = VM_LOCKED;
71873 - current->mm->def_flags = def_flags;
71874 + current->mm->def_flags |= VM_LOCKED;
71875 + else
71876 + current->mm->def_flags &= ~VM_LOCKED;
71877 if (flags == MCL_FUTURE)
71878 goto out;
71879
71880 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71881 vm_flags_t newflags;
71882
71883 +#ifdef CONFIG_PAX_SEGMEXEC
71884 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71885 + break;
71886 +#endif
71887 +
71888 + BUG_ON(vma->vm_end > TASK_SIZE);
71889 newflags = vma->vm_flags | VM_LOCKED;
71890 if (!(flags & MCL_CURRENT))
71891 newflags &= ~VM_LOCKED;
71892 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71893 lock_limit >>= PAGE_SHIFT;
71894
71895 ret = -ENOMEM;
71896 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71897 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71898 capable(CAP_IPC_LOCK))
71899 ret = do_mlockall(flags);
71900 diff --git a/mm/mmap.c b/mm/mmap.c
71901 index 3edfcdf..4a27ae9 100644
71902 --- a/mm/mmap.c
71903 +++ b/mm/mmap.c
71904 @@ -47,6 +47,16 @@
71905 #define arch_rebalance_pgtables(addr, len) (addr)
71906 #endif
71907
71908 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71909 +{
71910 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71911 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71912 + up_read(&mm->mmap_sem);
71913 + BUG();
71914 + }
71915 +#endif
71916 +}
71917 +
71918 static void unmap_region(struct mm_struct *mm,
71919 struct vm_area_struct *vma, struct vm_area_struct *prev,
71920 unsigned long start, unsigned long end);
71921 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
71922 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71923 *
71924 */
71925 -pgprot_t protection_map[16] = {
71926 +pgprot_t protection_map[16] __read_only = {
71927 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71928 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71929 };
71930
71931 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71932 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71933 {
71934 - return __pgprot(pgprot_val(protection_map[vm_flags &
71935 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71936 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71937 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71938 +
71939 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71940 + if (!(__supported_pte_mask & _PAGE_NX) &&
71941 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71942 + (vm_flags & (VM_READ | VM_WRITE)))
71943 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71944 +#endif
71945 +
71946 + return prot;
71947 }
71948 EXPORT_SYMBOL(vm_get_page_prot);
71949
71950 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71951 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71952 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71953 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71954 /*
71955 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71956 * other variables. It can be updated by several CPUs frequently.
71957 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71958 struct vm_area_struct *next = vma->vm_next;
71959
71960 might_sleep();
71961 + BUG_ON(vma->vm_mirror);
71962 if (vma->vm_ops && vma->vm_ops->close)
71963 vma->vm_ops->close(vma);
71964 if (vma->vm_file) {
71965 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71966 * not page aligned -Ram Gupta
71967 */
71968 rlim = rlimit(RLIMIT_DATA);
71969 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71970 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71971 (mm->end_data - mm->start_data) > rlim)
71972 goto out;
71973 @@ -708,6 +730,12 @@ static int
71974 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71975 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71976 {
71977 +
71978 +#ifdef CONFIG_PAX_SEGMEXEC
71979 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71980 + return 0;
71981 +#endif
71982 +
71983 if (is_mergeable_vma(vma, file, vm_flags) &&
71984 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71985 if (vma->vm_pgoff == vm_pgoff)
71986 @@ -727,6 +755,12 @@ static int
71987 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71988 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71989 {
71990 +
71991 +#ifdef CONFIG_PAX_SEGMEXEC
71992 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71993 + return 0;
71994 +#endif
71995 +
71996 if (is_mergeable_vma(vma, file, vm_flags) &&
71997 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71998 pgoff_t vm_pglen;
71999 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72000 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72001 struct vm_area_struct *prev, unsigned long addr,
72002 unsigned long end, unsigned long vm_flags,
72003 - struct anon_vma *anon_vma, struct file *file,
72004 + struct anon_vma *anon_vma, struct file *file,
72005 pgoff_t pgoff, struct mempolicy *policy)
72006 {
72007 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72008 struct vm_area_struct *area, *next;
72009 int err;
72010
72011 +#ifdef CONFIG_PAX_SEGMEXEC
72012 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72013 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72014 +
72015 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72016 +#endif
72017 +
72018 /*
72019 * We later require that vma->vm_flags == vm_flags,
72020 * so this tests vma->vm_flags & VM_SPECIAL, too.
72021 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72022 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72023 next = next->vm_next;
72024
72025 +#ifdef CONFIG_PAX_SEGMEXEC
72026 + if (prev)
72027 + prev_m = pax_find_mirror_vma(prev);
72028 + if (area)
72029 + area_m = pax_find_mirror_vma(area);
72030 + if (next)
72031 + next_m = pax_find_mirror_vma(next);
72032 +#endif
72033 +
72034 /*
72035 * Can it merge with the predecessor?
72036 */
72037 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72038 /* cases 1, 6 */
72039 err = vma_adjust(prev, prev->vm_start,
72040 next->vm_end, prev->vm_pgoff, NULL);
72041 - } else /* cases 2, 5, 7 */
72042 +
72043 +#ifdef CONFIG_PAX_SEGMEXEC
72044 + if (!err && prev_m)
72045 + err = vma_adjust(prev_m, prev_m->vm_start,
72046 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72047 +#endif
72048 +
72049 + } else { /* cases 2, 5, 7 */
72050 err = vma_adjust(prev, prev->vm_start,
72051 end, prev->vm_pgoff, NULL);
72052 +
72053 +#ifdef CONFIG_PAX_SEGMEXEC
72054 + if (!err && prev_m)
72055 + err = vma_adjust(prev_m, prev_m->vm_start,
72056 + end_m, prev_m->vm_pgoff, NULL);
72057 +#endif
72058 +
72059 + }
72060 if (err)
72061 return NULL;
72062 khugepaged_enter_vma_merge(prev);
72063 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72064 mpol_equal(policy, vma_policy(next)) &&
72065 can_vma_merge_before(next, vm_flags,
72066 anon_vma, file, pgoff+pglen)) {
72067 - if (prev && addr < prev->vm_end) /* case 4 */
72068 + if (prev && addr < prev->vm_end) { /* case 4 */
72069 err = vma_adjust(prev, prev->vm_start,
72070 addr, prev->vm_pgoff, NULL);
72071 - else /* cases 3, 8 */
72072 +
72073 +#ifdef CONFIG_PAX_SEGMEXEC
72074 + if (!err && prev_m)
72075 + err = vma_adjust(prev_m, prev_m->vm_start,
72076 + addr_m, prev_m->vm_pgoff, NULL);
72077 +#endif
72078 +
72079 + } else { /* cases 3, 8 */
72080 err = vma_adjust(area, addr, next->vm_end,
72081 next->vm_pgoff - pglen, NULL);
72082 +
72083 +#ifdef CONFIG_PAX_SEGMEXEC
72084 + if (!err && area_m)
72085 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72086 + next_m->vm_pgoff - pglen, NULL);
72087 +#endif
72088 +
72089 + }
72090 if (err)
72091 return NULL;
72092 khugepaged_enter_vma_merge(area);
72093 @@ -940,14 +1020,11 @@ none:
72094 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72095 struct file *file, long pages)
72096 {
72097 - const unsigned long stack_flags
72098 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72099 -
72100 if (file) {
72101 mm->shared_vm += pages;
72102 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72103 mm->exec_vm += pages;
72104 - } else if (flags & stack_flags)
72105 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72106 mm->stack_vm += pages;
72107 if (flags & (VM_RESERVED|VM_IO))
72108 mm->reserved_vm += pages;
72109 @@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72110 * (the exception is when the underlying filesystem is noexec
72111 * mounted, in which case we dont add PROT_EXEC.)
72112 */
72113 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72114 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72115 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72116 prot |= PROT_EXEC;
72117
72118 @@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72119 /* Obtain the address to map to. we verify (or select) it and ensure
72120 * that it represents a valid section of the address space.
72121 */
72122 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72123 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72124 if (addr & ~PAGE_MASK)
72125 return addr;
72126
72127 @@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72128 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72129 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72130
72131 +#ifdef CONFIG_PAX_MPROTECT
72132 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72133 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72134 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72135 + gr_log_rwxmmap(file);
72136 +
72137 +#ifdef CONFIG_PAX_EMUPLT
72138 + vm_flags &= ~VM_EXEC;
72139 +#else
72140 + return -EPERM;
72141 +#endif
72142 +
72143 + }
72144 +
72145 + if (!(vm_flags & VM_EXEC))
72146 + vm_flags &= ~VM_MAYEXEC;
72147 +#else
72148 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72149 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72150 +#endif
72151 + else
72152 + vm_flags &= ~VM_MAYWRITE;
72153 + }
72154 +#endif
72155 +
72156 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72157 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72158 + vm_flags &= ~VM_PAGEEXEC;
72159 +#endif
72160 +
72161 if (flags & MAP_LOCKED)
72162 if (!can_do_mlock())
72163 return -EPERM;
72164 @@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72165 locked += mm->locked_vm;
72166 lock_limit = rlimit(RLIMIT_MEMLOCK);
72167 lock_limit >>= PAGE_SHIFT;
72168 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72169 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72170 return -EAGAIN;
72171 }
72172 @@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72173 }
72174 }
72175
72176 + if (!gr_acl_handle_mmap(file, prot))
72177 + return -EACCES;
72178 +
72179 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72180 }
72181
72182 @@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72183 vm_flags_t vm_flags = vma->vm_flags;
72184
72185 /* If it was private or non-writable, the write bit is already clear */
72186 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72187 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72188 return 0;
72189
72190 /* The backer wishes to know when pages are first written to? */
72191 @@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72192 unsigned long charged = 0;
72193 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72194
72195 +#ifdef CONFIG_PAX_SEGMEXEC
72196 + struct vm_area_struct *vma_m = NULL;
72197 +#endif
72198 +
72199 + /*
72200 + * mm->mmap_sem is required to protect against another thread
72201 + * changing the mappings in case we sleep.
72202 + */
72203 + verify_mm_writelocked(mm);
72204 +
72205 /* Clear old maps */
72206 error = -ENOMEM;
72207 -munmap_back:
72208 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72209 if (vma && vma->vm_start < addr + len) {
72210 if (do_munmap(mm, addr, len))
72211 return -ENOMEM;
72212 - goto munmap_back;
72213 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72214 + BUG_ON(vma && vma->vm_start < addr + len);
72215 }
72216
72217 /* Check against address space limit. */
72218 @@ -1280,6 +1401,16 @@ munmap_back:
72219 goto unacct_error;
72220 }
72221
72222 +#ifdef CONFIG_PAX_SEGMEXEC
72223 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72224 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72225 + if (!vma_m) {
72226 + error = -ENOMEM;
72227 + goto free_vma;
72228 + }
72229 + }
72230 +#endif
72231 +
72232 vma->vm_mm = mm;
72233 vma->vm_start = addr;
72234 vma->vm_end = addr + len;
72235 @@ -1304,6 +1435,19 @@ munmap_back:
72236 error = file->f_op->mmap(file, vma);
72237 if (error)
72238 goto unmap_and_free_vma;
72239 +
72240 +#ifdef CONFIG_PAX_SEGMEXEC
72241 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72242 + added_exe_file_vma(mm);
72243 +#endif
72244 +
72245 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72246 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72247 + vma->vm_flags |= VM_PAGEEXEC;
72248 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72249 + }
72250 +#endif
72251 +
72252 if (vm_flags & VM_EXECUTABLE)
72253 added_exe_file_vma(mm);
72254
72255 @@ -1341,6 +1485,11 @@ munmap_back:
72256 vma_link(mm, vma, prev, rb_link, rb_parent);
72257 file = vma->vm_file;
72258
72259 +#ifdef CONFIG_PAX_SEGMEXEC
72260 + if (vma_m)
72261 + BUG_ON(pax_mirror_vma(vma_m, vma));
72262 +#endif
72263 +
72264 /* Once vma denies write, undo our temporary denial count */
72265 if (correct_wcount)
72266 atomic_inc(&inode->i_writecount);
72267 @@ -1349,6 +1498,7 @@ out:
72268
72269 mm->total_vm += len >> PAGE_SHIFT;
72270 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72271 + track_exec_limit(mm, addr, addr + len, vm_flags);
72272 if (vm_flags & VM_LOCKED) {
72273 if (!mlock_vma_pages_range(vma, addr, addr + len))
72274 mm->locked_vm += (len >> PAGE_SHIFT);
72275 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72276 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72277 charged = 0;
72278 free_vma:
72279 +
72280 +#ifdef CONFIG_PAX_SEGMEXEC
72281 + if (vma_m)
72282 + kmem_cache_free(vm_area_cachep, vma_m);
72283 +#endif
72284 +
72285 kmem_cache_free(vm_area_cachep, vma);
72286 unacct_error:
72287 if (charged)
72288 @@ -1378,6 +1534,44 @@ unacct_error:
72289 return error;
72290 }
72291
72292 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72293 +{
72294 + if (!vma) {
72295 +#ifdef CONFIG_STACK_GROWSUP
72296 + if (addr > sysctl_heap_stack_gap)
72297 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72298 + else
72299 + vma = find_vma(current->mm, 0);
72300 + if (vma && (vma->vm_flags & VM_GROWSUP))
72301 + return false;
72302 +#endif
72303 + return true;
72304 + }
72305 +
72306 + if (addr + len > vma->vm_start)
72307 + return false;
72308 +
72309 + if (vma->vm_flags & VM_GROWSDOWN)
72310 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72311 +#ifdef CONFIG_STACK_GROWSUP
72312 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72313 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72314 +#endif
72315 +
72316 + return true;
72317 +}
72318 +
72319 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72320 +{
72321 + if (vma->vm_start < len)
72322 + return -ENOMEM;
72323 + if (!(vma->vm_flags & VM_GROWSDOWN))
72324 + return vma->vm_start - len;
72325 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72326 + return vma->vm_start - len - sysctl_heap_stack_gap;
72327 + return -ENOMEM;
72328 +}
72329 +
72330 /* Get an address range which is currently unmapped.
72331 * For shmat() with addr=0.
72332 *
72333 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72334 if (flags & MAP_FIXED)
72335 return addr;
72336
72337 +#ifdef CONFIG_PAX_RANDMMAP
72338 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72339 +#endif
72340 +
72341 if (addr) {
72342 addr = PAGE_ALIGN(addr);
72343 - vma = find_vma(mm, addr);
72344 - if (TASK_SIZE - len >= addr &&
72345 - (!vma || addr + len <= vma->vm_start))
72346 - return addr;
72347 + if (TASK_SIZE - len >= addr) {
72348 + vma = find_vma(mm, addr);
72349 + if (check_heap_stack_gap(vma, addr, len))
72350 + return addr;
72351 + }
72352 }
72353 if (len > mm->cached_hole_size) {
72354 - start_addr = addr = mm->free_area_cache;
72355 + start_addr = addr = mm->free_area_cache;
72356 } else {
72357 - start_addr = addr = TASK_UNMAPPED_BASE;
72358 - mm->cached_hole_size = 0;
72359 + start_addr = addr = mm->mmap_base;
72360 + mm->cached_hole_size = 0;
72361 }
72362
72363 full_search:
72364 @@ -1426,34 +1625,40 @@ full_search:
72365 * Start a new search - just in case we missed
72366 * some holes.
72367 */
72368 - if (start_addr != TASK_UNMAPPED_BASE) {
72369 - addr = TASK_UNMAPPED_BASE;
72370 - start_addr = addr;
72371 + if (start_addr != mm->mmap_base) {
72372 + start_addr = addr = mm->mmap_base;
72373 mm->cached_hole_size = 0;
72374 goto full_search;
72375 }
72376 return -ENOMEM;
72377 }
72378 - if (!vma || addr + len <= vma->vm_start) {
72379 - /*
72380 - * Remember the place where we stopped the search:
72381 - */
72382 - mm->free_area_cache = addr + len;
72383 - return addr;
72384 - }
72385 + if (check_heap_stack_gap(vma, addr, len))
72386 + break;
72387 if (addr + mm->cached_hole_size < vma->vm_start)
72388 mm->cached_hole_size = vma->vm_start - addr;
72389 addr = vma->vm_end;
72390 }
72391 +
72392 + /*
72393 + * Remember the place where we stopped the search:
72394 + */
72395 + mm->free_area_cache = addr + len;
72396 + return addr;
72397 }
72398 #endif
72399
72400 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72401 {
72402 +
72403 +#ifdef CONFIG_PAX_SEGMEXEC
72404 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72405 + return;
72406 +#endif
72407 +
72408 /*
72409 * Is this a new hole at the lowest possible address?
72410 */
72411 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72412 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72413 mm->free_area_cache = addr;
72414 }
72415
72416 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72417 {
72418 struct vm_area_struct *vma;
72419 struct mm_struct *mm = current->mm;
72420 - unsigned long addr = addr0, start_addr;
72421 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72422
72423 /* requested length too big for entire address space */
72424 if (len > TASK_SIZE)
72425 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72426 if (flags & MAP_FIXED)
72427 return addr;
72428
72429 +#ifdef CONFIG_PAX_RANDMMAP
72430 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72431 +#endif
72432 +
72433 /* requesting a specific address */
72434 if (addr) {
72435 addr = PAGE_ALIGN(addr);
72436 - vma = find_vma(mm, addr);
72437 - if (TASK_SIZE - len >= addr &&
72438 - (!vma || addr + len <= vma->vm_start))
72439 - return addr;
72440 + if (TASK_SIZE - len >= addr) {
72441 + vma = find_vma(mm, addr);
72442 + if (check_heap_stack_gap(vma, addr, len))
72443 + return addr;
72444 + }
72445 }
72446
72447 /* check if free_area_cache is useful for us */
72448 @@ -1508,7 +1718,7 @@ try_again:
72449 * return with success:
72450 */
72451 vma = find_vma(mm, addr);
72452 - if (!vma || addr+len <= vma->vm_start)
72453 + if (check_heap_stack_gap(vma, addr, len))
72454 /* remember the address as a hint for next time */
72455 return (mm->free_area_cache = addr);
72456
72457 @@ -1517,8 +1727,8 @@ try_again:
72458 mm->cached_hole_size = vma->vm_start - addr;
72459
72460 /* try just below the current vma->vm_start */
72461 - addr = vma->vm_start-len;
72462 - } while (len < vma->vm_start);
72463 + addr = skip_heap_stack_gap(vma, len);
72464 + } while (!IS_ERR_VALUE(addr));
72465
72466 fail:
72467 /*
72468 @@ -1541,13 +1751,21 @@ fail:
72469 * can happen with large stack limits and large mmap()
72470 * allocations.
72471 */
72472 + mm->mmap_base = TASK_UNMAPPED_BASE;
72473 +
72474 +#ifdef CONFIG_PAX_RANDMMAP
72475 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72476 + mm->mmap_base += mm->delta_mmap;
72477 +#endif
72478 +
72479 + mm->free_area_cache = mm->mmap_base;
72480 mm->cached_hole_size = ~0UL;
72481 - mm->free_area_cache = TASK_UNMAPPED_BASE;
72482 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72483 /*
72484 * Restore the topdown base:
72485 */
72486 - mm->free_area_cache = mm->mmap_base;
72487 + mm->mmap_base = base;
72488 + mm->free_area_cache = base;
72489 mm->cached_hole_size = ~0UL;
72490
72491 return addr;
72492 @@ -1556,6 +1774,12 @@ fail:
72493
72494 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72495 {
72496 +
72497 +#ifdef CONFIG_PAX_SEGMEXEC
72498 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72499 + return;
72500 +#endif
72501 +
72502 /*
72503 * Is this a new hole at the highest possible address?
72504 */
72505 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72506 mm->free_area_cache = addr;
72507
72508 /* dont allow allocations above current base */
72509 - if (mm->free_area_cache > mm->mmap_base)
72510 + if (mm->free_area_cache > mm->mmap_base) {
72511 mm->free_area_cache = mm->mmap_base;
72512 + mm->cached_hole_size = ~0UL;
72513 + }
72514 }
72515
72516 unsigned long
72517 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72518 return vma;
72519 }
72520
72521 +#ifdef CONFIG_PAX_SEGMEXEC
72522 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72523 +{
72524 + struct vm_area_struct *vma_m;
72525 +
72526 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72527 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72528 + BUG_ON(vma->vm_mirror);
72529 + return NULL;
72530 + }
72531 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72532 + vma_m = vma->vm_mirror;
72533 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72534 + BUG_ON(vma->vm_file != vma_m->vm_file);
72535 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72536 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72537 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72538 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72539 + return vma_m;
72540 +}
72541 +#endif
72542 +
72543 /*
72544 * Verify that the stack growth is acceptable and
72545 * update accounting. This is shared with both the
72546 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72547 return -ENOMEM;
72548
72549 /* Stack limit test */
72550 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72551 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72552 return -ENOMEM;
72553
72554 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72555 locked = mm->locked_vm + grow;
72556 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72557 limit >>= PAGE_SHIFT;
72558 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72559 if (locked > limit && !capable(CAP_IPC_LOCK))
72560 return -ENOMEM;
72561 }
72562 @@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72563 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72564 * vma is the last one with address > vma->vm_end. Have to extend vma.
72565 */
72566 +#ifndef CONFIG_IA64
72567 +static
72568 +#endif
72569 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72570 {
72571 int error;
72572 + bool locknext;
72573
72574 if (!(vma->vm_flags & VM_GROWSUP))
72575 return -EFAULT;
72576
72577 + /* Also guard against wrapping around to address 0. */
72578 + if (address < PAGE_ALIGN(address+1))
72579 + address = PAGE_ALIGN(address+1);
72580 + else
72581 + return -ENOMEM;
72582 +
72583 /*
72584 * We must make sure the anon_vma is allocated
72585 * so that the anon_vma locking is not a noop.
72586 */
72587 if (unlikely(anon_vma_prepare(vma)))
72588 return -ENOMEM;
72589 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72590 + if (locknext && anon_vma_prepare(vma->vm_next))
72591 + return -ENOMEM;
72592 vma_lock_anon_vma(vma);
72593 + if (locknext)
72594 + vma_lock_anon_vma(vma->vm_next);
72595
72596 /*
72597 * vma->vm_start/vm_end cannot change under us because the caller
72598 * is required to hold the mmap_sem in read mode. We need the
72599 - * anon_vma lock to serialize against concurrent expand_stacks.
72600 - * Also guard against wrapping around to address 0.
72601 + * anon_vma locks to serialize against concurrent expand_stacks
72602 + * and expand_upwards.
72603 */
72604 - if (address < PAGE_ALIGN(address+4))
72605 - address = PAGE_ALIGN(address+4);
72606 - else {
72607 - vma_unlock_anon_vma(vma);
72608 - return -ENOMEM;
72609 - }
72610 error = 0;
72611
72612 /* Somebody else might have raced and expanded it already */
72613 - if (address > vma->vm_end) {
72614 + 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)
72615 + error = -ENOMEM;
72616 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72617 unsigned long size, grow;
72618
72619 size = address - vma->vm_start;
72620 @@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72621 }
72622 }
72623 }
72624 + if (locknext)
72625 + vma_unlock_anon_vma(vma->vm_next);
72626 vma_unlock_anon_vma(vma);
72627 khugepaged_enter_vma_merge(vma);
72628 return error;
72629 @@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72630 unsigned long address)
72631 {
72632 int error;
72633 + bool lockprev = false;
72634 + struct vm_area_struct *prev;
72635
72636 /*
72637 * We must make sure the anon_vma is allocated
72638 @@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72639 if (error)
72640 return error;
72641
72642 + prev = vma->vm_prev;
72643 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72644 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72645 +#endif
72646 + if (lockprev && anon_vma_prepare(prev))
72647 + return -ENOMEM;
72648 + if (lockprev)
72649 + vma_lock_anon_vma(prev);
72650 +
72651 vma_lock_anon_vma(vma);
72652
72653 /*
72654 @@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72655 */
72656
72657 /* Somebody else might have raced and expanded it already */
72658 - if (address < vma->vm_start) {
72659 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72660 + error = -ENOMEM;
72661 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72662 unsigned long size, grow;
72663
72664 +#ifdef CONFIG_PAX_SEGMEXEC
72665 + struct vm_area_struct *vma_m;
72666 +
72667 + vma_m = pax_find_mirror_vma(vma);
72668 +#endif
72669 +
72670 size = vma->vm_end - address;
72671 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72672
72673 @@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72674 if (!error) {
72675 vma->vm_start = address;
72676 vma->vm_pgoff -= grow;
72677 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72678 +
72679 +#ifdef CONFIG_PAX_SEGMEXEC
72680 + if (vma_m) {
72681 + vma_m->vm_start -= grow << PAGE_SHIFT;
72682 + vma_m->vm_pgoff -= grow;
72683 + }
72684 +#endif
72685 +
72686 perf_event_mmap(vma);
72687 }
72688 }
72689 }
72690 vma_unlock_anon_vma(vma);
72691 + if (lockprev)
72692 + vma_unlock_anon_vma(prev);
72693 khugepaged_enter_vma_merge(vma);
72694 return error;
72695 }
72696 @@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72697 do {
72698 long nrpages = vma_pages(vma);
72699
72700 +#ifdef CONFIG_PAX_SEGMEXEC
72701 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72702 + vma = remove_vma(vma);
72703 + continue;
72704 + }
72705 +#endif
72706 +
72707 if (vma->vm_flags & VM_ACCOUNT)
72708 nr_accounted += nrpages;
72709 mm->total_vm -= nrpages;
72710 @@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72711 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72712 vma->vm_prev = NULL;
72713 do {
72714 +
72715 +#ifdef CONFIG_PAX_SEGMEXEC
72716 + if (vma->vm_mirror) {
72717 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72718 + vma->vm_mirror->vm_mirror = NULL;
72719 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72720 + vma->vm_mirror = NULL;
72721 + }
72722 +#endif
72723 +
72724 rb_erase(&vma->vm_rb, &mm->mm_rb);
72725 mm->map_count--;
72726 tail_vma = vma;
72727 @@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72728 struct vm_area_struct *new;
72729 int err = -ENOMEM;
72730
72731 +#ifdef CONFIG_PAX_SEGMEXEC
72732 + struct vm_area_struct *vma_m, *new_m = NULL;
72733 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72734 +#endif
72735 +
72736 if (is_vm_hugetlb_page(vma) && (addr &
72737 ~(huge_page_mask(hstate_vma(vma)))))
72738 return -EINVAL;
72739
72740 +#ifdef CONFIG_PAX_SEGMEXEC
72741 + vma_m = pax_find_mirror_vma(vma);
72742 +#endif
72743 +
72744 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72745 if (!new)
72746 goto out_err;
72747
72748 +#ifdef CONFIG_PAX_SEGMEXEC
72749 + if (vma_m) {
72750 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72751 + if (!new_m) {
72752 + kmem_cache_free(vm_area_cachep, new);
72753 + goto out_err;
72754 + }
72755 + }
72756 +#endif
72757 +
72758 /* most fields are the same, copy all, and then fixup */
72759 *new = *vma;
72760
72761 @@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72762 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72763 }
72764
72765 +#ifdef CONFIG_PAX_SEGMEXEC
72766 + if (vma_m) {
72767 + *new_m = *vma_m;
72768 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72769 + new_m->vm_mirror = new;
72770 + new->vm_mirror = new_m;
72771 +
72772 + if (new_below)
72773 + new_m->vm_end = addr_m;
72774 + else {
72775 + new_m->vm_start = addr_m;
72776 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72777 + }
72778 + }
72779 +#endif
72780 +
72781 pol = mpol_dup(vma_policy(vma));
72782 if (IS_ERR(pol)) {
72783 err = PTR_ERR(pol);
72784 @@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72785 else
72786 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72787
72788 +#ifdef CONFIG_PAX_SEGMEXEC
72789 + if (!err && vma_m) {
72790 + if (anon_vma_clone(new_m, vma_m))
72791 + goto out_free_mpol;
72792 +
72793 + mpol_get(pol);
72794 + vma_set_policy(new_m, pol);
72795 +
72796 + if (new_m->vm_file) {
72797 + get_file(new_m->vm_file);
72798 + if (vma_m->vm_flags & VM_EXECUTABLE)
72799 + added_exe_file_vma(mm);
72800 + }
72801 +
72802 + if (new_m->vm_ops && new_m->vm_ops->open)
72803 + new_m->vm_ops->open(new_m);
72804 +
72805 + if (new_below)
72806 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72807 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72808 + else
72809 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72810 +
72811 + if (err) {
72812 + if (new_m->vm_ops && new_m->vm_ops->close)
72813 + new_m->vm_ops->close(new_m);
72814 + if (new_m->vm_file) {
72815 + if (vma_m->vm_flags & VM_EXECUTABLE)
72816 + removed_exe_file_vma(mm);
72817 + fput(new_m->vm_file);
72818 + }
72819 + mpol_put(pol);
72820 + }
72821 + }
72822 +#endif
72823 +
72824 /* Success. */
72825 if (!err)
72826 return 0;
72827 @@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72828 removed_exe_file_vma(mm);
72829 fput(new->vm_file);
72830 }
72831 - unlink_anon_vmas(new);
72832 out_free_mpol:
72833 mpol_put(pol);
72834 out_free_vma:
72835 +
72836 +#ifdef CONFIG_PAX_SEGMEXEC
72837 + if (new_m) {
72838 + unlink_anon_vmas(new_m);
72839 + kmem_cache_free(vm_area_cachep, new_m);
72840 + }
72841 +#endif
72842 +
72843 + unlink_anon_vmas(new);
72844 kmem_cache_free(vm_area_cachep, new);
72845 out_err:
72846 return err;
72847 @@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72848 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72849 unsigned long addr, int new_below)
72850 {
72851 +
72852 +#ifdef CONFIG_PAX_SEGMEXEC
72853 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72854 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72855 + if (mm->map_count >= sysctl_max_map_count-1)
72856 + return -ENOMEM;
72857 + } else
72858 +#endif
72859 +
72860 if (mm->map_count >= sysctl_max_map_count)
72861 return -ENOMEM;
72862
72863 @@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72864 * work. This now handles partial unmappings.
72865 * Jeremy Fitzhardinge <jeremy@goop.org>
72866 */
72867 +#ifdef CONFIG_PAX_SEGMEXEC
72868 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72869 {
72870 + int ret = __do_munmap(mm, start, len);
72871 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72872 + return ret;
72873 +
72874 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72875 +}
72876 +
72877 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72878 +#else
72879 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72880 +#endif
72881 +{
72882 unsigned long end;
72883 struct vm_area_struct *vma, *prev, *last;
72884
72885 + /*
72886 + * mm->mmap_sem is required to protect against another thread
72887 + * changing the mappings in case we sleep.
72888 + */
72889 + verify_mm_writelocked(mm);
72890 +
72891 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72892 return -EINVAL;
72893
72894 @@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72895 /* Fix up all other VM information */
72896 remove_vma_list(mm, vma);
72897
72898 + track_exec_limit(mm, start, end, 0UL);
72899 +
72900 return 0;
72901 }
72902
72903 @@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
72904 int ret;
72905 struct mm_struct *mm = current->mm;
72906
72907 +
72908 +#ifdef CONFIG_PAX_SEGMEXEC
72909 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72910 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
72911 + return -EINVAL;
72912 +#endif
72913 +
72914 down_write(&mm->mmap_sem);
72915 ret = do_munmap(mm, start, len);
72916 up_write(&mm->mmap_sem);
72917 @@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72918 return vm_munmap(addr, len);
72919 }
72920
72921 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72922 -{
72923 -#ifdef CONFIG_DEBUG_VM
72924 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72925 - WARN_ON(1);
72926 - up_read(&mm->mmap_sem);
72927 - }
72928 -#endif
72929 -}
72930 -
72931 /*
72932 * this is really a simplified "do_mmap". it only handles
72933 * anonymous maps. eventually we may be able to do some
72934 @@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72935 struct rb_node ** rb_link, * rb_parent;
72936 pgoff_t pgoff = addr >> PAGE_SHIFT;
72937 int error;
72938 + unsigned long charged;
72939
72940 len = PAGE_ALIGN(len);
72941 if (!len)
72942 @@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72943
72944 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72945
72946 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72947 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72948 + flags &= ~VM_EXEC;
72949 +
72950 +#ifdef CONFIG_PAX_MPROTECT
72951 + if (mm->pax_flags & MF_PAX_MPROTECT)
72952 + flags &= ~VM_MAYEXEC;
72953 +#endif
72954 +
72955 + }
72956 +#endif
72957 +
72958 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72959 if (error & ~PAGE_MASK)
72960 return error;
72961
72962 + charged = len >> PAGE_SHIFT;
72963 +
72964 /*
72965 * mlock MCL_FUTURE?
72966 */
72967 if (mm->def_flags & VM_LOCKED) {
72968 unsigned long locked, lock_limit;
72969 - locked = len >> PAGE_SHIFT;
72970 + locked = charged;
72971 locked += mm->locked_vm;
72972 lock_limit = rlimit(RLIMIT_MEMLOCK);
72973 lock_limit >>= PAGE_SHIFT;
72974 @@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72975 /*
72976 * Clear old maps. this also does some error checking for us
72977 */
72978 - munmap_back:
72979 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72980 if (vma && vma->vm_start < addr + len) {
72981 if (do_munmap(mm, addr, len))
72982 return -ENOMEM;
72983 - goto munmap_back;
72984 - }
72985 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72986 + BUG_ON(vma && vma->vm_start < addr + len);
72987 + }
72988
72989 /* Check against address space limits *after* clearing old maps... */
72990 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72991 + if (!may_expand_vm(mm, charged))
72992 return -ENOMEM;
72993
72994 if (mm->map_count > sysctl_max_map_count)
72995 return -ENOMEM;
72996
72997 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
72998 + if (security_vm_enough_memory_mm(mm, charged))
72999 return -ENOMEM;
73000
73001 /* Can we just expand an old private anonymous mapping? */
73002 @@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73003 */
73004 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73005 if (!vma) {
73006 - vm_unacct_memory(len >> PAGE_SHIFT);
73007 + vm_unacct_memory(charged);
73008 return -ENOMEM;
73009 }
73010
73011 @@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73012 vma_link(mm, vma, prev, rb_link, rb_parent);
73013 out:
73014 perf_event_mmap(vma);
73015 - mm->total_vm += len >> PAGE_SHIFT;
73016 + mm->total_vm += charged;
73017 if (flags & VM_LOCKED) {
73018 if (!mlock_vma_pages_range(vma, addr, addr + len))
73019 - mm->locked_vm += (len >> PAGE_SHIFT);
73020 + mm->locked_vm += charged;
73021 }
73022 + track_exec_limit(mm, addr, addr + len, flags);
73023 return addr;
73024 }
73025
73026 @@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
73027 while (vma) {
73028 if (vma->vm_flags & VM_ACCOUNT)
73029 nr_accounted += vma_pages(vma);
73030 + vma->vm_mirror = NULL;
73031 vma = remove_vma(vma);
73032 }
73033 vm_unacct_memory(nr_accounted);
73034 @@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73035 struct vm_area_struct * __vma, * prev;
73036 struct rb_node ** rb_link, * rb_parent;
73037
73038 +#ifdef CONFIG_PAX_SEGMEXEC
73039 + struct vm_area_struct *vma_m = NULL;
73040 +#endif
73041 +
73042 + if (security_mmap_addr(vma->vm_start))
73043 + return -EPERM;
73044 +
73045 /*
73046 * The vm_pgoff of a purely anonymous vma should be irrelevant
73047 * until its first write fault, when page's anon_vma and index
73048 @@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73049 if (vma->vm_file && uprobe_mmap(vma))
73050 return -EINVAL;
73051
73052 +#ifdef CONFIG_PAX_SEGMEXEC
73053 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73054 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73055 + if (!vma_m)
73056 + return -ENOMEM;
73057 + }
73058 +#endif
73059 +
73060 vma_link(mm, vma, prev, rb_link, rb_parent);
73061 +
73062 +#ifdef CONFIG_PAX_SEGMEXEC
73063 + if (vma_m)
73064 + BUG_ON(pax_mirror_vma(vma_m, vma));
73065 +#endif
73066 +
73067 return 0;
73068 }
73069
73070 @@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73071 struct mempolicy *pol;
73072 bool faulted_in_anon_vma = true;
73073
73074 + BUG_ON(vma->vm_mirror);
73075 +
73076 /*
73077 * If anonymous vma has not yet been faulted, update new pgoff
73078 * to match new location, to increase its chance of merging.
73079 @@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73080 return NULL;
73081 }
73082
73083 +#ifdef CONFIG_PAX_SEGMEXEC
73084 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73085 +{
73086 + struct vm_area_struct *prev_m;
73087 + struct rb_node **rb_link_m, *rb_parent_m;
73088 + struct mempolicy *pol_m;
73089 +
73090 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73091 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73092 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73093 + *vma_m = *vma;
73094 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73095 + if (anon_vma_clone(vma_m, vma))
73096 + return -ENOMEM;
73097 + pol_m = vma_policy(vma_m);
73098 + mpol_get(pol_m);
73099 + vma_set_policy(vma_m, pol_m);
73100 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73101 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73102 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73103 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73104 + if (vma_m->vm_file)
73105 + get_file(vma_m->vm_file);
73106 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73107 + vma_m->vm_ops->open(vma_m);
73108 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73109 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73110 + vma_m->vm_mirror = vma;
73111 + vma->vm_mirror = vma_m;
73112 + return 0;
73113 +}
73114 +#endif
73115 +
73116 /*
73117 * Return true if the calling process may expand its vm space by the passed
73118 * number of pages
73119 @@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73120
73121 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73122
73123 +#ifdef CONFIG_PAX_RANDMMAP
73124 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73125 + cur -= mm->brk_gap;
73126 +#endif
73127 +
73128 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73129 if (cur + npages > lim)
73130 return 0;
73131 return 1;
73132 @@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73133 vma->vm_start = addr;
73134 vma->vm_end = addr + len;
73135
73136 +#ifdef CONFIG_PAX_MPROTECT
73137 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73138 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73139 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73140 + return -EPERM;
73141 + if (!(vm_flags & VM_EXEC))
73142 + vm_flags &= ~VM_MAYEXEC;
73143 +#else
73144 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73145 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73146 +#endif
73147 + else
73148 + vm_flags &= ~VM_MAYWRITE;
73149 + }
73150 +#endif
73151 +
73152 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73153 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73154
73155 diff --git a/mm/mprotect.c b/mm/mprotect.c
73156 index a409926..8b32e6d 100644
73157 --- a/mm/mprotect.c
73158 +++ b/mm/mprotect.c
73159 @@ -23,10 +23,17 @@
73160 #include <linux/mmu_notifier.h>
73161 #include <linux/migrate.h>
73162 #include <linux/perf_event.h>
73163 +
73164 +#ifdef CONFIG_PAX_MPROTECT
73165 +#include <linux/elf.h>
73166 +#include <linux/binfmts.h>
73167 +#endif
73168 +
73169 #include <asm/uaccess.h>
73170 #include <asm/pgtable.h>
73171 #include <asm/cacheflush.h>
73172 #include <asm/tlbflush.h>
73173 +#include <asm/mmu_context.h>
73174
73175 #ifndef pgprot_modify
73176 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73177 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73178 flush_tlb_range(vma, start, end);
73179 }
73180
73181 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73182 +/* called while holding the mmap semaphor for writing except stack expansion */
73183 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73184 +{
73185 + unsigned long oldlimit, newlimit = 0UL;
73186 +
73187 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73188 + return;
73189 +
73190 + spin_lock(&mm->page_table_lock);
73191 + oldlimit = mm->context.user_cs_limit;
73192 + if ((prot & VM_EXEC) && oldlimit < end)
73193 + /* USER_CS limit moved up */
73194 + newlimit = end;
73195 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73196 + /* USER_CS limit moved down */
73197 + newlimit = start;
73198 +
73199 + if (newlimit) {
73200 + mm->context.user_cs_limit = newlimit;
73201 +
73202 +#ifdef CONFIG_SMP
73203 + wmb();
73204 + cpus_clear(mm->context.cpu_user_cs_mask);
73205 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73206 +#endif
73207 +
73208 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73209 + }
73210 + spin_unlock(&mm->page_table_lock);
73211 + if (newlimit == end) {
73212 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73213 +
73214 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73215 + if (is_vm_hugetlb_page(vma))
73216 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73217 + else
73218 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73219 + }
73220 +}
73221 +#endif
73222 +
73223 int
73224 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73225 unsigned long start, unsigned long end, unsigned long newflags)
73226 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73227 int error;
73228 int dirty_accountable = 0;
73229
73230 +#ifdef CONFIG_PAX_SEGMEXEC
73231 + struct vm_area_struct *vma_m = NULL;
73232 + unsigned long start_m, end_m;
73233 +
73234 + start_m = start + SEGMEXEC_TASK_SIZE;
73235 + end_m = end + SEGMEXEC_TASK_SIZE;
73236 +#endif
73237 +
73238 if (newflags == oldflags) {
73239 *pprev = vma;
73240 return 0;
73241 }
73242
73243 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73244 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73245 +
73246 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73247 + return -ENOMEM;
73248 +
73249 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73250 + return -ENOMEM;
73251 + }
73252 +
73253 /*
73254 * If we make a private mapping writable we increase our commit;
73255 * but (without finer accounting) cannot reduce our commit if we
73256 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73257 }
73258 }
73259
73260 +#ifdef CONFIG_PAX_SEGMEXEC
73261 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73262 + if (start != vma->vm_start) {
73263 + error = split_vma(mm, vma, start, 1);
73264 + if (error)
73265 + goto fail;
73266 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73267 + *pprev = (*pprev)->vm_next;
73268 + }
73269 +
73270 + if (end != vma->vm_end) {
73271 + error = split_vma(mm, vma, end, 0);
73272 + if (error)
73273 + goto fail;
73274 + }
73275 +
73276 + if (pax_find_mirror_vma(vma)) {
73277 + error = __do_munmap(mm, start_m, end_m - start_m);
73278 + if (error)
73279 + goto fail;
73280 + } else {
73281 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73282 + if (!vma_m) {
73283 + error = -ENOMEM;
73284 + goto fail;
73285 + }
73286 + vma->vm_flags = newflags;
73287 + error = pax_mirror_vma(vma_m, vma);
73288 + if (error) {
73289 + vma->vm_flags = oldflags;
73290 + goto fail;
73291 + }
73292 + }
73293 + }
73294 +#endif
73295 +
73296 /*
73297 * First try to merge with previous and/or next vma.
73298 */
73299 @@ -204,9 +307,21 @@ success:
73300 * vm_flags and vm_page_prot are protected by the mmap_sem
73301 * held in write mode.
73302 */
73303 +
73304 +#ifdef CONFIG_PAX_SEGMEXEC
73305 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73306 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73307 +#endif
73308 +
73309 vma->vm_flags = newflags;
73310 +
73311 +#ifdef CONFIG_PAX_MPROTECT
73312 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73313 + mm->binfmt->handle_mprotect(vma, newflags);
73314 +#endif
73315 +
73316 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73317 - vm_get_page_prot(newflags));
73318 + vm_get_page_prot(vma->vm_flags));
73319
73320 if (vma_wants_writenotify(vma)) {
73321 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73322 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73323 end = start + len;
73324 if (end <= start)
73325 return -ENOMEM;
73326 +
73327 +#ifdef CONFIG_PAX_SEGMEXEC
73328 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73329 + if (end > SEGMEXEC_TASK_SIZE)
73330 + return -EINVAL;
73331 + } else
73332 +#endif
73333 +
73334 + if (end > TASK_SIZE)
73335 + return -EINVAL;
73336 +
73337 if (!arch_validate_prot(prot))
73338 return -EINVAL;
73339
73340 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73341 /*
73342 * Does the application expect PROT_READ to imply PROT_EXEC:
73343 */
73344 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73345 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73346 prot |= PROT_EXEC;
73347
73348 vm_flags = calc_vm_prot_bits(prot);
73349 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73350 if (start > vma->vm_start)
73351 prev = vma;
73352
73353 +#ifdef CONFIG_PAX_MPROTECT
73354 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73355 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73356 +#endif
73357 +
73358 for (nstart = start ; ; ) {
73359 unsigned long newflags;
73360
73361 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73362
73363 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73364 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73365 + if (prot & (PROT_WRITE | PROT_EXEC))
73366 + gr_log_rwxmprotect(vma->vm_file);
73367 +
73368 + error = -EACCES;
73369 + goto out;
73370 + }
73371 +
73372 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73373 error = -EACCES;
73374 goto out;
73375 }
73376 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73377 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73378 if (error)
73379 goto out;
73380 +
73381 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
73382 +
73383 nstart = tmp;
73384
73385 if (nstart < prev->vm_end)
73386 diff --git a/mm/mremap.c b/mm/mremap.c
73387 index 21fed20..6822658 100644
73388 --- a/mm/mremap.c
73389 +++ b/mm/mremap.c
73390 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73391 continue;
73392 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73393 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73394 +
73395 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73396 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73397 + pte = pte_exprotect(pte);
73398 +#endif
73399 +
73400 set_pte_at(mm, new_addr, new_pte, pte);
73401 }
73402
73403 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73404 if (is_vm_hugetlb_page(vma))
73405 goto Einval;
73406
73407 +#ifdef CONFIG_PAX_SEGMEXEC
73408 + if (pax_find_mirror_vma(vma))
73409 + goto Einval;
73410 +#endif
73411 +
73412 /* We can't remap across vm area boundaries */
73413 if (old_len > vma->vm_end - addr)
73414 goto Efault;
73415 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73416 unsigned long ret = -EINVAL;
73417 unsigned long charged = 0;
73418 unsigned long map_flags;
73419 + unsigned long pax_task_size = TASK_SIZE;
73420
73421 if (new_addr & ~PAGE_MASK)
73422 goto out;
73423
73424 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73425 +#ifdef CONFIG_PAX_SEGMEXEC
73426 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73427 + pax_task_size = SEGMEXEC_TASK_SIZE;
73428 +#endif
73429 +
73430 + pax_task_size -= PAGE_SIZE;
73431 +
73432 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73433 goto out;
73434
73435 /* Check if the location we're moving into overlaps the
73436 * old location at all, and fail if it does.
73437 */
73438 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
73439 - goto out;
73440 -
73441 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
73442 + if (addr + old_len > new_addr && new_addr + new_len > addr)
73443 goto out;
73444
73445 ret = do_munmap(mm, new_addr, new_len);
73446 @@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73447 struct vm_area_struct *vma;
73448 unsigned long ret = -EINVAL;
73449 unsigned long charged = 0;
73450 + unsigned long pax_task_size = TASK_SIZE;
73451
73452 down_write(&current->mm->mmap_sem);
73453
73454 @@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73455 if (!new_len)
73456 goto out;
73457
73458 +#ifdef CONFIG_PAX_SEGMEXEC
73459 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
73460 + pax_task_size = SEGMEXEC_TASK_SIZE;
73461 +#endif
73462 +
73463 + pax_task_size -= PAGE_SIZE;
73464 +
73465 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73466 + old_len > pax_task_size || addr > pax_task_size-old_len)
73467 + goto out;
73468 +
73469 if (flags & MREMAP_FIXED) {
73470 if (flags & MREMAP_MAYMOVE)
73471 ret = mremap_to(addr, old_len, new_addr, new_len);
73472 @@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73473 addr + new_len);
73474 }
73475 ret = addr;
73476 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73477 goto out;
73478 }
73479 }
73480 @@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73481 goto out;
73482 }
73483
73484 + map_flags = vma->vm_flags;
73485 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73486 + if (!(ret & ~PAGE_MASK)) {
73487 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73488 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73489 + }
73490 }
73491 out:
73492 if (ret & ~PAGE_MASK)
73493 diff --git a/mm/nommu.c b/mm/nommu.c
73494 index d4b0c10..ed421b5 100644
73495 --- a/mm/nommu.c
73496 +++ b/mm/nommu.c
73497 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73498 int sysctl_overcommit_ratio = 50; /* default is 50% */
73499 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73500 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73501 -int heap_stack_gap = 0;
73502
73503 atomic_long_t mmap_pages_allocated;
73504
73505 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73506 EXPORT_SYMBOL(find_vma);
73507
73508 /*
73509 - * find a VMA
73510 - * - we don't extend stack VMAs under NOMMU conditions
73511 - */
73512 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73513 -{
73514 - return find_vma(mm, addr);
73515 -}
73516 -
73517 -/*
73518 * expand a stack to a given address
73519 * - not supported under NOMMU conditions
73520 */
73521 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73522
73523 /* most fields are the same, copy all, and then fixup */
73524 *new = *vma;
73525 + INIT_LIST_HEAD(&new->anon_vma_chain);
73526 *region = *vma->vm_region;
73527 new->vm_region = region;
73528
73529 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73530 index 4a4f921..eaa5e3a 100644
73531 --- a/mm/page_alloc.c
73532 +++ b/mm/page_alloc.c
73533 @@ -336,7 +336,7 @@ out:
73534 * This usage means that zero-order pages may not be compound.
73535 */
73536
73537 -static void free_compound_page(struct page *page)
73538 +void free_compound_page(struct page *page)
73539 {
73540 __free_pages_ok(page, compound_order(page));
73541 }
73542 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73543 int i;
73544 int bad = 0;
73545
73546 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73547 + unsigned long index = 1UL << order;
73548 +#endif
73549 +
73550 trace_mm_page_free(page, order);
73551 kmemcheck_free_shadow(page, order);
73552
73553 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73554 debug_check_no_obj_freed(page_address(page),
73555 PAGE_SIZE << order);
73556 }
73557 +
73558 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73559 + for (; index; --index)
73560 + sanitize_highpage(page + index - 1);
73561 +#endif
73562 +
73563 arch_free_page(page, order);
73564 kernel_map_pages(page, 1 << order, 0);
73565
73566 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73567 arch_alloc_page(page, order);
73568 kernel_map_pages(page, 1 << order, 1);
73569
73570 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73571 if (gfp_flags & __GFP_ZERO)
73572 prep_zero_page(page, order, gfp_flags);
73573 +#endif
73574
73575 if (order && (gfp_flags & __GFP_COMP))
73576 prep_compound_page(page, order);
73577 @@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73578 unsigned long pfn;
73579
73580 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73581 +#ifdef CONFIG_X86_32
73582 + /* boot failures in VMware 8 on 32bit vanilla since
73583 + this change */
73584 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73585 +#else
73586 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73587 +#endif
73588 return 1;
73589 }
73590 return 0;
73591 diff --git a/mm/percpu.c b/mm/percpu.c
73592 index bb4be74..a43ea85 100644
73593 --- a/mm/percpu.c
73594 +++ b/mm/percpu.c
73595 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73596 static unsigned int pcpu_high_unit_cpu __read_mostly;
73597
73598 /* the address of the first chunk which starts with the kernel static area */
73599 -void *pcpu_base_addr __read_mostly;
73600 +void *pcpu_base_addr __read_only;
73601 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73602
73603 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73604 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73605 index 926b466..b23df53 100644
73606 --- a/mm/process_vm_access.c
73607 +++ b/mm/process_vm_access.c
73608 @@ -13,6 +13,7 @@
73609 #include <linux/uio.h>
73610 #include <linux/sched.h>
73611 #include <linux/highmem.h>
73612 +#include <linux/security.h>
73613 #include <linux/ptrace.h>
73614 #include <linux/slab.h>
73615 #include <linux/syscalls.h>
73616 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73617 size_t iov_l_curr_offset = 0;
73618 ssize_t iov_len;
73619
73620 + return -ENOSYS; // PaX: until properly audited
73621 +
73622 /*
73623 * Work out how many pages of struct pages we're going to need
73624 * when eventually calling get_user_pages
73625 */
73626 for (i = 0; i < riovcnt; i++) {
73627 iov_len = rvec[i].iov_len;
73628 - if (iov_len > 0) {
73629 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73630 - + iov_len)
73631 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73632 - / PAGE_SIZE + 1;
73633 - nr_pages = max(nr_pages, nr_pages_iov);
73634 - }
73635 + if (iov_len <= 0)
73636 + continue;
73637 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73638 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73639 + nr_pages = max(nr_pages, nr_pages_iov);
73640 }
73641
73642 if (nr_pages == 0)
73643 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73644 goto free_proc_pages;
73645 }
73646
73647 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73648 + rc = -EPERM;
73649 + goto put_task_struct;
73650 + }
73651 +
73652 mm = mm_access(task, PTRACE_MODE_ATTACH);
73653 if (!mm || IS_ERR(mm)) {
73654 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73655 diff --git a/mm/rmap.c b/mm/rmap.c
73656 index 0f3b7cd..c5652b6 100644
73657 --- a/mm/rmap.c
73658 +++ b/mm/rmap.c
73659 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73660 struct anon_vma *anon_vma = vma->anon_vma;
73661 struct anon_vma_chain *avc;
73662
73663 +#ifdef CONFIG_PAX_SEGMEXEC
73664 + struct anon_vma_chain *avc_m = NULL;
73665 +#endif
73666 +
73667 might_sleep();
73668 if (unlikely(!anon_vma)) {
73669 struct mm_struct *mm = vma->vm_mm;
73670 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73671 if (!avc)
73672 goto out_enomem;
73673
73674 +#ifdef CONFIG_PAX_SEGMEXEC
73675 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73676 + if (!avc_m)
73677 + goto out_enomem_free_avc;
73678 +#endif
73679 +
73680 anon_vma = find_mergeable_anon_vma(vma);
73681 allocated = NULL;
73682 if (!anon_vma) {
73683 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73684 /* page_table_lock to protect against threads */
73685 spin_lock(&mm->page_table_lock);
73686 if (likely(!vma->anon_vma)) {
73687 +
73688 +#ifdef CONFIG_PAX_SEGMEXEC
73689 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73690 +
73691 + if (vma_m) {
73692 + BUG_ON(vma_m->anon_vma);
73693 + vma_m->anon_vma = anon_vma;
73694 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
73695 + avc_m = NULL;
73696 + }
73697 +#endif
73698 +
73699 vma->anon_vma = anon_vma;
73700 anon_vma_chain_link(vma, avc, anon_vma);
73701 allocated = NULL;
73702 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73703
73704 if (unlikely(allocated))
73705 put_anon_vma(allocated);
73706 +
73707 +#ifdef CONFIG_PAX_SEGMEXEC
73708 + if (unlikely(avc_m))
73709 + anon_vma_chain_free(avc_m);
73710 +#endif
73711 +
73712 if (unlikely(avc))
73713 anon_vma_chain_free(avc);
73714 }
73715 return 0;
73716
73717 out_enomem_free_avc:
73718 +
73719 +#ifdef CONFIG_PAX_SEGMEXEC
73720 + if (avc_m)
73721 + anon_vma_chain_free(avc_m);
73722 +#endif
73723 +
73724 anon_vma_chain_free(avc);
73725 out_enomem:
73726 return -ENOMEM;
73727 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73728 * Attach the anon_vmas from src to dst.
73729 * Returns 0 on success, -ENOMEM on failure.
73730 */
73731 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73732 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73733 {
73734 struct anon_vma_chain *avc, *pavc;
73735 struct anon_vma *root = NULL;
73736 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73737 * the corresponding VMA in the parent process is attached to.
73738 * Returns 0 on success, non-zero on failure.
73739 */
73740 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73741 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73742 {
73743 struct anon_vma_chain *avc;
73744 struct anon_vma *anon_vma;
73745 diff --git a/mm/shmem.c b/mm/shmem.c
73746 index bd10636..5c16d49 100644
73747 --- a/mm/shmem.c
73748 +++ b/mm/shmem.c
73749 @@ -31,7 +31,7 @@
73750 #include <linux/export.h>
73751 #include <linux/swap.h>
73752
73753 -static struct vfsmount *shm_mnt;
73754 +struct vfsmount *shm_mnt;
73755
73756 #ifdef CONFIG_SHMEM
73757 /*
73758 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73759 #define BOGO_DIRENT_SIZE 20
73760
73761 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73762 -#define SHORT_SYMLINK_LEN 128
73763 +#define SHORT_SYMLINK_LEN 64
73764
73765 struct shmem_xattr {
73766 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73767 @@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73768 int err = -ENOMEM;
73769
73770 /* Round up to L1_CACHE_BYTES to resist false sharing */
73771 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73772 - L1_CACHE_BYTES), GFP_KERNEL);
73773 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73774 if (!sbinfo)
73775 return -ENOMEM;
73776
73777 diff --git a/mm/slab.c b/mm/slab.c
73778 index e901a36..ca479fc 100644
73779 --- a/mm/slab.c
73780 +++ b/mm/slab.c
73781 @@ -153,7 +153,7 @@
73782
73783 /* Legal flag mask for kmem_cache_create(). */
73784 #if DEBUG
73785 -# define CREATE_MASK (SLAB_RED_ZONE | \
73786 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73787 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73788 SLAB_CACHE_DMA | \
73789 SLAB_STORE_USER | \
73790 @@ -161,7 +161,7 @@
73791 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73792 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73793 #else
73794 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73795 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73796 SLAB_CACHE_DMA | \
73797 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73798 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73799 @@ -290,7 +290,7 @@ struct kmem_list3 {
73800 * Need this for bootstrapping a per node allocator.
73801 */
73802 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73803 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73804 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73805 #define CACHE_CACHE 0
73806 #define SIZE_AC MAX_NUMNODES
73807 #define SIZE_L3 (2 * MAX_NUMNODES)
73808 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73809 if ((x)->max_freeable < i) \
73810 (x)->max_freeable = i; \
73811 } while (0)
73812 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73813 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73814 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73815 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73816 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73817 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73818 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73819 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73820 #else
73821 #define STATS_INC_ACTIVE(x) do { } while (0)
73822 #define STATS_DEC_ACTIVE(x) do { } while (0)
73823 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73824 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73825 */
73826 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73827 - const struct slab *slab, void *obj)
73828 + const struct slab *slab, const void *obj)
73829 {
73830 u32 offset = (obj - slab->s_mem);
73831 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73832 @@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73833 struct cache_names {
73834 char *name;
73835 char *name_dma;
73836 + char *name_usercopy;
73837 };
73838
73839 static struct cache_names __initdata cache_names[] = {
73840 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73841 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73842 #include <linux/kmalloc_sizes.h>
73843 - {NULL,}
73844 + {NULL}
73845 #undef CACHE
73846 };
73847
73848 @@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73849 if (unlikely(gfpflags & GFP_DMA))
73850 return csizep->cs_dmacachep;
73851 #endif
73852 +
73853 +#ifdef CONFIG_PAX_USERCOPY_SLABS
73854 + if (unlikely(gfpflags & GFP_USERCOPY))
73855 + return csizep->cs_usercopycachep;
73856 +#endif
73857 +
73858 return csizep->cs_cachep;
73859 }
73860
73861 @@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73862 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73863 sizes[INDEX_AC].cs_size,
73864 ARCH_KMALLOC_MINALIGN,
73865 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73866 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73867 NULL);
73868
73869 if (INDEX_AC != INDEX_L3) {
73870 @@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73871 kmem_cache_create(names[INDEX_L3].name,
73872 sizes[INDEX_L3].cs_size,
73873 ARCH_KMALLOC_MINALIGN,
73874 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73875 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73876 NULL);
73877 }
73878
73879 @@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73880 sizes->cs_cachep = kmem_cache_create(names->name,
73881 sizes->cs_size,
73882 ARCH_KMALLOC_MINALIGN,
73883 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73884 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73885 NULL);
73886 }
73887 #ifdef CONFIG_ZONE_DMA
73888 @@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73889 SLAB_PANIC,
73890 NULL);
73891 #endif
73892 +
73893 +#ifdef CONFIG_PAX_USERCOPY_SLABS
73894 + sizes->cs_usercopycachep = kmem_cache_create(
73895 + names->name_usercopy,
73896 + sizes->cs_size,
73897 + ARCH_KMALLOC_MINALIGN,
73898 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73899 + NULL);
73900 +#endif
73901 +
73902 sizes++;
73903 names++;
73904 }
73905 @@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
73906 }
73907 /* cpu stats */
73908 {
73909 - unsigned long allochit = atomic_read(&cachep->allochit);
73910 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73911 - unsigned long freehit = atomic_read(&cachep->freehit);
73912 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73913 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73914 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73915 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73916 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73917
73918 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73919 allochit, allocmiss, freehit, freemiss);
73920 @@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
73921 {
73922 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73923 #ifdef CONFIG_DEBUG_SLAB_LEAK
73924 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73925 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73926 #endif
73927 return 0;
73928 }
73929 module_init(slab_proc_init);
73930 #endif
73931
73932 +bool is_usercopy_object(const void *ptr)
73933 +{
73934 + struct page *page;
73935 + struct kmem_cache *cachep;
73936 +
73937 + if (ZERO_OR_NULL_PTR(ptr))
73938 + return false;
73939 +
73940 + if (!virt_addr_valid(ptr))
73941 + return false;
73942 +
73943 + page = virt_to_head_page(ptr);
73944 +
73945 + if (!PageSlab(page))
73946 + return false;
73947 +
73948 + cachep = page_get_cache(page);
73949 + return cachep->flags & SLAB_USERCOPY;
73950 +}
73951 +
73952 +#ifdef CONFIG_PAX_USERCOPY
73953 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
73954 +{
73955 + struct page *page;
73956 + struct kmem_cache *cachep;
73957 + struct slab *slabp;
73958 + unsigned int objnr;
73959 + unsigned long offset;
73960 +
73961 + if (ZERO_OR_NULL_PTR(ptr))
73962 + return "<null>";
73963 +
73964 + if (!virt_addr_valid(ptr))
73965 + return NULL;
73966 +
73967 + page = virt_to_head_page(ptr);
73968 +
73969 + if (!PageSlab(page))
73970 + return NULL;
73971 +
73972 + cachep = page_get_cache(page);
73973 + if (!(cachep->flags & SLAB_USERCOPY))
73974 + return cachep->name;
73975 +
73976 + slabp = page_get_slab(page);
73977 + objnr = obj_to_index(cachep, slabp, ptr);
73978 + BUG_ON(objnr >= cachep->num);
73979 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73980 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73981 + return NULL;
73982 +
73983 + return cachep->name;
73984 +}
73985 +#endif
73986 +
73987 /**
73988 * ksize - get the actual amount of memory allocated for a given object
73989 * @objp: Pointer to the object
73990 diff --git a/mm/slob.c b/mm/slob.c
73991 index 8105be4..3c15e57 100644
73992 --- a/mm/slob.c
73993 +++ b/mm/slob.c
73994 @@ -29,7 +29,7 @@
73995 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73996 * alloc_pages() directly, allocating compound pages so the page order
73997 * does not have to be separately tracked, and also stores the exact
73998 - * allocation size in page->private so that it can be used to accurately
73999 + * allocation size in slob_page->size so that it can be used to accurately
74000 * provide ksize(). These objects are detected in kfree() because slob_page()
74001 * is false for them.
74002 *
74003 @@ -58,6 +58,7 @@
74004 */
74005
74006 #include <linux/kernel.h>
74007 +#include <linux/sched.h>
74008 #include <linux/slab.h>
74009 #include <linux/mm.h>
74010 #include <linux/swap.h> /* struct reclaim_state */
74011 @@ -102,7 +103,8 @@ struct slob_page {
74012 unsigned long flags; /* mandatory */
74013 atomic_t _count; /* mandatory */
74014 slobidx_t units; /* free units left in page */
74015 - unsigned long pad[2];
74016 + unsigned long pad[1];
74017 + unsigned long size; /* size when >=PAGE_SIZE */
74018 slob_t *free; /* first free slob_t in page */
74019 struct list_head list; /* linked list of free pages */
74020 };
74021 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74022 */
74023 static inline int is_slob_page(struct slob_page *sp)
74024 {
74025 - return PageSlab((struct page *)sp);
74026 + return PageSlab((struct page *)sp) && !sp->size;
74027 }
74028
74029 static inline void set_slob_page(struct slob_page *sp)
74030 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74031
74032 static inline struct slob_page *slob_page(const void *addr)
74033 {
74034 - return (struct slob_page *)virt_to_page(addr);
74035 + return (struct slob_page *)virt_to_head_page(addr);
74036 }
74037
74038 /*
74039 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74040 /*
74041 * Return the size of a slob block.
74042 */
74043 -static slobidx_t slob_units(slob_t *s)
74044 +static slobidx_t slob_units(const slob_t *s)
74045 {
74046 if (s->units > 0)
74047 return s->units;
74048 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74049 /*
74050 * Return the next free slob block pointer after this one.
74051 */
74052 -static slob_t *slob_next(slob_t *s)
74053 +static slob_t *slob_next(const slob_t *s)
74054 {
74055 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74056 slobidx_t next;
74057 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74058 /*
74059 * Returns true if s is the last free block in its page.
74060 */
74061 -static int slob_last(slob_t *s)
74062 +static int slob_last(const slob_t *s)
74063 {
74064 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74065 }
74066 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74067 if (!page)
74068 return NULL;
74069
74070 + set_slob_page(page);
74071 return page_address(page);
74072 }
74073
74074 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74075 if (!b)
74076 return NULL;
74077 sp = slob_page(b);
74078 - set_slob_page(sp);
74079
74080 spin_lock_irqsave(&slob_lock, flags);
74081 sp->units = SLOB_UNITS(PAGE_SIZE);
74082 sp->free = b;
74083 + sp->size = 0;
74084 INIT_LIST_HEAD(&sp->list);
74085 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74086 set_slob_page_free(sp, slob_list);
74087 @@ -476,10 +479,9 @@ out:
74088 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74089 */
74090
74091 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74092 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74093 {
74094 - unsigned int *m;
74095 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74096 + slob_t *m;
74097 void *ret;
74098
74099 gfp &= gfp_allowed_mask;
74100 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74101
74102 if (!m)
74103 return NULL;
74104 - *m = size;
74105 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74106 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74107 + m[0].units = size;
74108 + m[1].units = align;
74109 ret = (void *)m + align;
74110
74111 trace_kmalloc_node(_RET_IP_, ret,
74112 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74113 gfp |= __GFP_COMP;
74114 ret = slob_new_pages(gfp, order, node);
74115 if (ret) {
74116 - struct page *page;
74117 - page = virt_to_page(ret);
74118 - page->private = size;
74119 + struct slob_page *sp;
74120 + sp = slob_page(ret);
74121 + sp->size = size;
74122 }
74123
74124 trace_kmalloc_node(_RET_IP_, ret,
74125 size, PAGE_SIZE << order, gfp, node);
74126 }
74127
74128 - kmemleak_alloc(ret, size, 1, gfp);
74129 + return ret;
74130 +}
74131 +
74132 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74133 +{
74134 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74135 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74136 +
74137 + if (!ZERO_OR_NULL_PTR(ret))
74138 + kmemleak_alloc(ret, size, 1, gfp);
74139 return ret;
74140 }
74141 EXPORT_SYMBOL(__kmalloc_node);
74142 @@ -533,13 +547,83 @@ void kfree(const void *block)
74143 sp = slob_page(block);
74144 if (is_slob_page(sp)) {
74145 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74146 - unsigned int *m = (unsigned int *)(block - align);
74147 - slob_free(m, *m + align);
74148 - } else
74149 + slob_t *m = (slob_t *)(block - align);
74150 + slob_free(m, m[0].units + align);
74151 + } else {
74152 + clear_slob_page(sp);
74153 + free_slob_page(sp);
74154 + sp->size = 0;
74155 put_page(&sp->page);
74156 + }
74157 }
74158 EXPORT_SYMBOL(kfree);
74159
74160 +bool is_usercopy_object(const void *ptr)
74161 +{
74162 + return false;
74163 +}
74164 +
74165 +#ifdef CONFIG_PAX_USERCOPY
74166 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74167 +{
74168 + struct slob_page *sp;
74169 + const slob_t *free;
74170 + const void *base;
74171 + unsigned long flags;
74172 +
74173 + if (ZERO_OR_NULL_PTR(ptr))
74174 + return "<null>";
74175 +
74176 + if (!virt_addr_valid(ptr))
74177 + return NULL;
74178 +
74179 + sp = slob_page(ptr);
74180 + if (!PageSlab((struct page *)sp))
74181 + return NULL;
74182 +
74183 + if (sp->size) {
74184 + base = page_address(&sp->page);
74185 + if (base <= ptr && n <= sp->size - (ptr - base))
74186 + return NULL;
74187 + return "<slob>";
74188 + }
74189 +
74190 + /* some tricky double walking to find the chunk */
74191 + spin_lock_irqsave(&slob_lock, flags);
74192 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74193 + free = sp->free;
74194 +
74195 + while (!slob_last(free) && (void *)free <= ptr) {
74196 + base = free + slob_units(free);
74197 + free = slob_next(free);
74198 + }
74199 +
74200 + while (base < (void *)free) {
74201 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74202 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74203 + int offset;
74204 +
74205 + if (ptr < base + align)
74206 + break;
74207 +
74208 + offset = ptr - base - align;
74209 + if (offset >= m) {
74210 + base += size;
74211 + continue;
74212 + }
74213 +
74214 + if (n > m - offset)
74215 + break;
74216 +
74217 + spin_unlock_irqrestore(&slob_lock, flags);
74218 + return NULL;
74219 + }
74220 +
74221 + spin_unlock_irqrestore(&slob_lock, flags);
74222 + return "<slob>";
74223 +}
74224 +#endif
74225 +
74226 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74227 size_t ksize(const void *block)
74228 {
74229 @@ -552,10 +636,10 @@ size_t ksize(const void *block)
74230 sp = slob_page(block);
74231 if (is_slob_page(sp)) {
74232 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74233 - unsigned int *m = (unsigned int *)(block - align);
74234 - return SLOB_UNITS(*m) * SLOB_UNIT;
74235 + slob_t *m = (slob_t *)(block - align);
74236 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74237 } else
74238 - return sp->page.private;
74239 + return sp->size;
74240 }
74241 EXPORT_SYMBOL(ksize);
74242
74243 @@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74244 {
74245 struct kmem_cache *c;
74246
74247 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74248 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74249 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74250 +#else
74251 c = slob_alloc(sizeof(struct kmem_cache),
74252 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74253 +#endif
74254
74255 if (c) {
74256 c->name = name;
74257 @@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74258
74259 lockdep_trace_alloc(flags);
74260
74261 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74262 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74263 +#else
74264 if (c->size < PAGE_SIZE) {
74265 b = slob_alloc(c->size, flags, c->align, node);
74266 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74267 SLOB_UNITS(c->size) * SLOB_UNIT,
74268 flags, node);
74269 } else {
74270 + struct slob_page *sp;
74271 +
74272 b = slob_new_pages(flags, get_order(c->size), node);
74273 + sp = slob_page(b);
74274 + sp->size = c->size;
74275 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74276 PAGE_SIZE << get_order(c->size),
74277 flags, node);
74278 }
74279 +#endif
74280
74281 if (c->ctor)
74282 c->ctor(b);
74283 @@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74284
74285 static void __kmem_cache_free(void *b, int size)
74286 {
74287 - if (size < PAGE_SIZE)
74288 + struct slob_page *sp = slob_page(b);
74289 +
74290 + if (is_slob_page(sp))
74291 slob_free(b, size);
74292 - else
74293 + else {
74294 + clear_slob_page(sp);
74295 + free_slob_page(sp);
74296 + sp->size = 0;
74297 slob_free_pages(b, get_order(size));
74298 + }
74299 }
74300
74301 static void kmem_rcu_free(struct rcu_head *head)
74302 @@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74303
74304 void kmem_cache_free(struct kmem_cache *c, void *b)
74305 {
74306 + int size = c->size;
74307 +
74308 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74309 + if (size + c->align < PAGE_SIZE) {
74310 + size += c->align;
74311 + b -= c->align;
74312 + }
74313 +#endif
74314 +
74315 kmemleak_free_recursive(b, c->flags);
74316 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74317 struct slob_rcu *slob_rcu;
74318 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74319 - slob_rcu->size = c->size;
74320 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74321 + slob_rcu->size = size;
74322 call_rcu(&slob_rcu->head, kmem_rcu_free);
74323 } else {
74324 - __kmem_cache_free(b, c->size);
74325 + __kmem_cache_free(b, size);
74326 }
74327
74328 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74329 + trace_kfree(_RET_IP_, b);
74330 +#else
74331 trace_kmem_cache_free(_RET_IP_, b);
74332 +#endif
74333 +
74334 }
74335 EXPORT_SYMBOL(kmem_cache_free);
74336
74337 diff --git a/mm/slub.c b/mm/slub.c
74338 index 8c691fa..ff23a85 100644
74339 --- a/mm/slub.c
74340 +++ b/mm/slub.c
74341 @@ -209,7 +209,7 @@ struct track {
74342
74343 enum track_item { TRACK_ALLOC, TRACK_FREE };
74344
74345 -#ifdef CONFIG_SYSFS
74346 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74347 static int sysfs_slab_add(struct kmem_cache *);
74348 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74349 static void sysfs_slab_remove(struct kmem_cache *);
74350 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74351 if (!t->addr)
74352 return;
74353
74354 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74355 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74356 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74357 #ifdef CONFIG_STACKTRACE
74358 {
74359 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74360
74361 page = virt_to_head_page(x);
74362
74363 + BUG_ON(!PageSlab(page));
74364 +
74365 slab_free(s, page, x, _RET_IP_);
74366
74367 trace_kmem_cache_free(_RET_IP_, x);
74368 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
74369 * Merge control. If this is set then no merging of slab caches will occur.
74370 * (Could be removed. This was introduced to pacify the merge skeptics.)
74371 */
74372 -static int slub_nomerge;
74373 +static int slub_nomerge = 1;
74374
74375 /*
74376 * Calculate the order of allocation given an slab object size.
74377 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74378 else
74379 s->cpu_partial = 30;
74380
74381 - s->refcount = 1;
74382 + atomic_set(&s->refcount, 1);
74383 #ifdef CONFIG_NUMA
74384 s->remote_node_defrag_ratio = 1000;
74385 #endif
74386 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74387 void kmem_cache_destroy(struct kmem_cache *s)
74388 {
74389 down_write(&slub_lock);
74390 - s->refcount--;
74391 - if (!s->refcount) {
74392 + if (atomic_dec_and_test(&s->refcount)) {
74393 list_del(&s->list);
74394 up_write(&slub_lock);
74395 if (kmem_cache_close(s)) {
74396 @@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74397 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74398 #endif
74399
74400 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74401 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74402 +#endif
74403 +
74404 static int __init setup_slub_min_order(char *str)
74405 {
74406 get_option(&str, &slub_min_order);
74407 @@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74408 return kmalloc_dma_caches[index];
74409
74410 #endif
74411 +
74412 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74413 + if (flags & SLAB_USERCOPY)
74414 + return kmalloc_usercopy_caches[index];
74415 +
74416 +#endif
74417 +
74418 return kmalloc_caches[index];
74419 }
74420
74421 @@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74422 EXPORT_SYMBOL(__kmalloc_node);
74423 #endif
74424
74425 +bool is_usercopy_object(const void *ptr)
74426 +{
74427 + struct page *page;
74428 + struct kmem_cache *s;
74429 +
74430 + if (ZERO_OR_NULL_PTR(ptr))
74431 + return false;
74432 +
74433 + if (!virt_addr_valid(ptr))
74434 + return false;
74435 +
74436 + page = virt_to_head_page(ptr);
74437 +
74438 + if (!PageSlab(page))
74439 + return false;
74440 +
74441 + s = page->slab;
74442 + return s->flags & SLAB_USERCOPY;
74443 +}
74444 +
74445 +#ifdef CONFIG_PAX_USERCOPY
74446 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74447 +{
74448 + struct page *page;
74449 + struct kmem_cache *s;
74450 + unsigned long offset;
74451 +
74452 + if (ZERO_OR_NULL_PTR(ptr))
74453 + return "<null>";
74454 +
74455 + if (!virt_addr_valid(ptr))
74456 + return NULL;
74457 +
74458 + page = virt_to_head_page(ptr);
74459 +
74460 + if (!PageSlab(page))
74461 + return NULL;
74462 +
74463 + s = page->slab;
74464 + if (!(s->flags & SLAB_USERCOPY))
74465 + return s->name;
74466 +
74467 + offset = (ptr - page_address(page)) % s->size;
74468 + if (offset <= s->objsize && n <= s->objsize - offset)
74469 + return NULL;
74470 +
74471 + return s->name;
74472 +}
74473 +#endif
74474 +
74475 size_t ksize(const void *object)
74476 {
74477 struct page *page;
74478 @@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74479 int node;
74480
74481 list_add(&s->list, &slab_caches);
74482 - s->refcount = -1;
74483 + atomic_set(&s->refcount, -1);
74484
74485 for_each_node_state(node, N_NORMAL_MEMORY) {
74486 struct kmem_cache_node *n = get_node(s, node);
74487 @@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74488
74489 /* Caches that are not of the two-to-the-power-of size */
74490 if (KMALLOC_MIN_SIZE <= 32) {
74491 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74492 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74493 caches++;
74494 }
74495
74496 if (KMALLOC_MIN_SIZE <= 64) {
74497 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74498 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74499 caches++;
74500 }
74501
74502 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74503 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74504 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74505 caches++;
74506 }
74507
74508 @@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74509 }
74510 }
74511 #endif
74512 +
74513 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74514 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74515 + struct kmem_cache *s = kmalloc_caches[i];
74516 +
74517 + if (s && s->size) {
74518 + char *name = kasprintf(GFP_NOWAIT,
74519 + "usercopy-kmalloc-%d", s->objsize);
74520 +
74521 + BUG_ON(!name);
74522 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74523 + s->objsize, SLAB_USERCOPY);
74524 + }
74525 + }
74526 +#endif
74527 +
74528 printk(KERN_INFO
74529 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74530 " CPUs=%d, Nodes=%d\n",
74531 @@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74532 /*
74533 * We may have set a slab to be unmergeable during bootstrap.
74534 */
74535 - if (s->refcount < 0)
74536 + if (atomic_read(&s->refcount) < 0)
74537 return 1;
74538
74539 return 0;
74540 @@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74541 down_write(&slub_lock);
74542 s = find_mergeable(size, align, flags, name, ctor);
74543 if (s) {
74544 - s->refcount++;
74545 + atomic_inc(&s->refcount);
74546 /*
74547 * Adjust the object sizes so that we clear
74548 * the complete object on kzalloc.
74549 @@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74550 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74551
74552 if (sysfs_slab_alias(s, name)) {
74553 - s->refcount--;
74554 + atomic_dec(&s->refcount);
74555 goto err;
74556 }
74557 up_write(&slub_lock);
74558 @@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74559 }
74560 #endif
74561
74562 -#ifdef CONFIG_SYSFS
74563 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74564 static int count_inuse(struct page *page)
74565 {
74566 return page->inuse;
74567 @@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74568 validate_slab_cache(kmalloc_caches[9]);
74569 }
74570 #else
74571 -#ifdef CONFIG_SYSFS
74572 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74573 static void resiliency_test(void) {};
74574 #endif
74575 #endif
74576
74577 -#ifdef CONFIG_SYSFS
74578 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74579 enum slab_stat_type {
74580 SL_ALL, /* All slabs */
74581 SL_PARTIAL, /* Only partially allocated slabs */
74582 @@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74583
74584 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74585 {
74586 - return sprintf(buf, "%d\n", s->refcount - 1);
74587 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74588 }
74589 SLAB_ATTR_RO(aliases);
74590
74591 @@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74592 return name;
74593 }
74594
74595 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74596 static int sysfs_slab_add(struct kmem_cache *s)
74597 {
74598 int err;
74599 @@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74600 kobject_del(&s->kobj);
74601 kobject_put(&s->kobj);
74602 }
74603 +#endif
74604
74605 /*
74606 * Need to buffer aliases during bootup until sysfs becomes
74607 @@ -5355,6 +5435,7 @@ struct saved_alias {
74608
74609 static struct saved_alias *alias_list;
74610
74611 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74612 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74613 {
74614 struct saved_alias *al;
74615 @@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74616 alias_list = al;
74617 return 0;
74618 }
74619 +#endif
74620
74621 static int __init slab_sysfs_init(void)
74622 {
74623 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74624 index 1b7e22a..3fcd4f3 100644
74625 --- a/mm/sparse-vmemmap.c
74626 +++ b/mm/sparse-vmemmap.c
74627 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74628 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74629 if (!p)
74630 return NULL;
74631 - pud_populate(&init_mm, pud, p);
74632 + pud_populate_kernel(&init_mm, pud, p);
74633 }
74634 return pud;
74635 }
74636 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74637 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74638 if (!p)
74639 return NULL;
74640 - pgd_populate(&init_mm, pgd, p);
74641 + pgd_populate_kernel(&init_mm, pgd, p);
74642 }
74643 return pgd;
74644 }
74645 diff --git a/mm/swap.c b/mm/swap.c
74646 index 4e7e2ec..0c57830 100644
74647 --- a/mm/swap.c
74648 +++ b/mm/swap.c
74649 @@ -30,6 +30,7 @@
74650 #include <linux/backing-dev.h>
74651 #include <linux/memcontrol.h>
74652 #include <linux/gfp.h>
74653 +#include <linux/hugetlb.h>
74654
74655 #include "internal.h"
74656
74657 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74658
74659 __page_cache_release(page);
74660 dtor = get_compound_page_dtor(page);
74661 + if (!PageHuge(page))
74662 + BUG_ON(dtor != free_compound_page);
74663 (*dtor)(page);
74664 }
74665
74666 diff --git a/mm/swapfile.c b/mm/swapfile.c
74667 index 71373d0..11fa7d9 100644
74668 --- a/mm/swapfile.c
74669 +++ b/mm/swapfile.c
74670 @@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74671
74672 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74673 /* Activity counter to indicate that a swapon or swapoff has occurred */
74674 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74675 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74676
74677 static inline unsigned char swap_count(unsigned char ent)
74678 {
74679 @@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74680 }
74681 filp_close(swap_file, NULL);
74682 err = 0;
74683 - atomic_inc(&proc_poll_event);
74684 + atomic_inc_unchecked(&proc_poll_event);
74685 wake_up_interruptible(&proc_poll_wait);
74686
74687 out_dput:
74688 @@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74689
74690 poll_wait(file, &proc_poll_wait, wait);
74691
74692 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74693 - seq->poll_event = atomic_read(&proc_poll_event);
74694 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74695 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74696 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74697 }
74698
74699 @@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74700 return ret;
74701
74702 seq = file->private_data;
74703 - seq->poll_event = atomic_read(&proc_poll_event);
74704 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74705 return 0;
74706 }
74707
74708 @@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74709 (frontswap_map) ? "FS" : "");
74710
74711 mutex_unlock(&swapon_mutex);
74712 - atomic_inc(&proc_poll_event);
74713 + atomic_inc_unchecked(&proc_poll_event);
74714 wake_up_interruptible(&proc_poll_wait);
74715
74716 if (S_ISREG(inode->i_mode))
74717 diff --git a/mm/util.c b/mm/util.c
74718 index 8c7265a..c96d884 100644
74719 --- a/mm/util.c
74720 +++ b/mm/util.c
74721 @@ -285,6 +285,12 @@ done:
74722 void arch_pick_mmap_layout(struct mm_struct *mm)
74723 {
74724 mm->mmap_base = TASK_UNMAPPED_BASE;
74725 +
74726 +#ifdef CONFIG_PAX_RANDMMAP
74727 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74728 + mm->mmap_base += mm->delta_mmap;
74729 +#endif
74730 +
74731 mm->get_unmapped_area = arch_get_unmapped_area;
74732 mm->unmap_area = arch_unmap_area;
74733 }
74734 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74735 index 2aad499..2e608e8 100644
74736 --- a/mm/vmalloc.c
74737 +++ b/mm/vmalloc.c
74738 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74739
74740 pte = pte_offset_kernel(pmd, addr);
74741 do {
74742 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74743 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74744 +
74745 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74746 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74747 + BUG_ON(!pte_exec(*pte));
74748 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74749 + continue;
74750 + }
74751 +#endif
74752 +
74753 + {
74754 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74755 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74756 + }
74757 } while (pte++, addr += PAGE_SIZE, addr != end);
74758 }
74759
74760 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74761 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74762 {
74763 pte_t *pte;
74764 + int ret = -ENOMEM;
74765
74766 /*
74767 * nr is a running index into the array which helps higher level
74768 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74769 pte = pte_alloc_kernel(pmd, addr);
74770 if (!pte)
74771 return -ENOMEM;
74772 +
74773 + pax_open_kernel();
74774 do {
74775 struct page *page = pages[*nr];
74776
74777 - if (WARN_ON(!pte_none(*pte)))
74778 - return -EBUSY;
74779 - if (WARN_ON(!page))
74780 - return -ENOMEM;
74781 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74782 + if (pgprot_val(prot) & _PAGE_NX)
74783 +#endif
74784 +
74785 + if (WARN_ON(!pte_none(*pte))) {
74786 + ret = -EBUSY;
74787 + goto out;
74788 + }
74789 + if (WARN_ON(!page)) {
74790 + ret = -ENOMEM;
74791 + goto out;
74792 + }
74793 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74794 (*nr)++;
74795 } while (pte++, addr += PAGE_SIZE, addr != end);
74796 - return 0;
74797 + ret = 0;
74798 +out:
74799 + pax_close_kernel();
74800 + return ret;
74801 }
74802
74803 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74804 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74805 pmd_t *pmd;
74806 unsigned long next;
74807
74808 - pmd = pmd_alloc(&init_mm, pud, addr);
74809 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74810 if (!pmd)
74811 return -ENOMEM;
74812 do {
74813 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74814 pud_t *pud;
74815 unsigned long next;
74816
74817 - pud = pud_alloc(&init_mm, pgd, addr);
74818 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74819 if (!pud)
74820 return -ENOMEM;
74821 do {
74822 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74823 * and fall back on vmalloc() if that fails. Others
74824 * just put it in the vmalloc space.
74825 */
74826 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74827 +#ifdef CONFIG_MODULES
74828 +#ifdef MODULES_VADDR
74829 unsigned long addr = (unsigned long)x;
74830 if (addr >= MODULES_VADDR && addr < MODULES_END)
74831 return 1;
74832 #endif
74833 +
74834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74835 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74836 + return 1;
74837 +#endif
74838 +
74839 +#endif
74840 +
74841 return is_vmalloc_addr(x);
74842 }
74843
74844 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74845
74846 if (!pgd_none(*pgd)) {
74847 pud_t *pud = pud_offset(pgd, addr);
74848 +#ifdef CONFIG_X86
74849 + if (!pud_large(*pud))
74850 +#endif
74851 if (!pud_none(*pud)) {
74852 pmd_t *pmd = pmd_offset(pud, addr);
74853 +#ifdef CONFIG_X86
74854 + if (!pmd_large(*pmd))
74855 +#endif
74856 if (!pmd_none(*pmd)) {
74857 pte_t *ptep, pte;
74858
74859 @@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74860 static struct vmap_area *alloc_vmap_area(unsigned long size,
74861 unsigned long align,
74862 unsigned long vstart, unsigned long vend,
74863 + int node, gfp_t gfp_mask) __size_overflow(1);
74864 +static struct vmap_area *alloc_vmap_area(unsigned long size,
74865 + unsigned long align,
74866 + unsigned long vstart, unsigned long vend,
74867 int node, gfp_t gfp_mask)
74868 {
74869 struct vmap_area *va;
74870 @@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74871 struct vm_struct *area;
74872
74873 BUG_ON(in_interrupt());
74874 +
74875 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74876 + if (flags & VM_KERNEXEC) {
74877 + if (start != VMALLOC_START || end != VMALLOC_END)
74878 + return NULL;
74879 + start = (unsigned long)MODULES_EXEC_VADDR;
74880 + end = (unsigned long)MODULES_EXEC_END;
74881 + }
74882 +#endif
74883 +
74884 if (flags & VM_IOREMAP) {
74885 int bit = fls(size);
74886
74887 @@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
74888 if (count > totalram_pages)
74889 return NULL;
74890
74891 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74892 + if (!(pgprot_val(prot) & _PAGE_NX))
74893 + flags |= VM_KERNEXEC;
74894 +#endif
74895 +
74896 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74897 __builtin_return_address(0));
74898 if (!area)
74899 @@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74900 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74901 goto fail;
74902
74903 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74904 + if (!(pgprot_val(prot) & _PAGE_NX))
74905 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74906 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74907 + else
74908 +#endif
74909 +
74910 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74911 start, end, node, gfp_mask, caller);
74912 if (!area)
74913 @@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
74914 * For tight control over page level allocator and protection flags
74915 * use __vmalloc() instead.
74916 */
74917 -
74918 void *vmalloc_exec(unsigned long size)
74919 {
74920 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74921 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74922 -1, __builtin_return_address(0));
74923 }
74924
74925 @@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74926 unsigned long uaddr = vma->vm_start;
74927 unsigned long usize = vma->vm_end - vma->vm_start;
74928
74929 + BUG_ON(vma->vm_mirror);
74930 +
74931 if ((PAGE_SIZE-1) & (unsigned long)addr)
74932 return -EINVAL;
74933
74934 diff --git a/mm/vmstat.c b/mm/vmstat.c
74935 index 1bbbbd9..ff35669 100644
74936 --- a/mm/vmstat.c
74937 +++ b/mm/vmstat.c
74938 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74939 *
74940 * vm_stat contains the global counters
74941 */
74942 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74943 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74944 EXPORT_SYMBOL(vm_stat);
74945
74946 #ifdef CONFIG_SMP
74947 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74948 v = p->vm_stat_diff[i];
74949 p->vm_stat_diff[i] = 0;
74950 local_irq_restore(flags);
74951 - atomic_long_add(v, &zone->vm_stat[i]);
74952 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74953 global_diff[i] += v;
74954 #ifdef CONFIG_NUMA
74955 /* 3 seconds idle till flush */
74956 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74957
74958 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74959 if (global_diff[i])
74960 - atomic_long_add(global_diff[i], &vm_stat[i]);
74961 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74962 }
74963
74964 #endif
74965 @@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
74966 start_cpu_timer(cpu);
74967 #endif
74968 #ifdef CONFIG_PROC_FS
74969 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74970 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74971 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74972 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74973 + {
74974 + mode_t gr_mode = S_IRUGO;
74975 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74976 + gr_mode = S_IRUSR;
74977 +#endif
74978 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74979 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74980 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74981 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74982 +#else
74983 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74984 +#endif
74985 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74986 + }
74987 #endif
74988 return 0;
74989 }
74990 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74991 index 9096bcb..43ed7bb 100644
74992 --- a/net/8021q/vlan.c
74993 +++ b/net/8021q/vlan.c
74994 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74995 err = -EPERM;
74996 if (!capable(CAP_NET_ADMIN))
74997 break;
74998 - if ((args.u.name_type >= 0) &&
74999 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75000 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75001 struct vlan_net *vn;
75002
75003 vn = net_generic(net, vlan_net_id);
75004 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75005 index 6449bae..8c1f454 100644
75006 --- a/net/9p/trans_fd.c
75007 +++ b/net/9p/trans_fd.c
75008 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75009 oldfs = get_fs();
75010 set_fs(get_ds());
75011 /* The cast to a user pointer is valid due to the set_fs() */
75012 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75013 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75014 set_fs(oldfs);
75015
75016 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75017 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75018 index 876fbe8..8bbea9f 100644
75019 --- a/net/atm/atm_misc.c
75020 +++ b/net/atm/atm_misc.c
75021 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75022 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75023 return 1;
75024 atm_return(vcc, truesize);
75025 - atomic_inc(&vcc->stats->rx_drop);
75026 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75027 return 0;
75028 }
75029 EXPORT_SYMBOL(atm_charge);
75030 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75031 }
75032 }
75033 atm_return(vcc, guess);
75034 - atomic_inc(&vcc->stats->rx_drop);
75035 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75036 return NULL;
75037 }
75038 EXPORT_SYMBOL(atm_alloc_charge);
75039 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75040
75041 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75042 {
75043 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75044 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75045 __SONET_ITEMS
75046 #undef __HANDLE_ITEM
75047 }
75048 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75049
75050 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75051 {
75052 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75053 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75054 __SONET_ITEMS
75055 #undef __HANDLE_ITEM
75056 }
75057 diff --git a/net/atm/lec.h b/net/atm/lec.h
75058 index a86aff9..3a0d6f6 100644
75059 --- a/net/atm/lec.h
75060 +++ b/net/atm/lec.h
75061 @@ -48,7 +48,7 @@ struct lane2_ops {
75062 const u8 *tlvs, u32 sizeoftlvs);
75063 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75064 const u8 *tlvs, u32 sizeoftlvs);
75065 -};
75066 +} __no_const;
75067
75068 /*
75069 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75070 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75071 index 0919a88..a23d54e 100644
75072 --- a/net/atm/mpc.h
75073 +++ b/net/atm/mpc.h
75074 @@ -33,7 +33,7 @@ struct mpoa_client {
75075 struct mpc_parameters parameters; /* parameters for this client */
75076
75077 const struct net_device_ops *old_ops;
75078 - struct net_device_ops new_ops;
75079 + net_device_ops_no_const new_ops;
75080 };
75081
75082
75083 diff --git a/net/atm/proc.c b/net/atm/proc.c
75084 index 0d020de..011c7bb 100644
75085 --- a/net/atm/proc.c
75086 +++ b/net/atm/proc.c
75087 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75088 const struct k_atm_aal_stats *stats)
75089 {
75090 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75091 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75092 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75093 - atomic_read(&stats->rx_drop));
75094 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75095 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75096 + atomic_read_unchecked(&stats->rx_drop));
75097 }
75098
75099 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75100 diff --git a/net/atm/resources.c b/net/atm/resources.c
75101 index 23f45ce..c748f1a 100644
75102 --- a/net/atm/resources.c
75103 +++ b/net/atm/resources.c
75104 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75105 static void copy_aal_stats(struct k_atm_aal_stats *from,
75106 struct atm_aal_stats *to)
75107 {
75108 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75109 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75110 __AAL_STAT_ITEMS
75111 #undef __HANDLE_ITEM
75112 }
75113 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75114 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75115 struct atm_aal_stats *to)
75116 {
75117 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75118 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75119 __AAL_STAT_ITEMS
75120 #undef __HANDLE_ITEM
75121 }
75122 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75123 index dc53798..dc66333 100644
75124 --- a/net/batman-adv/bat_iv_ogm.c
75125 +++ b/net/batman-adv/bat_iv_ogm.c
75126 @@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75127
75128 /* randomize initial seqno to avoid collision */
75129 get_random_bytes(&random_seqno, sizeof(random_seqno));
75130 - atomic_set(&hard_iface->seqno, random_seqno);
75131 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75132
75133 hard_iface->packet_len = BATMAN_OGM_HLEN;
75134 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75135 @@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75136
75137 /* change sequence number to network order */
75138 batman_ogm_packet->seqno =
75139 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75140 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75141
75142 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75143 batman_ogm_packet->tt_crc = htons((uint16_t)
75144 @@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75145 else
75146 batman_ogm_packet->gw_flags = NO_FLAGS;
75147
75148 - atomic_inc(&hard_iface->seqno);
75149 + atomic_inc_unchecked(&hard_iface->seqno);
75150
75151 slide_own_bcast_window(hard_iface);
75152 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75153 @@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75154 return;
75155
75156 /* could be changed by schedule_own_packet() */
75157 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75158 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75159
75160 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75161
75162 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75163 index dc334fa..766a01a 100644
75164 --- a/net/batman-adv/hard-interface.c
75165 +++ b/net/batman-adv/hard-interface.c
75166 @@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75167 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75168 dev_add_pack(&hard_iface->batman_adv_ptype);
75169
75170 - atomic_set(&hard_iface->frag_seqno, 1);
75171 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75172 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75173 hard_iface->net_dev->name);
75174
75175 @@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75176 * This can't be called via a bat_priv callback because
75177 * we have no bat_priv yet.
75178 */
75179 - atomic_set(&hard_iface->seqno, 1);
75180 + atomic_set_unchecked(&hard_iface->seqno, 1);
75181 hard_iface->packet_buff = NULL;
75182
75183 return hard_iface;
75184 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75185 index a0ec0e4..7beb587 100644
75186 --- a/net/batman-adv/soft-interface.c
75187 +++ b/net/batman-adv/soft-interface.c
75188 @@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75189
75190 /* set broadcast sequence number */
75191 bcast_packet->seqno =
75192 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75193 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75194
75195 add_bcast_packet_to_list(bat_priv, skb, 1);
75196
75197 @@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75198 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75199
75200 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75201 - atomic_set(&bat_priv->bcast_seqno, 1);
75202 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75203 atomic_set(&bat_priv->ttvn, 0);
75204 atomic_set(&bat_priv->tt_local_changes, 0);
75205 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75206 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75207 index 61308e8..2e142b2 100644
75208 --- a/net/batman-adv/types.h
75209 +++ b/net/batman-adv/types.h
75210 @@ -38,8 +38,8 @@ struct hard_iface {
75211 int16_t if_num;
75212 char if_status;
75213 struct net_device *net_dev;
75214 - atomic_t seqno;
75215 - atomic_t frag_seqno;
75216 + atomic_unchecked_t seqno;
75217 + atomic_unchecked_t frag_seqno;
75218 unsigned char *packet_buff;
75219 int packet_len;
75220 struct kobject *hardif_obj;
75221 @@ -163,7 +163,7 @@ struct bat_priv {
75222 atomic_t orig_interval; /* uint */
75223 atomic_t hop_penalty; /* uint */
75224 atomic_t log_level; /* uint */
75225 - atomic_t bcast_seqno;
75226 + atomic_unchecked_t bcast_seqno;
75227 atomic_t bcast_queue_left;
75228 atomic_t batman_queue_left;
75229 atomic_t ttvn; /* translation table version number */
75230 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75231 index 74175c2..32f8901 100644
75232 --- a/net/batman-adv/unicast.c
75233 +++ b/net/batman-adv/unicast.c
75234 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75235 frag1->flags = UNI_FRAG_HEAD | large_tail;
75236 frag2->flags = large_tail;
75237
75238 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75239 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75240 frag1->seqno = htons(seqno - 1);
75241 frag2->seqno = htons(seqno);
75242
75243 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75244 index 4554e80..b778671 100644
75245 --- a/net/bluetooth/l2cap_core.c
75246 +++ b/net/bluetooth/l2cap_core.c
75247 @@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75248 break;
75249
75250 case L2CAP_CONF_RFC:
75251 - if (olen == sizeof(rfc))
75252 - memcpy(&rfc, (void *)val, olen);
75253 + if (olen != sizeof(rfc))
75254 + break;
75255 +
75256 + memcpy(&rfc, (void *)val, olen);
75257
75258 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75259 rfc.mode != chan->mode)
75260 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75261 index d1820ff..d414b0e 100644
75262 --- a/net/bluetooth/rfcomm/tty.c
75263 +++ b/net/bluetooth/rfcomm/tty.c
75264 @@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75265 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75266
75267 spin_lock_irqsave(&dev->port.lock, flags);
75268 - if (dev->port.count > 0) {
75269 + if (atomic_read(&dev->port.count) > 0) {
75270 spin_unlock_irqrestore(&dev->port.lock, flags);
75271 return;
75272 }
75273 @@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75274 return -ENODEV;
75275
75276 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75277 - dev->channel, dev->port.count);
75278 + dev->channel, atomic_read(&dev->port.count));
75279
75280 spin_lock_irqsave(&dev->port.lock, flags);
75281 - if (++dev->port.count > 1) {
75282 + if (atomic_inc_return(&dev->port.count) > 1) {
75283 spin_unlock_irqrestore(&dev->port.lock, flags);
75284 return 0;
75285 }
75286 @@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75287 return;
75288
75289 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75290 - dev->port.count);
75291 + atomic_read(&dev->port.count));
75292
75293 spin_lock_irqsave(&dev->port.lock, flags);
75294 - if (!--dev->port.count) {
75295 + if (!atomic_dec_return(&dev->port.count)) {
75296 spin_unlock_irqrestore(&dev->port.lock, flags);
75297 if (dev->tty_dev->parent)
75298 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75299 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75300 index 5fe2ff3..10968b5 100644
75301 --- a/net/bridge/netfilter/ebtables.c
75302 +++ b/net/bridge/netfilter/ebtables.c
75303 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75304 tmp.valid_hooks = t->table->valid_hooks;
75305 }
75306 mutex_unlock(&ebt_mutex);
75307 - if (copy_to_user(user, &tmp, *len) != 0){
75308 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75309 BUGPRINT("c2u Didn't work\n");
75310 ret = -EFAULT;
75311 break;
75312 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75313 index 047cd0e..461fd28 100644
75314 --- a/net/caif/cfctrl.c
75315 +++ b/net/caif/cfctrl.c
75316 @@ -10,6 +10,7 @@
75317 #include <linux/spinlock.h>
75318 #include <linux/slab.h>
75319 #include <linux/pkt_sched.h>
75320 +#include <linux/sched.h>
75321 #include <net/caif/caif_layer.h>
75322 #include <net/caif/cfpkt.h>
75323 #include <net/caif/cfctrl.h>
75324 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75325 memset(&dev_info, 0, sizeof(dev_info));
75326 dev_info.id = 0xff;
75327 cfsrvl_init(&this->serv, 0, &dev_info, false);
75328 - atomic_set(&this->req_seq_no, 1);
75329 - atomic_set(&this->rsp_seq_no, 1);
75330 + atomic_set_unchecked(&this->req_seq_no, 1);
75331 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75332 this->serv.layer.receive = cfctrl_recv;
75333 sprintf(this->serv.layer.name, "ctrl");
75334 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75335 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75336 struct cfctrl_request_info *req)
75337 {
75338 spin_lock_bh(&ctrl->info_list_lock);
75339 - atomic_inc(&ctrl->req_seq_no);
75340 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75341 + atomic_inc_unchecked(&ctrl->req_seq_no);
75342 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75343 list_add_tail(&req->list, &ctrl->list);
75344 spin_unlock_bh(&ctrl->info_list_lock);
75345 }
75346 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75347 if (p != first)
75348 pr_warn("Requests are not received in order\n");
75349
75350 - atomic_set(&ctrl->rsp_seq_no,
75351 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75352 p->sequence_no);
75353 list_del(&p->list);
75354 goto out;
75355 diff --git a/net/can/gw.c b/net/can/gw.c
75356 index b41acf2..3affb3a 100644
75357 --- a/net/can/gw.c
75358 +++ b/net/can/gw.c
75359 @@ -96,7 +96,7 @@ struct cf_mod {
75360 struct {
75361 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75362 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75363 - } csumfunc;
75364 + } __no_const csumfunc;
75365 };
75366
75367
75368 diff --git a/net/compat.c b/net/compat.c
75369 index 1b96281..a7e6c91 100644
75370 --- a/net/compat.c
75371 +++ b/net/compat.c
75372 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75373 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75374 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75375 return -EFAULT;
75376 - kmsg->msg_name = compat_ptr(tmp1);
75377 - kmsg->msg_iov = compat_ptr(tmp2);
75378 - kmsg->msg_control = compat_ptr(tmp3);
75379 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75380 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75381 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75382 return 0;
75383 }
75384
75385 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75386
75387 if (kern_msg->msg_namelen) {
75388 if (mode == VERIFY_READ) {
75389 - int err = move_addr_to_kernel(kern_msg->msg_name,
75390 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75391 kern_msg->msg_namelen,
75392 kern_address);
75393 if (err < 0)
75394 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75395 kern_msg->msg_name = NULL;
75396
75397 tot_len = iov_from_user_compat_to_kern(kern_iov,
75398 - (struct compat_iovec __user *)kern_msg->msg_iov,
75399 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
75400 kern_msg->msg_iovlen);
75401 if (tot_len >= 0)
75402 kern_msg->msg_iov = kern_iov;
75403 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75404
75405 #define CMSG_COMPAT_FIRSTHDR(msg) \
75406 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75407 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75408 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75409 (struct compat_cmsghdr __user *)NULL)
75410
75411 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75412 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75413 (ucmlen) <= (unsigned long) \
75414 ((mhdr)->msg_controllen - \
75415 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75416 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75417
75418 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75419 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75420 {
75421 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75422 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75423 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75424 msg->msg_controllen)
75425 return NULL;
75426 return (struct compat_cmsghdr __user *)ptr;
75427 @@ -219,7 +219,7 @@ Efault:
75428
75429 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75430 {
75431 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75432 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75433 struct compat_cmsghdr cmhdr;
75434 int cmlen;
75435
75436 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75437
75438 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75439 {
75440 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75441 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75442 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75443 int fdnum = scm->fp->count;
75444 struct file **fp = scm->fp->fp;
75445 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75446 return -EFAULT;
75447 old_fs = get_fs();
75448 set_fs(KERNEL_DS);
75449 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75450 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75451 set_fs(old_fs);
75452
75453 return err;
75454 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75455 len = sizeof(ktime);
75456 old_fs = get_fs();
75457 set_fs(KERNEL_DS);
75458 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75459 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75460 set_fs(old_fs);
75461
75462 if (!err) {
75463 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75464 case MCAST_JOIN_GROUP:
75465 case MCAST_LEAVE_GROUP:
75466 {
75467 - struct compat_group_req __user *gr32 = (void *)optval;
75468 + struct compat_group_req __user *gr32 = (void __user *)optval;
75469 struct group_req __user *kgr =
75470 compat_alloc_user_space(sizeof(struct group_req));
75471 u32 interface;
75472 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75473 case MCAST_BLOCK_SOURCE:
75474 case MCAST_UNBLOCK_SOURCE:
75475 {
75476 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75477 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75478 struct group_source_req __user *kgsr = compat_alloc_user_space(
75479 sizeof(struct group_source_req));
75480 u32 interface;
75481 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75482 }
75483 case MCAST_MSFILTER:
75484 {
75485 - struct compat_group_filter __user *gf32 = (void *)optval;
75486 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75487 struct group_filter __user *kgf;
75488 u32 interface, fmode, numsrc;
75489
75490 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75491 char __user *optval, int __user *optlen,
75492 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75493 {
75494 - struct compat_group_filter __user *gf32 = (void *)optval;
75495 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75496 struct group_filter __user *kgf;
75497 int __user *koptlen;
75498 u32 interface, fmode, numsrc;
75499 diff --git a/net/core/datagram.c b/net/core/datagram.c
75500 index ae6acf6..d5c8f66 100644
75501 --- a/net/core/datagram.c
75502 +++ b/net/core/datagram.c
75503 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75504 }
75505
75506 kfree_skb(skb);
75507 - atomic_inc(&sk->sk_drops);
75508 + atomic_inc_unchecked(&sk->sk_drops);
75509 sk_mem_reclaim_partial(sk);
75510
75511 return err;
75512 diff --git a/net/core/dev.c b/net/core/dev.c
75513 index 1cb0d8a..0427dd9 100644
75514 --- a/net/core/dev.c
75515 +++ b/net/core/dev.c
75516 @@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75517 if (no_module && capable(CAP_NET_ADMIN))
75518 no_module = request_module("netdev-%s", name);
75519 if (no_module && capable(CAP_SYS_MODULE)) {
75520 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75521 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75522 +#else
75523 if (!request_module("%s", name))
75524 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75525 name);
75526 +#endif
75527 }
75528 }
75529 EXPORT_SYMBOL(dev_load);
75530 @@ -1601,7 +1605,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75531 {
75532 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75533 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75534 - atomic_long_inc(&dev->rx_dropped);
75535 + atomic_long_inc_unchecked(&dev->rx_dropped);
75536 kfree_skb(skb);
75537 return NET_RX_DROP;
75538 }
75539 @@ -1611,7 +1615,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75540 nf_reset(skb);
75541
75542 if (unlikely(!is_skb_forwardable(dev, skb))) {
75543 - atomic_long_inc(&dev->rx_dropped);
75544 + atomic_long_inc_unchecked(&dev->rx_dropped);
75545 kfree_skb(skb);
75546 return NET_RX_DROP;
75547 }
75548 @@ -2040,7 +2044,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75549
75550 struct dev_gso_cb {
75551 void (*destructor)(struct sk_buff *skb);
75552 -};
75553 +} __no_const;
75554
75555 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75556
75557 @@ -2875,7 +2879,7 @@ enqueue:
75558
75559 local_irq_restore(flags);
75560
75561 - atomic_long_inc(&skb->dev->rx_dropped);
75562 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75563 kfree_skb(skb);
75564 return NET_RX_DROP;
75565 }
75566 @@ -2947,7 +2951,7 @@ int netif_rx_ni(struct sk_buff *skb)
75567 }
75568 EXPORT_SYMBOL(netif_rx_ni);
75569
75570 -static void net_tx_action(struct softirq_action *h)
75571 +static void net_tx_action(void)
75572 {
75573 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75574
75575 @@ -3234,7 +3238,7 @@ ncls:
75576 if (pt_prev) {
75577 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75578 } else {
75579 - atomic_long_inc(&skb->dev->rx_dropped);
75580 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75581 kfree_skb(skb);
75582 /* Jamal, now you will not able to escape explaining
75583 * me how you were going to use this. :-)
75584 @@ -3799,7 +3803,7 @@ void netif_napi_del(struct napi_struct *napi)
75585 }
75586 EXPORT_SYMBOL(netif_napi_del);
75587
75588 -static void net_rx_action(struct softirq_action *h)
75589 +static void net_rx_action(void)
75590 {
75591 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75592 unsigned long time_limit = jiffies + 2;
75593 @@ -4269,8 +4273,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75594 else
75595 seq_printf(seq, "%04x", ntohs(pt->type));
75596
75597 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75598 + seq_printf(seq, " %-8s %p\n",
75599 + pt->dev ? pt->dev->name : "", NULL);
75600 +#else
75601 seq_printf(seq, " %-8s %pF\n",
75602 pt->dev ? pt->dev->name : "", pt->func);
75603 +#endif
75604 }
75605
75606 return 0;
75607 @@ -5820,7 +5829,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75608 } else {
75609 netdev_stats_to_stats64(storage, &dev->stats);
75610 }
75611 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75612 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75613 return storage;
75614 }
75615 EXPORT_SYMBOL(dev_get_stats);
75616 diff --git a/net/core/flow.c b/net/core/flow.c
75617 index e318c7e..168b1d0 100644
75618 --- a/net/core/flow.c
75619 +++ b/net/core/flow.c
75620 @@ -61,7 +61,7 @@ struct flow_cache {
75621 struct timer_list rnd_timer;
75622 };
75623
75624 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75625 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75626 EXPORT_SYMBOL(flow_cache_genid);
75627 static struct flow_cache flow_cache_global;
75628 static struct kmem_cache *flow_cachep __read_mostly;
75629 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75630
75631 static int flow_entry_valid(struct flow_cache_entry *fle)
75632 {
75633 - if (atomic_read(&flow_cache_genid) != fle->genid)
75634 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75635 return 0;
75636 if (fle->object && !fle->object->ops->check(fle->object))
75637 return 0;
75638 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75639 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75640 fcp->hash_count++;
75641 }
75642 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75643 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75644 flo = fle->object;
75645 if (!flo)
75646 goto ret_object;
75647 @@ -280,7 +280,7 @@ nocache:
75648 }
75649 flo = resolver(net, key, family, dir, flo, ctx);
75650 if (fle) {
75651 - fle->genid = atomic_read(&flow_cache_genid);
75652 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75653 if (!IS_ERR(flo))
75654 fle->object = flo;
75655 else
75656 diff --git a/net/core/iovec.c b/net/core/iovec.c
75657 index 7e7aeb0..2a998cb 100644
75658 --- a/net/core/iovec.c
75659 +++ b/net/core/iovec.c
75660 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75661 if (m->msg_namelen) {
75662 if (mode == VERIFY_READ) {
75663 void __user *namep;
75664 - namep = (void __user __force *) m->msg_name;
75665 + namep = (void __force_user *) m->msg_name;
75666 err = move_addr_to_kernel(namep, m->msg_namelen,
75667 address);
75668 if (err < 0)
75669 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75670 }
75671
75672 size = m->msg_iovlen * sizeof(struct iovec);
75673 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75674 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75675 return -EFAULT;
75676
75677 m->msg_iov = iov;
75678 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75679 index 21318d1..7f105e4 100644
75680 --- a/net/core/rtnetlink.c
75681 +++ b/net/core/rtnetlink.c
75682 @@ -58,7 +58,7 @@ struct rtnl_link {
75683 rtnl_doit_func doit;
75684 rtnl_dumpit_func dumpit;
75685 rtnl_calcit_func calcit;
75686 -};
75687 +} __no_const;
75688
75689 static DEFINE_MUTEX(rtnl_mutex);
75690
75691 diff --git a/net/core/scm.c b/net/core/scm.c
75692 index 611c5ef..88f6d6d 100644
75693 --- a/net/core/scm.c
75694 +++ b/net/core/scm.c
75695 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75696 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75697 {
75698 struct cmsghdr __user *cm
75699 - = (__force struct cmsghdr __user *)msg->msg_control;
75700 + = (struct cmsghdr __force_user *)msg->msg_control;
75701 struct cmsghdr cmhdr;
75702 int cmlen = CMSG_LEN(len);
75703 int err;
75704 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75705 err = -EFAULT;
75706 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75707 goto out;
75708 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75709 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75710 goto out;
75711 cmlen = CMSG_SPACE(len);
75712 if (msg->msg_controllen < cmlen)
75713 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75714 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75715 {
75716 struct cmsghdr __user *cm
75717 - = (__force struct cmsghdr __user*)msg->msg_control;
75718 + = (struct cmsghdr __force_user *)msg->msg_control;
75719
75720 int fdmax = 0;
75721 int fdnum = scm->fp->count;
75722 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75723 if (fdnum < fdmax)
75724 fdmax = fdnum;
75725
75726 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75727 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75728 i++, cmfptr++)
75729 {
75730 int new_fd;
75731 diff --git a/net/core/sock.c b/net/core/sock.c
75732 index 9e5b71f..66dec30 100644
75733 --- a/net/core/sock.c
75734 +++ b/net/core/sock.c
75735 @@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75736 struct sk_buff_head *list = &sk->sk_receive_queue;
75737
75738 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75739 - atomic_inc(&sk->sk_drops);
75740 + atomic_inc_unchecked(&sk->sk_drops);
75741 trace_sock_rcvqueue_full(sk, skb);
75742 return -ENOMEM;
75743 }
75744 @@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75745 return err;
75746
75747 if (!sk_rmem_schedule(sk, skb->truesize)) {
75748 - atomic_inc(&sk->sk_drops);
75749 + atomic_inc_unchecked(&sk->sk_drops);
75750 return -ENOBUFS;
75751 }
75752
75753 @@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75754 skb_dst_force(skb);
75755
75756 spin_lock_irqsave(&list->lock, flags);
75757 - skb->dropcount = atomic_read(&sk->sk_drops);
75758 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75759 __skb_queue_tail(list, skb);
75760 spin_unlock_irqrestore(&list->lock, flags);
75761
75762 @@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75763 skb->dev = NULL;
75764
75765 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
75766 - atomic_inc(&sk->sk_drops);
75767 + atomic_inc_unchecked(&sk->sk_drops);
75768 goto discard_and_relse;
75769 }
75770 if (nested)
75771 @@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75772 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75773 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
75774 bh_unlock_sock(sk);
75775 - atomic_inc(&sk->sk_drops);
75776 + atomic_inc_unchecked(&sk->sk_drops);
75777 goto discard_and_relse;
75778 }
75779
75780 @@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75781 if (len > sizeof(peercred))
75782 len = sizeof(peercred);
75783 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75784 - if (copy_to_user(optval, &peercred, len))
75785 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75786 return -EFAULT;
75787 goto lenout;
75788 }
75789 @@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75790 return -ENOTCONN;
75791 if (lv < len)
75792 return -EINVAL;
75793 - if (copy_to_user(optval, address, len))
75794 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75795 return -EFAULT;
75796 goto lenout;
75797 }
75798 @@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75799
75800 if (len > lv)
75801 len = lv;
75802 - if (copy_to_user(optval, &v, len))
75803 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75804 return -EFAULT;
75805 lenout:
75806 if (put_user(len, optlen))
75807 @@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75808 */
75809 smp_wmb();
75810 atomic_set(&sk->sk_refcnt, 1);
75811 - atomic_set(&sk->sk_drops, 0);
75812 + atomic_set_unchecked(&sk->sk_drops, 0);
75813 }
75814 EXPORT_SYMBOL(sock_init_data);
75815
75816 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75817 index 5fd1467..8b70900 100644
75818 --- a/net/core/sock_diag.c
75819 +++ b/net/core/sock_diag.c
75820 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75821
75822 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75823 {
75824 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75825 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75826 cookie[1] != INET_DIAG_NOCOOKIE) &&
75827 ((u32)(unsigned long)sk != cookie[0] ||
75828 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75829 return -ESTALE;
75830 else
75831 +#endif
75832 return 0;
75833 }
75834 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75835
75836 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75837 {
75838 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75839 + cookie[0] = 0;
75840 + cookie[1] = 0;
75841 +#else
75842 cookie[0] = (u32)(unsigned long)sk;
75843 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75844 +#endif
75845 }
75846 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75847
75848 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75849 index a55eecc..dd8428c 100644
75850 --- a/net/decnet/sysctl_net_decnet.c
75851 +++ b/net/decnet/sysctl_net_decnet.c
75852 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75853
75854 if (len > *lenp) len = *lenp;
75855
75856 - if (copy_to_user(buffer, addr, len))
75857 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75858 return -EFAULT;
75859
75860 *lenp = len;
75861 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75862
75863 if (len > *lenp) len = *lenp;
75864
75865 - if (copy_to_user(buffer, devname, len))
75866 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75867 return -EFAULT;
75868
75869 *lenp = len;
75870 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75871 index 3854411..2201a94 100644
75872 --- a/net/ipv4/fib_frontend.c
75873 +++ b/net/ipv4/fib_frontend.c
75874 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75875 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75876 fib_sync_up(dev);
75877 #endif
75878 - atomic_inc(&net->ipv4.dev_addr_genid);
75879 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75880 rt_cache_flush(dev_net(dev), -1);
75881 break;
75882 case NETDEV_DOWN:
75883 fib_del_ifaddr(ifa, NULL);
75884 - atomic_inc(&net->ipv4.dev_addr_genid);
75885 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75886 if (ifa->ifa_dev->ifa_list == NULL) {
75887 /* Last address was deleted from this interface.
75888 * Disable IP.
75889 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75890 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75891 fib_sync_up(dev);
75892 #endif
75893 - atomic_inc(&net->ipv4.dev_addr_genid);
75894 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75895 rt_cache_flush(dev_net(dev), -1);
75896 break;
75897 case NETDEV_DOWN:
75898 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75899 index e5b7182..570a90e 100644
75900 --- a/net/ipv4/fib_semantics.c
75901 +++ b/net/ipv4/fib_semantics.c
75902 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75903 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75904 nh->nh_gw,
75905 nh->nh_parent->fib_scope);
75906 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75907 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75908
75909 return nh->nh_saddr;
75910 }
75911 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75912 index 7880af9..70f92a3 100644
75913 --- a/net/ipv4/inet_hashtables.c
75914 +++ b/net/ipv4/inet_hashtables.c
75915 @@ -18,12 +18,15 @@
75916 #include <linux/sched.h>
75917 #include <linux/slab.h>
75918 #include <linux/wait.h>
75919 +#include <linux/security.h>
75920
75921 #include <net/inet_connection_sock.h>
75922 #include <net/inet_hashtables.h>
75923 #include <net/secure_seq.h>
75924 #include <net/ip.h>
75925
75926 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75927 +
75928 /*
75929 * Allocate and initialize a new local port bind bucket.
75930 * The bindhash mutex for snum's hash chain must be held here.
75931 @@ -530,6 +533,8 @@ ok:
75932 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75933 spin_unlock(&head->lock);
75934
75935 + gr_update_task_in_ip_table(current, inet_sk(sk));
75936 +
75937 if (tw) {
75938 inet_twsk_deschedule(tw, death_row);
75939 while (twrefcnt) {
75940 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75941 index dfba343..c827d50 100644
75942 --- a/net/ipv4/inetpeer.c
75943 +++ b/net/ipv4/inetpeer.c
75944 @@ -487,8 +487,8 @@ relookup:
75945 if (p) {
75946 p->daddr = *daddr;
75947 atomic_set(&p->refcnt, 1);
75948 - atomic_set(&p->rid, 0);
75949 - atomic_set(&p->ip_id_count,
75950 + atomic_set_unchecked(&p->rid, 0);
75951 + atomic_set_unchecked(&p->ip_id_count,
75952 (daddr->family == AF_INET) ?
75953 secure_ip_id(daddr->addr.a4) :
75954 secure_ipv6_id(daddr->addr.a6));
75955 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75956 index 9dbd3dd..0c59fb2 100644
75957 --- a/net/ipv4/ip_fragment.c
75958 +++ b/net/ipv4/ip_fragment.c
75959 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75960 return 0;
75961
75962 start = qp->rid;
75963 - end = atomic_inc_return(&peer->rid);
75964 + end = atomic_inc_return_unchecked(&peer->rid);
75965 qp->rid = end;
75966
75967 rc = qp->q.fragments && (end - start) > max;
75968 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75969 index 0d11f23..2bb3f64 100644
75970 --- a/net/ipv4/ip_sockglue.c
75971 +++ b/net/ipv4/ip_sockglue.c
75972 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75973 len = min_t(unsigned int, len, opt->optlen);
75974 if (put_user(len, optlen))
75975 return -EFAULT;
75976 - if (copy_to_user(optval, opt->__data, len))
75977 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75978 + copy_to_user(optval, opt->__data, len))
75979 return -EFAULT;
75980 return 0;
75981 }
75982 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75983 if (sk->sk_type != SOCK_STREAM)
75984 return -ENOPROTOOPT;
75985
75986 - msg.msg_control = optval;
75987 + msg.msg_control = (void __force_kernel *)optval;
75988 msg.msg_controllen = len;
75989 msg.msg_flags = flags;
75990
75991 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75992 index 67e8a6b..386764d 100644
75993 --- a/net/ipv4/ipconfig.c
75994 +++ b/net/ipv4/ipconfig.c
75995 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75996
75997 mm_segment_t oldfs = get_fs();
75998 set_fs(get_ds());
75999 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76000 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76001 set_fs(oldfs);
76002 return res;
76003 }
76004 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76005
76006 mm_segment_t oldfs = get_fs();
76007 set_fs(get_ds());
76008 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76009 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76010 set_fs(oldfs);
76011 return res;
76012 }
76013 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76014
76015 mm_segment_t oldfs = get_fs();
76016 set_fs(get_ds());
76017 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76018 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76019 set_fs(oldfs);
76020 return res;
76021 }
76022 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76023 index 2c00e8b..45b3bdd 100644
76024 --- a/net/ipv4/ping.c
76025 +++ b/net/ipv4/ping.c
76026 @@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76027 sk_rmem_alloc_get(sp),
76028 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76029 atomic_read(&sp->sk_refcnt), sp,
76030 - atomic_read(&sp->sk_drops), len);
76031 + atomic_read_unchecked(&sp->sk_drops), len);
76032 }
76033
76034 static int ping_seq_show(struct seq_file *seq, void *v)
76035 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76036 index 4032b81..625143c 100644
76037 --- a/net/ipv4/raw.c
76038 +++ b/net/ipv4/raw.c
76039 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76040 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76041 {
76042 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76043 - atomic_inc(&sk->sk_drops);
76044 + atomic_inc_unchecked(&sk->sk_drops);
76045 kfree_skb(skb);
76046 return NET_RX_DROP;
76047 }
76048 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
76049
76050 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76051 {
76052 + struct icmp_filter filter;
76053 +
76054 if (optlen > sizeof(struct icmp_filter))
76055 optlen = sizeof(struct icmp_filter);
76056 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76057 + if (copy_from_user(&filter, optval, optlen))
76058 return -EFAULT;
76059 + raw_sk(sk)->filter = filter;
76060 return 0;
76061 }
76062
76063 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76064 {
76065 int len, ret = -EFAULT;
76066 + struct icmp_filter filter;
76067
76068 if (get_user(len, optlen))
76069 goto out;
76070 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76071 if (len > sizeof(struct icmp_filter))
76072 len = sizeof(struct icmp_filter);
76073 ret = -EFAULT;
76074 - if (put_user(len, optlen) ||
76075 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76076 + filter = raw_sk(sk)->filter;
76077 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76078 goto out;
76079 ret = 0;
76080 out: return ret;
76081 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76082 sk_wmem_alloc_get(sp),
76083 sk_rmem_alloc_get(sp),
76084 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76085 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76086 + atomic_read(&sp->sk_refcnt),
76087 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76088 + NULL,
76089 +#else
76090 + sp,
76091 +#endif
76092 + atomic_read_unchecked(&sp->sk_drops));
76093 }
76094
76095 static int raw_seq_show(struct seq_file *seq, void *v)
76096 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76097 index 98b30d0..cfa3cf7 100644
76098 --- a/net/ipv4/route.c
76099 +++ b/net/ipv4/route.c
76100 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76101
76102 static inline int rt_genid(struct net *net)
76103 {
76104 - return atomic_read(&net->ipv4.rt_genid);
76105 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76106 }
76107
76108 #ifdef CONFIG_PROC_FS
76109 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76110 unsigned char shuffle;
76111
76112 get_random_bytes(&shuffle, sizeof(shuffle));
76113 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76114 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76115 inetpeer_invalidate_tree(AF_INET);
76116 }
76117
76118 @@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76119 error = rt->dst.error;
76120 if (peer) {
76121 inet_peer_refcheck(rt->peer);
76122 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76123 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76124 if (peer->tcp_ts_stamp) {
76125 ts = peer->tcp_ts;
76126 tsage = get_seconds() - peer->tcp_ts_stamp;
76127 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76128 index c8d28c4..e40f75a 100644
76129 --- a/net/ipv4/tcp_ipv4.c
76130 +++ b/net/ipv4/tcp_ipv4.c
76131 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76132 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76133
76134
76135 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76136 +extern int grsec_enable_blackhole;
76137 +#endif
76138 +
76139 #ifdef CONFIG_TCP_MD5SIG
76140 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76141 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76142 @@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76143 return 0;
76144
76145 reset:
76146 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76147 + if (!grsec_enable_blackhole)
76148 +#endif
76149 tcp_v4_send_reset(rsk, skb);
76150 discard:
76151 kfree_skb(skb);
76152 @@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76153 TCP_SKB_CB(skb)->sacked = 0;
76154
76155 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76156 - if (!sk)
76157 + if (!sk) {
76158 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76159 + ret = 1;
76160 +#endif
76161 goto no_tcp_socket;
76162 -
76163 + }
76164 process:
76165 - if (sk->sk_state == TCP_TIME_WAIT)
76166 + if (sk->sk_state == TCP_TIME_WAIT) {
76167 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76168 + ret = 2;
76169 +#endif
76170 goto do_time_wait;
76171 + }
76172
76173 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76174 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76175 @@ -1774,6 +1788,10 @@ no_tcp_socket:
76176 bad_packet:
76177 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76178 } else {
76179 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76180 + if (!grsec_enable_blackhole || (ret == 1 &&
76181 + (skb->dev->flags & IFF_LOOPBACK)))
76182 +#endif
76183 tcp_v4_send_reset(NULL, skb);
76184 }
76185
76186 @@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76187 0, /* non standard timer */
76188 0, /* open_requests have no inode */
76189 atomic_read(&sk->sk_refcnt),
76190 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76191 + NULL,
76192 +#else
76193 req,
76194 +#endif
76195 len);
76196 }
76197
76198 @@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76199 sock_i_uid(sk),
76200 icsk->icsk_probes_out,
76201 sock_i_ino(sk),
76202 - atomic_read(&sk->sk_refcnt), sk,
76203 + atomic_read(&sk->sk_refcnt),
76204 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76205 + NULL,
76206 +#else
76207 + sk,
76208 +#endif
76209 jiffies_to_clock_t(icsk->icsk_rto),
76210 jiffies_to_clock_t(icsk->icsk_ack.ato),
76211 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76212 @@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76213 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76214 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76215 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76216 - atomic_read(&tw->tw_refcnt), tw, len);
76217 + atomic_read(&tw->tw_refcnt),
76218 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76219 + NULL,
76220 +#else
76221 + tw,
76222 +#endif
76223 + len);
76224 }
76225
76226 #define TMPSZ 150
76227 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76228 index b85d9fe..4b0eed9 100644
76229 --- a/net/ipv4/tcp_minisocks.c
76230 +++ b/net/ipv4/tcp_minisocks.c
76231 @@ -27,6 +27,10 @@
76232 #include <net/inet_common.h>
76233 #include <net/xfrm.h>
76234
76235 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76236 +extern int grsec_enable_blackhole;
76237 +#endif
76238 +
76239 int sysctl_tcp_syncookies __read_mostly = 1;
76240 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76241
76242 @@ -754,6 +758,10 @@ listen_overflow:
76243
76244 embryonic_reset:
76245 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76246 +
76247 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76248 + if (!grsec_enable_blackhole)
76249 +#endif
76250 if (!(flg & TCP_FLAG_RST))
76251 req->rsk_ops->send_reset(sk, skb);
76252
76253 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76254 index 4526fe6..1a34e43 100644
76255 --- a/net/ipv4/tcp_probe.c
76256 +++ b/net/ipv4/tcp_probe.c
76257 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76258 if (cnt + width >= len)
76259 break;
76260
76261 - if (copy_to_user(buf + cnt, tbuf, width))
76262 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76263 return -EFAULT;
76264 cnt += width;
76265 }
76266 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76267 index e911e6c..d0a9356 100644
76268 --- a/net/ipv4/tcp_timer.c
76269 +++ b/net/ipv4/tcp_timer.c
76270 @@ -22,6 +22,10 @@
76271 #include <linux/gfp.h>
76272 #include <net/tcp.h>
76273
76274 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76275 +extern int grsec_lastack_retries;
76276 +#endif
76277 +
76278 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76279 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76280 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76281 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76282 }
76283 }
76284
76285 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76286 + if ((sk->sk_state == TCP_LAST_ACK) &&
76287 + (grsec_lastack_retries > 0) &&
76288 + (grsec_lastack_retries < retry_until))
76289 + retry_until = grsec_lastack_retries;
76290 +#endif
76291 +
76292 if (retransmits_timed_out(sk, retry_until,
76293 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76294 /* Has it gone just too far? */
76295 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76296 index eaca736..60488ae 100644
76297 --- a/net/ipv4/udp.c
76298 +++ b/net/ipv4/udp.c
76299 @@ -87,6 +87,7 @@
76300 #include <linux/types.h>
76301 #include <linux/fcntl.h>
76302 #include <linux/module.h>
76303 +#include <linux/security.h>
76304 #include <linux/socket.h>
76305 #include <linux/sockios.h>
76306 #include <linux/igmp.h>
76307 @@ -110,6 +111,10 @@
76308 #include <linux/static_key.h>
76309 #include "udp_impl.h"
76310
76311 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76312 +extern int grsec_enable_blackhole;
76313 +#endif
76314 +
76315 struct udp_table udp_table __read_mostly;
76316 EXPORT_SYMBOL(udp_table);
76317
76318 @@ -568,6 +573,9 @@ found:
76319 return s;
76320 }
76321
76322 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76323 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76324 +
76325 /*
76326 * This routine is called by the ICMP module when it gets some
76327 * sort of error condition. If err < 0 then the socket should
76328 @@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76329 dport = usin->sin_port;
76330 if (dport == 0)
76331 return -EINVAL;
76332 +
76333 + err = gr_search_udp_sendmsg(sk, usin);
76334 + if (err)
76335 + return err;
76336 } else {
76337 if (sk->sk_state != TCP_ESTABLISHED)
76338 return -EDESTADDRREQ;
76339 +
76340 + err = gr_search_udp_sendmsg(sk, NULL);
76341 + if (err)
76342 + return err;
76343 +
76344 daddr = inet->inet_daddr;
76345 dport = inet->inet_dport;
76346 /* Open fast path for connected socket.
76347 @@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76348 udp_lib_checksum_complete(skb)) {
76349 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76350 IS_UDPLITE(sk));
76351 - atomic_inc(&sk->sk_drops);
76352 + atomic_inc_unchecked(&sk->sk_drops);
76353 __skb_unlink(skb, rcvq);
76354 __skb_queue_tail(&list_kill, skb);
76355 }
76356 @@ -1189,6 +1206,10 @@ try_again:
76357 if (!skb)
76358 goto out;
76359
76360 + err = gr_search_udp_recvmsg(sk, skb);
76361 + if (err)
76362 + goto out_free;
76363 +
76364 ulen = skb->len - sizeof(struct udphdr);
76365 copied = len;
76366 if (copied > ulen)
76367 @@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76368
76369 drop:
76370 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76371 - atomic_inc(&sk->sk_drops);
76372 + atomic_inc_unchecked(&sk->sk_drops);
76373 kfree_skb(skb);
76374 return -1;
76375 }
76376 @@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76377 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76378
76379 if (!skb1) {
76380 - atomic_inc(&sk->sk_drops);
76381 + atomic_inc_unchecked(&sk->sk_drops);
76382 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76383 IS_UDPLITE(sk));
76384 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76385 @@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76386 goto csum_error;
76387
76388 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76389 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76390 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76391 +#endif
76392 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76393
76394 /*
76395 @@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76396 sk_wmem_alloc_get(sp),
76397 sk_rmem_alloc_get(sp),
76398 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76399 - atomic_read(&sp->sk_refcnt), sp,
76400 - atomic_read(&sp->sk_drops), len);
76401 + atomic_read(&sp->sk_refcnt),
76402 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76403 + NULL,
76404 +#else
76405 + sp,
76406 +#endif
76407 + atomic_read_unchecked(&sp->sk_drops), len);
76408 }
76409
76410 int udp4_seq_show(struct seq_file *seq, void *v)
76411 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76412 index 8f6411c..5767579 100644
76413 --- a/net/ipv6/addrconf.c
76414 +++ b/net/ipv6/addrconf.c
76415 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76416 p.iph.ihl = 5;
76417 p.iph.protocol = IPPROTO_IPV6;
76418 p.iph.ttl = 64;
76419 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76420 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76421
76422 if (ops->ndo_do_ioctl) {
76423 mm_segment_t oldfs = get_fs();
76424 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76425 index e6cee52..cf47476 100644
76426 --- a/net/ipv6/inet6_connection_sock.c
76427 +++ b/net/ipv6/inet6_connection_sock.c
76428 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76429 #ifdef CONFIG_XFRM
76430 {
76431 struct rt6_info *rt = (struct rt6_info *)dst;
76432 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76433 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76434 }
76435 #endif
76436 }
76437 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76438 #ifdef CONFIG_XFRM
76439 if (dst) {
76440 struct rt6_info *rt = (struct rt6_info *)dst;
76441 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76442 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76443 __sk_dst_reset(sk);
76444 dst = NULL;
76445 }
76446 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76447 index ba6d13d..6899122 100644
76448 --- a/net/ipv6/ipv6_sockglue.c
76449 +++ b/net/ipv6/ipv6_sockglue.c
76450 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76451 if (sk->sk_type != SOCK_STREAM)
76452 return -ENOPROTOOPT;
76453
76454 - msg.msg_control = optval;
76455 + msg.msg_control = (void __force_kernel *)optval;
76456 msg.msg_controllen = len;
76457 msg.msg_flags = flags;
76458
76459 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76460 index 93d6983..8e54c4d 100644
76461 --- a/net/ipv6/raw.c
76462 +++ b/net/ipv6/raw.c
76463 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76464 {
76465 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76466 skb_checksum_complete(skb)) {
76467 - atomic_inc(&sk->sk_drops);
76468 + atomic_inc_unchecked(&sk->sk_drops);
76469 kfree_skb(skb);
76470 return NET_RX_DROP;
76471 }
76472 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76473 struct raw6_sock *rp = raw6_sk(sk);
76474
76475 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76476 - atomic_inc(&sk->sk_drops);
76477 + atomic_inc_unchecked(&sk->sk_drops);
76478 kfree_skb(skb);
76479 return NET_RX_DROP;
76480 }
76481 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76482
76483 if (inet->hdrincl) {
76484 if (skb_checksum_complete(skb)) {
76485 - atomic_inc(&sk->sk_drops);
76486 + atomic_inc_unchecked(&sk->sk_drops);
76487 kfree_skb(skb);
76488 return NET_RX_DROP;
76489 }
76490 @@ -602,7 +602,7 @@ out:
76491 return err;
76492 }
76493
76494 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76495 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76496 struct flowi6 *fl6, struct dst_entry **dstp,
76497 unsigned int flags)
76498 {
76499 @@ -914,12 +914,15 @@ do_confirm:
76500 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76501 char __user *optval, int optlen)
76502 {
76503 + struct icmp6_filter filter;
76504 +
76505 switch (optname) {
76506 case ICMPV6_FILTER:
76507 if (optlen > sizeof(struct icmp6_filter))
76508 optlen = sizeof(struct icmp6_filter);
76509 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76510 + if (copy_from_user(&filter, optval, optlen))
76511 return -EFAULT;
76512 + raw6_sk(sk)->filter = filter;
76513 return 0;
76514 default:
76515 return -ENOPROTOOPT;
76516 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76517 char __user *optval, int __user *optlen)
76518 {
76519 int len;
76520 + struct icmp6_filter filter;
76521
76522 switch (optname) {
76523 case ICMPV6_FILTER:
76524 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76525 len = sizeof(struct icmp6_filter);
76526 if (put_user(len, optlen))
76527 return -EFAULT;
76528 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76529 + filter = raw6_sk(sk)->filter;
76530 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76531 return -EFAULT;
76532 return 0;
76533 default:
76534 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76535 0, 0L, 0,
76536 sock_i_uid(sp), 0,
76537 sock_i_ino(sp),
76538 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76539 + atomic_read(&sp->sk_refcnt),
76540 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76541 + NULL,
76542 +#else
76543 + sp,
76544 +#endif
76545 + atomic_read_unchecked(&sp->sk_drops));
76546 }
76547
76548 static int raw6_seq_show(struct seq_file *seq, void *v)
76549 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76550 index 9df64a5..39875da 100644
76551 --- a/net/ipv6/tcp_ipv6.c
76552 +++ b/net/ipv6/tcp_ipv6.c
76553 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76554 }
76555 #endif
76556
76557 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76558 +extern int grsec_enable_blackhole;
76559 +#endif
76560 +
76561 static void tcp_v6_hash(struct sock *sk)
76562 {
76563 if (sk->sk_state != TCP_CLOSE) {
76564 @@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76565 return 0;
76566
76567 reset:
76568 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76569 + if (!grsec_enable_blackhole)
76570 +#endif
76571 tcp_v6_send_reset(sk, skb);
76572 discard:
76573 if (opt_skb)
76574 @@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76575 TCP_SKB_CB(skb)->sacked = 0;
76576
76577 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76578 - if (!sk)
76579 + if (!sk) {
76580 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76581 + ret = 1;
76582 +#endif
76583 goto no_tcp_socket;
76584 + }
76585
76586 process:
76587 - if (sk->sk_state == TCP_TIME_WAIT)
76588 + if (sk->sk_state == TCP_TIME_WAIT) {
76589 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76590 + ret = 2;
76591 +#endif
76592 goto do_time_wait;
76593 + }
76594
76595 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76596 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76597 @@ -1679,6 +1694,10 @@ no_tcp_socket:
76598 bad_packet:
76599 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76600 } else {
76601 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76602 + if (!grsec_enable_blackhole || (ret == 1 &&
76603 + (skb->dev->flags & IFF_LOOPBACK)))
76604 +#endif
76605 tcp_v6_send_reset(NULL, skb);
76606 }
76607
76608 @@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76609 uid,
76610 0, /* non standard timer */
76611 0, /* open_requests have no inode */
76612 - 0, req);
76613 + 0,
76614 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76615 + NULL
76616 +#else
76617 + req
76618 +#endif
76619 + );
76620 }
76621
76622 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76623 @@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76624 sock_i_uid(sp),
76625 icsk->icsk_probes_out,
76626 sock_i_ino(sp),
76627 - atomic_read(&sp->sk_refcnt), sp,
76628 + atomic_read(&sp->sk_refcnt),
76629 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76630 + NULL,
76631 +#else
76632 + sp,
76633 +#endif
76634 jiffies_to_clock_t(icsk->icsk_rto),
76635 jiffies_to_clock_t(icsk->icsk_ack.ato),
76636 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76637 @@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76638 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76639 tw->tw_substate, 0, 0,
76640 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76641 - atomic_read(&tw->tw_refcnt), tw);
76642 + atomic_read(&tw->tw_refcnt),
76643 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76644 + NULL
76645 +#else
76646 + tw
76647 +#endif
76648 + );
76649 }
76650
76651 static int tcp6_seq_show(struct seq_file *seq, void *v)
76652 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76653 index f05099f..ea613f0 100644
76654 --- a/net/ipv6/udp.c
76655 +++ b/net/ipv6/udp.c
76656 @@ -50,6 +50,10 @@
76657 #include <linux/seq_file.h>
76658 #include "udp_impl.h"
76659
76660 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76661 +extern int grsec_enable_blackhole;
76662 +#endif
76663 +
76664 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76665 {
76666 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76667 @@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76668 return rc;
76669 drop:
76670 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76671 - atomic_inc(&sk->sk_drops);
76672 + atomic_inc_unchecked(&sk->sk_drops);
76673 kfree_skb(skb);
76674 return -1;
76675 }
76676 @@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76677 if (likely(skb1 == NULL))
76678 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76679 if (!skb1) {
76680 - atomic_inc(&sk->sk_drops);
76681 + atomic_inc_unchecked(&sk->sk_drops);
76682 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76683 IS_UDPLITE(sk));
76684 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76685 @@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76686 goto discard;
76687
76688 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76689 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76690 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76691 +#endif
76692 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76693
76694 kfree_skb(skb);
76695 @@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76696 0, 0L, 0,
76697 sock_i_uid(sp), 0,
76698 sock_i_ino(sp),
76699 - atomic_read(&sp->sk_refcnt), sp,
76700 - atomic_read(&sp->sk_drops));
76701 + atomic_read(&sp->sk_refcnt),
76702 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76703 + NULL,
76704 +#else
76705 + sp,
76706 +#endif
76707 + atomic_read_unchecked(&sp->sk_drops));
76708 }
76709
76710 int udp6_seq_show(struct seq_file *seq, void *v)
76711 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76712 index 6b9d5a0..4dffaf1 100644
76713 --- a/net/irda/ircomm/ircomm_tty.c
76714 +++ b/net/irda/ircomm/ircomm_tty.c
76715 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76716 add_wait_queue(&self->open_wait, &wait);
76717
76718 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76719 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76720 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76721
76722 /* As far as I can see, we protect open_count - Jean II */
76723 spin_lock_irqsave(&self->spinlock, flags);
76724 if (!tty_hung_up_p(filp)) {
76725 extra_count = 1;
76726 - self->open_count--;
76727 + local_dec(&self->open_count);
76728 }
76729 spin_unlock_irqrestore(&self->spinlock, flags);
76730 - self->blocked_open++;
76731 + local_inc(&self->blocked_open);
76732
76733 while (1) {
76734 if (tty->termios->c_cflag & CBAUD) {
76735 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76736 }
76737
76738 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76739 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76740 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76741
76742 schedule();
76743 }
76744 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76745 if (extra_count) {
76746 /* ++ is not atomic, so this should be protected - Jean II */
76747 spin_lock_irqsave(&self->spinlock, flags);
76748 - self->open_count++;
76749 + local_inc(&self->open_count);
76750 spin_unlock_irqrestore(&self->spinlock, flags);
76751 }
76752 - self->blocked_open--;
76753 + local_dec(&self->blocked_open);
76754
76755 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76756 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76757 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76758
76759 if (!retval)
76760 self->flags |= ASYNC_NORMAL_ACTIVE;
76761 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76762 }
76763 /* ++ is not atomic, so this should be protected - Jean II */
76764 spin_lock_irqsave(&self->spinlock, flags);
76765 - self->open_count++;
76766 + local_inc(&self->open_count);
76767
76768 tty->driver_data = self;
76769 self->tty = tty;
76770 spin_unlock_irqrestore(&self->spinlock, flags);
76771
76772 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76773 - self->line, self->open_count);
76774 + self->line, local_read(&self->open_count));
76775
76776 /* Not really used by us, but lets do it anyway */
76777 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76778 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76779 return;
76780 }
76781
76782 - if ((tty->count == 1) && (self->open_count != 1)) {
76783 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76784 /*
76785 * Uh, oh. tty->count is 1, which means that the tty
76786 * structure will be freed. state->count should always
76787 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76788 */
76789 IRDA_DEBUG(0, "%s(), bad serial port count; "
76790 "tty->count is 1, state->count is %d\n", __func__ ,
76791 - self->open_count);
76792 - self->open_count = 1;
76793 + local_read(&self->open_count));
76794 + local_set(&self->open_count, 1);
76795 }
76796
76797 - if (--self->open_count < 0) {
76798 + if (local_dec_return(&self->open_count) < 0) {
76799 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76800 - __func__, self->line, self->open_count);
76801 - self->open_count = 0;
76802 + __func__, self->line, local_read(&self->open_count));
76803 + local_set(&self->open_count, 0);
76804 }
76805 - if (self->open_count) {
76806 + if (local_read(&self->open_count)) {
76807 spin_unlock_irqrestore(&self->spinlock, flags);
76808
76809 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76810 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76811 tty->closing = 0;
76812 self->tty = NULL;
76813
76814 - if (self->blocked_open) {
76815 + if (local_read(&self->blocked_open)) {
76816 if (self->close_delay)
76817 schedule_timeout_interruptible(self->close_delay);
76818 wake_up_interruptible(&self->open_wait);
76819 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76820 spin_lock_irqsave(&self->spinlock, flags);
76821 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76822 self->tty = NULL;
76823 - self->open_count = 0;
76824 + local_set(&self->open_count, 0);
76825 spin_unlock_irqrestore(&self->spinlock, flags);
76826
76827 wake_up_interruptible(&self->open_wait);
76828 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76829 seq_putc(m, '\n');
76830
76831 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76832 - seq_printf(m, "Open count: %d\n", self->open_count);
76833 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76834 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76835 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76836
76837 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76838 index cd6f7a9..e63fe89 100644
76839 --- a/net/iucv/af_iucv.c
76840 +++ b/net/iucv/af_iucv.c
76841 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
76842
76843 write_lock_bh(&iucv_sk_list.lock);
76844
76845 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76846 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76847 while (__iucv_get_sock_by_name(name)) {
76848 sprintf(name, "%08x",
76849 - atomic_inc_return(&iucv_sk_list.autobind_name));
76850 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76851 }
76852
76853 write_unlock_bh(&iucv_sk_list.lock);
76854 diff --git a/net/key/af_key.c b/net/key/af_key.c
76855 index 34e4185..8823368 100644
76856 --- a/net/key/af_key.c
76857 +++ b/net/key/af_key.c
76858 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76859 static u32 get_acqseq(void)
76860 {
76861 u32 res;
76862 - static atomic_t acqseq;
76863 + static atomic_unchecked_t acqseq;
76864
76865 do {
76866 - res = atomic_inc_return(&acqseq);
76867 + res = atomic_inc_return_unchecked(&acqseq);
76868 } while (!res);
76869 return res;
76870 }
76871 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76872 index 3f3cd50..d2cf249 100644
76873 --- a/net/mac80211/ieee80211_i.h
76874 +++ b/net/mac80211/ieee80211_i.h
76875 @@ -28,6 +28,7 @@
76876 #include <net/ieee80211_radiotap.h>
76877 #include <net/cfg80211.h>
76878 #include <net/mac80211.h>
76879 +#include <asm/local.h>
76880 #include "key.h"
76881 #include "sta_info.h"
76882
76883 @@ -863,7 +864,7 @@ struct ieee80211_local {
76884 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76885 spinlock_t queue_stop_reason_lock;
76886
76887 - int open_count;
76888 + local_t open_count;
76889 int monitors, cooked_mntrs;
76890 /* number of interfaces with corresponding FIF_ flags */
76891 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76892 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76893 index 8664111..1d6a065 100644
76894 --- a/net/mac80211/iface.c
76895 +++ b/net/mac80211/iface.c
76896 @@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76897 break;
76898 }
76899
76900 - if (local->open_count == 0) {
76901 + if (local_read(&local->open_count) == 0) {
76902 res = drv_start(local);
76903 if (res)
76904 goto err_del_bss;
76905 @@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76906 break;
76907 }
76908
76909 - if (local->monitors == 0 && local->open_count == 0) {
76910 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
76911 res = ieee80211_add_virtual_monitor(local);
76912 if (res)
76913 goto err_stop;
76914 @@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76915 mutex_unlock(&local->mtx);
76916
76917 if (coming_up)
76918 - local->open_count++;
76919 + local_inc(&local->open_count);
76920
76921 if (hw_reconf_flags)
76922 ieee80211_hw_config(local, hw_reconf_flags);
76923 @@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76924 err_del_interface:
76925 drv_remove_interface(local, sdata);
76926 err_stop:
76927 - if (!local->open_count)
76928 + if (!local_read(&local->open_count))
76929 drv_stop(local);
76930 err_del_bss:
76931 sdata->bss = NULL;
76932 @@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76933 }
76934
76935 if (going_down)
76936 - local->open_count--;
76937 + local_dec(&local->open_count);
76938
76939 switch (sdata->vif.type) {
76940 case NL80211_IFTYPE_AP_VLAN:
76941 @@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76942
76943 ieee80211_recalc_ps(local, -1);
76944
76945 - if (local->open_count == 0) {
76946 + if (local_read(&local->open_count) == 0) {
76947 if (local->ops->napi_poll)
76948 napi_disable(&local->napi);
76949 ieee80211_clear_tx_pending(local);
76950 @@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76951 }
76952 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
76953
76954 - if (local->monitors == local->open_count && local->monitors > 0)
76955 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
76956 ieee80211_add_virtual_monitor(local);
76957 }
76958
76959 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76960 index f5548e9..474a15f 100644
76961 --- a/net/mac80211/main.c
76962 +++ b/net/mac80211/main.c
76963 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76964 local->hw.conf.power_level = power;
76965 }
76966
76967 - if (changed && local->open_count) {
76968 + if (changed && local_read(&local->open_count)) {
76969 ret = drv_config(local, changed);
76970 /*
76971 * Goal:
76972 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76973 index af1c4e2..24dbbe3 100644
76974 --- a/net/mac80211/pm.c
76975 +++ b/net/mac80211/pm.c
76976 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76977 struct ieee80211_sub_if_data *sdata;
76978 struct sta_info *sta;
76979
76980 - if (!local->open_count)
76981 + if (!local_read(&local->open_count))
76982 goto suspend;
76983
76984 ieee80211_scan_cancel(local);
76985 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76986 cancel_work_sync(&local->dynamic_ps_enable_work);
76987 del_timer_sync(&local->dynamic_ps_timer);
76988
76989 - local->wowlan = wowlan && local->open_count;
76990 + local->wowlan = wowlan && local_read(&local->open_count);
76991 if (local->wowlan) {
76992 int err = drv_suspend(local, wowlan);
76993 if (err < 0) {
76994 @@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76995 drv_remove_interface(local, sdata);
76996
76997 /* stop hardware - this must stop RX */
76998 - if (local->open_count)
76999 + if (local_read(&local->open_count))
77000 ieee80211_stop_device(local);
77001
77002 suspend:
77003 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77004 index 3313c11..bec9f17 100644
77005 --- a/net/mac80211/rate.c
77006 +++ b/net/mac80211/rate.c
77007 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77008
77009 ASSERT_RTNL();
77010
77011 - if (local->open_count)
77012 + if (local_read(&local->open_count))
77013 return -EBUSY;
77014
77015 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77016 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77017 index c97a065..ff61928 100644
77018 --- a/net/mac80211/rc80211_pid_debugfs.c
77019 +++ b/net/mac80211/rc80211_pid_debugfs.c
77020 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77021
77022 spin_unlock_irqrestore(&events->lock, status);
77023
77024 - if (copy_to_user(buf, pb, p))
77025 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77026 return -EFAULT;
77027
77028 return p;
77029 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77030 index 8dd4712..19594fa 100644
77031 --- a/net/mac80211/util.c
77032 +++ b/net/mac80211/util.c
77033 @@ -1216,7 +1216,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77034 }
77035 #endif
77036 /* everything else happens only if HW was up & running */
77037 - if (!local->open_count)
77038 + if (!local_read(&local->open_count))
77039 goto wake_up;
77040
77041 /*
77042 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77043 index 209c1ed..39484dc 100644
77044 --- a/net/netfilter/Kconfig
77045 +++ b/net/netfilter/Kconfig
77046 @@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
77047
77048 To compile it as a module, choose M here. If unsure, say N.
77049
77050 +config NETFILTER_XT_MATCH_GRADM
77051 + tristate '"gradm" match support'
77052 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77053 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77054 + ---help---
77055 + The gradm match allows to match on grsecurity RBAC being enabled.
77056 + It is useful when iptables rules are applied early on bootup to
77057 + prevent connections to the machine (except from a trusted host)
77058 + while the RBAC system is disabled.
77059 +
77060 config NETFILTER_XT_MATCH_HASHLIMIT
77061 tristate '"hashlimit" match support'
77062 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77063 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77064 index 4e7960c..89e48d4 100644
77065 --- a/net/netfilter/Makefile
77066 +++ b/net/netfilter/Makefile
77067 @@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77068 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77069 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77070 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77071 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77072 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77073 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77074 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77075 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77076 index 1548df9..98ad9b4 100644
77077 --- a/net/netfilter/ipvs/ip_vs_conn.c
77078 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77079 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77080 /* Increase the refcnt counter of the dest */
77081 atomic_inc(&dest->refcnt);
77082
77083 - conn_flags = atomic_read(&dest->conn_flags);
77084 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77085 if (cp->protocol != IPPROTO_UDP)
77086 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77087 flags = cp->flags;
77088 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77089 atomic_set(&cp->refcnt, 1);
77090
77091 atomic_set(&cp->n_control, 0);
77092 - atomic_set(&cp->in_pkts, 0);
77093 + atomic_set_unchecked(&cp->in_pkts, 0);
77094
77095 atomic_inc(&ipvs->conn_count);
77096 if (flags & IP_VS_CONN_F_NO_CPORT)
77097 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77098
77099 /* Don't drop the entry if its number of incoming packets is not
77100 located in [0, 8] */
77101 - i = atomic_read(&cp->in_pkts);
77102 + i = atomic_read_unchecked(&cp->in_pkts);
77103 if (i > 8 || i < 0) return 0;
77104
77105 if (!todrop_rate[i]) return 0;
77106 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77107 index a54b018c..07e0120 100644
77108 --- a/net/netfilter/ipvs/ip_vs_core.c
77109 +++ b/net/netfilter/ipvs/ip_vs_core.c
77110 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77111 ret = cp->packet_xmit(skb, cp, pd->pp);
77112 /* do not touch skb anymore */
77113
77114 - atomic_inc(&cp->in_pkts);
77115 + atomic_inc_unchecked(&cp->in_pkts);
77116 ip_vs_conn_put(cp);
77117 return ret;
77118 }
77119 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77120 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77121 pkts = sysctl_sync_threshold(ipvs);
77122 else
77123 - pkts = atomic_add_return(1, &cp->in_pkts);
77124 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77125
77126 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77127 ip_vs_sync_conn(net, cp, pkts);
77128 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77129 index 84444dd..86adaa0 100644
77130 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77131 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77132 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77133 ip_vs_rs_hash(ipvs, dest);
77134 write_unlock_bh(&ipvs->rs_lock);
77135 }
77136 - atomic_set(&dest->conn_flags, conn_flags);
77137 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77138
77139 /* bind the service */
77140 if (!dest->svc) {
77141 @@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77142 " %-7s %-6d %-10d %-10d\n",
77143 &dest->addr.in6,
77144 ntohs(dest->port),
77145 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77146 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77147 atomic_read(&dest->weight),
77148 atomic_read(&dest->activeconns),
77149 atomic_read(&dest->inactconns));
77150 @@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77151 "%-7s %-6d %-10d %-10d\n",
77152 ntohl(dest->addr.ip),
77153 ntohs(dest->port),
77154 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77155 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77156 atomic_read(&dest->weight),
77157 atomic_read(&dest->activeconns),
77158 atomic_read(&dest->inactconns));
77159 @@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77160
77161 entry.addr = dest->addr.ip;
77162 entry.port = dest->port;
77163 - entry.conn_flags = atomic_read(&dest->conn_flags);
77164 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77165 entry.weight = atomic_read(&dest->weight);
77166 entry.u_threshold = dest->u_threshold;
77167 entry.l_threshold = dest->l_threshold;
77168 @@ -3089,7 +3089,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77169 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77170 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77171 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77172 - (atomic_read(&dest->conn_flags) &
77173 + (atomic_read_unchecked(&dest->conn_flags) &
77174 IP_VS_CONN_F_FWD_MASK)) ||
77175 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77176 atomic_read(&dest->weight)) ||
77177 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77178 index effa10c..9058928 100644
77179 --- a/net/netfilter/ipvs/ip_vs_sync.c
77180 +++ b/net/netfilter/ipvs/ip_vs_sync.c
77181 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77182 cp = cp->control;
77183 if (cp) {
77184 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77185 - pkts = atomic_add_return(1, &cp->in_pkts);
77186 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77187 else
77188 pkts = sysctl_sync_threshold(ipvs);
77189 ip_vs_sync_conn(net, cp->control, pkts);
77190 @@ -758,7 +758,7 @@ control:
77191 if (!cp)
77192 return;
77193 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77194 - pkts = atomic_add_return(1, &cp->in_pkts);
77195 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77196 else
77197 pkts = sysctl_sync_threshold(ipvs);
77198 goto sloop;
77199 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77200
77201 if (opt)
77202 memcpy(&cp->in_seq, opt, sizeof(*opt));
77203 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77204 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77205 cp->state = state;
77206 cp->old_state = cp->state;
77207 /*
77208 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77209 index 7fd66de..e6fb361 100644
77210 --- a/net/netfilter/ipvs/ip_vs_xmit.c
77211 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
77212 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77213 else
77214 rc = NF_ACCEPT;
77215 /* do not touch skb anymore */
77216 - atomic_inc(&cp->in_pkts);
77217 + atomic_inc_unchecked(&cp->in_pkts);
77218 goto out;
77219 }
77220
77221 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77222 else
77223 rc = NF_ACCEPT;
77224 /* do not touch skb anymore */
77225 - atomic_inc(&cp->in_pkts);
77226 + atomic_inc_unchecked(&cp->in_pkts);
77227 goto out;
77228 }
77229
77230 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77231 index ac3af97..c134c21 100644
77232 --- a/net/netfilter/nf_conntrack_core.c
77233 +++ b/net/netfilter/nf_conntrack_core.c
77234 @@ -1530,6 +1530,10 @@ err_proto:
77235 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77236 #define DYING_NULLS_VAL ((1<<30)+1)
77237
77238 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77239 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77240 +#endif
77241 +
77242 static int nf_conntrack_init_net(struct net *net)
77243 {
77244 int ret;
77245 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77246 goto err_stat;
77247 }
77248
77249 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77250 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77251 +#else
77252 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77253 +#endif
77254 if (!net->ct.slabname) {
77255 ret = -ENOMEM;
77256 goto err_slabname;
77257 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77258 index 3c3cfc0..7a6ea1a 100644
77259 --- a/net/netfilter/nfnetlink_log.c
77260 +++ b/net/netfilter/nfnetlink_log.c
77261 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77262 };
77263
77264 static DEFINE_SPINLOCK(instances_lock);
77265 -static atomic_t global_seq;
77266 +static atomic_unchecked_t global_seq;
77267
77268 #define INSTANCE_BUCKETS 16
77269 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77270 @@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77271 /* global sequence number */
77272 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77273 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77274 - htonl(atomic_inc_return(&global_seq))))
77275 + htonl(atomic_inc_return_unchecked(&global_seq))))
77276 goto nla_put_failure;
77277
77278 if (data_len) {
77279 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77280 new file mode 100644
77281 index 0000000..6905327
77282 --- /dev/null
77283 +++ b/net/netfilter/xt_gradm.c
77284 @@ -0,0 +1,51 @@
77285 +/*
77286 + * gradm match for netfilter
77287 + * Copyright © Zbigniew Krzystolik, 2010
77288 + *
77289 + * This program is free software; you can redistribute it and/or modify
77290 + * it under the terms of the GNU General Public License; either version
77291 + * 2 or 3 as published by the Free Software Foundation.
77292 + */
77293 +#include <linux/module.h>
77294 +#include <linux/moduleparam.h>
77295 +#include <linux/skbuff.h>
77296 +#include <linux/netfilter/x_tables.h>
77297 +#include <linux/grsecurity.h>
77298 +#include <linux/netfilter/xt_gradm.h>
77299 +
77300 +static bool
77301 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77302 +{
77303 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77304 + bool retval = false;
77305 + if (gr_acl_is_enabled())
77306 + retval = true;
77307 + return retval ^ info->invflags;
77308 +}
77309 +
77310 +static struct xt_match gradm_mt_reg __read_mostly = {
77311 + .name = "gradm",
77312 + .revision = 0,
77313 + .family = NFPROTO_UNSPEC,
77314 + .match = gradm_mt,
77315 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77316 + .me = THIS_MODULE,
77317 +};
77318 +
77319 +static int __init gradm_mt_init(void)
77320 +{
77321 + return xt_register_match(&gradm_mt_reg);
77322 +}
77323 +
77324 +static void __exit gradm_mt_exit(void)
77325 +{
77326 + xt_unregister_match(&gradm_mt_reg);
77327 +}
77328 +
77329 +module_init(gradm_mt_init);
77330 +module_exit(gradm_mt_exit);
77331 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77332 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77333 +MODULE_LICENSE("GPL");
77334 +MODULE_ALIAS("ipt_gradm");
77335 +MODULE_ALIAS("ip6t_gradm");
77336 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
77337 index 4fe4fb4..87a89e5 100644
77338 --- a/net/netfilter/xt_statistic.c
77339 +++ b/net/netfilter/xt_statistic.c
77340 @@ -19,7 +19,7 @@
77341 #include <linux/module.h>
77342
77343 struct xt_statistic_priv {
77344 - atomic_t count;
77345 + atomic_unchecked_t count;
77346 } ____cacheline_aligned_in_smp;
77347
77348 MODULE_LICENSE("GPL");
77349 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
77350 break;
77351 case XT_STATISTIC_MODE_NTH:
77352 do {
77353 - oval = atomic_read(&info->master->count);
77354 + oval = atomic_read_unchecked(&info->master->count);
77355 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77356 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77357 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77358 if (nval == 0)
77359 ret = !ret;
77360 break;
77361 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
77362 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77363 if (info->master == NULL)
77364 return -ENOMEM;
77365 - atomic_set(&info->master->count, info->u.nth.count);
77366 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77367
77368 return 0;
77369 }
77370 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
77371 index b3025a6..d63a537 100644
77372 --- a/net/netlink/af_netlink.c
77373 +++ b/net/netlink/af_netlink.c
77374 @@ -753,7 +753,7 @@ static void netlink_overrun(struct sock *sk)
77375 sk->sk_error_report(sk);
77376 }
77377 }
77378 - atomic_inc(&sk->sk_drops);
77379 + atomic_inc_unchecked(&sk->sk_drops);
77380 }
77381
77382 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77383 @@ -2022,7 +2022,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
77384 sk_wmem_alloc_get(s),
77385 nlk->cb,
77386 atomic_read(&s->sk_refcnt),
77387 - atomic_read(&s->sk_drops),
77388 + atomic_read_unchecked(&s->sk_drops),
77389 sock_i_ino(s)
77390 );
77391
77392 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
77393 index 06592d8..64860f6 100644
77394 --- a/net/netrom/af_netrom.c
77395 +++ b/net/netrom/af_netrom.c
77396 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77397 struct sock *sk = sock->sk;
77398 struct nr_sock *nr = nr_sk(sk);
77399
77400 + memset(sax, 0, sizeof(*sax));
77401 lock_sock(sk);
77402 if (peer != 0) {
77403 if (sk->sk_state != TCP_ESTABLISHED) {
77404 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
77405 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77406 } else {
77407 sax->fsa_ax25.sax25_family = AF_NETROM;
77408 - sax->fsa_ax25.sax25_ndigis = 0;
77409 sax->fsa_ax25.sax25_call = nr->source_addr;
77410 *uaddr_len = sizeof(struct sockaddr_ax25);
77411 }
77412 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
77413 index 0f66174..2f50376 100644
77414 --- a/net/packet/af_packet.c
77415 +++ b/net/packet/af_packet.c
77416 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77417
77418 spin_lock(&sk->sk_receive_queue.lock);
77419 po->stats.tp_packets++;
77420 - skb->dropcount = atomic_read(&sk->sk_drops);
77421 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77422 __skb_queue_tail(&sk->sk_receive_queue, skb);
77423 spin_unlock(&sk->sk_receive_queue.lock);
77424 sk->sk_data_ready(sk, skb->len);
77425 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
77426 drop_n_acct:
77427 spin_lock(&sk->sk_receive_queue.lock);
77428 po->stats.tp_drops++;
77429 - atomic_inc(&sk->sk_drops);
77430 + atomic_inc_unchecked(&sk->sk_drops);
77431 spin_unlock(&sk->sk_receive_queue.lock);
77432
77433 drop_n_restore:
77434 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77435 case PACKET_HDRLEN:
77436 if (len > sizeof(int))
77437 len = sizeof(int);
77438 - if (copy_from_user(&val, optval, len))
77439 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77440 return -EFAULT;
77441 switch (val) {
77442 case TPACKET_V1:
77443 @@ -3314,7 +3314,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
77444 len = lv;
77445 if (put_user(len, optlen))
77446 return -EFAULT;
77447 - if (copy_to_user(optval, data, len))
77448 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77449 return -EFAULT;
77450 return 0;
77451 }
77452 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
77453 index 5a940db..f0b9c12 100644
77454 --- a/net/phonet/af_phonet.c
77455 +++ b/net/phonet/af_phonet.c
77456 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
77457 {
77458 struct phonet_protocol *pp;
77459
77460 - if (protocol >= PHONET_NPROTO)
77461 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77462 return NULL;
77463
77464 rcu_read_lock();
77465 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
77466 {
77467 int err = 0;
77468
77469 - if (protocol >= PHONET_NPROTO)
77470 + if (protocol < 0 || protocol >= PHONET_NPROTO)
77471 return -EINVAL;
77472
77473 err = proto_register(pp->prot, 1);
77474 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
77475 index 576f22c..bc7a71b 100644
77476 --- a/net/phonet/pep.c
77477 +++ b/net/phonet/pep.c
77478 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77479
77480 case PNS_PEP_CTRL_REQ:
77481 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
77482 - atomic_inc(&sk->sk_drops);
77483 + atomic_inc_unchecked(&sk->sk_drops);
77484 break;
77485 }
77486 __skb_pull(skb, 4);
77487 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77488 }
77489
77490 if (pn->rx_credits == 0) {
77491 - atomic_inc(&sk->sk_drops);
77492 + atomic_inc_unchecked(&sk->sk_drops);
77493 err = -ENOBUFS;
77494 break;
77495 }
77496 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77497 }
77498
77499 if (pn->rx_credits == 0) {
77500 - atomic_inc(&sk->sk_drops);
77501 + atomic_inc_unchecked(&sk->sk_drops);
77502 err = NET_RX_DROP;
77503 break;
77504 }
77505 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77506 index 0acc943..c727611 100644
77507 --- a/net/phonet/socket.c
77508 +++ b/net/phonet/socket.c
77509 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77510 pn->resource, sk->sk_state,
77511 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77512 sock_i_uid(sk), sock_i_ino(sk),
77513 - atomic_read(&sk->sk_refcnt), sk,
77514 - atomic_read(&sk->sk_drops), &len);
77515 + atomic_read(&sk->sk_refcnt),
77516 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77517 + NULL,
77518 +#else
77519 + sk,
77520 +#endif
77521 + atomic_read_unchecked(&sk->sk_drops), &len);
77522 }
77523 seq_printf(seq, "%*s\n", 127 - len, "");
77524 return 0;
77525 diff --git a/net/rds/cong.c b/net/rds/cong.c
77526 index e5b65ac..f3b6fb7 100644
77527 --- a/net/rds/cong.c
77528 +++ b/net/rds/cong.c
77529 @@ -78,7 +78,7 @@
77530 * finds that the saved generation number is smaller than the global generation
77531 * number, it wakes up the process.
77532 */
77533 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77534 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77535
77536 /*
77537 * Congestion monitoring
77538 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77539 rdsdebug("waking map %p for %pI4\n",
77540 map, &map->m_addr);
77541 rds_stats_inc(s_cong_update_received);
77542 - atomic_inc(&rds_cong_generation);
77543 + atomic_inc_unchecked(&rds_cong_generation);
77544 if (waitqueue_active(&map->m_waitq))
77545 wake_up(&map->m_waitq);
77546 if (waitqueue_active(&rds_poll_waitq))
77547 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77548
77549 int rds_cong_updated_since(unsigned long *recent)
77550 {
77551 - unsigned long gen = atomic_read(&rds_cong_generation);
77552 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77553
77554 if (likely(*recent == gen))
77555 return 0;
77556 diff --git a/net/rds/ib.h b/net/rds/ib.h
77557 index 8d2b3d5..227ec5b 100644
77558 --- a/net/rds/ib.h
77559 +++ b/net/rds/ib.h
77560 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77561 /* sending acks */
77562 unsigned long i_ack_flags;
77563 #ifdef KERNEL_HAS_ATOMIC64
77564 - atomic64_t i_ack_next; /* next ACK to send */
77565 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77566 #else
77567 spinlock_t i_ack_lock; /* protect i_ack_next */
77568 u64 i_ack_next; /* next ACK to send */
77569 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77570 index a1e1162..265e129 100644
77571 --- a/net/rds/ib_cm.c
77572 +++ b/net/rds/ib_cm.c
77573 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77574 /* Clear the ACK state */
77575 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77576 #ifdef KERNEL_HAS_ATOMIC64
77577 - atomic64_set(&ic->i_ack_next, 0);
77578 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77579 #else
77580 ic->i_ack_next = 0;
77581 #endif
77582 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77583 index 8d19491..05a3e65 100644
77584 --- a/net/rds/ib_recv.c
77585 +++ b/net/rds/ib_recv.c
77586 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77587 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77588 int ack_required)
77589 {
77590 - atomic64_set(&ic->i_ack_next, seq);
77591 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77592 if (ack_required) {
77593 smp_mb__before_clear_bit();
77594 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77595 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77596 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77597 smp_mb__after_clear_bit();
77598
77599 - return atomic64_read(&ic->i_ack_next);
77600 + return atomic64_read_unchecked(&ic->i_ack_next);
77601 }
77602 #endif
77603
77604 diff --git a/net/rds/iw.h b/net/rds/iw.h
77605 index 04ce3b1..48119a6 100644
77606 --- a/net/rds/iw.h
77607 +++ b/net/rds/iw.h
77608 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77609 /* sending acks */
77610 unsigned long i_ack_flags;
77611 #ifdef KERNEL_HAS_ATOMIC64
77612 - atomic64_t i_ack_next; /* next ACK to send */
77613 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77614 #else
77615 spinlock_t i_ack_lock; /* protect i_ack_next */
77616 u64 i_ack_next; /* next ACK to send */
77617 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77618 index a91e1db..cf3053f 100644
77619 --- a/net/rds/iw_cm.c
77620 +++ b/net/rds/iw_cm.c
77621 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77622 /* Clear the ACK state */
77623 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77624 #ifdef KERNEL_HAS_ATOMIC64
77625 - atomic64_set(&ic->i_ack_next, 0);
77626 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77627 #else
77628 ic->i_ack_next = 0;
77629 #endif
77630 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77631 index 4503335..db566b4 100644
77632 --- a/net/rds/iw_recv.c
77633 +++ b/net/rds/iw_recv.c
77634 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77635 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77636 int ack_required)
77637 {
77638 - atomic64_set(&ic->i_ack_next, seq);
77639 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77640 if (ack_required) {
77641 smp_mb__before_clear_bit();
77642 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77643 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77644 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77645 smp_mb__after_clear_bit();
77646
77647 - return atomic64_read(&ic->i_ack_next);
77648 + return atomic64_read_unchecked(&ic->i_ack_next);
77649 }
77650 #endif
77651
77652 diff --git a/net/rds/recv.c b/net/rds/recv.c
77653 index 5c6e9f1..9f0f17c 100644
77654 --- a/net/rds/recv.c
77655 +++ b/net/rds/recv.c
77656 @@ -410,6 +410,8 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
77657
77658 rdsdebug("size %zu flags 0x%x timeo %ld\n", size, msg_flags, timeo);
77659
77660 + msg->msg_namelen = 0;
77661 +
77662 if (msg_flags & MSG_OOB)
77663 goto out;
77664
77665 @@ -485,6 +487,7 @@ int rds_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
77666 sin->sin_port = inc->i_hdr.h_sport;
77667 sin->sin_addr.s_addr = inc->i_saddr;
77668 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
77669 + msg->msg_namelen = sizeof(*sin);
77670 }
77671 break;
77672 }
77673 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77674 index edac9ef..16bcb98 100644
77675 --- a/net/rds/tcp.c
77676 +++ b/net/rds/tcp.c
77677 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77678 int val = 1;
77679
77680 set_fs(KERNEL_DS);
77681 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77682 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77683 sizeof(val));
77684 set_fs(oldfs);
77685 }
77686 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77687 index 1b4fd68..2234175 100644
77688 --- a/net/rds/tcp_send.c
77689 +++ b/net/rds/tcp_send.c
77690 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77691
77692 oldfs = get_fs();
77693 set_fs(KERNEL_DS);
77694 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77695 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77696 sizeof(val));
77697 set_fs(oldfs);
77698 }
77699 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77700 index 05996d0..5a1dfe0 100644
77701 --- a/net/rxrpc/af_rxrpc.c
77702 +++ b/net/rxrpc/af_rxrpc.c
77703 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77704 __be32 rxrpc_epoch;
77705
77706 /* current debugging ID */
77707 -atomic_t rxrpc_debug_id;
77708 +atomic_unchecked_t rxrpc_debug_id;
77709
77710 /* count of skbs currently in use */
77711 atomic_t rxrpc_n_skbs;
77712 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77713 index e4d9cbc..b229649 100644
77714 --- a/net/rxrpc/ar-ack.c
77715 +++ b/net/rxrpc/ar-ack.c
77716 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77717
77718 _enter("{%d,%d,%d,%d},",
77719 call->acks_hard, call->acks_unacked,
77720 - atomic_read(&call->sequence),
77721 + atomic_read_unchecked(&call->sequence),
77722 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77723
77724 stop = 0;
77725 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77726
77727 /* each Tx packet has a new serial number */
77728 sp->hdr.serial =
77729 - htonl(atomic_inc_return(&call->conn->serial));
77730 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77731
77732 hdr = (struct rxrpc_header *) txb->head;
77733 hdr->serial = sp->hdr.serial;
77734 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77735 */
77736 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77737 {
77738 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77739 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77740 }
77741
77742 /*
77743 @@ -629,7 +629,7 @@ process_further:
77744
77745 latest = ntohl(sp->hdr.serial);
77746 hard = ntohl(ack.firstPacket);
77747 - tx = atomic_read(&call->sequence);
77748 + tx = atomic_read_unchecked(&call->sequence);
77749
77750 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77751 latest,
77752 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77753 goto maybe_reschedule;
77754
77755 send_ACK_with_skew:
77756 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77757 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77758 ntohl(ack.serial));
77759 send_ACK:
77760 mtu = call->conn->trans->peer->if_mtu;
77761 @@ -1173,7 +1173,7 @@ send_ACK:
77762 ackinfo.rxMTU = htonl(5692);
77763 ackinfo.jumbo_max = htonl(4);
77764
77765 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77766 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77767 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77768 ntohl(hdr.serial),
77769 ntohs(ack.maxSkew),
77770 @@ -1191,7 +1191,7 @@ send_ACK:
77771 send_message:
77772 _debug("send message");
77773
77774 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77775 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77776 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77777 send_message_2:
77778
77779 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77780 index a3bbb36..3341fb9 100644
77781 --- a/net/rxrpc/ar-call.c
77782 +++ b/net/rxrpc/ar-call.c
77783 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77784 spin_lock_init(&call->lock);
77785 rwlock_init(&call->state_lock);
77786 atomic_set(&call->usage, 1);
77787 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77788 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77789 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77790
77791 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77792 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77793 index 4106ca9..a338d7a 100644
77794 --- a/net/rxrpc/ar-connection.c
77795 +++ b/net/rxrpc/ar-connection.c
77796 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77797 rwlock_init(&conn->lock);
77798 spin_lock_init(&conn->state_lock);
77799 atomic_set(&conn->usage, 1);
77800 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77801 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77802 conn->avail_calls = RXRPC_MAXCALLS;
77803 conn->size_align = 4;
77804 conn->header_size = sizeof(struct rxrpc_header);
77805 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77806 index e7ed43a..6afa140 100644
77807 --- a/net/rxrpc/ar-connevent.c
77808 +++ b/net/rxrpc/ar-connevent.c
77809 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77810
77811 len = iov[0].iov_len + iov[1].iov_len;
77812
77813 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77814 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77815 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77816
77817 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77818 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77819 index 529572f..c758ca7 100644
77820 --- a/net/rxrpc/ar-input.c
77821 +++ b/net/rxrpc/ar-input.c
77822 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77823 /* track the latest serial number on this connection for ACK packet
77824 * information */
77825 serial = ntohl(sp->hdr.serial);
77826 - hi_serial = atomic_read(&call->conn->hi_serial);
77827 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77828 while (serial > hi_serial)
77829 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77830 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77831 serial);
77832
77833 /* request ACK generation for any ACK or DATA packet that requests
77834 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77835 index a693aca..81e7293 100644
77836 --- a/net/rxrpc/ar-internal.h
77837 +++ b/net/rxrpc/ar-internal.h
77838 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77839 int error; /* error code for local abort */
77840 int debug_id; /* debug ID for printks */
77841 unsigned int call_counter; /* call ID counter */
77842 - atomic_t serial; /* packet serial number counter */
77843 - atomic_t hi_serial; /* highest serial number received */
77844 + atomic_unchecked_t serial; /* packet serial number counter */
77845 + atomic_unchecked_t hi_serial; /* highest serial number received */
77846 u8 avail_calls; /* number of calls available */
77847 u8 size_align; /* data size alignment (for security) */
77848 u8 header_size; /* rxrpc + security header size */
77849 @@ -346,7 +346,7 @@ struct rxrpc_call {
77850 spinlock_t lock;
77851 rwlock_t state_lock; /* lock for state transition */
77852 atomic_t usage;
77853 - atomic_t sequence; /* Tx data packet sequence counter */
77854 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77855 u32 abort_code; /* local/remote abort code */
77856 enum { /* current state of call */
77857 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77858 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77859 */
77860 extern atomic_t rxrpc_n_skbs;
77861 extern __be32 rxrpc_epoch;
77862 -extern atomic_t rxrpc_debug_id;
77863 +extern atomic_unchecked_t rxrpc_debug_id;
77864 extern struct workqueue_struct *rxrpc_workqueue;
77865
77866 /*
77867 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77868 index 87f7135..74d3703 100644
77869 --- a/net/rxrpc/ar-local.c
77870 +++ b/net/rxrpc/ar-local.c
77871 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77872 spin_lock_init(&local->lock);
77873 rwlock_init(&local->services_lock);
77874 atomic_set(&local->usage, 1);
77875 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77876 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77877 memcpy(&local->srx, srx, sizeof(*srx));
77878 }
77879
77880 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77881 index 16ae887..d24f12b 100644
77882 --- a/net/rxrpc/ar-output.c
77883 +++ b/net/rxrpc/ar-output.c
77884 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77885 sp->hdr.cid = call->cid;
77886 sp->hdr.callNumber = call->call_id;
77887 sp->hdr.seq =
77888 - htonl(atomic_inc_return(&call->sequence));
77889 + htonl(atomic_inc_return_unchecked(&call->sequence));
77890 sp->hdr.serial =
77891 - htonl(atomic_inc_return(&conn->serial));
77892 + htonl(atomic_inc_return_unchecked(&conn->serial));
77893 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77894 sp->hdr.userStatus = 0;
77895 sp->hdr.securityIndex = conn->security_ix;
77896 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77897 index bebaa43..2644591 100644
77898 --- a/net/rxrpc/ar-peer.c
77899 +++ b/net/rxrpc/ar-peer.c
77900 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77901 INIT_LIST_HEAD(&peer->error_targets);
77902 spin_lock_init(&peer->lock);
77903 atomic_set(&peer->usage, 1);
77904 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77905 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77906 memcpy(&peer->srx, srx, sizeof(*srx));
77907
77908 rxrpc_assess_MTU_size(peer);
77909 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77910 index 38047f7..9f48511 100644
77911 --- a/net/rxrpc/ar-proc.c
77912 +++ b/net/rxrpc/ar-proc.c
77913 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77914 atomic_read(&conn->usage),
77915 rxrpc_conn_states[conn->state],
77916 key_serial(conn->key),
77917 - atomic_read(&conn->serial),
77918 - atomic_read(&conn->hi_serial));
77919 + atomic_read_unchecked(&conn->serial),
77920 + atomic_read_unchecked(&conn->hi_serial));
77921
77922 return 0;
77923 }
77924 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77925 index 92df566..87ec1bf 100644
77926 --- a/net/rxrpc/ar-transport.c
77927 +++ b/net/rxrpc/ar-transport.c
77928 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77929 spin_lock_init(&trans->client_lock);
77930 rwlock_init(&trans->conn_lock);
77931 atomic_set(&trans->usage, 1);
77932 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77933 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77934
77935 if (peer->srx.transport.family == AF_INET) {
77936 switch (peer->srx.transport_type) {
77937 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77938 index f226709..0e735a8 100644
77939 --- a/net/rxrpc/rxkad.c
77940 +++ b/net/rxrpc/rxkad.c
77941 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77942
77943 len = iov[0].iov_len + iov[1].iov_len;
77944
77945 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77946 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77947 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77948
77949 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77950 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77951
77952 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77953
77954 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77955 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77956 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77957
77958 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77959 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77960 index 1e2eee8..ce3967e 100644
77961 --- a/net/sctp/proc.c
77962 +++ b/net/sctp/proc.c
77963 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77964 seq_printf(seq,
77965 "%8pK %8pK %-3d %-3d %-2d %-4d "
77966 "%4d %8d %8d %7d %5lu %-5d %5d ",
77967 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77968 + assoc, sk,
77969 + sctp_sk(sk)->type, sk->sk_state,
77970 assoc->state, hash,
77971 assoc->assoc_id,
77972 assoc->sndbuf_used,
77973 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77974 index 31c7bfc..bc380ae 100644
77975 --- a/net/sctp/socket.c
77976 +++ b/net/sctp/socket.c
77977 @@ -4577,7 +4577,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77978 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77979 if (space_left < addrlen)
77980 return -ENOMEM;
77981 - if (copy_to_user(to, &temp, addrlen))
77982 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77983 return -EFAULT;
77984 to += addrlen;
77985 cnt++;
77986 diff --git a/net/socket.c b/net/socket.c
77987 index 6e0ccc0..e3387a27 100644
77988 --- a/net/socket.c
77989 +++ b/net/socket.c
77990 @@ -88,6 +88,7 @@
77991 #include <linux/nsproxy.h>
77992 #include <linux/magic.h>
77993 #include <linux/slab.h>
77994 +#include <linux/in.h>
77995
77996 #include <asm/uaccess.h>
77997 #include <asm/unistd.h>
77998 @@ -105,6 +106,8 @@
77999 #include <linux/sockios.h>
78000 #include <linux/atalk.h>
78001
78002 +#include <linux/grsock.h>
78003 +
78004 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78005 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78006 unsigned long nr_segs, loff_t pos);
78007 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78008 &sockfs_dentry_operations, SOCKFS_MAGIC);
78009 }
78010
78011 -static struct vfsmount *sock_mnt __read_mostly;
78012 +struct vfsmount *sock_mnt __read_mostly;
78013
78014 static struct file_system_type sock_fs_type = {
78015 .name = "sockfs",
78016 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78017 return -EAFNOSUPPORT;
78018 if (type < 0 || type >= SOCK_MAX)
78019 return -EINVAL;
78020 + if (protocol < 0)
78021 + return -EINVAL;
78022
78023 /* Compatibility.
78024
78025 @@ -1338,6 +1343,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78026 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78027 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78028
78029 + if(!gr_search_socket(family, type, protocol)) {
78030 + retval = -EACCES;
78031 + goto out;
78032 + }
78033 +
78034 + if (gr_handle_sock_all(family, type, protocol)) {
78035 + retval = -EACCES;
78036 + goto out;
78037 + }
78038 +
78039 retval = sock_create(family, type, protocol, &sock);
78040 if (retval < 0)
78041 goto out;
78042 @@ -1450,6 +1465,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78043 if (sock) {
78044 err = move_addr_to_kernel(umyaddr, addrlen, &address);
78045 if (err >= 0) {
78046 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78047 + err = -EACCES;
78048 + goto error;
78049 + }
78050 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78051 + if (err)
78052 + goto error;
78053 +
78054 err = security_socket_bind(sock,
78055 (struct sockaddr *)&address,
78056 addrlen);
78057 @@ -1458,6 +1481,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78058 (struct sockaddr *)
78059 &address, addrlen);
78060 }
78061 +error:
78062 fput_light(sock->file, fput_needed);
78063 }
78064 return err;
78065 @@ -1481,10 +1505,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78066 if ((unsigned int)backlog > somaxconn)
78067 backlog = somaxconn;
78068
78069 + if (gr_handle_sock_server_other(sock->sk)) {
78070 + err = -EPERM;
78071 + goto error;
78072 + }
78073 +
78074 + err = gr_search_listen(sock);
78075 + if (err)
78076 + goto error;
78077 +
78078 err = security_socket_listen(sock, backlog);
78079 if (!err)
78080 err = sock->ops->listen(sock, backlog);
78081
78082 +error:
78083 fput_light(sock->file, fput_needed);
78084 }
78085 return err;
78086 @@ -1528,6 +1562,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78087 newsock->type = sock->type;
78088 newsock->ops = sock->ops;
78089
78090 + if (gr_handle_sock_server_other(sock->sk)) {
78091 + err = -EPERM;
78092 + sock_release(newsock);
78093 + goto out_put;
78094 + }
78095 +
78096 + err = gr_search_accept(sock);
78097 + if (err) {
78098 + sock_release(newsock);
78099 + goto out_put;
78100 + }
78101 +
78102 /*
78103 * We don't need try_module_get here, as the listening socket (sock)
78104 * has the protocol module (sock->ops->owner) held.
78105 @@ -1566,6 +1612,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78106 fd_install(newfd, newfile);
78107 err = newfd;
78108
78109 + gr_attach_curr_ip(newsock->sk);
78110 +
78111 out_put:
78112 fput_light(sock->file, fput_needed);
78113 out:
78114 @@ -1598,6 +1646,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78115 int, addrlen)
78116 {
78117 struct socket *sock;
78118 + struct sockaddr *sck;
78119 struct sockaddr_storage address;
78120 int err, fput_needed;
78121
78122 @@ -1608,6 +1657,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78123 if (err < 0)
78124 goto out_put;
78125
78126 + sck = (struct sockaddr *)&address;
78127 +
78128 + if (gr_handle_sock_client(sck)) {
78129 + err = -EACCES;
78130 + goto out_put;
78131 + }
78132 +
78133 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78134 + if (err)
78135 + goto out_put;
78136 +
78137 err =
78138 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78139 if (err)
78140 @@ -1962,7 +2022,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78141 * checking falls down on this.
78142 */
78143 if (copy_from_user(ctl_buf,
78144 - (void __user __force *)msg_sys->msg_control,
78145 + (void __force_user *)msg_sys->msg_control,
78146 ctl_len))
78147 goto out_freectl;
78148 msg_sys->msg_control = ctl_buf;
78149 @@ -2130,7 +2190,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78150 * kernel msghdr to use the kernel address space)
78151 */
78152
78153 - uaddr = (__force void __user *)msg_sys->msg_name;
78154 + uaddr = (void __force_user *)msg_sys->msg_name;
78155 uaddr_len = COMPAT_NAMELEN(msg);
78156 if (MSG_CMSG_COMPAT & flags) {
78157 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
78158 @@ -2758,7 +2818,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78159 }
78160
78161 ifr = compat_alloc_user_space(buf_size);
78162 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78163 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78164
78165 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78166 return -EFAULT;
78167 @@ -2782,12 +2842,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78168 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78169
78170 if (copy_in_user(rxnfc, compat_rxnfc,
78171 - (void *)(&rxnfc->fs.m_ext + 1) -
78172 - (void *)rxnfc) ||
78173 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78174 + (void __user *)rxnfc) ||
78175 copy_in_user(&rxnfc->fs.ring_cookie,
78176 &compat_rxnfc->fs.ring_cookie,
78177 - (void *)(&rxnfc->fs.location + 1) -
78178 - (void *)&rxnfc->fs.ring_cookie) ||
78179 + (void __user *)(&rxnfc->fs.location + 1) -
78180 + (void __user *)&rxnfc->fs.ring_cookie) ||
78181 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78182 sizeof(rxnfc->rule_cnt)))
78183 return -EFAULT;
78184 @@ -2799,12 +2859,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78185
78186 if (convert_out) {
78187 if (copy_in_user(compat_rxnfc, rxnfc,
78188 - (const void *)(&rxnfc->fs.m_ext + 1) -
78189 - (const void *)rxnfc) ||
78190 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78191 + (const void __user *)rxnfc) ||
78192 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78193 &rxnfc->fs.ring_cookie,
78194 - (const void *)(&rxnfc->fs.location + 1) -
78195 - (const void *)&rxnfc->fs.ring_cookie) ||
78196 + (const void __user *)(&rxnfc->fs.location + 1) -
78197 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78198 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78199 sizeof(rxnfc->rule_cnt)))
78200 return -EFAULT;
78201 @@ -2874,7 +2934,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78202 old_fs = get_fs();
78203 set_fs(KERNEL_DS);
78204 err = dev_ioctl(net, cmd,
78205 - (struct ifreq __user __force *) &kifr);
78206 + (struct ifreq __force_user *) &kifr);
78207 set_fs(old_fs);
78208
78209 return err;
78210 @@ -2983,7 +3043,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78211
78212 old_fs = get_fs();
78213 set_fs(KERNEL_DS);
78214 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78215 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78216 set_fs(old_fs);
78217
78218 if (cmd == SIOCGIFMAP && !err) {
78219 @@ -3088,7 +3148,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
78220 ret |= __get_user(rtdev, &(ur4->rt_dev));
78221 if (rtdev) {
78222 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
78223 - r4.rt_dev = (char __user __force *)devname;
78224 + r4.rt_dev = (char __force_user *)devname;
78225 devname[15] = 0;
78226 } else
78227 r4.rt_dev = NULL;
78228 @@ -3314,8 +3374,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
78229 int __user *uoptlen;
78230 int err;
78231
78232 - uoptval = (char __user __force *) optval;
78233 - uoptlen = (int __user __force *) optlen;
78234 + uoptval = (char __force_user *) optval;
78235 + uoptlen = (int __force_user *) optlen;
78236
78237 set_fs(KERNEL_DS);
78238 if (level == SOL_SOCKET)
78239 @@ -3335,7 +3395,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
78240 char __user *uoptval;
78241 int err;
78242
78243 - uoptval = (char __user __force *) optval;
78244 + uoptval = (char __force_user *) optval;
78245
78246 set_fs(KERNEL_DS);
78247 if (level == SOL_SOCKET)
78248 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
78249 index 994cfea..5343b6b 100644
78250 --- a/net/sunrpc/sched.c
78251 +++ b/net/sunrpc/sched.c
78252 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
78253 #ifdef RPC_DEBUG
78254 static void rpc_task_set_debuginfo(struct rpc_task *task)
78255 {
78256 - static atomic_t rpc_pid;
78257 + static atomic_unchecked_t rpc_pid;
78258
78259 - task->tk_pid = atomic_inc_return(&rpc_pid);
78260 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78261 }
78262 #else
78263 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78264 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
78265 index 8343737..677025e 100644
78266 --- a/net/sunrpc/xprtrdma/svc_rdma.c
78267 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
78268 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
78269 static unsigned int min_max_inline = 4096;
78270 static unsigned int max_max_inline = 65536;
78271
78272 -atomic_t rdma_stat_recv;
78273 -atomic_t rdma_stat_read;
78274 -atomic_t rdma_stat_write;
78275 -atomic_t rdma_stat_sq_starve;
78276 -atomic_t rdma_stat_rq_starve;
78277 -atomic_t rdma_stat_rq_poll;
78278 -atomic_t rdma_stat_rq_prod;
78279 -atomic_t rdma_stat_sq_poll;
78280 -atomic_t rdma_stat_sq_prod;
78281 +atomic_unchecked_t rdma_stat_recv;
78282 +atomic_unchecked_t rdma_stat_read;
78283 +atomic_unchecked_t rdma_stat_write;
78284 +atomic_unchecked_t rdma_stat_sq_starve;
78285 +atomic_unchecked_t rdma_stat_rq_starve;
78286 +atomic_unchecked_t rdma_stat_rq_poll;
78287 +atomic_unchecked_t rdma_stat_rq_prod;
78288 +atomic_unchecked_t rdma_stat_sq_poll;
78289 +atomic_unchecked_t rdma_stat_sq_prod;
78290
78291 /* Temporary NFS request map and context caches */
78292 struct kmem_cache *svc_rdma_map_cachep;
78293 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
78294 len -= *ppos;
78295 if (len > *lenp)
78296 len = *lenp;
78297 - if (len && copy_to_user(buffer, str_buf, len))
78298 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78299 return -EFAULT;
78300 *lenp = len;
78301 *ppos += len;
78302 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
78303 {
78304 .procname = "rdma_stat_read",
78305 .data = &rdma_stat_read,
78306 - .maxlen = sizeof(atomic_t),
78307 + .maxlen = sizeof(atomic_unchecked_t),
78308 .mode = 0644,
78309 .proc_handler = read_reset_stat,
78310 },
78311 {
78312 .procname = "rdma_stat_recv",
78313 .data = &rdma_stat_recv,
78314 - .maxlen = sizeof(atomic_t),
78315 + .maxlen = sizeof(atomic_unchecked_t),
78316 .mode = 0644,
78317 .proc_handler = read_reset_stat,
78318 },
78319 {
78320 .procname = "rdma_stat_write",
78321 .data = &rdma_stat_write,
78322 - .maxlen = sizeof(atomic_t),
78323 + .maxlen = sizeof(atomic_unchecked_t),
78324 .mode = 0644,
78325 .proc_handler = read_reset_stat,
78326 },
78327 {
78328 .procname = "rdma_stat_sq_starve",
78329 .data = &rdma_stat_sq_starve,
78330 - .maxlen = sizeof(atomic_t),
78331 + .maxlen = sizeof(atomic_unchecked_t),
78332 .mode = 0644,
78333 .proc_handler = read_reset_stat,
78334 },
78335 {
78336 .procname = "rdma_stat_rq_starve",
78337 .data = &rdma_stat_rq_starve,
78338 - .maxlen = sizeof(atomic_t),
78339 + .maxlen = sizeof(atomic_unchecked_t),
78340 .mode = 0644,
78341 .proc_handler = read_reset_stat,
78342 },
78343 {
78344 .procname = "rdma_stat_rq_poll",
78345 .data = &rdma_stat_rq_poll,
78346 - .maxlen = sizeof(atomic_t),
78347 + .maxlen = sizeof(atomic_unchecked_t),
78348 .mode = 0644,
78349 .proc_handler = read_reset_stat,
78350 },
78351 {
78352 .procname = "rdma_stat_rq_prod",
78353 .data = &rdma_stat_rq_prod,
78354 - .maxlen = sizeof(atomic_t),
78355 + .maxlen = sizeof(atomic_unchecked_t),
78356 .mode = 0644,
78357 .proc_handler = read_reset_stat,
78358 },
78359 {
78360 .procname = "rdma_stat_sq_poll",
78361 .data = &rdma_stat_sq_poll,
78362 - .maxlen = sizeof(atomic_t),
78363 + .maxlen = sizeof(atomic_unchecked_t),
78364 .mode = 0644,
78365 .proc_handler = read_reset_stat,
78366 },
78367 {
78368 .procname = "rdma_stat_sq_prod",
78369 .data = &rdma_stat_sq_prod,
78370 - .maxlen = sizeof(atomic_t),
78371 + .maxlen = sizeof(atomic_unchecked_t),
78372 .mode = 0644,
78373 .proc_handler = read_reset_stat,
78374 },
78375 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78376 index 41cb63b..c4a1489 100644
78377 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78378 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78379 @@ -501,7 +501,7 @@ next_sge:
78380 svc_rdma_put_context(ctxt, 0);
78381 goto out;
78382 }
78383 - atomic_inc(&rdma_stat_read);
78384 + atomic_inc_unchecked(&rdma_stat_read);
78385
78386 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78387 chl_map->ch[ch_no].count -= read_wr.num_sge;
78388 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78389 dto_q);
78390 list_del_init(&ctxt->dto_q);
78391 } else {
78392 - atomic_inc(&rdma_stat_rq_starve);
78393 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78394 clear_bit(XPT_DATA, &xprt->xpt_flags);
78395 ctxt = NULL;
78396 }
78397 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
78398 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78399 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78400 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78401 - atomic_inc(&rdma_stat_recv);
78402 + atomic_inc_unchecked(&rdma_stat_recv);
78403
78404 /* Build up the XDR from the receive buffers. */
78405 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78406 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78407 index 42eb7ba..c887c45 100644
78408 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78409 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78410 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
78411 write_wr.wr.rdma.remote_addr = to;
78412
78413 /* Post It */
78414 - atomic_inc(&rdma_stat_write);
78415 + atomic_inc_unchecked(&rdma_stat_write);
78416 if (svc_rdma_send(xprt, &write_wr))
78417 goto err;
78418 return 0;
78419 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78420 index 73b428b..5f3f8f3 100644
78421 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
78422 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
78423 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78424 return;
78425
78426 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78427 - atomic_inc(&rdma_stat_rq_poll);
78428 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78429
78430 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78431 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78432 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
78433 }
78434
78435 if (ctxt)
78436 - atomic_inc(&rdma_stat_rq_prod);
78437 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78438
78439 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78440 /*
78441 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78442 return;
78443
78444 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78445 - atomic_inc(&rdma_stat_sq_poll);
78446 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78447 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78448 if (wc.status != IB_WC_SUCCESS)
78449 /* Close the transport */
78450 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
78451 }
78452
78453 if (ctxt)
78454 - atomic_inc(&rdma_stat_sq_prod);
78455 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78456 }
78457
78458 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78459 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
78460 spin_lock_bh(&xprt->sc_lock);
78461 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78462 spin_unlock_bh(&xprt->sc_lock);
78463 - atomic_inc(&rdma_stat_sq_starve);
78464 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78465
78466 /* See if we can opportunistically reap SQ WR to make room */
78467 sq_cq_reap(xprt);
78468 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
78469 index e3a6e37..be2ea77 100644
78470 --- a/net/sysctl_net.c
78471 +++ b/net/sysctl_net.c
78472 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
78473 struct ctl_table *table)
78474 {
78475 /* Allow network administrator to have same access as root. */
78476 - if (capable(CAP_NET_ADMIN)) {
78477 + if (capable_nolog(CAP_NET_ADMIN)) {
78478 int mode = (table->mode >> 6) & 7;
78479 return (mode << 6) | (mode << 3) | mode;
78480 }
78481 diff --git a/net/tipc/link.c b/net/tipc/link.c
78482 index 7a614f4..b14dbd2 100644
78483 --- a/net/tipc/link.c
78484 +++ b/net/tipc/link.c
78485 @@ -1164,7 +1164,7 @@ static int link_send_sections_long(struct tipc_port *sender,
78486 struct tipc_msg fragm_hdr;
78487 struct sk_buff *buf, *buf_chain, *prev;
78488 u32 fragm_crs, fragm_rest, hsz, sect_rest;
78489 - const unchar *sect_crs;
78490 + const unchar __user *sect_crs;
78491 int curr_sect;
78492 u32 fragm_no;
78493
78494 @@ -1205,7 +1205,7 @@ again:
78495
78496 if (!sect_rest) {
78497 sect_rest = msg_sect[++curr_sect].iov_len;
78498 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78499 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78500 }
78501
78502 if (sect_rest < fragm_rest)
78503 @@ -1224,7 +1224,7 @@ error:
78504 }
78505 } else
78506 skb_copy_to_linear_data_offset(buf, fragm_crs,
78507 - sect_crs, sz);
78508 + (const void __force_kernel *)sect_crs, sz);
78509 sect_crs += sz;
78510 sect_rest -= sz;
78511 fragm_crs += sz;
78512 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78513 index deea0d2..fa13bd7 100644
78514 --- a/net/tipc/msg.c
78515 +++ b/net/tipc/msg.c
78516 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78517 msg_sect[cnt].iov_len);
78518 else
78519 skb_copy_to_linear_data_offset(*buf, pos,
78520 - msg_sect[cnt].iov_base,
78521 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78522 msg_sect[cnt].iov_len);
78523 pos += msg_sect[cnt].iov_len;
78524 }
78525 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78526 index f976e9cd..560d055 100644
78527 --- a/net/tipc/subscr.c
78528 +++ b/net/tipc/subscr.c
78529 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78530 {
78531 struct iovec msg_sect;
78532
78533 - msg_sect.iov_base = (void *)&sub->evt;
78534 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78535 msg_sect.iov_len = sizeof(struct tipc_event);
78536
78537 sub->evt.event = htohl(event, sub->swap);
78538 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78539 index 641f2e4..a63f5e1 100644
78540 --- a/net/unix/af_unix.c
78541 +++ b/net/unix/af_unix.c
78542 @@ -780,6 +780,12 @@ static struct sock *unix_find_other(struct net *net,
78543 err = -ECONNREFUSED;
78544 if (!S_ISSOCK(inode->i_mode))
78545 goto put_fail;
78546 +
78547 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78548 + err = -EACCES;
78549 + goto put_fail;
78550 + }
78551 +
78552 u = unix_find_socket_byinode(inode);
78553 if (!u)
78554 goto put_fail;
78555 @@ -800,6 +806,13 @@ static struct sock *unix_find_other(struct net *net,
78556 if (u) {
78557 struct dentry *dentry;
78558 dentry = unix_sk(u)->path.dentry;
78559 +
78560 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78561 + err = -EPERM;
78562 + sock_put(u);
78563 + goto fail;
78564 + }
78565 +
78566 if (dentry)
78567 touch_atime(&unix_sk(u)->path);
78568 } else
78569 @@ -882,11 +895,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78570 err = security_path_mknod(&path, dentry, mode, 0);
78571 if (err)
78572 goto out_mknod_drop_write;
78573 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78574 + err = -EACCES;
78575 + goto out_mknod_drop_write;
78576 + }
78577 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78578 out_mknod_drop_write:
78579 mnt_drop_write(path.mnt);
78580 if (err)
78581 goto out_mknod_dput;
78582 +
78583 + gr_handle_create(dentry, path.mnt);
78584 +
78585 mutex_unlock(&path.dentry->d_inode->i_mutex);
78586 dput(path.dentry);
78587 path.dentry = dentry;
78588 diff --git a/net/wireless/core.h b/net/wireless/core.h
78589 index 8523f38..79f6091 100644
78590 --- a/net/wireless/core.h
78591 +++ b/net/wireless/core.h
78592 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78593 struct mutex mtx;
78594
78595 /* rfkill support */
78596 - struct rfkill_ops rfkill_ops;
78597 + rfkill_ops_no_const rfkill_ops;
78598 struct rfkill *rfkill;
78599 struct work_struct rfkill_sync;
78600
78601 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78602 index b0eb7aa..7d73e82 100644
78603 --- a/net/wireless/wext-core.c
78604 +++ b/net/wireless/wext-core.c
78605 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78606 */
78607
78608 /* Support for very large requests */
78609 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78610 - (user_length > descr->max_tokens)) {
78611 + if (user_length > descr->max_tokens) {
78612 /* Allow userspace to GET more than max so
78613 * we can support any size GET requests.
78614 * There is still a limit : -ENOMEM.
78615 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78616 }
78617 }
78618
78619 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78620 - /*
78621 - * If this is a GET, but not NOMAX, it means that the extra
78622 - * data is not bounded by userspace, but by max_tokens. Thus
78623 - * set the length to max_tokens. This matches the extra data
78624 - * allocation.
78625 - * The driver should fill it with the number of tokens it
78626 - * provided, and it may check iwp->length rather than having
78627 - * knowledge of max_tokens. If the driver doesn't change the
78628 - * iwp->length, this ioctl just copies back max_token tokens
78629 - * filled with zeroes. Hopefully the driver isn't claiming
78630 - * them to be valid data.
78631 - */
78632 - iwp->length = descr->max_tokens;
78633 - }
78634 -
78635 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78636
78637 iwp->length += essid_compat;
78638 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78639 index ccfbd32..9b61cf9f 100644
78640 --- a/net/xfrm/xfrm_policy.c
78641 +++ b/net/xfrm/xfrm_policy.c
78642 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78643 {
78644 policy->walk.dead = 1;
78645
78646 - atomic_inc(&policy->genid);
78647 + atomic_inc_unchecked(&policy->genid);
78648
78649 if (del_timer(&policy->timer))
78650 xfrm_pol_put(policy);
78651 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78652 hlist_add_head(&policy->bydst, chain);
78653 xfrm_pol_hold(policy);
78654 net->xfrm.policy_count[dir]++;
78655 - atomic_inc(&flow_cache_genid);
78656 + atomic_inc_unchecked(&flow_cache_genid);
78657 if (delpol)
78658 __xfrm_policy_unlink(delpol, dir);
78659 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78660 @@ -1532,7 +1532,7 @@ free_dst:
78661 goto out;
78662 }
78663
78664 -static int inline
78665 +static inline int
78666 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78667 {
78668 if (!*target) {
78669 @@ -1544,7 +1544,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78670 return 0;
78671 }
78672
78673 -static int inline
78674 +static inline int
78675 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78676 {
78677 #ifdef CONFIG_XFRM_SUB_POLICY
78678 @@ -1556,7 +1556,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78679 #endif
78680 }
78681
78682 -static int inline
78683 +static inline int
78684 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78685 {
78686 #ifdef CONFIG_XFRM_SUB_POLICY
78687 @@ -1650,7 +1650,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78688
78689 xdst->num_pols = num_pols;
78690 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78691 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78692 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78693
78694 return xdst;
78695 }
78696 @@ -2350,7 +2350,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78697 if (xdst->xfrm_genid != dst->xfrm->genid)
78698 return 0;
78699 if (xdst->num_pols > 0 &&
78700 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78701 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78702 return 0;
78703
78704 mtu = dst_mtu(dst->child);
78705 @@ -2887,7 +2887,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78706 sizeof(pol->xfrm_vec[i].saddr));
78707 pol->xfrm_vec[i].encap_family = mp->new_family;
78708 /* flush bundles */
78709 - atomic_inc(&pol->genid);
78710 + atomic_inc_unchecked(&pol->genid);
78711 }
78712 }
78713
78714 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78715 index ff1720d..ed8475e 100644
78716 --- a/scripts/Makefile.build
78717 +++ b/scripts/Makefile.build
78718 @@ -111,7 +111,7 @@ endif
78719 endif
78720
78721 # Do not include host rules unless needed
78722 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78723 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
78724 include scripts/Makefile.host
78725 endif
78726
78727 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78728 index 686cb0d..9d653bf 100644
78729 --- a/scripts/Makefile.clean
78730 +++ b/scripts/Makefile.clean
78731 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78732 __clean-files := $(extra-y) $(always) \
78733 $(targets) $(clean-files) \
78734 $(host-progs) \
78735 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78736 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78737 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78738
78739 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78740
78741 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78742 index 1ac414f..38575f7 100644
78743 --- a/scripts/Makefile.host
78744 +++ b/scripts/Makefile.host
78745 @@ -31,6 +31,8 @@
78746 # Note: Shared libraries consisting of C++ files are not supported
78747
78748 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78749 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78750 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
78751
78752 # C code
78753 # Executables compiled from a single .c file
78754 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78755 # Shared libaries (only .c supported)
78756 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78757 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78758 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78759 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
78760 # Remove .so files from "xxx-objs"
78761 host-cobjs := $(filter-out %.so,$(host-cobjs))
78762 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
78763
78764 -#Object (.o) files used by the shared libaries
78765 +# Object (.o) files used by the shared libaries
78766 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
78767 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
78768
78769 # output directory for programs/.o files
78770 # hostprogs-y := tools/build may have been specified. Retrieve directory
78771 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
78772 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
78773 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
78774 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
78775 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
78776 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
78777 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
78778 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
78779
78780 obj-dirs += $(host-objdirs)
78781 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
78782 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
78783 $(call if_changed_dep,host-cshobjs)
78784
78785 +# Compile .c file, create position independent .o file
78786 +# host-cxxshobjs -> .o
78787 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
78788 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
78789 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
78790 + $(call if_changed_dep,host-cxxshobjs)
78791 +
78792 # Link a shared library, based on position independent .o files
78793 # *.o -> .so shared library (host-cshlib)
78794 quiet_cmd_host-cshlib = HOSTLLD -shared $@
78795 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
78796 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
78797 $(call if_changed,host-cshlib)
78798
78799 +# Link a shared library, based on position independent .o files
78800 +# *.o -> .so shared library (host-cxxshlib)
78801 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
78802 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
78803 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
78804 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
78805 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
78806 + $(call if_changed,host-cxxshlib)
78807 +
78808 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
78809 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
78810 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
78811
78812 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78813 index cb1f50c..cef2a7c 100644
78814 --- a/scripts/basic/fixdep.c
78815 +++ b/scripts/basic/fixdep.c
78816 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78817 /*
78818 * Lookup a value in the configuration string.
78819 */
78820 -static int is_defined_config(const char *name, int len, unsigned int hash)
78821 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78822 {
78823 struct item *aux;
78824
78825 @@ -211,10 +211,10 @@ static void clear_config(void)
78826 /*
78827 * Record the use of a CONFIG_* word.
78828 */
78829 -static void use_config(const char *m, int slen)
78830 +static void use_config(const char *m, unsigned int slen)
78831 {
78832 unsigned int hash = strhash(m, slen);
78833 - int c, i;
78834 + unsigned int c, i;
78835
78836 if (is_defined_config(m, slen, hash))
78837 return;
78838 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78839
78840 static void parse_config_file(const char *map, size_t len)
78841 {
78842 - const int *end = (const int *) (map + len);
78843 + const unsigned int *end = (const unsigned int *) (map + len);
78844 /* start at +1, so that p can never be < map */
78845 - const int *m = (const int *) map + 1;
78846 + const unsigned int *m = (const unsigned int *) map + 1;
78847 const char *p, *q;
78848
78849 for (; m < end; m++) {
78850 @@ -406,7 +406,7 @@ static void print_deps(void)
78851 static void traps(void)
78852 {
78853 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78854 - int *p = (int *)test;
78855 + unsigned int *p = (unsigned int *)test;
78856
78857 if (*p != INT_CONF) {
78858 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78859 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78860 new file mode 100644
78861 index 0000000..008ac1a
78862 --- /dev/null
78863 +++ b/scripts/gcc-plugin.sh
78864 @@ -0,0 +1,17 @@
78865 +#!/bin/bash
78866 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
78867 +#include "gcc-plugin.h"
78868 +#include "tree.h"
78869 +#include "tm.h"
78870 +#include "rtl.h"
78871 +#ifdef ENABLE_BUILD_WITH_CXX
78872 +#warning $2
78873 +#else
78874 +#warning $1
78875 +#endif
78876 +EOF`
78877 +if [ $? -eq 0 ]
78878 +then
78879 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
78880 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
78881 +fi
78882 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
78883 index cd9c6c6..0c8f0fa 100644
78884 --- a/scripts/link-vmlinux.sh
78885 +++ b/scripts/link-vmlinux.sh
78886 @@ -147,7 +147,7 @@ else
78887 fi;
78888
78889 # final build of init/
78890 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
78891 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
78892
78893 kallsymso=""
78894 kallsyms_vmlinux=""
78895 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78896 index 5759751..b170367 100644
78897 --- a/scripts/mod/file2alias.c
78898 +++ b/scripts/mod/file2alias.c
78899 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78900 unsigned long size, unsigned long id_size,
78901 void *symval)
78902 {
78903 - int i;
78904 + unsigned int i;
78905
78906 if (size % id_size || size < id_size) {
78907 if (cross_build != 0)
78908 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78909 /* USB is special because the bcdDevice can be matched against a numeric range */
78910 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78911 static void do_usb_entry(struct usb_device_id *id,
78912 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78913 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78914 unsigned char range_lo, unsigned char range_hi,
78915 unsigned char max, struct module *mod)
78916 {
78917 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78918 {
78919 unsigned int devlo, devhi;
78920 unsigned char chi, clo, max;
78921 - int ndigits;
78922 + unsigned int ndigits;
78923
78924 id->match_flags = TO_NATIVE(id->match_flags);
78925 id->idVendor = TO_NATIVE(id->idVendor);
78926 @@ -504,7 +504,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78927 for (i = 0; i < count; i++) {
78928 const char *id = (char *)devs[i].id;
78929 char acpi_id[sizeof(devs[0].id)];
78930 - int j;
78931 + unsigned int j;
78932
78933 buf_printf(&mod->dev_table_buf,
78934 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78935 @@ -534,7 +534,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78936
78937 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78938 const char *id = (char *)card->devs[j].id;
78939 - int i2, j2;
78940 + unsigned int i2, j2;
78941 int dup = 0;
78942
78943 if (!id[0])
78944 @@ -560,7 +560,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78945 /* add an individual alias for every device entry */
78946 if (!dup) {
78947 char acpi_id[sizeof(card->devs[0].id)];
78948 - int k;
78949 + unsigned int k;
78950
78951 buf_printf(&mod->dev_table_buf,
78952 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78953 @@ -885,7 +885,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78954 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78955 char *alias)
78956 {
78957 - int i, j;
78958 + unsigned int i, j;
78959
78960 sprintf(alias, "dmi*");
78961
78962 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78963 index 0f84bb3..2d42035 100644
78964 --- a/scripts/mod/modpost.c
78965 +++ b/scripts/mod/modpost.c
78966 @@ -925,6 +925,7 @@ enum mismatch {
78967 ANY_INIT_TO_ANY_EXIT,
78968 ANY_EXIT_TO_ANY_INIT,
78969 EXPORT_TO_INIT_EXIT,
78970 + DATA_TO_TEXT
78971 };
78972
78973 struct sectioncheck {
78974 @@ -1033,6 +1034,12 @@ const struct sectioncheck sectioncheck[] = {
78975 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78976 .mismatch = EXPORT_TO_INIT_EXIT,
78977 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78978 +},
78979 +/* Do not reference code from writable data */
78980 +{
78981 + .fromsec = { DATA_SECTIONS, NULL },
78982 + .tosec = { TEXT_SECTIONS, NULL },
78983 + .mismatch = DATA_TO_TEXT
78984 }
78985 };
78986
78987 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78988 continue;
78989 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78990 continue;
78991 - if (sym->st_value == addr)
78992 - return sym;
78993 /* Find a symbol nearby - addr are maybe negative */
78994 d = sym->st_value - addr;
78995 + if (d == 0)
78996 + return sym;
78997 if (d < 0)
78998 d = addr - sym->st_value;
78999 if (d < distance) {
79000 @@ -1437,6 +1444,14 @@ static void report_sec_mismatch(const char *modname,
79001 tosym, prl_to, prl_to, tosym);
79002 free(prl_to);
79003 break;
79004 + case DATA_TO_TEXT:
79005 +#if 0
79006 + fprintf(stderr,
79007 + "The %s %s:%s references\n"
79008 + "the %s %s:%s%s\n",
79009 + from, fromsec, fromsym, to, tosec, tosym, to_p);
79010 +#endif
79011 + break;
79012 }
79013 fprintf(stderr, "\n");
79014 }
79015 @@ -1671,7 +1686,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
79016 static void check_sec_ref(struct module *mod, const char *modname,
79017 struct elf_info *elf)
79018 {
79019 - int i;
79020 + unsigned int i;
79021 Elf_Shdr *sechdrs = elf->sechdrs;
79022
79023 /* Walk through all sections */
79024 @@ -1769,7 +1784,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
79025 va_end(ap);
79026 }
79027
79028 -void buf_write(struct buffer *buf, const char *s, int len)
79029 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79030 {
79031 if (buf->size - buf->pos < len) {
79032 buf->size += len + SZ;
79033 @@ -1987,7 +2002,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
79034 if (fstat(fileno(file), &st) < 0)
79035 goto close_write;
79036
79037 - if (st.st_size != b->pos)
79038 + if (st.st_size != (off_t)b->pos)
79039 goto close_write;
79040
79041 tmp = NOFAIL(malloc(b->pos));
79042 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
79043 index 51207e4..f7d603d 100644
79044 --- a/scripts/mod/modpost.h
79045 +++ b/scripts/mod/modpost.h
79046 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
79047
79048 struct buffer {
79049 char *p;
79050 - int pos;
79051 - int size;
79052 + unsigned int pos;
79053 + unsigned int size;
79054 };
79055
79056 void __attribute__((format(printf, 2, 3)))
79057 buf_printf(struct buffer *buf, const char *fmt, ...);
79058
79059 void
79060 -buf_write(struct buffer *buf, const char *s, int len);
79061 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79062
79063 struct module {
79064 struct module *next;
79065 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79066 index 9dfcd6d..099068e 100644
79067 --- a/scripts/mod/sumversion.c
79068 +++ b/scripts/mod/sumversion.c
79069 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79070 goto out;
79071 }
79072
79073 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79074 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79075 warn("writing sum in %s failed: %s\n",
79076 filename, strerror(errno));
79077 goto out;
79078 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79079 index 5c11312..72742b5 100644
79080 --- a/scripts/pnmtologo.c
79081 +++ b/scripts/pnmtologo.c
79082 @@ -237,14 +237,14 @@ static void write_header(void)
79083 fprintf(out, " * Linux logo %s\n", logoname);
79084 fputs(" */\n\n", out);
79085 fputs("#include <linux/linux_logo.h>\n\n", out);
79086 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79087 + fprintf(out, "static unsigned char %s_data[] = {\n",
79088 logoname);
79089 }
79090
79091 static void write_footer(void)
79092 {
79093 fputs("\n};\n\n", out);
79094 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79095 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79096 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79097 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79098 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79099 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79100 fputs("\n};\n\n", out);
79101
79102 /* write logo clut */
79103 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79104 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79105 logoname);
79106 write_hex_cnt = 0;
79107 for (i = 0; i < logo_clutsize; i++) {
79108 diff --git a/security/Kconfig b/security/Kconfig
79109 index e9c6ac7..4349785 100644
79110 --- a/security/Kconfig
79111 +++ b/security/Kconfig
79112 @@ -4,6 +4,876 @@
79113
79114 menu "Security options"
79115
79116 +menu "Grsecurity"
79117 +
79118 + config ARCH_TRACK_EXEC_LIMIT
79119 + bool
79120 +
79121 + config PAX_KERNEXEC_PLUGIN
79122 + bool
79123 +
79124 + config PAX_PER_CPU_PGD
79125 + bool
79126 +
79127 + config TASK_SIZE_MAX_SHIFT
79128 + int
79129 + depends on X86_64
79130 + default 47 if !PAX_PER_CPU_PGD
79131 + default 42 if PAX_PER_CPU_PGD
79132 +
79133 + config PAX_ENABLE_PAE
79134 + bool
79135 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79136 +
79137 + config PAX_USERCOPY_SLABS
79138 + bool
79139 +
79140 +config GRKERNSEC
79141 + bool "Grsecurity"
79142 + select CRYPTO
79143 + select CRYPTO_SHA256
79144 + select PROC_FS
79145 + select STOP_MACHINE
79146 + help
79147 + If you say Y here, you will be able to configure many features
79148 + that will enhance the security of your system. It is highly
79149 + recommended that you say Y here and read through the help
79150 + for each option so that you fully understand the features and
79151 + can evaluate their usefulness for your machine.
79152 +
79153 +choice
79154 + prompt "Configuration Method"
79155 + depends on GRKERNSEC
79156 + default GRKERNSEC_CONFIG_CUSTOM
79157 + help
79158 +
79159 +config GRKERNSEC_CONFIG_AUTO
79160 + bool "Automatic"
79161 + help
79162 + If you choose this configuration method, you'll be able to answer a small
79163 + number of simple questions about how you plan to use this kernel.
79164 + The settings of grsecurity and PaX will be automatically configured for
79165 + the highest commonly-used settings within the provided constraints.
79166 +
79167 + If you require additional configuration, custom changes can still be made
79168 + from the "custom configuration" menu.
79169 +
79170 +config GRKERNSEC_CONFIG_CUSTOM
79171 + bool "Custom"
79172 + help
79173 + If you choose this configuration method, you'll be able to configure all
79174 + grsecurity and PaX settings manually. Via this method, no options are
79175 + automatically enabled.
79176 +
79177 +endchoice
79178 +
79179 +choice
79180 + prompt "Usage Type"
79181 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79182 + default GRKERNSEC_CONFIG_SERVER
79183 + help
79184 +
79185 +config GRKERNSEC_CONFIG_SERVER
79186 + bool "Server"
79187 + help
79188 + Choose this option if you plan to use this kernel on a server.
79189 +
79190 +config GRKERNSEC_CONFIG_DESKTOP
79191 + bool "Desktop"
79192 + help
79193 + Choose this option if you plan to use this kernel on a desktop.
79194 +
79195 +endchoice
79196 +
79197 +choice
79198 + prompt "Virtualization Type"
79199 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
79200 + default GRKERNSEC_CONFIG_VIRT_NONE
79201 + help
79202 +
79203 +config GRKERNSEC_CONFIG_VIRT_NONE
79204 + bool "None"
79205 + help
79206 + Choose this option if this kernel will be run on bare metal.
79207 +
79208 +config GRKERNSEC_CONFIG_VIRT_GUEST
79209 + bool "Guest"
79210 + help
79211 + Choose this option if this kernel will be run as a VM guest.
79212 +
79213 +config GRKERNSEC_CONFIG_VIRT_HOST
79214 + bool "Host"
79215 + help
79216 + Choose this option if this kernel will be run as a VM host.
79217 +
79218 +endchoice
79219 +
79220 +choice
79221 + prompt "Virtualization Hardware"
79222 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79223 + help
79224 +
79225 +config GRKERNSEC_CONFIG_VIRT_EPT
79226 + bool "EPT/RVI Processor Support"
79227 + depends on X86
79228 + help
79229 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
79230 + hardware virtualization. This allows for additional kernel hardening protections
79231 + to operate without additional performance impact.
79232 +
79233 + To see if your Intel processor supports EPT, see:
79234 + http://ark.intel.com/Products/VirtualizationTechnology
79235 + (Most Core i3/5/7 support EPT)
79236 +
79237 + To see if your AMD processor supports RVI, see:
79238 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
79239 +
79240 +config GRKERNSEC_CONFIG_VIRT_SOFT
79241 + bool "First-gen/No Hardware Virtualization"
79242 + help
79243 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
79244 + support hardware virtualization or doesn't support the EPT/RVI extensions.
79245 +
79246 +endchoice
79247 +
79248 +choice
79249 + prompt "Virtualization Software"
79250 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
79251 + help
79252 +
79253 +config GRKERNSEC_CONFIG_VIRT_XEN
79254 + bool "Xen"
79255 + help
79256 + Choose this option if this kernel is running as a Xen guest or host.
79257 +
79258 +config GRKERNSEC_CONFIG_VIRT_VMWARE
79259 + bool "VMWare"
79260 + help
79261 + Choose this option if this kernel is running as a VMWare guest or host.
79262 +
79263 +config GRKERNSEC_CONFIG_VIRT_KVM
79264 + bool "KVM"
79265 + help
79266 + Choose this option if this kernel is running as a KVM guest or host.
79267 +
79268 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
79269 + bool "VirtualBox"
79270 + help
79271 + Choose this option if this kernel is running as a VirtualBox guest or host.
79272 +
79273 +endchoice
79274 +
79275 +choice
79276 + prompt "Required Priorities"
79277 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79278 + default GRKERNSEC_CONFIG_PRIORITY_PERF
79279 + help
79280 +
79281 +config GRKERNSEC_CONFIG_PRIORITY_PERF
79282 + bool "Performance"
79283 + help
79284 + Choose this option if performance is of highest priority for this deployment
79285 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
79286 + and freed memory sanitizing will be disabled.
79287 +
79288 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
79289 + bool "Security"
79290 + help
79291 + Choose this option if security is of highest priority for this deployment of
79292 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
79293 + be enabled for this kernel. In a worst-case scenario, these features can
79294 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
79295 +
79296 +endchoice
79297 +
79298 +menu "Default Special Groups"
79299 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
79300 +
79301 +config GRKERNSEC_PROC_GID
79302 + int "GID exempted from /proc restrictions"
79303 + default 1001
79304 + help
79305 + Setting this GID determines which group will be exempted from
79306 + grsecurity's /proc restrictions, allowing users of the specified
79307 + group to view network statistics and the existence of other users'
79308 + processes on the system.
79309 +
79310 +config GRKERNSEC_TPE_GID
79311 + int "GID for untrusted users"
79312 + depends on GRKERNSEC_CONFIG_SERVER
79313 + default 1005
79314 + help
79315 + Setting this GID determines which group untrusted users should
79316 + be added to. These users will be placed under grsecurity's Trusted Path
79317 + Execution mechanism, preventing them from executing their own binaries.
79318 + The users will only be able to execute binaries in directories owned and
79319 + writable only by the root user.
79320 +
79321 +config GRKERNSEC_SYMLINKOWN_GID
79322 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
79323 + depends on GRKERNSEC_CONFIG_SERVER
79324 + default 1006
79325 + help
79326 + Setting this GID determines what group kernel-enforced
79327 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
79328 + is enabled, a sysctl option with name "symlinkown_gid" is created.
79329 +
79330 +
79331 +endmenu
79332 +
79333 +menu "Customize Configuration"
79334 +depends on GRKERNSEC
79335 +
79336 +menu "PaX"
79337 +
79338 +config PAX
79339 + bool "Enable various PaX features"
79340 + default y if GRKERNSEC_CONFIG_AUTO
79341 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79342 + help
79343 + This allows you to enable various PaX features. PaX adds
79344 + intrusion prevention mechanisms to the kernel that reduce
79345 + the risks posed by exploitable memory corruption bugs.
79346 +
79347 +menu "PaX Control"
79348 + depends on PAX
79349 +
79350 +config PAX_SOFTMODE
79351 + bool 'Support soft mode'
79352 + help
79353 + Enabling this option will allow you to run PaX in soft mode, that
79354 + is, PaX features will not be enforced by default, only on executables
79355 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79356 + support as they are the only way to mark executables for soft mode use.
79357 +
79358 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79359 + line option on boot. Furthermore you can control various PaX features
79360 + at runtime via the entries in /proc/sys/kernel/pax.
79361 +
79362 +config PAX_EI_PAX
79363 + bool 'Use legacy ELF header marking'
79364 + default y if GRKERNSEC_CONFIG_AUTO
79365 + help
79366 + Enabling this option will allow you to control PaX features on
79367 + a per executable basis via the 'chpax' utility available at
79368 + http://pax.grsecurity.net/. The control flags will be read from
79369 + an otherwise reserved part of the ELF header. This marking has
79370 + numerous drawbacks (no support for soft-mode, toolchain does not
79371 + know about the non-standard use of the ELF header) therefore it
79372 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79373 + support.
79374 +
79375 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79376 + support as well, they will override the legacy EI_PAX marks.
79377 +
79378 + If you enable none of the marking options then all applications
79379 + will run with PaX enabled on them by default.
79380 +
79381 +config PAX_PT_PAX_FLAGS
79382 + bool 'Use ELF program header marking'
79383 + default y if GRKERNSEC_CONFIG_AUTO
79384 + help
79385 + Enabling this option will allow you to control PaX features on
79386 + a per executable basis via the 'paxctl' utility available at
79387 + http://pax.grsecurity.net/. The control flags will be read from
79388 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79389 + has the benefits of supporting both soft mode and being fully
79390 + integrated into the toolchain (the binutils patch is available
79391 + from http://pax.grsecurity.net).
79392 +
79393 + Note that if you enable the legacy EI_PAX marking support as well,
79394 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79395 +
79396 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79397 + must make sure that the marks are the same if a binary has both marks.
79398 +
79399 + If you enable none of the marking options then all applications
79400 + will run with PaX enabled on them by default.
79401 +
79402 +config PAX_XATTR_PAX_FLAGS
79403 + bool 'Use filesystem extended attributes marking'
79404 + default y if GRKERNSEC_CONFIG_AUTO
79405 + select CIFS_XATTR if CIFS
79406 + select EXT2_FS_XATTR if EXT2_FS
79407 + select EXT3_FS_XATTR if EXT3_FS
79408 + select EXT4_FS_XATTR if EXT4_FS
79409 + select JFFS2_FS_XATTR if JFFS2_FS
79410 + select REISERFS_FS_XATTR if REISERFS_FS
79411 + select SQUASHFS_XATTR if SQUASHFS
79412 + select TMPFS_XATTR if TMPFS
79413 + select UBIFS_FS_XATTR if UBIFS_FS
79414 + help
79415 + Enabling this option will allow you to control PaX features on
79416 + a per executable basis via the 'setfattr' utility. The control
79417 + flags will be read from the user.pax.flags extended attribute of
79418 + the file. This marking has the benefit of supporting binary-only
79419 + applications that self-check themselves (e.g., skype) and would
79420 + not tolerate chpax/paxctl changes. The main drawback is that
79421 + extended attributes are not supported by some filesystems (e.g.,
79422 + isofs, udf, vfat) so copying files through such filesystems will
79423 + lose the extended attributes and these PaX markings.
79424 +
79425 + Note that if you enable the legacy EI_PAX marking support as well,
79426 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79427 +
79428 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79429 + must make sure that the marks are the same if a binary has both marks.
79430 +
79431 + If you enable none of the marking options then all applications
79432 + will run with PaX enabled on them by default.
79433 +
79434 +choice
79435 + prompt 'MAC system integration'
79436 + default PAX_HAVE_ACL_FLAGS
79437 + help
79438 + Mandatory Access Control systems have the option of controlling
79439 + PaX flags on a per executable basis, choose the method supported
79440 + by your particular system.
79441 +
79442 + - "none": if your MAC system does not interact with PaX,
79443 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79444 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79445 +
79446 + NOTE: this option is for developers/integrators only.
79447 +
79448 + config PAX_NO_ACL_FLAGS
79449 + bool 'none'
79450 +
79451 + config PAX_HAVE_ACL_FLAGS
79452 + bool 'direct'
79453 +
79454 + config PAX_HOOK_ACL_FLAGS
79455 + bool 'hook'
79456 +endchoice
79457 +
79458 +endmenu
79459 +
79460 +menu "Non-executable pages"
79461 + depends on PAX
79462 +
79463 +config PAX_NOEXEC
79464 + bool "Enforce non-executable pages"
79465 + default y if GRKERNSEC_CONFIG_AUTO
79466 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79467 + help
79468 + By design some architectures do not allow for protecting memory
79469 + pages against execution or even if they do, Linux does not make
79470 + use of this feature. In practice this means that if a page is
79471 + readable (such as the stack or heap) it is also executable.
79472 +
79473 + There is a well known exploit technique that makes use of this
79474 + fact and a common programming mistake where an attacker can
79475 + introduce code of his choice somewhere in the attacked program's
79476 + memory (typically the stack or the heap) and then execute it.
79477 +
79478 + If the attacked program was running with different (typically
79479 + higher) privileges than that of the attacker, then he can elevate
79480 + his own privilege level (e.g. get a root shell, write to files for
79481 + which he does not have write access to, etc).
79482 +
79483 + Enabling this option will let you choose from various features
79484 + that prevent the injection and execution of 'foreign' code in
79485 + a program.
79486 +
79487 + This will also break programs that rely on the old behaviour and
79488 + expect that dynamically allocated memory via the malloc() family
79489 + of functions is executable (which it is not). Notable examples
79490 + are the XFree86 4.x server, the java runtime and wine.
79491 +
79492 +config PAX_PAGEEXEC
79493 + bool "Paging based non-executable pages"
79494 + default y if GRKERNSEC_CONFIG_AUTO
79495 + 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)
79496 + select S390_SWITCH_AMODE if S390
79497 + select S390_EXEC_PROTECT if S390
79498 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79499 + help
79500 + This implementation is based on the paging feature of the CPU.
79501 + On i386 without hardware non-executable bit support there is a
79502 + variable but usually low performance impact, however on Intel's
79503 + P4 core based CPUs it is very high so you should not enable this
79504 + for kernels meant to be used on such CPUs.
79505 +
79506 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79507 + with hardware non-executable bit support there is no performance
79508 + impact, on ppc the impact is negligible.
79509 +
79510 + Note that several architectures require various emulations due to
79511 + badly designed userland ABIs, this will cause a performance impact
79512 + but will disappear as soon as userland is fixed. For example, ppc
79513 + userland MUST have been built with secure-plt by a recent toolchain.
79514 +
79515 +config PAX_SEGMEXEC
79516 + bool "Segmentation based non-executable pages"
79517 + default y if GRKERNSEC_CONFIG_AUTO
79518 + depends on PAX_NOEXEC && X86_32
79519 + help
79520 + This implementation is based on the segmentation feature of the
79521 + CPU and has a very small performance impact, however applications
79522 + will be limited to a 1.5 GB address space instead of the normal
79523 + 3 GB.
79524 +
79525 +config PAX_EMUTRAMP
79526 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79527 + default y if PARISC
79528 + help
79529 + There are some programs and libraries that for one reason or
79530 + another attempt to execute special small code snippets from
79531 + non-executable memory pages. Most notable examples are the
79532 + signal handler return code generated by the kernel itself and
79533 + the GCC trampolines.
79534 +
79535 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79536 + such programs will no longer work under your kernel.
79537 +
79538 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79539 + utilities to enable trampoline emulation for the affected programs
79540 + yet still have the protection provided by the non-executable pages.
79541 +
79542 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79543 + your system will not even boot.
79544 +
79545 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79546 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79547 + for the affected files.
79548 +
79549 + NOTE: enabling this feature *may* open up a loophole in the
79550 + protection provided by non-executable pages that an attacker
79551 + could abuse. Therefore the best solution is to not have any
79552 + files on your system that would require this option. This can
79553 + be achieved by not using libc5 (which relies on the kernel
79554 + signal handler return code) and not using or rewriting programs
79555 + that make use of the nested function implementation of GCC.
79556 + Skilled users can just fix GCC itself so that it implements
79557 + nested function calls in a way that does not interfere with PaX.
79558 +
79559 +config PAX_EMUSIGRT
79560 + bool "Automatically emulate sigreturn trampolines"
79561 + depends on PAX_EMUTRAMP && PARISC
79562 + default y
79563 + help
79564 + Enabling this option will have the kernel automatically detect
79565 + and emulate signal return trampolines executing on the stack
79566 + that would otherwise lead to task termination.
79567 +
79568 + This solution is intended as a temporary one for users with
79569 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79570 + Modula-3 runtime, etc) or executables linked to such, basically
79571 + everything that does not specify its own SA_RESTORER function in
79572 + normal executable memory like glibc 2.1+ does.
79573 +
79574 + On parisc you MUST enable this option, otherwise your system will
79575 + not even boot.
79576 +
79577 + NOTE: this feature cannot be disabled on a per executable basis
79578 + and since it *does* open up a loophole in the protection provided
79579 + by non-executable pages, the best solution is to not have any
79580 + files on your system that would require this option.
79581 +
79582 +config PAX_MPROTECT
79583 + bool "Restrict mprotect()"
79584 + default y if GRKERNSEC_CONFIG_AUTO
79585 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79586 + help
79587 + Enabling this option will prevent programs from
79588 + - changing the executable status of memory pages that were
79589 + not originally created as executable,
79590 + - making read-only executable pages writable again,
79591 + - creating executable pages from anonymous memory,
79592 + - making read-only-after-relocations (RELRO) data pages writable again.
79593 +
79594 + You should say Y here to complete the protection provided by
79595 + the enforcement of non-executable pages.
79596 +
79597 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79598 + this feature on a per file basis.
79599 +
79600 +config PAX_MPROTECT_COMPAT
79601 + bool "Use legacy/compat protection demoting (read help)"
79602 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
79603 + depends on PAX_MPROTECT
79604 + help
79605 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79606 + by sending the proper error code to the application. For some broken
79607 + userland, this can cause problems with Python or other applications. The
79608 + current implementation however allows for applications like clamav to
79609 + detect if JIT compilation/execution is allowed and to fall back gracefully
79610 + to an interpreter-based mode if it does not. While we encourage everyone
79611 + to use the current implementation as-is and push upstream to fix broken
79612 + userland (note that the RWX logging option can assist with this), in some
79613 + environments this may not be possible. Having to disable MPROTECT
79614 + completely on certain binaries reduces the security benefit of PaX,
79615 + so this option is provided for those environments to revert to the old
79616 + behavior.
79617 +
79618 +config PAX_ELFRELOCS
79619 + bool "Allow ELF text relocations (read help)"
79620 + depends on PAX_MPROTECT
79621 + default n
79622 + help
79623 + Non-executable pages and mprotect() restrictions are effective
79624 + in preventing the introduction of new executable code into an
79625 + attacked task's address space. There remain only two venues
79626 + for this kind of attack: if the attacker can execute already
79627 + existing code in the attacked task then he can either have it
79628 + create and mmap() a file containing his code or have it mmap()
79629 + an already existing ELF library that does not have position
79630 + independent code in it and use mprotect() on it to make it
79631 + writable and copy his code there. While protecting against
79632 + the former approach is beyond PaX, the latter can be prevented
79633 + by having only PIC ELF libraries on one's system (which do not
79634 + need to relocate their code). If you are sure this is your case,
79635 + as is the case with all modern Linux distributions, then leave
79636 + this option disabled. You should say 'n' here.
79637 +
79638 +config PAX_ETEXECRELOCS
79639 + bool "Allow ELF ET_EXEC text relocations"
79640 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79641 + select PAX_ELFRELOCS
79642 + default y
79643 + help
79644 + On some architectures there are incorrectly created applications
79645 + that require text relocations and would not work without enabling
79646 + this option. If you are an alpha, ia64 or parisc user, you should
79647 + enable this option and disable it once you have made sure that
79648 + none of your applications need it.
79649 +
79650 +config PAX_EMUPLT
79651 + bool "Automatically emulate ELF PLT"
79652 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79653 + default y
79654 + help
79655 + Enabling this option will have the kernel automatically detect
79656 + and emulate the Procedure Linkage Table entries in ELF files.
79657 + On some architectures such entries are in writable memory, and
79658 + become non-executable leading to task termination. Therefore
79659 + it is mandatory that you enable this option on alpha, parisc,
79660 + sparc and sparc64, otherwise your system would not even boot.
79661 +
79662 + NOTE: this feature *does* open up a loophole in the protection
79663 + provided by the non-executable pages, therefore the proper
79664 + solution is to modify the toolchain to produce a PLT that does
79665 + not need to be writable.
79666 +
79667 +config PAX_DLRESOLVE
79668 + bool 'Emulate old glibc resolver stub'
79669 + depends on PAX_EMUPLT && SPARC
79670 + default n
79671 + help
79672 + This option is needed if userland has an old glibc (before 2.4)
79673 + that puts a 'save' instruction into the runtime generated resolver
79674 + stub that needs special emulation.
79675 +
79676 +config PAX_KERNEXEC
79677 + bool "Enforce non-executable kernel pages"
79678 + 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))
79679 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79680 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79681 + select PAX_KERNEXEC_PLUGIN if X86_64
79682 + help
79683 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79684 + that is, enabling this option will make it harder to inject
79685 + and execute 'foreign' code in kernel memory itself.
79686 +
79687 + Note that on x86_64 kernels there is a known regression when
79688 + this feature and KVM/VMX are both enabled in the host kernel.
79689 +
79690 +choice
79691 + prompt "Return Address Instrumentation Method"
79692 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
79693 + depends on PAX_KERNEXEC_PLUGIN
79694 + help
79695 + Select the method used to instrument function pointer dereferences.
79696 + Note that binary modules cannot be instrumented by this approach.
79697 +
79698 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
79699 + bool "bts"
79700 + help
79701 + This method is compatible with binary only modules but has
79702 + a higher runtime overhead.
79703 +
79704 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
79705 + bool "or"
79706 + depends on !PARAVIRT
79707 + help
79708 + This method is incompatible with binary only modules but has
79709 + a lower runtime overhead.
79710 +endchoice
79711 +
79712 +config PAX_KERNEXEC_PLUGIN_METHOD
79713 + string
79714 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
79715 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
79716 + default ""
79717 +
79718 +config PAX_KERNEXEC_MODULE_TEXT
79719 + int "Minimum amount of memory reserved for module code"
79720 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
79721 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
79722 + depends on PAX_KERNEXEC && X86_32 && MODULES
79723 + help
79724 + Due to implementation details the kernel must reserve a fixed
79725 + amount of memory for module code at compile time that cannot be
79726 + changed at runtime. Here you can specify the minimum amount
79727 + in MB that will be reserved. Due to the same implementation
79728 + details this size will always be rounded up to the next 2/4 MB
79729 + boundary (depends on PAE) so the actually available memory for
79730 + module code will usually be more than this minimum.
79731 +
79732 + The default 4 MB should be enough for most users but if you have
79733 + an excessive number of modules (e.g., most distribution configs
79734 + compile many drivers as modules) or use huge modules such as
79735 + nvidia's kernel driver, you will need to adjust this amount.
79736 + A good rule of thumb is to look at your currently loaded kernel
79737 + modules and add up their sizes.
79738 +
79739 +endmenu
79740 +
79741 +menu "Address Space Layout Randomization"
79742 + depends on PAX
79743 +
79744 +config PAX_ASLR
79745 + bool "Address Space Layout Randomization"
79746 + default y if GRKERNSEC_CONFIG_AUTO
79747 + help
79748 + Many if not most exploit techniques rely on the knowledge of
79749 + certain addresses in the attacked program. The following options
79750 + will allow the kernel to apply a certain amount of randomization
79751 + to specific parts of the program thereby forcing an attacker to
79752 + guess them in most cases. Any failed guess will most likely crash
79753 + the attacked program which allows the kernel to detect such attempts
79754 + and react on them. PaX itself provides no reaction mechanisms,
79755 + instead it is strongly encouraged that you make use of Nergal's
79756 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79757 + (http://www.grsecurity.net/) built-in crash detection features or
79758 + develop one yourself.
79759 +
79760 + By saying Y here you can choose to randomize the following areas:
79761 + - top of the task's kernel stack
79762 + - top of the task's userland stack
79763 + - base address for mmap() requests that do not specify one
79764 + (this includes all libraries)
79765 + - base address of the main executable
79766 +
79767 + It is strongly recommended to say Y here as address space layout
79768 + randomization has negligible impact on performance yet it provides
79769 + a very effective protection.
79770 +
79771 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79772 + this feature on a per file basis.
79773 +
79774 +config PAX_RANDKSTACK
79775 + bool "Randomize kernel stack base"
79776 + default y if GRKERNSEC_CONFIG_AUTO
79777 + depends on X86_TSC && X86
79778 + help
79779 + By saying Y here the kernel will randomize every task's kernel
79780 + stack on every system call. This will not only force an attacker
79781 + to guess it but also prevent him from making use of possible
79782 + leaked information about it.
79783 +
79784 + Since the kernel stack is a rather scarce resource, randomization
79785 + may cause unexpected stack overflows, therefore you should very
79786 + carefully test your system. Note that once enabled in the kernel
79787 + configuration, this feature cannot be disabled on a per file basis.
79788 +
79789 +config PAX_RANDUSTACK
79790 + bool "Randomize user stack base"
79791 + default y if GRKERNSEC_CONFIG_AUTO
79792 + depends on PAX_ASLR
79793 + help
79794 + By saying Y here the kernel will randomize every task's userland
79795 + stack. The randomization is done in two steps where the second
79796 + one may apply a big amount of shift to the top of the stack and
79797 + cause problems for programs that want to use lots of memory (more
79798 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79799 + For this reason the second step can be controlled by 'chpax' or
79800 + 'paxctl' on a per file basis.
79801 +
79802 +config PAX_RANDMMAP
79803 + bool "Randomize mmap() base"
79804 + default y if GRKERNSEC_CONFIG_AUTO
79805 + depends on PAX_ASLR
79806 + help
79807 + By saying Y here the kernel will use a randomized base address for
79808 + mmap() requests that do not specify one themselves. As a result
79809 + all dynamically loaded libraries will appear at random addresses
79810 + and therefore be harder to exploit by a technique where an attacker
79811 + attempts to execute library code for his purposes (e.g. spawn a
79812 + shell from an exploited program that is running at an elevated
79813 + privilege level).
79814 +
79815 + Furthermore, if a program is relinked as a dynamic ELF file, its
79816 + base address will be randomized as well, completing the full
79817 + randomization of the address space layout. Attacking such programs
79818 + becomes a guess game. You can find an example of doing this at
79819 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79820 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79821 +
79822 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79823 + feature on a per file basis.
79824 +
79825 +endmenu
79826 +
79827 +menu "Miscellaneous hardening features"
79828 +
79829 +config PAX_MEMORY_SANITIZE
79830 + bool "Sanitize all freed memory"
79831 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
79832 + depends on !HIBERNATION
79833 + help
79834 + By saying Y here the kernel will erase memory pages as soon as they
79835 + are freed. This in turn reduces the lifetime of data stored in the
79836 + pages, making it less likely that sensitive information such as
79837 + passwords, cryptographic secrets, etc stay in memory for too long.
79838 +
79839 + This is especially useful for programs whose runtime is short, long
79840 + lived processes and the kernel itself benefit from this as long as
79841 + they operate on whole memory pages and ensure timely freeing of pages
79842 + that may hold sensitive information.
79843 +
79844 + The tradeoff is performance impact, on a single CPU system kernel
79845 + compilation sees a 3% slowdown, other systems and workloads may vary
79846 + and you are advised to test this feature on your expected workload
79847 + before deploying it.
79848 +
79849 + Note that this feature does not protect data stored in live pages,
79850 + e.g., process memory swapped to disk may stay there for a long time.
79851 +
79852 +config PAX_MEMORY_STACKLEAK
79853 + bool "Sanitize kernel stack"
79854 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
79855 + depends on X86
79856 + help
79857 + By saying Y here the kernel will erase the kernel stack before it
79858 + returns from a system call. This in turn reduces the information
79859 + that a kernel stack leak bug can reveal.
79860 +
79861 + Note that such a bug can still leak information that was put on
79862 + the stack by the current system call (the one eventually triggering
79863 + the bug) but traces of earlier system calls on the kernel stack
79864 + cannot leak anymore.
79865 +
79866 + The tradeoff is performance impact: on a single CPU system kernel
79867 + compilation sees a 1% slowdown, other systems and workloads may vary
79868 + and you are advised to test this feature on your expected workload
79869 + before deploying it.
79870 +
79871 + Note: full support for this feature requires gcc with plugin support
79872 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79873 + versions means that functions with large enough stack frames may
79874 + leave uninitialized memory behind that may be exposed to a later
79875 + syscall leaking the stack.
79876 +
79877 +config PAX_MEMORY_UDEREF
79878 + bool "Prevent invalid userland pointer dereference"
79879 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
79880 + depends on X86 && !UML_X86 && !XEN
79881 + select PAX_PER_CPU_PGD if X86_64
79882 + help
79883 + By saying Y here the kernel will be prevented from dereferencing
79884 + userland pointers in contexts where the kernel expects only kernel
79885 + pointers. This is both a useful runtime debugging feature and a
79886 + security measure that prevents exploiting a class of kernel bugs.
79887 +
79888 + The tradeoff is that some virtualization solutions may experience
79889 + a huge slowdown and therefore you should not enable this feature
79890 + for kernels meant to run in such environments. Whether a given VM
79891 + solution is affected or not is best determined by simply trying it
79892 + out, the performance impact will be obvious right on boot as this
79893 + mechanism engages from very early on. A good rule of thumb is that
79894 + VMs running on CPUs without hardware virtualization support (i.e.,
79895 + the majority of IA-32 CPUs) will likely experience the slowdown.
79896 +
79897 +config PAX_REFCOUNT
79898 + bool "Prevent various kernel object reference counter overflows"
79899 + default y if GRKERNSEC_CONFIG_AUTO
79900 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79901 + help
79902 + By saying Y here the kernel will detect and prevent overflowing
79903 + various (but not all) kinds of object reference counters. Such
79904 + overflows can normally occur due to bugs only and are often, if
79905 + not always, exploitable.
79906 +
79907 + The tradeoff is that data structures protected by an overflowed
79908 + refcount will never be freed and therefore will leak memory. Note
79909 + that this leak also happens even without this protection but in
79910 + that case the overflow can eventually trigger the freeing of the
79911 + data structure while it is still being used elsewhere, resulting
79912 + in the exploitable situation that this feature prevents.
79913 +
79914 + Since this has a negligible performance impact, you should enable
79915 + this feature.
79916 +
79917 +config PAX_USERCOPY
79918 + bool "Harden heap object copies between kernel and userland"
79919 + default y if GRKERNSEC_CONFIG_AUTO
79920 + depends on X86 || PPC || SPARC || ARM
79921 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79922 + select PAX_USERCOPY_SLABS
79923 + help
79924 + By saying Y here the kernel will enforce the size of heap objects
79925 + when they are copied in either direction between the kernel and
79926 + userland, even if only a part of the heap object is copied.
79927 +
79928 + Specifically, this checking prevents information leaking from the
79929 + kernel heap during kernel to userland copies (if the kernel heap
79930 + object is otherwise fully initialized) and prevents kernel heap
79931 + overflows during userland to kernel copies.
79932 +
79933 + Note that the current implementation provides the strictest bounds
79934 + checks for the SLUB allocator.
79935 +
79936 + Enabling this option also enables per-slab cache protection against
79937 + data in a given cache being copied into/out of via userland
79938 + accessors. Though the whitelist of regions will be reduced over
79939 + time, it notably protects important data structures like task structs.
79940 +
79941 + If frame pointers are enabled on x86, this option will also restrict
79942 + copies into and out of the kernel stack to local variables within a
79943 + single frame.
79944 +
79945 + Since this has a negligible performance impact, you should enable
79946 + this feature.
79947 +
79948 +config PAX_SIZE_OVERFLOW
79949 + bool "Prevent various integer overflows in function size parameters"
79950 + default y if GRKERNSEC_CONFIG_AUTO
79951 + depends on X86
79952 + help
79953 + By saying Y here the kernel recomputes expressions of function
79954 + arguments marked by a size_overflow attribute with double integer
79955 + precision (DImode/TImode for 32/64 bit integer types).
79956 +
79957 + The recomputed argument is checked against INT_MAX and an event
79958 + is logged on overflow and the triggering process is killed.
79959 +
79960 + Homepage:
79961 + http://www.grsecurity.net/~ephox/overflow_plugin/
79962 +
79963 +config PAX_LATENT_ENTROPY
79964 + bool "Generate some entropy during boot"
79965 + default y if GRKERNSEC_CONFIG_AUTO
79966 + help
79967 + By saying Y here the kernel will instrument early boot code to
79968 + extract some entropy from both original and artificially created
79969 + program state. This will help especially embedded systems where
79970 + there is little 'natural' source of entropy normally. The cost
79971 + is some slowdown of the boot process.
79972 +
79973 + Note that entropy extracted this way is not cryptographically
79974 + secure!
79975 +
79976 +endmenu
79977 +
79978 +endmenu
79979 +
79980 +source grsecurity/Kconfig
79981 +
79982 +endmenu
79983 +
79984 +endmenu
79985 +
79986 source security/keys/Kconfig
79987
79988 config SECURITY_DMESG_RESTRICT
79989 @@ -103,7 +973,7 @@ config INTEL_TXT
79990 config LSM_MMAP_MIN_ADDR
79991 int "Low address space for LSM to protect from user allocation"
79992 depends on SECURITY && SECURITY_SELINUX
79993 - default 32768 if ARM
79994 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79995 default 65536
79996 help
79997 This is the portion of low virtual memory which should be protected
79998 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79999 index 8ea39aa..8569ac5 100644
80000 --- a/security/apparmor/lsm.c
80001 +++ b/security/apparmor/lsm.c
80002 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
80003 return error;
80004 }
80005
80006 -static struct security_operations apparmor_ops = {
80007 +static struct security_operations apparmor_ops __read_only = {
80008 .name = "apparmor",
80009
80010 .ptrace_access_check = apparmor_ptrace_access_check,
80011 diff --git a/security/commoncap.c b/security/commoncap.c
80012 index 6dbae46..f534748 100644
80013 --- a/security/commoncap.c
80014 +++ b/security/commoncap.c
80015 @@ -583,6 +583,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
80016 const struct cred *cred = current_cred();
80017 kuid_t root_uid = make_kuid(cred->user_ns, 0);
80018
80019 + if (gr_acl_enable_at_secure())
80020 + return 1;
80021 +
80022 if (!uid_eq(cred->uid, root_uid)) {
80023 if (bprm->cap_effective)
80024 return 1;
80025 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
80026 index 3ccf7ac..d73ad64 100644
80027 --- a/security/integrity/ima/ima.h
80028 +++ b/security/integrity/ima/ima.h
80029 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80030 extern spinlock_t ima_queue_lock;
80031
80032 struct ima_h_table {
80033 - atomic_long_t len; /* number of stored measurements in the list */
80034 - atomic_long_t violations;
80035 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
80036 + atomic_long_unchecked_t violations;
80037 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
80038 };
80039 extern struct ima_h_table ima_htable;
80040 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
80041 index 88a2788..581ab92 100644
80042 --- a/security/integrity/ima/ima_api.c
80043 +++ b/security/integrity/ima/ima_api.c
80044 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80045 int result;
80046
80047 /* can overflow, only indicator */
80048 - atomic_long_inc(&ima_htable.violations);
80049 + atomic_long_inc_unchecked(&ima_htable.violations);
80050
80051 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
80052 if (!entry) {
80053 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
80054 index e1aa2b4..52027bf 100644
80055 --- a/security/integrity/ima/ima_fs.c
80056 +++ b/security/integrity/ima/ima_fs.c
80057 @@ -28,12 +28,12 @@
80058 static int valid_policy = 1;
80059 #define TMPBUFLEN 12
80060 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
80061 - loff_t *ppos, atomic_long_t *val)
80062 + loff_t *ppos, atomic_long_unchecked_t *val)
80063 {
80064 char tmpbuf[TMPBUFLEN];
80065 ssize_t len;
80066
80067 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
80068 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
80069 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
80070 }
80071
80072 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
80073 index 55a6271..ad829c3 100644
80074 --- a/security/integrity/ima/ima_queue.c
80075 +++ b/security/integrity/ima/ima_queue.c
80076 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
80077 INIT_LIST_HEAD(&qe->later);
80078 list_add_tail_rcu(&qe->later, &ima_measurements);
80079
80080 - atomic_long_inc(&ima_htable.len);
80081 + atomic_long_inc_unchecked(&ima_htable.len);
80082 key = ima_hash_key(entry->digest);
80083 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
80084 return 0;
80085 diff --git a/security/keys/compat.c b/security/keys/compat.c
80086 index c92d42b..341e7ea 100644
80087 --- a/security/keys/compat.c
80088 +++ b/security/keys/compat.c
80089 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
80090 if (ret == 0)
80091 goto no_payload_free;
80092
80093 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80094 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80095
80096 if (iov != iovstack)
80097 kfree(iov);
80098 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
80099 index 0f5b3f0..b8d47c1 100644
80100 --- a/security/keys/keyctl.c
80101 +++ b/security/keys/keyctl.c
80102 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
80103 /*
80104 * Copy the iovec data from userspace
80105 */
80106 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80107 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
80108 unsigned ioc)
80109 {
80110 for (; ioc > 0; ioc--) {
80111 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80112 * If successful, 0 will be returned.
80113 */
80114 long keyctl_instantiate_key_common(key_serial_t id,
80115 - const struct iovec *payload_iov,
80116 + const struct iovec __user *payload_iov,
80117 unsigned ioc,
80118 size_t plen,
80119 key_serial_t ringid)
80120 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
80121 [0].iov_len = plen
80122 };
80123
80124 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
80125 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
80126 }
80127
80128 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
80129 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
80130 if (ret == 0)
80131 goto no_payload_free;
80132
80133 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80134 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80135
80136 if (iov != iovstack)
80137 kfree(iov);
80138 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
80139 index 7445875..262834f 100644
80140 --- a/security/keys/keyring.c
80141 +++ b/security/keys/keyring.c
80142 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
80143 ret = -EFAULT;
80144
80145 for (loop = 0; loop < klist->nkeys; loop++) {
80146 + key_serial_t serial;
80147 key = rcu_deref_link_locked(klist, loop,
80148 keyring);
80149 + serial = key->serial;
80150
80151 tmp = sizeof(key_serial_t);
80152 if (tmp > buflen)
80153 tmp = buflen;
80154
80155 - if (copy_to_user(buffer,
80156 - &key->serial,
80157 - tmp) != 0)
80158 + if (copy_to_user(buffer, &serial, tmp))
80159 goto error;
80160
80161 buflen -= tmp;
80162 diff --git a/security/min_addr.c b/security/min_addr.c
80163 index f728728..6457a0c 100644
80164 --- a/security/min_addr.c
80165 +++ b/security/min_addr.c
80166 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
80167 */
80168 static void update_mmap_min_addr(void)
80169 {
80170 +#ifndef SPARC
80171 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80172 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80173 mmap_min_addr = dac_mmap_min_addr;
80174 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80175 #else
80176 mmap_min_addr = dac_mmap_min_addr;
80177 #endif
80178 +#endif
80179 }
80180
80181 /*
80182 diff --git a/security/security.c b/security/security.c
80183 index 860aeb3..45765c0 100644
80184 --- a/security/security.c
80185 +++ b/security/security.c
80186 @@ -20,6 +20,7 @@
80187 #include <linux/ima.h>
80188 #include <linux/evm.h>
80189 #include <linux/fsnotify.h>
80190 +#include <linux/mm.h>
80191 #include <linux/mman.h>
80192 #include <linux/mount.h>
80193 #include <linux/personality.h>
80194 @@ -32,8 +33,8 @@
80195 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
80196 CONFIG_DEFAULT_SECURITY;
80197
80198 -static struct security_operations *security_ops;
80199 -static struct security_operations default_security_ops = {
80200 +static struct security_operations *security_ops __read_only;
80201 +static struct security_operations default_security_ops __read_only = {
80202 .name = "default",
80203 };
80204
80205 @@ -74,7 +75,9 @@ int __init security_init(void)
80206
80207 void reset_security_ops(void)
80208 {
80209 + pax_open_kernel();
80210 security_ops = &default_security_ops;
80211 + pax_close_kernel();
80212 }
80213
80214 /* Save user chosen LSM */
80215 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80216 index ffd8900..0b1751b 100644
80217 --- a/security/selinux/hooks.c
80218 +++ b/security/selinux/hooks.c
80219 @@ -95,8 +95,6 @@
80220
80221 #define NUM_SEL_MNT_OPTS 5
80222
80223 -extern struct security_operations *security_ops;
80224 -
80225 /* SECMARK reference count */
80226 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80227
80228 @@ -2792,11 +2790,16 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
80229
80230 /* We strip a nul only if it is at the end, otherwise the
80231 * context contains a nul and we should audit that */
80232 - str = value;
80233 - if (str[size - 1] == '\0')
80234 - audit_size = size - 1;
80235 - else
80236 - audit_size = size;
80237 + if (value) {
80238 + str = value;
80239 + if (str[size - 1] == '\0')
80240 + audit_size = size - 1;
80241 + else
80242 + audit_size = size;
80243 + } else {
80244 + str = "";
80245 + audit_size = 0;
80246 + }
80247 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
80248 audit_log_format(ab, "op=setxattr invalid_context=");
80249 audit_log_n_untrustedstring(ab, value, audit_size);
80250 @@ -5506,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80251
80252 #endif
80253
80254 -static struct security_operations selinux_ops = {
80255 +static struct security_operations selinux_ops __read_only = {
80256 .name = "selinux",
80257
80258 .ptrace_access_check = selinux_ptrace_access_check,
80259 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80260 index c220f31..89fab3f 100644
80261 --- a/security/selinux/include/xfrm.h
80262 +++ b/security/selinux/include/xfrm.h
80263 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80264
80265 static inline void selinux_xfrm_notify_policyload(void)
80266 {
80267 - atomic_inc(&flow_cache_genid);
80268 + atomic_inc_unchecked(&flow_cache_genid);
80269 }
80270 #else
80271 static inline int selinux_xfrm_enabled(void)
80272 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80273 index ee0bb57..57fcd43 100644
80274 --- a/security/smack/smack_lsm.c
80275 +++ b/security/smack/smack_lsm.c
80276 @@ -3432,7 +3432,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80277 return 0;
80278 }
80279
80280 -struct security_operations smack_ops = {
80281 +struct security_operations smack_ops __read_only = {
80282 .name = "smack",
80283
80284 .ptrace_access_check = smack_ptrace_access_check,
80285 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80286 index c2d04a5..e6a1aeb 100644
80287 --- a/security/tomoyo/tomoyo.c
80288 +++ b/security/tomoyo/tomoyo.c
80289 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80290 * tomoyo_security_ops is a "struct security_operations" which is used for
80291 * registering TOMOYO.
80292 */
80293 -static struct security_operations tomoyo_security_ops = {
80294 +static struct security_operations tomoyo_security_ops __read_only = {
80295 .name = "tomoyo",
80296 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80297 .cred_prepare = tomoyo_cred_prepare,
80298 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
80299 index 51d6709..1f3dbe2 100644
80300 --- a/security/yama/Kconfig
80301 +++ b/security/yama/Kconfig
80302 @@ -1,6 +1,6 @@
80303 config SECURITY_YAMA
80304 bool "Yama support"
80305 - depends on SECURITY
80306 + depends on SECURITY && !GRKERNSEC
80307 select SECURITYFS
80308 select SECURITY_PATH
80309 default n
80310 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80311 index 270790d..c67dfcb 100644
80312 --- a/sound/aoa/codecs/onyx.c
80313 +++ b/sound/aoa/codecs/onyx.c
80314 @@ -54,7 +54,7 @@ struct onyx {
80315 spdif_locked:1,
80316 analog_locked:1,
80317 original_mute:2;
80318 - int open_count;
80319 + local_t open_count;
80320 struct codec_info *codec_info;
80321
80322 /* mutex serializes concurrent access to the device
80323 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80324 struct onyx *onyx = cii->codec_data;
80325
80326 mutex_lock(&onyx->mutex);
80327 - onyx->open_count++;
80328 + local_inc(&onyx->open_count);
80329 mutex_unlock(&onyx->mutex);
80330
80331 return 0;
80332 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80333 struct onyx *onyx = cii->codec_data;
80334
80335 mutex_lock(&onyx->mutex);
80336 - onyx->open_count--;
80337 - if (!onyx->open_count)
80338 + if (local_dec_and_test(&onyx->open_count))
80339 onyx->spdif_locked = onyx->analog_locked = 0;
80340 mutex_unlock(&onyx->mutex);
80341
80342 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80343 index ffd2025..df062c9 100644
80344 --- a/sound/aoa/codecs/onyx.h
80345 +++ b/sound/aoa/codecs/onyx.h
80346 @@ -11,6 +11,7 @@
80347 #include <linux/i2c.h>
80348 #include <asm/pmac_low_i2c.h>
80349 #include <asm/prom.h>
80350 +#include <asm/local.h>
80351
80352 /* PCM3052 register definitions */
80353
80354 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80355 index 08fde00..0bf641a 100644
80356 --- a/sound/core/oss/pcm_oss.c
80357 +++ b/sound/core/oss/pcm_oss.c
80358 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80359 if (in_kernel) {
80360 mm_segment_t fs;
80361 fs = snd_enter_user();
80362 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80363 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80364 snd_leave_user(fs);
80365 } else {
80366 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80367 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80368 }
80369 if (ret != -EPIPE && ret != -ESTRPIPE)
80370 break;
80371 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80372 if (in_kernel) {
80373 mm_segment_t fs;
80374 fs = snd_enter_user();
80375 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80376 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80377 snd_leave_user(fs);
80378 } else {
80379 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80380 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80381 }
80382 if (ret == -EPIPE) {
80383 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80384 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80385 struct snd_pcm_plugin_channel *channels;
80386 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80387 if (!in_kernel) {
80388 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80389 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80390 return -EFAULT;
80391 buf = runtime->oss.buffer;
80392 }
80393 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80394 }
80395 } else {
80396 tmp = snd_pcm_oss_write2(substream,
80397 - (const char __force *)buf,
80398 + (const char __force_kernel *)buf,
80399 runtime->oss.period_bytes, 0);
80400 if (tmp <= 0)
80401 goto err;
80402 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80403 struct snd_pcm_runtime *runtime = substream->runtime;
80404 snd_pcm_sframes_t frames, frames1;
80405 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80406 - char __user *final_dst = (char __force __user *)buf;
80407 + char __user *final_dst = (char __force_user *)buf;
80408 if (runtime->oss.plugin_first) {
80409 struct snd_pcm_plugin_channel *channels;
80410 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80411 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80412 xfer += tmp;
80413 runtime->oss.buffer_used -= tmp;
80414 } else {
80415 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80416 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80417 runtime->oss.period_bytes, 0);
80418 if (tmp <= 0)
80419 goto err;
80420 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80421 size1);
80422 size1 /= runtime->channels; /* frames */
80423 fs = snd_enter_user();
80424 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80425 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80426 snd_leave_user(fs);
80427 }
80428 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80429 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80430 index 91cdf94..4085161 100644
80431 --- a/sound/core/pcm_compat.c
80432 +++ b/sound/core/pcm_compat.c
80433 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80434 int err;
80435
80436 fs = snd_enter_user();
80437 - err = snd_pcm_delay(substream, &delay);
80438 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80439 snd_leave_user(fs);
80440 if (err < 0)
80441 return err;
80442 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80443 index 53b5ada..2db94c8 100644
80444 --- a/sound/core/pcm_native.c
80445 +++ b/sound/core/pcm_native.c
80446 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80447 switch (substream->stream) {
80448 case SNDRV_PCM_STREAM_PLAYBACK:
80449 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80450 - (void __user *)arg);
80451 + (void __force_user *)arg);
80452 break;
80453 case SNDRV_PCM_STREAM_CAPTURE:
80454 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80455 - (void __user *)arg);
80456 + (void __force_user *)arg);
80457 break;
80458 default:
80459 result = -EINVAL;
80460 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80461 index 5cf8d65..912a79c 100644
80462 --- a/sound/core/seq/seq_device.c
80463 +++ b/sound/core/seq/seq_device.c
80464 @@ -64,7 +64,7 @@ struct ops_list {
80465 int argsize; /* argument size */
80466
80467 /* operators */
80468 - struct snd_seq_dev_ops ops;
80469 + struct snd_seq_dev_ops *ops;
80470
80471 /* registred devices */
80472 struct list_head dev_list; /* list of devices */
80473 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80474
80475 mutex_lock(&ops->reg_mutex);
80476 /* copy driver operators */
80477 - ops->ops = *entry;
80478 + ops->ops = entry;
80479 ops->driver |= DRIVER_LOADED;
80480 ops->argsize = argsize;
80481
80482 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80483 dev->name, ops->id, ops->argsize, dev->argsize);
80484 return -EINVAL;
80485 }
80486 - if (ops->ops.init_device(dev) >= 0) {
80487 + if (ops->ops->init_device(dev) >= 0) {
80488 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80489 ops->num_init_devices++;
80490 } else {
80491 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80492 dev->name, ops->id, ops->argsize, dev->argsize);
80493 return -EINVAL;
80494 }
80495 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80496 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80497 dev->status = SNDRV_SEQ_DEVICE_FREE;
80498 dev->driver_data = NULL;
80499 ops->num_init_devices--;
80500 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80501 index 621e60e..f4543f5 100644
80502 --- a/sound/drivers/mts64.c
80503 +++ b/sound/drivers/mts64.c
80504 @@ -29,6 +29,7 @@
80505 #include <sound/initval.h>
80506 #include <sound/rawmidi.h>
80507 #include <sound/control.h>
80508 +#include <asm/local.h>
80509
80510 #define CARD_NAME "Miditerminal 4140"
80511 #define DRIVER_NAME "MTS64"
80512 @@ -67,7 +68,7 @@ struct mts64 {
80513 struct pardevice *pardev;
80514 int pardev_claimed;
80515
80516 - int open_count;
80517 + local_t open_count;
80518 int current_midi_output_port;
80519 int current_midi_input_port;
80520 u8 mode[MTS64_NUM_INPUT_PORTS];
80521 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80522 {
80523 struct mts64 *mts = substream->rmidi->private_data;
80524
80525 - if (mts->open_count == 0) {
80526 + if (local_read(&mts->open_count) == 0) {
80527 /* We don't need a spinlock here, because this is just called
80528 if the device has not been opened before.
80529 So there aren't any IRQs from the device */
80530 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80531
80532 msleep(50);
80533 }
80534 - ++(mts->open_count);
80535 + local_inc(&mts->open_count);
80536
80537 return 0;
80538 }
80539 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80540 struct mts64 *mts = substream->rmidi->private_data;
80541 unsigned long flags;
80542
80543 - --(mts->open_count);
80544 - if (mts->open_count == 0) {
80545 + if (local_dec_return(&mts->open_count) == 0) {
80546 /* We need the spinlock_irqsave here because we can still
80547 have IRQs at this point */
80548 spin_lock_irqsave(&mts->lock, flags);
80549 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80550
80551 msleep(500);
80552
80553 - } else if (mts->open_count < 0)
80554 - mts->open_count = 0;
80555 + } else if (local_read(&mts->open_count) < 0)
80556 + local_set(&mts->open_count, 0);
80557
80558 return 0;
80559 }
80560 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
80561 index b953fb4..1999c01 100644
80562 --- a/sound/drivers/opl4/opl4_lib.c
80563 +++ b/sound/drivers/opl4/opl4_lib.c
80564 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
80565 MODULE_DESCRIPTION("OPL4 driver");
80566 MODULE_LICENSE("GPL");
80567
80568 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
80569 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
80570 {
80571 int timeout = 10;
80572 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
80573 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
80574 index 3e32bd3..46fc152 100644
80575 --- a/sound/drivers/portman2x4.c
80576 +++ b/sound/drivers/portman2x4.c
80577 @@ -48,6 +48,7 @@
80578 #include <sound/initval.h>
80579 #include <sound/rawmidi.h>
80580 #include <sound/control.h>
80581 +#include <asm/local.h>
80582
80583 #define CARD_NAME "Portman 2x4"
80584 #define DRIVER_NAME "portman"
80585 @@ -85,7 +86,7 @@ struct portman {
80586 struct pardevice *pardev;
80587 int pardev_claimed;
80588
80589 - int open_count;
80590 + local_t open_count;
80591 int mode[PORTMAN_NUM_INPUT_PORTS];
80592 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80593 };
80594 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
80595 index ea995af..f1bfa37 100644
80596 --- a/sound/firewire/amdtp.c
80597 +++ b/sound/firewire/amdtp.c
80598 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
80599 ptr = s->pcm_buffer_pointer + data_blocks;
80600 if (ptr >= pcm->runtime->buffer_size)
80601 ptr -= pcm->runtime->buffer_size;
80602 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
80603 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
80604
80605 s->pcm_period_pointer += data_blocks;
80606 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
80607 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
80608 */
80609 void amdtp_out_stream_update(struct amdtp_out_stream *s)
80610 {
80611 - ACCESS_ONCE(s->source_node_id_field) =
80612 + ACCESS_ONCE_RW(s->source_node_id_field) =
80613 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
80614 }
80615 EXPORT_SYMBOL(amdtp_out_stream_update);
80616 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
80617 index b680c5e..061b7a0 100644
80618 --- a/sound/firewire/amdtp.h
80619 +++ b/sound/firewire/amdtp.h
80620 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
80621 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
80622 struct snd_pcm_substream *pcm)
80623 {
80624 - ACCESS_ONCE(s->pcm) = pcm;
80625 + ACCESS_ONCE_RW(s->pcm) = pcm;
80626 }
80627
80628 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
80629 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
80630 index d428ffe..751ef78 100644
80631 --- a/sound/firewire/isight.c
80632 +++ b/sound/firewire/isight.c
80633 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
80634 ptr += count;
80635 if (ptr >= runtime->buffer_size)
80636 ptr -= runtime->buffer_size;
80637 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
80638 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
80639
80640 isight->period_counter += count;
80641 if (isight->period_counter >= runtime->period_size) {
80642 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
80643 if (err < 0)
80644 return err;
80645
80646 - ACCESS_ONCE(isight->pcm_active) = true;
80647 + ACCESS_ONCE_RW(isight->pcm_active) = true;
80648
80649 return 0;
80650 }
80651 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
80652 {
80653 struct isight *isight = substream->private_data;
80654
80655 - ACCESS_ONCE(isight->pcm_active) = false;
80656 + ACCESS_ONCE_RW(isight->pcm_active) = false;
80657
80658 mutex_lock(&isight->mutex);
80659 isight_stop_streaming(isight);
80660 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
80661
80662 switch (cmd) {
80663 case SNDRV_PCM_TRIGGER_START:
80664 - ACCESS_ONCE(isight->pcm_running) = true;
80665 + ACCESS_ONCE_RW(isight->pcm_running) = true;
80666 break;
80667 case SNDRV_PCM_TRIGGER_STOP:
80668 - ACCESS_ONCE(isight->pcm_running) = false;
80669 + ACCESS_ONCE_RW(isight->pcm_running) = false;
80670 break;
80671 default:
80672 return -EINVAL;
80673 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
80674 index 7bd5e33..1fcab12 100644
80675 --- a/sound/isa/cmi8330.c
80676 +++ b/sound/isa/cmi8330.c
80677 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
80678
80679 struct snd_pcm *pcm;
80680 struct snd_cmi8330_stream {
80681 - struct snd_pcm_ops ops;
80682 + snd_pcm_ops_no_const ops;
80683 snd_pcm_open_callback_t open;
80684 void *private_data; /* sb or wss */
80685 } streams[2];
80686 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
80687 index 733b014..56ce96f 100644
80688 --- a/sound/oss/sb_audio.c
80689 +++ b/sound/oss/sb_audio.c
80690 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
80691 buf16 = (signed short *)(localbuf + localoffs);
80692 while (c)
80693 {
80694 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80695 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
80696 if (copy_from_user(lbuf8,
80697 userbuf+useroffs + p,
80698 locallen))
80699 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
80700 index 09d4648..cf234c7 100644
80701 --- a/sound/oss/swarm_cs4297a.c
80702 +++ b/sound/oss/swarm_cs4297a.c
80703 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
80704 {
80705 struct cs4297a_state *s;
80706 u32 pwr, id;
80707 - mm_segment_t fs;
80708 int rval;
80709 #ifndef CONFIG_BCM_CS4297A_CSWARM
80710 u64 cfg;
80711 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
80712 if (!rval) {
80713 char *sb1250_duart_present;
80714
80715 +#if 0
80716 + mm_segment_t fs;
80717 fs = get_fs();
80718 set_fs(KERNEL_DS);
80719 -#if 0
80720 val = SOUND_MASK_LINE;
80721 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
80722 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
80723 val = initvol[i].vol;
80724 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
80725 }
80726 + set_fs(fs);
80727 // cs4297a_write_ac97(s, 0x18, 0x0808);
80728 #else
80729 // cs4297a_write_ac97(s, 0x5e, 0x180);
80730 cs4297a_write_ac97(s, 0x02, 0x0808);
80731 cs4297a_write_ac97(s, 0x18, 0x0808);
80732 #endif
80733 - set_fs(fs);
80734
80735 list_add(&s->list, &cs4297a_devs);
80736
80737 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
80738 index 2fdaadb..7df8fc6 100644
80739 --- a/sound/pci/hda/hda_codec.h
80740 +++ b/sound/pci/hda/hda_codec.h
80741 @@ -611,7 +611,7 @@ struct hda_bus_ops {
80742 /* notify power-up/down from codec to controller */
80743 void (*pm_notify)(struct hda_bus *bus);
80744 #endif
80745 -};
80746 +} __no_const;
80747
80748 /* template to pass to the bus constructor */
80749 struct hda_bus_template {
80750 @@ -711,6 +711,7 @@ struct hda_codec_ops {
80751 #endif
80752 void (*reboot_notify)(struct hda_codec *codec);
80753 };
80754 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
80755
80756 /* record for amp information cache */
80757 struct hda_cache_head {
80758 @@ -741,7 +742,7 @@ struct hda_pcm_ops {
80759 struct snd_pcm_substream *substream);
80760 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
80761 struct snd_pcm_substream *substream);
80762 -};
80763 +} __no_const;
80764
80765 /* PCM information for each substream */
80766 struct hda_pcm_stream {
80767 @@ -799,7 +800,7 @@ struct hda_codec {
80768 const char *modelname; /* model name for preset */
80769
80770 /* set by patch */
80771 - struct hda_codec_ops patch_ops;
80772 + hda_codec_ops_no_const patch_ops;
80773
80774 /* PCM to create, set by patch_ops.build_pcms callback */
80775 unsigned int num_pcms;
80776 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
80777 index 0da778a..bc38b84 100644
80778 --- a/sound/pci/ice1712/ice1712.h
80779 +++ b/sound/pci/ice1712/ice1712.h
80780 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
80781 unsigned int mask_flags; /* total mask bits */
80782 struct snd_akm4xxx_ops {
80783 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
80784 - } ops;
80785 + } __no_const ops;
80786 };
80787
80788 struct snd_ice1712_spdif {
80789 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
80790 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80791 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80792 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
80793 - } ops;
80794 + } __no_const ops;
80795 };
80796
80797
80798 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
80799 index a8159b81..5f006a5 100644
80800 --- a/sound/pci/ymfpci/ymfpci_main.c
80801 +++ b/sound/pci/ymfpci/ymfpci_main.c
80802 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
80803 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
80804 break;
80805 }
80806 - if (atomic_read(&chip->interrupt_sleep_count)) {
80807 - atomic_set(&chip->interrupt_sleep_count, 0);
80808 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80809 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80810 wake_up(&chip->interrupt_sleep);
80811 }
80812 __end:
80813 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
80814 continue;
80815 init_waitqueue_entry(&wait, current);
80816 add_wait_queue(&chip->interrupt_sleep, &wait);
80817 - atomic_inc(&chip->interrupt_sleep_count);
80818 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
80819 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
80820 remove_wait_queue(&chip->interrupt_sleep, &wait);
80821 }
80822 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
80823 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
80824 spin_unlock(&chip->reg_lock);
80825
80826 - if (atomic_read(&chip->interrupt_sleep_count)) {
80827 - atomic_set(&chip->interrupt_sleep_count, 0);
80828 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
80829 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80830 wake_up(&chip->interrupt_sleep);
80831 }
80832 }
80833 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80834 spin_lock_init(&chip->reg_lock);
80835 spin_lock_init(&chip->voice_lock);
80836 init_waitqueue_head(&chip->interrupt_sleep);
80837 - atomic_set(&chip->interrupt_sleep_count, 0);
80838 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80839 chip->card = card;
80840 chip->pci = pci;
80841 chip->irq = -1;
80842 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
80843 new file mode 100644
80844 index 0000000..50f2f2f
80845 --- /dev/null
80846 +++ b/tools/gcc/.gitignore
80847 @@ -0,0 +1 @@
80848 +size_overflow_hash.h
80849 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80850 new file mode 100644
80851 index 0000000..1d09b7e
80852 --- /dev/null
80853 +++ b/tools/gcc/Makefile
80854 @@ -0,0 +1,43 @@
80855 +#CC := gcc
80856 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80857 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80858 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80859 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80860 +
80861 +ifeq ($(PLUGINCC),$(HOSTCC))
80862 +HOSTLIBS := hostlibs
80863 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80864 +else
80865 +HOSTLIBS := hostcxxlibs
80866 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
80867 +endif
80868 +
80869 +$(HOSTLIBS)-y := constify_plugin.so
80870 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80871 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80872 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80873 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80874 +$(HOSTLIBS)-y += colorize_plugin.so
80875 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80876 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
80877 +
80878 +always := $($(HOSTLIBS)-y)
80879 +
80880 +constify_plugin-objs := constify_plugin.o
80881 +stackleak_plugin-objs := stackleak_plugin.o
80882 +kallocstat_plugin-objs := kallocstat_plugin.o
80883 +kernexec_plugin-objs := kernexec_plugin.o
80884 +checker_plugin-objs := checker_plugin.o
80885 +colorize_plugin-objs := colorize_plugin.o
80886 +size_overflow_plugin-objs := size_overflow_plugin.o
80887 +latent_entropy_plugin-objs := latent_entropy_plugin.o
80888 +
80889 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
80890 +
80891 +quiet_cmd_build_size_overflow_hash = GENHASH $@
80892 + cmd_build_size_overflow_hash = \
80893 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
80894 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
80895 + $(call if_changed,build_size_overflow_hash)
80896 +
80897 +targets += size_overflow_hash.h
80898 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80899 new file mode 100644
80900 index 0000000..d41b5af
80901 --- /dev/null
80902 +++ b/tools/gcc/checker_plugin.c
80903 @@ -0,0 +1,171 @@
80904 +/*
80905 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80906 + * Licensed under the GPL v2
80907 + *
80908 + * Note: the choice of the license means that the compilation process is
80909 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80910 + * but for the kernel it doesn't matter since it doesn't link against
80911 + * any of the gcc libraries
80912 + *
80913 + * gcc plugin to implement various sparse (source code checker) features
80914 + *
80915 + * TODO:
80916 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80917 + *
80918 + * BUGS:
80919 + * - none known
80920 + */
80921 +#include "gcc-plugin.h"
80922 +#include "config.h"
80923 +#include "system.h"
80924 +#include "coretypes.h"
80925 +#include "tree.h"
80926 +#include "tree-pass.h"
80927 +#include "flags.h"
80928 +#include "intl.h"
80929 +#include "toplev.h"
80930 +#include "plugin.h"
80931 +//#include "expr.h" where are you...
80932 +#include "diagnostic.h"
80933 +#include "plugin-version.h"
80934 +#include "tm.h"
80935 +#include "function.h"
80936 +#include "basic-block.h"
80937 +#include "gimple.h"
80938 +#include "rtl.h"
80939 +#include "emit-rtl.h"
80940 +#include "tree-flow.h"
80941 +#include "target.h"
80942 +
80943 +extern void c_register_addr_space (const char *str, addr_space_t as);
80944 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80945 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80946 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80947 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80948 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80949 +
80950 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80951 +extern rtx emit_move_insn(rtx x, rtx y);
80952 +
80953 +int plugin_is_GPL_compatible;
80954 +
80955 +static struct plugin_info checker_plugin_info = {
80956 + .version = "201111150100",
80957 +};
80958 +
80959 +#define ADDR_SPACE_KERNEL 0
80960 +#define ADDR_SPACE_FORCE_KERNEL 1
80961 +#define ADDR_SPACE_USER 2
80962 +#define ADDR_SPACE_FORCE_USER 3
80963 +#define ADDR_SPACE_IOMEM 0
80964 +#define ADDR_SPACE_FORCE_IOMEM 0
80965 +#define ADDR_SPACE_PERCPU 0
80966 +#define ADDR_SPACE_FORCE_PERCPU 0
80967 +#define ADDR_SPACE_RCU 0
80968 +#define ADDR_SPACE_FORCE_RCU 0
80969 +
80970 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80971 +{
80972 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80973 +}
80974 +
80975 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80976 +{
80977 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80978 +}
80979 +
80980 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80981 +{
80982 + return default_addr_space_valid_pointer_mode(mode, as);
80983 +}
80984 +
80985 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80986 +{
80987 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80988 +}
80989 +
80990 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80991 +{
80992 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80993 +}
80994 +
80995 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80996 +{
80997 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80998 + return true;
80999 +
81000 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
81001 + return true;
81002 +
81003 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
81004 + return true;
81005 +
81006 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
81007 + return true;
81008 +
81009 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
81010 + return true;
81011 +
81012 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
81013 + return true;
81014 +
81015 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
81016 + return true;
81017 +
81018 + return subset == superset;
81019 +}
81020 +
81021 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
81022 +{
81023 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
81024 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
81025 +
81026 + return op;
81027 +}
81028 +
81029 +static void register_checker_address_spaces(void *event_data, void *data)
81030 +{
81031 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
81032 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
81033 + c_register_addr_space("__user", ADDR_SPACE_USER);
81034 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
81035 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
81036 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
81037 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
81038 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
81039 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
81040 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
81041 +
81042 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
81043 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
81044 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
81045 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
81046 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
81047 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
81048 + targetm.addr_space.convert = checker_addr_space_convert;
81049 +}
81050 +
81051 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81052 +{
81053 + const char * const plugin_name = plugin_info->base_name;
81054 + const int argc = plugin_info->argc;
81055 + const struct plugin_argument * const argv = plugin_info->argv;
81056 + int i;
81057 +
81058 + if (!plugin_default_version_check(version, &gcc_version)) {
81059 + error(G_("incompatible gcc/plugin versions"));
81060 + return 1;
81061 + }
81062 +
81063 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
81064 +
81065 + for (i = 0; i < argc; ++i)
81066 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81067 +
81068 + if (TARGET_64BIT == 0)
81069 + return 0;
81070 +
81071 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
81072 +
81073 + return 0;
81074 +}
81075 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
81076 new file mode 100644
81077 index 0000000..846aeb0
81078 --- /dev/null
81079 +++ b/tools/gcc/colorize_plugin.c
81080 @@ -0,0 +1,148 @@
81081 +/*
81082 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
81083 + * Licensed under the GPL v2
81084 + *
81085 + * Note: the choice of the license means that the compilation process is
81086 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81087 + * but for the kernel it doesn't matter since it doesn't link against
81088 + * any of the gcc libraries
81089 + *
81090 + * gcc plugin to colorize diagnostic output
81091 + *
81092 + */
81093 +
81094 +#include "gcc-plugin.h"
81095 +#include "config.h"
81096 +#include "system.h"
81097 +#include "coretypes.h"
81098 +#include "tree.h"
81099 +#include "tree-pass.h"
81100 +#include "flags.h"
81101 +#include "intl.h"
81102 +#include "toplev.h"
81103 +#include "plugin.h"
81104 +#include "diagnostic.h"
81105 +#include "plugin-version.h"
81106 +#include "tm.h"
81107 +
81108 +int plugin_is_GPL_compatible;
81109 +
81110 +static struct plugin_info colorize_plugin_info = {
81111 + .version = "201203092200",
81112 + .help = NULL,
81113 +};
81114 +
81115 +#define GREEN "\033[32m\033[2m"
81116 +#define LIGHTGREEN "\033[32m\033[1m"
81117 +#define YELLOW "\033[33m\033[2m"
81118 +#define LIGHTYELLOW "\033[33m\033[1m"
81119 +#define RED "\033[31m\033[2m"
81120 +#define LIGHTRED "\033[31m\033[1m"
81121 +#define BLUE "\033[34m\033[2m"
81122 +#define LIGHTBLUE "\033[34m\033[1m"
81123 +#define BRIGHT "\033[m\033[1m"
81124 +#define NORMAL "\033[m"
81125 +
81126 +static diagnostic_starter_fn old_starter;
81127 +static diagnostic_finalizer_fn old_finalizer;
81128 +
81129 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81130 +{
81131 + const char *color;
81132 + char *newprefix;
81133 +
81134 + switch (diagnostic->kind) {
81135 + case DK_NOTE:
81136 + color = LIGHTBLUE;
81137 + break;
81138 +
81139 + case DK_PEDWARN:
81140 + case DK_WARNING:
81141 + color = LIGHTYELLOW;
81142 + break;
81143 +
81144 + case DK_ERROR:
81145 + case DK_FATAL:
81146 + case DK_ICE:
81147 + case DK_PERMERROR:
81148 + case DK_SORRY:
81149 + color = LIGHTRED;
81150 + break;
81151 +
81152 + default:
81153 + color = NORMAL;
81154 + }
81155 +
81156 + old_starter(context, diagnostic);
81157 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
81158 + return;
81159 + pp_destroy_prefix(context->printer);
81160 + pp_set_prefix(context->printer, newprefix);
81161 +}
81162 +
81163 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81164 +{
81165 + old_finalizer(context, diagnostic);
81166 +}
81167 +
81168 +static void colorize_arm(void)
81169 +{
81170 + old_starter = diagnostic_starter(global_dc);
81171 + old_finalizer = diagnostic_finalizer(global_dc);
81172 +
81173 + diagnostic_starter(global_dc) = start_colorize;
81174 + diagnostic_finalizer(global_dc) = finalize_colorize;
81175 +}
81176 +
81177 +static unsigned int execute_colorize_rearm(void)
81178 +{
81179 + if (diagnostic_starter(global_dc) == start_colorize)
81180 + return 0;
81181 +
81182 + colorize_arm();
81183 + return 0;
81184 +}
81185 +
81186 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
81187 + .pass = {
81188 + .type = SIMPLE_IPA_PASS,
81189 + .name = "colorize_rearm",
81190 + .gate = NULL,
81191 + .execute = execute_colorize_rearm,
81192 + .sub = NULL,
81193 + .next = NULL,
81194 + .static_pass_number = 0,
81195 + .tv_id = TV_NONE,
81196 + .properties_required = 0,
81197 + .properties_provided = 0,
81198 + .properties_destroyed = 0,
81199 + .todo_flags_start = 0,
81200 + .todo_flags_finish = 0
81201 + }
81202 +};
81203 +
81204 +static void colorize_start_unit(void *gcc_data, void *user_data)
81205 +{
81206 + colorize_arm();
81207 +}
81208 +
81209 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81210 +{
81211 + const char * const plugin_name = plugin_info->base_name;
81212 + struct register_pass_info colorize_rearm_pass_info = {
81213 + .pass = &pass_ipa_colorize_rearm.pass,
81214 + .reference_pass_name = "*free_lang_data",
81215 + .ref_pass_instance_number = 1,
81216 + .pos_op = PASS_POS_INSERT_AFTER
81217 + };
81218 +
81219 + if (!plugin_default_version_check(version, &gcc_version)) {
81220 + error(G_("incompatible gcc/plugin versions"));
81221 + return 1;
81222 + }
81223 +
81224 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
81225 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
81226 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
81227 + return 0;
81228 +}
81229 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
81230 new file mode 100644
81231 index 0000000..048d4ff
81232 --- /dev/null
81233 +++ b/tools/gcc/constify_plugin.c
81234 @@ -0,0 +1,328 @@
81235 +/*
81236 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81237 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81238 + * Licensed under the GPL v2, or (at your option) v3
81239 + *
81240 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81241 + *
81242 + * Homepage:
81243 + * http://www.grsecurity.net/~ephox/const_plugin/
81244 + *
81245 + * Usage:
81246 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81247 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81248 + */
81249 +
81250 +#include "gcc-plugin.h"
81251 +#include "config.h"
81252 +#include "system.h"
81253 +#include "coretypes.h"
81254 +#include "tree.h"
81255 +#include "tree-pass.h"
81256 +#include "flags.h"
81257 +#include "intl.h"
81258 +#include "toplev.h"
81259 +#include "plugin.h"
81260 +#include "diagnostic.h"
81261 +#include "plugin-version.h"
81262 +#include "tm.h"
81263 +#include "function.h"
81264 +#include "basic-block.h"
81265 +#include "gimple.h"
81266 +#include "rtl.h"
81267 +#include "emit-rtl.h"
81268 +#include "tree-flow.h"
81269 +
81270 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81271 +
81272 +int plugin_is_GPL_compatible;
81273 +
81274 +static struct plugin_info const_plugin_info = {
81275 + .version = "201205300030",
81276 + .help = "no-constify\tturn off constification\n",
81277 +};
81278 +
81279 +static void deconstify_tree(tree node);
81280 +
81281 +static void deconstify_type(tree type)
81282 +{
81283 + tree field;
81284 +
81285 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
81286 + tree type = TREE_TYPE(field);
81287 +
81288 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81289 + continue;
81290 + if (!TYPE_READONLY(type))
81291 + continue;
81292 +
81293 + deconstify_tree(field);
81294 + }
81295 + TYPE_READONLY(type) = 0;
81296 + C_TYPE_FIELDS_READONLY(type) = 0;
81297 +}
81298 +
81299 +static void deconstify_tree(tree node)
81300 +{
81301 + tree old_type, new_type, field;
81302 +
81303 + old_type = TREE_TYPE(node);
81304 +
81305 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
81306 +
81307 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81308 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81309 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81310 + DECL_FIELD_CONTEXT(field) = new_type;
81311 +
81312 + deconstify_type(new_type);
81313 +
81314 + TREE_READONLY(node) = 0;
81315 + TREE_TYPE(node) = new_type;
81316 +}
81317 +
81318 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81319 +{
81320 + tree type;
81321 +
81322 + *no_add_attrs = true;
81323 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81324 + error("%qE attribute does not apply to functions", name);
81325 + return NULL_TREE;
81326 + }
81327 +
81328 + if (TREE_CODE(*node) == VAR_DECL) {
81329 + error("%qE attribute does not apply to variables", name);
81330 + return NULL_TREE;
81331 + }
81332 +
81333 + if (TYPE_P(*node)) {
81334 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81335 + *no_add_attrs = false;
81336 + else
81337 + error("%qE attribute applies to struct and union types only", name);
81338 + return NULL_TREE;
81339 + }
81340 +
81341 + type = TREE_TYPE(*node);
81342 +
81343 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81344 + error("%qE attribute applies to struct and union types only", name);
81345 + return NULL_TREE;
81346 + }
81347 +
81348 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81349 + error("%qE attribute is already applied to the type", name);
81350 + return NULL_TREE;
81351 + }
81352 +
81353 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81354 + error("%qE attribute used on type that is not constified", name);
81355 + return NULL_TREE;
81356 + }
81357 +
81358 + if (TREE_CODE(*node) == TYPE_DECL) {
81359 + deconstify_tree(*node);
81360 + return NULL_TREE;
81361 + }
81362 +
81363 + return NULL_TREE;
81364 +}
81365 +
81366 +static void constify_type(tree type)
81367 +{
81368 + TYPE_READONLY(type) = 1;
81369 + C_TYPE_FIELDS_READONLY(type) = 1;
81370 +}
81371 +
81372 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81373 +{
81374 + *no_add_attrs = true;
81375 + if (!TYPE_P(*node)) {
81376 + error("%qE attribute applies to types only", name);
81377 + return NULL_TREE;
81378 + }
81379 +
81380 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81381 + error("%qE attribute applies to struct and union types only", name);
81382 + return NULL_TREE;
81383 + }
81384 +
81385 + *no_add_attrs = false;
81386 + constify_type(*node);
81387 + return NULL_TREE;
81388 +}
81389 +
81390 +static struct attribute_spec no_const_attr = {
81391 + .name = "no_const",
81392 + .min_length = 0,
81393 + .max_length = 0,
81394 + .decl_required = false,
81395 + .type_required = false,
81396 + .function_type_required = false,
81397 + .handler = handle_no_const_attribute,
81398 +#if BUILDING_GCC_VERSION >= 4007
81399 + .affects_type_identity = true
81400 +#endif
81401 +};
81402 +
81403 +static struct attribute_spec do_const_attr = {
81404 + .name = "do_const",
81405 + .min_length = 0,
81406 + .max_length = 0,
81407 + .decl_required = false,
81408 + .type_required = false,
81409 + .function_type_required = false,
81410 + .handler = handle_do_const_attribute,
81411 +#if BUILDING_GCC_VERSION >= 4007
81412 + .affects_type_identity = true
81413 +#endif
81414 +};
81415 +
81416 +static void register_attributes(void *event_data, void *data)
81417 +{
81418 + register_attribute(&no_const_attr);
81419 + register_attribute(&do_const_attr);
81420 +}
81421 +
81422 +static bool is_fptr(tree field)
81423 +{
81424 + tree ptr = TREE_TYPE(field);
81425 +
81426 + if (TREE_CODE(ptr) != POINTER_TYPE)
81427 + return false;
81428 +
81429 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81430 +}
81431 +
81432 +static bool walk_struct(tree node)
81433 +{
81434 + tree field;
81435 +
81436 + if (TYPE_FIELDS(node) == NULL_TREE)
81437 + return false;
81438 +
81439 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
81440 + gcc_assert(!TYPE_READONLY(node));
81441 + deconstify_type(node);
81442 + return false;
81443 + }
81444 +
81445 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81446 + tree type = TREE_TYPE(field);
81447 + enum tree_code code = TREE_CODE(type);
81448 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81449 + if (!(walk_struct(type)))
81450 + return false;
81451 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81452 + return false;
81453 + }
81454 + return true;
81455 +}
81456 +
81457 +static void finish_type(void *event_data, void *data)
81458 +{
81459 + tree type = (tree)event_data;
81460 +
81461 + if (type == NULL_TREE)
81462 + return;
81463 +
81464 + if (TYPE_READONLY(type))
81465 + return;
81466 +
81467 + if (walk_struct(type))
81468 + constify_type(type);
81469 +}
81470 +
81471 +static unsigned int check_local_variables(void);
81472 +
81473 +struct gimple_opt_pass pass_local_variable = {
81474 + {
81475 + .type = GIMPLE_PASS,
81476 + .name = "check_local_variables",
81477 + .gate = NULL,
81478 + .execute = check_local_variables,
81479 + .sub = NULL,
81480 + .next = NULL,
81481 + .static_pass_number = 0,
81482 + .tv_id = TV_NONE,
81483 + .properties_required = 0,
81484 + .properties_provided = 0,
81485 + .properties_destroyed = 0,
81486 + .todo_flags_start = 0,
81487 + .todo_flags_finish = 0
81488 + }
81489 +};
81490 +
81491 +static unsigned int check_local_variables(void)
81492 +{
81493 + tree var;
81494 + referenced_var_iterator rvi;
81495 +
81496 +#if BUILDING_GCC_VERSION == 4005
81497 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81498 +#else
81499 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81500 +#endif
81501 + tree type = TREE_TYPE(var);
81502 +
81503 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81504 + continue;
81505 +
81506 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81507 + continue;
81508 +
81509 + if (!TYPE_READONLY(type))
81510 + continue;
81511 +
81512 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81513 +// continue;
81514 +
81515 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81516 +// continue;
81517 +
81518 + if (walk_struct(type)) {
81519 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
81520 + return 1;
81521 + }
81522 + }
81523 + return 0;
81524 +}
81525 +
81526 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81527 +{
81528 + const char * const plugin_name = plugin_info->base_name;
81529 + const int argc = plugin_info->argc;
81530 + const struct plugin_argument * const argv = plugin_info->argv;
81531 + int i;
81532 + bool constify = true;
81533 +
81534 + struct register_pass_info local_variable_pass_info = {
81535 + .pass = &pass_local_variable.pass,
81536 + .reference_pass_name = "*referenced_vars",
81537 + .ref_pass_instance_number = 1,
81538 + .pos_op = PASS_POS_INSERT_AFTER
81539 + };
81540 +
81541 + if (!plugin_default_version_check(version, &gcc_version)) {
81542 + error(G_("incompatible gcc/plugin versions"));
81543 + return 1;
81544 + }
81545 +
81546 + for (i = 0; i < argc; ++i) {
81547 + if (!(strcmp(argv[i].key, "no-constify"))) {
81548 + constify = false;
81549 + continue;
81550 + }
81551 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81552 + }
81553 +
81554 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81555 + if (constify) {
81556 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81557 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81558 + }
81559 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
81560 +
81561 + return 0;
81562 +}
81563 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
81564 new file mode 100644
81565 index 0000000..a0fe8b2
81566 --- /dev/null
81567 +++ b/tools/gcc/generate_size_overflow_hash.sh
81568 @@ -0,0 +1,94 @@
81569 +#!/bin/bash
81570 +
81571 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
81572 +
81573 +header1="size_overflow_hash.h"
81574 +database="size_overflow_hash.data"
81575 +n=65536
81576 +
81577 +usage() {
81578 +cat <<EOF
81579 +usage: $0 options
81580 +OPTIONS:
81581 + -h|--help help
81582 + -o header file
81583 + -d database file
81584 + -n hash array size
81585 +EOF
81586 + return 0
81587 +}
81588 +
81589 +while true
81590 +do
81591 + case "$1" in
81592 + -h|--help) usage && exit 0;;
81593 + -n) n=$2; shift 2;;
81594 + -o) header1="$2"; shift 2;;
81595 + -d) database="$2"; shift 2;;
81596 + --) shift 1; break ;;
81597 + *) break ;;
81598 + esac
81599 +done
81600 +
81601 +create_defines() {
81602 + for i in `seq 1 10`
81603 + do
81604 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
81605 + done
81606 + echo >> "$header1"
81607 +}
81608 +
81609 +create_structs () {
81610 + rm -f "$header1"
81611 +
81612 + create_defines
81613 +
81614 + cat "$database" | while read data
81615 + do
81616 + data_array=($data)
81617 + struct_hash_name="${data_array[0]}"
81618 + funcn="${data_array[1]}"
81619 + params="${data_array[2]}"
81620 + next="${data_array[5]}"
81621 +
81622 + echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
81623 +
81624 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
81625 + echo -en "\t.param\t= " >> "$header1"
81626 + line=
81627 + for param_num in ${params//-/ };
81628 + do
81629 + line="${line}PARAM"$param_num"|"
81630 + done
81631 +
81632 + echo -e "${line%?},\n};\n" >> "$header1"
81633 + done
81634 +}
81635 +
81636 +create_headers () {
81637 + echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
81638 +}
81639 +
81640 +create_array_elements () {
81641 + index=0
81642 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
81643 + do
81644 + data_array=($data)
81645 + i="${data_array[3]}"
81646 + hash="${data_array[4]}"
81647 + while [[ $index -lt $i ]]
81648 + do
81649 + echo -e "\t["$index"]\t= NULL," >> "$header1"
81650 + index=$(($index + 1))
81651 + done
81652 + index=$(($index + 1))
81653 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
81654 + done
81655 + echo '};' >> $header1
81656 +}
81657 +
81658 +create_structs
81659 +create_headers
81660 +create_array_elements
81661 +
81662 +exit 0
81663 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
81664 new file mode 100644
81665 index 0000000..a86e422
81666 --- /dev/null
81667 +++ b/tools/gcc/kallocstat_plugin.c
81668 @@ -0,0 +1,167 @@
81669 +/*
81670 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81671 + * Licensed under the GPL v2
81672 + *
81673 + * Note: the choice of the license means that the compilation process is
81674 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81675 + * but for the kernel it doesn't matter since it doesn't link against
81676 + * any of the gcc libraries
81677 + *
81678 + * gcc plugin to find the distribution of k*alloc sizes
81679 + *
81680 + * TODO:
81681 + *
81682 + * BUGS:
81683 + * - none known
81684 + */
81685 +#include "gcc-plugin.h"
81686 +#include "config.h"
81687 +#include "system.h"
81688 +#include "coretypes.h"
81689 +#include "tree.h"
81690 +#include "tree-pass.h"
81691 +#include "flags.h"
81692 +#include "intl.h"
81693 +#include "toplev.h"
81694 +#include "plugin.h"
81695 +//#include "expr.h" where are you...
81696 +#include "diagnostic.h"
81697 +#include "plugin-version.h"
81698 +#include "tm.h"
81699 +#include "function.h"
81700 +#include "basic-block.h"
81701 +#include "gimple.h"
81702 +#include "rtl.h"
81703 +#include "emit-rtl.h"
81704 +
81705 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81706 +
81707 +int plugin_is_GPL_compatible;
81708 +
81709 +static const char * const kalloc_functions[] = {
81710 + "__kmalloc",
81711 + "kmalloc",
81712 + "kmalloc_large",
81713 + "kmalloc_node",
81714 + "kmalloc_order",
81715 + "kmalloc_order_trace",
81716 + "kmalloc_slab",
81717 + "kzalloc",
81718 + "kzalloc_node",
81719 +};
81720 +
81721 +static struct plugin_info kallocstat_plugin_info = {
81722 + .version = "201111150100",
81723 +};
81724 +
81725 +static unsigned int execute_kallocstat(void);
81726 +
81727 +static struct gimple_opt_pass kallocstat_pass = {
81728 + .pass = {
81729 + .type = GIMPLE_PASS,
81730 + .name = "kallocstat",
81731 + .gate = NULL,
81732 + .execute = execute_kallocstat,
81733 + .sub = NULL,
81734 + .next = NULL,
81735 + .static_pass_number = 0,
81736 + .tv_id = TV_NONE,
81737 + .properties_required = 0,
81738 + .properties_provided = 0,
81739 + .properties_destroyed = 0,
81740 + .todo_flags_start = 0,
81741 + .todo_flags_finish = 0
81742 + }
81743 +};
81744 +
81745 +static bool is_kalloc(const char *fnname)
81746 +{
81747 + size_t i;
81748 +
81749 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
81750 + if (!strcmp(fnname, kalloc_functions[i]))
81751 + return true;
81752 + return false;
81753 +}
81754 +
81755 +static unsigned int execute_kallocstat(void)
81756 +{
81757 + basic_block bb;
81758 +
81759 + // 1. loop through BBs and GIMPLE statements
81760 + FOR_EACH_BB(bb) {
81761 + gimple_stmt_iterator gsi;
81762 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81763 + // gimple match:
81764 + tree fndecl, size;
81765 + gimple call_stmt;
81766 + const char *fnname;
81767 +
81768 + // is it a call
81769 + call_stmt = gsi_stmt(gsi);
81770 + if (!is_gimple_call(call_stmt))
81771 + continue;
81772 + fndecl = gimple_call_fndecl(call_stmt);
81773 + if (fndecl == NULL_TREE)
81774 + continue;
81775 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
81776 + continue;
81777 +
81778 + // is it a call to k*alloc
81779 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
81780 + if (!is_kalloc(fnname))
81781 + continue;
81782 +
81783 + // is the size arg the result of a simple const assignment
81784 + size = gimple_call_arg(call_stmt, 0);
81785 + while (true) {
81786 + gimple def_stmt;
81787 + expanded_location xloc;
81788 + size_t size_val;
81789 +
81790 + if (TREE_CODE(size) != SSA_NAME)
81791 + break;
81792 + def_stmt = SSA_NAME_DEF_STMT(size);
81793 + if (!def_stmt || !is_gimple_assign(def_stmt))
81794 + break;
81795 + if (gimple_num_ops(def_stmt) != 2)
81796 + break;
81797 + size = gimple_assign_rhs1(def_stmt);
81798 + if (!TREE_CONSTANT(size))
81799 + continue;
81800 + xloc = expand_location(gimple_location(def_stmt));
81801 + if (!xloc.file)
81802 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
81803 + size_val = TREE_INT_CST_LOW(size);
81804 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
81805 + break;
81806 + }
81807 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81808 +//debug_tree(gimple_call_fn(call_stmt));
81809 +//print_node(stderr, "pax", fndecl, 4);
81810 + }
81811 + }
81812 +
81813 + return 0;
81814 +}
81815 +
81816 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81817 +{
81818 + const char * const plugin_name = plugin_info->base_name;
81819 + struct register_pass_info kallocstat_pass_info = {
81820 + .pass = &kallocstat_pass.pass,
81821 + .reference_pass_name = "ssa",
81822 + .ref_pass_instance_number = 1,
81823 + .pos_op = PASS_POS_INSERT_AFTER
81824 + };
81825 +
81826 + if (!plugin_default_version_check(version, &gcc_version)) {
81827 + error(G_("incompatible gcc/plugin versions"));
81828 + return 1;
81829 + }
81830 +
81831 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
81832 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
81833 +
81834 + return 0;
81835 +}
81836 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
81837 new file mode 100644
81838 index 0000000..98011fa
81839 --- /dev/null
81840 +++ b/tools/gcc/kernexec_plugin.c
81841 @@ -0,0 +1,427 @@
81842 +/*
81843 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81844 + * Licensed under the GPL v2
81845 + *
81846 + * Note: the choice of the license means that the compilation process is
81847 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81848 + * but for the kernel it doesn't matter since it doesn't link against
81849 + * any of the gcc libraries
81850 + *
81851 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
81852 + *
81853 + * TODO:
81854 + *
81855 + * BUGS:
81856 + * - none known
81857 + */
81858 +#include "gcc-plugin.h"
81859 +#include "config.h"
81860 +#include "system.h"
81861 +#include "coretypes.h"
81862 +#include "tree.h"
81863 +#include "tree-pass.h"
81864 +#include "flags.h"
81865 +#include "intl.h"
81866 +#include "toplev.h"
81867 +#include "plugin.h"
81868 +//#include "expr.h" where are you...
81869 +#include "diagnostic.h"
81870 +#include "plugin-version.h"
81871 +#include "tm.h"
81872 +#include "function.h"
81873 +#include "basic-block.h"
81874 +#include "gimple.h"
81875 +#include "rtl.h"
81876 +#include "emit-rtl.h"
81877 +#include "tree-flow.h"
81878 +
81879 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81880 +extern rtx emit_move_insn(rtx x, rtx y);
81881 +
81882 +int plugin_is_GPL_compatible;
81883 +
81884 +static struct plugin_info kernexec_plugin_info = {
81885 + .version = "201111291120",
81886 + .help = "method=[bts|or]\tinstrumentation method\n"
81887 +};
81888 +
81889 +static unsigned int execute_kernexec_reload(void);
81890 +static unsigned int execute_kernexec_fptr(void);
81891 +static unsigned int execute_kernexec_retaddr(void);
81892 +static bool kernexec_cmodel_check(void);
81893 +
81894 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
81895 +static void (*kernexec_instrument_retaddr)(rtx);
81896 +
81897 +static struct gimple_opt_pass kernexec_reload_pass = {
81898 + .pass = {
81899 + .type = GIMPLE_PASS,
81900 + .name = "kernexec_reload",
81901 + .gate = kernexec_cmodel_check,
81902 + .execute = execute_kernexec_reload,
81903 + .sub = NULL,
81904 + .next = NULL,
81905 + .static_pass_number = 0,
81906 + .tv_id = TV_NONE,
81907 + .properties_required = 0,
81908 + .properties_provided = 0,
81909 + .properties_destroyed = 0,
81910 + .todo_flags_start = 0,
81911 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81912 + }
81913 +};
81914 +
81915 +static struct gimple_opt_pass kernexec_fptr_pass = {
81916 + .pass = {
81917 + .type = GIMPLE_PASS,
81918 + .name = "kernexec_fptr",
81919 + .gate = kernexec_cmodel_check,
81920 + .execute = execute_kernexec_fptr,
81921 + .sub = NULL,
81922 + .next = NULL,
81923 + .static_pass_number = 0,
81924 + .tv_id = TV_NONE,
81925 + .properties_required = 0,
81926 + .properties_provided = 0,
81927 + .properties_destroyed = 0,
81928 + .todo_flags_start = 0,
81929 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81930 + }
81931 +};
81932 +
81933 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81934 + .pass = {
81935 + .type = RTL_PASS,
81936 + .name = "kernexec_retaddr",
81937 + .gate = kernexec_cmodel_check,
81938 + .execute = execute_kernexec_retaddr,
81939 + .sub = NULL,
81940 + .next = NULL,
81941 + .static_pass_number = 0,
81942 + .tv_id = TV_NONE,
81943 + .properties_required = 0,
81944 + .properties_provided = 0,
81945 + .properties_destroyed = 0,
81946 + .todo_flags_start = 0,
81947 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81948 + }
81949 +};
81950 +
81951 +static bool kernexec_cmodel_check(void)
81952 +{
81953 + tree section;
81954 +
81955 + if (ix86_cmodel != CM_KERNEL)
81956 + return false;
81957 +
81958 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81959 + if (!section || !TREE_VALUE(section))
81960 + return true;
81961 +
81962 + section = TREE_VALUE(TREE_VALUE(section));
81963 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81964 + return true;
81965 +
81966 + return false;
81967 +}
81968 +
81969 +/*
81970 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81971 + */
81972 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81973 +{
81974 + gimple asm_movabs_stmt;
81975 +
81976 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81977 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81978 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81979 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81980 + update_stmt(asm_movabs_stmt);
81981 +}
81982 +
81983 +/*
81984 + * find all asm() stmts that clobber r10 and add a reload of r10
81985 + */
81986 +static unsigned int execute_kernexec_reload(void)
81987 +{
81988 + basic_block bb;
81989 +
81990 + // 1. loop through BBs and GIMPLE statements
81991 + FOR_EACH_BB(bb) {
81992 + gimple_stmt_iterator gsi;
81993 +
81994 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81995 + // gimple match: __asm__ ("" : : : "r10");
81996 + gimple asm_stmt;
81997 + size_t nclobbers;
81998 +
81999 + // is it an asm ...
82000 + asm_stmt = gsi_stmt(gsi);
82001 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
82002 + continue;
82003 +
82004 + // ... clobbering r10
82005 + nclobbers = gimple_asm_nclobbers(asm_stmt);
82006 + while (nclobbers--) {
82007 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
82008 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
82009 + continue;
82010 + kernexec_reload_fptr_mask(&gsi);
82011 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
82012 + break;
82013 + }
82014 + }
82015 + }
82016 +
82017 + return 0;
82018 +}
82019 +
82020 +/*
82021 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
82022 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
82023 + */
82024 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
82025 +{
82026 + gimple assign_intptr, assign_new_fptr, call_stmt;
82027 + tree intptr, old_fptr, new_fptr, kernexec_mask;
82028 +
82029 + call_stmt = gsi_stmt(*gsi);
82030 + old_fptr = gimple_call_fn(call_stmt);
82031 +
82032 + // create temporary unsigned long variable used for bitops and cast fptr to it
82033 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
82034 + add_referenced_var(intptr);
82035 + mark_sym_for_renaming(intptr);
82036 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
82037 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82038 + update_stmt(assign_intptr);
82039 +
82040 + // apply logical or to temporary unsigned long and bitmask
82041 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
82042 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
82043 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
82044 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82045 + update_stmt(assign_intptr);
82046 +
82047 + // cast temporary unsigned long back to a temporary fptr variable
82048 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
82049 + add_referenced_var(new_fptr);
82050 + mark_sym_for_renaming(new_fptr);
82051 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
82052 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
82053 + update_stmt(assign_new_fptr);
82054 +
82055 + // replace call stmt fn with the new fptr
82056 + gimple_call_set_fn(call_stmt, new_fptr);
82057 + update_stmt(call_stmt);
82058 +}
82059 +
82060 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
82061 +{
82062 + gimple asm_or_stmt, call_stmt;
82063 + tree old_fptr, new_fptr, input, output;
82064 + VEC(tree, gc) *inputs = NULL;
82065 + VEC(tree, gc) *outputs = NULL;
82066 +
82067 + call_stmt = gsi_stmt(*gsi);
82068 + old_fptr = gimple_call_fn(call_stmt);
82069 +
82070 + // create temporary fptr variable
82071 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
82072 + add_referenced_var(new_fptr);
82073 + mark_sym_for_renaming(new_fptr);
82074 +
82075 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
82076 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
82077 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
82078 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
82079 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
82080 + VEC_safe_push(tree, gc, inputs, input);
82081 + VEC_safe_push(tree, gc, outputs, output);
82082 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
82083 + gimple_asm_set_volatile(asm_or_stmt, true);
82084 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
82085 + update_stmt(asm_or_stmt);
82086 +
82087 + // replace call stmt fn with the new fptr
82088 + gimple_call_set_fn(call_stmt, new_fptr);
82089 + update_stmt(call_stmt);
82090 +}
82091 +
82092 +/*
82093 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
82094 + */
82095 +static unsigned int execute_kernexec_fptr(void)
82096 +{
82097 + basic_block bb;
82098 +
82099 + // 1. loop through BBs and GIMPLE statements
82100 + FOR_EACH_BB(bb) {
82101 + gimple_stmt_iterator gsi;
82102 +
82103 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82104 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
82105 + tree fn;
82106 + gimple call_stmt;
82107 +
82108 + // is it a call ...
82109 + call_stmt = gsi_stmt(gsi);
82110 + if (!is_gimple_call(call_stmt))
82111 + continue;
82112 + fn = gimple_call_fn(call_stmt);
82113 + if (TREE_CODE(fn) == ADDR_EXPR)
82114 + continue;
82115 + if (TREE_CODE(fn) != SSA_NAME)
82116 + gcc_unreachable();
82117 +
82118 + // ... through a function pointer
82119 + fn = SSA_NAME_VAR(fn);
82120 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
82121 + continue;
82122 + fn = TREE_TYPE(fn);
82123 + if (TREE_CODE(fn) != POINTER_TYPE)
82124 + continue;
82125 + fn = TREE_TYPE(fn);
82126 + if (TREE_CODE(fn) != FUNCTION_TYPE)
82127 + continue;
82128 +
82129 + kernexec_instrument_fptr(&gsi);
82130 +
82131 +//debug_tree(gimple_call_fn(call_stmt));
82132 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82133 + }
82134 + }
82135 +
82136 + return 0;
82137 +}
82138 +
82139 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
82140 +static void kernexec_instrument_retaddr_bts(rtx insn)
82141 +{
82142 + rtx btsq;
82143 + rtvec argvec, constraintvec, labelvec;
82144 + int line;
82145 +
82146 + // create asm volatile("btsq $63,(%%rsp)":::)
82147 + argvec = rtvec_alloc(0);
82148 + constraintvec = rtvec_alloc(0);
82149 + labelvec = rtvec_alloc(0);
82150 + line = expand_location(RTL_LOCATION(insn)).line;
82151 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82152 + MEM_VOLATILE_P(btsq) = 1;
82153 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
82154 + emit_insn_before(btsq, insn);
82155 +}
82156 +
82157 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
82158 +static void kernexec_instrument_retaddr_or(rtx insn)
82159 +{
82160 + rtx orq;
82161 + rtvec argvec, constraintvec, labelvec;
82162 + int line;
82163 +
82164 + // create asm volatile("orq %%r10,(%%rsp)":::)
82165 + argvec = rtvec_alloc(0);
82166 + constraintvec = rtvec_alloc(0);
82167 + labelvec = rtvec_alloc(0);
82168 + line = expand_location(RTL_LOCATION(insn)).line;
82169 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82170 + MEM_VOLATILE_P(orq) = 1;
82171 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
82172 + emit_insn_before(orq, insn);
82173 +}
82174 +
82175 +/*
82176 + * find all asm level function returns and forcibly set the highest bit of the return address
82177 + */
82178 +static unsigned int execute_kernexec_retaddr(void)
82179 +{
82180 + rtx insn;
82181 +
82182 + // 1. find function returns
82183 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82184 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
82185 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
82186 + rtx body;
82187 +
82188 + // is it a retn
82189 + if (!JUMP_P(insn))
82190 + continue;
82191 + body = PATTERN(insn);
82192 + if (GET_CODE(body) == PARALLEL)
82193 + body = XVECEXP(body, 0, 0);
82194 + if (GET_CODE(body) != RETURN)
82195 + continue;
82196 + kernexec_instrument_retaddr(insn);
82197 + }
82198 +
82199 +// print_simple_rtl(stderr, get_insns());
82200 +// print_rtl(stderr, get_insns());
82201 +
82202 + return 0;
82203 +}
82204 +
82205 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82206 +{
82207 + const char * const plugin_name = plugin_info->base_name;
82208 + const int argc = plugin_info->argc;
82209 + const struct plugin_argument * const argv = plugin_info->argv;
82210 + int i;
82211 + struct register_pass_info kernexec_reload_pass_info = {
82212 + .pass = &kernexec_reload_pass.pass,
82213 + .reference_pass_name = "ssa",
82214 + .ref_pass_instance_number = 1,
82215 + .pos_op = PASS_POS_INSERT_AFTER
82216 + };
82217 + struct register_pass_info kernexec_fptr_pass_info = {
82218 + .pass = &kernexec_fptr_pass.pass,
82219 + .reference_pass_name = "ssa",
82220 + .ref_pass_instance_number = 1,
82221 + .pos_op = PASS_POS_INSERT_AFTER
82222 + };
82223 + struct register_pass_info kernexec_retaddr_pass_info = {
82224 + .pass = &kernexec_retaddr_pass.pass,
82225 + .reference_pass_name = "pro_and_epilogue",
82226 + .ref_pass_instance_number = 1,
82227 + .pos_op = PASS_POS_INSERT_AFTER
82228 + };
82229 +
82230 + if (!plugin_default_version_check(version, &gcc_version)) {
82231 + error(G_("incompatible gcc/plugin versions"));
82232 + return 1;
82233 + }
82234 +
82235 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
82236 +
82237 + if (TARGET_64BIT == 0)
82238 + return 0;
82239 +
82240 + for (i = 0; i < argc; ++i) {
82241 + if (!strcmp(argv[i].key, "method")) {
82242 + if (!argv[i].value) {
82243 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82244 + continue;
82245 + }
82246 + if (!strcmp(argv[i].value, "bts")) {
82247 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
82248 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
82249 + } else if (!strcmp(argv[i].value, "or")) {
82250 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
82251 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
82252 + fix_register("r10", 1, 1);
82253 + } else
82254 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82255 + continue;
82256 + }
82257 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82258 + }
82259 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
82260 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
82261 +
82262 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
82263 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
82264 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
82265 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
82266 +
82267 + return 0;
82268 +}
82269 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
82270 new file mode 100644
82271 index 0000000..b8008f7
82272 --- /dev/null
82273 +++ b/tools/gcc/latent_entropy_plugin.c
82274 @@ -0,0 +1,295 @@
82275 +/*
82276 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
82277 + * Licensed under the GPL v2
82278 + *
82279 + * Note: the choice of the license means that the compilation process is
82280 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82281 + * but for the kernel it doesn't matter since it doesn't link against
82282 + * any of the gcc libraries
82283 + *
82284 + * gcc plugin to help generate a little bit of entropy from program state,
82285 + * used during boot in the kernel
82286 + *
82287 + * TODO:
82288 + * - add ipa pass to identify not explicitly marked candidate functions
82289 + * - mix in more program state (function arguments/return values, loop variables, etc)
82290 + * - more instrumentation control via attribute parameters
82291 + *
82292 + * BUGS:
82293 + * - LTO needs -flto-partition=none for now
82294 + */
82295 +#include "gcc-plugin.h"
82296 +#include "config.h"
82297 +#include "system.h"
82298 +#include "coretypes.h"
82299 +#include "tree.h"
82300 +#include "tree-pass.h"
82301 +#include "flags.h"
82302 +#include "intl.h"
82303 +#include "toplev.h"
82304 +#include "plugin.h"
82305 +//#include "expr.h" where are you...
82306 +#include "diagnostic.h"
82307 +#include "plugin-version.h"
82308 +#include "tm.h"
82309 +#include "function.h"
82310 +#include "basic-block.h"
82311 +#include "gimple.h"
82312 +#include "rtl.h"
82313 +#include "emit-rtl.h"
82314 +#include "tree-flow.h"
82315 +
82316 +int plugin_is_GPL_compatible;
82317 +
82318 +static tree latent_entropy_decl;
82319 +
82320 +static struct plugin_info latent_entropy_plugin_info = {
82321 + .version = "201207271820",
82322 + .help = NULL
82323 +};
82324 +
82325 +static unsigned int execute_latent_entropy(void);
82326 +static bool gate_latent_entropy(void);
82327 +
82328 +static struct gimple_opt_pass latent_entropy_pass = {
82329 + .pass = {
82330 + .type = GIMPLE_PASS,
82331 + .name = "latent_entropy",
82332 + .gate = gate_latent_entropy,
82333 + .execute = execute_latent_entropy,
82334 + .sub = NULL,
82335 + .next = NULL,
82336 + .static_pass_number = 0,
82337 + .tv_id = TV_NONE,
82338 + .properties_required = PROP_gimple_leh | PROP_cfg,
82339 + .properties_provided = 0,
82340 + .properties_destroyed = 0,
82341 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
82342 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
82343 + }
82344 +};
82345 +
82346 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82347 +{
82348 + if (TREE_CODE(*node) != FUNCTION_DECL) {
82349 + *no_add_attrs = true;
82350 + error("%qE attribute only applies to functions", name);
82351 + }
82352 + return NULL_TREE;
82353 +}
82354 +
82355 +static struct attribute_spec latent_entropy_attr = {
82356 + .name = "latent_entropy",
82357 + .min_length = 0,
82358 + .max_length = 0,
82359 + .decl_required = true,
82360 + .type_required = false,
82361 + .function_type_required = false,
82362 + .handler = handle_latent_entropy_attribute,
82363 +#if BUILDING_GCC_VERSION >= 4007
82364 + .affects_type_identity = false
82365 +#endif
82366 +};
82367 +
82368 +static void register_attributes(void *event_data, void *data)
82369 +{
82370 + register_attribute(&latent_entropy_attr);
82371 +}
82372 +
82373 +static bool gate_latent_entropy(void)
82374 +{
82375 + tree latent_entropy_attr;
82376 +
82377 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
82378 + return latent_entropy_attr != NULL_TREE;
82379 +}
82380 +
82381 +static unsigned HOST_WIDE_INT seed;
82382 +static unsigned HOST_WIDE_INT get_random_const(void)
82383 +{
82384 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
82385 + return seed;
82386 +}
82387 +
82388 +static enum tree_code get_op(tree *rhs)
82389 +{
82390 + static enum tree_code op;
82391 + unsigned HOST_WIDE_INT random_const;
82392 +
82393 + random_const = get_random_const();
82394 +
82395 + switch (op) {
82396 + case BIT_XOR_EXPR:
82397 + op = PLUS_EXPR;
82398 + break;
82399 +
82400 + case PLUS_EXPR:
82401 + if (rhs) {
82402 + op = LROTATE_EXPR;
82403 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
82404 + break;
82405 + }
82406 +
82407 + case LROTATE_EXPR:
82408 + default:
82409 + op = BIT_XOR_EXPR;
82410 + break;
82411 + }
82412 + if (rhs)
82413 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
82414 + return op;
82415 +}
82416 +
82417 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
82418 +{
82419 + gimple_stmt_iterator gsi;
82420 + gimple assign;
82421 + tree addxorrol, rhs;
82422 + enum tree_code op;
82423 +
82424 + op = get_op(&rhs);
82425 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
82426 + assign = gimple_build_assign(local_entropy, addxorrol);
82427 + find_referenced_vars_in(assign);
82428 +//debug_bb(bb);
82429 + gsi = gsi_after_labels(bb);
82430 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
82431 + update_stmt(assign);
82432 +}
82433 +
82434 +static void perturb_latent_entropy(basic_block bb, tree rhs)
82435 +{
82436 + gimple_stmt_iterator gsi;
82437 + gimple assign;
82438 + tree addxorrol, temp;
82439 +
82440 + // 1. create temporary copy of latent_entropy
82441 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
82442 + add_referenced_var(temp);
82443 + mark_sym_for_renaming(temp);
82444 +
82445 + // 2. read...
82446 + assign = gimple_build_assign(temp, latent_entropy_decl);
82447 + find_referenced_vars_in(assign);
82448 + gsi = gsi_after_labels(bb);
82449 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82450 + update_stmt(assign);
82451 +
82452 + // 3. ...modify...
82453 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
82454 + assign = gimple_build_assign(temp, addxorrol);
82455 + find_referenced_vars_in(assign);
82456 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82457 + update_stmt(assign);
82458 +
82459 + // 4. ...write latent_entropy
82460 + assign = gimple_build_assign(latent_entropy_decl, temp);
82461 + find_referenced_vars_in(assign);
82462 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82463 + update_stmt(assign);
82464 +}
82465 +
82466 +static unsigned int execute_latent_entropy(void)
82467 +{
82468 + basic_block bb;
82469 + gimple assign;
82470 + gimple_stmt_iterator gsi;
82471 + tree local_entropy;
82472 +
82473 + if (!latent_entropy_decl) {
82474 + struct varpool_node *node;
82475 +
82476 + for (node = varpool_nodes; node; node = node->next) {
82477 + tree var = node->decl;
82478 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
82479 + continue;
82480 + latent_entropy_decl = var;
82481 +// debug_tree(var);
82482 + break;
82483 + }
82484 + if (!latent_entropy_decl) {
82485 +// debug_tree(current_function_decl);
82486 + return 0;
82487 + }
82488 + }
82489 +
82490 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
82491 +
82492 + // 1. create local entropy variable
82493 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
82494 + add_referenced_var(local_entropy);
82495 + mark_sym_for_renaming(local_entropy);
82496 +
82497 + // 2. initialize local entropy variable
82498 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
82499 + if (dom_info_available_p(CDI_DOMINATORS))
82500 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
82501 + gsi = gsi_start_bb(bb);
82502 +
82503 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
82504 +// gimple_set_location(assign, loc);
82505 + find_referenced_vars_in(assign);
82506 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
82507 + update_stmt(assign);
82508 + bb = bb->next_bb;
82509 +
82510 + // 3. instrument each BB with an operation on the local entropy variable
82511 + while (bb != EXIT_BLOCK_PTR) {
82512 + perturb_local_entropy(bb, local_entropy);
82513 + bb = bb->next_bb;
82514 + };
82515 +
82516 + // 4. mix local entropy into the global entropy variable
82517 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
82518 + return 0;
82519 +}
82520 +
82521 +static void start_unit_callback(void *gcc_data, void *user_data)
82522 +{
82523 +#if BUILDING_GCC_VERSION >= 4007
82524 + seed = get_random_seed(false);
82525 +#else
82526 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
82527 + seed *= seed;
82528 +#endif
82529 +
82530 + if (in_lto_p)
82531 + return;
82532 +
82533 + // extern u64 latent_entropy
82534 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
82535 +
82536 + TREE_STATIC(latent_entropy_decl) = 1;
82537 + TREE_PUBLIC(latent_entropy_decl) = 1;
82538 + TREE_USED(latent_entropy_decl) = 1;
82539 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
82540 + DECL_EXTERNAL(latent_entropy_decl) = 1;
82541 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
82542 + DECL_INITIAL(latent_entropy_decl) = NULL;
82543 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
82544 +// varpool_finalize_decl(latent_entropy_decl);
82545 +// varpool_mark_needed_node(latent_entropy_decl);
82546 +}
82547 +
82548 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82549 +{
82550 + const char * const plugin_name = plugin_info->base_name;
82551 + struct register_pass_info latent_entropy_pass_info = {
82552 + .pass = &latent_entropy_pass.pass,
82553 + .reference_pass_name = "optimized",
82554 + .ref_pass_instance_number = 1,
82555 + .pos_op = PASS_POS_INSERT_BEFORE
82556 + };
82557 +
82558 + if (!plugin_default_version_check(version, &gcc_version)) {
82559 + error(G_("incompatible gcc/plugin versions"));
82560 + return 1;
82561 + }
82562 +
82563 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
82564 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
82565 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
82566 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82567 +
82568 + return 0;
82569 +}
82570 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
82571 new file mode 100644
82572 index 0000000..daaa86c
82573 --- /dev/null
82574 +++ b/tools/gcc/size_overflow_hash.data
82575 @@ -0,0 +1,2486 @@
82576 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
82577 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
82578 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
82579 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
82580 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
82581 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
82582 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
82583 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
82584 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
82585 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
82586 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
82587 +_000013_hash kmemdup 2 64015 _000013_hash NULL
82588 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
82589 +_000015_hash memdup_user 2 59590 _000015_hash NULL
82590 +_000016_hash module_alloc 1 63630 _000016_hash NULL
82591 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
82592 +_000018_hash read_kcore 3 63488 _000018_hash NULL
82593 +_000019_hash read_ldt 2 47570 _000019_hash NULL
82594 +_000020_hash read_zero 3 19366 _000020_hash NULL
82595 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
82596 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
82597 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
82598 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
82599 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
82600 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
82601 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
82602 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
82603 +_000029_hash adu_write 3 30487 _000029_hash NULL
82604 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
82605 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
82606 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
82607 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
82608 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
82609 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
82610 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
82611 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
82612 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
82613 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
82614 +_000041_hash alloc_context 1 3194 _000041_hash NULL
82615 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
82616 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
82617 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
82618 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
82619 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
82620 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
82621 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
82622 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
82623 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
82624 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
82625 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
82626 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
82627 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
82628 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
82629 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
82630 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
82631 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
82632 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
82633 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
82634 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
82635 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
82636 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
82637 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
82638 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
82639 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
82640 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
82641 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
82642 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
82643 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
82644 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
82645 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
82646 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
82647 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
82648 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
82649 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
82650 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
82651 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
82652 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
82653 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
82654 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
82655 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
82656 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
82657 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
82658 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
82659 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
82660 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
82661 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
82662 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
82663 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
82664 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
82665 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
82666 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
82667 +_000096_hash capi_write 3 35104 _000096_hash NULL
82668 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
82669 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
82670 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
82671 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
82672 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
82673 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
82674 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
82675 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
82676 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
82677 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
82678 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
82679 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
82680 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
82681 +_000111_hash change_xattr 5 61390 _000111_hash NULL
82682 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
82683 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
82684 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
82685 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
82686 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
82687 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
82688 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
82689 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
82690 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
82691 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
82692 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
82693 +_000123_hash cmm_write 3 2896 _000123_hash NULL
82694 +_000124_hash cm_write 3 36858 _000124_hash NULL
82695 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
82696 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
82697 +_000127_hash command_file_write 3 31318 _000127_hash NULL
82698 +_000128_hash command_write 3 58841 _000128_hash NULL
82699 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
82700 +_000130_hash concat_writev 3 21451 _000130_hash NULL
82701 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
82702 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
82703 +_000133_hash copy_items 6 50140 _000133_hash NULL
82704 +_000134_hash copy_macs 4 45534 _000134_hash NULL
82705 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
82706 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
82707 +_000137_hash cosa_write 3 1774 _000137_hash NULL
82708 +_000138_hash create_entry 2 33479 _000138_hash NULL
82709 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
82710 +_000141_hash create_xattr 5 54106 _000141_hash NULL
82711 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
82712 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
82713 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
82714 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
82715 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
82716 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
82717 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
82718 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
82719 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
82720 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
82721 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
82722 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
82723 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
82724 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
82725 +_000158_hash dev_config 3 8506 _000158_hash NULL
82726 +_000159_hash device_write 3 45156 _000159_hash NULL
82727 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
82728 +_000161_hash devres_alloc 2 551 _000161_hash NULL
82729 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
82730 +_000163_hash direct_entry 3 38836 _000163_hash NULL
82731 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
82732 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
82733 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
82734 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
82735 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
82736 +_000169_hash dm_read 3 15674 _000169_hash NULL
82737 +_000170_hash dm_write 3 2513 _000170_hash NULL
82738 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
82739 +_000172_hash dns_query 3 9676 _000172_hash NULL
82740 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
82741 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
82742 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
82743 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
82744 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
82745 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
82746 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
82747 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
82748 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
82749 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
82750 +_000183_hash dsp_write 2 46218 _000183_hash NULL
82751 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
82752 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
82753 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
82754 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
82755 +_000188_hash dvb_play 3 50814 _000188_hash NULL
82756 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
82757 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
82758 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
82759 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
82760 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
82761 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
82762 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
82763 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
82764 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
82765 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
82766 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
82767 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
82768 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
82769 +_000202_hash ep_read 3 58813 _000202_hash NULL
82770 +_000203_hash ep_write 3 59008 _000203_hash NULL
82771 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
82772 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
82773 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
82774 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
82775 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
82776 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
82777 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
82778 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
82779 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
82780 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
82781 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
82782 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
82783 +_000216_hash fl_create 5 56435 _000216_hash NULL
82784 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
82785 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
82786 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
82787 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
82788 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
82789 +_000222_hash get_arg 3 5694 _000222_hash NULL
82790 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
82791 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
82792 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
82793 +_000226_hash get_registers 3 26187 _000226_hash NULL
82794 +_000227_hash get_scq 2 10897 _000227_hash NULL
82795 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
82796 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
82797 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
82798 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
82799 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
82800 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
82801 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
82802 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
82803 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
82804 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
82805 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
82806 +_000239_hash handle_request 9 10024 _000239_hash NULL
82807 +_000240_hash hash_new 1 62224 _000240_hash NULL
82808 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
82809 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
82810 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
82811 +_000244_hash heap_init 2 49617 _000244_hash NULL
82812 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
82813 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
82814 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
82815 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
82816 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
82817 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
82818 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
82819 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
82820 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
82821 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
82822 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
82823 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
82824 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
82825 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
82826 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
82827 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
82828 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
82829 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
82830 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
82831 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
82832 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
82833 +_000266_hash ieee80211_build_probe_req 7 27660 _000266_hash NULL
82834 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
82835 +_000268_hash if_write 3 51756 _000268_hash NULL
82836 +_000269_hash ilo_write 3 64378 _000269_hash NULL
82837 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
82838 +_000271_hash init_data_container 1 60709 _000271_hash NULL
82839 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
82840 +_000273_hash insert_dent 7 65034 _000273_hash NULL
82841 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
82842 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
82843 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
82844 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
82845 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
82846 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
82847 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
82848 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
82849 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
82850 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
82851 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
82852 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
82853 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
82854 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
82855 +_000288_hash irias_new_octseq_value 2 13596 _000288_hash NULL
82856 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
82857 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
82858 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
82859 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
82860 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
82861 +_000294_hash isdn_read 3 50021 _000294_hash NULL
82862 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
82863 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
82864 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
82865 +_000298_hash iso_callback 3 43208 _000298_hash NULL
82866 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
82867 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
82868 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
82869 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
82870 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
82871 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
82872 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
82873 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
82874 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
82875 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
82876 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
82877 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
82878 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
82879 +_000314_hash kmalloc_node 1 50163 _000314_hash NULL
82880 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
82881 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
82882 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
82883 +_000319_hash kone_receive 4 4690 _000319_hash NULL
82884 +_000320_hash kone_send 4 63435 _000320_hash NULL
82885 +_000321_hash krealloc 2 14908 _000321_hash NULL
82886 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
82887 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
82888 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
82889 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
82890 +_000326_hash kzalloc 1 54740 _000326_hash NULL
82891 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
82892 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
82893 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
82894 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
82895 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
82896 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
82897 +_000333_hash __lgread 4 31668 _000333_hash NULL
82898 +_000334_hash libipw_alloc_txb 1 27579 _000334_hash NULL
82899 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
82900 +_000336_hash listxattr 3 12769 _000336_hash NULL
82901 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
82902 +_000338_hash load_msg 2 95 _000338_hash NULL
82903 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
82904 +_000340_hash lp_write 3 9511 _000340_hash NULL
82905 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
82906 +_000342_hash mce_write 3 26201 _000342_hash NULL
82907 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
82908 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
82909 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
82910 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
82911 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
82912 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
82913 +_000350_hash mem_rw 3 22085 _000350_hash NULL
82914 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
82915 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
82916 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
82917 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
82918 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
82919 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
82920 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
82921 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
82922 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
82923 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
82924 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
82925 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
82926 +_000363_hash mtdchar_write 3 56831 _000363_hash NULL
82927 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
82928 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
82929 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
82930 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
82931 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
82932 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
82933 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
82934 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
82935 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
82936 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
82937 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
82938 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
82939 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
82940 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
82941 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
82942 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
82943 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
82944 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
82945 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
82946 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
82947 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
82948 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
82949 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
82950 +_000391_hash nvram_write 3 3894 _000391_hash NULL
82951 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
82952 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
82953 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
82954 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
82955 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
82956 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
82957 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
82958 +_000399_hash opticon_write 4 60775 _000399_hash NULL
82959 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
82960 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
82961 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
82962 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
82963 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
82964 +_000405_hash parse_command 2 37079 _000405_hash NULL
82965 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
82966 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
82967 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
82968 +_000409_hash pg_write 3 40766 _000409_hash NULL
82969 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
82970 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
82971 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
82972 +_000413_hash pkt_add 3 39897 _000413_hash NULL
82973 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
82974 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
82975 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
82976 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
82977 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
82978 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
82979 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
82980 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
82981 +_000422_hash ppp_write 3 34034 _000422_hash NULL
82982 +_000423_hash pp_read 3 33210 _000423_hash NULL
82983 +_000424_hash pp_write 3 39554 _000424_hash NULL
82984 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
82985 +_000426_hash printer_write 3 60276 _000426_hash NULL
82986 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
82987 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
82988 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
82989 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
82990 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
82991 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
82992 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
82993 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
82994 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
82995 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
82996 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
82997 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
82998 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
82999 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
83000 +_000442_hash pt_write 3 40159 _000442_hash NULL
83001 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
83002 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
83003 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
83004 +_000446_hash r3964_write 4 57662 _000446_hash NULL
83005 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
83006 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
83007 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
83008 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
83009 +_000451_hash rbd_add 3 16366 _000451_hash NULL
83010 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
83011 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
83012 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
83013 +_000455_hash read 3 9397 _000455_hash NULL
83014 +_000456_hash read_buf 2 20469 _000456_hash NULL
83015 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
83016 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
83017 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
83018 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
83019 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
83020 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
83021 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
83022 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
83023 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
83024 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
83025 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
83026 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
83027 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
83028 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
83029 +_000471_hash revalidate 2 19043 _000471_hash NULL
83030 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
83031 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
83032 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
83033 +_000475_hash rngapi_reset 3 34366 _000475_hash NULL
83034 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
83035 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
83036 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
83037 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
83038 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
83039 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
83040 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
83041 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
83042 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
83043 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
83044 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
83045 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
83046 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
83047 +_000489_hash savemem 3 58129 _000489_hash NULL
83048 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
83049 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
83050 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
83051 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
83052 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
83053 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
83054 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
83055 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
83056 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
83057 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
83058 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
83059 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
83060 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
83061 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
83062 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
83063 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
83064 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
83065 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
83066 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
83067 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
83068 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
83069 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
83070 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
83071 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
83072 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
83073 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
83074 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
83075 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
83076 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
83077 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
83078 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
83079 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
83080 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
83081 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
83082 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
83083 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
83084 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
83085 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
83086 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
83087 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
83088 +_000532_hash set_registers 3 53582 _000532_hash NULL
83089 +_000533_hash setsockopt 5 54539 _000533_hash NULL
83090 +_000534_hash setup_req 3 5848 _000534_hash NULL
83091 +_000535_hash setup_window 7 59178 _000535_hash NULL
83092 +_000536_hash setxattr 4 37006 _000536_hash NULL
83093 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
83094 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
83095 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
83096 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
83097 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
83098 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
83099 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
83100 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
83101 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
83102 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
83103 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
83104 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
83105 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
83106 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
83107 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
83108 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
83109 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
83110 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
83111 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
83112 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
83113 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
83114 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
83115 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
83116 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
83117 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
83118 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
83119 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
83120 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
83121 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
83122 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
83123 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
83124 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
83125 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
83126 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
83127 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
83128 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
83129 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
83130 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
83131 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
83132 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
83133 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
83134 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
83135 +_000581_hash spidev_write 3 44510 _000581_hash NULL
83136 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
83137 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
83138 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
83139 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
83140 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
83141 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
83142 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
83143 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
83144 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
83145 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
83146 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
83147 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
83148 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
83149 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
83150 +_000597_hash tower_write 3 8580 _000597_hash NULL
83151 +_000598_hash tpm_write 3 50798 _000598_hash NULL
83152 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
83153 +_000600_hash trusted_update 3 12664 _000600_hash NULL
83154 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
83155 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
83156 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
83157 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
83158 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
83159 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
83160 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
83161 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
83162 +_000609_hash uea_request 4 47613 _000609_hash NULL
83163 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
83164 +_000611_hash uio_write 3 43202 _000611_hash NULL
83165 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
83166 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
83167 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
83168 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
83169 +_000616_hash usblp_write 3 23178 _000616_hash NULL
83170 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
83171 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
83172 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
83173 +_000621_hash user_update 3 41332 _000621_hash NULL
83174 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
83175 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
83176 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
83177 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
83178 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
83179 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
83180 +_000629_hash vcs_write 3 3910 _000629_hash NULL
83181 +_000630_hash vfd_write 3 14717 _000630_hash NULL
83182 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
83183 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
83184 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
83185 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
83186 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
83187 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
83188 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
83189 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
83190 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
83191 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
83192 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
83193 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
83194 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
83195 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
83196 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
83197 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
83198 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
83199 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
83200 +_000651_hash wdm_write 3 53735 _000651_hash NULL
83201 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
83202 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
83203 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
83204 +_000655_hash write 3 62671 _000655_hash NULL
83205 +_000656_hash write_flush 3 50803 _000656_hash NULL
83206 +_000657_hash write_rio 3 54837 _000657_hash NULL
83207 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
83208 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
83209 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
83210 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
83211 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
83212 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
83213 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
83214 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
83215 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
83216 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
83217 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
83218 +_000669_hash zoran_write 3 22404 _000669_hash NULL
83219 +_000671_hash acpi_ex_allocate_name_string 2 7685 _000671_hash NULL
83220 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
83221 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
83222 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
83223 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
83224 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
83225 +_000677_hash add_res_range 4 21310 _000677_hash NULL
83226 +_000678_hash addtgt 3 54703 _000678_hash NULL
83227 +_000679_hash add_uuid 4 49831 _000679_hash NULL
83228 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
83229 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
83230 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
83231 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
83232 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
83233 +_000685_hash alloc_async 1 14208 _000685_hash NULL
83234 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
83235 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
83236 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
83237 +_000689_hash alloc_context 1 41283 _000689_hash NULL
83238 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
83239 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
83240 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
83241 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
83242 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
83243 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
83244 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
83245 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
83246 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
83247 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
83248 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
83249 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
83250 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
83251 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
83252 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
83253 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
83254 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
83255 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
83256 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
83257 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
83258 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
83259 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
83260 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
83261 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
83262 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
83263 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
83264 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
83265 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
83266 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
83267 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
83268 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
83269 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
83270 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
83271 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
83272 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
83273 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
83274 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
83275 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
83276 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
83277 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
83278 +_000736_hash ati_create_gatt_pages 1 4722 _000736_hash NULL
83279 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
83280 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
83281 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
83282 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
83283 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
83284 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
83285 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
83286 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
83287 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
83288 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
83289 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
83290 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
83291 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
83292 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
83293 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
83294 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
83295 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
83296 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
83297 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
83298 +_000759_hash ca_extend 2 64541 _000759_hash NULL
83299 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
83300 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
83301 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
83302 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
83303 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
83304 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
83305 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
83306 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
83307 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
83308 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
83309 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
83310 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
83311 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
83312 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
83313 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
83314 +_000778_hash cifs_writedata_alloc 1 32880 _000778_hash NULL
83315 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
83316 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
83317 +_000781_hash construct_key 3 11329 _000781_hash NULL
83318 +_000782_hash context_alloc 3 24645 _000782_hash NULL
83319 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
83320 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
83321 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
83322 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
83323 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
83324 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
83325 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
83326 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
83327 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
83328 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
83329 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
83330 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
83331 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
83332 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
83333 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
83334 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
83335 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
83336 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
83337 +_000805_hash depth_write 3 3021 _000805_hash NULL
83338 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
83339 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
83340 +_000808_hash dev_write 3 7708 _000808_hash NULL
83341 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
83342 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
83343 +_000811_hash disconnect 4 32521 _000811_hash NULL
83344 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
83345 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
83346 +_000815_hash do_dccp_setsockopt 5 54377 _000815_hash NULL
83347 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
83348 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
83349 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
83350 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
83351 +_000820_hash do_sync 1 9604 _000820_hash NULL
83352 +_000821_hash dup_array 3 33551 _000821_hash NULL
83353 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
83354 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
83355 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
83356 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
83357 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
83358 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
83359 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
83360 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
83361 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
83362 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
83363 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
83364 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
83365 +_000834_hash enable_write 3 30456 _000834_hash NULL
83366 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
83367 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
83368 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
83369 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
83370 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
83371 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
83372 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
83373 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
83374 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
83375 +_000844_hash fillonedir 3 41746 _000844_hash NULL
83376 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
83377 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
83378 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
83379 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
83380 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
83381 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
83382 +_000851_hash get_entry 4 16003 _000851_hash NULL
83383 +_000852_hash get_free_de 2 33714 _000852_hash NULL
83384 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
83385 +_000854_hash getxattr 4 24398 _000854_hash NULL
83386 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
83387 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
83388 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
83389 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
83390 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
83391 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
83392 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
83393 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
83394 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
83395 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
83396 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
83397 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
83398 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
83399 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
83400 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
83401 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
83402 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
83403 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
83404 +_000876_hash ieee80211_send_probe_req 6 6924 _000876_hash NULL
83405 +_000877_hash if_writecmd 2 815 _000877_hash NULL
83406 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
83407 +_000880_hash init_ipath 1 48187 _000880_hash NULL
83408 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
83409 +_000883_hash init_q 4 132 _000883_hash NULL
83410 +_000884_hash init_state 2 60165 _000884_hash NULL
83411 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
83412 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
83413 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
83414 +_000888_hash interfaces 2 38859 _000888_hash NULL
83415 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
83416 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
83417 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
83418 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
83419 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
83420 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
83421 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
83422 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
83423 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
83424 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
83425 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
83426 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
83427 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
83428 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
83429 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
83430 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
83431 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
83432 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
83433 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
83434 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
83435 +_000911_hash isdn_write 3 45863 _000911_hash NULL
83436 +_000912_hash isku_receive 4 54130 _000912_hash NULL
83437 +_000913_hash isku_send 4 41542 _000913_hash NULL
83438 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
83439 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
83440 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
83441 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
83442 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
83443 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
83444 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
83445 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
83446 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
83447 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
83448 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
83449 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
83450 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
83451 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
83452 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
83453 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
83454 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
83455 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
83456 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
83457 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
83458 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
83459 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
83460 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
83461 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
83462 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
83463 +_000940_hash kvm_write_guest_page 5 63555 _000940_hash NULL
83464 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
83465 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
83466 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
83467 +_000945_hash lc_create 3 48662 _000945_hash NULL
83468 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
83469 +_000947_hash linear_conf 2 23485 _000947_hash NULL
83470 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
83471 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
83472 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
83473 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
83474 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
83475 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
83476 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
83477 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
83478 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
83479 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
83480 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
83481 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
83482 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
83483 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
83484 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
83485 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
83486 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
83487 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
83488 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
83489 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
83490 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
83491 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
83492 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
83493 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
83494 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
83495 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
83496 +_000977_hash new_dir 3 31919 _000977_hash NULL
83497 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
83498 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
83499 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
83500 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
83501 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
83502 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
83503 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
83504 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
83505 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
83506 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
83507 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
83508 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
83509 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
83510 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
83511 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
83512 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
83513 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
83514 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
83515 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
83516 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
83517 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
83518 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
83519 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
83520 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
83521 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
83522 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
83523 +_001008_hash osst_write 3 31581 _001008_hash NULL
83524 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
83525 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
83526 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
83527 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
83528 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
83529 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
83530 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
83531 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
83532 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
83533 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
83534 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
83535 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
83536 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
83537 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
83538 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
83539 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
83540 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
83541 +_001030_hash play_iframe 3 8219 _001030_hash NULL
83542 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
83543 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
83544 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
83545 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
83546 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
83547 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
83548 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
83549 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
83550 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
83551 +_001042_hash proc_write 3 51003 _001042_hash NULL
83552 +_001043_hash profile_load 3 58267 _001043_hash NULL
83553 +_001044_hash profile_remove 3 8556 _001044_hash NULL
83554 +_001045_hash profile_replace 3 14652 _001045_hash NULL
83555 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
83556 +_001047_hash pyra_send 4 12061 _001047_hash NULL
83557 +_001048_hash qc_capture 3 19298 _001048_hash NULL
83558 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
83559 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
83560 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
83561 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
83562 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
83563 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
83564 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
83565 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
83566 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
83567 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
83568 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
83569 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
83570 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
83571 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
83572 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
83573 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
83574 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
83575 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
83576 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
83577 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
83578 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
83579 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
83580 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
83581 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
83582 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
83583 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
83584 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
83585 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
83586 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
83587 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
83588 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
83589 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
83590 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
83591 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
83592 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
83593 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
83594 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
83595 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
83596 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
83597 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
83598 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
83599 +_001092_hash security_context_to_sid_default 2 3492 _001092_hash NULL
83600 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
83601 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
83602 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
83603 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
83604 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
83605 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
83606 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
83607 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
83608 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
83609 +_001102_hash set_connectable 4 56458 _001102_hash NULL
83610 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
83611 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
83612 +_001105_hash setkey 3 14987 _001105_hash NULL
83613 +_001106_hash set_le 4 30581 _001106_hash NULL
83614 +_001107_hash set_link_security 4 4502 _001107_hash NULL
83615 +_001108_hash set_local_name 4 55757 _001108_hash NULL
83616 +_001109_hash set_powered 4 12129 _001109_hash NULL
83617 +_001110_hash set_ssp 4 62411 _001110_hash NULL
83618 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
83619 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
83620 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
83621 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
83622 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
83623 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
83624 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
83625 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
83626 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
83627 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
83628 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
83629 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
83630 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
83631 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
83632 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
83633 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
83634 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
83635 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
83636 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
83637 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
83638 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
83639 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
83640 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
83641 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
83642 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
83643 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
83644 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
83645 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
83646 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
83647 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
83648 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
83649 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
83650 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
83651 +_001148_hash sound_write 3 5102 _001148_hash NULL
83652 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
83653 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
83654 +_001151_hash spidev_message 3 5518 _001151_hash NULL
83655 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
83656 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
83657 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
83658 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
83659 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
83660 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
83661 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
83662 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
83663 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
83664 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
83665 +_001163_hash st_write 3 16874 _001163_hash NULL
83666 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
83667 +_001165_hash symtab_init 2 61050 _001165_hash NULL
83668 +_001166_hash sys_bind 3 10799 _001166_hash NULL
83669 +_001167_hash sys_connect 3 15291 _001167_hash NULL
83670 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
83671 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
83672 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
83673 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
83674 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
83675 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
83676 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
83677 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
83678 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
83679 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
83680 +_001178_hash sys_semop 3 39457 _001178_hash NULL
83681 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
83682 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
83683 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
83684 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
83685 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
83686 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
83687 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
83688 +_001186_hash timeout_write 3 50991 _001186_hash NULL
83689 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
83690 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
83691 +_001189_hash tm6000_read_write_usb 7 50774 _001189_hash NULL
83692 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
83693 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
83694 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
83695 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
83696 +_001195_hash ts_write 3 64336 _001195_hash NULL
83697 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
83698 +_001197_hash tty_write 3 5494 _001197_hash NULL
83699 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
83700 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
83701 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
83702 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
83703 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
83704 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
83705 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
83706 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
83707 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
83708 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
83709 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
83710 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
83711 +_001211_hash uvc_alloc_entity 3 20836 _001211_hash NULL
83712 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
83713 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
83714 +_001214_hash vb2_read 3 42703 _001214_hash NULL
83715 +_001215_hash vb2_write 3 31948 _001215_hash NULL
83716 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
83717 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
83718 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
83719 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
83720 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
83721 +_001223_hash vmalloc 1 15464 _001223_hash NULL
83722 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
83723 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
83724 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
83725 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
83726 +_001228_hash vzalloc 1 47421 _001228_hash NULL
83727 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
83728 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
83729 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
83730 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
83731 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
83732 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
83733 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
83734 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
83735 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
83736 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
83737 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
83738 +_001240_hash xfs_dir_cilookup_result 3 64288 _001240_hash NULL
83739 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
83740 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
83741 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
83742 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
83743 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
83744 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
83745 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
83746 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
83747 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
83748 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
83749 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
83750 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
83751 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
83752 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
83753 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
83754 +_001256_hash add_child 4 45201 _001256_hash NULL
83755 +_001257_hash add_port 2 54941 _001257_hash NULL
83756 +_001258_hash adu_read 3 24177 _001258_hash NULL
83757 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
83758 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
83759 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
83760 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
83761 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
83762 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
83763 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
83764 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
83765 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
83766 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
83767 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
83768 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
83769 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
83770 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
83771 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
83772 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
83773 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
83774 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
83775 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
83776 +_001280_hash async_setkey 3 35521 _001280_hash NULL
83777 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
83778 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
83779 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
83780 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
83781 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
83782 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
83783 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
83784 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
83785 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
83786 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
83787 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
83788 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
83789 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
83790 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
83791 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
83792 +_001298_hash bm_init 2 13529 _001298_hash NULL
83793 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
83794 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
83795 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
83796 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
83797 +_001303_hash cache_read 3 24790 _001303_hash NULL
83798 +_001304_hash cache_write 3 13589 _001304_hash NULL
83799 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
83800 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
83801 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
83802 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
83803 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
83804 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
83805 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
83806 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
83807 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
83808 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
83809 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
83810 +_001317_hash copy_oldmem_page 3 26164 _001317_hash NULL
83811 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
83812 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
83813 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
83814 +_001321_hash crypto_authenc_setkey 3 80 _001321_hash NULL
83815 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
83816 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
83817 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
83818 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
83819 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
83820 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
83821 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
83822 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
83823 +_001331_hash dev_read 3 56369 _001331_hash NULL
83824 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
83825 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
83826 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
83827 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
83828 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
83829 +_001338_hash do_readlink 2 43518 _001338_hash NULL
83830 +_001339_hash __do_replace 5 37227 _001339_hash NULL
83831 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
83832 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
83833 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
83834 +_001343_hash dump_midi 3 51040 _001343_hash NULL
83835 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
83836 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
83837 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5 4303 _001346_hash NULL
83838 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
83839 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
83840 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
83841 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
83842 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
83843 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
83844 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
83845 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
83846 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
83847 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
83848 +_001358_hash filldir 3 55137 _001358_hash NULL
83849 +_001359_hash filldir64 3 46469 _001359_hash NULL
83850 +_001360_hash fops_read 3 40672 _001360_hash NULL
83851 +_001361_hash from_buffer 3 18625 _001361_hash NULL
83852 +_001362_hash fsm_init 2 16134 _001362_hash NULL
83853 +_001363_hash get_subdir 3 62581 _001363_hash NULL
83854 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
83855 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
83856 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
83857 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
83858 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
83859 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
83860 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
83861 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
83862 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
83863 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
83864 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
83865 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
83866 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
83867 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
83868 +_001379_hash ilo_read 3 32531 _001379_hash NULL
83869 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
83870 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
83871 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
83872 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
83873 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
83874 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
83875 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
83876 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
83877 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
83878 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
83879 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
83880 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
83881 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
83882 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
83883 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
83884 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
83885 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
83886 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
83887 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
83888 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
83889 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
83890 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
83891 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
83892 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
83893 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
83894 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
83895 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
83896 +_001412_hash keyring_read 3 13438 _001412_hash NULL
83897 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
83898 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
83899 +_001415_hash kmp_init 2 41373 _001415_hash NULL
83900 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
83901 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
83902 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
83903 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
83904 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
83905 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
83906 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
83907 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
83908 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
83909 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
83910 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
83911 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
83912 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
83913 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
83914 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
83915 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
83916 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
83917 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
83918 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
83919 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
83920 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
83921 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
83922 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
83923 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
83924 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
83925 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
83926 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
83927 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
83928 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
83929 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
83930 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
83931 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
83932 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
83933 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
83934 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
83935 +_001454_hash override_release 2 52032 _001454_hash NULL
83936 +_001455_hash packet_snd 3 13634 _001455_hash NULL
83937 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
83938 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
83939 +_001458_hash pg_read 3 17276 _001458_hash NULL
83940 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
83941 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
83942 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
83943 +_001462_hash pms_capture 4 27142 _001462_hash NULL
83944 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
83945 +_001464_hash printer_read 3 54851 _001464_hash NULL
83946 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
83947 +_001466_hash pt_read 3 49136 _001466_hash NULL
83948 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
83949 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
83950 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
83951 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
83952 +_001471_hash qcam_read 3 13977 _001471_hash NULL
83953 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
83954 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
83955 +_001474_hash read_flush 3 43851 _001474_hash NULL
83956 +_001475_hash read_profile 3 27859 _001475_hash NULL
83957 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
83958 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
83959 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
83960 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
83961 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
83962 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
83963 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
83964 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
83965 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
83966 +_001486_hash roccat_read 3 41093 _001486_hash NULL
83967 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
83968 +_001488_hash scsi_register 2 49094 _001488_hash NULL
83969 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
83970 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
83971 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
83972 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
83973 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
83974 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
83975 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
83976 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
83977 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
83978 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
83979 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
83980 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
83981 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
83982 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
83983 +_001503_hash set_arg 3 42824 _001503_hash NULL
83984 +_001504_hash sg_read 3 25799 _001504_hash NULL
83985 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
83986 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
83987 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
83988 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
83989 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
83990 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
83991 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
83992 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
83993 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
83994 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
83995 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
83996 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
83997 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
83998 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
83999 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
84000 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
84001 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
84002 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
84003 +_001525_hash store_msg 3 56417 _001525_hash NULL
84004 +_001526_hash str_to_user 2 11411 _001526_hash NULL
84005 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
84006 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
84007 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
84008 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
84009 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
84010 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
84011 +_001533_hash sys_process_vm_readv 3-5 19090 _001533_hash NULL
84012 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
84013 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
84014 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
84015 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
84016 +_001540_hash team_options_register 3 20091 _001540_hash NULL
84017 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
84018 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
84019 +_001543_hash tipc_send 4 51238 _001543_hash NULL
84020 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
84021 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
84022 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
84023 +_001547_hash tnode_new 3 44757 _001547_hash NULL
84024 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
84025 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
84026 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
84027 +_001551_hash tpm_read 3 50344 _001551_hash NULL
84028 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
84029 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
84030 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
84031 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
84032 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
84033 +_001558_hash uio_read 3 49300 _001558_hash NULL
84034 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
84035 +_001560_hash unlink1 3 63059 _001560_hash NULL
84036 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
84037 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
84038 +_001564_hash usblp_read 3 57342 _001564_hash NULL
84039 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
84040 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
84041 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
84042 +_001568_hash user_read 3 51881 _001568_hash NULL
84043 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
84044 +_001570_hash vcs_read 3 8017 _001570_hash NULL
84045 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
84046 +_001572_hash venus_create 4 20555 _001572_hash NULL
84047 +_001573_hash venus_link 5 32165 _001573_hash NULL
84048 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
84049 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
84050 +_001576_hash venus_remove 4 59781 _001576_hash NULL
84051 +_001577_hash venus_rename 4-5 17707 _001577_hash NULL
84052 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
84053 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
84054 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
84055 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
84056 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
84057 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
84058 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
84059 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
84060 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
84061 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
84062 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
84063 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
84064 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
84065 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
84066 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
84067 +_001596_hash wdm_read 3 6549 _001596_hash NULL
84068 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
84069 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
84070 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
84071 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
84072 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
84073 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
84074 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
84075 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
84076 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
84077 +_001606_hash xz_dec_lzma2_create 2 36353 _001606_hash NULL
84078 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
84079 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
84080 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
84081 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
84082 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
84083 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
84084 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
84085 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
84086 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
84087 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
84088 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
84089 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
84090 +_001619_hash __alloc_bootmem_low 1 43423 _001619_hash NULL
84091 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
84092 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
84093 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
84094 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
84095 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
84096 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
84097 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
84098 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
84099 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
84100 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
84101 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
84102 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
84103 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
84104 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
84105 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
84106 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
84107 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
84108 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
84109 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
84110 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
84111 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
84112 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
84113 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
84114 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
84115 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
84116 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
84117 +_001648_hash blk_queue_init_tags 2 44355 _001648_hash NULL
84118 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
84119 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
84120 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
84121 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
84122 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
84123 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
84124 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
84125 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
84126 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
84127 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
84128 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
84129 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
84130 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
84131 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
84132 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
84133 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
84134 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
84135 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
84136 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
84137 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
84138 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
84139 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
84140 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
84141 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
84142 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
84143 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
84144 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
84145 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
84146 +_001677_hash create_subvol 4 2347 _001677_hash NULL
84147 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
84148 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
84149 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
84150 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
84151 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
84152 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
84153 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
84154 +_001687_hash debug_output 3 18575 _001687_hash NULL
84155 +_001688_hash debug_read 3 19322 _001688_hash NULL
84156 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
84157 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
84158 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
84159 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
84160 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
84161 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
84162 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
84163 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
84164 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
84165 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
84166 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
84167 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
84168 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
84169 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
84170 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
84171 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
84172 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
84173 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
84174 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
84175 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
84176 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
84177 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
84178 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
84179 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
84180 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
84181 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
84182 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
84183 +_001716_hash filter_read 3 61692 _001716_hash NULL
84184 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
84185 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
84186 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
84187 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
84188 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
84189 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
84190 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
84191 +_001724_hash ht40allow_map_read 3 55209 _001724_hash NULL
84192 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
84193 +_001726_hash hysdn_conf_read 3 42324 _001726_hash NULL
84194 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
84195 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
84196 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
84197 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
84198 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
84199 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
84200 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
84201 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
84202 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
84203 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
84204 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
84205 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
84206 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
84207 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
84208 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
84209 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
84210 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
84211 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
84212 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
84213 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
84214 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
84215 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
84216 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
84217 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
84218 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
84219 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
84220 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
84221 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
84222 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
84223 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
84224 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
84225 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
84226 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
84227 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
84228 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
84229 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
84230 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
84231 +_001765_hash ipw_write 3 59807 _001765_hash NULL
84232 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
84233 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
84234 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
84235 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
84236 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
84237 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
84238 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
84239 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
84240 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
84241 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
84242 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
84243 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
84244 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
84245 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
84246 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
84247 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
84248 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
84249 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
84250 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
84251 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
84252 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
84253 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
84254 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
84255 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
84256 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
84257 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
84258 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
84259 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
84260 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
84261 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
84262 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
84263 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
84264 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
84265 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
84266 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
84267 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
84268 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
84269 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
84270 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
84271 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
84272 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
84273 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
84274 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _001808_hash NULL
84275 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
84276 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
84277 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
84278 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
84279 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
84280 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
84281 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
84282 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
84283 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
84284 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
84285 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
84286 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
84287 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
84288 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
84289 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
84290 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
84291 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
84292 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
84293 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
84294 +_001828_hash key_key_read 3 3241 _001828_hash NULL
84295 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
84296 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
84297 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
84298 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
84299 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
84300 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
84301 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
84302 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
84303 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
84304 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
84305 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
84306 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
84307 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
84308 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
84309 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
84310 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
84311 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
84312 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
84313 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
84314 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
84315 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
84316 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
84317 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
84318 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
84319 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
84320 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
84321 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
84322 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
84323 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
84324 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
84325 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
84326 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
84327 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
84328 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
84329 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
84330 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
84331 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
84332 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
84333 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
84334 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
84335 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
84336 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
84337 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
84338 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
84339 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
84340 +_001876_hash nfsd_vfs_read 6 62605 _001876_hash NULL
84341 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
84342 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
84343 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
84344 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
84345 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
84346 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
84347 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
84348 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
84349 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
84350 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
84351 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
84352 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
84353 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
84354 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
84355 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
84356 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
84357 +_001893_hash page_readlink 3 23346 _001893_hash NULL
84358 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
84359 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
84360 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
84361 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
84362 +_001898_hash pms_read 3 53873 _001898_hash NULL
84363 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
84364 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
84365 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
84366 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
84367 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
84368 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
84369 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
84370 +_001906_hash proc_read 3 43614 _001906_hash NULL
84371 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
84372 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
84373 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
84374 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
84375 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
84376 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
84377 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
84378 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
84379 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
84380 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
84381 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
84382 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
84383 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
84384 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
84385 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
84386 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
84387 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
84388 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
84389 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
84390 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
84391 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
84392 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
84393 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
84394 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
84395 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
84396 +_001932_hash queues_read 3 24877 _001932_hash NULL
84397 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
84398 +_001934_hash rcname_read 3 25919 _001934_hash NULL
84399 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
84400 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
84401 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
84402 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
84403 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
84404 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
84405 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
84406 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
84407 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
84408 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
84409 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
84410 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
84411 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
84412 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
84413 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
84414 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
84415 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
84416 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
84417 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
84418 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
84419 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
84420 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
84421 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
84422 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
84423 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
84424 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
84425 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
84426 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
84427 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
84428 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
84429 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
84430 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
84431 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
84432 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
84433 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
84434 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
84435 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
84436 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
84437 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
84438 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
84439 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
84440 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
84441 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
84442 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
84443 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
84444 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
84445 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
84446 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
84447 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
84448 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
84449 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
84450 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
84451 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
84452 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
84453 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _001989_hash NULL
84454 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
84455 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
84456 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
84457 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
84458 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
84459 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
84460 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
84461 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
84462 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
84463 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
84464 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
84465 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
84466 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
84467 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
84468 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
84469 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
84470 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
84471 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
84472 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
84473 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
84474 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
84475 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
84476 +_002013_hash sel_read_policyvers 3 55 _002013_hash NULL
84477 +_002014_hash send_msg 4 37323 _002014_hash NULL
84478 +_002015_hash send_packet 4 52960 _002015_hash NULL
84479 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
84480 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
84481 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
84482 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
84483 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
84484 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
84485 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
84486 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
84487 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
84488 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
84489 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
84490 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
84491 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
84492 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
84493 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
84494 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
84495 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
84496 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
84497 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
84498 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
84499 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
84500 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
84501 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
84502 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
84503 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
84504 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
84505 +_002045_hash st_read 3 51251 _002045_hash NULL
84506 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
84507 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
84508 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
84509 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
84510 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
84511 +_002051_hash sys_readv 3 50664 _002051_hash NULL
84512 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
84513 +_002053_hash sys_writev 3 28384 _002053_hash NULL
84514 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
84515 +_002055_hash ts_read 3 44687 _002055_hash NULL
84516 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
84517 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
84518 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
84519 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
84520 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
84521 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
84522 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
84523 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
84524 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
84525 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
84526 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
84527 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
84528 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
84529 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
84530 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
84531 +_002074_hash waiters_read 3 40902 _002074_hash NULL
84532 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
84533 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
84534 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
84535 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
84536 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
84537 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
84538 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
84539 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
84540 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
84541 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
84542 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
84543 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
84544 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
84545 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
84546 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
84547 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
84548 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
84549 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
84550 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
84551 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
84552 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
84553 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
84554 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
84555 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
84556 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
84557 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
84558 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
84559 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
84560 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
84561 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
84562 +_002106_hash cx18_read 3 23699 _002106_hash NULL
84563 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
84564 +_002108_hash depth_read 3 31112 _002108_hash NULL
84565 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
84566 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
84567 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
84568 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
84569 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
84570 +_002115_hash enable_read 3 2117 _002115_hash NULL
84571 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
84572 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
84573 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
84574 +_002119_hash frequency_read 3 64031 _002119_hash NULL
84575 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
84576 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
84577 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
84578 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
84579 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
84580 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
84581 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
84582 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
84583 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
84584 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
84585 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
84586 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
84587 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
84588 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
84589 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
84590 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
84591 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
84592 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
84593 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
84594 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
84595 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
84596 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
84597 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
84598 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
84599 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
84600 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
84601 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
84602 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
84603 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
84604 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
84605 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
84606 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
84607 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
84608 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
84609 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
84610 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
84611 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
84612 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002157_hash NULL
84613 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
84614 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
84615 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
84616 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
84617 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
84618 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
84619 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
84620 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
84621 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
84622 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
84623 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
84624 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
84625 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
84626 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
84627 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
84628 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
84629 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
84630 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
84631 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
84632 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
84633 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
84634 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
84635 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
84636 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
84637 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
84638 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
84639 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
84640 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
84641 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
84642 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
84643 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
84644 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
84645 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
84646 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
84647 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
84648 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
84649 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
84650 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
84651 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
84652 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
84653 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
84654 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
84655 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
84656 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
84657 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
84658 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
84659 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
84660 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
84661 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
84662 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
84663 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
84664 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
84665 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
84666 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
84667 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
84668 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
84669 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
84670 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
84671 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
84672 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
84673 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
84674 +_002220_hash power_read 3 15939 _002220_hash NULL
84675 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
84676 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
84677 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
84678 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
84679 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
84680 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
84681 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
84682 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
84683 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
84684 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
84685 +_002231_hash read_tree_block 3 841 _002231_hash NULL
84686 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
84687 +_002234_hash recv_msg 4 48709 _002234_hash NULL
84688 +_002235_hash recv_stream 4 30138 _002235_hash NULL
84689 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
84690 +_002237_hash request_key_async 4 6990 _002237_hash NULL
84691 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
84692 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
84693 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
84694 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
84695 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
84696 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
84697 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
84698 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
84699 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
84700 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
84701 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
84702 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
84703 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
84704 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
84705 +_002252_hash send_stream 4 3397 _002252_hash NULL
84706 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
84707 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
84708 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
84709 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
84710 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
84711 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
84712 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
84713 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
84714 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
84715 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
84716 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
84717 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
84718 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
84719 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
84720 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
84721 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
84722 +_002270_hash timeout_read 3 47915 _002270_hash NULL
84723 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
84724 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
84725 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
84726 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
84727 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
84728 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
84729 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
84730 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
84731 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
84732 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
84733 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
84734 +_002283_hash user_power_read 3 39414 _002283_hash NULL
84735 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
84736 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
84737 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
84738 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
84739 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
84740 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
84741 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
84742 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
84743 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
84744 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
84745 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
84746 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
84747 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
84748 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
84749 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
84750 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
84751 +_002300_hash spi_execute 5 28736 _002300_hash NULL
84752 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
84753 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
84754 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
84755 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
84756 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
84757 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
84758 +_002308_hash write_leb 5 36957 _002308_hash NULL
84759 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
84760 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
84761 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
84762 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
84763 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
84764 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
84765 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
84766 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
84767 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
84768 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
84769 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
84770 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
84771 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
84772 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
84773 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
84774 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
84775 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
84776 +_002329_hash recover_head 3 17904 _002329_hash NULL
84777 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
84778 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
84779 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
84780 +_002334_hash amthi_read 4 45831 _002334_hash NULL
84781 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
84782 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
84783 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
84784 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
84785 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
84786 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
84787 +_002341_hash card_send_command 3 40757 _002341_hash NULL
84788 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
84789 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
84790 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
84791 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
84792 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
84793 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
84794 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
84795 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
84796 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
84797 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
84798 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
84799 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
84800 +_002354_hash fir16_create 3 5574 _002354_hash NULL
84801 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
84802 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
84803 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
84804 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
84805 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
84806 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
84807 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
84808 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
84809 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
84810 +_002365_hash keymap_store 4 45406 _002365_hash NULL
84811 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
84812 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
84813 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
84814 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
84815 +_002370_hash lirc_write 3 20604 _002370_hash NULL
84816 +_002371_hash _malloc 1 54077 _002371_hash NULL
84817 +_002372_hash mei_read 3 6507 _002372_hash NULL
84818 +_002373_hash mei_write 3 4005 _002373_hash NULL
84819 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
84820 +_002375_hash msg_set 3 51725 _002375_hash NULL
84821 +_002376_hash newpart 6 47485 _002376_hash NULL
84822 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
84823 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
84824 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
84825 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
84826 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
84827 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
84828 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
84829 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
84830 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
84831 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
84832 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
84833 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
84834 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
84835 +_002393_hash sep_read 3 17161 _002393_hash NULL
84836 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
84837 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
84838 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
84839 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
84840 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
84841 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
84842 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
84843 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
84844 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
84845 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
84846 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
84847 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
84848 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
84849 +_002411_hash mempool_create 1 29437 _002411_hash NULL
84850 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
84851 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
84852 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
84853 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
84854 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
84855 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
84856 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
84857 +_002419_hash add_partition 2 55588 _002419_hash NULL
84858 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
84859 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
84860 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
84861 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
84862 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
84863 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
84864 +_002427_hash bioset_create 1 5580 _002427_hash NULL
84865 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
84866 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
84867 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
84868 +_002431_hash prison_create 1 43623 _002431_hash NULL
84869 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
84870 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
84871 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
84872 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
84873 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
84874 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
84875 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
84876 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
84877 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
84878 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
84879 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
84880 +_002443_hash comedi_read 3 13199 _002443_hash NULL
84881 +_002444_hash comedi_write 3 47926 _002444_hash NULL
84882 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
84883 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
84884 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
84885 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
84886 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
84887 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
84888 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
84889 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
84890 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
84891 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
84892 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
84893 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
84894 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
84895 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
84896 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
84897 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
84898 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
84899 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
84900 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
84901 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
84902 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
84903 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
84904 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
84905 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
84906 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
84907 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
84908 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
84909 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
84910 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
84911 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
84912 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
84913 +_002476_hash flash_read 3 57843 _002476_hash NULL
84914 +_002477_hash flash_write 3 62354 _002477_hash NULL
84915 +_002478_hash gather_array 3 56641 _002478_hash NULL
84916 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
84917 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
84918 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
84919 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
84920 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
84921 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
84922 +_002486_hash ieee80211_alloc_txb 1 52477 _002486_hash NULL
84923 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
84924 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
84925 +_002489_hash init_cdev 1 8274 _002489_hash NULL
84926 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
84927 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
84928 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
84929 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
84930 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
84931 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
84932 +_002496_hash options_write 3 47243 _002496_hash NULL
84933 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
84934 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
84935 +_002499_hash portnames_read 3 41958 _002499_hash NULL
84936 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
84937 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
84938 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
84939 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
84940 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
84941 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
84942 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
84943 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
84944 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
84945 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
84946 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
84947 +_002511_hash queue_reply 3 22416 _002511_hash NULL
84948 +_002512_hash Realloc 2 34961 _002512_hash NULL
84949 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
84950 +_002514_hash rtllib_alloc_txb 1 21687 _002514_hash NULL
84951 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
84952 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
84953 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
84954 +_002518_hash split 2 11691 _002518_hash NULL
84955 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
84956 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
84957 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
84958 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
84959 +_002523_hash tunables_read 3 36385 _002523_hash NULL
84960 +_002524_hash tunables_write 3 59563 _002524_hash NULL
84961 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
84962 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
84963 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
84964 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
84965 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
84966 +_002530_hash xsd_read 3 15653 _002530_hash NULL
84967 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
84968 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _002532_hash NULL
84969 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
84970 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
84971 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
84972 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
84973 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
84974 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
84975 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
84976 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
84977 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
84978 +_002546_hash compat_readv 3 30273 _002546_hash NULL
84979 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
84980 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
84981 +_002551_hash compat_writev 3 60063 _002551_hash NULL
84982 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
84983 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
84984 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
84985 +_002555_hash xd_rw 4 49020 _002555_hash NULL
84986 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
84987 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
84988 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
84989 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
84990 +_002560_hash ms_rw 4 17220 _002560_hash NULL
84991 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
84992 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
84993 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
84994 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
84995 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
84996 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
84997 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
84998 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
84999 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
85000 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
85001 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
85002 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
85003 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
85004 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
85005 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
85006 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
85007 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
85008 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
85009 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
85010 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
85011 +_002584_hash fb_read 3 33506 _002584_hash NULL
85012 +_002585_hash fb_write 3 46924 _002585_hash NULL
85013 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
85014 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
85015 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
85016 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
85017 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
85018 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
85019 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
85020 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
85021 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
85022 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
85023 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
85024 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
85025 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
85026 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
85027 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
85028 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
85029 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
85030 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
85031 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
85032 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
85033 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
85034 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
85035 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
85036 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
85037 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
85038 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
85039 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
85040 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
85041 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
85042 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
85043 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
85044 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
85045 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
85046 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
85047 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
85048 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
85049 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
85050 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
85051 +_002626_hash create_table 2 16213 _002626_hash NULL
85052 +_002627_hash mem_read 3 57631 _002627_hash NULL
85053 +_002628_hash mem_write 3 22232 _002628_hash NULL
85054 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
85055 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
85056 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
85057 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
85058 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
85059 +_002634_hash acl_alloc 1 35979 _002634_hash NULL
85060 +_002635_hash acl_alloc_stack_init 1 60630 _002635_hash NULL
85061 +_002636_hash acl_alloc_num 1-2 60778 _002636_hash NULL
85062 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
85063 new file mode 100644
85064 index 0000000..cc96254
85065 --- /dev/null
85066 +++ b/tools/gcc/size_overflow_plugin.c
85067 @@ -0,0 +1,1204 @@
85068 +/*
85069 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
85070 + * Licensed under the GPL v2, or (at your option) v3
85071 + *
85072 + * Homepage:
85073 + * http://www.grsecurity.net/~ephox/overflow_plugin/
85074 + *
85075 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
85076 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
85077 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
85078 + *
85079 + * Usage:
85080 + * $ 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
85081 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
85082 + */
85083 +
85084 +#include "gcc-plugin.h"
85085 +#include "config.h"
85086 +#include "system.h"
85087 +#include "coretypes.h"
85088 +#include "tree.h"
85089 +#include "tree-pass.h"
85090 +#include "intl.h"
85091 +#include "plugin-version.h"
85092 +#include "tm.h"
85093 +#include "toplev.h"
85094 +#include "function.h"
85095 +#include "tree-flow.h"
85096 +#include "plugin.h"
85097 +#include "gimple.h"
85098 +#include "c-common.h"
85099 +#include "diagnostic.h"
85100 +#include "cfgloop.h"
85101 +
85102 +struct size_overflow_hash {
85103 + struct size_overflow_hash *next;
85104 + const char *name;
85105 + unsigned int param;
85106 +};
85107 +
85108 +#include "size_overflow_hash.h"
85109 +
85110 +#define __unused __attribute__((__unused__))
85111 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
85112 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
85113 +#define BEFORE_STMT true
85114 +#define AFTER_STMT false
85115 +#define CREATE_NEW_VAR NULL_TREE
85116 +#define CODES_LIMIT 32
85117 +#define MAX_PARAM 10
85118 +
85119 +#if BUILDING_GCC_VERSION == 4005
85120 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
85121 +#endif
85122 +
85123 +int plugin_is_GPL_compatible;
85124 +void debug_gimple_stmt(gimple gs);
85125 +
85126 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
85127 +static tree signed_size_overflow_type;
85128 +static tree unsigned_size_overflow_type;
85129 +static tree report_size_overflow_decl;
85130 +static tree const_char_ptr_type_node;
85131 +static unsigned int handle_function(void);
85132 +
85133 +static struct plugin_info size_overflow_plugin_info = {
85134 + .version = "20120618beta",
85135 + .help = "no-size-overflow\tturn off size overflow checking\n",
85136 +};
85137 +
85138 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
85139 +{
85140 + unsigned int arg_count = type_num_arguments(*node);
85141 +
85142 + for (; args; args = TREE_CHAIN(args)) {
85143 + tree position = TREE_VALUE(args);
85144 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
85145 + error("handle_size_overflow_attribute: overflow parameter outside range.");
85146 + *no_add_attrs = true;
85147 + }
85148 + }
85149 + return NULL_TREE;
85150 +}
85151 +
85152 +static struct attribute_spec no_size_overflow_attr = {
85153 + .name = "size_overflow",
85154 + .min_length = 1,
85155 + .max_length = -1,
85156 + .decl_required = false,
85157 + .type_required = true,
85158 + .function_type_required = true,
85159 + .handler = handle_size_overflow_attribute,
85160 +#if BUILDING_GCC_VERSION >= 4007
85161 + .affects_type_identity = false
85162 +#endif
85163 +};
85164 +
85165 +static void register_attributes(void __unused *event_data, void __unused *data)
85166 +{
85167 + register_attribute(&no_size_overflow_attr);
85168 +}
85169 +
85170 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
85171 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
85172 +{
85173 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
85174 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
85175 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
85176 +
85177 + const unsigned int m = 0x57559429;
85178 + const unsigned int n = 0x5052acdb;
85179 + const unsigned int *key4 = (const unsigned int *)key;
85180 + unsigned int h = len;
85181 + unsigned int k = len + seed + n;
85182 + unsigned long long p;
85183 +
85184 + while (len >= 8) {
85185 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
85186 + len -= 8;
85187 + }
85188 + if (len >= 4) {
85189 + cwmixb(key4[0]) key4 += 1;
85190 + len -= 4;
85191 + }
85192 + if (len)
85193 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
85194 + cwmixb(h ^ (k + n));
85195 + return k ^ h;
85196 +
85197 +#undef cwfold
85198 +#undef cwmixa
85199 +#undef cwmixb
85200 +}
85201 +
85202 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
85203 +{
85204 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
85205 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
85206 + return fn ^ codes;
85207 +}
85208 +
85209 +static inline tree get_original_function_decl(tree fndecl)
85210 +{
85211 + if (DECL_ABSTRACT_ORIGIN(fndecl))
85212 + return DECL_ABSTRACT_ORIGIN(fndecl);
85213 + return fndecl;
85214 +}
85215 +
85216 +static inline gimple get_def_stmt(tree node)
85217 +{
85218 + gcc_assert(TREE_CODE(node) == SSA_NAME);
85219 + return SSA_NAME_DEF_STMT(node);
85220 +}
85221 +
85222 +static unsigned char get_tree_code(tree type)
85223 +{
85224 + switch (TREE_CODE(type)) {
85225 + case ARRAY_TYPE:
85226 + return 0;
85227 + case BOOLEAN_TYPE:
85228 + return 1;
85229 + case ENUMERAL_TYPE:
85230 + return 2;
85231 + case FUNCTION_TYPE:
85232 + return 3;
85233 + case INTEGER_TYPE:
85234 + return 4;
85235 + case POINTER_TYPE:
85236 + return 5;
85237 + case RECORD_TYPE:
85238 + return 6;
85239 + case UNION_TYPE:
85240 + return 7;
85241 + case VOID_TYPE:
85242 + return 8;
85243 + case REAL_TYPE:
85244 + return 9;
85245 + case VECTOR_TYPE:
85246 + return 10;
85247 + case REFERENCE_TYPE:
85248 + return 11;
85249 + default:
85250 + debug_tree(type);
85251 + gcc_unreachable();
85252 + }
85253 +}
85254 +
85255 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
85256 +{
85257 + gcc_assert(type != NULL_TREE);
85258 +
85259 + while (type && len < CODES_LIMIT) {
85260 + tree_codes[len] = get_tree_code(type);
85261 + len++;
85262 + type = TREE_TYPE(type);
85263 + }
85264 + return len;
85265 +}
85266 +
85267 +static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
85268 +{
85269 + tree arg, result, type = TREE_TYPE(fndecl);
85270 + enum tree_code code = TREE_CODE(type);
85271 + size_t len = 0;
85272 +
85273 + gcc_assert(code == FUNCTION_TYPE);
85274 +
85275 + arg = TYPE_ARG_TYPES(type);
85276 + // skip builtins __builtin_constant_p
85277 + if (!arg && DECL_BUILT_IN(fndecl))
85278 + return 0;
85279 + gcc_assert(arg != NULL_TREE);
85280 +
85281 + if (TREE_CODE_CLASS(code) == tcc_type)
85282 + result = type;
85283 + else
85284 + result = DECL_RESULT(fndecl);
85285 +
85286 + gcc_assert(result != NULL_TREE);
85287 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
85288 +
85289 + while (arg && len < CODES_LIMIT) {
85290 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
85291 + arg = TREE_CHAIN(arg);
85292 + }
85293 +
85294 + gcc_assert(len != 0);
85295 + return len;
85296 +}
85297 +
85298 +static struct size_overflow_hash *get_function_hash(tree fndecl)
85299 +{
85300 + unsigned int hash;
85301 + struct size_overflow_hash *entry;
85302 + unsigned char tree_codes[CODES_LIMIT];
85303 + size_t len;
85304 + const char *func_name = NAME(fndecl);
85305 +
85306 + len = get_function_decl(fndecl, tree_codes);
85307 + if (len == 0)
85308 + return NULL;
85309 +
85310 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
85311 +
85312 + entry = size_overflow_hash[hash];
85313 + while (entry) {
85314 + if (!strcmp(entry->name, func_name))
85315 + return entry;
85316 + entry = entry->next;
85317 + }
85318 +
85319 + return NULL;
85320 +}
85321 +
85322 +static void check_arg_type(tree var)
85323 +{
85324 + tree type = TREE_TYPE(var);
85325 + enum tree_code code = TREE_CODE(type);
85326 +
85327 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
85328 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
85329 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
85330 +}
85331 +
85332 +static int find_arg_number(tree arg, tree func)
85333 +{
85334 + tree var;
85335 + bool match = false;
85336 + unsigned int argnum = 1;
85337 +
85338 + if (TREE_CODE(arg) == SSA_NAME)
85339 + arg = SSA_NAME_VAR(arg);
85340 +
85341 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
85342 + if (strcmp(NAME(arg), NAME(var))) {
85343 + argnum++;
85344 + continue;
85345 + }
85346 + check_arg_type(var);
85347 +
85348 + match = true;
85349 + break;
85350 + }
85351 + if (!match) {
85352 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
85353 + return 0;
85354 + }
85355 + return argnum;
85356 +}
85357 +
85358 +static void print_missing_msg(tree func, unsigned int argnum)
85359 +{
85360 + unsigned int new_hash;
85361 + size_t len;
85362 + unsigned char tree_codes[CODES_LIMIT];
85363 + location_t loc = DECL_SOURCE_LOCATION(func);
85364 + const char *curfunc = NAME(func);
85365 +
85366 + len = get_function_decl(func, tree_codes);
85367 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
85368 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
85369 +}
85370 +
85371 +static void check_missing_attribute(tree arg)
85372 +{
85373 + tree type, func = get_original_function_decl(current_function_decl);
85374 + unsigned int argnum;
85375 + struct size_overflow_hash *hash;
85376 +
85377 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
85378 +
85379 + type = TREE_TYPE(arg);
85380 + // skip function pointers
85381 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
85382 + return;
85383 +
85384 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
85385 + return;
85386 +
85387 + argnum = find_arg_number(arg, func);
85388 + if (argnum == 0)
85389 + return;
85390 +
85391 + hash = get_function_hash(func);
85392 + if (!hash || !(hash->param & (1U << argnum)))
85393 + print_missing_msg(func, argnum);
85394 +}
85395 +
85396 +static tree create_new_var(tree type)
85397 +{
85398 + tree new_var = create_tmp_var(type, "cicus");
85399 +
85400 + add_referenced_var(new_var);
85401 + mark_sym_for_renaming(new_var);
85402 + return new_var;
85403 +}
85404 +
85405 +static bool is_bool(tree node)
85406 +{
85407 + tree type;
85408 +
85409 + if (node == NULL_TREE)
85410 + return false;
85411 +
85412 + type = TREE_TYPE(node);
85413 + if (!INTEGRAL_TYPE_P(type))
85414 + return false;
85415 + if (TREE_CODE(type) == BOOLEAN_TYPE)
85416 + return true;
85417 + if (TYPE_PRECISION(type) == 1)
85418 + return true;
85419 + return false;
85420 +}
85421 +
85422 +static tree cast_a_tree(tree type, tree var)
85423 +{
85424 + gcc_assert(type != NULL_TREE && var != NULL_TREE);
85425 + gcc_assert(fold_convertible_p(type, var));
85426 +
85427 + return fold_convert(type, var);
85428 +}
85429 +
85430 +static tree signed_cast(tree var)
85431 +{
85432 + return cast_a_tree(signed_size_overflow_type, var);
85433 +}
85434 +
85435 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
85436 +{
85437 + gimple assign;
85438 +
85439 + if (new_var == CREATE_NEW_VAR)
85440 + new_var = create_new_var(type);
85441 +
85442 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
85443 + gimple_set_location(assign, loc);
85444 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
85445 +
85446 + return assign;
85447 +}
85448 +
85449 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
85450 +{
85451 + tree oldstmt_rhs1;
85452 + enum tree_code code;
85453 + gimple stmt;
85454 + gimple_stmt_iterator gsi;
85455 +
85456 + if (!*potentionally_overflowed)
85457 + return NULL_TREE;
85458 +
85459 + if (rhs1 == NULL_TREE) {
85460 + debug_gimple_stmt(oldstmt);
85461 + error("create_assign: rhs1 is NULL_TREE");
85462 + gcc_unreachable();
85463 + }
85464 +
85465 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
85466 + code = TREE_CODE(oldstmt_rhs1);
85467 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
85468 + check_missing_attribute(oldstmt_rhs1);
85469 +
85470 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
85471 + gsi = gsi_for_stmt(oldstmt);
85472 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
85473 + basic_block next_bb, cur_bb;
85474 + edge e;
85475 +
85476 + gcc_assert(before == false);
85477 + gcc_assert(stmt_can_throw_internal(oldstmt));
85478 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
85479 + gcc_assert(!gsi_end_p(gsi));
85480 +
85481 + cur_bb = gimple_bb(oldstmt);
85482 + next_bb = cur_bb->next_bb;
85483 + e = find_edge(cur_bb, next_bb);
85484 + gcc_assert(e != NULL);
85485 + gcc_assert(e->flags & EDGE_FALLTHRU);
85486 +
85487 + gsi = gsi_after_labels(next_bb);
85488 + gcc_assert(!gsi_end_p(gsi));
85489 + before = true;
85490 + }
85491 + if (before)
85492 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
85493 + else
85494 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
85495 + update_stmt(stmt);
85496 + pointer_set_insert(visited, oldstmt);
85497 + return gimple_get_lhs(stmt);
85498 +}
85499 +
85500 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
85501 +{
85502 + tree new_var, lhs = gimple_get_lhs(oldstmt);
85503 + gimple stmt;
85504 + gimple_stmt_iterator gsi;
85505 +
85506 + if (!*potentionally_overflowed)
85507 + return NULL_TREE;
85508 +
85509 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
85510 + rhs1 = gimple_assign_rhs1(oldstmt);
85511 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
85512 + }
85513 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
85514 + rhs2 = gimple_assign_rhs2(oldstmt);
85515 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
85516 + }
85517 +
85518 + stmt = gimple_copy(oldstmt);
85519 + gimple_set_location(stmt, gimple_location(oldstmt));
85520 +
85521 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
85522 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
85523 +
85524 + if (is_bool(lhs))
85525 + new_var = SSA_NAME_VAR(lhs);
85526 + else
85527 + new_var = create_new_var(signed_size_overflow_type);
85528 + new_var = make_ssa_name(new_var, stmt);
85529 + gimple_set_lhs(stmt, new_var);
85530 +
85531 + if (rhs1 != NULL_TREE) {
85532 + if (!gimple_assign_cast_p(oldstmt))
85533 + rhs1 = signed_cast(rhs1);
85534 + gimple_assign_set_rhs1(stmt, rhs1);
85535 + }
85536 +
85537 + if (rhs2 != NULL_TREE)
85538 + gimple_assign_set_rhs2(stmt, rhs2);
85539 +#if BUILDING_GCC_VERSION >= 4007
85540 + if (rhs3 != NULL_TREE)
85541 + gimple_assign_set_rhs3(stmt, rhs3);
85542 +#endif
85543 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
85544 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
85545 +
85546 + gsi = gsi_for_stmt(oldstmt);
85547 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
85548 + update_stmt(stmt);
85549 + pointer_set_insert(visited, oldstmt);
85550 + return gimple_get_lhs(stmt);
85551 +}
85552 +
85553 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
85554 +{
85555 + basic_block bb;
85556 + gimple phi;
85557 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
85558 +
85559 + bb = gsi_bb(gsi);
85560 +
85561 + phi = create_phi_node(var, bb);
85562 + gsi = gsi_last(phi_nodes(bb));
85563 + gsi_remove(&gsi, false);
85564 +
85565 + gsi = gsi_for_stmt(oldstmt);
85566 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
85567 + gimple_set_bb(phi, bb);
85568 + return phi;
85569 +}
85570 +
85571 +static basic_block create_a_first_bb(void)
85572 +{
85573 + basic_block first_bb;
85574 +
85575 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85576 + if (dom_info_available_p(CDI_DOMINATORS))
85577 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
85578 + return first_bb;
85579 +}
85580 +
85581 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
85582 +{
85583 + basic_block bb;
85584 + gimple newstmt, def_stmt;
85585 + gimple_stmt_iterator gsi;
85586 +
85587 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
85588 + if (TREE_CODE(arg) == SSA_NAME) {
85589 + def_stmt = get_def_stmt(arg);
85590 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
85591 + gsi = gsi_for_stmt(def_stmt);
85592 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
85593 + return newstmt;
85594 + }
85595 + }
85596 +
85597 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
85598 + if (bb->index == 0)
85599 + bb = create_a_first_bb();
85600 + gsi = gsi_after_labels(bb);
85601 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
85602 + return newstmt;
85603 +}
85604 +
85605 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
85606 +{
85607 + gimple newstmt;
85608 + gimple_stmt_iterator gsi;
85609 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
85610 + gimple def_newstmt = get_def_stmt(new_rhs);
85611 +
85612 + gsi_insert = gsi_insert_after;
85613 + gsi = gsi_for_stmt(def_newstmt);
85614 +
85615 + switch (gimple_code(get_def_stmt(arg))) {
85616 + case GIMPLE_PHI:
85617 + newstmt = gimple_build_assign(new_var, new_rhs);
85618 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
85619 + gsi_insert = gsi_insert_before;
85620 + break;
85621 + case GIMPLE_ASM:
85622 + case GIMPLE_CALL:
85623 + newstmt = gimple_build_assign(new_var, new_rhs);
85624 + break;
85625 + case GIMPLE_ASSIGN:
85626 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
85627 + break;
85628 + default:
85629 + /* unknown gimple_code (handle_build_new_phi_arg) */
85630 + gcc_unreachable();
85631 + }
85632 +
85633 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
85634 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
85635 + update_stmt(newstmt);
85636 + return newstmt;
85637 +}
85638 +
85639 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
85640 +{
85641 + gimple newstmt;
85642 + tree new_rhs;
85643 +
85644 + new_rhs = expand(visited, potentionally_overflowed, arg);
85645 +
85646 + if (new_rhs == NULL_TREE)
85647 + return NULL_TREE;
85648 +
85649 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
85650 + return gimple_get_lhs(newstmt);
85651 +}
85652 +
85653 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
85654 +{
85655 + gimple phi;
85656 + tree new_var = create_new_var(signed_size_overflow_type);
85657 + unsigned int i, n = gimple_phi_num_args(oldstmt);
85658 +
85659 + pointer_set_insert(visited, oldstmt);
85660 + phi = overflow_create_phi_node(oldstmt, new_var);
85661 + for (i = 0; i < n; i++) {
85662 + tree arg, lhs;
85663 +
85664 + arg = gimple_phi_arg_def(oldstmt, i);
85665 + if (is_gimple_constant(arg))
85666 + arg = signed_cast(arg);
85667 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
85668 + if (lhs == NULL_TREE)
85669 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
85670 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
85671 + }
85672 +
85673 + update_stmt(phi);
85674 + return gimple_phi_result(phi);
85675 +}
85676 +
85677 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85678 +{
85679 + gimple def_stmt = get_def_stmt(var);
85680 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
85681 +
85682 + *potentionally_overflowed = true;
85683 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85684 + if (new_rhs1 == NULL_TREE) {
85685 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
85686 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85687 + else
85688 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
85689 + }
85690 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
85691 +}
85692 +
85693 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85694 +{
85695 + gimple def_stmt = get_def_stmt(var);
85696 + tree rhs1 = gimple_assign_rhs1(def_stmt);
85697 +
85698 + if (is_gimple_constant(rhs1))
85699 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast(rhs1), NULL_TREE, NULL_TREE);
85700 +
85701 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
85702 + switch (TREE_CODE(rhs1)) {
85703 + case SSA_NAME:
85704 + return handle_unary_rhs(visited, potentionally_overflowed, var);
85705 +
85706 + case ARRAY_REF:
85707 + case BIT_FIELD_REF:
85708 + case ADDR_EXPR:
85709 + case COMPONENT_REF:
85710 + case INDIRECT_REF:
85711 +#if BUILDING_GCC_VERSION >= 4006
85712 + case MEM_REF:
85713 +#endif
85714 + case PARM_DECL:
85715 + case TARGET_MEM_REF:
85716 + case VAR_DECL:
85717 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85718 +
85719 + default:
85720 + debug_gimple_stmt(def_stmt);
85721 + debug_tree(rhs1);
85722 + gcc_unreachable();
85723 + }
85724 +}
85725 +
85726 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
85727 +{
85728 + gimple cond_stmt;
85729 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
85730 +
85731 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
85732 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
85733 + update_stmt(cond_stmt);
85734 +}
85735 +
85736 +static tree create_string_param(tree string)
85737 +{
85738 + tree i_type, a_type;
85739 + int length = TREE_STRING_LENGTH(string);
85740 +
85741 + gcc_assert(length > 0);
85742 +
85743 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
85744 + a_type = build_array_type(char_type_node, i_type);
85745 +
85746 + TREE_TYPE(string) = a_type;
85747 + TREE_CONSTANT(string) = 1;
85748 + TREE_READONLY(string) = 1;
85749 +
85750 + return build1(ADDR_EXPR, ptr_type_node, string);
85751 +}
85752 +
85753 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
85754 +{
85755 + gimple func_stmt, def_stmt;
85756 + tree current_func, loc_file, loc_line;
85757 + expanded_location xloc;
85758 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
85759 +
85760 + def_stmt = get_def_stmt(arg);
85761 + xloc = expand_location(gimple_location(def_stmt));
85762 +
85763 + if (!gimple_has_location(def_stmt)) {
85764 + xloc = expand_location(gimple_location(stmt));
85765 + if (!gimple_has_location(stmt))
85766 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85767 + }
85768 +
85769 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
85770 +
85771 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
85772 + loc_file = create_string_param(loc_file);
85773 +
85774 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
85775 + current_func = create_string_param(current_func);
85776 +
85777 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
85778 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
85779 +
85780 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
85781 +}
85782 +
85783 +static void __unused print_the_code_insertions(gimple stmt)
85784 +{
85785 + location_t loc = gimple_location(stmt);
85786 +
85787 + inform(loc, "Integer size_overflow check applied here.");
85788 +}
85789 +
85790 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
85791 +{
85792 + basic_block cond_bb, join_bb, bb_true;
85793 + edge e;
85794 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85795 +
85796 + cond_bb = gimple_bb(stmt);
85797 + gsi_prev(&gsi);
85798 + if (gsi_end_p(gsi))
85799 + e = split_block_after_labels(cond_bb);
85800 + else
85801 + e = split_block(cond_bb, gsi_stmt(gsi));
85802 + cond_bb = e->src;
85803 + join_bb = e->dest;
85804 + e->flags = EDGE_FALSE_VALUE;
85805 + e->probability = REG_BR_PROB_BASE;
85806 +
85807 + bb_true = create_empty_bb(cond_bb);
85808 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
85809 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
85810 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
85811 +
85812 + if (dom_info_available_p(CDI_DOMINATORS)) {
85813 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
85814 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
85815 + }
85816 +
85817 + if (current_loops != NULL) {
85818 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
85819 + add_bb_to_loop(bb_true, cond_bb->loop_father);
85820 + }
85821 +
85822 + insert_cond(cond_bb, arg, cond_code, type_value);
85823 + insert_cond_result(bb_true, stmt, arg);
85824 +
85825 +// print_the_code_insertions(stmt);
85826 +}
85827 +
85828 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
85829 +{
85830 + gimple ucast_stmt;
85831 + gimple_stmt_iterator gsi;
85832 + location_t loc = gimple_location(stmt);
85833 +
85834 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
85835 + gsi = gsi_for_stmt(stmt);
85836 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
85837 + return ucast_stmt;
85838 +}
85839 +
85840 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
85841 +{
85842 + tree type_max, type_min, rhs_type = TREE_TYPE(rhs);
85843 + gimple ucast_stmt;
85844 +
85845 + if (!*potentionally_overflowed)
85846 + return;
85847 +
85848 + if (TYPE_UNSIGNED(rhs_type)) {
85849 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
85850 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
85851 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
85852 + } else {
85853 + type_max = signed_cast(TYPE_MAX_VALUE(rhs_type));
85854 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
85855 +
85856 + type_min = signed_cast(TYPE_MIN_VALUE(rhs_type));
85857 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
85858 + }
85859 +}
85860 +
85861 +static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
85862 +{
85863 + gimple assign;
85864 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
85865 + tree origtype = TREE_TYPE(orig_rhs);
85866 +
85867 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
85868 +
85869 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
85870 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
85871 + update_stmt(assign);
85872 + return gimple_get_lhs(assign);
85873 +}
85874 +
85875 +static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var, tree orig_rhs, tree var_rhs, tree new_rhs1, tree new_rhs2, void (*gimple_assign_set_rhs)(gimple, tree))
85876 +{
85877 + tree new_rhs;
85878 +
85879 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
85880 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85881 +
85882 + if (var_rhs == NULL_TREE)
85883 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85884 +
85885 + new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
85886 + gimple_assign_set_rhs(def_stmt, new_rhs);
85887 + update_stmt(def_stmt);
85888 +
85889 + check_size_overflow(def_stmt, var_rhs, orig_rhs, potentionally_overflowed);
85890 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85891 +}
85892 +
85893 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85894 +{
85895 + tree rhs1, rhs2;
85896 + gimple def_stmt = get_def_stmt(var);
85897 + tree new_rhs1 = NULL_TREE;
85898 + tree new_rhs2 = NULL_TREE;
85899 +
85900 + rhs1 = gimple_assign_rhs1(def_stmt);
85901 + rhs2 = gimple_assign_rhs2(def_stmt);
85902 +
85903 + /* no DImode/TImode division in the 32/64 bit kernel */
85904 + switch (gimple_assign_rhs_code(def_stmt)) {
85905 + case RDIV_EXPR:
85906 + case TRUNC_DIV_EXPR:
85907 + case CEIL_DIV_EXPR:
85908 + case FLOOR_DIV_EXPR:
85909 + case ROUND_DIV_EXPR:
85910 + case TRUNC_MOD_EXPR:
85911 + case CEIL_MOD_EXPR:
85912 + case FLOOR_MOD_EXPR:
85913 + case ROUND_MOD_EXPR:
85914 + case EXACT_DIV_EXPR:
85915 + case POINTER_PLUS_EXPR:
85916 + case BIT_AND_EXPR:
85917 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
85918 + default:
85919 + break;
85920 + }
85921 +
85922 + *potentionally_overflowed = true;
85923 +
85924 + if (TREE_CODE(rhs1) == SSA_NAME)
85925 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
85926 + if (TREE_CODE(rhs2) == SSA_NAME)
85927 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
85928 +
85929 + if (is_gimple_constant(rhs2))
85930 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, new_rhs1, signed_cast(rhs2), &gimple_assign_set_rhs1);
85931 +
85932 + if (is_gimple_constant(rhs1))
85933 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, new_rhs2, signed_cast(rhs1), new_rhs2, &gimple_assign_set_rhs2);
85934 +
85935 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
85936 +}
85937 +
85938 +#if BUILDING_GCC_VERSION >= 4007
85939 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
85940 +{
85941 + if (is_gimple_constant(rhs))
85942 + return signed_cast(rhs);
85943 + if (TREE_CODE(rhs) != SSA_NAME)
85944 + return NULL_TREE;
85945 + return expand(visited, potentionally_overflowed, rhs);
85946 +}
85947 +
85948 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
85949 +{
85950 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
85951 + gimple def_stmt = get_def_stmt(var);
85952 +
85953 + *potentionally_overflowed = true;
85954 +
85955 + rhs1 = gimple_assign_rhs1(def_stmt);
85956 + rhs2 = gimple_assign_rhs2(def_stmt);
85957 + rhs3 = gimple_assign_rhs3(def_stmt);
85958 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
85959 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
85960 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
85961 +
85962 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
85963 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
85964 + error("handle_ternary_ops: unknown rhs");
85965 + gcc_unreachable();
85966 +}
85967 +#endif
85968 +
85969 +static void set_size_overflow_type(tree node)
85970 +{
85971 + switch (TYPE_MODE(TREE_TYPE(node))) {
85972 + case SImode:
85973 + signed_size_overflow_type = intDI_type_node;
85974 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85975 + break;
85976 + case DImode:
85977 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
85978 + signed_size_overflow_type = intDI_type_node;
85979 + unsigned_size_overflow_type = unsigned_intDI_type_node;
85980 + } else {
85981 + signed_size_overflow_type = intTI_type_node;
85982 + unsigned_size_overflow_type = unsigned_intTI_type_node;
85983 + }
85984 + break;
85985 + default:
85986 + error("set_size_overflow_type: unsupported gcc configuration.");
85987 + gcc_unreachable();
85988 + }
85989 +}
85990 +
85991 +static tree expand_visited(gimple def_stmt)
85992 +{
85993 + gimple tmp;
85994 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
85995 +
85996 + gsi_next(&gsi);
85997 + tmp = gsi_stmt(gsi);
85998 + switch (gimple_code(tmp)) {
85999 + case GIMPLE_ASSIGN:
86000 + return gimple_get_lhs(tmp);
86001 + case GIMPLE_PHI:
86002 + return gimple_phi_result(tmp);
86003 + case GIMPLE_CALL:
86004 + return gimple_call_lhs(tmp);
86005 + default:
86006 + return NULL_TREE;
86007 + }
86008 +}
86009 +
86010 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86011 +{
86012 + gimple def_stmt;
86013 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
86014 +
86015 + if (is_gimple_constant(var))
86016 + return NULL_TREE;
86017 +
86018 + if (TREE_CODE(var) == ADDR_EXPR)
86019 + return NULL_TREE;
86020 +
86021 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
86022 + if (code != INTEGER_TYPE)
86023 + return NULL_TREE;
86024 +
86025 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
86026 + check_missing_attribute(var);
86027 + return NULL_TREE;
86028 + }
86029 +
86030 + def_stmt = get_def_stmt(var);
86031 +
86032 + if (!def_stmt)
86033 + return NULL_TREE;
86034 +
86035 + if (pointer_set_contains(visited, def_stmt))
86036 + return expand_visited(def_stmt);
86037 +
86038 + switch (gimple_code(def_stmt)) {
86039 + case GIMPLE_NOP:
86040 + check_missing_attribute(var);
86041 + return NULL_TREE;
86042 + case GIMPLE_PHI:
86043 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
86044 + case GIMPLE_CALL:
86045 + case GIMPLE_ASM:
86046 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
86047 + case GIMPLE_ASSIGN:
86048 + switch (gimple_num_ops(def_stmt)) {
86049 + case 2:
86050 + return handle_unary_ops(visited, potentionally_overflowed, var);
86051 + case 3:
86052 + return handle_binary_ops(visited, potentionally_overflowed, var);
86053 +#if BUILDING_GCC_VERSION >= 4007
86054 + case 4:
86055 + return handle_ternary_ops(visited, potentionally_overflowed, var);
86056 +#endif
86057 + }
86058 + default:
86059 + debug_gimple_stmt(def_stmt);
86060 + error("expand: unknown gimple code");
86061 + gcc_unreachable();
86062 + }
86063 +}
86064 +
86065 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
86066 +{
86067 + gimple assign;
86068 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86069 + tree origtype = TREE_TYPE(origarg);
86070 +
86071 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
86072 +
86073 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
86074 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
86075 + update_stmt(assign);
86076 +
86077 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
86078 + update_stmt(stmt);
86079 +}
86080 +
86081 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
86082 +{
86083 + const char *origid;
86084 + tree arg, origarg;
86085 +
86086 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
86087 + gcc_assert(gimple_call_num_args(stmt) > argnum);
86088 + return gimple_call_arg(stmt, argnum);
86089 + }
86090 +
86091 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
86092 + while (origarg && argnum) {
86093 + argnum--;
86094 + origarg = TREE_CHAIN(origarg);
86095 + }
86096 +
86097 + gcc_assert(argnum == 0);
86098 +
86099 + gcc_assert(origarg != NULL_TREE);
86100 + origid = NAME(origarg);
86101 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
86102 + if (!strcmp(origid, NAME(arg)))
86103 + return arg;
86104 + }
86105 + return NULL_TREE;
86106 +}
86107 +
86108 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
86109 +{
86110 + struct pointer_set_t *visited;
86111 + tree arg, newarg;
86112 + bool potentionally_overflowed;
86113 +
86114 + arg = get_function_arg(argnum, stmt, fndecl);
86115 + if (arg == NULL_TREE)
86116 + return;
86117 +
86118 + if (is_gimple_constant(arg))
86119 + return;
86120 + if (TREE_CODE(arg) != SSA_NAME)
86121 + return;
86122 +
86123 + check_arg_type(arg);
86124 +
86125 + set_size_overflow_type(arg);
86126 +
86127 + visited = pointer_set_create();
86128 + potentionally_overflowed = false;
86129 + newarg = expand(visited, &potentionally_overflowed, arg);
86130 + pointer_set_destroy(visited);
86131 +
86132 + if (newarg == NULL_TREE || !potentionally_overflowed)
86133 + return;
86134 +
86135 + change_function_arg(stmt, arg, argnum, newarg);
86136 +
86137 + check_size_overflow(stmt, newarg, arg, &potentionally_overflowed);
86138 +}
86139 +
86140 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
86141 +{
86142 + tree p = TREE_VALUE(attr);
86143 + do {
86144 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
86145 + p = TREE_CHAIN(p);
86146 + } while (p);
86147 +}
86148 +
86149 +static void handle_function_by_hash(gimple stmt, tree fndecl)
86150 +{
86151 + tree orig_fndecl;
86152 + unsigned int num;
86153 + struct size_overflow_hash *hash;
86154 +
86155 + orig_fndecl = get_original_function_decl(fndecl);
86156 + hash = get_function_hash(orig_fndecl);
86157 + if (!hash)
86158 + return;
86159 +
86160 + for (num = 1; num <= MAX_PARAM; num++)
86161 + if (hash->param & (1U << num))
86162 + handle_function_arg(stmt, fndecl, num - 1);
86163 +}
86164 +
86165 +static unsigned int handle_function(void)
86166 +{
86167 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
86168 + int saved_last_basic_block = last_basic_block;
86169 +
86170 + do {
86171 + gimple_stmt_iterator gsi;
86172 + basic_block next = bb->next_bb;
86173 +
86174 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86175 + tree fndecl, attr;
86176 + gimple stmt = gsi_stmt(gsi);
86177 +
86178 + if (!(is_gimple_call(stmt)))
86179 + continue;
86180 + fndecl = gimple_call_fndecl(stmt);
86181 + if (fndecl == NULL_TREE)
86182 + continue;
86183 + if (gimple_call_num_args(stmt) == 0)
86184 + continue;
86185 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
86186 + if (!attr || !TREE_VALUE(attr))
86187 + handle_function_by_hash(stmt, fndecl);
86188 + else
86189 + handle_function_by_attribute(stmt, attr, fndecl);
86190 + gsi = gsi_for_stmt(stmt);
86191 + }
86192 + bb = next;
86193 + } while (bb && bb->index <= saved_last_basic_block);
86194 + return 0;
86195 +}
86196 +
86197 +static struct gimple_opt_pass size_overflow_pass = {
86198 + .pass = {
86199 + .type = GIMPLE_PASS,
86200 + .name = "size_overflow",
86201 + .gate = NULL,
86202 + .execute = handle_function,
86203 + .sub = NULL,
86204 + .next = NULL,
86205 + .static_pass_number = 0,
86206 + .tv_id = TV_NONE,
86207 + .properties_required = PROP_cfg | PROP_referenced_vars,
86208 + .properties_provided = 0,
86209 + .properties_destroyed = 0,
86210 + .todo_flags_start = 0,
86211 + .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
86212 + }
86213 +};
86214 +
86215 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
86216 +{
86217 + tree fntype;
86218 +
86219 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
86220 +
86221 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
86222 + fntype = build_function_type_list(void_type_node,
86223 + const_char_ptr_type_node,
86224 + unsigned_type_node,
86225 + const_char_ptr_type_node,
86226 + NULL_TREE);
86227 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
86228 +
86229 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
86230 + TREE_PUBLIC(report_size_overflow_decl) = 1;
86231 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
86232 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
86233 +}
86234 +
86235 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86236 +{
86237 + int i;
86238 + const char * const plugin_name = plugin_info->base_name;
86239 + const int argc = plugin_info->argc;
86240 + const struct plugin_argument * const argv = plugin_info->argv;
86241 + bool enable = true;
86242 +
86243 + struct register_pass_info size_overflow_pass_info = {
86244 + .pass = &size_overflow_pass.pass,
86245 + .reference_pass_name = "ssa",
86246 + .ref_pass_instance_number = 1,
86247 + .pos_op = PASS_POS_INSERT_AFTER
86248 + };
86249 +
86250 + if (!plugin_default_version_check(version, &gcc_version)) {
86251 + error(G_("incompatible gcc/plugin versions"));
86252 + return 1;
86253 + }
86254 +
86255 + for (i = 0; i < argc; ++i) {
86256 + if (!strcmp(argv[i].key, "no-size-overflow")) {
86257 + enable = false;
86258 + continue;
86259 + }
86260 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86261 + }
86262 +
86263 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
86264 + if (enable) {
86265 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86266 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
86267 + }
86268 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86269 +
86270 + return 0;
86271 +}
86272 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
86273 new file mode 100644
86274 index 0000000..38d2014
86275 --- /dev/null
86276 +++ b/tools/gcc/stackleak_plugin.c
86277 @@ -0,0 +1,313 @@
86278 +/*
86279 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
86280 + * Licensed under the GPL v2
86281 + *
86282 + * Note: the choice of the license means that the compilation process is
86283 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86284 + * but for the kernel it doesn't matter since it doesn't link against
86285 + * any of the gcc libraries
86286 + *
86287 + * gcc plugin to help implement various PaX features
86288 + *
86289 + * - track lowest stack pointer
86290 + *
86291 + * TODO:
86292 + * - initialize all local variables
86293 + *
86294 + * BUGS:
86295 + * - none known
86296 + */
86297 +#include "gcc-plugin.h"
86298 +#include "config.h"
86299 +#include "system.h"
86300 +#include "coretypes.h"
86301 +#include "tree.h"
86302 +#include "tree-pass.h"
86303 +#include "flags.h"
86304 +#include "intl.h"
86305 +#include "toplev.h"
86306 +#include "plugin.h"
86307 +//#include "expr.h" where are you...
86308 +#include "diagnostic.h"
86309 +#include "plugin-version.h"
86310 +#include "tm.h"
86311 +#include "function.h"
86312 +#include "basic-block.h"
86313 +#include "gimple.h"
86314 +#include "rtl.h"
86315 +#include "emit-rtl.h"
86316 +
86317 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86318 +
86319 +int plugin_is_GPL_compatible;
86320 +
86321 +static int track_frame_size = -1;
86322 +static const char track_function[] = "pax_track_stack";
86323 +static const char check_function[] = "pax_check_alloca";
86324 +static bool init_locals;
86325 +
86326 +static struct plugin_info stackleak_plugin_info = {
86327 + .version = "201203140940",
86328 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
86329 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
86330 +};
86331 +
86332 +static bool gate_stackleak_track_stack(void);
86333 +static unsigned int execute_stackleak_tree_instrument(void);
86334 +static unsigned int execute_stackleak_final(void);
86335 +
86336 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
86337 + .pass = {
86338 + .type = GIMPLE_PASS,
86339 + .name = "stackleak_tree_instrument",
86340 + .gate = gate_stackleak_track_stack,
86341 + .execute = execute_stackleak_tree_instrument,
86342 + .sub = NULL,
86343 + .next = NULL,
86344 + .static_pass_number = 0,
86345 + .tv_id = TV_NONE,
86346 + .properties_required = PROP_gimple_leh | PROP_cfg,
86347 + .properties_provided = 0,
86348 + .properties_destroyed = 0,
86349 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86350 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86351 + }
86352 +};
86353 +
86354 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
86355 + .pass = {
86356 + .type = RTL_PASS,
86357 + .name = "stackleak_final",
86358 + .gate = gate_stackleak_track_stack,
86359 + .execute = execute_stackleak_final,
86360 + .sub = NULL,
86361 + .next = NULL,
86362 + .static_pass_number = 0,
86363 + .tv_id = TV_NONE,
86364 + .properties_required = 0,
86365 + .properties_provided = 0,
86366 + .properties_destroyed = 0,
86367 + .todo_flags_start = 0,
86368 + .todo_flags_finish = TODO_dump_func
86369 + }
86370 +};
86371 +
86372 +static bool gate_stackleak_track_stack(void)
86373 +{
86374 + return track_frame_size >= 0;
86375 +}
86376 +
86377 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
86378 +{
86379 + gimple check_alloca;
86380 + tree fntype, fndecl, alloca_size;
86381 +
86382 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
86383 + fndecl = build_fn_decl(check_function, fntype);
86384 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86385 +
86386 + // insert call to void pax_check_alloca(unsigned long size)
86387 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
86388 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
86389 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
86390 +}
86391 +
86392 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
86393 +{
86394 + gimple track_stack;
86395 + tree fntype, fndecl;
86396 +
86397 + fntype = build_function_type_list(void_type_node, NULL_TREE);
86398 + fndecl = build_fn_decl(track_function, fntype);
86399 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86400 +
86401 + // insert call to void pax_track_stack(void)
86402 + track_stack = gimple_build_call(fndecl, 0);
86403 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
86404 +}
86405 +
86406 +#if BUILDING_GCC_VERSION == 4005
86407 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
86408 +{
86409 + tree fndecl;
86410 +
86411 + if (!is_gimple_call(stmt))
86412 + return false;
86413 + fndecl = gimple_call_fndecl(stmt);
86414 + if (!fndecl)
86415 + return false;
86416 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
86417 + return false;
86418 +// print_node(stderr, "pax", fndecl, 4);
86419 + return DECL_FUNCTION_CODE(fndecl) == code;
86420 +}
86421 +#endif
86422 +
86423 +static bool is_alloca(gimple stmt)
86424 +{
86425 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
86426 + return true;
86427 +
86428 +#if BUILDING_GCC_VERSION >= 4007
86429 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
86430 + return true;
86431 +#endif
86432 +
86433 + return false;
86434 +}
86435 +
86436 +static unsigned int execute_stackleak_tree_instrument(void)
86437 +{
86438 + basic_block bb, entry_bb;
86439 + bool prologue_instrumented = false, is_leaf = true;
86440 +
86441 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
86442 +
86443 + // 1. loop through BBs and GIMPLE statements
86444 + FOR_EACH_BB(bb) {
86445 + gimple_stmt_iterator gsi;
86446 +
86447 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86448 + gimple stmt;
86449 +
86450 + stmt = gsi_stmt(gsi);
86451 +
86452 + if (is_gimple_call(stmt))
86453 + is_leaf = false;
86454 +
86455 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
86456 + if (!is_alloca(stmt))
86457 + continue;
86458 +
86459 + // 2. insert stack overflow check before each __builtin_alloca call
86460 + stackleak_check_alloca(&gsi);
86461 +
86462 + // 3. insert track call after each __builtin_alloca call
86463 + stackleak_add_instrumentation(&gsi);
86464 + if (bb == entry_bb)
86465 + prologue_instrumented = true;
86466 + }
86467 + }
86468 +
86469 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
86470 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
86471 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
86472 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
86473 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
86474 + return 0;
86475 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
86476 + return 0;
86477 +
86478 + // 4. insert track call at the beginning
86479 + if (!prologue_instrumented) {
86480 + gimple_stmt_iterator gsi;
86481 +
86482 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86483 + if (dom_info_available_p(CDI_DOMINATORS))
86484 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86485 + gsi = gsi_start_bb(bb);
86486 + stackleak_add_instrumentation(&gsi);
86487 + }
86488 +
86489 + return 0;
86490 +}
86491 +
86492 +static unsigned int execute_stackleak_final(void)
86493 +{
86494 + rtx insn;
86495 +
86496 + if (cfun->calls_alloca)
86497 + return 0;
86498 +
86499 + // keep calls only if function frame is big enough
86500 + if (get_frame_size() >= track_frame_size)
86501 + return 0;
86502 +
86503 + // 1. find pax_track_stack calls
86504 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86505 + // 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))
86506 + rtx body;
86507 +
86508 + if (!CALL_P(insn))
86509 + continue;
86510 + body = PATTERN(insn);
86511 + if (GET_CODE(body) != CALL)
86512 + continue;
86513 + body = XEXP(body, 0);
86514 + if (GET_CODE(body) != MEM)
86515 + continue;
86516 + body = XEXP(body, 0);
86517 + if (GET_CODE(body) != SYMBOL_REF)
86518 + continue;
86519 + if (strcmp(XSTR(body, 0), track_function))
86520 + continue;
86521 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86522 + // 2. delete call
86523 + insn = delete_insn_and_edges(insn);
86524 +#if BUILDING_GCC_VERSION >= 4007
86525 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
86526 + insn = delete_insn_and_edges(insn);
86527 +#endif
86528 + }
86529 +
86530 +// print_simple_rtl(stderr, get_insns());
86531 +// print_rtl(stderr, get_insns());
86532 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
86533 +
86534 + return 0;
86535 +}
86536 +
86537 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86538 +{
86539 + const char * const plugin_name = plugin_info->base_name;
86540 + const int argc = plugin_info->argc;
86541 + const struct plugin_argument * const argv = plugin_info->argv;
86542 + int i;
86543 + struct register_pass_info stackleak_tree_instrument_pass_info = {
86544 + .pass = &stackleak_tree_instrument_pass.pass,
86545 +// .reference_pass_name = "tree_profile",
86546 + .reference_pass_name = "optimized",
86547 + .ref_pass_instance_number = 1,
86548 + .pos_op = PASS_POS_INSERT_BEFORE
86549 + };
86550 + struct register_pass_info stackleak_final_pass_info = {
86551 + .pass = &stackleak_final_rtl_opt_pass.pass,
86552 + .reference_pass_name = "final",
86553 + .ref_pass_instance_number = 1,
86554 + .pos_op = PASS_POS_INSERT_BEFORE
86555 + };
86556 +
86557 + if (!plugin_default_version_check(version, &gcc_version)) {
86558 + error(G_("incompatible gcc/plugin versions"));
86559 + return 1;
86560 + }
86561 +
86562 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
86563 +
86564 + for (i = 0; i < argc; ++i) {
86565 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
86566 + if (!argv[i].value) {
86567 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86568 + continue;
86569 + }
86570 + track_frame_size = atoi(argv[i].value);
86571 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
86572 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86573 + continue;
86574 + }
86575 + if (!strcmp(argv[i].key, "initialize-locals")) {
86576 + if (argv[i].value) {
86577 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86578 + continue;
86579 + }
86580 + init_locals = true;
86581 + continue;
86582 + }
86583 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86584 + }
86585 +
86586 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
86587 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
86588 +
86589 + return 0;
86590 +}
86591 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
86592 index 6789d78..4afd019 100644
86593 --- a/tools/perf/util/include/asm/alternative-asm.h
86594 +++ b/tools/perf/util/include/asm/alternative-asm.h
86595 @@ -5,4 +5,7 @@
86596
86597 #define altinstruction_entry #
86598
86599 + .macro pax_force_retaddr rip=0, reload=0
86600 + .endm
86601 +
86602 #endif
86603 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
86604 index af0f22f..9a7d479 100644
86605 --- a/usr/gen_init_cpio.c
86606 +++ b/usr/gen_init_cpio.c
86607 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
86608 int retval;
86609 int rc = -1;
86610 int namesize;
86611 - int i;
86612 + unsigned int i;
86613
86614 mode |= S_IFREG;
86615
86616 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
86617 *env_var = *expanded = '\0';
86618 strncat(env_var, start + 2, end - start - 2);
86619 strncat(expanded, new_location, start - new_location);
86620 - strncat(expanded, getenv(env_var), PATH_MAX);
86621 - strncat(expanded, end + 1, PATH_MAX);
86622 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
86623 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
86624 strncpy(new_location, expanded, PATH_MAX);
86625 + new_location[PATH_MAX] = 0;
86626 } else
86627 break;
86628 }
86629 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
86630 index 44ee712..7da730b 100644
86631 --- a/virt/kvm/kvm_main.c
86632 +++ b/virt/kvm/kvm_main.c
86633 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
86634
86635 static cpumask_var_t cpus_hardware_enabled;
86636 static int kvm_usage_count = 0;
86637 -static atomic_t hardware_enable_failed;
86638 +static atomic_unchecked_t hardware_enable_failed;
86639
86640 struct kmem_cache *kvm_vcpu_cache;
86641 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
86642 @@ -2291,7 +2291,7 @@ static void hardware_enable_nolock(void *junk)
86643
86644 if (r) {
86645 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
86646 - atomic_inc(&hardware_enable_failed);
86647 + atomic_inc_unchecked(&hardware_enable_failed);
86648 printk(KERN_INFO "kvm: enabling virtualization on "
86649 "CPU%d failed\n", cpu);
86650 }
86651 @@ -2345,10 +2345,10 @@ static int hardware_enable_all(void)
86652
86653 kvm_usage_count++;
86654 if (kvm_usage_count == 1) {
86655 - atomic_set(&hardware_enable_failed, 0);
86656 + atomic_set_unchecked(&hardware_enable_failed, 0);
86657 on_each_cpu(hardware_enable_nolock, NULL, 1);
86658
86659 - if (atomic_read(&hardware_enable_failed)) {
86660 + if (atomic_read_unchecked(&hardware_enable_failed)) {
86661 hardware_disable_all_nolock();
86662 r = -EBUSY;
86663 }
86664 @@ -2709,7 +2709,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
86665 kvm_arch_vcpu_put(vcpu);
86666 }
86667
86668 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86669 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86670 struct module *module)
86671 {
86672 int r;
86673 @@ -2772,7 +2772,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86674 if (!vcpu_align)
86675 vcpu_align = __alignof__(struct kvm_vcpu);
86676 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
86677 - 0, NULL);
86678 + SLAB_USERCOPY, NULL);
86679 if (!kvm_vcpu_cache) {
86680 r = -ENOMEM;
86681 goto out_free_3;
86682 @@ -2782,9 +2782,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
86683 if (r)
86684 goto out_free;
86685
86686 - kvm_chardev_ops.owner = module;
86687 - kvm_vm_fops.owner = module;
86688 - kvm_vcpu_fops.owner = module;
86689 + pax_open_kernel();
86690 + *(void **)&kvm_chardev_ops.owner = module;
86691 + *(void **)&kvm_vm_fops.owner = module;
86692 + *(void **)&kvm_vcpu_fops.owner = module;
86693 + pax_close_kernel();
86694
86695 r = misc_register(&kvm_dev);
86696 if (r) {